[R] Weighted least squares

Ming Hsu hsu at charter.net
Tue Jan 18 01:29:45 CET 2005


Hi,

I would like to run a weighted least squares with the the weighting matrix
W.  I ran the following two regressions,

(W^-1)Y = Xb + e
Y = WXb+ We

In both cases, E[bhat] = b.

I used the following commands in R

lm1 <- lm(Y/W ~ X)
lm2 <- lm(Y ~ W:X, weights = W)

where 

Y <- rnorm(10,1)
X <- Y + rnorm(10,1)
W <- 1:10

In lm2, I believe W is applied to the error term, resulting in WLS.  However
the estimated coefficients in lm1 and lm2 are really different.  I tried glm
as well, but the result was the same as lm.

Any advice would be appreciated,

Hsu Ming




More information about the R-help mailing list