William Dunlap
2011-Sep-08 20:45 UTC
[Rd] nobs(lm(...)) != nobs(glm(...)) when there are 0s in weights
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