The dimensions of the log-likelihood matrix are number of posterior draws by number of data points, so this error message could mean that the two models either have a different number of data points or were run for a different number of MCMC iterations. I think you can check this by doing:
dim(log_lik(model1))
dim(log_lik(model2))
If you do that do you get the same or different dimensions?
I checked. Both models were run with “iter=10000, chains=2”. Both models are also using the same data.
However, when I run dim(log_lik(model1)) I get the error:
Error in UseMethod("log_lik") :
no applicable method for 'log_lik' applied to an object of class "c('kfold', 'loo')"
I’m sorry, but I’ve only ever used rstanarm and brms, never really looked under the hood in stan, so is really difficult for me to search for the errors.
I apologize in advance if (as it probably is…) some mistake I’ve made.
According to that error message it thinks that model1 is the output from kfold() but I thought model1 was the output from brm().
But actually now that I check the documentation for brms::loo_model_weights it looks like the input should be the model objects themselves and not the output from kfold, so I’m not sure if using loo_model_weights after kfold is intended to work. Here’s the Examples section from ?brms::loo_model_weights:
# model with population-level effects only
fit1 <- brm(rating ~ treat + period + carry,
data = inhaler, family = "gaussian")
# model with an additional varying intercept for subjects
fit2 <- brm(rating ~ treat + period + carry + (1|subject),
data = inhaler, family = "gaussian")
loo_model_weights(fit1, fit2)
Ok I see what you mean. I think we need to make it easier to get stacking weights after kfold cv. For now, can you see if this works?
# assuming md1LOGO and md2LOGO are the output from kfold()
x <- cbind(md1LOGO$pointwise[, "elpd_kfold"], md2LOGO$pointwise[, "elpd_kfold"])
loo::stacking_weights(x)