Hi: 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!> version_ platform sparc-sun-solaris2.9 arch sparc os solaris2.9 system sparc, solaris2.9 status major 1 minor 9.0 year 2004 month 04 day 12 language R Yu Shao Wadsworth Center NY Department of Health Albany, NY 12208
Yu Shao wrote:> Hi: > > 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! >Did you look at ?lm.wfit? w: vector of weights (length 'n') to be used in the fitting process for the 'wfit' functions. Weighted least squares is used with weights 'w', i.e., 'sum(w * e^2)' is minimized. So, no, the weights are not normalized. --sundar> > > >>version > > _ > platform sparc-sun-solaris2.9 > arch sparc > os solaris2.9 > system sparc, solaris2.9 > status > major 1 > minor 9.0 > year 2004 > month 04 > day 12 > language R > > > Yu Shao > Wadsworth Center > NY Department of Health > Albany, NY 12208 > > ______________________________________________ > 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
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