waic: Compute waic

Description Usage Arguments Details Value Examples

View source: R/waic.R

Description

This function computes the waic described in Gelman et al. (2013) information criterion paper for multi-scale occupancy models.

Usage

1

Arguments

msocc_mod

output from msocc_mod

type

one of c(1, 2) denoting the type of penalty to use when calculating the waic

Details

The authors of Gelman et al. (2013) note that the type 2 penalty is a better representation of leave one out cross-validation, and therefore recommend its use.
In the case of hierarchical models, they also note that there are two ways to think the likelihood; one that incorporates the hyper-parameters and one that does not. Both are arguably justifiable depending upon the situation. We do not incorporate the hyper-parameters in our calculations here.

Value

numeric value that is the waic

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
data(fung)

# prep data
fung.detect <- fung %>%
  dplyr::select(1:4)

site.df <- fung %>%
  dplyr::select(-sample, -pcr1, -pcr2) %>%
  dplyr::distinct(site, .keep_all = TRUE) %>%
  dplyr::arrange(site)

sample.df <- fung %>%
  dplyr::select(-pcr1, -pcr2) %>%
  dplyr::arrange(site, sample)

# fit intercept model at all three levels use beta-binomial sampler
fung_mod1 <- msocc_mod(wide_data = fung.detect, progress = T,
                       site = list(model = ~ 1, cov_tbl = site.df),
                       sample = list(model = ~ 1, cov_tbl = sample.df),
                       rep = list(model = ~ 1, cov_tbl = sample.df), # covariates aggregated at sample level
                       num.mcmc = 1000, beta_bin = T)

# model sample level occurence by frog density
fung_mod2 <- msocc_mod(wide_data = fung.detect, progress = T,
                       site = list(model = ~ 1, cov_tbl = site.df),
                       sample = list(model = ~ frogs, cov_tbl = sample.df),
                       rep = list(model = ~ 1, cov_tbl = sample.df),
                       num.mcmc = 1000, beta_bin = T)

# compare
waic(fung_mod1)
waic(fung_mod2)

StrattonCh/msocc documentation built on Dec. 22, 2020, 2:51 a.m.