Problem running loo_subsample(), wheras loo() works

Yes, of course.

draws[, c( 1:( dim( draws )[2] )-1 )] corresponds to the posterior draws of mu, that is, mean of the normal distribution from which samples are taken. ( draws[, c( 1:( dim( draws )[2] corresponds to the variance of the normal distribution.)

With [, data_i$x] I use a subset corresponding to the draws for the first, second, …, nth observation (because data_i is a subset of the whole dataset corresponding to the ith observation.

Basically, I borrowed this approach from this topic.

In the meantime, I solved my problem by computing the loglik in the generated quantities block and I defined:

draws = as_draws_matrix( fit$draws( variables=c( "loglik" ) ) )
llfun = function( data_i, draws, log=TRUE) {loglik[, data_i$x]}

However, I will check whether using subset_draws() also solves the problem later when I have time.

Thanks for the reply!

1 Like