[R] d.f. in F test of nested glm models

David Winsemius dwinsemius at comcast.net
Sat Nov 27 04:57:05 CET 2010


On Nov 26, 2010, at 9:30 PM, Jonathan Flowers wrote:

> Dear all,
>
> I am fitting a glm to count data using poison errors with the log  
> link.  My
> goal is to test for the significance of model terms by calling the  
> anova
> function on two nested models following the recommendation in Michael
> Crawley's guide to Statistical Computing.
>
> Without going into too much detail, essentially, I have a small
> overdispersion problem (errors do not fit the poisson assumption) so  
> I am
> following Crawley's recommendation and setting family=quasipoisson  
> and using

> an F test (rather than a chi-square test) to test for significance.
>
> This is working fine, but I cannot figure out how the F value in the
> analysis of deviance table was obtained and what degrees of freedom  
> were
> used to obtain the P value (essentially

Numerator df are the absolute values of differences and the  
denominator df's are the starting point.
 > 1-pf(0.7134, 1, 197)
[1] 0.3993472

Or equivalently:
 > pf(0.7134, 1, 196, lower.tail=FALSE)
[1] 0.3993472

> I don't know how to report the
> result).

Ergo: Time for a statistician.

> The following example (while errors are not overdispersed)
> otherwise generates a comparable analysis of deviance table to my  
> analysis.
> Any help would be much appreciated.
>
> Jonathan
>
> counts <- c(rpois(100,5),rpois(100,20))
> sites <- rep(100,200)
> fac1 <- factor(c(rep("A",100),rep("B",100)))
> fac2 <- factor(c(rep("C",50),rep("D",100),rep("C",50)))
> model1 <- glm(counts ~ fac1 * fac2,family=quasipoisson,  
> offset=log(sites))
> model2 <- glm(counts ~ fac1 + fac2,family=quasipoisson,  
> offset=log(sites))
> anova(model1,model2,test="F")
> Analysis of Deviance Table
>
> Model 1: counts ~ fac1 * fac2
> Model 2: counts ~ fac1 + fac2
>  Resid. Df Resid. Dev  Df Deviance      F Pr(>F)
> 1       196    218.432
> 2       197    219.210  -1   -0.778 0.7134 0.3993
>
> 	[[alternative HTML version deleted]]
>

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list