In [1]:
import pandas as pd
import rpy2.robjects as ro
In [2]:
df_addicts = pd.read_csv("demo_surv/addicts.csv")
In [3]:
df_addicts.head()
Out[3]:
Unnamed: 0 id clinic status survtime prison mdose mdosedata
0 1 1 1 1 428 0 50 1
1 2 2 1 1 275 1 55 2
2 3 3 1 1 262 0 55 2
3 4 4 1 1 183 0 30 1
4 5 5 1 1 259 1 65 3

5 rows × 8 columns

In [4]:
%load_ext rpy2.ipython
In [5]:
%Rpush df_addicts
In [6]:
%%R
library(survival)

Y <- with(df_addicts, Surv(survtime, status == 1))
model_coxph <- coxph(Y ~ strata(clinic) + prison + mdosedata, data=df_addicts)
print(summary(model_coxph))
Loading required package: splines
Call:
coxph(formula = Y ~ strata(clinic) + prison + mdosedata, data = df_addicts)

  n= 238, number of events= 150 

             coef exp(coef) se(coef)      z Pr(>|z|)    
prison     0.3690    1.4463   0.1685  2.191   0.0285 *  
mdosedata -0.4349    0.6473   0.1031 -4.218 2.46e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

          exp(coef) exp(-coef) lower .95 upper .95
prison       1.4463     0.6914    1.0396    2.0121
mdosedata    0.6473     1.5449    0.5289    0.7923

Concordance= 0.628  (se = 0.033 )
Rsquare= 0.087   (max possible= 0.994 )
Likelihood ratio test= 21.54  on 2 df,   p=2.103e-05
Wald test            = 21.53  on 2 df,   p=2.108e-05
Score (logrank) test = 22.11  on 2 df,   p=1.583e-05

NULL
In [6]: