CommencerCommencer gratuitement

Senators' terms in office

You want to compare if senators from Quebec tend to serve a different term length than those from British Columbia. One simple method is to plot their Kaplan-Meier survival functions on the same graph.

The DataFrame containing British Columbia senator term durations information is called bc_df. It contains columns

  • name: the name the of senator
  • diff_days: the duration of the senator in office
  • observed: whether the end of the term is observed (1 or 0)

The survival curve of Quebec senators has been plotted on a pyplot object called senator_fig, and a KaplanMeierFitter instance called kmf has been created.

Additionally, the pandas package is loaded as pd, the KaplanMeierFitter class is imported from lifelines, and the pyplot module has been import from matplotlib as plt.

Cet exercice fait partie du cours

Survival Analysis in Python

Afficher le cours

Instructions

  • Fit the KaplanMeierFitter instance kmf to British Columbia senators' term durations.
  • Plot the British Columbia senators' survival curve on the same figure as that of Quebec senators.
  • Display the figure.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Fit Kaplan-Meier estimator
____(____, ____, label='British Columbia')

# Plot survival function on senator_fig
____

# Display the figure
____
Modifier et exécuter le code