Using age as 'timescale' for Cox Model in lifelines?
dcstang opened this issue · 1 comments
I came across several methods of defining the timescale when performing a cox regression.
The two main ones are:
- time in study
- age of participant
Example of time-on-study as the time-scale:
o=censored X=event
------------------------------o 36 months
--------------------------o 34
------------o 18
-------X 12
------------------X 24
------------------------------o 36
0 12 24 36
Months since baseline
Example of age as the time-scale:
o=censored X=event
50-----o 53
52----------o 55
54----------X 57
55------------o 58
56--------------o 59
58---------o 60
Age in years
In R the way to incorporate age as time-scale is to use the code:
Surv(age, age + time, status)
Is there a way to do the same for lifelines package in Python? From the docs the current CoxPHFitter only takes in a duration_col
. How do I incorporate the age in this column?
from lifelines import CoxPHFitter
cph = CoxPHFitter()
# example lifelines fit but
# how to fit age in function?
cph.fit(inputDf,
duration_col='timeToDiagnosis',
event_col='caseCancer',
formula="age + sex")
The duration_col only takes in one column in a dataframe, hence setting the "time difference" in years is essentially similar to 1). Also, I could just incorporate age within the model covariates - though I think this is fundamentally different to allowing the model to evaluate age in the person-years / hazard estimation.
closing and answer posted here
https://stackoverflow.com/questions/78340199/using-age-as-timescale-for-cox-model-in-lifelines-python/78402705#78402705