简体   繁体   中英

heteroscedasticity: weights in lm function in R

I am confused. I have the following model: lm(GAV ~ EMPLOYED). This model has heteroscedasticity, and I believe the error standard deviation of this model can be approximated by a variable called SDL.

I have fitted the corresponding weighted model, resulting after dividing each term by variable SDL, using two forms:

lm(I(GAV/SDL) ~ I(1/SDL) + I(EMPLOYED/SDL)-1) And lm(GAV ~EMPLOYED,weights = 1/SDL)

I thought they would yield the same results. However, I get different parameters estimates...

Can anyone show me the error I am making?

Thanks in advance!

Fede

help("lm") clearly explains:

weighted least squares is used with weights weights (that is, minimizing sum(w*e^2));

So:

x <- 1:10
set.seed(42)
w <- sample(10)
y <- 1 + 2 * x + rnorm(10, sd = sqrt(w))

lm(y ~ x, weights = 1/w)
#Call:
#  lm(formula = y ~ x, weights = 1/w)
#
#Coefficients:
#(Intercept)            x  
#      3.715        1.643  
lm(I(y/w^0.5) ~ I(1/w^0.5) + I(x/w^0.5) - 1)
#Call:
#  lm(formula = I(y/w^0.5) ~ I(1/w^0.5) + I(x/w^0.5) - 1)
#
#Coefficients:
#I(1/w^0.5)  I(x/w^0.5)  
#     3.715       1.643

Btw., you might be interested in library(nlme); help("gls") library(nlme); help("gls") . It offers more sophisticated possibilities for modelling heteroscedasticity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM