options pagesize=150 linesize=68;
filename grafout 'g08.ps';
goptions device=pslmono gsfname=grafout 
   rotate=landscape gsfmode=append;
/********************************************************/
/* Laundry data from Cox and Snell (1981) Applied Stat- */
/* istics.  Variables are count, temperature (low or    */
/* high), previous user of standard detergent (no or    */
/* yes, preference (new or old), and water hardness.    */
/********************************************************/
data laundry; input n tl mpu nr ws @@; cards;
 68 0 0 0 0 42 1 0 0 0  37 0 1 0 0 24 1 1 0 0
110 0 0 1 0 72 1 0 1 0  89 0 1 1 0 67 1 1 1 0
 66 0 0 0 1 33 1 0 0 1  47 0 1 0 1 23 1 1 0 1
116 0 0 1 1 56 1 0 1 1 102 0 1 1 1 70 1 1 1 1
 63 0 0 0 2 29 1 0 0 2  57 0 1 0 2 19 1 1 0 2
116 0 0 1 2 56 1 0 1 2 106 0 1 1 2 48 1 1 1 2
; run;
proc sort data=laundry; by tl mpu ws nr; run;
data laundry; set laundry; retain test;
   if nr=0 then test=n; if nr=1 then n=n-test;
   if ws=0 then hard="Hard";
   if ws=1 then hard="Medium";
   if ws=2 then hard="Soft";
   run;
/********************************************************/
/* Mark B: 3 regressions show that collapsing over mp   */
/* changes other interactions a bit.                    */
/********************************************************/
title 'Laundry Data With 6 2 Way Interactions';
proc genmod data=laundry; class hard ;
   model n=hard nr tl mpu hard*nr hard*tl hard*mpu
      nr*tl nr*mpu tl*mpu/dist=poisson type3; run;
title 'Laundry Data With 4 2 Way Interactions';
proc genmod data=laundry; class hard ;
   model n=hard nr tl mpu hard*tl hard*mpu nr*tl nr*mpu
      /dist=poisson  converge=1.0e-8 type3; run;
title 'Laundry Data With Prior Detergent Removed';
proc genmod data=laundry; class hard ;
   model n=hard nr tl hard*tl nr*tl /dist=poisson
       converge=1.0e-8 type3; run;
/*****************************************************/
/* Housing data from Cox and Snell (1980), Example W,*/
/* on satisfaction with housing in Copenhagen.  Data */
/* was extracted from R package MASS.  Data may also */
/* be found at                                       */
/* www.stat.ucla.edu/data/cox-and-snell/exampleW.data*/
/*****************************************************/
data housing; infile 'housing.dat'; 
   input nn sat $ infl $ type $ contact $ freq ;
   nsat=0;if sat="Medium" then nsat=1; 
   if sat="High" then nsat=2;
   ninf=0;if infl="Medium" then ninf=1; 
   if infl="High" then ninf=2;
   ncont=0;if contact="Medium" then ncont=1; 
   if contact="High" then ncont=2;
   run;
title 'Copenhagen housing data, linear by linear inter.';
/**********************************************************/
/* Mark C: Regression has linear*linear interactions show-*/
/* ing satisfaction increasing with influence, contact.   */
/**********************************************************/
proc genmod data=housing; class sat infl type contact;
   model freq=sat infl type contact nsat*ninf
      nsat*ncont/dist=poisson; run;
/*****************************************************/
/* Performing likelihood ratio test using likelihood */
/* shows richer interaction model is not necessary.  */
/*****************************************************/
title 'Housing data, larger overparameterized  model';
proc genmod data=housing; class sat infl type contact;
   model freq=sat infl type contact nsat*ninf 
      nsat*ncont sat*contact sat*infl / dist=poisson; run;