# WAIC: calculates the WAIC In BayesianTools: General-Purpose MCMC and SMC Samplers and Tools for Bayesian Statistics

 WAIC R Documentation

## calculates the WAIC

### Description

calculates the WAIC

### Usage

WAIC(bayesianOutput, numSamples = 1000, ...)

### Arguments

 bayesianOutput an object of class BayesianOutput. Must implement a log-likelihood density function that can return point-wise log-likelihood values ("sum" argument). numSamples the number of samples to calculate the WAIC ... optional values to be passed on the the getSample function

### Details

The WAIC is constructed as

WAIC = -2 * (lppd - p_{WAIC})

The lppd (log pointwise predictive density), defined in Gelman et al., 2013, eq. 4 as

lppd = ∑_{i=1}^n \log ≤ft(\frac{1}{S} ∑_{s=1}^S p(y_i | θ^s)\right)

The value of p_WAIC can be calculated in two ways, the method used is determined by the method argument.

Method 1 is defined as,

p_{WAIC1} = 2 ∑_{i=1}^{n} (\log (\frac{1}{S} ∑_{s=1}^{S} p(y_i \ θ^s)) - \frac{1}{S} ∑_{s = 1}^{S} \log p(y_i | θ^s))

Method 2 is defined as,

p_{WAIC2} = 2 ∑_{i=1}^{n} V_{s=1}^{S} (\log p(y_i | θ^s))

where V_{s=1}^{S} is the sample variance.

### Note

The function requires that the likelihood passed on to BayesianSetup contains the option sum = T/F, with defaul F. If set to true, the likelihood for each data point must be returned.

Florian Hartig

### References

Gelman, Andrew and Jessica Hwang and Aki Vehtari (2013), "Understanding Predictive Information Criteria for Bayesian Models," http://www.stat.columbia.edu/~gelman/research/unpublished/waic_understand_final.pdf.

Watanabe, S. (2010). "Asymptotic Equivalence of Bayes Cross Validation and Widely Applicable Information Criterion in Singular Learning Theory", Journal of Machine Learning Research, https://www.jmlr.org/papers/v11/watanabe10a.html.

DIC, MAP, marginalLikelihood

### Examples

bayesianSetup <- createBayesianSetup(likelihood = testDensityNormal,
prior = createUniformPrior(lower = rep(-10,2),
upper = rep(10,2)))

# likelihood density needs to have option sum = FALSE

testDensityNormal(c(1,1,1), sum = FALSE)
bayesianSetup$likelihood$density(c(1,1,1), sum = FALSE)
bayesianSetup$likelihood$density(matrix(rep(1,9), ncol = 3), sum = FALSE)

# running MCMC

out = runMCMC(bayesianSetup = bayesianSetup)

WAIC(out)

BayesianTools documentation built on Feb. 16, 2023, 8:44 p.m.