This is the third part of a series surrounding survival analysis. For part 1, click here. For part 2, click here.

This particular post follows the final part of fitting a Cox proportional hazards model; residual checking and model validation.

Solutions can be found for these exercises here.

**Exercise 1**

Load the survival and survminer libraries. Build our previously derived final Cox model.

**Exercise 2**

Calculate Martingale residuals and build a dataframe of these residuals with a second index column.

**Exercise 3**

Plot your Martingale residuals now.

**Exercise 4**

In a similar way to above, calculate deviance residuals, incorporate them into your residual data frame, and plot.

**Exercise 5**

Calculate the linear predictors of your final model and plot against your deviance residuals.

You may need to use ggrepel here to handle label positioning.

**Exercise 6**

Build a new dataframe containing dfbeta values for each variable within your final model.

**Exercise 7**

Using a for loop, plot each of these dfbeta residuals.

**Exercise 8**

With graphical residual plots created, formally test that the PH assumption has been met for your final model.

**Exercise 9**

Plot this now to graphically confirm your test.

**Exercise 10**

With all residuals and model checking complete, visualise your final survival curve generated by your model.

## Leave a Reply