Description Usage Arguments Value References See Also Examples
View source: R/expect_invariant.R
Test of MCMC steps having the correct stationary distribution without assuming reversibility of the chain. Details of this are in \insertCitegandy_scott_2019;textualmcunit; it uses ideas described in the appendix of \insertCitegandy_veraart_2017;textualmcunit.
1 | expect_mcmc(object, control = NULL, thinning = NULL, joint = FALSE)
|
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. |
The first argument, invisibly, to allow chaining of expectations.
expect_mcmc_reversible
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.