waic: WAIC Calculator

Description Usage Arguments Details Value Examples

View source: R/waic.R

Description

Calculates the WAIC of the fitted object of S4-class stanfit whose stan file is described by only "target += ", which calculates likelihoods with constant terms.

Usage

1
waic(StanS4classwithTargetFormulation, dig = 4, summary = TRUE)

Arguments

StanS4classwithTargetFormulation

This is a fitted model object built by rstan::sampling() whose model block is described by target formulation in the rstan package. This object is avaliable for both S4 classes: stanfit and stanfitExtended.

In this package, the author made a new S4 class named stanfitExtended which is an inherited S4 class of rstan's S4 class called stanfit. This function is also available for a such stanfit S4 object.

dig

The number of significant digits of WAIC.

summary

Logical: TRUE of FALSE. Whether to print the verbose summary. If TRUE then verbose summary is printed in the R console. If FALSE, the output is minimal. I regret, this variable name should be verbose.

Details

WAIC is an abbreviation for Widely Applicable Information Criterion (Watanabe-Akaike Information Criterion)

Value

A real number, representing the value of WAIC of the fitted model object StanS4classwithTargetFormulation.

Revised 2020 Jan, Jul

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## Not run: 
#========================================================================================
#             Model selection based on WAIC
#========================================================================================

# (1) We prepare an example dataset in this package:



        dat  <- get(data("dataList.Chakra.1"))




# (2) Create a fitted model object;


          fit1 <- fit_Bayesian_FROC(dat,
                        ModifiedPoisson = FALSE)


# (3) Using the fitted model object "fit", we can calculate the WAIC of it



                 waic(fit1)


# Fuerthermore,
# the Author provides an another model for a single reader and a single modality case.
# One is false alarm rates means "per lesion" and the other means "per image".
# The above "fit" is "per image".
# Now we shall consider to compare WAIC of these two models
# To do so, next we shall fit the "per lesion" model to the data as follows:



          fit2  <- fit_Bayesian_FROC(dat,
                        ModifiedPoisson = TRUE)

               waic(fit2)



# By compare two model's WAIC we can say which model is better.
# Note that the smaller WAIC is better.



           waic(fit1)     # per lesion model
           waic(fit2)    # per image model




# For the dataset,
# We should select one of the above two models
# by the criteria that the smaller waic is better.
# Namely, if the following inequality


                  waic(fit2) > waic(fit1)



#  is TRUE, then we should use fit1.
# Similary, if the following inequality


                 waic(fit2) < waic(fit1)


#  is TRUE, then we should use fit2.
# 2019.05.21 Revised.
# 2020 Feb Revised.

## End(Not run)# dottest

BayesianFROC documentation built on Jan. 23, 2022, 9:06 a.m.