/*TEST 1 of the LINEARITY ASSUMPTION /*TEST of linearity assumption for continuous predictors in Cox Regression STEPS: 1. Divide your continuous predictor into some number of even bins (quartiles, quintiles, deciles, etc.). 2. Record the mean value of your continuous predictor in each bin (this will be used later in graphing). 3. Treat this bin variable as a categorical predictor in Cox regression (use a dummy code for each bin). 4. Save the beta for each bin (from the fitted model) into a new SAS dataset. 5. Plot these fitted betas against the mean value of your continuous predictor in each bin. 6. This should be roughly a straight line. */ /*DIVIDE your continuous predictor variable (here: depression score) up into some number of bins; here=10*/ proc rank data=hrp262.uis bin=10 out=ranks; var becktota; ranks bins; run; /*Record the mean value of depression score in each bin*/ proc means data=ranks mean; class bins; var becktota; run; /*Dummy code your bin variable for use in PROC PHREG*/ data ranks; set ranks; bin1=(bins=0); bin2=(bins=1); bin3=(bins=2); bin4=(bins=3); bin5=(bins=4); bin6=(bins=5); bin7=(bins=6); bin8=(bins=7); bin9=(bins=8); bin10=(bins=9); run; /*Run your Cox regression model with your dummy coded bin variable to obtain betas for each bin*/ proc phreg data=ranks; model time*censor(0)=age ndrugtx bin1 bin2 bin3 bin4 bin5 bin6 bin7 bin8 bin9 bin10; ods output parameterestimates=betas; run; /*Create one variable "binmean" that stores the mean value of depression score for each bin*/ data betas; set betas; if variable = 'bin1' then binmean = 3; if variable = 'bin2' then binmean = 7.2; if variable = 'bin3' then binmean = 10; if variable = 'bin4' then binmean = 13; if variable = 'bin5' then binmean = 15.5; if variable = 'bin6' then binmean= 18; if variable = 'bin7' then binmean = 20.8; if variable = 'bin8' then binmean = 23.6; if variable = 'bin9' then binmean = 27.6; if variable = 'bin10' then binmean = 35; run; /*PLOT the betas against the bin means and assess linearity*/ proc gplot data=betas; plot estimate*binmean ; symbol v=dot i=sm80s; label binmeanl='Mean Level'; title 'Assess the Linearity Assumption of Depression Score'; run; quit; /*TEST 2 of the LINEARITY ASSUMPTION /*An alternative test of the linearity assumption is to plot each continuous predictor variable against the martingale residuals from a Cox regression model that EXCLUDES the predictor, as follows:*/ /* Run the Cox regression model excluding your continuous predictor, here Beck depression score*/ /*Output the martingale residuals from this model*/ proc phreg data=hrp262.uis noprint; model time*censor(0)=age ndrugtx; id becktota; *This tells SAS to also include the variable becktota in the output dataset even though it is not part of the model; output out=residuals resmart=martingales; run; /*Plot the martingale residuals against depression score to look for linearity*/ proc gplot data=residuals; plot martingales*becktota ; symbol1 v=dot i=sm90s; title 'Assess the Linearity Assumption of Depression Score'; run; quit;