stan-dev / loo

loo R package for approximate leave-one-out cross-validation (LOO-CV) and Pareto smoothed importance sampling (PSIS)
https://mc-stan.org/loo
Other
149 stars 34 forks source link

model_weights does not yet seem to work #55

Closed paul-buerkner closed 6 years ago

paul-buerkner commented 6 years ago

I recently updated to the dev version of loo 2.0 (new-psis branch) to prepare brms for its release. I also tried out the new model_weights function, which results in an error. Reproducible example:

library(brms)
fit1 <- brm(rating ~ treat + period, data = inhaler)
fit2 <- brm(rating ~ treat + period + carry, data = inhaler)

ll1 <- log_lik(fit1)
ll2 <- log_lik(fit2)
loo::model_weights(list(ll1, ll2))

"Error in elpd_loo[k] <- L$elpd_loo : replacement has length zero"
yao-yl commented 6 years ago

Hi, Thanks for sharing. It seems I am able to run this code without error on my computer.

library(brms)
fit1 <- brm(rating ~ treat + period, data = inhaler)
fit2 <- brm(rating ~ treat + period + carry, data = inhaler)
ll1 <- log_lik(fit1)
ll2 <- log_lik(fit2)
model_weights(list(ll1, ll2), method="stacking")
The stacking weights are:
     [,1]      [,2]     
[1,] "Model 1" "Model 2"
[2,] "1"       "0"      
[1] 9.999992e-01 8.183364e-07

So it might be the gitHub version problem. I will try to fix it soon. Yuling

paul-buerkner commented 6 years ago

Thanks that would be perfect!

paul-buerkner commented 6 years ago

Will model_weights and model_select be part of the loo 2.0 release? If yes, I would really appreciate you merging the latest version of these functions into the new-psis branch so that I can write wrappes around them for use with brmsfit objects.

yao-yl commented 6 years ago

Yes I believe it will be merged very soon...

yao-yl commented 6 years ago

I have made a pull request and model_weghts() will be there.