bug: na.action in stan_g/lmer passed incorrectly

61 views
Skip to first unread message

Henrik Singmann

unread,
Apr 26, 2017, 6:01:49 AM4/26/17
to Stan users mailing list
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"

I have pushed the correction to my fork of the repository: https://github.com/singmann/rstanarm/commit/471474766113d337674609463681fc10774ce36f

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. 

Ben Goodrich

unread,
Apr 26, 2017, 11:20:52 AM4/26/17
to Stan users mailing list
On Wednesday, April 26, 2017 at 6:01:49 AM UTC-4, Henrik Singmann wrote:
Do you want me to submit a pull request with the correction?

Thanks Henrik. I fixed it in commit 6850cd8b.

Ben

Reply all
Reply to author
Forward
0 new messages