STA429/1007 F 2004 Handout 12

Loglinear modelling (Fever and death penalty data)


/*************  dengue.sas ************************
Dengue fever example: NWK data set C.3
**************************************************/

title 'Log-linear on Dengue fever data';
options linesize=79 pagesize=500 noovp formdlim='_';

proc format;  /* value labels used in data step below */
     value agefmt 1 = '12 and under'  2 = '13-29'  3 = '30+';
     value sesfmt 1 = 'High'  2 = 'Middle' 3 = 'Low';
     value ynfmt  0 = 'No'    1 = 'Yes';

data mexico;
     infile 'fever.dat';
     input id age ses sector gotfever savings;
     label ses = 'Socioeconomic Status'
           sector = 'Area of City'
           savgings = 'Have Savings Account';
     if 1 <= age <= 12 then agegrp=1;
        else if 13 <= age <= 29 then agegrp=2;
        else if age >= 30 then agegrp=3;
/*     if savings=2 then err=id; */
     format agegrp agefmt.;
     format ses sesfmt.;
     format gotfever savings ynfmt.;

proc freq;
     title2 'Check to make sure there are no sampling zeros';
     tables agegrp*ses*sector*gotfever / norow nocol nopercent;

     proc freq;
          title2 'First look, to see what we have';
          tables agegrp   * (ses sector gotfever)
                 ses      * (sector gotfever)
                 sector*gotfever / nopercent chisq;


/* Here is a rough summary of the findings

                        agegrp  ses sector  gotfever
                 agegrp    x      .    .     youngLess

                 ses             x  1=low     .

                 sector               x     2=yes

                 gotfever                     x


The first model we will try will have just these relationships -- see
if it fits okay. In bracket notation,

     [agegrp gotfever] [ses sector] [sector gotfever]

Here are the proc catmod syntax rules for loglinear models:
     model    and all the vars, separated by *s = _response_;
     loglin   and all the subsets (items in same brackets) connected by |s;
*/

proc catmod;
     title2 'Model with just selected 2-way relationships';
     model agegrp*ses*sector*gotfever = _response_
           / nodesign noprofile noresponse noparm;
     loglin  agegrp|gotfever ses|sector sector|gotfever;

/* In practice, we never have to fit a saturated model in order to test
goodness of fit because SAS produces the LR test by default. It is being done
here just to verify that this is exactly the test for goodness of fit that SAS
produces. */

proc catmod;
     title2 'Saturated model';
     model agegrp*ses*sector*gotfever = _response_
           / nodesign noprofile noresponse noparm;
     loglin  agegrp|ses|sector|gotfever;

proc iml;
     title2 'Reproduce Goodness of fit LR Chisquare = 10.18 with 24 df';
     G = 1318.5055 - 1308.3252; pval = 1-probchi(G,24);
     print "G = " G ", df = 24, p = " pval;

/* Now test each of the three 2-way relationships with LR tests. Just do the
first here. */

proc catmod;
     title2 'Reduced model for testing agegrp by gotfever';
     model agegrp*ses*sector*gotfever = _response_
           / nodesign noprofile noresponse noparm;
     loglin  agegrp ses|sector sector|gotfever;

proc iml;
     title2 'LR Chisquare for agegrp by gotfever. Compare Wald chisq = 14.08';
     G = 1336.9829 - 1318.5055; pval = 1-probchi(G,2);
     print "G = " G ", df = 2, p = " pval;



_______________________________________________________________________________

                        Log-linear on Dengue fever data                       1
                Check to make sure there are no sampling zeros
                                                11:00 Monday, November 22, 2004

                              The FREQ Procedure

                         Table 1 of sector by gotfever
                 Controlling for agegrp=12 and under ses=High

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |      9 |      1 |     10
                      ---------+--------+--------+
                             2 |      6 |      1 |      7
                      ---------+--------+--------+
                      Total          15        2       17


                         Table 2 of sector by gotfever
                Controlling for agegrp=12 and under ses=Middle

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     10 |      1 |     11
                      ---------+--------+--------+
                             2 |      6 |      1 |      7
                      ---------+--------+--------+
                      Total          16        2       18


                         Table 3 of sector by gotfever
                  Controlling for agegrp=12 and under ses=Low

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     18 |      1 |     19
                      ---------+--------+--------+
                             2 |      5 |      1 |      6
                      ---------+--------+--------+
                      Total          23        2       25


                         Table 4 of sector by gotfever
                     Controlling for agegrp=13-29 ses=High

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     13 |      3 |     16
                      ---------+--------+--------+
                             2 |      8 |      7 |     15
                      ---------+--------+--------+
                      Total          21       10       31


                         Table 5 of sector by gotfever
                    Controlling for agegrp=13-29 ses=Middle

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |      7 |      2 |      9
                      ---------+--------+--------+
                             2 |      2 |      3 |      5
                      ---------+--------+--------+
                      Total           9        5       14


                         Table 6 of sector by gotfever
                     Controlling for agegrp=13-29 ses=Low

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     12 |      6 |     18
                      ---------+--------+--------+
                             2 |      3 |      3 |      6
                      ---------+--------+--------+
                      Total          15        9       24


                         Table 7 of sector by gotfever
                      Controlling for agegrp=30+ ses=High

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |      9 |      3 |     12
                      ---------+--------+--------+
                             2 |      8 |      9 |     17
                      ---------+--------+--------+
                      Total          17       12       29


                         Table 8 of sector by gotfever
                     Controlling for agegrp=30+ ses=Middle

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |      6 |      1 |      7
                      ---------+--------+--------+
                             2 |      4 |      7 |     11
                      ---------+--------+--------+
                      Total          10        8       18


                         Table 9 of sector by gotfever
                      Controlling for agegrp=30+ ses=Low

                      sector(Area of City)
                                gotfever
                      Frequency|No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     11 |      5 |     16
                      ---------+--------+--------+
                             2 |      2 |      3 |      5
                      ---------+--------+--------+
                      Total          13        8       21

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       2
                        First look, to see what we have
                                                11:00 Monday, November 22, 2004

                              The FREQ Procedure

                            Table of agegrp by ses

               agegrp        ses(Socioeconomic Status)

               Frequency    |
               Row Pct      |
               Col Pct      |High    |Middle  |Low     |  Total
               -------------+--------+--------+--------+
               12 and under |     17 |     18 |     25 |     60
                            |  28.33 |  30.00 |  41.67 |
                            |  22.08 |  36.00 |  35.71 |
               -------------+--------+--------+--------+
               13-29        |     31 |     14 |     24 |     69
                            |  44.93 |  20.29 |  34.78 |
                            |  40.26 |  28.00 |  34.29 |
               -------------+--------+--------+--------+
               30+          |     29 |     18 |     21 |     68
                            |  42.65 |  26.47 |  30.88 |
                            |  37.66 |  36.00 |  30.00 |
               -------------+--------+--------+--------+
               Total              77       50       70      197


                     Statistics for Table of agegrp by ses

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     4      4.8988    0.2978
            Likelihood Ratio Chi-Square    4      5.0638    0.2808
            Mantel-Haenszel Chi-Square     1      2.5837    0.1080
            Phi Coefficient                       0.1577
            Contingency Coefficient               0.1558
            Cramer's V                            0.1115

                               Sample Size = 197


                           Table of agegrp by sector

                    agegrp        sector(Area of City)

                    Frequency    |
                    Row Pct      |
                    Col Pct      |       1|       2|  Total
                    -------------+--------+--------+
                    12 and under |     40 |     20 |     60
                                 |  66.67 |  33.33 |
                                 |  33.90 |  25.32 |
                    -------------+--------+--------+
                    13-29        |     43 |     26 |     69
                                 |  62.32 |  37.68 |
                                 |  36.44 |  32.91 |
                    -------------+--------+--------+
                    30+          |     35 |     33 |     68
                                 |  51.47 |  48.53 |
                                 |  29.66 |  41.77 |
                    -------------+--------+--------+
                    Total             118       79      197


                   Statistics for Table of agegrp by sector

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     2      3.3233    0.1898
            Likelihood Ratio Chi-Square    2      3.3146    0.1907
            Mantel-Haenszel Chi-Square     1      3.1106    0.0778
            Phi Coefficient                       0.1299
            Contingency Coefficient               0.1288
            Cramer's V                            0.1299

                               Sample Size = 197


                          Table of agegrp by gotfever

                    agegrp        gotfever

                    Frequency    |
                    Row Pct      |
                    Col Pct      |No      |Yes     |  Total
                    -------------+--------+--------+
                    12 and under |     54 |      6 |     60
                                 |  90.00 |  10.00 |
                                 |  38.85 |  10.34 |
                    -------------+--------+--------+
                    13-29        |     45 |     24 |     69
                                 |  65.22 |  34.78 |
                                 |  32.37 |  41.38 |
                    -------------+--------+--------+
                    30+          |     40 |     28 |     68
                                 |  58.82 |  41.18 |
                                 |  28.78 |  48.28 |
                    -------------+--------+--------+
                    Total             139       58      197


                  Statistics for Table of agegrp by gotfever

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     2     16.3723    0.0003
            Likelihood Ratio Chi-Square    2     18.4774    <.0001
            Mantel-Haenszel Chi-Square     1     14.4765    0.0001
            Phi Coefficient                       0.2883
            Contingency Coefficient               0.2770
            Cramer's V                            0.2883

                               Sample Size = 197


                            Table of ses by sector

                      ses(Socioeconomic Status)
                                sector(Area of City)
                      Frequency|
                      Row Pct  |
                      Col Pct  |       1|       2|  Total
                      ---------+--------+--------+
                      High     |     38 |     39 |     77
                               |  49.35 |  50.65 |
                               |  32.20 |  49.37 |
                      ---------+--------+--------+
                      Middle   |     27 |     23 |     50
                               |  54.00 |  46.00 |
                               |  22.88 |  29.11 |
                      ---------+--------+--------+
                      Low      |     53 |     17 |     70
                               |  75.71 |  24.29 |
                               |  44.92 |  21.52 |
                      ---------+--------+--------+
                      Total         118       79      197


                     Statistics for Table of ses by sector

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     2     11.5803    0.0031
            Likelihood Ratio Chi-Square    2     11.9927    0.0025
            Mantel-Haenszel Chi-Square     1     10.3971    0.0013
            Phi Coefficient                       0.2425
            Contingency Coefficient               0.2356
            Cramer's V                            0.2425

                               Sample Size = 197


                           Table of ses by gotfever

                      ses(Socioeconomic Status)
                                gotfever
                      Frequency|
                      Row Pct  |
                      Col Pct  |No      |Yes     |  Total
                      ---------+--------+--------+
                      High     |     53 |     24 |     77
                               |  68.83 |  31.17 |
                               |  38.13 |  41.38 |
                      ---------+--------+--------+
                      Middle   |     35 |     15 |     50
                               |  70.00 |  30.00 |
                               |  25.18 |  25.86 |
                      ---------+--------+--------+
                      Low      |     51 |     19 |     70
                               |  72.86 |  27.14 |
                               |  36.69 |  32.76 |
                      ---------+--------+--------+
                      Total         139       58      197


                    Statistics for Table of ses by gotfever

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     2      0.2961    0.8624
            Likelihood Ratio Chi-Square    2      0.2977    0.8617
            Mantel-Haenszel Chi-Square     1      0.2819    0.5954
            Phi Coefficient                       0.0388
            Contingency Coefficient               0.0387
            Cramer's V                            0.0388

                               Sample Size = 197


                          Table of sector by gotfever

                      sector(Area of City)
                                gotfever
                      Frequency|
                      Row Pct  |
                      Col Pct  |No      |Yes     |  Total
                      ---------+--------+--------+
                             1 |     95 |     23 |    118
                               |  80.51 |  19.49 |
                               |  68.35 |  39.66 |
                      ---------+--------+--------+
                             2 |     44 |     35 |     79
                               |  55.70 |  44.30 |
                               |  31.65 |  60.34 |
                      ---------+--------+--------+
                      Total         139       58      197


                  Statistics for Table of sector by gotfever

            Statistic                     DF       Value      Prob
            ------------------------------------------------------
            Chi-Square                     1     14.0238    0.0002
            Likelihood Ratio Chi-Square    1     13.8852    0.0002
            Continuity Adj. Chi-Square     1     12.8548    0.0003
            Mantel-Haenszel Chi-Square     1     13.9526    0.0002
            Phi Coefficient                       0.2668
            Contingency Coefficient               0.2578
            Cramer's V                            0.2668


                             Fisher's Exact Test
                      ----------------------------------
                      Cell (1,1) Frequency (F)        95
                      Left-sided Pr <= F          0.9999
                      Right-sided Pr >= F      1.797E-04

                      Table Probability (P)    1.290E-04
                      Two-sided Pr <= P        2.360E-04

                               Sample Size = 197

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       3
                 Model with just selected 2-way relationships
                                                11:00 Monday, November 22, 2004

                             The CATMOD Procedure

                                 Data Summary

     Response           agegrp*ses*sector*gotfev     Response Levels   36
     Weight Variable    None                         Populations        1
     Data Set           MEXICO                       Total Frequency  197
     Frequency Missing  0                            Observations     197


                         Maximum Likelihood Analysis

              Sub         -2 Log  Convergence        Parameter Estimates
Iteration  Iteration  Likelihood    Criterion          1          2          3
------------------------------------------------------------------------------
     0         0       1411.9065       1.0000          0          0          0
     1         0       1327.4244       0.0598    -0.0863     0.0508     0.4112
     2         0       1318.7325     0.006548    -0.3476     0.1630     0.4727
     3         0       1318.5067     0.000171    -0.4024     0.1921     0.5028
     4         0       1318.5055    9.7208E-7    -0.4074     0.1946     0.5052
     5         0       1318.5055    4.623E-11    -0.4074     0.1946     0.5052

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration          4          5          6          7          8          9
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1        0.3198    -0.0914     0.1726    -0.2386     0.1980    -0.2132
       2        0.5100    -0.1859     0.2308    -0.2080     0.0946    -0.2315
       3        0.5632    -0.2136     0.2280    -0.2070     0.0988    -0.2249
       4        0.5682    -0.2161     0.2279    -0.2070     0.0987    -0.2249
       5        0.5682    -0.2161     0.2279    -0.2070     0.0987    -0.2249

                          Maximum Likelihood Analysis

                                    Parameter Estimates
                       Iteration         10           11
                       ---------------------------------
                            0             0            0
                            1       -0.1371       0.3198
                            2       -0.1343       0.2950
                            3       -0.1317       0.2974
                            4       -0.1317       0.2974
                            5       -0.1317       0.2974

                  Maximum likelihood computations converged.


                   Maximum Likelihood Analysis of Variance

              Source               DF   Chi-Square    Pr > ChiSq
              --------------------------------------------------
              agegrp                2         6.92        0.0314
              gotfever              1        28.12        <.0001
              agegrp*gotfever       2        14.08        0.0009
              ses                   2         5.94        0.0514
              sector                1         1.37        0.2424
              ses*sector            2        11.13        0.0038
              sector*gotfever       1        13.44        0.0002

              Likelihood Ratio     24        10.18        0.9938

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       4
                                Saturated model 11:00 Monday, November 22, 2004

                             The CATMOD Procedure

                                 Data Summary

     Response           agegrp*ses*sector*gotfev     Response Levels   36
     Weight Variable    None                         Populations        1
     Data Set           MEXICO                       Total Frequency  197
     Frequency Missing  0                            Observations     197


                         Maximum Likelihood Analysis

              Sub         -2 Log  Convergence        Parameter Estimates
Iteration  Iteration  Likelihood    Criterion          1          2          3
------------------------------------------------------------------------------
     0         0       1411.9065       1.0000          0          0          0
     1         0       1333.0577       0.0558    -0.0863     0.0508     0.1726
     2         0       1309.1189       0.0180    -0.2863     0.1403     0.2158
     3         0       1308.3283     0.000604    -0.3299     0.1690     0.2239
     4         0       1308.3252    2.4154E-6    -0.3312     0.1697     0.2244
     5         0       1308.3252    7.295E-11    -0.3312     0.1697     0.2244

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration          4          5          6          7          8          9
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1       -0.2386    -0.3096     0.1472     0.1929    -0.1726     0.1980
       2       -0.2401    -0.2834     0.1956     0.1625    -0.2084     0.1289
       3       -0.2426    -0.2764     0.2166     0.1486    -0.1989     0.1243
       4       -0.2424    -0.2758     0.2173     0.1483    -0.1994     0.1238
       5       -0.2424    -0.2758     0.2174     0.1483    -0.1994     0.1238

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration         10         11         12         13         14         15
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1        0.1066     0.0609    -0.2132    -0.1371     0.0457     0.0152
       2        0.0597     0.0852    -0.2166    -0.1388     0.1186     0.0639
       3        0.0601     0.0895    -0.2022    -0.1393     0.1193     0.0828
       4        0.0593     0.0900    -0.2019    -0.1390     0.1201     0.0836
       5        0.0593     0.0900    -0.2019    -0.1390     0.1202     0.0836

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration         16         17         18         19         20         21
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1     3.984E-17     0.0609     0.4112     0.3198    -0.0914     0.0305
       2       -0.1017     0.1447     0.4955     0.5278    -0.2379     0.0378
       3       -0.1017     0.1371     0.5089     0.5398    -0.2471     0.0382
       4       -0.1023     0.1371     0.5089     0.5397    -0.2472     0.0386
       5       -0.1023     0.1371     0.5089     0.5397    -0.2472     0.0386

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration         22         23         24         25         26         27
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1       -0.1066    -0.1675     0.0152     0.1523    -0.0305     0.3198
       2      0.001349    -0.1054    -0.0458     0.0993    -0.0390     0.2948
       3      0.004996    -0.0907    -0.0311     0.1001    -0.0551     0.2960
       4      0.005608    -0.0900    -0.0306     0.0997    -0.0555     0.2956
       5      0.005609    -0.0899    -0.0306     0.0997    -0.0555     0.2956

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration         28         29         30         31         32         33
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1       -0.0152  2.456E-17    -0.0305    -0.0457    -0.1371    -0.0761
       2       -0.1062     0.0139    -0.0526     0.0783    -0.0454    -0.1532
       3       -0.1116     0.0109    -0.0497     0.0804    -0.0332    -0.1368
       4       -0.1125     0.0114    -0.0494     0.0811    -0.0323    -0.1365
       5       -0.1125     0.0114    -0.0494     0.0811    -0.0323    -0.1365

                          Maximum Likelihood Analysis

                                    Parameter Estimates
                       Iteration         34           35
                       ---------------------------------
                            0             0            0
                            1        0.1218    3.655E-17
                            2        0.0797       0.0450
                            3        0.0760       0.0267
                            4        0.0756       0.0265
                            5        0.0756       0.0265

                  Maximum likelihood computations converged.


                   Maximum Likelihood Analysis of Variance

          Source                       DF   Chi-Square    Pr > ChiSq
          ----------------------------------------------------------
          agegrp                        2         4.23        0.1205
          ses                           2         3.52        0.1724
          agegrp*ses                    4         2.02        0.7325
          sector                        1         1.50        0.2206
          agegrp*sector                 2         1.40        0.4966
          ses*sector                    2         6.03        0.0490
          agegrp*ses*sector             4         2.06        0.7253
          gotfever                      1        25.36        <.0001
          agegrp*gotfever               2        11.25        0.0036
          ses*gotfever                  2         0.12        0.9394
          agegrp*ses*gotfever           4         0.54        0.9695
          sector*gotfever               1         8.56        0.0034
          agegrp*sector*gotfever        2         0.66        0.7201
          ses*sector*gotfever           2         0.30        0.8598
          agegrp*ses*sector*gotfev      4         0.81        0.9375

          Likelihood Ratio              0          .           .

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       5
           Reproduce Goodness of fit LR Chisquare = 10.18 with 24 df
                                                11:00 Monday, November 22, 2004

                                G                      PVAL

                   G =    10.1803 , df = 24, p =  0.9937627

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       6
                 Reduced model for testing agegrp by gotfever
                                                11:00 Monday, November 22, 2004

                             The CATMOD Procedure

                                 Data Summary

     Response           agegrp*ses*sector*gotfev     Response Levels   36
     Weight Variable    None                         Populations        1
     Data Set           MEXICO                       Total Frequency  197
     Frequency Missing  0                            Observations     197


                         Maximum Likelihood Analysis

              Sub         -2 Log  Convergence        Parameter Estimates
