> log
log type: text
opened on: 28 Sep 2005, 11:05:09
. edit
(3 vars, 4 obs pasted into editor)
- preserve
. set linesize 79
. desmat: poisson count color live
--------------------------------------------------------------------------------
Poisson regression
--------------------------------------------------------------------------------
Dependent variable count
Optimization: ml
Number of observations: 4
Initial log likelihood: -14.328
Log likelihood: -9.540
LR chi square: 9.578
Model degrees of freedom: 2
Pseudo R-squared: 0.334
Prob: 0.008
------------------------------------------------------------------------------------------
nr Effect Coeff s.e.
------------------------------------------------------------------------------------------
count
color
1 Green -0.693** 0.245
live
2 Water 0.241 0.233
3 _cons 3.091** 0.192
------------------------------------------------------------------------------------------
* p < .05
** p < .01
. predict independenc
(option n assumed; predicted number of events)
. rename independenc independence
. tabulate live color [fweight=count]
| Color
live | Blue Green | Total
-----------+----------------------+----------
Lilly | 23 10 | 33
Water | 27 15 | 42
-----------+----------------------+----------
Total | 50 25 | 75
. *This is our actual dataset.
. tabulate live color [fweight= independence]
| Color
live | Blue Green | Total
-----------+----------------------+----------
Lilly | 22 11 | 33
Water | 28 14 | 42
-----------+----------------------+----------
Total | 50 25 | 75
. *This second table is the predicted values under independence.
. *The independence model uses up 3 degrees of freedom
. *The dataset has 4 degrees of freedom
. desmat: poisson count color*live
------------------------------------------------------------------------------------------
Poisson regression
------------------------------------------------------------------------------------------
Dependent variable count
Optimization: ml
Number of observations: 4
Initial log likelihood: -14.328
Log likelihood: -9.417
LR chi square: 9.822
Model degrees of freedom: 3
Pseudo R-squared: 0.343
Prob: 0.020
------------------------------------------------------------------------------------------
nr Effect Coeff s.e.
------------------------------------------------------------------------------------------
count
color
1 Green -0.833* 0.379
live
2 Water 0.160 0.284
color.live
3 Green.Water 0.245 0.497
4 _cons 3.135** 0.209
------------------------------------------------------------------------------------------
* p < .05
** p < .01
. *This is the saturated model.
. *Notice that the interaction term, the only interesting term here is actually the
log odds ratio that we calculated by hand in class one.
. *And also notice that the SE of the log odds ratio is the same as we calculated by hand
. poisgof
Goodness-of-fit chi2 = 7.95e-06
Prob > chi2(0) = .
. *What this means is that the model fits the data exactly, to within the limit
of the software to maximize the likelihood exactly
. *That was a silly experiment, actually, because the saturated model fits the data exactly,
and chisquare tests on zero degrees of freedom don't really make sense.
. *However, goodness of fit does mean something for the independence model.
. desmat: poisson count live
------------------------------------------------------------------------------------------
Poisson regression
------------------------------------------------------------------------------------------
Dependent variable count
Optimization: ml
Number of observations: 4
Initial log likelihood: -14.328
Log likelihood: -13.787
LR chi square: 1.083
Model degrees of freedom: 1
Pseudo R-squared: 0.038
Prob: 0.298
------------------------------------------------------------------------------------------
nr Effect Coeff s.e.
------------------------------------------------------------------------------------------
count
live
1 Water 0.241 0.233
2 _cons 2.803** 0.174
------------------------------------------------------------------------------------------
* p < .05
** p < .01
. desmat: poisson count live color
------------------------------------------------------------------------------------------
Poisson regression
------------------------------------------------------------------------------------------
Dependent variable count
Optimization: ml
Number of observations: 4
Initial log likelihood: -14.328
Log likelihood: -9.540
LR chi square: 9.578
Model degrees of freedom: 2
Pseudo R-squared: 0.334
Prob: 0.008
------------------------------------------------------------------------------------------
nr Effect Coeff s.e.
------------------------------------------------------------------------------------------
count
live
1 Water 0.241 0.233
color
2 Green -0.693** 0.245
3 _cons 3.091** 0.192
------------------------------------------------------------------------------------------
* p < .05
** p < .01
. poisgof
Goodness-of-fit chi2 = .2445188
Prob > chi2(1) = 0.6210
. poisgof, pearson
Goodness-of-fit chi2 = .2435065
Prob > chi2(1) = 0.6217
. *In fact, the way one usually encounters the chisquare test for independence is not
through loglinear models, of course, but just tacked on the bottom of a table with not much
in the way of explanation.
. tabulate live color [fweight=count], chi2 lrchi2
| Color
live | Blue Green | Total
-----------+----------------------+----------
Lilly | 23 10 | 33
Water | 27 15 | 42
-----------+----------------------+----------
Total | 50 25 | 75
Pearson chi2(1) = 0.2435 Pr = 0.622
likelihood-ratio chi2(1) = 0.2445 Pr = 0.621
. exit, clear