Get startedGet started for free

Plot covariate effects on survival

Two convicts are on the waitlist to be released. You want to predict their survival function for time-to-arrest using the CoxPHFitter model you just fitted. The covariate values for the individuals are listed below:

Name fin age wexp mar paro prio
Jack 0 35 0 1 1 3
Marie 1 22 0 0 0 0

Plot Jack's and Marie's survival curves side-by-side with the baseline survival curve using cph. The fitted model cph has been loaded for you.

The CoxPHFitter class has been imported and the matplotlib.pyplot module has been imported as plt. The pandas and numpy libraries are imported as pd and np, respectively.

This exercise is part of the course

Survival Analysis in Python

View Course

Exercise instructions

  • Use .plot_partial_effects_on_outcome() to specify the covariate values (listed above) for Jack and Marie and plot their survival curves.
  • Show the plot.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot partial effects
cph.____(covariates=____,
         values=____)

# Show plot
plt.show()
Edit and Run Code