Error in extract_log_lik from the loo package

Dear all,
I ran my model in the RSTAN as follow.
fit.total06 ← stan(“dependencymodel.stan”,data = da,iter=iter, warmup=warmup, cores =2,chains = 2, thin = 1, init = “random”, control = list(c(adapt_delta = 0.99,max_treedepth = 15)))

Now, When I want to calculate the loo and WAIC from the loo package, I get the following error.
extract_log_lik (fit.total06, parameter_name = “log_lik”, merge_chains = TRUE)

Error is as below:
“”
Error in extract_log_lik(fit.total06, parameter_name = “log_lik”, merge_chains = TRUE) :
could not find function “extract_log_lik”
“”
Could someone help me to solve this problem?

Thank you in advance!

Is the loo package loaded via library(loo)? Alternatively you can do loo::extract_log_lik().

Thanks for your reply. First, I installed the loo package from CRAN and loaded it via library(loo). But, I encountered the following error again.

“”
Error in check_pars(allpars, pars) : no parameter log_lik
“”
Thank you!

extract_log_lik(fit.total06, parameter_name = "log_lik", merge_chains = TRUE) will only work if you have a variable in your model called log_lik. If it’s not called log_lik then you can change the name in the parameter_name argument, but it needs to be able to find the log likelihood values computed in the Stan program. For more info on this check out this vignette in the loo package, which demonstrates how to write a Stan program compatible with loo:

Hope that helps!

Thanks for your detailed explanation and help.

1 Like