The Stratified Cox Proportional Hazards Regression Model | by Sachin Date | Dec, 2020

[ad_1]


import pandas as pddata_types = {'TREATMENT_TYPE':'int', 'CELL_TYPE':'category', 'SURVIVAL_IN_DAYS':'int', 'STATUS':'int', 'KARNOFSKY_SCORE':'int', 'MONTHS_FROM_DIAGNOSIS':'int', 'AGE':'int', 'PRIOR_THERAPY':'int'}df = pd.read_csv(filepath_or_buffer='va_lung_cancer_dataset.csv', dtype=data_types)df.head()
The first few rows of the VA lung cancer data set (Image by Author)
from patsy import dmatrices#Build the model expression in Patsy syntax. 
model_expr = 'SURVIVAL_IN_DAYS ~ TREATMENT_TYPE + CELL_TYPE + KARNOFSKY_SCORE + MONTHS_FROM_DIAGNOSIS + AGE + PRIOR_THERAPY + SURVIVAL_IN_DAYS + STATUS'
#Use the model expression to break out the CELL_TYPE categorical variable into 1-0 type columns
y, X = dmatrices(model_expr, df, return_type='dataframe')
#Print out the first few rows
X.head()
The first few rows of the regression matrix (Image by Author)
from lifelines import CoxPHFitter
#Create the Cox model
cph_model = CoxPHFitter()
#Train the model on the data set
cph_model.fit(df=X, duration_col='SURVIVAL_IN_DAYS', event_col='STATUS')
#Print the model summary
cph_model.print_summary()
Cox model training summary (Image by Author)
scaled_schoenfeld = cph_model.compute_residuals(training_dataframe=X, kind='scaled_schoenfeld')
from lifelines.statistics import proportional_hazard_testproportional_hazard_test(fitted_cox_model=cph_model, training_df=X, time_transform='log', precomputed_residuals=scaled_schoenfeld)
Output of the proportional_hazard_test (Image by Author)
Output of the proportional_hazard_test (Image by Author)

Read More …

[ad_2]


Write a comment