[R] Issue with subset in glm
Ganz, Carl
carlganz at ucla.edu
Tue Mar 21 16:50:12 CET 2017
Hello,
I am experiencing odd behavior with the subset parameter for glm. It appears that the parameter uses non-standard evaluation, but only in some cases. Below is a reproducible example.
library(survey) # for example dataset
data(api)
stype <- "E"
(a <- glm(api00~ell+meals+mobility, data = apistrat,
subset = apistrat$stype == stype))
(b <- glm(api00~ell+meals+mobility, data = apistrat,
subset = apistrat$stype == "E"))
# should be equal since stype = "E" but they aren't
coef(a)==coef(b)
# for some reason works as expected here
i = 4
(c <- glm(mpg ~ wt, data = mtcars, subset = mtcars$cyl==i))
(d <- glm(mpg ~ wt, data = mtcars, subset = mtcars$cyl==4))
coef(c)==coef(d)
I can't really explain what is happening so I would appreciate help.
Kind Regards,
Carl Ganz
More information about the R-help
mailing list