[R] Question on WLS (gls vs lm)

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jun 24 21:04:47 CEST 2010


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)



More information about the R-help mailing list