A package for Calibrated posterior predictive p-values.
This is an active research project in early development. It is public so collaborators can follow along, not because it is ready.
- The interface changes often, without notice or deprecation.
- There is no released version, and nothing here should be depended on.
If you want to try it, get in touch first.
It provides a general framework for a MCMC engine—to:
- Compute calibrated posterior p-values (cppp),
- Estimate their Monte Carlo variance using the idea of the transfer effective sample size (ESS)
- Can handle different MCMC engines. NIMBLE and R for now, other MCMC engines later.
Given data
- Run an long MCMC chain to obtain draws from the posterior
$p(\theta \mid y)$ . With$M$ draws, we sample new datafrom the posterior predictive of the data$p(y^* \mid \theta_i)$ and compute
This chain of
-
Generate
$r$ calibration replicates:- simulate new datasets
$\tilde{y}_j$ from the model, - run short chains of length $\tilde{m} $ for
$p(\theta \mid \tilde{y}_j)$ , - compute short-run posterior-predictive p-values
$\hat{p}_j$ .
- simulate new datasets
-
Estimate the CPPP:
- Estimate the Monte Carlo variance using the transfer ESS idea:
match each
$\hat{p}_j$ to a quantile on the observed$\Delta$ -chain, compute the transfer autocorrelation, and estimate the cppp variance.
| Function | Purpose |
|---|---|
runCalibration() |
Generic function for calibration |
runCalibrationNIMBLE() |
NIMBLE-specific setup that builds the generic inputs and calls runCalibration(). |
| Function | Role |
|---|---|
discrepancy() |
Describes one discrepancy: its name, the nodes it reads, and optionally your own nimbleFunction. |
simulation() |
Describes how replicated datasets are generated. |
makeColDiscFun() |
Returns a function that extracts an “online” discrepancy column. |
makeOfflineDiscFun() |
Returns a function that computes discrepancies “offline.” |
computeCppp() |
Computes cppp from |
transferAutocorrelation() |
Transfer-ESS machinery for the cppp variance. Placeholder — not implemented. |
cpppResult (S3), currently holding:
CPPP— one value per discrepancyobsPPP,repPPP— observed and replicated posterior predictive p-valuesdiscrepancies— the observed and replicated discrepancy valuesdrawnIndices— which posterior draws seeded the calibration replicates
Standard errors, confidence intervals, and print / summary / plot methods
are planned but not implemented.
-
Build your MCMC engine
- For NIMBLE: configure a model and compiled MCMC object.
- Otherwise: supply a function
MCMCFun(targetData, control)that runs an MCMC and returns samples.
-
Provide a data simulator
-
simulateNewDataFun(thetaRow, control)draws a dataset$\tilde{y}$ from the model posterior predictive.
-
-
Describe your discrepancies
-
discrepancy("mean")names one the package ships;discrepancy("asymm", modelNodes = "mu", fun = myAsymm)supplies your own as a nimbleFunction. - Online: the discrepancy or PPP is computed during MCMC; just extract the column.
-
Offline: compute
$D(y,\theta)$ and$D(y^*,\theta)$ after sampling. - Note: the step that turns these descriptions into what
runCalibration()consumes is still being built.
-
-
Run calibration
- Call
runCalibration()with your functions and number of replicates$r$ . - the function iteratively: simulate → run short chain → compute
$\hat{p}_j$ .
- Call
-
Compute cppp and variance
computeCppp(obsPPP, repPPP)-
transferAutocorrelation(deltaChain, obsPPP, repPPP, mTilde)— not implemented yet
TO DO