[R] Weighted least squares
S Ellison
S.Ellison at lgc.co.uk
Tue May 8 19:21:21 CEST 2007
Hadley,
You asked
> .. what is the usual way to do a linear
> regression when you have aggregated data?
Least squares generally uses inverse variance weighting. For aggregated data fitted as mean values, you just need the variances for the _means_.
So if you have individual means x_i and sd's s_i that arise from aggregated data with n_i observations in group i, the natural weighting is by inverse squared standard error of the mean. The appropriate weight for x_i would then be n_i/(s_i^2). In R, that's n/(s^2), as n and s would be vectors with the same length as x. If all the groups had the same variance, or nearly so, s is a scalar; if they have the same number of observations, n is a scalar.
Of course, if they have the same variance and same number of observations, they all have the same weight and you needn't weight them at all: see previous posting!
Steve E
*******************************************************************
This email and any attachments are confidential. Any use, co...{{dropped}}
More information about the R-help
mailing list