From: hadley wickham <h.wickham_at_gmail.com>

Date: Wed, 09 May 2007 08:22:26 +0200

R-help_at_stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 May 2007 - 06:31:23 GMT

Date: Wed, 09 May 2007 08:22:26 +0200

On 5/9/07, Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk> wrote:

> http://en.wikipedia.org/wiki/Weighted_least_squares gives a formulaic

*> description of what you have said.
*

Except it doesn't describe what I think is important in my case - how do you calculate the degrees of freedom/n for weighted linear regression?

> I believe the original poster has converted something like this

*>
**> y x
**> 0 1.1
**> 0 2.2
**> 0 2.2
**> 0 2.2
**> 1 3.3
**> 1 3.3
**> 2 4.4
**> ...
**>
**> into something like the following
**>
**> y x freq
**> 0 1.1 1
**> 0 2.2 3
**> 1 3.3 2
**> 2 4.4 1
**> ...
*

Exactly! Thanks for providing that example.

*>
*

> Now, the variance of means of each row in table above is ZERO because

*> the individual elements that comprise each row are identical. Therefore
**> your method of using inverse-variance will not work here.
**>
**> Then is it valid then to use lm( y ~ x, weights=freq ) ?
**>
**> Regards, Adai
**>
**>
**>
**> S Ellison wrote:
**> > 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}}
**> >
**> > ______________________________________________
**> > R-help_at_stat.math.ethz.ch mailing list
**> > https://stat.ethz.ch/mailman/listinfo/r-help
**> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
**> > and provide commented, minimal, self-contained, reproducible code.
**> >
**> >
**> >
**>
**>
*

R-help_at_stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 May 2007 - 06:31:23 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Wed 09 May 2007 - 07:31:24 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*