Description Usage Arguments Value Examples
The jagsUI function is a basic user interface for running JAGS
analyses via package rjags inspired by similar packages like
R2WinBUGS, R2OpenBUGS, and R2jags. The user provides
a model file, data, initial values (optional), and parameters to save.
The function compiles the information and sends it to JAGS,
then consolidates and summarizes the MCMC output in an object of
class jagsUI.
1 2 3 |
model_file |
Path to file containing the model written in
|
data |
A named list of the data objects required by the model. |
inits |
A list with |
params |
Character vector of the names of the parameters in the model which should be monitored. |
n_cores |
If > 1, the number of parallel CPU cores to use. MCMC chains are split between cores. |
n_chains |
Number of Markov chains to run. |
n_adapt |
Number of iterations to run in the adaptive phase. |
n_iter |
Total number of iterations per chain (*including* warm-up). |
n_warmup |
Number of iterations at the beginning of each chain to discard. Does not include the adaptive iterations. |
n_thin |
Thinning rate. Must be a positive integer. |
modules |
List of JAGS modules to load before analysis. |
factories |
Optional character vector of factories to enable or
disable, in the format <factory> <type> <setting>. For example, to turn
|
quiet |
If |
An object of class jagsUI. Notable elements in the output
object include:
samples |
The original output object from the |
summary |
A summary of various statistics calculated based on model output, in matrix form. |
model |
The |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #Analyze Longley economic data in JAGS
#Package data
data(longley)
data <- list(gnp=longley$GNP, employed=longley$Employed,
n=length(longley$Employed))
#Write model file
model_file <- tempfile()
writeLines("
model{
#Likelihood
for (i in 1:n){
employed[i] ~ dnorm(mu[i], tau)
mu[i] <- alpha + beta*gnp[i]
}
#Priors
alpha ~ dnorm(0, 0.00001)
beta ~ dnorm(0, 0.00001)
sigma ~ dunif(0,1000)
tau <- pow(sigma,-2)
}
", con=model_file)
#Inits function
inits <- function(){
list(alpha=rnorm(1,0,1),beta=rnorm(1,0,1),sigma=runif(1,0,3))
}
#Parameters to save posteriors for
params <- c('alpha','beta','sigma')
#Run analysis
out <- jagsUI(model_file, data, inits, params,
n_chains=3, n_iter=1000, n_warmup=500)
#Take another 1000 posterior samples
out <- update(out, n_iter=1000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.