Skip to content
Prev 22661 / 398502 Next

Why can't Anove (car package) see the data?

Dear Patrick,

It's difficult for me to tell from your description what the specific 
nature of the problem is, though it seems to be some kind of scoping issue.

I've experimented a bit and found that the call to update (indirectly) from 
Anova.glm (with LR type-II tests) seems to cause problems:

     > fun.1 <- function(df){
     +     mod <- glm(partic != 'not.work' ~ hincome + children + region,
     +         data=df, family=binomial)
     +     Anova(mod)
     +     }
     > fun.1(Womenlf)
     Error in eval(expr, envir, enclos) : numeric envir arg not of length one
     > traceback()
     16: eval(predvars, data, env)
     15: model.frame.default(formula = partic != "not.work" ~ children +
             region, data = df, drop.unused.levels = TRUE)
     14: model.frame(formula = partic != "not.work" ~ children + region,
             data = df, drop.unused.levels = TRUE)
     13: eval(expr, envir, enclos)
     12: eval(mf, parent.frame())
     11: glm(formula = partic != "not.work" ~ children + region, family = 
binomial,
             data = df)
     10: eval(expr, envir, enclos)
     9: eval(call, parent.frame())
     8: update.default(mod, eval(parse(text = paste(".~.-", 
paste(c(names[term],
         rels), collapse = "-")))))
     7: update(mod, eval(parse(text = paste(".~.-", paste(c(names[term],
         rels), collapse = "-")))))
     6: Anova.II.LR.glm(mod)
     5: switch(test.statistic, LR = Anova.II.LR.glm(mod), Wald = 
Anova.II.Wald.glm(mod),
         F = Anova.II.F.glm(mod, error, error.estimate))
     4: switch(type, II = switch(test.statistic, LR = Anova.II.LR.glm(mod),
         Wald = Anova.II.Wald.glm(mod), F = Anova.II.F.glm(mod, error,
             error.estimate)), III = switch(test.statistic, LR = 
Anova.III.LR.glm(mod),
         Wald = Anova.III.Wald.glm(mod), F = Anova.III.F.glm(mod,
             error, error.estimate)))
     3: Anova.glm(mod)
     2: Anova(mod)
     1: fun.1(Womenlf)

(This uses the Womenlf data frame in the car package.)

In contrast, Anova.lm, which doesn't call update, works OK:

    > fun.2 <- function(df){
     +     mod <- lm(prestige ~ income + education, data=df)
     +     Anova(mod)
     +     }
     > fun.2(Prestige)
     Anova Table (Type II tests)

     Response: prestige
             Sum Sq Df F value    Pr(>F)
     income    2248.1  1  36.856 2.355e-08
     education 8577.3  1 140.615 < 2.2e-16
     Residuals 6038.9 99
     >

(using the Prestige data frame, again in car.)

I don't see an immediate way around the problem, but I'll think about it. 
In addition, if you send me some more information -- the data that you were 
using, the model that you fit, the function from which you called Anova -- 
I'll take a look a it. I'm leaving town for several days tomorrow. If you 
send me the information before then, I'll take it with me.

I'm sorry that you're experiencing this problem,
  John
At 03:14 PM 8/14/2002 +1200, Patrick Connolly wrote:
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._