Description Usage Arguments Value See Also Examples
A convenience function for extracting the effective number of parameters (pD)
and the Deviance Information Criterion (DIC) from an rjags
object.
1 | pd_dic(x)
|
x |
An |
A list with two elements: pD
, and DIC
. If these were
not computed for model x
, elements will have value NA
.
jagsresults
for subsetting summaries of rjags
,
rjags.parallel
, and mcmc.list
objects.
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 38 | ## Data
N <- 100
temp <- runif(N)
rain <- runif(N)
wind <- runif(N)
a <- 0.13
beta.temp <- 1.3
beta.rain <- 0.86
beta.wind <- -0.44
sd <- 0.16
y <- rnorm(N, a + beta.temp*temp + beta.rain*rain + beta.wind*wind, sd)
dat <- list(N=N, temp=temp, rain=rain, wind=wind, y=y)
### jags example
library(R2jags)
## Model
M <- function() {
for (i in 1:N) {
y[i] ~ dnorm(y.hat[i], sd^-2)
y.hat[i] <- a + beta.temp*temp[i] + beta.rain*rain[i] + beta.wind*wind[i]
resid[i] <- y[i] - y.hat[i]
}
sd ~ dunif(0, 100)
a ~ dnorm(0, 0.0001)
beta.temp ~ dnorm(0, 0.0001)
beta.rain ~ dnorm(0, 0.0001)
beta.wind ~ dnorm(0, 0.0001)
}
## Fit model
jagsfit <- jags(dat, inits=NULL,
parameters.to.save=c('a', 'beta.temp', 'beta.rain',
'beta.wind', 'sd', 'resid'),
model.file=M, n.iter=10000)
## Extract pD and DIC
pd_dic(jagsfit)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.