This example shows how to compute approximate loo classification accuracy for binary outcomes. However, I seem not to be savvy enough to replicate that when the response has >2 categories. (I know it’s not the best metric, but my audience will probably want to see it.) Here’s an example of how far I get, using an über-simple example dataset:
Gators <- read.table("http://www.stat.ufl.edu/~aa/cat/data/Alligators.dat", header = TRUE)
require(brms)
mymod.bayes <- brm(y ~ x, data = Gators, family = categorical, prior = prior(normal(0,4), class = b))
myloo <- loo(mymod.bayes, save_psis = TRUE)
preds <- posterior_epred(mymod.bayes)
pred <- colMeans(preds)
loopreds <- E_loo(preds, myloo$psis_object, type = "mean", log_ratios = -log_lik(mymod.bayes))$value
Error in E_loo.default(preds, myloo$psis_object, type = “mean”, log_ratios = -log_lik(mymod.bayes)) : **
** length(x) == dim(psis_object)[1] is not TRUE
Can this actually be done, or are the functions not yet applicable to multicategory responses?