1. Visualizing the Cox model
In this video, we will discuss how to visualize the Cox model. It is easier than visualizing the Weibull model, so I am sure you will do very well!
2. Steps to visualize a Cox model
The steps for visualizing Cox models are essentially the same as for Weibull models. There are some details which differ between the visualization process of the two models and we will discuss them in the following.
3. Step 1: Compute Cox model
You already know how to do the first two steps. You have already practiced the first step in the exercise. The second step is the same as in Weibull model visualization. We again define the imaginary patients based on the levels of hormonal therapy, which are "no" and "yes", as well as some quantiles of the tumor size. We want to give rownames to the newdat object that we can remember. To make it simple we use letters a-f. We will need these rownames in the upcoming steps.
4. Step 2: Compute survival curves
We can now use the survfit() function to compute survival curves. Do you remember what we used this function for before? Right. For computing Kaplan-Meier curves.
When entering a Cox model instead of a formula, you get the survival curves estimated by the Cox model instead of the Kaplan-Meier estimates. We set conf-dot-type to "none" because we don't need confidence intervals. Note here, that the survival curve info in this object, has the same names as the row names we gave to the newdat data frame. The function automatically does that for us.
5. Step 3: Create data.frame with survival curve information
In this step, we use the surv_summary function provided by the survminer package to compute the data.frame with the survival curve info we need. At this point, we again need the row names we created before because this is what the surv_summary function outputs as "strata". We add two more columns to the data frame with the info on the covariate combinations of tumor size (tsize) and hormonal therapy (horTh). For this, we select for every row in the data frame the row of newdat that corresponds to the correct variable combination and combine it with the survival curve information using the cbind() function. If this seems complicated to you now, don't worry. We'll go through this step by step again in the exercise and you can thoroughly look at the different R objects.
6. Step 4: Plot
The last step of plotting the curves is again already familiar to you. We use the ggsurvplot_df() function, add the survival curve information as the first argument and specify the linetype according to the hormonal therapy and the color according to the tumor size. As before we use legend-dot-title = NULL to have a nice legend. We also set censor to FALSE, because having the censoring ticks clutters the visualization too much. You could also set this to TRUE if you prefer.
7. Now it's your turn to visualize!
The steps may seem daunting now, but once you go through the exercises you will see, that you can do it, too!