Weighted linear regression in R I am attempting a weighted linear regression in R based on the example given here. My code is:
example <- data.frame(
  X = c(21:15),
  Y = c(17.26, 17.07, 16.37, 16.40, 16.13, 16.17, 15.98),
  W = c(20, 26, 27, 24, 36, 39, 32)
)
lm_ex <- lm(Y ~ X, data = example, weights = W)
summary(lm_ex)

My results are ever so slightly off of theirs. Why?
 A: The results are close and it's different software. With R you get
Call:
lm(formula = Y ~ X, data = example, weights = W)

Weighted Residuals:
      1       2       3       4       5       6       7 
 0.7963  0.9652 -1.6082 -0.3834 -0.8823  0.5881  0.5962 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 12.85626    0.68965  18.642 8.18e-06 ***
X            0.20122    0.03884   5.181  0.00352 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.075 on 5 degrees of freedom
Multiple R-squared:  0.843, Adjusted R-squared:  0.8116 
F-statistic: 26.85 on 1 and 5 DF,  p-value: 0.003521

while the Excel result is

I haven't used Excel for years, but the solution claims to use the following formula to estimate the parameters
=MMULT(MINVERSE(MMULT(TRANSPOSE(DESIGN(A7:A13)),C7:C13*
DESIGN(A7:A13))),MMULT(TRANSPOSE(DESIGN(A7:A13)),C7:C13*B7:B13))

If I understand it correctly, it directly inverses the matrix and uses the vanilla OLS algorithm, so uses an inferior solution that is not used by high-quality statistical software like R. The result you got from R is more trustworthy.