Iteration  Iteration  Likelihood    Criterion          1          2          3
------------------------------------------------------------------------------
     0         0       1411.9065       1.0000          0          0          0
     1         0       1340.6702       0.0505    -0.0863     0.0508     0.1726
     2         0       1336.9981     0.002739    -0.0883     0.0515     0.2309
     3         0       1336.9829    0.0000113    -0.0883     0.0515     0.2279
     4         0       1336.9829     1.67E-10    -0.0883     0.0515     0.2279

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration          4          5          6          7          8          9
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1       -0.2386     0.1980    -0.2132    -0.1371     0.4112     0.3198
       2       -0.2080     0.0943    -0.2317    -0.1343     0.4145     0.2963
       3       -0.2070     0.0987    -0.2249    -0.1317     0.4118     0.2974
       4       -0.2070     0.0987    -0.2249    -0.1317     0.4118     0.2974

                  Maximum likelihood computations converged.


                   Maximum Likelihood Analysis of Variance

              Source               DF   Chi-Square    Pr > ChiSq
              --------------------------------------------------
              agegrp                2         0.74        0.6907
              ses                   2         5.94        0.0514
              sector                1         1.37        0.2424
              ses*sector            2        11.13        0.0038
              gotfever              1        25.77        <.0001
              sector*gotfever       1        13.44        0.0002

              Likelihood Ratio     26        28.66        0.3269

