expect_mcmc {mcunit} | R Documentation |
Test of MCMC chain
Description
Test of MCMC steps having the correct stationary distribution without assuming reversibility of the chain. Details of this are in Gandy and Scott (2020); it uses ideas described in the appendix of Gandy and Veraart (2017).
Usage
expect_mcmc(object, control = NULL, thinning = NULL, joint = FALSE)
Arguments
object |
A list describing the MCMC sampler with the following elements:
|
control |
a list controlling the algorithm
|
thinning |
Amount of thinning for the MCMC chain. 1 corresponds to no thinning. Default: automatically computed to ensure an autocorrelation of at most 0.5 at lag 1. |
joint |
If TRUE, then the MCMC uses systematic scan of both data and parameters, rather than just updating parameters with the sampler to be tested. Default: FALSE. |
Value
The first argument, invisibly, to allow chaining of expectations.
References
Gandy A, Scott J (2020).
“Unit Testing for MCMC and other Monte Carlo Methods.”
https://arxiv.org/abs/2001.06465.
Gandy A, Veraart LAM (2017).
“A Bayesian Methodology for Systemic Risk Assessment in Financial Networks.”
Management Science, 63(12), 4428–4446.
doi: 10.1287/mnsc.2016.2546, https://doi.org/10.1287/mnsc.2016.2546.
See Also
Examples
object <- list(genprior=function() rnorm(1),
gendata=function(theta) rnorm(5,theta),
stepMCMC=function(theta,data,thinning){
f <- function(x) prod(dnorm(data,x))*dnorm(x)
for (i in 1:thinning){
thetanew = rnorm(1,mean=theta,sd=1)
if (runif(1)<f(thetanew)/f(theta))
theta <- thetanew
}
theta
}
)
expect_mcmc(object)