calculates the WAIC
WAIC(bayesianOutput, numSamples = 1000, ...)
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 |
The WAIC is constructed as
The lppd (log pointwise predictive density), defined in Gelman et al., 2013, eq. 4 as
The value of can be calculated in two ways, the method used is determined by the
method
argument.
Method 1 is defined as, Method 2 is defined as, where 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.
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.
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)#> [1] -1.418939 -1.418939 -1.418939bayesianSetup$likelihood$density(c(1,1,1), sum = FALSE)#> [1] -1.418939 -1.418939 -1.418939bayesianSetup$likelihood$density(matrix(rep(1,9), ncol = 3), sum = FALSE)#> [,1] [,2] [,3] #> [1,] -1.418939 -1.418939 -1.418939 #> [2,] -1.418939 -1.418939 -1.418939 #> [3,] -1.418939 -1.418939 -1.418939#> Running DEzs-MCMC, chain 1 iteration 300 of 10002 . Current logp -8.435686 -7.89902 -8.224242 . Please wait! Running DEzs-MCMC, chain 1 iteration 600 of 10002 . Current logp -9.623622 -8.0001 -9.358736 . Please wait! Running DEzs-MCMC, chain 1 iteration 900 of 10002 . Current logp -8.210087 -9.184124 -7.869296 . Please wait! Running DEzs-MCMC, chain 1 iteration 1200 of 10002 . Current logp -8.680172 -8.612244 -8.269293 . Please wait! Running DEzs-MCMC, chain 1 iteration 1500 of 10002 . Current logp -9.730421 -8.775348 -8.081375 . Please wait! Running DEzs-MCMC, chain 1 iteration 1800 of 10002 . Current logp -8.270908 -8.957659 -10.43252 . Please wait! Running DEzs-MCMC, chain 1 iteration 2100 of 10002 . Current logp -7.984955 -8.251509 -8.458087 . Please wait! Running DEzs-MCMC, chain 1 iteration 2400 of 10002 . Current logp -7.882363 -7.898614 -9.155126 . Please wait! Running DEzs-MCMC, chain 1 iteration 2700 of 10002 . Current logp -9.426532 -8.327137 -8.185499 . Please wait! Running DEzs-MCMC, chain 1 iteration 3000 of 10002 . Current logp -9.454616 -9.183276 -9.804906 . Please wait! Running DEzs-MCMC, chain 1 iteration 3300 of 10002 . Current logp -9.85258 -8.817787 -8.349674 . Please wait! Running DEzs-MCMC, chain 1 iteration 3600 of 10002 . Current logp -7.963722 -8.886764 -8.318415 . Please wait! Running DEzs-MCMC, chain 1 iteration 3900 of 10002 . Current logp -11.09728 -9.129186 -9.112218 . Please wait! Running DEzs-MCMC, chain 1 iteration 4200 of 10002 . Current logp -7.944314 -12.44574 -9.136989 . Please wait! Running DEzs-MCMC, chain 1 iteration 4500 of 10002 . Current logp -8.305425 -7.936811 -7.953184 . Please wait! Running DEzs-MCMC, chain 1 iteration 4800 of 10002 . Current logp -10.98229 -8.645307 -8.081101 . Please wait! Running DEzs-MCMC, chain 1 iteration 5100 of 10002 . Current logp -8.032454 -8.045189 -9.515575 . Please wait! Running DEzs-MCMC, chain 1 iteration 5400 of 10002 . Current logp -8.120442 -10.54898 -9.443533 . Please wait! Running DEzs-MCMC, chain 1 iteration 5700 of 10002 . Current logp -8.049416 -8.717827 -7.862733 . Please wait! Running DEzs-MCMC, chain 1 iteration 6000 of 10002 . Current logp -8.084893 -8.251851 -9.081135 . Please wait! Running DEzs-MCMC, chain 1 iteration 6300 of 10002 . Current logp -8.073244 -7.974431 -8.079902 . Please wait! Running DEzs-MCMC, chain 1 iteration 6600 of 10002 . Current logp -8.218521 -9.22812 -8.772962 . Please wait! Running DEzs-MCMC, chain 1 iteration 6900 of 10002 . Current logp -8.246165 -8.5875 -8.108148 . Please wait! Running DEzs-MCMC, chain 1 iteration 7200 of 10002 . Current logp -10.74085 -7.880688 -10.23808 . Please wait! Running DEzs-MCMC, chain 1 iteration 7500 of 10002 . Current logp -8.916833 -8.728722 -8.486303 . Please wait! Running DEzs-MCMC, chain 1 iteration 7800 of 10002 . Current logp -8.363117 -8.274794 -8.98649 . Please wait! Running DEzs-MCMC, chain 1 iteration 8100 of 10002 . Current logp -9.306803 -8.630766 -9.00387 . Please wait! Running DEzs-MCMC, chain 1 iteration 8400 of 10002 . Current logp -7.83784 -9.938769 -7.96229 . Please wait! Running DEzs-MCMC, chain 1 iteration 8700 of 10002 . Current logp -10.16324 -8.538351 -8.001384 . Please wait! Running DEzs-MCMC, chain 1 iteration 9000 of 10002 . Current logp -9.678691 -8.667391 -10.28152 . Please wait! Running DEzs-MCMC, chain 1 iteration 9300 of 10002 . Current logp -8.111272 -10.70121 -8.247235 . Please wait! Running DEzs-MCMC, chain 1 iteration 9600 of 10002 . Current logp -8.228964 -9.800455 -12.53619 . Please wait! Running DEzs-MCMC, chain 1 iteration 9900 of 10002 . Current logp -8.535171 -8.331085 -7.84911 . Please wait! Running DEzs-MCMC, chain 1 iteration 10002 of 10002 . Current logp -8.401052 -8.317495 -8.432323 . Please wait!#>WAIC(out)#> $WAIC1 #> [1] 6.345918 #> #> $WAIC2 #> [1] 7.044639 #> #> $lppd #> [1] -2.55475 #> #> $pWAIC1 #> [1] 0.6182095 #> #> $pWAIC2 #> [1] 0.9675698 #>