expect_mcmc_reversible {mcunit} | R Documentation |
Test of MCMC chain assuming reversibility of the chain
Description
Test of MCMC steps having the correct stationary distribution assuming reversibility of the chain. Uses ideas from Besag and Clifford (1989) as extended to possible ties in Gandy and Scott (2020).
Usage
expect_mcmc_reversible(
object,
control = NULL,
thinning = NULL,
nsteps = 10,
p = 1,
tolerance = 1e-08
)
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. |
nsteps |
Number of steps of the chain to use. Default: 10. |
p |
The probability with which the MCMC updates the parameter as opposed to the data in a given step. If less than 1.0, then the MCMC is a random scan on both data and parameters. Default: 1.0. |
tolerance |
Absolute error where value of the samplers are treated as equal. Default: 1e-8. |
Value
The first argument, invisibly, to allow chaining of expectations.
References
Besag J, Clifford P (1989).
“Generalized Monte Carlo significance tests.”
Biometrika, 76(4), 633–642.
doi: 10.1093/biomet/76.4.633, https://doi.org/10.1093/biomet/76.4.633.
Gandy A, Scott J (2020).
“Unit Testing for MCMC and other Monte Carlo Methods.”
https://arxiv.org/abs/2001.06465.
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
},
test=function(x) x
)
expect_mcmc_reversible(object)