 Dear R-List users,

Can anyone explain exactly the difference between Weights options in lm glm
and gls?

I try the following codes, but the results are different.


> lm1

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)            x
     0.1183       7.3075

> lm2

Call:
lm(formula = y ~ x, weights = W)

Coefficients:
(Intercept)            x
    0.04193      7.30660

> lm3

Call:
lm(formula = ys ~ Xs - 1)

Coefficients:
     Xs      Xsx
0.04193  7.30660

Here ys= y*sqrt(W), Xs<- sqrt(W)*cbind(1,x)

So we can see weights here for lm means the scale for X and y.

But for glm and gls I try

> glm1

Call:  glm(formula = y ~ x)

Coefficients:
(Intercept)            x
     0.1183       7.3075

Degrees of Freedom: 1242 Total (i.e. Null);  1241 Residual
Null Deviance:      1049000
Residual Deviance: 28210        AIC: 7414
> glm2

Call:  glm(formula = y ~ x, weights = W)

Coefficients:
(Intercept)            x
     0.1955       7.3053

Degrees of Freedom: 1242 Total (i.e. Null);  1241 Residual
Null Deviance:      1548000
Residual Deviance: 44800        AIC: 11670
> glm3

Call:  glm(formula = y ~ x, weights = 1/W)

Coefficients:
(Intercept)            x
    0.03104      7.31033

Degrees of Freedom: 1242 Total (i.e. Null);  1241 Residual
Null Deviance:      798900
Residual Deviance: 19900        AIC: 5285

> glm4

Call:  glm(formula = ys ~ Xs - 1)

Coefficients:
   Xs    Xsx
2.687  6.528

Degrees of Freedom: 1243 Total (i.e. Null);  1241 Residual
Null Deviance:      4490000
Residual Deviance: 506700       AIC: 11000

With weights, the glm did not give the same results as lm why?

Also for gls, I use varFixed here.

> gls3
Generalized least squares fit by REML
  Model: y ~ x
  Data: NULL
  Log-restricted-likelihood: -3737.392

Coefficients:
(Intercept)           x
 0.03104214  7.31032540

Variance function:
 Structure: fixed weights
 Formula: ~W
Degrees of freedom: 1243 total; 1241 residual
Residual standard error: 4.004827
> gls4
Generalized least squares fit by REML
  Model: ys ~ Xs - 1
  Data: NULL
  Log-restricted-likelihood: -5500.311

Coefficients:
      Xs      Xsx
2.687205 6.527893

Degrees of freedom: 1243 total; 1241 residual
Residual standard error: 20.20705

We can see the relation between glm and gls with weight as what

I think,  but what's the difference between lm wit gls and glm? why?

Thanks so much.!

Goeland

	[[alternative HTML version deleted]]


