In [1]:
%load_ext rpy2.ipython

We mustn't be afraid to dream a little bigger :)

In [2]:
%%R
library(survival)

addicts <- read.csv("demo_surv/addicts.csv", head=TRUE)

Y <- with(addicts, Surv(survtime, status == 1))

model_coxph <- coxph(Y ~ strata(clinic) + prison + mdosedata, data=addicts)
print(summary(model_coxph))
Loading required package: splines
Call:
coxph(formula = Y ~ strata(clinic) + prison + mdosedata, data = 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 [3]:
%%R
library(ggplot2)
library(data.table)

source('demo_surv/myggsurv.R')
model_clinic <- with(addicts, Surv(survtime, status==1) ~ clinic)
g_dose <- myggsurv(
  survfit(model_clinic),
  xlab='Time stay in the experiement (days)', ylab='Survival probability'
) + theme_classic(18)

g <- g_dose + theme(legend.position=c(0, 0), legend.justification=c(0, 0)) + 
  labs(title='KM curves', color='Categories') +
  scale_color_brewer(palette='Paired')
show(g)
data.table 1.9.2  For help type: help("data.table")
Scale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale.
NULL
In [3]: