get Cox results (p-value, confidence interval, etc)
aster94 opened this issue · 3 comments
Using print_summary() I am able to see the p-value, confidence interval, hazard ratio coefficient, but, funnily, I think that I am doing something cumberstone, this is how I get them into a variable:
import pandas as pd
from lifelines import CoxPHFitter
df = pd.DataFrame({'days':[0,1,2],
'event':[3,4,5],
'covariable':[6,7,8]})
cph = CoxPHFitter(alpha=0.1)
d = cph.fit(df, duration_col='days', event_col='event')
cph.print_summary()
r = round(d.hazard_ratios_.iat[0],2)
ci = (round(1+d.confidence_intervals_.iat[0,0],2), round(1+d.confidence_intervals_.iat[0,1],2))
And also, I am not able to get the p-value as a variable, can someone enlight me?
.print_summary
is just a nice way to look at .summary
:
import pandas as pd
from lifelines import CoxPHFitter
df = pd.DataFrame({'days':[0,1,2],
'event':[3,4,5],
'covariable':[6,7,8]})
cph = CoxPHFitter(alpha=0.1)
cph.fit(df, duration_col='days', event_col='event')
cph.print_summary()
covariable_summary = cph.summary.loc['covariable']
hz = covariable_summary['exp(coef)']
ci = (covariable_summary['exp(coef) lower 90%'], covariable_summary['exp(coef) upper 90%'])
What do you think?
Far away a cleaner way to get the variables!
I have a question about your library: how do you manage the missing values?
Because my dataset is actually missing some values here and there, something like this:
df = pd.DataFrame({'days':[0,1,2,3,4],
'event':[3,4,5,9,7],
'cov1':[6,7,8,1,Na],
'cov2':[1,2,3,Na,2],
'cov3':[Na,2,3,8,2]})
My approach was to make a for loop and remove the whole line where a missing value was present
Missing values is an entire field of statistics, take a look at pages like this: https://stefvanbuuren.name/fimd/sec-problem.html
I think lifelines will just reject the data if there are nans