# Re: [R] Question on WLS (gls vs lm)

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 24 Jun 2010 15:04:47 -0400

On Thu, Jun 24, 2010 at 9:20 AM, Viechtbauer Wolfgang (STAT) <Wolfgang.Viechtbauer_at_stat.unimaas.nl> wrote:
> The weights in 'aa' are the inverse standard deviations. But you want to use the inverse variances as the weights:
>
> aa <- (attributes(summary(f1)\$modelStruct\$varStruct)\$weights)^2
>
> And then the results are essentially identical.
>

We might now ask how we might have found Wolfgang's answer via calculation. Lets redo the gls calculation of variance from scratch by iterated re-weighted least squares (just one iteration here) and compare that to the gls aa calculated by the original poster:

# estimate beta
fm <- lm(Petal.Width ~ Species / Petal.Length, iris)

# estimate variance
v <- fitted(lm(resid(fm)^2 ~ Species, iris)) v <- v/v[1]

# compare to aa from original poster
lm(log(aa) ~ log(v))

The last line gives:

(Intercept) log(v)
-4.212e-07 -5.000e-01

which suggsts: aa = 1/sqrt(variance)

R-help_at_r-project.org 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 Thu 24 Jun 2010 - 19:06:49 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 Thu 24 Jun 2010 - 19:30:34 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.