DATA preg; INPUT obsno duration y1 y2 y3 nutrition age20less age30more alcohol smoking; cards; 1 1 1 0 0 150 0 0 0 1 2 1 1 0 0 124 1 0 0 0 3 1 1 0 0 128 0 0 0 1 4 1 1 0 0 128 1 0 0 1 5 1 1 0 0 133 0 0 1 1 6 1 1 0 0 130 0 0 1 1 7 1 1 0 0 154 0 0 0 0 8 1 1 0 0 110 1 0 0 0 9 1 1 0 0 104 0 0 1 1 10 1 1 0 0 133 0 0 0 1 11 1 1 0 0 144 0 0 1 0 12 1 1 0 0 128 0 0 1 1 13 1 1 0 0 102 0 0 0 1 14 1 1 0 0 127 0 0 1 1 15 1 1 0 0 111 0 0 1 1 16 1 1 0 0 100 0 0 0 0 17 1 1 0 0 128 1 0 0 0 18 1 1 0 0 102 0 1 0 0 19 1 1 0 0 94 0 0 1 0 20 1 1 0 0 117 0 1 1 0 21 1 1 0 0 97 1 0 1 1 22 1 1 0 0 139 0 1 1 1 23 1 1 0 0 125 0 1 1 1 24 1 1 0 0 149 0 1 0 1 25 1 1 0 0 150 0 1 1 1 26 1 1 0 0 137 1 0 1 0 27 2 0 1 0 130 0 0 0 0 28 2 0 1 0 122 0 0 0 0 29 2 0 1 0 99 1 0 0 0 30 2 0 1 0 122 1 0 0 0 31 2 0 1 0 111 0 0 0 1 32 2 0 1 0 124 0 0 0 1 33 2 0 1 0 123 0 0 0 1 34 2 0 1 0 121 0 0 0 1 35 2 0 1 0 139 0 0 1 0 36 2 0 1 0 110 0 0 0 1 37 2 0 1 0 122 0 0 0 1 38 2 0 1 0 144 1 0 0 0 39 2 0 1 0 127 1 0 0 0 40 2 0 1 0 125 0 0 1 0 41 2 0 1 0 122 1 0 0 0 42 2 0 1 0 127 1 0 0 0 43 2 0 1 0 114 0 1 0 1 44 2 0 1 0 143 0 1 1 0 45 2 0 1 0 148 1 0 0 1 46 2 0 1 0 144 0 1 0 1 47 2 0 1 0 174 0 1 1 0 48 2 0 1 0 131 0 1 0 1 49 2 0 1 0 134 0 0 1 1 50 2 0 1 0 124 0 1 0 1 51 2 0 1 0 142 1 0 1 0 52 2 0 1 0 133 0 0 1 1 53 2 0 1 0 113 1 0 0 1 54 2 0 1 0 126 0 1 0 0 55 2 0 1 0 104 0 1 0 1 56 2 0 1 0 144 1 0 0 1 57 2 0 1 0 134 1 0 0 1 58 2 0 1 0 130 0 0 1 1 59 2 0 1 0 127 0 0 1 0 60 2 0 1 0 135 0 0 1 1 61 2 0 1 0 164 0 0 1 1 62 3 0 0 1 181 0 0 0 1 63 3 0 0 1 130 0 0 0 0 64 3 0 0 1 185 0 0 0 0 65 3 0 0 1 160 0 0 0 1 66 3 0 0 1 165 0 0 0 0 67 3 0 0 1 161 0 0 0 0 68 3 0 0 1 110 0 0 0 0 69 3 0 0 1 110 0 0 0 0 70 3 0 0 1 150 0 0 1 0 71 3 0 0 1 119 0 0 1 0 72 3 0 0 1 104 0 0 0 0 73 3 0 0 1 120 0 0 0 0 74 3 0 0 1 133 0 0 0 0 75 3 0 0 1 135 0 0 0 0 76 3 0 0 1 150 0 0 1 0 77 3 0 0 1 179 0 0 1 0 78 3 0 0 1 194 0 1 0 0 79 3 0 0 1 179 0 0 1 0 80 3 0 0 1 190 1 0 0 0 81 3 0 0 1 165 0 0 0 1 82 3 0 0 1 155 0 0 0 1 83 3 0 0 1 159 0 1 0 0 84 3 0 0 1 132 0 1 0 0 85 3 0 0 1 130 0 0 0 1 86 3 0 0 1 152 0 0 0 1 87 3 0 0 1 152 0 1 0 0 88 3 0 0 1 180 0 0 0 1 89 3 0 0 1 109 0 0 1 0 90 3 0 0 1 152 0 0 0 1 91 3 0 0 1 117 0 0 1 0 92 3 0 0 1 139 0 1 0 0 93 3 0 0 1 149 0 0 0 1 94 3 0 0 1 170 0 0 0 1 95 3 0 0 1 139 1 0 0 0 96 3 0 0 1 135 1 0 0 0 97 3 0 0 1 115 0 1 0 0 98 3 0 0 1 144 1 0 0 0 99 3 0 0 1 102 0 0 1 0 100 3 0 0 1 117 0 0 1 1 101 3 0 0 1 165 0 0 1 1 102 3 0 0 1 134 0 0 1 1 ; run; /* Some plots of the data */ PROC SGPLOT data=preg; SCATTER y=duration x=nutrition / group = alcohol; run; PROC SGPLOT data=preg; SCATTER y=duration x=nutrition / group = smoking; run; PROC LOGISTIC data=preg outest=preg_param descending; CLASS duration (ref = "3") age20less (ref= "0") age30more (ref= "0") alcohol (ref="0") smoking (ref="0") / param = ref; MODEL duration = nutrition age20less age30more alcohol smoking / link=glogit; OUTPUT out=probs predicted = prob xbeta=logit; run; proc transpose data = preg_param; run; proc print noobs; run; /* Testing whether the nutrition effect in the intermediate model equals the nutrition effect in the preterm model */ PROC LOGISTIC data=preg outest=preg_param descending; CLASS duration (ref = "3") age20less (ref= "0") age30more (ref= "0") alcohol (ref="0") smoking (ref="0") / param = ref; MODEL duration = nutrition age20less age30more alcohol smoking / link=glogit; OUTPUT out=probs predicted = prob xbeta=logit; nut_intermed_vs_nut_preterm: TEST nutrition_2 - nutrition_1; run; /* Predicting the category probabilities for a new individual with nutrition = 120, teenaged, non-smoking, alcohol drinker: */ data one; INPUT obsno duration y1 y2 y3 nutrition age20less age30more alcohol smoking; cards; 103 . . . . 120 1 0 1 0 ; run; data preg; set preg one; run; PROC LOGISTIC data=preg outest=preg_param descending; CLASS duration (ref = "3") age20less (ref= "0") age30more (ref= "0") alcohol (ref="0") smoking (ref="0") / param = ref; MODEL duration = nutrition age20less age30more alcohol smoking / link=glogit; OUTPUT out=probs2 predicted = prob xbeta=logit; run; proc print data=probs2; run; /*******************************/ /* Ordinal Logistic regression */ /*******************************/ DATA preg; INPUT obsno duration y1 y2 y3 nutrition age20less age30more alcohol smoking; cards; 1 1 1 0 0 150 0 0 0 1 2 1 1 0 0 124 1 0 0 0 3 1 1 0 0 128 0 0 0 1 4 1 1 0 0 128 1 0 0 1 5 1 1 0 0 133 0 0 1 1 6 1 1 0 0 130 0 0 1 1 7 1 1 0 0 154 0 0 0 0 8 1 1 0 0 110 1 0 0 0 9 1 1 0 0 104 0 0 1 1 10 1 1 0 0 133 0 0 0 1 11 1 1 0 0 144 0 0 1 0 12 1 1 0 0 128 0 0 1 1 13 1 1 0 0 102 0 0 0 1 14 1 1 0 0 127 0 0 1 1 15 1 1 0 0 111 0 0 1 1 16 1 1 0 0 100 0 0 0 0 17 1 1 0 0 128 1 0 0 0 18 1 1 0 0 102 0 1 0 0 19 1 1 0 0 94 0 0 1 0 20 1 1 0 0 117 0 1 1 0 21 1 1 0 0 97 1 0 1 1 22 1 1 0 0 139 0 1 1 1 23 1 1 0 0 125 0 1 1 1 24 1 1 0 0 149 0 1 0 1 25 1 1 0 0 150 0 1 1 1 26 1 1 0 0 137 1 0 1 0 27 2 0 1 0 130 0 0 0 0 28 2 0 1 0 122 0 0 0 0 29 2 0 1 0 99 1 0 0 0 30 2 0 1 0 122 1 0 0 0 31 2 0 1 0 111 0 0 0 1 32 2 0 1 0 124 0 0 0 1 33 2 0 1 0 123 0 0 0 1 34 2 0 1 0 121 0 0 0 1 35 2 0 1 0 139 0 0 1 0 36 2 0 1 0 110 0 0 0 1 37 2 0 1 0 122 0 0 0 1 38 2 0 1 0 144 1 0 0 0 39 2 0 1 0 127 1 0 0 0 40 2 0 1 0 125 0 0 1 0 41 2 0 1 0 122 1 0 0 0 42 2 0 1 0 127 1 0 0 0 43 2 0 1 0 114 0 1 0 1 44 2 0 1 0 143 0 1 1 0 45 2 0 1 0 148 1 0 0 1 46 2 0 1 0 144 0 1 0 1 47 2 0 1 0 174 0 1 1 0 48 2 0 1 0 131 0 1 0 1 49 2 0 1 0 134 0 0 1 1 50 2 0 1 0 124 0 1 0 1 51 2 0 1 0 142 1 0 1 0 52 2 0 1 0 133 0 0 1 1 53 2 0 1 0 113 1 0 0 1 54 2 0 1 0 126 0 1 0 0 55 2 0 1 0 104 0 1 0 1 56 2 0 1 0 144 1 0 0 1 57 2 0 1 0 134 1 0 0 1 58 2 0 1 0 130 0 0 1 1 59 2 0 1 0 127 0 0 1 0 60 2 0 1 0 135 0 0 1 1 61 2 0 1 0 164 0 0 1 1 62 3 0 0 1 181 0 0 0 1 63 3 0 0 1 130 0 0 0 0 64 3 0 0 1 185 0 0 0 0 65 3 0 0 1 160 0 0 0 1 66 3 0 0 1 165 0 0 0 0 67 3 0 0 1 161 0 0 0 0 68 3 0 0 1 110 0 0 0 0 69 3 0 0 1 110 0 0 0 0 70 3 0 0 1 150 0 0 1 0 71 3 0 0 1 119 0 0 1 0 72 3 0 0 1 104 0 0 0 0 73 3 0 0 1 120 0 0 0 0 74 3 0 0 1 133 0 0 0 0 75 3 0 0 1 135 0 0 0 0 76 3 0 0 1 150 0 0 1 0 77 3 0 0 1 179 0 0 1 0 78 3 0 0 1 194 0 1 0 0 79 3 0 0 1 179 0 0 1 0 80 3 0 0 1 190 1 0 0 0 81 3 0 0 1 165 0 0 0 1 82 3 0 0 1 155 0 0 0 1 83 3 0 0 1 159 0 1 0 0 84 3 0 0 1 132 0 1 0 0 85 3 0 0 1 130 0 0 0 1 86 3 0 0 1 152 0 0 0 1 87 3 0 0 1 152 0 1 0 0 88 3 0 0 1 180 0 0 0 1 89 3 0 0 1 109 0 0 1 0 90 3 0 0 1 152 0 0 0 1 91 3 0 0 1 117 0 0 1 0 92 3 0 0 1 139 0 1 0 0 93 3 0 0 1 149 0 0 0 1 94 3 0 0 1 170 0 0 0 1 95 3 0 0 1 139 1 0 0 0 96 3 0 0 1 135 1 0 0 0 97 3 0 0 1 115 0 1 0 0 98 3 0 0 1 144 1 0 0 0 99 3 0 0 1 102 0 0 1 0 100 3 0 0 1 117 0 0 1 1 101 3 0 0 1 165 0 0 1 1 102 3 0 0 1 134 0 0 1 1 ; run; /* Proportional Odds Model (assumes common slope) */ PROC LOGISTIC data=preg; MODEL duration = nutrition age20less age30more alcohol smoking; OUTPUT out=probsPO predicted = prob xbeta=logit; run; /* Here the Proportional Odds model fits well. */ /* If the common slope assumption of the proportional odds model is doubtful, */ /* PROC CATMOD fits a cumulative logit model with separate slope parameters. */ /* PROC CATMOD can also fit a generalized logit model. */ /* Predicting the category probabilities for a new individual with nutrition = 120, teenaged, non-smoking, alcohol drinker: */ data one; INPUT obsno duration y1 y2 y3 nutrition age20less age30more alcohol smoking; cards; 103 . . . . 120 1 0 1 0 ; run; data preg; set preg one; run; PROC LOGISTIC data=preg; MODEL duration = nutrition age20less age30more alcohol smoking; OUTPUT out=probsPO2 predicted = prob xbeta=logit; run; proc print data=probsPO2; run;