next up previous
Next:

SAS for Chi-Squared and Measures of Association with Table 3.2

-----------------------------------------------------------------------------
data table;
    input degree religion $ count ;
datalines;
1 fund 178  
1 mod 138  
1 lib 108
2 fund 570  
2 mod 648  
2 lib 442
3 fund 138  
3 mod 252  
3 lib 252
  ;    
proc freq  order=data; weight count;
  tables degree*religion / chisq expected measures cmh1;
proc genmod  order=data;  class degree religion;
    model count = degree religion / dist=poi link=log residuals;
-----------------------------------------------------------------------------

SAS for Fisher's Exact Test and Confidence Intervals for Odds Ratio for Table 3.8

-----------------------------------------------------------------------------
data fisher;
input poured guess count ;
datalines;
1 1 3    
1 2 1    
2 1 1    
2 2 3
;
proc freq;  weight count;
   tables poured*guess / measures riskdiff;
   exact fisher or / alpha=.05;
proc logistic descending;  freq count;
    model guess = poured / clodds=pl;
-----------------------------------------------------------------------------

SAS for Binary GLMs for Snoring Data in Table 4.2

-------------------------------------------------------------------------
data glm;
input snoring disease total ;
datalines;
0 24 1379    
2 35 638    
4 21 213    
5 30 254
; 
proc genmod; model disease/total = snoring  /  dist=bin  link=identity; 
proc genmod; model disease/total = snoring  /  dist=bin  link=logit; 
proc genmod; model disease/total = snoring  /  dist=bin  link=probit;
-------------------------------------------------------------------------

SAS for Poisson and Negative Binomial GLMs for Crab Data of Table 4.3

--------------------------------------------------------------
data crab;
input color spine width satell weight; 
   weight=weight/1000; color=color-1;
datalines;
3  3  28.3  8  3050
4  3  22.5  0  1550
2  1  26.0  9  2300
4  3  24.8  0  2100
4  3  26.0  4  2600
3  3  23.8  0  2100
2  1  26.5  0  2350
4  2  24.7  0  1900
3  1  23.7  0  1950
4  3  25.6  0  2150
4  3  24.3  0  2150
3  3  25.8  0  2650
3  3  28.2  11 3050
5  2  21.0  0  1850
3  1  26.0  14 2300
2  1  27.1  8  2950
3  3  25.2  1  2000
3  3  29.0  1  3000
5  3  24.7  0  2200
3  3  27.4  5  2700
3  2  23.2  4  1950
2  2  25.0  3  2300
3  1  22.5  1  1600
4  3  26.7  2  2600
5  3  25.8  3  2000
5  3  26.2  0  1300
3  3  28.7  3  3150
3  1  26.8  5  2700
5  3  27.5  0  2600
3  3  24.9  0  2100
2  1  29.3  4  3200
2  3  25.8  0  2600
3  2  25.7  0  2000
3  1  25.7  8  2000
3  1  26.7  5  2700
5  3  23.7  0  1850
3  3  26.8  0  2650
3  3  27.5  6  3150
5  3  23.4  0  1900
3  3  27.9  6  2800
4  3  27.5  3  3100
2  1  26.1  5  2800
2  1  27.7  6  2500
3  1  30.0  5  3300
4  1  28.5  9  3250
4  3  28.9  4  2800
3  3  28.2  6  2600
3  3  25.0  4  2100
3  3  28.5  3  3000
3  1  30.3  3  3600
5  3  24.7  5  2100
3  3  27.7  5  2900
2  1  27.4  6  2700
3  3  22.9  4  1600
3  1  25.7  5  2000
3  3  28.3  15 3000
3  3  27.2  3  2700
4  3  26.2  3  2300
3  1  27.8  0  2750
5  3  25.5  0  2250
4  3  27.1  0  2550
4  3  24.5  5  2050
4  1  27.0  3  2450
3  3  26.0  5  2150
3  3  28.0  1  2800
3  3  30.0  8  3050
3  3  29.0  10 3200
3  3  26.2  0  2400
3  1  26.5  0  1300
3  3  26.2  3  2400
4  3  25.6  7  2800
4  3  23.0  1  1650
4  3  23.0  0  1800
3  3  25.4  6  2250
4  3  24.2  0  1900
3  2  22.9  0  1600
4  2  26.0  3  2200
3  3  25.4  4  2250
4  3  25.7  0  1200
3  3  25.1  5  2100
4  2  24.5  0  2250
5  3  27.5  0  2900
4  3  23.1  0  1650
4  1  25.9  4  2550
3  3  25.8  0  2300
5  3  27.0  3  2250
3  3  28.5  0  3050
5  1  25.5  0  2750
5  3  23.5  0  1900
3  2  24.0  0  1700
3  1  29.7  5  3850
3  1  26.8  0  2550
5  3  26.7  0  2450
3  1  28.7  0  3200
4  3  23.1  0  1550
3  1  29.0  1  2800
4  3  25.5  0  2250
4  3  26.5  1  1967
4  3  24.5  1  2200
4  3  28.5  1  3000
3  3  28.2  1  2867
3  3  24.5  1  1600
3  3  27.5  1  2550
3  2  24.7  4  2550
3  1  25.2  1  2000
4  3  27.3  1  2900
3  3  26.3  1  2400
3  3  29.0  1  3100
3  3  25.3  2  1900
3  3  26.5  4  2300
3  3  27.8  3  3250
3  3  27.0  6  2500
4  3  25.7  0  2100
3  3  25.0  2  2100
3  3  31.9  2  3325
5  3  23.7  0  1800
5  3  29.3  12 3225
4  3  22.0  0  1400
3  3  25.0  5  2400
4  3  27.0  6  2500
4  3  23.8  6  1800
2  1  30.2  2  3275
4  3  26.2  0  2225
3  3  24.2  2  1650
3  3  27.4  3  2900
3  2  25.4  0  2300
4  3  28.4  3  3200
5  3  22.5  4  1475
3  3  26.2  2  2025
3  1  24.9  6  2300
2  2  24.5  6  1950
3  3  25.1  0  1800
3  1  28.0  4  2900
5  3  25.8  10 2250
3  3  27.9  7  3050
3  3  24.9  0  2200
3  1  28.4  5  3100
4  3  27.2  5  2400
3  2  25.0  6  2250
3  3  27.5  6  2625
3  1  33.5  7  5200
3  3  30.5  3  3325
4  3  29.0  3  2925
3  1  24.3  0  2000
3  3  25.8  0  2400
5  3  25.0  8  2100
3  1  31.7  4  3725
3  3  29.5  4  3025
4  3  24.0  10 1900
3  3  30.0  9  3000
3  3  27.6  4  2850
3  3  26.2  0  2300
3  1  23.1  0  2000
3  1  22.9  0  1600
5  3  24.5  0  1900
3  3  24.7  4  1950
3  3  28.3  0  3200
3  3  23.9  2  1850
4  3  23.8  0  1800
4  2  29.8  4  3500
3  3  26.5  4  2350
3  3  26.0  3  2275
3  3  28.2  8  3050
5  3  25.7  0  2150
3  3  26.5  7  2750
3  3  25.8  0  2200
4  3  24.1  0  1800
4  3  26.2  2  2175
4  3  26.1  3  2750
4  3  29.0  4  3275
2  1  28.0  0  2625
5  3  27.0  0  2625
3  2  24.5  0  2000
;
proc genmod;
   model satell = width / dist=poi link=log ; 
proc genmod;
   model satell = width / dist=poi link=identity ;  
proc genmod;
   model satell = width / dist=negbin link=identity ;  
---------------------------------------------------------------

SAS for Overdispersion Modeling of Teratology Data in Table 4.5

------------------------------------------------------------------------
data moore;
  input litter group n y ;
datalines;
 1  1 10 1   
 2 1 11 4   
 3 1 12 9   
 4 1 4 4     
 5 1 10 10   
 6 1 11 9
 7  1 9  9   
 8 1 11 11  
 9 1 10 10  
 10 1 10 7  
 11 1 12 12  
 12 1 10 9
 13 1 8  8  
 14 1 11  9 
 15 1 6  4   
 16 1  9 7  
 17 1 14 14  
 18 1 12 7
 19 1 11 9  
 20 1 13 8  
 21 1 14 5   
 22 1 10 10 
 23 1 12 10  
 24 1 13 8
 25 1 10 10 
 26 1 14 3  
 27 1 13 13  
 28 1 4 3   
 29 1  8  8  
 30 1 13 5
 31 1 12 12 
 32 2 10 1  
 33 2  3  1  
 34 2 13 1  
 35 2 12  0  
 36 2 14 4
 37 2  9  2 
 38 2 13 2  
 39 2 16  1  
 40 2 11 0  
 41 2  4  0  
 42 2 1  0
 43 2 12 0  
 44 3  8 0  
 45 3 11  1  
 46 3 14 0  
 47 3 14 1   
 48 3 11 0
 49 4  3 0   
 50 4 13 0  
 51 4 9   2  
 52 4 17 2  
 53 4 15 0   
 54 4 2 0
 55 4 14 1  
 56 4 8  0  
 57 4 6  0   
 58 4 17 0
;
proc genmod;  class group;
  model y/n = group / dist=bin link=identity noint;
estimate 'pi1-pi2' group 1 -1 0 0;
proc genmod;  class group;
  model y/n = group / dist=bin link=identity noint scale=pearson;
------------------------------------------------------------------------

SAS for Modeling Grouped Crab Data of Table 5.2

---------------------------------------------------------------------
data crab;
input width y n satell;  
   logcases=log(n);
datalines;
22.69  5 14  14 
23.84  4 14  20
24.77 17 28  67
25.84 21 39 105
26.79 15 22  63
27.74 20 24  93
28.67 15 18  71
30.41 14 14  72
;
proc genmod; 
  model y/n = width / dist=bin link=logit lrci alpha=.01 type3;
proc logistic; 
  model y/n = width / influence stb; 
  output out=predict  p=pi_hat  lower=LCL  upper=UCL;
proc print  data=predict;
proc genmod;
  model satell = width / dist=poi link=log offset=logcases residuals;
---------------------------------------------------------------------

SAS for Logit Modeling of AIDS Data in Table 5.5

-----------------------------------------------------------------------
data aids;
input race $ azt $ y n ;
datalines;
 White Yes 14 107  
 White No 32 113  
 Black Yes 11 63  
 Black No 12 55
;
proc genmod; class race azt;
  model y/n = azt race / dist=bin type3 lrci residuals obstats;
proc logistic; class race azt / param=reference;
  model y/n = azt race / aggregate scale=none clparm=both clodds=both;
  output out=predict p=pi_hat lower=lower upper=upper;
proc print data=predict;
proc logistic; class race azt (ref=first) / param=ref;
  model y/n = azt / aggregate=(azt race) scale=none;
-----------------------------------------------------------------------

SAS for Logistic Regression Models with Crab Data of Table 4.3

----------------------------------------------------------------------------------
data crab;
input  color  spine  width  satell  weight;
   weight=weight/1000; color=color-1;
  if satell>0 then y=1; if satell=0 then y=0; 
  if color=4 then light=0; if color < 4 then light=1;
datalines;
3  3  28.3  8  3050
4  3  22.5  0  1550
2  1  26.0  9  2300
4  3  24.8  0  2100
4  3  26.0  4  2600
3  3  23.8  0  2100
2  1  26.5  0  2350
4  2  24.7  0  1900
3  1  23.7  0  1950
4  3  25.6  0  2150
4  3  24.3  0  2150
3  3  25.8  0  2650
3  3  28.2  11 3050
5  2  21.0  0  1850
3  1  26.0  14 2300
2  1  27.1  8  2950
3  3  25.2  1  2000
3  3  29.0  1  3000
5  3  24.7  0  2200
3  3  27.4  5  2700
3  2  23.2  4  1950
2  2  25.0  3  2300
3  1  22.5  1  1600
4  3  26.7  2  2600
5  3  25.8  3  2000
5  3  26.2  0  1300
3  3  28.7  3  3150
3  1  26.8  5  2700
5  3  27.5  0  2600
3  3  24.9  0  2100
2  1  29.3  4  3200
2  3  25.8  0  2600
3  2  25.7  0  2000
3  1  25.7  8  2000
3  1  26.7  5  2700
5  3  23.7  0  1850
3  3  26.8  0  2650
3  3  27.5  6  3150
5  3  23.4  0  1900
3  3  27.9  6  2800
4  3  27.5  3  3100
2  1  26.1  5  2800
2  1  27.7  6  2500
3  1  30.0  5  3300
4  1  28.5  9  3250
4  3  28.9  4  2800
3  3  28.2  6  2600
3  3  25.0  4  2100
3  3  28.5  3  3000
3  1  30.3  3  3600
5  3  24.7  5  2100
3  3  27.7  5  2900
2  1  27.4  6  2700
3  3  22.9  4  1600
3  1  25.7  5  2000
3  3  28.3  15 3000
3  3  27.2  3  2700
4  3  26.2  3  2300
3  1  27.8  0  2750
5  3  25.5  0  2250
4  3  27.1  0  2550
4  3  24.5  5  2050
4  1  27.0  3  2450
3  3  26.0  5  2150
3  3  28.0  1  2800
3  3  30.0  8  3050
3  3  29.0  10 3200
3  3  26.2  0  2400
3  1  26.5  0  1300
3  3  26.2  3  2400
4  3  25.6  7  2800
4  3  23.0  1  1650
4  3  23.0  0  1800
3  3  25.4  6  2250
4  3  24.2  0  1900
3  2  22.9  0  1600
4  2  26.0  3  2200
3  3  25.4  4  2250
4  3  25.7  0  1200
3  3  25.1  5  2100
4  2  24.5  0  2250
5  3  27.5  0  2900
4  3  23.1  0  1650
4  1  25.9  4  2550
3  3  25.8  0  2300
5  3  27.0  3  2250
3  3  28.5  0  3050
5  1  25.5  0  2750
5  3  23.5  0  1900
3  2  24.0  0  1700
3  1  29.7  5  3850
3  1  26.8  0  2550
5  3  26.7  0  2450
3  1  28.7  0  3200
4  3  23.1  0  1550
3  1  29.0  1  2800
4  3  25.5  0  2250
4  3  26.5  1  1967
4  3  24.5  1  2200
4  3  28.5  1  3000
3  3  28.2  1  2867
3  3  24.5  1  1600
3  3  27.5  1  2550
3  2  24.7  4  2550
3  1  25.2  1  2000
4  3  27.3  1  2900
3  3  26.3  1  2400
3  3  29.0  1  3100
3  3  25.3  2  1900
3  3  26.5  4  2300
3  3  27.8  3  3250
3  3  27.0  6  2500
4  3  25.7  0  2100
3  3  25.0  2  2100
3  3  31.9  2  3325
5  3  23.7  0  1800
5  3  29.3  12 3225
4  3  22.0  0  1400
3  3  25.0  5  2400
4  3  27.0  6  2500
4  3  23.8  6  1800
2  1  30.2  2  3275
4  3  26.2  0  2225
3  3  24.2  2  1650
3  3  27.4  3  2900
3  2  25.4  0  2300
4  3  28.4  3  3200
5  3  22.5  4  1475
3  3  26.2  2  2025
3  1  24.9  6  2300
2  2  24.5  6  1950
3  3  25.1  0  1800
3  1  28.0  4  2900
5  3  25.8  10 2250
3  3  27.9  7  3050
3  3  24.9  0  2200
3  1  28.4  5  3100
4  3  27.2  5  2400
3  2  25.0  6  2250
3  3  27.5  6  2625
3  1  33.5  7  5200
3  3  30.5  3  3325
4  3  29.0  3  2925
3  1  24.3  0  2000
3  3  25.8  0  2400
5  3  25.0  8  2100
3  1  31.7  4  3725
3  3  29.5  4  3025
4  3  24.0  10 1900
3  3  30.0  9  3000
3  3  27.6  4  2850
3  3  26.2  0  2300
3  1  23.1  0  2000
3  1  22.9  0  1600
5  3  24.5  0  1900
3  3  24.7  4  1950
3  3  28.3  0  3200
3  3  23.9  2  1850
4  3  23.8  0  1800
4  2  29.8  4  3500
3  3  26.5  4  2350
3  3  26.0  3  2275
3  3  28.2  8  3050
5  3  25.7  0  2150
3  3  26.5  7  2750
3  3  25.8  0  2200
4  3  24.1  0  1800
4  3  26.2  2  2175
4  3  26.1  3  2750
4  3  29.0  4  3275
2  1  28.0  0  2625
5  3  27.0  0  2625
3  2  24.5  0  2000
; 
proc genmod descending; class color;
  model y = width color / dist=bin link=logit lrci type3 obstats; 
  contrast 'a-d' color 1  0  0  -1; 
proc genmod descending; 
  model y = width color / dist=bin link=logit; 
proc genmod descending; 
  model y = width light / dist=bin link=logit;   
proc genmod descending; class color spine;
  model y = width weight color spine / dist=bin link=logit type3;
proc logistic descending; class color spine / param=ref;
  model y = width weight color spine / selection=backward lackfit outroc=classif1;
proc plot data=classif1; plot _sensit_ * _1mspec_  ;
----------------------------------------------------------------------------------

SAS for CMH Analyses of Clinical Trial Data of Table 6.9

-----------------------------------------------------------------------------
data cmh;
input center $ treat response count ;
datalines;
 a 1 1 11 
 a 1 2 25  
 a 2 1 10  
 a 2 2 27
 b 1 1 16 
 b 1 2 4   
 b 2 1 22  
 b 2 2 10
 c 1 1 14 
 c 1 2 5   
 c 2 1 7   
 c 2 2 12
 d 1 1 2  
 d 1 2 14  
 d 2 1 1   
 d 2 2 16
 e 1 1 6  
 e 1 2 11  
 e 2 1 0   
 e 2 2 12
 f 1 1 1  
 f 1 2 10  
 f 2 1 0   
 f 2 2 10
 g 1 1 1  
 g 1 2 4   
 g 2 1 1   
 g 2 2 8
 h 1 1 4  
 h 1 2 2   
 h 2 1 6   
 h 2 2 1
;
proc freq; weight count;
  tables center*treat*response / cmh chisq;
-----------------------------------------------------------------------------

SAS for Baseline-Category Logit Models with Alligator Data in Table 7.1

 
----------------------------------------------------------------------
data gator;
input lake gender size food count ;
datalines;
1 1 1 1 7   
1 1 1 2 1   
1 1 1 3 0   
1 1 1 4 0   
1 1 1 5 5
1 1 2 1 4   
1 1 2 2 0   
1 1 2 3 0   
1 1 2 4 1   
1 1 2 5 2        
1 2 1 1 16  
1 2 1 2 3   
1 2 1 3 2   
1 2 1 4 2   
1 2 1 5 3
1 2 2 1 3   
1 2 2 2 0   
1 2 2 3 1   
1 2 2 4 2   
1 2 2 5 3
2 1 1 1 2   
2 1 1 2 2   
2 1 1 3 0   
2 1 1 4 0   
2 1 1 5 1  
2 1 2 1 13  
2 1 2 2 7   
2 1 2 3 6   
2 1 2 4 0   
2 1 2 5 0  
2 2 1 1 3   
2 2 1 2 9   
2 2 1 3 1   
2 2 1 4 0   
2 2 1 5 2  
2 2 2 1 0   
2 2 2 2 1   
2 2 2 3 0   
2 2 2 4 1   
2 2 2 5 0 
3 1 1 1 3   
3 1 1 2 7   
3 1 1 3 1   
3 1 1 4 0   
3 1 1 5 1
3 1 2 1 8   
3 1 2 2 6   
3 1 2 3 6   
3 1 2 4 3   
3 1 2 5 5  
3 2 1 1 2   
3 2 1 2 4   
3 2 1 3 1   
3 2 1 4 1   
3 2 1 5 4          
3 2 2 1 0   
3 2 2 2 1   
3 2 2 3 0   
3 2 2 4 0   
3 2 2 5 0  
4 1 1 1 13  
4 1 1 2 10  
4 1 1 3 0   
4 1 1 4 2   
4 1 1 5 2  
4 1 2 1 9   
4 1 2 2 0   
4 1 2 3 0   
4 1 2 4 1   
4 1 2 5 2  
4 2 1 1 3   
4 2 1 2 9   
4 2 1 3 1   
4 2 1 4 0   
4 2 1 5 1
4 2 2 1 8   
4 2 2 2 1   
4 2 2 3 0   
4 2 2 4 0   
4 2 2 5 1           
;
proc logistic; freq count; class lake size / param=ref;
  model food(ref='1') = lake size / link=glogit aggregate scale=none;
proc catmod; weight count;
  population lake size gender;
  model food = lake size / pred=freq pred=prob;
----------------------------------------------------------------------

