WAIC {BayesianTools}R Documentation

calculates the WAIC


calculates the WAIC


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



an object of class BayesianOutput. Must implement a log-likelihood density function that can return point-wise log-likelihood values ("sum" argument).


the number of samples to calculate the WAIC


optional values to be passed on the the getSample function


The WAIC is constructed as

WAIC = -2 * (lppd - pWAIC)

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

lpdd = Σi=1n log 1/S Σs=1S p(yi | Θs)

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

Method 1 is defined as,

pWAIC1 = 2 Σi=1n {log[1/S Σs=1S p(yi | Θs)] - 1/S Σs=1S log p(yi | Θs)}

Method 2 is defined as,
pWAIC2 = 2 Σi=1n Vs=1S[log p(yi | Θs)]

where Vs=1S is the sample variance.


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


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


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)


[Package BayesianTools version 0.1.7 Index]