Created
June 7, 2019 01:33
-
-
Save CamDavidsonPilon/3a778678d393163bacdb1ce2cc3d6c5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zepid.base import create_spline_transform | |
from lifelines import CoxPHFitter | |
from lifelines.datasets import load_rossi | |
rossi = load_rossi() | |
rossi_with_splines = rossi.copy() | |
spline_transform, bp = create_spline_transform(rossi_with_splines['age'], term=3, restricted=False) | |
rossi_with_splines[['age0', 'age1', 'age2']] = pd.DataFrame(spline_transform(rossi_with_splines['age'])) | |
rossi_with_splines = rossi_with_splines.drop('age', axis=1) | |
cph = CoxPHFitter().fit(rossi_with_splines, 'week', 'arrest') | |
cph.print_summary() | |
x = np.linspace(19, 50) | |
y = spline_transform(x).dot(cph.hazards_.loc[['age0', 'age1', 'age2']]) | |
plot(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment