jags.fit | R Documentation |
Convenient functions designed to work well with cloned data arguments and JAGS.
jags.fit(data, params, model, inits = NULL, n.chains = 3,
n.adapt = 1000, n.update = 1000, thin = 1, n.iter = 5000,
updated.model = TRUE, ...)
data |
A named list or environment containing the data.
If an environment, |
params |
Character vector of parameters to be sampled. |
model |
Character string (name of the model file), a function containing
the model, or a or |
inits |
Optional specification of initial values in the form of a
list or a function (see Initialization at
|
n.chains |
Number of chains to generate. |
n.adapt |
Number of steps for adaptation. |
n.update |
Number of updates before iterations.
It is usually a bad idea to use |
thin |
Thinning value. |
n.iter |
Number of iterations. |
updated.model |
Logical, if the updated model should be attached as attribute
(this can be used to further update if convergence
was not satisfactory, see |
... |
Further arguments passed to |
An mcmc.list
object. If data cloning is used via the
data
argument, summary
returns a modified summary
containing scaled data cloning standard errors
(scaled by sqrt(n.clones)
, see dcsd
),
and R_{hat}
values
(as returned by gelman.diag
).
Peter Solymos
Underlying functions: jags.model
,
update.jags
,
coda.samples
Parallel chain computations: jags.parfit
Methods: dcsd
, confint.mcmc.list.dc
,
coef.mcmc.list
, quantile.mcmc.list
,
vcov.mcmc.list.dc
## Not run:
if (require(rjags)) {
## simple regression example from the JAGS manual
jfun <- function() {
for (i in 1:N) {
Y[i] ~ dnorm(mu[i], tau)
mu[i] <- alpha + beta * (x[i] - x.bar)
}
x.bar <- mean(x[])
alpha ~ dnorm(0.0, 1.0E-4)
beta ~ dnorm(0.0, 1.0E-4)
sigma <- 1.0/sqrt(tau)
tau ~ dgamma(1.0E-3, 1.0E-3)
}
## data generation
set.seed(1234)
N <- 100
alpha <- 1
beta <- -1
sigma <- 0.5
x <- runif(N)
linpred <- crossprod(t(model.matrix(~x)), c(alpha, beta))
Y <- rnorm(N, mean = linpred, sd = sigma)
## list of data for the model
jdata <- list(N = N, Y = Y, x = x)
## what to monitor
jpara <- c("alpha", "beta", "sigma")
## fit the model with JAGS
regmod <- jags.fit(jdata, jpara, jfun, n.chains = 3)
## model summary
summary(regmod)
## data cloning
dcdata <- dclone(jdata, 5, multiply = "N")
dcmod <- jags.fit(dcdata, jpara, jfun, n.chains = 3)
summary(dcmod)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.