[R] Possible bug in summary of residuals with lm and weights

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 28 18:34:45 CEST 2005


On Tue, 28 Jun 2005, Frank E Harrell Jr wrote:

> I sent this to r-devel the other day but didn't get any takers.  This
> may not be a bug but rather an inconsistency.
> I'm not sure if this is intentional.  summary.lm stores weighted
> residuals whereas I think most users will want print.summary.lm to
> summarize unweighted ones as if saying summary(resid(fit)).

It seems no one agreed with you!

I think most users will want S-compatibility here, and after that
residuals that are in some sense on the same scale (that is taking the
weights into account). In short, the status quo.

I suspect no one wants the definition of the "summary.lm" class changed.

There is a bug in the print method, which has

     cat(if (!is.null(x$w) && diff(range(x$w)))
         "Weighted ", "Residuals:\n", sep = "")

so it is intended to say Weighted Residuals, but w is not in a
"summary.lm" object.


>
>> set.seed(1)
>> dat <- data.frame(y = rnorm(15), x = rnorm(15), w = 1:15)
>> f <- lm(y ~ x, weights = w, data = dat)
>> summary(f)
> . . . .
> Residuals:
>    Min     1Q Median     3Q    Max
> -8.260 -1.565  0.117  2.105  4.666
> . . . .
>> resid(f)
>
>           1           2           3           4           5           6
> -0.73429677  0.06818092 -1.20558034  1.25783256  0.05231879 -1.18383039
>           7           8           9          10          11          12
>  0.16034166  0.59880438  0.98337588 -0.58944957  1.40690588  0.31138819
>          13          14          15
> -0.35111933 -2.20770335  0.89438636
>
>> version
> platform i386-pc-linux-gnu
> arch     i386
> os       linux-gnu
> system   i386, linux-gnu
> status
> major    2
> minor    1.0
> year     2005
> month    04
> day      18
> language R
>
> -- 
> Frank E Harrell Jr   Professor and Chair           School of Medicine
>                      Department of Biostatistics   Vanderbilt University
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list