# NOT RUN {
# Use a short run when testing the code on CRAN
# Set nIter manually if running on local computer,
# nIter=1000 is usually enough
if(nchar(Sys.getenv("LONG_TEST")) != 0) {
nIter=7500
} else {
nIter=100
}
## Generates T=500 observations from a linear state space model with
## ( phi, sigma_e, sigma_v ) = ( 0.5, 1.0, 0.1 ) and zero initial state.
d <- generateData(phi=0.5, sigmav=1.0, sigmae=0.1, T=500, x0=0.0)
## Estimate the marginal posterior for phi
res <- pmh(d$y, initPar=0.1, sigmav=1.0, sigmae=0.1, nPart=50, T=500,
x0=0.0, nIter, stepSize=0.10)
## Plot the estimate
par(mfrow=c(1,1))
hist(res, main="", xlab=expression(phi),
ylab="marginal posterior", freq=FALSE)
# }
Run the code above in your browser using DataLab