Hi,
I have encountered a bug in stan_glmer regarding the use of na.action. In contrast to other stanarm functions it is not passed correctly to the final object.
The desired behavior (from lme4::glmer):
require(stanarm)
data(roaches)
roaches$roach1 <- roaches$roach1 / 100
roaches2 <- roaches
roaches2[1, "y"] <- NA
require(lme4)
glmm1 <- glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches, family = poisson)
glmm2 <- glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches2, family = poisson)
attr(glmm1@frame, "na.action")
# NULL
attr(glmm2@frame, "na.action")
# 1
# 1
# attr(,"class")
# [1] "omit"
The current behavior of stan_glmer:
stan_glmm1 <- stan_glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches, family = poisson)
stan_glmm2 <- stan_glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches2, family = poisson)
stan_glmm1$na.action
# [1] "na.omit"
stan_glmm2$na.action
# [1] "na.omit"
I have tracked the bug down, the correct na.action attribute is not passed in the nlist() call in line 135 of stan_glmer.R. After changing this line to
na.action = attr(glmod$fr, "na.action"), contrasts, algorithm, glmod,
the correct behavior is shown:
stan_glmm1 <- stan_glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches, family = poisson)
stan_glmm2 <- stan_glmer(y ~ roach1 + treatment + (1|senior), offset = log(exposure2),
data = roaches2, family = poisson)
stan_glmm1$na.action
# NULL
stan_glmm2$na.action
# 1
# 1
# attr(,"class")
# [1] "omit"
Do you want me to submit a pull request with the correction?
Cheers,
Henrik
PS: At least for stan_glm the correct behavior is shown.