Loo_compare issue


I’m running a simple loo_compare and although I can extract the likelihoods for both models, when I run the compare program, I receive an error message

Error: Not all models have the same number of data points.

log_lik_1 <- extract_log_lik(myfit, merge_chains = FALSE) // These two lines are fine
log_lik_2 <- extract_log_lik(myfit2, merge_chains = FALSE)

loo1 <- loo(log_lik_1)                 //  These four lines give me the output
loo2 <- loo(log_lik_2)

comp <- loo_compare(loo1, loo2)                   //  This line gives me the error message

Thank you,


Is the error message correct in noting that the models do not have the same number of data points? If your loo values are based on models with different data, then it is quite possible the comparison will not work, because loo is about the predictive power of the models and I presume should be applied to the same data.

1 Like

Hi JimBob,

Thanks for our reply. The data sources are the same and when I ask for the number of rows of log_lik_1 and log_lik_2 (each models extraced log likelhood) they are the same.


Hi David, the number of rows should be the number of posterior draws not the number of data points. What do you get if you check all the dimensions with dim(log_lik_1) and dim(log_lik_2)?

That was it. Thanks! The two models with different variables also had different amounts of missing data, and the way I handled the missing data gave rise to two different sample sizes.



Ok great, glad you figured it out!