Event History Analysis in Julia. Cox regression (right censoring+left truncation), ...
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
test
.gitignore
.travis.yml
LICENSE.md
README.org
REQUIRE

README.org

1 Event History Analysis

Event History Analysis for the Julia Language

using EventHistory

1.1 Event class

1.1.1 Right-censored event times

stop   = [2,3,3];
status = [false,true,true];
e1 = Event(stop,status)
3-element Array{EventHistory.Surv,1}:
 2+
 3 
 3
Time(e1)
3-element Array{Int64,1}:
 2
 3
 3
Status(e1)
3-element Array{Bool,1}:
 false
  true
  true

1.1.2 Right-censored+left truncation

start  = [0,1,2];
e2 = Event(start,stop,status)
3-element Array{EventHistory.SurvTrunc,1}:
 (0;2+]
 (1;3] 
 (2;3]
Entry(e2)
3-element Array{Int64,1}:
 0
 1
 2

1.1.3 Competing risks data

cause = [0,2,1];
e3 = Event(start,stop,cause)
3-element Array{EventHistory.CompRisk,1}:
 (0;2:+]
 (1;3:2]
 (2;3:1]
Status(e3)
3-element Array{Bool,1}:
 false
  true
  true
Cause(e3)
3-element Array{Int64,1}:
 0
 2
 1

1.1.4 Interval censoring

right  =  [2,3,Inf];
left =  [1,-Inf,1];
e4=Event(left,right,"interval")
3-element Array{EventHistory.SurvInt,1}:
 [1.0;2.0]              
 (-Inf;3.0]             
 [EventHistory.Time;Inf)

1.1.5 Formula syntax (see also examples below)

using DataFrames
d = DataFrame(start=start,stop=stop,status=status);
Event([:stop,:status],d)
3-element Array{EventHistory.Surv,1}:
 2+
 3 
 3
Event([:start,:stop,:status],d)
3-element Array{EventHistory.SurvTrunc,1}:
 (0;2+]
 (1;3] 
 (2;3]

1.2 Cox regression

1.2.1 Examples

1.2.1.1 Cox regression

Ovarian cancer example (randomized trial)

using RDatasets
using EventHistory
ovarian = dataset("survival", "ovarian");
ovarian[:Group] = ovarian[:Rx].-1;
ovarian[:S] = Event([:FUTime,:FUStat],ovarian);

mm = phreg(@formula(S~Age+Group),ovarian)
Model: Cox; Formula: S ~ Age + Group

n=26, events=12

        Estimate       S.E naive S.E.    P-value
Age     0.147327 0.0488846   0.046147 0.00258032
Group  -0.803973  0.633937   0.632049   0.204718

1.2.1.2 Prediction

Predictions:

## Prediction
predict(mm,surv=false,X=[0 0]); ## Baseline
s56 = predict(mm,X=[56 1],order=true); ## Survival probabilities age 40, group 1
predict(mm,X=[56 0],time=[100,400,600]); ## ... at time 100,400,600
predict(mm,X=[56 1; 56 0],time=[600,100,400]) ## ... both groups
3×3 Array{Real,2}:
 600.0  0.618402  0.341676
 100.0  0.983831  0.964233
 400.0  0.834936  0.668255
s = predict(mm,X=[56 1; 56 0], order=true);
pr = DataFrame(Time=[s[:,1];s[:,1]], S=[s[:,2];s[:,3]], 
		 Group=Compat.repeat(["Group1","Group2"], inner=size(s,1)));

using Gadfly
p = plot(pr, x="Time", y="S",color="Group",
         Geom.step, Geom.point,
         Guide.ylabel("Survival probability"), Guide.title("Age 56"))
draw(PNG("surv.png",7inch,7inch),p)

examples/surv.png

1.2.1.3 Cox regression, Left truncation+right censoring

Simple example from the `survival` R-package

d = DataFrame(start=[1,2,5,2,1,7,3,4,8,8],
                stop=[2,3,6,7,8,9,9,9,14,17],
                event=[1,1,1,1,1,1,1,0,0,0],
                x=[1,0,0,1,0,1,1,1,0,0]);
d[:S] = Event([:start,:stop,:event], d);

e = phreg(@formula(S~x), d)
Model: Cox; Formula: S ~ x

n=10, events=7

       Estimate      S.E naive S.E.  P-value
x    -0.0211052 0.838301   0.795177 0.979914

1.3 Installation

Get it from https://github.com/kkholst/EventHistory.jl

1.4 Roadmap

  • Additive models
  • Stratified analysis
  • Handle ties (Efron)
  • Frailty models (Copula)
  • Residuals