_______________________________________________________________________________

                        Log-linear on Dengue fever data                       7
        LR Chisquare for agegrp by gotfever. Compare Wald chisq = 14.08
                                                11:00 Monday, November 22, 2004

                                 G                     PVAL

                    G =    18.4774 , df = 2, p =  0.0000972



/**************************** deathpen2.sas *********************************/
options linesize=79 pagesize=35 noovp formdlim='_';

title  'Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927';
title2 'Log-linear analysis with sampling zeros';
data deathrow;
     input  deathp $ victrace $ defrace $ numbr;
     label  defrace  = 'Race of Defendant'
            victrace = 'Race of Victim'
            deathp   = 'Death Penalty';
     if numbr=0 then numbr=1.0E-20; /* That's the zero cell freq */
     /* proc catmod assumes all zeros are structural */
     datalines;
               Yes     White     White            19
               Yes     White     Black            11
               Yes     Black     Black             6
               Yes     Black     White             0
               No      White     White           132
               No      White     Black            52
               No      Black     White             9
               No      Black     Black            97
     ;

proc catmod;
     title3 'Test any association among vars with goodness of fit test';
     model deathp*victrace*defrace=_response_
           / nodesign noprofile noresponse noparm;
     loglin deathp victrace defrace;
     weight numbr;

proc catmod;
     title3 'Model with all 2-way relationships';
     model deathp*victrace*defrace=_response_
          / nodesign noprofile noresponse noparm;
     loglin deathp|victrace deathp|defrace victrace|defrace;
     weight numbr;


/* Now test each relationship in turn. Start with deathp|defrace */

proc catmod;
     title3 'Test deathp by defrace';
     model deathp*victrace*defrace=_response_
          / nodesign noprofile noresponse noparm;
     loglin  deathp|victrace victrace|defrace;
     weight numbr;

proc iml;
     title2 'LR Chisquare for deathp by defrace';
     G = 961.76247 - 960.58132; pval = 1-probchi(G,1);
     print "G = " G ", df = 1, p = " pval;

/* Now I'd use this as a new full model and test the other two relationships.*/




_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           1
                    Log-linear analysis with sampling zeros
           Test any association among vars with goodness of fit test
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                                 Data Summary

      Response           deathp*victrace*defrace     Response Levels    8
      Weight Variable    numbr                       Populations        1
      Data Set           DEATHROW                    Total Frequency  326
      Frequency Missing  0                           Observations       8


                         Maximum Likelihood Analysis

              Sub         -2 Log  Convergence        Parameter Estimates
Iteration  Iteration  Likelihood    Criterion          1          2          3
------------------------------------------------------------------------------
     0         0       1355.7959       1.0000          0          0          0
     1         0       1108.0806       0.1827     0.7791    -0.3129     0.0184
     2         0       1098.0538     0.009049     1.0000    -0.3237     0.0184
     3         0       1097.8102     0.000222     1.0418    -0.3237     0.0184
     4         0       1097.8099    2.2821E-7     1.0432    -0.3237     0.0184
     5         0       1097.8099    2.699E-13     1.0432    -0.3237     0.0184

                  Maximum likelihood computations converged.



_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           2
                    Log-linear analysis with sampling zeros
           Test any association among vars with goodness of fit test
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                   Maximum Likelihood Analysis of Variance

              Source               DF   Chi-Square    Pr > ChiSq
              --------------------------------------------------
              deathp                1       139.40        <.0001
              victrace              1        30.82        <.0001
              defrace               1         0.11        0.7397

              Likelihood Ratio      4       137.93        <.0001

