Starting from:

$35

BSDA-Homework 8 Solved

Model assessment: LOO-CV for factory data with Stan

Use leave-one-out cross-validation (LOO-CV) to assess the predictive performance of the pooled, separate and hierarchical Gaussian models for the factory dataset (see the second exercise in Assignment 7). To read in the data, just use:

library(bsda) data("factory")

PSIS-LOO is a recently developed method for approximating the exact LOO and is thus not in BDA3. For more information, see the original paper here or here.

Use Stan for tting the models, and the loo R package for computing the approximate LOO-CV given the posterior samples provided by Stan. You can install the package as

install.packages("loo")

Python users can use PSIS-LOO implementation in ArviZ library. The report should include the following parts.

1.    Fit the models with Stan as instructed in Assignment 7. To use the loo or psisloo functions, you need to compute the log-likelihood values of each observation for every posterior draw (i.e. an S-by-N matrix, where S is the number of posterior draws and N = 30 is the total number of observations). This can be done in the generated quantities block in the Stan code.

2.    Compute the PSIS-LOO elpd values and the kˆ-values for each of the three models. Hint! It will be convenient to visualize the kˆ-values for each model so that you can easily see how many of these values fall in the range k >ˆ 0.7 to assess the reliability of the PSIS-LOO estimate for each model. You can read more about the theoretical guarantees for the accuracy of the estimate depending on kˆ from the original article (see here or here), but regarding this assignment, it su ces to understand that if all the kˆ-values are kˆ ≲ 0.7, the PSIS-LOO estimate can be considered to be reliable, otherwise there is a concern that it may be biased (too optimistic, overestimating the predictive accuracy of the model).

3.    Compute the e ective number of parameters pe for each of the three models. Hint! The estimated e ective number of parameters in the model can be computed from equation (7.15) in the book, where elpdloo-cv is the PSIS-LOO value (sum of the LOO log densities) and lpd is given by equation (7.5) in the book.

4.    Assess how reliable the PSIS-LOO estimates are for the three models based on the kˆ-values.

5.    An assessment of whether there are di erences between the models with regard to the elpdloo-cv, and if so, which model should be selected according to PSIS-LOO.

6.    Both the Stan and R code should be included in your report.

More products