[R] expected risk from coxph (survival)
Dieter Menne
dieter.menne at menne-biomed.de
Sat Jun 7 10:15:48 CEST 2008
Reid Tingley <r_tingley <at> hotmail.com> writes:
> When I try to to obtain the expected risk for a new dataset using coxph in the
survival package I get an error.
> Using the example from ?coxph:
# Example rewritten by DM; please do not use HTML mail
library(survival)
test1 <- list(time= c(4, 3,1,1,2,2,3),
status=c(1,NA,1,0,1,1,0),
x= c(0, 2,1,1,1,0,0),
sex= c(0,0,0,0,1,1,1))
cox<-coxph( Surv(time, status) ~ x + strata(sex), test1) #stratified model
new<-list(time= c(5, 1,1,2,2,4,3),
status=c(1,NA,1,0,0,1,1),
x= c(0, 2,1,1,1,0,0),
sex= c(0,0,0,0,1,1,1))
predict(cox,new,type="expected")
# }
# else if (type == "expected") {
# if (missing(newdata))
# pred <- y[, ncol(y)] - object$residuals
# else stop("Method not yet finished")
Looks like this is "by design"; see the code above.
You might try to use cph and predict.Design from Frank Harrell's Design package
instead.
Dieter
More information about the R-help
mailing list