rvhulst / evidence

Site of the R-package evidence for Bayesian statistical inference.
0 stars 0 forks source link

Compatibility with upcoming loo package update #1

Open jgabry opened 6 years ago

jgabry commented 6 years ago

Hi @rvhulst ,

As I mentioned in the email I sent we will be releasing a major update to the loo package (this week I hope) and I wanted to follow up and give you a bit more detail specific to your package. When checking the evidence package compatibility with the new loo package I get:

checking examples ... ERROR
Running examples in ‘evidence-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: looicplot
> ### Title: A dot plot is produced for several related models showing for
> ###   each model its LOOIC-value with its credible interval.
> ### Aliases: looicplot
> 
... 313 lines ...
               0.072735 seconds (Sampling)
               0.152936 seconds (Total)

> looicplot(looiclist=list(Mbudworm1, Mbudworm2, Mbudworm3),
+          modnames=c("~ ldose", "~ ldose + sex", "~ ldose * sex"),
+          perc=90)
Warning in ic[i] <- qq[[i]][[3]] :
  number of items to replace is not a multiple of replacement length
Error in qq[[i]][[6]] : subscript out of bounds
Calls: looicplot
Execution halted

This is almost certainly happening because the structure of the objects returned by loo has changed slightly to accommodate some of the new features. I believe you only need to change this part inside looicplot:

    for (i in 1:n) {
        model[i] <- modnames[i]
        ic[i] <- qq[[i]][[3]]
        se[i] <- qq[[i]][[6]]
        upr[i] <- ic[i] - se[i] * qnorm((100 - perc)/100)
        lwr[i] <- ic[i] + se[i] * qnorm((100 - perc)/100)
    }

The new loo objects will have a component estimates which is a matrix from which you can pull the required info. For example, if loo_obj is the result from a call to loo then loo_obj$estimates will be a matrix like this:

           Estimate       SE
elpd_loo -83.614057 4.289943
p_loo      3.353629 1.159908
looic    167.228115 8.579885

I'll send out a follow-up email to my previous one once the loo update is up on CRAN. In the meantime it's now available from the master branch at stan-dev/loo on GitHub if you want to install it.

jgabry commented 6 years ago

@rvhulst Just following up to let you know that the loo package update is now on CRAN, so you can go ahead and submit an update to evidence.