Learn R Programming

BayesianTools (version 0.1.0)

WAIC: calculates the WAIC

Description

calculates the WAIC

Usage

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

Arguments

bayesianOutput
an object of class BayesianOutput
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 = \sum_{i=1}^n \log \left(\frac{1}{S} \sum_{s=1}^S p(y_i | \theta^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 \sum_{i=1}^{n} (\log (\frac{1}{S} \sum_{s=1}^{S} p(y_i \ \theta^s)) - \frac{1}{S} \sum_{s = 1}^{S} \log p(y_i | \theta^s))$$ Method 2 is defined as, $$p_{WAIC2} = 2 \sum_{i=1}^{n} V_{s=1}^{S} (\log p(y_i | \theta^s))$$ where \(V_{s=1}^{S}\) is the sample variance.

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, http://www.jmlr.org/papers/v11/watanabe10a.html.

See Also

DIC, MAP, marginalLikelihood

Examples

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

# likelihood density needs to have option sum = F

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)

Run the code above in your browser using DataLab