### Stata 4, Survival

Stata 4, Survival
Hein Stigum
Presentation, data and programs at:
http://folk.uio.no/heins/
Apr-15
H.S.
1
Agenda
• Kaplan-Meier plots
• Cox regression
• Example
– Age at first intercourse
Apr-15
H.S.
2
Survival data
Outcome:
Status
No debut
Debut
0
1
Time
age
debut age
Cencored
Event
• Unajusted analysis
– Kaplan-Meier
• Regression method
– Cox-regression
Apr-15
H.S.
3
Survival data setup
• Status and time
generate status=!missing(DebutAge)
generate time=DebutAge
replace time=Age if status==0
generate time2=time+uniform()
avoid ties
• Set and describe
stset time, failure(status==1)
stdes
Apr-15
H.S.
Set data
Describe
4
Setting the timescale
Time = time since diagnosis in years:
Time = age in years:
stset dateexit, failure(dead==1) origin(datebth) enter(datediag) scale(365.25)
Apr-15
H.S.
5
Mathematical functions
• Standard distribution functions
Time to event
Density
Cumulative density
T
f(t)
F(t)
• Survival functions
Survival :
S (t )  P(T  t )
Hazard :
h (t ) 
1
dt
t
P(t  dt  T  t | T  t )
Cum. hazard: H (t )   h( s )ds
0
Failure :
Apr-15
1  S (t )  F (t )
H.S.
6
Some relationships
S (t )  e
 H (t )
F (t )  1  e
f(t)  h(t)e
H (t )
 H (t ) if small
H (t )
d
h(t )   ln(S (t ))
dt
Apr-15
H.S.
7
Kaplan-Meier
• Survival function
S (t )   (1  ), f j  failures , rj  at risk
t j t
fj
rj
• Syntax
sts graph, by(sex)
sts test sex
stci, p(50) by(sex)
sts list, at(5 10 30)
Apr-15
KM survival plot
log-rank test
time to 50% failure
survival at time 5,…
H.S.
8
Kaplan-Meier, all
sts graph, fail gwood tmin(8) tmax(30) noorigin
Age at 50% failure:
stci, p(50)
18.4 (18.1,18.8)
0
.25
.5
.75
1
Kaplan-Meier failure estimate
10
Apr-15
15
20
analysis time
25
30
H.S.
9
Kaplan-Meier, by sex
sts graph, fail by(gender) tmin(8) tmax(30) noorigin
Age at 50% failure: :
stci, p(50) by (gender)
Males: 18.6 (18.3,19.0)
Females: 18.1(17.8,18.9)
1.00
Kaplan-Meier failure estimates, by gender
0.50
0.75
Males
Females
0.00
0.25
Log-rank test:
sts test gender
p-value=0.3
10
Apr-15
15
20
Age
25
30
H.S.
10
Hazards
sts graph, hazard by(gender) width(2)
0
.1
.2
.3
.4
Smoothed hazard estimates, by gender
10
Apr-15
15
20
analysis time
H.S.
25
30
11
Cox regression
• Model
hx (t )  h0 (t )  exp(b1x1  b2 x2  ...)
hazard
baseline
RR
• Syntax
– stcox x1 x2
• Proportional hazard test
– stcox x1 x2, schoenfeld(sc*) scaledsch(ssc*)
– estat phtest, detail
– estat phtest, plot(x1)
Apr-15
H.S.
12
Full model
stcox gender cohab partfrq
Apr-15
H.S.
13
Proportion hazard test
Save residuals:
stcox gender cohab partfrq, schoenfeld(sc*) scaledsch(ssc*)
Test:
estat phtest, detail
Apr-15
H.S.
14
Smoothed Schoenfeld residuals
estat phtest, plot(cohab)
-5
0
5
Test of PH Assumption
0
10
20
Time
30
40
bandwidth = .8
Apr-15
H.S.
15
Baseline hazard
stcox gender cohab partfrq, basesurv(bsurv) basehc(bhaz)
stcurve, hazard at(gender=1 cohab=1 partfrq=0) range(8 30) width(1)
0
.1
.2
.3
Cox proportional hazards regression
10
Apr-15
15
20
analysis time
H.S.
25
30
16
Predicted survival
stcurve, survival
at1(gender=1 cohab=1 partfrq=0)
at2(gender=2 cohab=1 partfrq=0)
.6
.4
0
.2
Survival
.8
1
Cox proportional hazards regression
10
Apr-15
15
20
analysis time
H.S.
25
30
17
If proptional hazard fails
• Stratified Cox regression
• Separate analysis on time intervals
• Time dependent covariats
Apr-15
H.S.
18
Some Cox options
stcox drug age, strata(sex)
Stratified
stcox drug age, shared(family) Frailty
stcox drug age, tvc(varlist)
Apr-15
H.S.
Timevar cov
19