pd_dic: Extract pD and DIC

Description Usage Arguments Value See Also Examples

View source: R/pd_dic.R

Description

A convenience function for extracting the effective number of parameters (pD) and the Deviance Information Criterion (DIC) from an rjags object.

Usage

1
pd_dic(x)

Arguments

x

An rjags or rjags.parallel object.

Value

A list with two elements: pD, and DIC. If these were not computed for model x, elements will have value NA.

See Also

jagsresults for subsetting summaries of rjags, rjags.parallel, and mcmc.list objects.

Examples

 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)

johnbaums/jagstools documentation built on May 19, 2019, 3:03 p.m.