June 2007
Beginner to intermediate
950 pages
27h 8m
English
The data on red blood cell counts were introduced on p. 187. Here we read similar count data from a file:
data<-read.table("c:\\temp\\bloodcells.txt",header=T) attach(data) names(data) [1] "count"
Now we need to create a vector for gender containing 5000 repeats of ‘female’ and then 5000 repeats of ‘male’:
gender<-factor(rep(c("female","male"),c(5000,5000)))
The idea is to test the significance of the difference in mean cell counts for the two genders, which is slightly higher in males than in females:
tapply(count,gender,mean)
female male
1.1986 1.2408
We begin with the simplest log-linear model – a GLM with Poisson errors:
model<-glm(count~gender,poisson) summary(model)
You should check for overdispersion before drawing any conclusions about the significance of the gender effect. It turns out that there is substantial overdispersion (scale parameter = 23 154/9998 = 2.315 863), so we repeat the modelling using quasi-Poisson errors instead:
model<-glm(count~gender,quasipoisson) summary(model) Call: glm(formula = count ~ gender, family = quasipoisson) Deviance Residuals: Min 1Q Median 3Q Max -1.5753 -1.5483 -1.5483 0.6254 7.3023 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.18115 0.02167 8.360 <2e-16 *** gendermale 0.03460 0.03038 1.139 0.255 (Dispersion parameter for quasipoisson family taken to be 2.813817) Null deviance: 23158 on 9999 degrees of freedom Residual deviance: 23154 on 9998 degrees of ...
Read now
Unlock full access