Skip to content

loo_R2 can fail on examples where it worked before #263

Description

@bgoodri

The newest loo package seems to be less robust than previous versions when calculating loo_R2. From the NES example,

data("nes", package = "rosdata")
ok <- nes$year==1992 & !is.na(nes$rvote) & !is.na(nes$dvote) & (nes$rvote==1 | nes$dvote==1)
library(rstanarm)
fit_1 <- stan_glm(rvote ~ income, family=binomial(link="logit"), data=nes92, refresh = 0)
loo_R2(fit_1)

This fails with the warning message "Input contains infinite or NA values, Pareto smoothing not performed." and error message "Error: $ operator is invalid for atomic vectors". Neither of these messages is very helpful. The warning results from posterior:::should_return_NA but it is due to the input being within tol of a constant rather than infinite or NA values. The error comes from loo:::.E_loo_khat_i due to the fact that posterior::pareto_khat returns the scalar NA rather than a list in this situation, so trying to select the $khat element fails.

This all worked with loo 2.6.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions