[Rd] nobs(lm(...)) != nobs(glm(...)) when there are 0s in weights

From: William Dunlap <wdunlap_at_tibco.com>
Date: Thu, 08 Sep 2011 20:45:49 +0000


What is the rationale for nobs.lm omitting observations with zero weights while nobs.glm includes them?

> df <- data.frame(x1=log(1:10), x2=1/(1:10), y=1:10, wt=c(0,2,0,4,0,6,7,8,9,10))
> nobs(lm(data=df, y~x1+x2, weights=wt))
[1] 7
> nobs(glm(data=df, y~x1+x2, weights=wt))
[1] 10

The anova methods for lm and glm seem to agree on the number of degrees of freedom here, although anova.glm issues a message about it:

> anova(lm(data=df, y~x1+x2, weights=wt))
Analysis of Variance Table

Response: y

          Df  Sum Sq Mean Sq  F value    Pr(>F)    
x1         1 196.682 196.682 1034.648 5.569e-06 ***
x2         1  11.514  11.514   60.572   0.00147 ** 
Residuals  4   0.760   0.190                       
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

> anova(glm(data=df, y~x1+x2, weights=wt))
Analysis of Deviance Table Model: gaussian, link: identity Response: y Terms added sequentially (first to last) Df Deviance Resid. Df Resid. Dev NULL 6 208.957 x1 1 196.682 5 12.275 x2 1 11.514 4 0.760 Warning message: In summary.glm(object, dispersion = dispersion) : observations with zero weight not used for calculating dispersion Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com ______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 08 Sep 2011 - 20:47:06 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Fri 09 Sep 2011 - 08:40:28 GMT.

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

list of date sections of archive