[R] R.squared in summary.lm with weights
murdoch.duncan at gmail.com
Fri Apr 8 12:57:27 CEST 2016
On 07/04/2016 5:21 PM, Murray Efford wrote:
> Following some old advice on this list, I have been reading the code for summary.lm to understand the computation of R-squared from a weighted regression. Usually weights in lm are applied to squared residuals, but I see that the weighted mean of the observations is calculated as if the weights are on the original scale:
> f <- z$fitted.values
> w <- z$weights
> m <- sum(w * f/sum(w))
> [mss <-] sum(w * (f - m)^2)
> This seems inconsistent to me. What am I missing?
I think you are expecting consistency where there needn't be any. Why
do you see an inconsistency here? Those are different calculations.
You get expressions like these if you assume observations have variance
sigma^2/w, and you're trying to estimate sigma^2.
More information about the R-help