library(survival)
testdata <- data.frame(list(start=c(1, 2, 5, 2, 1, 7, 3, 4, 8, 8),
stop =c(2, 3, 6, 7, 8, 9, 9, 9,14,17),
event=c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0),
x1 =c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0),
x2 =c(0, 1, 1, 1, 0, 0, 1, 0, 1, 0),
x3 =c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0)))
summary( coxphf( formula=Surv(start, stop, event) ~ x1+x2+x3, data=testdata))
# testing H0: x1=0, x2=0
coxphftest( formula=Surv(start, stop, event) ~ x1+x2+x3, test=~x1+x2, data=testdata)
# How to test total effect of a variable with time-dependent effect
# NOT RUN (works)
#fitt<- coxphf( formula=Surv(start, stop, event) ~ x1+x2+x3*stop, data=testdata, pl=FALSE)
#test <- coxphf(formula=Surv(start, stop, event) ~ x1+x2+x3*stop, data=testdata, adapt=c(1,1,0,0))
# PLR p-value for x3 + x3:stop
#pchisq((fitt$loglik[2]-test$loglik[2])*2, 2, lower.tail=FALSE)
#NOT RUN (does not work)
#test <- coxphf(formula=Surv(start, stop, event) ~ x1+x2+x3*stop, data=testdata, test=~x3+stop:x3)
Run the code above in your browser using DataLab