Department of Statistics: Course Stats 330
Department of Statistics: Course Stats 330
Department of Statistics: Course Stats 330
COURSESTATS330
ModelanswersforAssignment5,2007
Question1
1. TypethedataintoRandconstructadataframesuitableforfittingloglinearmodels.
Printoutthedataframe.[5marks]
2. Fitasuitableloglinearmodeltothedata.Arethereanycellsthatarenotfittedwellby
themodel?[5marks]
Ifwefitthesaturatedmodelanddoananova,weobtain
1
This suggests that the threeway interaction term is not significant, and that the
homogeneous association model is appropriate for thesedata. Fitting this model, and using
thesummaryfunction,weget
Call:
glm(formula = counts ~ (Ejected + Seatbelt + Injury)^2, family = poisson,
data = accident.df)
Deviance Residuals:
1 2 3 4 5 6 7 8
0.20704 -0.01071 -0.10095 0.01731 -1.59987 0.31400 0.30951 -0.21583
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 7.00137 0.02992 233.99 <2e-16 ***
EjectedNo 5.92527 0.02996 197.76 <2e-16 ***
SeatbeltNo 1.43913 0.03321 43.33 <2e-16 ***
InjuryFatal -3.96315 0.06944 -57.07 <2e-16 ***
EjectedNo:SeatbeltNo -2.39964 0.03334 -71.97 <2e-16 ***
EjectedNo:InjuryFatal -2.79779 0.05526 -50.63 <2e-16 ***
SeatbeltNo:InjuryFatal 1.71732 0.05402 31.79 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
NoneoftheDevianceresidualsarelarge,indicatingthatallcellsarereasonablywellfitted.
3. Compute the conditional odds ratio between seatbelt use and injury, conditional on
Ejected.Dotheseoddsratiosdependonbeingejectedfromthecar?Whateffectdoes
seatbeltusehaveonthetypeofinjury?Alsocomputea95%confidenceintervalforthe
conditionaloddsratio.[10marks]
ThehomogeneousassociationmodelimpliesthattheoddsratiosbetweenInjuryandSeatbelt
in the separate tables for Eject = yes and Eject=No are the same, ant that the logodds
ratioisthecoefficientfortheSeatbeltInjuryinteraction.Theestimatedcoefficientis1.71732,
so the odds ratio in both tables is exp(1.71732) = 5.569582. Thus, the odds of an accident
being fatal are about 5 and a half times more if a seat belt is not worn. A 95% confidence
intervalisobtainedby
2
> exp(confint(ham.glm))
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) 1.034985e+03 1.163800e+03
EjectedNo 3.532271e+02 3.972509e+02
SeatbeltNo 3.952975e+00 4.502698e+00
InjuryFatal 1.656784e-02 2.175183e-02
EjectedNo:SeatbeltNo 8.497287e-02 9.683767e-02
EjectedNo:InjuryFatal 5.472342e-02 6.796101e-02
SeatbeltNo:InjuryFatal 5.013605e+00 6.196228e+00
Q2.Thefollowingcodemakesthedataframeandplotstherelativefrequenciesofthe
variousmonthsseparatelyformalesandfemales:
counts = scan()
3755 3251 3777 3706 3717 3660 3669 3626 3481 3590 3650 3392
1362 1244 1496 1452 1448 1376 1370 1301 1337 1351 1416 1226
heights = matrix(counts, 2,12, byrow=T)
relheights = heights/apply(heights, 1, sum)
barplot(relheights, beside=T, legend.text = T, ylim=c(0,0.12))
0.12
Male
Female
0.10
0.08
0.06
0.04
0.02
0.00
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
3
Weseefromthegraphthatthedistributionoverthemonthsissimilarformalesand
females.However,themonthsseemtodiffer:thereisadipinDecemberandFebrurary,
andapeakinMarch.
Aretheseobserveddifferencesduetochance?Wecanseeifthedistributionsarethe
sameformalesandfemalesbytestingifgenderandmonthareindependent,or,
alternativelyiftheinteractionsarezerointhePoissonmodel.Weget
> suicide.df = data.frame(counts=counts, expand.grid(month= c("Jan",
"Feb", "Mar", "Apr", "May", "Jun", "Jul",
+ "Aug", "Sep", "Oct", "Nov", "Dec"), sex=c("Male","Female")))
>
> anova(glm(counts~month*sex, data=suicide.df, family=poisson),
test="Chisq")
Analysis of Deviance Table
Model: poisson, link: log
Response: counts
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev P(>|Chi|)
NULL 23 12704.5
month 11 118.4 12 12586.2 3.886e-20
sex 1 12574.2 11 12.0 0.0
month:sex 11 12.0 0 4.441e-14 0.4
Thepvaluecorrespondingtoadevianceof12.0in11dfis0.3636indicatingthatthe
distributionsarethesameforbothsexes.However,themodelwithgenderalonehasa
devianceof130.35on22df,correspondingtoapvalueof0.000,sothatthereisa
significantdifferencebetweenthemonths.