I have a significant interaction that I want to explore further. I'm not the best with contrast coding and most of the examples I'm finding are either 3-way interactions or those with all class variables or a combo class/continuous. Here are the basics of my model:
ODS RTF;
ODS GRAPHICS ON;
PROC LOGISTIC DATA=work.data1 DESCENDING SIMPLE PLOTS=ALL;
CLASS a (REF='0') b (REF='0') / PARAM=reference ;
MODEL y = a b c d c*d / EXPB CL INFLUENCE ;
ODDSRATIO c / AT(d = 0 1) CL=WALD;
ODDSRATIO d / AT(c = 0 1) CL=WALD;
CONTRAST 'c=1 & d=0' c 1 d 0 /ESTIMATE = PARM E;
CONTRAST 'c=1 & d=1' c 1 d 1 /ESTIMATE = PARM E;
CONTRAST 'c=0 & d=0' c 0 d 0 /ESTIMATE = PARM E;
CONTRAST 'c=0 & d=1' c 0 d 1 /ESTIMATE = PARM E;
UNITS / DEFAULT=1;
OUTPUT OUT=Results;
RUN;
ODS GRAPHICS OFF;
For this model, y is binary (0,1), a and b and both categorical with numerous levels, and c and d are continuous binary (0,1) variables. What I want is to get estimates/odds ratios for all levels of the interaction, which is p<.01. I don't think this code is correct, but I have a feeling I'm close. Any advice would be appreciated!
Hello @NMB82,
Your ODDSRATIO statements are correct. Option "CL=WALD" is the default, though, hence redundant. Also redundant are the UNITS statement (unit 1 is the default) and three of the CONTRAST statements: The third is trivial, the first and the fourth repeat the results for the parameters of c and d.
From the ODDSRATIO statements you already get the odds ratios (and pertinent confidence limits) for (c,d)= (1, 0) vs. (0, 0), (1, 1) vs. (0, 1), (0, 1) vs. (0, 0) and (1, 1) vs. (1, 0), all adjusted for a and b. The second CONTRAST statement suggests that you're also interested in the odds ratio "(1, 1) vs. (0, 0)", but for this you would need to use the ESTIMATE=EXP option and to insert the interaction term c*d 1 into the list of effects and values. You can get both the estimate (here: of the sum of the estimates for c, d and c*d) and the odds ratio (i.e. the exponentiated estimate) with a similar ESTIMATE statement. Here's an ESTIMATE statement that in addition (just for completeness and as another example) includes the remaining odds ratio "(1, 0) vs. (0, 1)":
estimate 'c=1, d=0 vs. c=0, d=1' c 1 d -1,
'c=1, d=1 vs. c=0, d=0' c 1 d 1 c*d 1 / e cl exp;
You don't need any of the ODDSRATIO or CONTRASTS statements. You can get all possible pairwise comparisons of the four C*D levels using a single LSMEANS statement:
PROC LOGISTIC DATA=work.data1;
CLASS a (REF='0') b (REF='0') c d / PARAM=glm ;
MODEL y(event="1") = a b c d c*d;
lsmeans c*d / ilink cl diff oddsratio;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.