stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
389 stars 134 forks source link

posterior_predict() fails for models estimated with family = mgcv::betar #324

Closed bgoodri closed 5 years ago

bgoodri commented 6 years ago

Summary:

posterior_predict() fails for models estimated with family = mgcv::betar. It does not find the eta element of the list.

Description:

https://discourse.mc-stan.org/t/rstanarm-mgcv-betar-family/2947/5?u=bgoodri

We should perhaps think about using the standalone generated quantities feature that is (sort of) in rstan for all the posterior_linpred and posterior_predict stuff.

jgabry commented 5 years ago

It seems that just adding "betareg" as one of the classes of the stanreg object avoids this error:

example(stan_betareg, ask = FALSE)
fake_dat$group <- rep(1:10, each = 20)
fit <- stan_glmer(y ~ x + (1 | group), data = fake_dat, family = mgcv::betar,
                  prior_aux = exponential(2))
class(fit) <- c(class(fit), "betareg")
posterior_predict(fit) # No error

Some internal stuff uses inherits(object, "betareg") sometimes, which works for stan_betareg() but not for stan_glm(family = mgcv::betar). I don't know if doing this is totally safe though as there many be unintended consequences when applying other methods to the object.

jgabry commented 5 years ago

Also, I agree about using standalone GQ if possible. Would take a decent bit of work probably.