_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           3
                    Log-linear analysis with sampling zeros
                      Model with all 2-way relationships
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                                 Data Summary

      Response           deathp*victrace*defrace     Response Levels    8
      Weight Variable    numbr                       Populations        1
      Data Set           DEATHROW                    Total Frequency  326
      Frequency Missing  0                           Observations       8


                          Maximum Likelihood Analysis

                             Sub           -2 Log    Convergence
               Iteration  Iteration    Likelihood      Criterion
               -------------------------------------------------
                    0         0         1355.7959         1.0000
                    1         0         1007.3817         0.2570
                    2         0         966.58695         0.0405
                    3         0         960.82256       0.005964
                    4         0         960.58234       0.000250
                    5         0         960.58132      1.0681E-6
                    6         0         960.58132      3.562E-11

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration          1          2          3          4          5          6
  ---------------------------------------------------------------------------
       0             0          0          0          0          0          0
       1        0.7791    -0.3129    -0.1656     0.0184     0.0307     0.5583

_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           4
                    Log-linear analysis with sampling zeros
                      Model with all 2-way relationships
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                          Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration          1          2          3          4          5          6
  ---------------------------------------------------------------------------
       2        1.0319    -0.5367     0.1184     0.2993     0.0163     0.7490
       3        1.1522    -0.7969     0.2911     0.4564    -0.1057     0.8166
       4        1.1968    -0.8500     0.3278     0.4784    -0.1098     0.8387
       5        1.2000    -0.8540     0.3310     0.4794    -0.1101     0.8395
       6        1.2001    -0.8540     0.3311     0.4794    -0.1101     0.8395

                  Maximum likelihood computations converged.


                   Maximum Likelihood Analysis of Variance

              Source               DF   Chi-Square    Pr > ChiSq
              --------------------------------------------------
              deathp                1       100.06        <.0001
              victrace              1        33.83        <.0001
              deathp*victrace       1         6.50        0.0108
              defrace               1        14.87        0.0001
              deathp*defrace        1         1.21        0.2722
              victrace*defrace      1        77.29        <.0001

              Likelihood Ratio      1         0.70        0.4025

_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           5
                    Log-linear analysis with sampling zeros
                            Test deathp by defrace
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                                 Data Summary

      Response           deathp*victrace*defrace     Response Levels    8
      Weight Variable    numbr                       Populations        1
      Data Set           DEATHROW                    Total Frequency  326
      Frequency Missing  0                           Observations       8


                          Maximum Likelihood Analysis

                              Sub           -2 Log    Convergence
              Iteration    Iteration    Likelihood      Criterion
              ---------------------------------------------------
                   0           0         1355.7959         1.0000
                   1           0         1011.0092         0.2543
                   2           0         966.42214         0.0441
                   3           0         961.92902       0.004649
                   4           0         961.76311       0.000172
                   5           0         961.76247      6.6622E-7
                   6           0         961.76247      1.515E-11

                         Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration            1            2            3            4            5
  --------------------------------------------------------------------------
       0               0            0            0            0            0
       1          0.7791      -0.3129      -0.1656       0.0184       0.5583

_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           6
                    Log-linear analysis with sampling zeros
                            Test deathp by defrace
                                                22:02 Sunday, November 21, 2004

                             The CATMOD Procedure

                         Maximum Likelihood Analysis

                                    Parameter Estimates
  Iteration            1            2            3            4            5
  --------------------------------------------------------------------------
       2          1.0385      -0.5414       0.1306       0.3155       0.7534
       3          1.1347      -0.7481       0.2279       0.3760       0.8130
       4          1.1688      -0.7956       0.2620       0.3904       0.8274
       5          1.1713      -0.7986       0.2645       0.3908       0.8279
       6          1.1714      -0.7986       0.2645       0.3908       0.8279

                  Maximum likelihood computations converged.


                   Maximum Likelihood Analysis of Variance

              Source               DF   Chi-Square    Pr > ChiSq
              --------------------------------------------------
              deathp                1       102.17        <.0001
              victrace              1        33.59        <.0001
              deathp*victrace       1         5.21        0.0225
              defrace               1        17.05        <.0001
              victrace*defrace      1        76.52        <.0001

              Likelihood Ratio      2         1.88        0.3903

_______________________________________________________________________________

           Race & Death Penalty:  Am. Soc. Review 1981, 46, 918-927           7
                      LR Chisquare for deathp by defrace
                                                22:02 Sunday, November 21, 2004

                                 G                     PVAL

                    G =    1.18115 , df = 1, p =   0.277122