dummy-link

EventHistory

Event History Analysis in Julia. Cox regression (right censoring+left truncation), ...

Readme

+PROPERTY: header-args:julia :session julia

+PROPERTY: header-args :eval never-export :exports both :results output :tangle yes :comments yes

+PROPERTY: header-args:R+ :colnames yes :rownames no :hlines yes

+OPTIONS: timestamp:t title:t date:t author:t creator:nil toc:nil

+OPTIONS: h:4 num:t tags:nil d:t ^:{}

+BEGIN_HTML

+END_HTML

  • Event History Analysis

/Event History Analysis for the Julia Language/

+BEGIN_SRC julia :exports code

using EventHistory

+END_SRC

+RESULTS:

: WARNING: Method definition function_module(Function) in module Base at reflection.jl:907 overwritten in module ESS at none:29. : ERROR: UndefVarError: ASCIIString not defined

** Event class

*** Right-censored event times

+BEGIN_SRC julia :exports both

stop = [2,3,3]; status = [false,true,true]; e1 = Event(stop,status)

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.Surv,1}: : 2+ : 3 : 3

+BEGIN_SRC julia :exports both

Time(e1)

+END_SRC

+RESULTS:

: 3-element Array{Int64,1}: : 2 : 3 : 3

+BEGIN_SRC julia :exports both

Status(e1)

+END_SRC

+RESULTS:

: 3-element Array{Bool,1}: : false : true : true

*** Right-censored+left truncation

+BEGIN_SRC julia :exports both

start = [0,1,2]; e2 = Event(start,stop,status)

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.SurvTrunc,1}: : (0;2+] : (1;3] : (2;3]

+BEGIN_SRC julia :exports both

Entry(e2)

+END_SRC

+RESULTS:

: 3-element Array{Int64,1}: : 0 : 1 : 2

*** Competing risks data

+BEGIN_SRC julia :exports both

cause = [0,2,1]; e3 = Event(start,stop,cause)

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.CompRisk,1}: : (0;2:+] : (1;3:2] : (2;3:1]

+BEGIN_SRC julia :exports both

Status(e3)

+END_SRC

+RESULTS:

: 3-element Array{Bool,1}: : false : true : true

+BEGIN_SRC julia :exports both

Cause(e3)

+END_SRC

+RESULTS:

: 3-element Array{Int64,1}: : 0 : 2 : 1

*** Interval censoring

+BEGIN_SRC julia :exports both

right = [2,3,Inf]; left = [1,-Inf,1]; e4=Event(left,right,"interval")

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.SurvInt,1}: : [1.0;2.0]
: (-Inf;3.0]
: [EventHistory.Time;Inf)

*** Formula syntax (see also examples below)

+BEGIN_SRC julia :exports both

using DataFrames d = DataFrame(start=start,stop=stop,status=status); Event([:stop,:status],d)

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.Surv,1}: : 2+ : 3 : 3

+BEGIN_SRC julia :exports both

Event([:start,:stop,:status],d)

+END_SRC

+RESULTS:

: 3-element Array{EventHistory.SurvTrunc,1}: : (0;2+] : (1;3] : (2;3]

** Cox regression

*** Examples

**** Cox regression

Ovarian cancer example (randomized trial)

+BEGIN_SRC julia :exports both

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)

+END_SRC

+RESULTS:

+begin_example

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

+end_example

**** Prediction

Predictions:

+BEGIN_SRC julia :exports both

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

+END_SRC

+RESULTS:

: 3×3 Array{Real,2}: : 600.0 0.618402 0.341676 : 100.0 0.983831 0.964233 : 400.0 0.834936 0.668255

+BEGIN_SRC julia :exports both

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)

+END_SRC

[[file:examples/surv.png]]

**** Cox regression, Left truncation+right censoring

Simple example from the survival R-package

+BEGIN_SRC julia :exports both

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)

+END_SRC

+RESULTS:

+begin_example

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

+end_example

** Installation

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

+BEGIN_SRC julia :eval never :exports none

Pkg.clone("https://github.com/kkholst/EventHistory.jl")

+END_SRC

** Roadmap

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

First Commit

10/15/2013

Last Touched

about 2 years ago

Commits

52 commits

Used By: