Hello,
I am trying to check the linearity assumption of my covariates as well as the PH assumption. Knowing that all my covariates are time varying (the value can change many times during the follow up) is it possible to check for the lineraity as well as PH assumption?
I am trying tu use this code:
ODS GRAPHICS ON;
proc phreg data=data1;
Model(start,stop)*event(0)=x1 x2 x3 x4 x5 x6;
assess var=(x1 x2 )/resample;
run;
ODS GRAPHICS Off;
But this code did not work with the counting process neither the programming statement code.
Is there any other way to plot martingal and shoenfeld residuals ?
Thank you in advance.
Hi there,
As printed in the log:
NOTE: Model assessment is not available with the counting process style of input. The ASSESS statement is ignored.
You can however still calculate the Martingale and Schoenfeld residuals by using the OUTPUT statement:
proc phreg data=data1;
Model(start,stop)*event(0)=x1 x2 x3 x4 x5 x6;
output out=output_dsn resmart=Mart RESSCH=schoenfeld;
run;
Next you will have to plot it for each variable, for example using PROC LOESS which plots us a nice smoothing spline to help discover the (residual) functional form of the covariate:
ods output on;
proc loess data=Out1 plots(only)=(fit);
model Mart=x1 /CLM smooth=0.5;
ods output OutputStatistics=Results;
run;
You can do the same thing for plotting Schoenfeld residuals over time. If you need a formal test you can perform a simple linear regression where the dependent variable is the Schoenfeld residual and the independent variable is time. As an extra caveat introduced by working with time dependent covariates, you will have to reweight the rows in the dataset based on which proportion of the patient survival time they represen. Otherwise you would be introducing bias by having clustered rows belonging to the same patient.
Me personally I like to test covariates before I enter them in the model by fitting a null model and plotting the residuals. This allows you to gain insight in the true functional form of the covariate. To throw that all together it would look something like this:
data _dummy_abt;
set &table;
dummy=0;
keep dummy &var_time &var_event &var;
run;
proc phreg data=_dummy_abt;
model &var_time*&var_event(0)=dummy;
output out=_out resmart=rr
/order=data;
run;
ods graphics on;
proc loess data=Out1 plots(only)=(fit);
model resmart=x1 /CLM smooth=0.5;
ods output OutputStatistics=Results;
run;
proc datasets lib=work;
delete _dummy_abt _out;
run;
You can write a macro to loop over the variables.
For more details on model assessment see Thomas R Fleming and David P Harrington. Counting processes and survival analysis, volume 8. Wiley Online Library, 1991.
Hi,
Thank you for your help... it works for schoenfeld residuals but for martingale residuals it gave me many residuals for the same subject as shown in the table:
id | start | stop | x1 | martingale |
1 | 1 | 3 | 2 | r1 |
1 | 3 | 5 | 5 | r2 |
1 | 5 | 10 | 4 | r3 |
1 | 10 | 19 | 7 | r4 |
1 | 19 | 20 | 8 | r5 |
1 | 20 | 21 | 10 | . |
Is it correct to plot martingale residuals with many residuals for each subject ? is there anyway to aggregate them ?
If i need to have one residual for each subject, can i sum the residuals per subject ?
Thank you in advance,
Aya
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: