![]() |
|
![]() | |||
|
|
|||||
In this section we illustrate the use of Stata's
poisson command to
fit log-linear models to contingency tables.
We start with a two-way table, namely the data on cholesterol and heart disease in Section 5.1 of the lecture notes. Let us read in the four counts with suitable markers for the rows and columns. I will use strings to represent the categories of cholesterol and heart disease.
. input str4 chol str4 hdis n
chol hdis n
1. low yes 51
2. low no 992
3. high yes 41
4. high no 245
5. end
To fit the model of independence of cholesterol and heart disease we treat the four counts as Poisson observations and fit an additive model. Here are the necessary dummy variables and the fit:
. gen hichol = chol == "high"
. gen heartdis = hdis == "yes"
. quietly poisson n hichol heartdis
. poisgof
Goodness-of-fit chi2 = 26.43064
Prob > chi2(1) = 0.0000
The model's deviance or goodness of fit chi-squared is 26.43 on 1 df, as noted on the lecture notes. Let us get the fitted values:
. predict mu (option n assumed; predicted number of events)
Note that using predict after a
Poisson regression calculates the fitted counts.
Pearson's chi-squared statistic can be obtained using
the glm command or from first principles as
. gen Pearson = sum( (n-mu)^2/mu ) . display "Pearson's chi2 = " Pearson[_N] Pearson's chi2 = 31.081829
Continue with 5.2 Models for Three-dimensional Tables
Copyright © Germán Rodríguez, 1993-2003.
Please send feedback to grodri@princeton.edu