[Rd] anova.glm and explicit contrast matrices (PR#1187)

bates@stat.wisc.edu bates@stat.wisc.edu
Thu, 29 Nov 2001 22:13:08 +0100 (MET)


anova.glm does not calculate the degrees of freedom properly when an
explicit contrast has been set on a factor and the contrast has fewer
than (len(levels(thisfactor)) - 1) columns.

> load("/p/stat/course/st849-bates/public/slides/figs/src/viet.rda")
> fm1 <- glm(accuracy ~ proficiency * task + proficiency/learner, viet,
+    family = binomial())
> anova(fm1)
Analysis of Deviance Table

Model: binomial, link: logit

Response: accuracy

Terms added sequentially (first to last)


                      Df Deviance Resid. Df Resid. Dev
NULL                                   5592     4921.9
proficiency            3     69.5      5589     4852.4
task                   4    132.9      5585     4719.5
proficiency:task      12     96.2      5573     4623.4
proficiency:learner    2     35.0      5571     4588.4
> contrasts(viet$proficiency, 1) <- contrasts(viet$proficiency)
> contrasts(viet$proficiency)
          .L
l -0.6708204
m -0.2236068
h  0.2236068
a  0.6708204
> fm2 <- glm(accuracy ~ proficiency * task + proficiency/learner, viet,
+   family = binomial())
> anova(fm2)
Analysis of Deviance Table

Model: binomial, link: logit

Response: accuracy

Terms added sequentially (first to last)


                      Df Deviance Resid. Df Resid. Dev
NULL                                   5592     4921.9
proficiency            3     69.5      5589     4852.4
task                   4    132.9      5585     4719.5
proficiency:task      12     96.2      5573     4623.4
proficiency:learner   -6     13.9      5579     4609.5

The degrees of freedom for proficiency should be 1, for
proficiency:task should be 4 and for proficiency:learner should be 4.

The coefficient count is correct.

--please do not edit the information below--

Version:
 platform = i386-pc-linux-gnu
 arch = i386
 os = linux-gnu
 system = i386, linux-gnu
 status = Under development (unstable)
 major = 1
 minor = 4.0
 year = 2001
 month = 11
 day = 28
 language = R

Search Path:
 .GlobalEnv, package:Devore5, package:ctest, Autoloads, package:base

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._