From nalimilan at club.fr  Tue Feb 19 17:32:05 2013
From: nalimilan at club.fr (Milan Bouchet-Valat)
Date: Tue, 19 Feb 2013 17:32:05 +0100
Subject: [Rd] Small quirks in summary.(g)lm docs
Message-ID: <1361291525.2067.109.camel@milan.ined.fr>

Hi!

In R 3.0.0 from current SVN, ?summary.lm says:
> Value [...]
> df degrees of freedom, a 3-vector (p, n-p, p*), the last
>    being the number of non-aliased coefficients.

?summary.glm says:
> df a 3-vector of the rank of the model and the number of residual 
>    degrees of freedom, plus number of non-aliased coefficients.

It seems to me that the description is reversed: p is the number of
non-aliased coefficients, and p* the total number of coefficients. I do
not have reference books off-hand to check how it is intended to work,
but see this example:

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group + I(group != "Ctl"))
lm.D9

Call:
lm(formula = weight ~ group + I(group != "Ctl"))

Coefficients:
          (Intercept)               groupTrt  I(group != "Ctl")TRUE  
                5.032                 -0.371                     NA  

summary(lm.D9)$df
[1]  2 18  3

sum(!summary(lm.D9)$aliased)
[1] 2


The same is true with glm().


Also, ?summary.lm seems to miss a mention that is present
in ?summary.glm:
> Aliased coefficients are omitted in the returned object but (as from
> R 1.8.0) restored by the print method.

This is apparently true of summary.lm too:

summary(lm.D9)

Call:
lm(formula = weight ~ group + I(group != "Ctl"))

Residuals:
    Min      1Q  Median      3Q     Max 
-1.0710 -0.4938  0.0685  0.2462  1.3690 

Coefficients: (1 not defined because of singularities)
                      Estimate Std. Error t value Pr(>|t|)    
(Intercept)             5.0320     0.2202  22.850 9.55e-15 ***
groupTrt               -0.3710     0.3114  -1.191    0.249    
I(group != "Ctl")TRUE       NA         NA      NA       NA    
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 

Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.07308,	Adjusted R-squared: 0.02158 
F-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249 

summary(lm.D9)$coefficients
            Estimate Std. Error  t value     Pr(>|t|)
(Intercept)    5.032  0.2202177 22.85012 9.547128e-15
groupTrt      -0.371  0.3114349 -1.19126 2.490232e-01


Attached is a patch that applies these changes, if I'm not mistaken (and
my English can be improved...).


Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: summary.patch
Type: text/x-patch
Size: 2117 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20130219/3842ca4c/attachment.bin>


[Rd] Small quirks in summary.(g)lm docs
Milan Bouchet-Valat