[R] Weighted regresion using lm

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Oct 28 21:49:47 CEST 2004


On Thu, 28 Oct 2004, Yu Shao wrote:

> Could anyone help me to clarify this: are the weights normalized inside lm 
> function (package:stats) before applied to the error term?  For example:
> 
> >lm (cost ~ material, weights=quatity, data=receipt)
> 
> will lm normalize quatity such that sum(quatity) = 1? I traced to lm.wfit and 
> then the weights get transferred into a precompiled FORTRAN module so I can't 
> figure out. Thanks!

Yes you can, as you have the sources and the documentation.  (R is Open 
Source.)  You could also do a simple experiment like that below.

Weighted regression is not defined to use normalized weights, and this is
not done in R.  Note, though, that the fit and the coefficients are the
same whether you normalize or not.

y <- rnorm(100)
x <- runif(100)
w <- 1:100
w1 <- w/sum(w)
(fm <- lm(y ~x, weights=w))
(fm1 <- lm(y ~x, weights=w1))
summary(fm)
summary(fm1)

show that only the residual se and the residuals are affected.


-- 
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