SAS for Cumulative Logit Model with Mental Impairment Data of Table 7.5

-------------------------------------------------------------------------
data impair;
input mental ses life; 
datalines;
1 1 1
1 1 9
1 1 4
1 1 3
1 0 2
1 1 0
1 0 1
1 1 3
1 1 3
1 1 7
1 0 1
1 0 2
2 1 5
2 0 6
2 1 3
2 0 1
2 1 8
2 1 2
2 0 5
2 1 5
2 1 9
2 0 3
2 1 3
2 1 1
3 0 0
3 1 4
3 0 3
3 0 9
3 1 6
3 0 4
3 0 3
4 1 8
4 1 2
4 1 7
4 0 5
4 0 4
4 0 4
4 1 8
4 0 8
4 0 9
;
proc genmod ;
   model mental = life ses / dist=multinomial link=clogit lrci type3;
proc logistic;
   model mental = life ses / link=probit;
-------------------------------------------------------------------------

SAS for Adjacent-Categories Logit and Mean Response Models and CMH Analyses of Job Satisfaction Data in Table 7.8

------------------------------------------------------------------------
data jobsat;
input gender income satisf count ; 
count2 = count + .01;
datalines;
1  1 1 1  
1  1 2 3  
1  1 3 11  
1 1 4 2 
1  2 1 2  
1  2 2 3  
1  2 3 17  
1 2 4 3 
1  3 1 0  
1  3 2 1  
1  3 3  8  
1 3 4 5
1  4 1 0  
1  4 2 2  
1  4 3 4   
1 4 4 2
0  1 1 1  
0  1 2 1  
0  1 3 2   
0 1 4 1
0  2 1 0  
0  2 2 3  
0  2 3 5   
0 2 4 1
0  3 1 0  
0  3 2 0  
0  3 3 7   
0 3 4 3
0  4 1 0  
0  4 2 1  
0  4 3 9   
0 4 4 6
;
proc catmod order=data; * ML analysis of adj-cat logit (ACL) model;
    weight count;
    population gender income;
    model satisf =
       (1 0 0  3 3, 0 1 0 2 2, 0 0 1 1 1,
        1 0 0  6 3, 0 1 0 4 2, 0 0 1 2 1,
        1 0 0  9 3, 0 1 0 6 2, 0 0 1 3 1,
        1 0 0 12 3, 0 1 0 8 2, 0 0 1 4 1,
        1 0 0  3 0, 0 1 0 2 0, 0 0 1 1 0,
        1 0 0  6 0, 0 1 0 4 0, 0 0 1 2 0,
        1 0 0  9 0, 0 1 0 6 0, 0 0 1 3 0,
        1 0 0 12 0, 0 1 0 8 0, 0 0 1 4 0)
          / ml pred=freq;
proc catmod order=data; weight count2; * WLS analysis of ACL model;
  response alogits; population gender income; direct gender income;
  model satisf =  _response_ gender income;
proc catmod; weight count; * mean response model;
  population gender income; response mean; direct gender income;
  model satisf =  gender income / covb;
proc freq; weight count;
   tables gender*income*satisf / cmh scores=table;
------------------------------------------------------------------------

SAS for Loglinear Models with Drug Survey Data of Table 8.3

-------------------------------------------------------------------------
data drugs;
input a c m count ; 
datalines;
1 1 1 911  
1 1 2 538   
1 2 1 44   
1 2 2 456
2 1 1   3   
2 1 2  43   
2 2 1  2   
2 2 2 279
;
proc genmod; class a c m;
  model count = a c m a*m a*c c*m / dist=poi lrci type3 residuals obstats;
--------------------------------------------------------------------------

SAS for Raking Table 8.15

-----------------------------------------------------------------------
data rake;
input school atti count ;
log_c = log(count); pseudo = 100/3; 
cards;
1 1 209   
1 2 101   
1 3 237   
2 1 151   
2 2 126   
2 3 426   
3 1  16   
3 2  21   
3 3 138  
; 
proc genmod; class school atti;
  model pseudo = school atti / dist=poi link=log offset=log_c obstats;
-----------------------------------------------------------------------

SAS for Table 9.3

-------------------------------------------------------------------
data sex;
input premar birth u v count ;  
   assoc = u*v ;
datalines;
1 4  1 1 38   
1 3 1 2 60   
1 2 1 4  68   
1 1  1 5 81
2 4  2 1 14    
2 3  2 2 29   
2 2 2 4 26   
2 1 2 5  24
3 4  4 1 42   
3 3 4 2 74   
3 2 4 4 41   
3 1 4 5 18
4 4  5 1 157   
4 3 5 2 161   
4 2 5 4 57  
4 1 5 5 36
;
proc genmod; class premar birth;
  model  count = premar birth assoc / dist=poi link=log;
proc genmod; class premar birth;
  model  count = premar birth premar*v / dist=poi link=log;
-------------------------------------------------------------------

SAS for McNemar's Test and Comparing Proportions for Matched Samples in Table 10.1

--------------------------------------------------------------
data matched;
input first second count ;
datalines;
 1 1 794 
 1 2 150  
 2 1  86  
 2 2 570
;
proc freq; weight count;
    tables first*second / agree;  exact mcnem;
proc catmod; weight count;
    response marginals;
    model first*second =  (1 0 ,
                           1 1 ) ;
--------------------------------------------------------------

SAS for Testing Marginal Homogeneity with Migration Data of Table 10.6

--------------------------------------------------------------------------
data migrate;
input then $ now $ count m11 m12 m13 m21 m22 m23 m31 m32 m33 m44 m1 m2 m3;
datalines;
  ne ne 11607  1  0  0  0  0  0  0  0  0  0  0  0  0
  ne mw   100  0  1  0  0  0  0  0  0  0  0  0  0  0
  ne  s   366  0  0  1  0  0  0  0  0  0  0  0  0  0
  ne  w   124 -1 -1 -1  0  0  0  0  0  0  0  1  0  0 
  mw ne    87  0  0  0  1  0  0  0  0  0  0  0  0  0 
  mw mw 13677  0  0  0  0  1  0  0  0  0  0  0  0  0
  mw  s   515  0  0  0  0  0  1  0  0  0  0  0  0  0
  mw  w   302  0  0  0 -1 -1 -1  0  0  0  0  0  1  0
   s ne   172  0  0  0  0  0  0  1  0  0  0  0  0  0
   s mw   225  0  0  0  0  0  0  0  1  0  0  0  0  0
   s  s 17819  0  0  0  0  0  0  0  0  1  0  0  0  0
   s  w   270  0  0  0  0  0  0 -1 -1 -1  0  0  0  1
   w ne    63 -1  0  0 -1  0  0 -1  0  0  0  1  0  0
   w mw   176  0 -1  0  0 -1  0  0 -1  0  0  0  1  0
   w  s   286  0  0 -1  0  0 -1  0  0 -1  0  0  0  1
   w  w 10192  0  0  0  0  0  0  0  0  0  1  0  0  0
      ;
proc genmod;
    model count = m11 m12 m13 m21 m22 m23 m31 m32 m33 m44 m1 m2 m3
        / dist=poi  link=identity;
proc catmod; weight count;  response marginals;
    model then*now =  _response_  / freq;
    repeated time 2;
--------------------------------------------------------------------------

SAS for Square-Table Analyses of Table 10.5

--------------------------------------------------------------------------
data sex;
input premar  extramar  symm  qi  count;
unif = premar*extramar;
datalines;
1 1 1 1 144   
1 2 2 5  2   
1 3 3 5  0   
1 4  4 5 0
2 1 2 5  33   
2 2 5 2  4   
2 3 6 5  2   
2 4  7 5 0
3 1 3 5  84   
3 2 6 5 14   
3 3 8 3  6   
3 4  9 5 1
4 1 4 5 126   
4 2 7 5 29   
4 3 9 5 25   
4 4 10 4 5
;
proc genmod; class symm;
  model  count = symm / dist=poi link=log; * symmetry;
proc genmod; class extramar premar symm;
  model  count = symm extramar premar / dist=poi link=log; *QS;
proc genmod; class symm;
  model  count = symm extramar premar / dist=poi link=log; * ordinal QS;
proc genmod; class extramar premar qi;
  model count = extramar premar qi / dist=poi link=log; * quasi indep;
proc genmod;  class extramar premar;
  model count = extramar premar unif / dist=poi link=log;
data sex2;
input score below above @@; trials = below + above;
datalines;
1 33 2    1 14 2    1 25 1    2 84 0    2 29 0    3 126 0
;
proc genmod data=sex2; 
  model above/trials = score / dist=bin link=logit noint;
proc genmod data=sex2;
  model above/trials = / dist=bin link=logit noint;
proc genmod data=sex2;
  model above/trials = / dist=bin link=logit;
--------------------------------------------------------------------------

SAS for Bradley-Terry Model with Table 10.10

-----------------------------------------------------------------------------
data baseball;
input wins games milw detr toro newy bost clev balt;
datalines;
 7 13  1 -1  0  0  0  0  0 
 9 13  1  0 -1  0  0  0  0
 7 13  1  0  0 -1  0  0  0
 7 13  1  0  0  0 -1  0  0
 9 13  1  0  0  0  0 -1  0
11 13  1  0  0  0  0  0 -1
 7 13  0  1 -1  0  0  0  0
 5 13  0  1  0 -1  0  0  0
11 13  0  1  0  0 -1  0  0
 9 13  0  1  0  0  0 -1  0
 9 13  0  1  0  0  0  0 -1
 7 13  0  0  1 -1  0  0  0
 7 13  0  0  1  0 -1  0  0
 8 13  0  0  1  0  0 -1  0
12 13  0  0  1  0  0  0 -1
 6 13  0  0  0  1 -1  0  0
 7 13  0  0  0  1  0 -1  0
10 13  0  0  0  1  0  0 -1
 7 13  0  0  0  0  1 -1  0
12 13  0  0  0  0  1  0 -1
 6 13  0  0  0  0  0  1 -1
;
proc genmod;
   model wins/games = milw detr toro newy bost clev balt /
   dist=bin link=logit noint covb;
-----------------------------------------------------------------------------

SAS for Testing Marginal Homogeneity with Crossover Study of Table 11.1

-----------------------------------------------------------------------------
data crossove;
input a b c count m111 m11p m1p1 mp11 m1pp m222 ;
datalines;
 1 1 1  6   1  0  0  0  0  0     
 1 1 2 16  -1  1  0  0  0  0 
 1 2 1  2  -1  0  1  0  0  0     
 1 2 2  4   1 -1 -1  0  1  0
 2 1 1  2  -1  0  0  1  0  0     
 2 1 2  4   1 -1  0 -1  1  0
 2 2 1  6   1  0 -1 -1  1  0     
 2 2 2  6   0  0  0  0  0  1
;
proc genmod;
   model count = m111 m11p m1p1 mp11 m1pp m222 / dist=poi link=identity;
proc catmod; weight count; response marginals;
    model a*b*c =  _response_  / freq;
    repeated drug 3;
-----------------------------------------------------------------------------

SAS for Marginal Modeling of Depression Data of Table 11.2

-----------------------------------------------------------------------------
data depress;
input case diagnose treat time outcome ; * outcome=1 is normal;
datalines;
  1  0  0  0  1
  1  0  0  1  1
  1  0  0  2  1
  2  0  0  0  1
  2  0  0  1  1
  2  0  0  2  1
  3  0  0  0  1
  3  0  0  1  1
  3  0  0  2  1
  4  0  0  0  1
  4  0  0  1  1
  4  0  0  2  1
  5  0  0  0  1
  5  0  0  1  1
  5  0  0  2  1
  6  0  0  0  1
  6  0  0  1  1
  6  0  0  2  1
  7  0  0  0  1
  7  0  0  1  1
  7  0  0  2  1
  8  0  0  0  1
  8  0  0  1  1
  8  0  0  2  1
  9  0  0  0  1
  9  0  0  1  1
  9  0  0  2  1
 10  0  0  0  1
 10  0  0  1  1
 10  0  0  2  1
 11  0  0  0  1
 11  0  0  1  1
 11  0  0  2  1
 12  0  0  0  1
 12  0  0  1  1
 12  0  0  2  1
 13  0  0  0  1
 13  0  0  1  1
 13  0  0  2  1
 14  0  0  0  1
 14  0  0  1  1
 14  0  0  2  1
 15  0  0  0  1
 15  0  0  1  1
 15  0  0  2  1
 16  0  0  0  1
 16  0  0  1  1
 16  0  0  2  1
 17  0  0  0  1
 17  0  0  1  1
 17  0  0  2  0
 18  0  0  0  1
 18  0  0  1  1
 18  0  0  2  0
 19  0  0  0  1
 19  0  0  1  1
 19  0  0  2  0
 20  0  0  0  1
 20  0  0  1  1
 20  0  0  2  0
 21  0  0  0  1
 21  0  0  1  1
 21  0  0  2  0
 22  0  0  0  1
 22  0  0  1  1
 22  0  0  2  0
 23  0  0  0  1
 23  0  0  1  1
 23  0  0  2  0
 24  0  0  0  1
 24  0  0  1  1
 24  0  0  2  0
 25  0  0  0  1
 25  0  0  1  1
 25  0  0  2  0
 26  0  0  0  1
 26  0  0  1  1
 26  0  0  2  0
 27  0  0  0  1
 27  0  0  1  1
 27  0  0  2  0
 28  0  0  0  1
 28  0  0  1  1
 28  0  0  2  0
 29  0  0  0  1
 29  0  0  1  1
 29  0  0  2  0
 30  0  0  0  1
 30  0  0  1  0
 30  0  0  2  1
 31  0  0  0  1
 31  0  0  1  0
 31  0  0  2  1
 32  0  0  0  1
 32  0  0  1  0
 32  0  0  2  1
 33  0  0  0  1
 33  0  0  1  0
 33  0  0  2  1
 34  0  0  0  1
 34  0  0  1  0
 34  0  0  2  1
 35  0  0  0  1
 35  0  0  1  0
 35  0  0  2  1
 36  0  0  0  1
 36  0  0  1  0
 36  0  0  2  1
 37  0  0  0  1
 37  0  0  1  0
 37  0  0  2  1
 38  0  0  0  1
 38  0  0  1  0
 38  0  0  2  1
 39  0  0  0  1
 39  0  0  1  0
 39  0  0  2  0
 40  0  0  0  1
 40  0  0  1  0
 40  0  0  2  0
 41  0  0  0  1
 41  0  0  1  0
 41  0  0  2  0
 42  0  0  0  0
 42  0  0  1  1
 42  0  0  2  1
 43  0  0  0  0
 43  0  0  1  1
 43  0  0  2  1
 44  0  0  0  0
 44  0  0  1  1
 44  0  0  2  1
 45  0  0  0  0
 45  0  0  1  1
 45  0  0  2  1
 46  0  0  0  0
 46  0  0  1  1
 46  0  0  2  1
 47  0  0  0  0
 47  0  0  1  1
 47  0  0  2  1
 48  0  0  0  0
 48  0  0  1  1
 48  0  0  2  1
 49  0  0  0  0
 49  0  0  1  1
 49  0  0  2  1
 50  0  0  0  0
 50  0  0  1  1
 50  0  0  2  1
 51  0  0  0  0
 51  0  0  1  1
 51  0  0  2  1
 52  0  0  0  0
 52  0  0  1  1
 52  0  0  2  1
 53  0  0  0  0
 53  0  0  1  1
 53  0  0  2  1
 54  0  0  0  0
 54  0  0  1  1
 54  0  0  2  1
 55  0  0  0  0
 55  0  0  1  1
 55  0  0  2  1
 56  0  0  0  0
 56  0  0  1  1
 56  0  0  2  0
 57  0  0  0  0
 57  0  0  1  1
 57  0  0  2  0
 58  0  0  0  0
 58  0  0  1  1
 58  0  0  2  0
 59  0  0  0  0
 59  0  0  1  1
 59  0  0  2  0
 60  0  0  0  0
 60  0  0  1  0
 60  0  0  2  1
 61  0  0  0  0
 61  0  0  1  0
 61  0  0  2  1
 62  0  0  0  0
 62  0  0  1  0
 62  0  0  2  1
 63  0  0  0  0
 63  0  0  1  0
 63  0  0  2  1
 64  0  0  0  0
 64  0  0  1  0
 64  0  0  2  1
 65  0  0  0  0
 65  0  0  1  0
 65  0  0  2  1
 66  0  0  0  0
 66  0  0  1  0
 66  0  0  2  1
 67  0  0  0  0
 67  0  0  1  0
 67  0  0  2  1
 68  0  0  0  0
 68  0  0  1  0
 68  0  0  2  1
 69  0  0  0  0
 69  0  0  1  0
 69  0  0  2  1
 70  0  0  0  0
 70  0  0  1  0
 70  0  0  2  1
 71  0  0  0  0
 71  0  0  1  0
 71  0  0  2  1
 72  0  0  0  0
 72  0  0  1  0
 72  0  0  2  1
 73  0  0  0  0
 73  0  0  1  0
 73  0  0  2  1
 74  0  0  0  0
 74  0  0  1  0
 74  0  0  2  1
 75  0  0  0  0
 75  0  0  1  0
 75  0  0  2  0
336  0  0  0  0
336  0  0  1  0
336  0  0  2  0
337  0  0  0  0
337  0  0  1  0
337  0  0  2  0
338  0  0  0  0
338  0  0  1  0
338  0  0  2  0
339  0  0  0  0
339  0  0  1  0
339  0  0  2  0
340  0  0  0  0
340  0  0  1  0
340  0  0  2  0

 76  0  1  0  1
 76  0  1  1  1
 76  0  1  2  1
 77  0  1  0  1
 77  0  1  1  1
 77  0  1  2  1
 78  0  1  0  1
 78  0  1  1  1
 78  0  1  2  1
 79  0  1  0  1
 79  0  1  1  1
 79  0  1  2  1
 80  0  1  0  1
 80  0  1  1  1
 80  0  1  2  1
 81  0  1  0  1
 81  0  1  1  1
 81  0  1  2  1
 82  0  1  0  1
 82  0  1  1  1
 82  0  1  2  1
 83  0  1  0  1
 83  0  1  1  1
 83  0  1  2  1
 84  0  1  0  1
 84  0  1  1  1
 84  0  1  2  1
 85  0  1  0  1
 85  0  1  1  1
 85  0  1  2  1
 86  0  1  0  1
 86  0  1  1  1
 86  0  1  2  1
 87  0  1  0  1
 87  0  1  1  1
 87  0  1  2  1
 88  0  1  0  1
 88  0  1  1  1
 88  0  1  2  1
 89  0  1  0  1
 89  0  1  1  1
 89  0  1  2  1
 90  0  1  0  1
 90  0  1  1  1
 90  0  1  2  1
 91  0  1  0  1
 91  0  1  1  1
 91  0  1  2  1
 92  0  1  0  1
 92  0  1  1  1
 92  0  1  2  1
 93  0  1  0  1
 93  0  1  1  1
 93  0  1  2  1
 94  0  1  0  1
 94  0  1  1  1
 94  0  1  2  1
 95  0  1  0  1
 95  0  1  1  1
 95  0  1  2  1
 96  0  1  0  1
 96  0  1  1  1
 96  0  1  2  1
 97  0  1  0  1
 97  0  1  1  1
 97  0  1  2  1
 98  0  1  0  1
 98  0  1  1  1
 98  0  1  2  1
 99  0  1  0  1
 99  0  1  1  1
 99  0  1  2  1
100  0  1  0  1
100  0  1  1  1
100  0  1  2  1
101  0  1  0  1
101  0  1  1  1
101  0  1  2  1
102  0  1  0  1
102  0  1  1  1
102  0  1  2  1
103  0  1  0  1
103  0  1  1  1
103  0  1  2  1
104  0  1  0  1
104  0  1  1  1
104  0  1  2  1
105  0  1  0  1
105  0  1  1  1
105  0  1  2  1
106  0  1  0  1
106  0  1  1  1
106  0  1  2  1
107  0  1  0  1
107  0  1  1  0
107  0  1  2  1
108  0  1  0  1
108  0  1  1  0
108  0  1  2  1
109  0  1  0  1
109  0  1  1  0
109  0  1  2  1
110  0  1  0  1
110  0  1  1  0
110  0  1  2  1
111  0  1  0  1
111  0  1  1  0
111  0  1  2  1
112  0  1  0  1
112  0  1  1  0
112  0  1  2  1
113  0  1  0  0
113  0  1  1  1
113  0  1  2  1
114  0  1  0  0
114  0  1  1  1
114  0  1  2  1
115  0  1  0  0
115  0  1  1  1
115  0  1  2  1
116  0  1  0  0
116  0  1  1  1
116  0  1  2  1
117  0  1  0  0
117  0  1  1  1
117  0  1  2  1
118  0  1  0  0
118  0  1  1  1
118  0  1  2  1
119  0  1  0  0
119  0  1  1  1
119  0  1  2  1
120  0  1  0  0
120  0  1  1  1
120  0  1  2  1
121  0  1  0  0
121  0  1  1  1
121  0  1  2  1
122  0  1  0  0
122  0  1  1  1
122  0  1  2  1
123  0  1  0  0
123  0  1  1  1
123  0  1  2  1
124  0  1  0  0
124  0  1  1  1
124  0  1  2  1
125  0  1  0  0
125  0  1  1  1
125  0  1  2  1
126  0  1  0  0
126  0  1  1  1
126  0  1  2  1
127  0  1  0  0
127  0  1  1  1
127  0  1  2  1
128  0  1  0  0
128  0  1  1  1
128  0  1  2  1
129  0  1  0  0
129  0  1  1  1
129  0  1  2  1
130  0  1  0  0
130  0  1  1  1
130  0  1  2  1
131  0  1  0  0
131  0  1  1  1
131  0  1  2  1
132  0  1  0  0
132  0  1  1  1
132  0  1  2  1
133  0  1  0  0
133  0  1  1  1
133  0  1  2  1
134  0  1  0  0
134  0  1  1  1
134  0  1  2  1
135  0  1  0  0
135  0  1  1  1
135  0  1  2  0
136  0  1  0  0
136  0  1  1  1
136  0  1  2  0
137  0  1  0  0
137  0  1  1  0
137  0  1  2  1
138  0  1  0  0
138  0  1  1  0
138  0  1  2  1
139  0  1  0  0
139  0  1  1  0
139  0  1  2  1
140  0  1  0  0
140  0  1  1  0
140  0  1  2  1
141  0  1  0  0
141  0  1  1  0
141  0  1  2  1
142  0  1  0  0
142  0  1  1  0
142  0  1  2  1
143  0  1  0  0
143  0  1  1  0
143  0  1  2  1
144  0  1  0  0
144  0  1  1  0
144  0  1  2  1
145  0  1  0  0
145  0  1  1  0
145  0  1  2  1

146  1  0  0  1
146  1  0  1  1
146  1  0  2  1
147  1  0  0  1
147  1  0  1  1
147  1  0  2  1
148  1  0  0  1
148  1  0  1  1
148  1  0  2  0
149  1  0  0  1
149  1  0  1  1
149  1  0  2  0
150  1  0  0  1
150  1  0  1  0
150  1  0  2  1
151  1  0  0  1
151  1  0  1  0
151  1  0  2  1
152  1  0  0  1
152  1  0  1  0
152  1  0  2  1
153  1  0  0  1
153  1  0  1  0
153  1  0  2  1
154  1  0  0  1
154  1  0  1  0
154  1  0  2  1
155  1  0  0  1
155  1  0  1  0
155  1  0  2  1
156  1  0  0  1
156  1  0  1  0
156  1  0  2  1
157  1  0  0  1
157  1  0  1  0
157  1  0  2  1
158  1  0  0  1
158  1  0  1  0
158  1  0  2  0
159  1  0  0  1
159  1  0  1  0
159  1  0  2  0
160  1  0  0  1
160  1  0  1  0
160  1  0  2  0
161  1  0  0  1
161  1  0  1  0
161  1  0  2  0
162  1  0  0  1
162  1  0  1  0
162  1  0  2  0
163  1  0  0  1
163  1  0  1  0
163  1  0  2  0
164  1  0  0  1
164  1  0  1  0
164  1  0  2  0
165  1  0  0  1
165  1  0  1  0
165  1  0  2  0
166  1  0  0  1
166  1  0  1  0
166  1  0  2  0
167  1  0  0  0
167  1  0  1  1
167  1  0  2  1
168  1  0  0  0
168  1  0  1  1
168  1  0  2  1
169  1  0  0  0
169  1  0  1  1
169  1  0  2  1
170  1  0  0  0
170  1  0  1  1
170  1  0  2  1
171  1  0  0  0
171  1  0  1  1
171  1  0  2  1
172  1  0  0  0
172  1  0  1  1
172  1  0  2  1
173  1  0  0  0
173  1  0  1  1
173  1  0  2  1
174  1  0  0  0
174  1  0  1  1
174  1  0  2  1
175  1  0  0  0
175  1  0  1  1
175  1  0  2  1
176  1  0  0  0
176  1  0  1  1
176  1  0  2  0
177  1  0  0  0
177  1  0  1  1
177  1  0  2  0
178  1  0  0  0
178  1  0  1  1
178  1  0  2  0
179  1  0  0  0
179  1  0  1  1
179  1  0  2  0
180  1  0  0  0
180  1  0  1  1
180  1  0  2  0
181  1  0  0  0
181  1  0  1  1
181  1  0  2  0
182  1  0  0  0
182  1  0  1  1
182  1  0  2  0
183  1  0  0  0
183  1  0  1  1
183  1  0  2  0
184  1  0  0  0
184  1  0  1  1
184  1  0  2  0
185  1  0  0  0
185  1  0  1  1
185  1  0  2  0
186  1  0  0  0
186  1  0  1  1
186  1  0  2  0
187  1  0  0  0
187  1  0  1  1
187  1  0  2  0
188  1  0  0  0
188  1  0  1  1
188  1  0  2  0
189  1  0  0  0
189  1  0  1  1
189  1  0  2  0
190  1  0  0  0
190  1  0  1  1
190  1  0  2  0
191  1  0  0  0
191  1  0  1  0
191  1  0  2  1
192  1  0  0  0
192  1  0  1  0
192  1  0  2  1
193  1  0  0  0
193  1  0  1  0
193  1  0  2  1
194  1  0  0  0
194  1  0  1  0
194  1  0  2  1
195  1  0  0  0
195  1  0  1  0
195  1  0  2  1
196  1  0  0  0
196  1  0  1  0
196  1  0  2  1
197  1  0  0  0
197  1  0  1  0
197  1  0  2  1
198  1  0  0  0
198  1  0  1  0
198  1  0  2  1
199  1  0  0  0
199  1  0  1  0
199  1  0  2  1
200  1  0  0  0
200  1  0  1  0
200  1  0  2  1
201  1  0  0  0
201  1  0  1  0
201  1  0  2  1
202  1  0  0  0
202  1  0  1  0
202  1  0  2  1
203  1  0  0  0
203  1  0  1  0
203  1  0  2  1
204  1  0  0  0
204  1  0  1  0
204  1  0  2  1
205  1  0  0  0
205  1  0  1  0
205  1  0  2  1
206  1  0  0  0
206  1  0  1  0
206  1  0  2  1
207  1  0  0  0
207  1  0  1  0
207  1  0  2  1
208  1  0  0  0
208  1  0  1  0
208  1  0  2  1
209  1  0  0  0
209  1  0  1  0
209  1  0  2  1
210  1  0  0  0
210  1  0  1  0
210  1  0  2  1
211  1  0  0  0
211  1  0  1  0
211  1  0  2  1
212  1  0  0  0
212  1  0  1  0
212  1  0  2  1
213  1  0  0  0
213  1  0  1  0
213  1  0  2  1
214  1  0  0  0
214  1  0  1  0
214  1  0  2  1
215  1  0  0  0
215  1  0  1  0
215  1  0  2  1
216  1  0  0  0
216  1  0  1  0
216  1  0  2  1
217  1  0  0  0
217  1  0  1  0
217  1  0  2  1
218  1  0  0  0
218  1  0  1  0
218  1  0  2  0
219  1  0  0  0
219  1  0  1  0
219  1  0  2  0
220  1  0  0  0
220  1  0  1  0
220  1  0  2  0
221  1  0  0  0
221  1  0  1  0
221  1  0  2  0
222  1  0  0  0
222  1  0  1  0
222  1  0  2  0
223  1  0  0  0
223  1  0  1  0
223  1  0  2  0
224  1  0  0  0
224  1  0  1  0
224  1  0  2  0
225  1  0  0  0
225  1  0  1  0
225  1  0  2  0
226  1  0  0  0
226  1  0  1  0
226  1  0  2  0
227  1  0  0  0
227  1  0  1  0
227  1  0  2  0
228  1  0  0  0
228  1  0  1  0
228  1  0  2  0
229  1  0  0  0
229  1  0  1  0
229  1  0  2  0
230  1  0  0  0
230  1  0  1  0
230  1  0  2  0
231  1  0  0  0
231  1  0  1  0
231  1  0  2  0
232  1  0  0  0
232  1  0  1  0
232  1  0  2  0
233  1  0  0  0
233  1  0  1  0
233  1  0  2  0
234  1  0  0  0
234  1  0  1  0
234  1  0  2  0
235  1  0  0  0
235  1  0  1  0
235  1  0  2  0
236  1  0  0  0
236  1  0  1  0
236  1  0  2  0
237  1  0  0  0
237  1  0  1  0
237  1  0  2  0
238  1  0  0  0
238  1  0  1  0
238  1  0  2  0
239  1  0  0  0
239  1  0  1  0
239  1  0  2  0
240  1  0  0  0
240  1  0  1  0
240  1  0  2  0
241  1  0  0  0
241  1  0  1  0
241  1  0  2  0
242  1  0  0  0
242  1  0  1  0
242  1  0  2  0
243  1  0  0  0
243  1  0  1  0
243  1  0  2  0
244  1  0  0  0
244  1  0  1  0
244  1  0  2  0
245  1  0  0  0
245  1  0  1  0
245  1  0  2  0

246  1  1  0  1
246  1  1  1  1
246  1  1  2  1
247  1  1  0  1
247  1  1  1  1
247  1  1  2  1
248  1  1  0  1
248  1  1  1  1
248  1  1  2  1
249  1  1  0  1
249  1  1  1  1
249  1  1  2  1
250  1  1  0  1
250  1  1  1  1
250  1  1  2  1
251  1  1  0  1
251  1  1  1  1
251  1  1  2  1
252  1  1  0  1
252  1  1  1  1
252  1  1  2  1
253  1  1  0  1
253  1  1  1  1
253  1  1  2  0 
254  1  1  0  1
254  1  1  1  1
254  1  1  2  0 
255  1  1  0  1
255  1  1  1  0
255  1  1  2  1
256  1  1  0  1
256  1  1  1  0
256  1  1  2  1
257  1  1  0  1
257  1  1  1  0
257  1  1  2  1
258  1  1  0  1
258  1  1  1  0
258  1  1  2  1
259  1  1  0  1
259  1  1  1  0
259  1  1  2  1
260  1  1  0  1
260  1  1  1  0
260  1  1  2  0
261  1  1  0  1
261  1  1  1  0
261  1  1  2  0
262  1  1  0  0
262  1  1  1  1
262  1  1  2  1
263  1  1  0  0
263  1  1  1  1
263  1  1  2  1
264  1  1  0  0
264  1  1  1  1
264  1  1  2  1
265  1  1  0  0
265  1  1  1  1
265  1  1  2  1
266  1  1  0  0
266  1  1  1  1
266  1  1  2  1
267  1  1  0  0
267  1  1  1  1
267  1  1  2  1
268  1  1  0  0
268  1  1  1  1
268  1  1  2  1
269  1  1  0  0
269  1  1  1  1
269  1  1  2  1
270  1  1  0  0
270  1  1  1  1
270  1  1  2  1
271  1  1  0  0
271  1  1  1  1
271  1  1  2  1
272  1  1  0  0
272  1  1  1  1
272  1  1  2  1
273  1  1  0  0
273  1  1  1  1
273  1  1  2  1
274  1  1  0  0
274  1  1  1  1
274  1  1  2  1
275  1  1  0  0
275  1  1  1  1
275  1  1  2  1
276  1  1  0  0
276  1  1  1  1
276  1  1  2  1
277  1  1  0  0
277  1  1  1  1
277  1  1  2  1
278  1  1  0  0
278  1  1  1  1
278  1  1  2  1
279  1  1  0  0
279  1  1  1  1
279  1  1  2  1
280  1  1  0  0
280  1  1  1  1
280  1  1  2  1
281  1  1  0  0
281  1  1  1  1
281  1  1  2  1
282  1  1  0  0
282  1  1  1  1
282  1  1  2  1
283  1  1  0  0
283  1  1  1  1
283  1  1  2  1
284  1  1  0  0
284  1  1  1  1
284  1  1  2  1
285  1  1  0  0
285  1  1  1  1
285  1  1  2  1
286  1  1  0  0
286  1  1  1  1
286  1  1  2  1
287  1  1  0  0
287  1  1  1  1
287  1  1  2  1
288  1  1  0  0
288  1  1  1  1
288  1  1  2  1
289  1  1  0  0
289  1  1  1  1
289  1  1  2  1
290  1  1  0  0
290  1  1  1  1
290  1  1  2  1
291  1  1  0  0
291  1  1  1  1
291  1  1  2  1
292  1  1  0  0
292  1  1  1  1
292  1  1  2  1
293  1  1  0  0
293  1  1  1  1 
293  1  1  2  0
294  1  1  0  0
294  1  1  1  1 
294  1  1  2  0
295  1  1  0  0
295  1  1  1  1 
295  1  1  2  0
296  1  1  0  0
296  1  1  1  1 
296  1  1  2  0
297  1  1  0  0
297  1  1  1  1 
297  1  1  2  0
298  1  1  0  0
298  1  1  1  0
298  1  1  2  1
299  1  1  0  0
299  1  1  1  0
299  1  1  2  1
300  1  1  0  0
300  1  1  1  0
300  1  1  2  1
301  1  1  0  0
301  1  1  1  0
301  1  1  2  1
302  1  1  0  0
302  1  1  1  0
302  1  1  2  1
303  1  1  0  0
303  1  1  1  0
303  1  1  2  1
304  1  1  0  0
304  1  1  1  0
304  1  1  2  1
305  1  1  0  0
305  1  1  1  0
305  1  1  2  1
306  1  1  0  0
306  1  1  1  0
306  1  1  2  1
307  1  1  0  0
307  1  1  1  0
307  1  1  2  1
308  1  1  0  0
308  1  1  1  0
308  1  1  2  1
309  1  1  0  0
309  1  1  1  0
309  1  1  2  1
310  1  1  0  0
310  1  1  1  0
310  1  1  2  1
311  1  1  0  0
311  1  1  1  0
311  1  1  2  1
312  1  1  0  0
312  1  1  1  0
312  1  1  2  1
313  1  1  0  0
313  1  1  1  0
313  1  1  2  1
314  1  1  0  0
314  1  1  1  0
314  1  1  2  1
315  1  1  0  0
315  1  1  1  0
315  1  1  2  1
316  1  1  0  0
316  1  1  1  0
316  1  1  2  1
317  1  1  0  0
317  1  1  1  0
317  1  1  2  1
318  1  1  0  0
318  1  1  1  0
318  1  1  2  1
319  1  1  0  0
319  1  1  1  0
319  1  1  2  1
320  1  1  0  0
320  1  1  1  0
320  1  1  2  1
321  1  1  0  0
321  1  1  1  0
321  1  1  2  1
322  1  1  0  0
322  1  1  1  0
322  1  1  2  1
323  1  1  0  0
323  1  1  1  0
323  1  1  2  1
324  1  1  0  0
324  1  1  1  0
324  1  1  2  1
325  1  1  0  0
325  1  1  1  0
325  1  1  2  1
326  1  1  0  0
326  1  1  1  0
326  1  1  2  1
327  1  1  0  0
327  1  1  1  0
327  1  1  2  1
328  1  1  0  0
328  1  1  1  0
328  1  1  2  1
329  1  1  0  0
329  1  1  1  0
329  1  1  2  1
330  1  1  0  0
330  1  1  1  0
330  1  1  2  0
331  1  1  0  0
331  1  1  1  0
331  1  1  2  0
332  1  1  0  0
332  1  1  1  0
332  1  1  2  0
333  1  1  0  0
333  1  1  1  0
333  1  1  2  0
334  1  1  0  0
334  1  1  1  0
334  1  1  2  0
335  1  1  0  0
335  1  1  1  0
335  1  1  2  0
;
proc genmod descending;  class case;
  model outcome = diagnose treat time treat*time / dist=bin link=logit type3;
  repeated subject=case / type=exch corrw;
proc nlmixed  qpoints=200;
  parms alpha=-.03 beta1=-1.3 beta2=-.06 beta3=.48 beta4=1.02 sigma=.066;   
  eta = alpha + beta1*diagnose + beta2*treat + beta3*time + beta4*treat*time + u;
  p = exp(eta)/(1 + exp(eta));
  model outcome ~ binary(p);
  random u ~ normal(0, sigma*sigma) subject = case;
-----------------------------------------------------------------------------

SAS for GEE and Random Intercept Cumulative Logit Analyses of Insomnia data of Table 11.4

--------------------------------------------------------------------------
data francom;
 input case treat occasion outcome count;
datalines;                   
        1       1     0        1   7
        1       1     1        1   7
        2       1     0        1   7
        2       1     1        1   7
        3       1     0        1   7
        3       1     1        1   7
        4       1     0        1   7
        4       1     1        1   7
        5       1     0        1   7
        5       1     1        1   7
        6       1     0        1   7
        6       1     1        1   7
        7       1     0        1   7
        7       1     1        1   7
        8       1     0        1   4
        8       1     1        2   4
        9       1     0        1   4
        9       1     1        2   4
       10       1     0        1   4
       10       1     1        2   4
       11       1     0        1   4
       11       1     1        2   4
       12       1     0        1   1
       12       1     1        3   1
       13       1     0        2  11
       13       1     1        1  11
       14       1     0        2  11
       14       1     1        1  11
       15       1     0        2  11
       15       1     1        1  11
       16       1     0        2  11
       16       1     1        1  11
       17       1     0        2  11
       17       1     1        1  11
       18       1     0        2  11
       18       1     1        1  11
       19       1     0        2  11
       19       1     1        1  11
       20       1     0        2  11
       20       1     1        1  11
       21       1     0        2  11
       21       1     1        1  11
       22       1     0        2  11
       22       1     1        1  11
       23       1     0        2  11
       23       1     1        1  11
       24       1     0        2   5
       24       1     1        2   5
       25       1     0        2   5
       25       1     1        2   5
       26       1     0        2   5
       26       1     1        2   5
       27       1     0        2   5
       27       1     1        2   5
       28       1     0        2   5
       28       1     1        2   5
       29       1     0        2   2
       29       1     1        3   2
       30       1     0        2   2
       30       1     1        3   2
       31       1     0        2   2
       31       1     1        4   2
       32       1     0        2   2
       32       1     1        4   2
       33       1     0        3  13
       33       1     1        1  13
       34       1     0        3  13
       34       1     1        1  13
       35       1     0        3  13
       35       1     1        1  13
       36       1     0        3  13
       36       1     1        1  13
       37       1     0        3  13
       37       1     1        1  13
       38       1     0        3  13
       38       1     1        1  13
       39       1     0        3  13
       39       1     1        1  13
       40       1     0        3  13
       40       1     1        1  13
       41       1     0        3  13
       41       1     1        1  13
       42       1     0        3  13
       42       1     1        1  13
       43       1     0        3  13
       43       1     1        1  13
       44       1     0        3  13
       44       1     1        1  13
       45       1     0        3  13
       45       1     1        1  13
       46       1     0        3  23
       46       1     1        2  23
       47       1     0        3  23
       47       1     1        2  23
       48       1     0        3  23
       48       1     1        2  23
       49       1     0        3  23
       49       1     1        2  23
       50       1     0        3  23
       50       1     1        2  23
       51       1     0        3  23
       51       1     1        2  23
       52       1     0        3  23
       52       1     1        2  23
       53       1     0        3  23
       53       1     1        2  23
       54       1     0        3  23
       54       1     1        2  23
       55       1     0        3  23
       55       1     1        2  23
       56       1     0        3  23
       56       1     1        2  23
       57       1     0        3  23
       57       1     1        2  23
       58       1     0        3  23
       58       1     1        2  23
       59       1     0        3  23
       59       1     1        2  23
       60       1     0        3  23
       60       1     1        2  23
       61       1     0        3  23
       61       1     1        2  23
       62       1     0        3  23
       62       1     1        2  23
       63       1     0        3  23
       63       1     1        2  23
       64       1     0        3  23
       64       1     1        2  23
       65       1     0        3  23
       65       1     1        2  23
       66       1     0        3  23
       66       1     1        2  23
       67       1     0        3  23
       67       1     1        2  23
       68       1     0        3  23
       68       1     1        2  23
       69       1     0        3   3
       69       1     1        3   3
       70       1     0        3   3
       70       1     1        3   3
       71       1     0        3   3
       71       1     1        3   3
       72       1     0        3   1
       72       1     1        4   1
       73       1     0        4   9
       73       1     1        1   9
       74       1     0        4   9
       74       1     1        1   9
       75       1     0        4   9
       75       1     1        1   9
       76       1     0        4   9
       76       1     1        1   9
       77       1     0        4   9
       77       1     1        1   9
       78       1     0        4   9
       78       1     1        1   9
       79       1     0        4   9
       79       1     1        1   9
       80       1     0        4   9
       80       1     1        1   9
       81       1     0        4   9
       81       1     1        1   9
       82       1     0        4  17
       82       1     1        2  17
       83       1     0        4  17
       83       1     1        2  17
       84       1     0        4  17
       84       1     1        2  17
       85       1     0        4  17
       85       1     1        2  17
       86       1     0        4  17
       86       1     1        2  17
       87       1     0        4  17
       87       1     1        2  17
       88       1     0        4  17
       88       1     1        2  17
       89       1     0        4  17
       89       1     1        2  17
       90       1     0        4  17
       90       1     1        2  17
       91       1     0        4  17
       91       1     1        2  17
       92       1     0        4  17
       92       1     1        2  17
       93       1     0        4  17
       93       1     1        2  17
       94       1     0        4  17
       94       1     1        2  17
       95       1     0        4  17
       95       1     1        2  17
       96       1     0        4  17
       96       1     1        2  17
       97       1     0        4  17
       97       1     1        2  17
       98       1     0        4  17
       98       1     1        2  17
       99       1     0        4  13
       99       1     1        3  13
      100       1     0        4  13
      100       1     1        3  13
      101       1     0        4  13
      101       1     1        3  13
      102       1     0        4  13
      102       1     1        3  13
      103       1     0        4  13
      103       1     1        3  13
      104       1     0        4  13
      104       1     1        3  13
      105       1     0        4  13
      105       1     1        3  13
      106       1     0        4  13
      106       1     1        3  13
      107       1     0        4  13
      107       1     1        3  13
      108       1     0        4  13
      108       1     1        3  13
      109       1     0        4  13
      109       1     1        3  13
      110       1     0        4  13
      110       1     1        3  13
      111       1     0        4  13
      111       1     1        3  13
      112       1     0        4   8
      112       1     1        4   8
      113       1     0        4   8
      113       1     1        4   8
      114       1     0        4   8
      114       1     1        4   8
      115       1     0        4   8
      115       1     1        4   8
      116       1     0        4   8
      116       1     1        4   8
      117       1     0        4   8
      117       1     1        4   8
      118       1     0        4   8
      118       1     1        4   8
      119       1     0        4   8
      119       1     1        4   8
      120       0     0        1   7
      120       0     1        1   7
      121       0     0        1   7
      121       0     1        1   7
      122       0     0        1   7
      122       0     1        1   7
      123       0     0        1   7
      123       0     1        1   7
      124       0     0        1   7
      124       0     1        1   7
      125       0     0        1   7
      125       0     1        1   7
      126       0     0        1   7
      126       0     1        1   7
      128       0     0        1   4
      128       0     1        2   4
      129       0     0        1   4
      129       0     1        2   4
      130       0     0        1   4
      130       0     1        2   4
      131       0     0        1   4
      131       0     1        2   4
      132       0     0        1   2
      132       0     1        3   2
      133       0     0        1   2
      133       0     1        3   2
      134       0     0        1   1
      134       0     1        4   1
      135       0     0        2  14
      135       0     1        1  14
      136       0     0        2  14
      136       0     1        1  14
      137       0     0        2  14
      137       0     1        1  14
      138       0     0        2  14
      138       0     1        1  14
      139       0     0        2  14
      139       0     1        1  14
      140       0     0        2  14
      140       0     1        1  14
      141       0     0        2  14
      141       0     1        1  14
      142       0     0        2  14
      142       0     1        1  14
      143       0     0        2  14
      143       0     1        1  14
      144       0     0        2  14
      144       0     1        1  14
      145       0     0        2  14
      145       0     1        1  14
      146       0     0        2  14
      146       0     1        1  14
      147       0     0        2  14
      147       0     1        1  14
      148       0     0        2  14
      148       0     1        1  14
      149       0     0        2   5
      149       0     1        2   5
      150       0     0        2   5
      150       0     1        2   5
      151       0     0        2   5
      151       0     1        2   5
      152       0     0        2   5
      152       0     1        2   5
      153       0     0        2   5
      153       0     1        2   5
      154       0     0        2   1
      154       0     1        3   1
      155       0     0        3   6
      155       0     1        1   6
      156       0     0        3   6
      156       0     1        1   6
      157       0     0        3   6
      157       0     1        1   6
      158       0     0        3   6
      158       0     1        1   6
      159       0     0        3   6
      159       0     1        1   6
      160       0     0        3   6
      160       0     1        1   6
      161       0     0        3   9
      161       0     1        2   9
      162       0     0        3   9
      162       0     1        2   9
      163       0     0        3   9
      163       0     1        2   9
      164       0     0        3   9
      164       0     1        2   9
      165       0     0        3   9
      165       0     1        2   9
      166       0     0        3   9
      166       0     1        2   9
      167       0     0        3   9
      167       0     1        2   9
      168       0     0        3   9
      168       0     1        2   9
      169       0     0        3   9
      169       0     1        2   9
      170       0     0        3  18
      170       0     1        3  18
      171       0     0        3  18
      171       0     1        3  18
      172       0     0        3  18
      172       0     1        3  18
      173       0     0        3  18
      173       0     1        3  18
      174       0     0        3  18
      174       0     1        3  18
      175       0     0        3  18
      175       0     1        3  18
      176       0     0        3  18
      176       0     1        3  18
      177       0     0        3  18
      177       0     1        3  18
      178       0     0        3  18
      178       0     1        3  18
      179       0     0        3  18
      179       0     1        3  18
      180       0     0        3  18
      180       0     1        3  18
      181       0     0        3  18
      181       0     1        3  18
      182       0     0        3  18
      182       0     1        3  18
      183       0     0        3  18
      183       0     1        3  18
      184       0     0        3  18
      184       0     1        3  18
      185       0     0        3  18
      185       0     1        3  18
      186       0     0        3  18
      186       0     1        3  18
      187       0     0        3  18
      187       0     1        3  18
      188       0     0        3   2
      188       0     1        4   2
      189       0     0        3   2
      189       0     1        4   2
      190       0     0        4   4
      190       0     1        1   4
      191       0     0        4   4
      191       0     1        1   4
      192       0     0        4   4
      192       0     1        1   4
      193       0     0        4   4
      193       0     1        1   4
      194       0     0        4  11
      194       0     1        2  11
      195       0     0        4  11
      195       0     1        2  11
      196       0     0        4  11
      196       0     1        2  11
      197       0     0        4  11
      197       0     1        2  11
      198       0     0        4  11
      198       0     1        2  11
      199       0     0        4  11
      199       0     1        2  11
      200       0     0        4  11
      200       0     1        2  11
      201       0     0        4  11
      201       0     1        2  11
      202       0     0        4  11
      202       0     1        2  11
      203       0     0        4  11
      203       0     1        2  11
      204       0     0        4  11
      204       0     1        2  11
      205       0     0        4  14
      205       0     1        3  14
      206       0     0        4  14
      206       0     1        3  14
      207       0     0        4  14
      207       0     1        3  14
      208       0     0        4  14
      208       0     1        3  14
      209       0     0        4  14
      209       0     1        3  14
      210       0     0        4  14
      210       0     1        3  14
      211       0     0        4  14
      211       0     1        3  14
      212       0     0        4  14
      212       0     1        3  14
      213       0     0        4  14
      213       0     1        3  14
      214       0     0        4  14
      214       0     1        3  14
      215       0     0        4  14
      215       0     1        3  14
      216       0     0        4  14
      216       0     1        3  14
      217       0     0        4  14
      217       0     1        3  14
      218       0     0        4  14
      218       0     1        3  14
      219       0     0        4  22
      219       0     1        4  22
      220       0     0        4  22
      220       0     1        4  22
      221       0     0        4  22
      221       0     1        4  22
      222       0     0        4  22
      222       0     1        4  22
      223       0     0        4  22
      223       0     1        4  22
      224       0     0        4  22
      224       0     1        4  22
      225       0     0        4  22
      225       0     1        4  22
      226       0     0        4  22
      226       0     1        4  22
      227       0     0        4  22
      227       0     1        4  22
      228       0     0        4  22
      228       0     1        4  22
      229       0     0        4  22
      229       0     1        4  22
      230       0     0        4  22
      230       0     1        4  22
      231       0     0        4  22
      231       0     1        4  22
      232       0     0        4  22
      232       0     1        4  22
      233       0     0        4  22
      233       0     1        4  22
      234       0     0        4  22
      234       0     1        4  22
      235       0     0        4  22
      235       0     1        4  22
      236       0     0        4  22
      236       0     1        4  22
      237       0     0        4  22
      237       0     1        4  22
      238       0     0        4  22
      238       0     1        4  22
      239       0     0        4  22
      239       0     1        4  22
      127       0     0        4  22
      127       0     1        4  22
;
proc genmod;  class case;
  model outcome = treat occasion treat*occasion / dist=multinomial link=clogit;
  repeated subject=case / type=indep corrw;
proc nlmixed;
  eta1 = alpha1 + beta1*treat + beta2*occasion + beta3*treat*occasion + u;
  eta2 = alpha1 + i2 + beta1*treat + beta2*occasion + beta3*treat*occasion + u;
  eta3 = alpha1 + i2 + i3 + beta1*treat + beta2*occasion + beta3*treat*occasion + u;
  if (outcome=1) then p = exp(eta1)/(1 + exp(eta1));
  else if (outcome=2) then p = exp(eta2)/(1 + exp(eta2)) - exp(eta1)/(1 + exp(eta1));
  else if (outcome=3) then p = exp(eta3)/(1 + exp(eta3)) - exp(eta2)/(1 + exp(eta2));
  else if (outcome=4) then p = 1 - exp(eta3)/(1 + exp(eta3)); 
  ll = log(p);
  model outcome ~ general(ll);
  random u ~ normal(0, sigma*sigma) subject=case;
  estimate 'alpha2' alpha1+i2; * this is alpha_2 in model;
  estimate 'alpha3' alpha1+i2+i3;  * this is alpha_3 in model;
run;
--------------------------------------------------------------------------

SAS for Model (12.3) with Matched Pairs from Table 12.1

-------------------------------------------------------------------
data matched;
input case occasion response count ;
datalines;
 1  0 1  794     
 1  1 1  794      
 2  0 1  150      
 2  1 0  150 
 3  0 0   86      
 3  1 1   86      
 4  0 0  570      
 4  1 0  570
;
proc nlmixed;
  eta = alpha + beta*occasion + u;  p = exp(eta)/(1 + exp(eta));
  model  response ~ binary(p);
  random u ~ normal(0, sigma*sigma) subject = case;
  replicate count;
-------------------------------------------------------------------

SAS for GLMM Analyses of Election Data in Table 12.2

-----------------------------------------------------------------------------
data vote;
input y n;
case = _n_;
datalines;
1   5   
16  32  
10  19  
21  34  
129 240 
17  29  
18  25  
4   4   
2   5   
65  108 
31  56  
5   9   
11  22  
1   9   
48  89  
19  44  
6   19  
13  29  
22  33  
34  46  
18  38  
7   9   
43  73  
20  35  
23  41  
7   21  
3   7   
25  55  
3   5   
6   13  
5   9   
40  60  
6   13  
6   12  
103 137 
41  84  
11  23  
15  24  
51  90  
4   7   
16  28  
4   6   
20  40  
64  144 
5   15  
21  51  
2   4   
26  42  
19  39  
8   14  
1   4   
;
proc nlmixed;
   eta = alpha + u;  p = exp(eta) / (1 + exp(eta));
   model y ~ binomial(n,p);
   random u ~ normal(0,sigma*sigma) subject=case;
   predict p out=new;
proc print data=new;
-----------------------------------------------------------------------------

SAS for GLMM with Opinions on Abortion of Table 10.13

-----------------------------------------------------------------------------
data new;
input sex poor single any count;
datalines;
1 1 1 1 342
1 1 1 0 26
1 1 0 1 11
1 1 0 0 32
1 0 1 1 6
1 0 1 0 21
1 0 0 1 19
1 0 0 0 356
2 1 1 1 440
2 1 1 0 25
2 1 0 1 14
2 1 0 0 47
2 0 1 1 14
2 0 1 0 18
2 0 0 1 22
2 0 0 0 457
;
data new;  set new;
   sex = sex-1; case = _n_;
   q1=1; q2=0; resp = poor; output;
   q1=0; q2=1; resp = single; output;
   q1=0; q2=0; resp = any;  output;
drop poor single any;
proc nlmixed  qpoints = 50;
   parms alpha=0  beta1=.8  beta2=.3  gamma=0  sigma=8.6;
   eta = alpha + beta1*q1 + beta2*q2 + gamma*sex + u;
   p = exp(eta)/(1 + exp(eta));
   model resp ~ binary(p);
   random u ~ normal(0,sigma*sigma) subject = case;
   replicate count;
-----------------------------------------------------------------------------

SAS for GLMM for Leading Crowd Data of Table 12.8

-------------------------------------------------------------------------------
data crowd;
input mem1 att1 mem2 att2 count;
datalines;
1 1 1 1 458
1 1 1 0 140
1 1 0 1 110
1 1 0 0 49
1 0 1 1 171
1 0 1 0 182
1 0 0 1 56
1 0 0 0 87
0 1 1 1 184
0 1 1 0 75
0 1 0 1 531
0 1 0 0 281
0 0 1 1 85
0 0 1 0 97
0 0 0 1 338
0 0 0 0 554
;
data new; set crowd;
  case=_n_;
  x1m=1; x1a=0; x2m=0; x2a=0; var=1; resp=mem1; output;
  x1m=0; x1a=1; x2m=0; x2a=0; var=0; resp=att1; output;
  x1m=0; x1a=0; x2m=1; x2a=0; var=1; resp=mem2; output;
  x1m=0; x1a=0; x2m=0; x2a=1; var=0; resp=att2; output;
  drop mem1 att1 mem2 att2;
proc nlmixed data=new;
  eta=beta1m*x1m + beta1a*x1a + beta2m*x2m + beta2a*x2a + um*var + ua*(1-var);
  p=exp(eta)/(1+exp(eta));
  model resp ~ binary(p);
  random um ua ~ normal([0,0],[s1*s1, cov12, s2*s2]) subject=case;
  replicate count;
  estimate 'mem change' beta2m-beta1m; estimate 'att change' beta2a-beta1a;
-------------------------------------------------------------------------------

SAS for Cluster Sampling Data from Brier (1980)

-----------------------------------------------------------------------------
data new;
input nbhd satis_1 satis_2;
datalines;
1 1 1
1 2 1
1 2 1
1 2 2
1 2 2
2 1 1
2 2 1
2 2 1
2 2 2
2 2 2
3 1 2
3 1 2
3 2 2
3 2 2
3 3 2
4 1 2
4 2 1
4 2 1
4 2 2
4 3 1
5 2 2
5 2 2
5 2 2
5 2 2
5 3 2
6 1 1
6 2 1
6 2 1
6 2 1
6 2 2
7 1 1
7 1 1
7 1 1
7 2 2
7 3 2
8 1 1
8 2 1
8 2 2
8 2 2
8 2 2
9 1 1
9 1 1
9 1 1
9 3 1
9 3 3
10 1 2
10 2 2
10 2 2
10 2 2
10 2 3
11 1 1
11 1 2
11 2 2
11 2 2
11 3 1
12 1 2
12 2 1
12 2 1
12 2 1
12 2 1
13 2 1
13 2 1
13 2 1
13 2 1
13 2 2
14 2 1
14 2 2
14 2 2
14 3 3
14 3 3
15 1 1
15 1 1
15 2 1
15 2 1
15 2 2
16 1 1
16 2 1
16 2 2
17 2 1
17 2 2
17 2 3
17 3 2
17 3 2
18 2 1
18 2 3
18 3 3
19 1 1
19 1 1
19 2 1
19 2 1
19 2 2
20 1 1
20 1 1
20 2 1
20 2 1
20 3 1
;

proc logistic;
model satis_2 = satis_1;
run;

data new;
set new;
if satis_2 = 1 then do;
   y1 = 1; y2 = 0; y3 = 0;
end;
else if satis_2 = 2 then do;
   y1 = 0; y2 = 1; y3 = 0;
end;
else if satis_2 = 3 then do;
   y1 = 0; y2 = 0; y3 = 1;
end;
else delete;

proc nlmixed data=new qpoints = 20;
   *parms i1 = i2 = sigma=;
   bounds i2 > 0;

   eta1 = i1 + Beta * satis_1 + u;
   eta2 = i1 + i2 + Beta * satis_1 + u;

   p1 = 1/(1+exp(-eta1));
   p2 = 1/(1+exp(-eta2)) - 1/(1+exp(-eta1));
   p3 = 1 - 1/(1+exp(-eta2));

   **  Multinomial likelihood **;

   z = (p1**y1)*(p2**y2)*(p3**y3);

   **  Check for small values of z **;

   if (z > 1e-8) then ll = log(z);
     else ll=-1e100;

   **  Define general log-likelihood.  I think you can put any
   variable **;
   **  before the tilde (ie. y1 or y2 or y3).
   **;

   model y1 ~ general(ll);

   **  Estimate second threshold. **;

   estimate 'thresh2' i1+i2;
   random u ~ normal(0,sigma*sigma) subject = nbhd;
run;
-------------------------------------------------------------------------------

SAS for Overdispersion Analyses of Table 4.5

-----------------------------------------------------------------------------
data moore;
input litter group n y ;
  z2=0; z3=0; z4=0;
  if group=2 then z2=1; if group=3 then z3=1; if group=4 then z4=1;
datalines;
 1  1 10 1   
 2 1 11 4   
 3 1 12 9   
 4 1 4 4     
 5 1 10 10   
 6 1 11 9
 7  1 9  9   
 8 1 11 11  
 9 1 10 10  
 10 1 10 7  
 11 1 12 12  
 12 1 10 9
 13 1 8  8  
 14 1 11  9 
 15 1 6  4   
 16 1  9 7  
 17 1 14 14  
 18 1 12 7
 19 1 11 9  
 20 1 13 8  
 21 1 14 5   
 22 1 10 10 
 23 1 12 10  
 24 1 13 8
 25 1 10 10 
 26 1 14 3  
 27 1 13 13  
 28 1 4 3   
 29 1  8  8  
 30 1 13 5
 31 1 12 12 
 32 2 10 1  
 33 2  3  1  
 34 2 13 1  
 35 2 12  0  
 36 2 14 4
 37 2  9  2 
 38 2 13 2  
 39 2 16  1  
 40 2 11 0  
 41 2  4  0  
 42 2 1  0
 43 2 12 0  
 44 3  8 0  
 45 3 11  1  
 46 3 14 0  
 47 3 14 1   
 48 3 11 0
 49 4  3 0   
 50 4 13 0  
 51 4 9   2  
 52 4 17 2  
 53 4 15 0   
 54 4 2 0
 55 4 14 1  
 56 4 8  0  
 57 4 6  0   
 58 4 17 0
;
proc logistic; 
   model y/n = z2 z3 z4 / scale=williams;
proc logistic; 
   model y/n = z2 z3 z4 / scale=pearson;
proc nlmixed  qpoints=200;
  eta = alpha + beta2*z2 + beta3*z3 + beta4*z4 + u ; 
  p = exp(eta)/(1 + exp(eta));
  model y ~ binomial(n,p) ;
  random u ~ normal(0, sigma*sigma) subject=litter; 
-----------------------------------------------------------------------------

SAS for Modeling Murder Data of Table 13.6

-----------------------------------------------------------------------------
data new;
input white black other response;
datalines;
1070 119 55 0
  60  16  5 1
  14  12  1 2
   4   7  0 3
   0   3  1 4
   0   2  0 5
   1   0  0 6
;
data new; set new; count = white; race = 0; output;
   count = black; race = 1; output; drop white black other;
data new2; set new; do i = 1 to count; output; end; drop i;
proc genmod data=new2;
   model response = race / dist=negbin link=log;
proc genmod data=new2;
   model response = race / dist=poi link=log scale=pearson;
data new; set new; case = _n_;
proc nlmixed  data = new  qpoints=400;
   parms alpha=-3.7 beta=1.90 sigma=1.6;
   eta = alpha + beta*race + u;  mu = exp(eta);
   model response ~ poisson(mu);
   random  u ~ normal(0, sigma*sigma) subject=case;
   replicate count;
-----------------------------------------------------------------------------



Copyright © 2002, Alan Agresti, Department of Statistics, University of Florida.



next up previous
Next:
Alan Agresti 2001-12-27