Description Usage Arguments Value References See Also Examples
View source: R/expect_invariant.R
Test of MCMC steps having the correct stationary distribution assuming reversibility of the chain. Uses ideas from \insertCitebesag_clifford_1989;textualmcunit as extended to possible ties in \insertCitegandy_scott_2019;textualmcunit.
1 2 3 4 5 6 7 8 | expect_mcmc_reversible(
object,
control = NULL,
thinning = NULL,
nsteps = 10,
p = 1,
tolerance = 1e-08
)
|
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. |
The first argument, invisibly, to allow chaining of expectations.
expect_mcmc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.