Description Usage Arguments Value Author(s) References See Also Examples
The create.model function creates a model object. The run.model function simulates an mcmc chain of the nodes in the model. After the completion of run.model, the history of the run is returned as a named list.
1 2 3 | create.model(...)
run.model(m, iterations, burn, adapt, thin)
get.ar(x)
|
m |
the rcppbugs model object. |
iterations |
how many iterations to sample. |
burn |
how many iterations to use for burnin. |
adapt |
how many iterations to use for the adaptive period. |
thin |
how frequently to record traces of the model nodes. |
... |
rcppbugs objects to use as the nodes of the model. |
x |
the result of an rcppbugs run. |
create.model returns a mcmc.model model object. run.model returns a named list containing the historical traces of the model run. get.ar returns the acceptance ratio of an MCMC run
rcppbugs was written by Whit Armstrong.
https://github.com/armstrtw/CppBugs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | library(rcppbugs)
NR <- 1e2L
NC <- 2L
y <- matrix(rnorm(NR,1) + 10,nr=NR,nc=1L)
X <- matrix(nr=NR,nc=NC)
X[,1] <- 1
X[,2] <- y + rnorm(NR)/2 - 10
## RCppBugs Model
b <- mcmc.normal(rnorm(NC),mu=0,tau=0.0001)
tau.y <- mcmc.gamma(sd(as.vector(y)),alpha=0.1,beta=0.1)
y.hat <- linear(X,b)
y.lik <- mcmc.normal(y,mu=y.hat,tau=tau.y,observed=TRUE)
m <- create.model(b, tau.y, y.hat, y.lik)
runtime <- system.time(ans <- run.model(m, iterations=1e2L, burn=1e2L, adapt=1e3L, thin=10L))
print(get.ar(ans))
print(apply(ans[["b"]],2,mean))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.