# Weighted Linear Regression R

Can anyone expalin to me in simple terms what happens when we use weights in regsubsets or lm in R? What effect do weights have on a linear regression? for example :

Model1<-lm(Ozone~Solar.R,data=airquality)
summary(Model1)
#Coefficients:
#            Estimate Std. Error t value Pr(>|t|)
#(Intercept) 18.59873    6.74790   2.756 0.006856 **
#Solar.R      0.12717    0.03278   3.880 0.000179 ***
Model1<-lm(Ozone~Solar.R,data=airquality,weights=(2*seq(nrow(airquality),1,-1)))
summary(Model1)
#Coefficients:
#            Estimate Std. Error t value Pr(>|t|)
#(Intercept) 18.57106    6.26067   2.966 0.003704 **
#Solar.R      0.10824    0.02927   3.699 0.000341 ***


please explain the changes in intercepts and slope.

• This is not a SO question -- what you're asking is how linear regression w/ or w/o weights works. But the simple answer: assigning weights is equivalent to adding more data points where you think the values are more reliable. Mar 21 '14 at 11:30
• @CarlWitthoft that's not strictly true as the type of weighting used by R does't affect the df of the t-distribution. Mar 21 '14 at 14:36
• @hadley fair enough. I prob'ly should have written "sorta kinda like" instead of "equivalent to" . Mar 21 '14 at 16:15

Ordinary least squares minimizes the sum of squared residuals (residual = measured value - fitted value). Weighted least squares weights the sqared residuals. From help("lm"):
weighted least squares is used with weights weights (that is, minimizing sum(w*e^2))