get.external.valid: External Validation of Cox PH model

Description Usage Arguments Details Author(s) Examples

View source: R/get_external_validation.R

Description

This function allows you to generate an Uno's C-index of external validation of a Cox PH model.

Usage

1
get.external.valid(TR.data, TE.data, Surv.rsp, Surv.rsp.new, times, formula)

Arguments

TR.data

the name of a data frame containing all needed variables, used as training dataset. Need to make sure TR.data and TE.data are in exactly the same structure, i.e. the same variables.

TE.data

the name of a data frame containing all needed variables, used as testing dataset.

Surv.rsp

a Surv object for TR.data. For example, Surv(TR$time_to_death, TR$censor)

Surv.rsp.new

a Surv object for TE.data. For example, Surv(TE$time_to_death, TE$censor)

times

a vector of scalars to specify the timepoints you are interested in for validation.

formula

a formula used to specify a Cox PH model, see cph function.

Details

Returns C.index, the Uno's C-statistic (given by the integral of AUC on [0, max(times)] weighted by the estimated probability density of the time-to-event outcome). see output iauc from survAUC::AUC.uno.

Author(s)

Xi "Ada" Wang

Ph.D. Student of Biostatistics

Penn State College of Medicine

xzw149@psu.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n <- 500
set.seed(2019)
var1 <- 30 + 5*rnorm(n)
var2 <- factor(sample(c("White","Black"),n,rep=TRUE,prob=c(.3,.7)))
hazard <- .1*exp(.2*(var1-30)+.5*(var2=="Black"))
time_to_event <- -log(runif(n))/hazard
cens <- 15*runif(n)
censor <- ifelse(time_to_event <= cens,1,0)
All <- data.frame(time_to_event = time_to_event,censor=censor, var1 = var1, var2= var2)
TR <- All[1:300,]
TE <- All[301:500,]
get.external.valid(TR,TE,Surv.rsp=Surv(TR$time_to_event, TR$censor),
                   Surv.rsp.new=Surv(TE$time_to_event, TE$censor),
                   times=20,formula=Surv(time_to_event,censor) ~ var1 + var2)
get.external.valid(TR,TE,Surv.rsp=Surv(TR$time_to_event, TR$censor),
                   Surv.rsp.new=Surv(TE$time_to_event, TE$censor),
                   times=seq(1,max(TE$time_to_event),1) ,
                   formula=Surv(time_to_event,censor) ~ var1 + var2)

ccwangxi/nomovalidation documentation built on Feb. 14, 2020, 9:21 a.m.