options pagesize=150 linesize=68;
filename grafout 'g13.ps';
goptions device=pscolor gsfname=grafout 
   rotate=landscape gsfmode=append;
/**************************************************************/
/* Mark A: Exact logistic regression.                         */
/**************************************************************/
/**************************************************************/
/* Data obtained from http://www-fars.nhtsa.dot.gov by re-    */
/* questing violations, accident severity, body type, speed   */
/* limit, and restraint use for NJ, 1999.  Variables are id,  */
/* id=line in the data set                                    */
/* state=34 for New Jersey                                    */
/* case=a numberof the accident                               */
/* vh=number of the vehicle within accident                   */
/* pn=number of passenger within vehicle                      */
/* sl=speed limit where the accident occurred                 */
/* bt=body type of vehicle                                    */
/* v1-v3=codes for violations cited.                          */
/* rs=whether proper restraints (ex. seat belts) were used    */
/* is=injury severity                                         */
/* Each accident potentially involves multiple vehicles, and  */
/* each vehicle potentially involves multiple passengers.     */
/* Select one vehicle (vh=1) from each crash.  Select one     */
/* passenger (pn=1) from  this vehicle.                       */
/**************************************************************/
data pairedcrash ; infile "crash.dat";
   input id state case vh pn sl bt v1 v2 v3 rs is;
   if vh=0 then delete; if vh>2 then delete; 
   if pn>1 then delete;
   fatal="Not fatal"; if is=4 then fatal="Fatal";
   vt="Car        "; if bt>10 then vt="Light truck";
   if bt>20 then vt="Van"; if bt>30 then vt="Truck";
   beltuse="Improper or no restraint use";
   beltuse="Proper restraint use";
   if rs> 12 then beltuse="Improper or no restraint use";
   if rs=0 then beltuse="Improper or no restraint use";
   if rs=. then beltuse="";
   keep case vh vt fatal beltuse;
run;
data crash; set pairedcrash; if vh=2 then delete; 
   keep vt fatal beltuse; run;
/**************************************************************/
/* Examine the data.  Note single-vehicle starata.            */
/**************************************************************/
pcrash[1:5,]
options obs=5; proc print data=pairedcrash;run;options obs=5000;
/**************************************************************/
/* A stratified approach is automatically conditional, but not*/
/* exact.  This technique cannot give an estimate for Speed   */
/* limit, since speeed limit is constant over each stratum.   */
/**************************************************************/
title 'Stratified results with 1 entry strata left in';
proc logistic data=pairedcrash; class case beltuse fatal;
   strata case; model fatal=beltuse ; run;
/**************************************************************/
/* Remove single-vehicle strata, and note identical results.  */
/**************************************************************/
title 'Stratified results with 1 entry strata removed ';
data pairedcrash; set pairedcrash; by case;
   if first.case=last.case then delete; run;
proc logistic data=pairedcrash; class case beltuse fatal;
   strata case; model fatal=beltuse; run;
/**************************************************************/
/* The above analysis gave normal theory results.  Force exact*/
/* results.                                                   */
/**************************************************************/
title 'Stratified exact results';
proc logistic data=pairedcrash; class case beltuse fatal;
   strata case; model fatal=beltuse; exact beltuse/estimate=parm; 
   run;
/**************************************************************/
/* Stratification as above indicates to SAS that it needs to  */
/* remove the intercept via conditioning.  SAS can use the in-*/
/* formation that data are in strata to more efficiently do   */
/* the exact algorithm.  The exact algorithm could also be ap-*/
/* lied directly via a class variable, but this is slow.  Om- */
/* mission of strata forces construction of agreement table   */
/* including pairs, which is not what we need.  Estimates are */
/* identical to asymptotic stratified approach, and exact     */
/* stratified approach.  Tests are the same as the exact      */
/* stratified approach.                                       */
/**************************************************************/
title 'General regression exact results';
proc logistic data=pairedcrash; class case beltuse fatal;
   model fatal=beltuse case; exact beltuse/estimate=parm; 
   run;