Re: [R] Median expected survival

2014-07-11 Thread Andrews, Chris
Hi Lars,

Graph it:

plot(pred_leuk)

will show that some of the survival curves do not reach 0.5 before you run out 
of data.  Thus the median is not estimated and you get NA.

Chris

-Original Message-
From: Lars Bishop [mailto:lars...@gmail.com] 
Sent: Thursday, July 10, 2014 6:23 AM
To: r-help@r-project.org
Subject: [R] Median expected survival

Hi All,

Apologies for the simple question, but I could not find a straightforward
answer based on my limited knowledge of survival analysis.

I’m trying to obtain the predicted median survival time for each subject on
a new dataset from a fitted coxph{survival} or cph{rms} object. Would the
quantile.survfit function (as used below) return the expected median
survival? Why this function returns NAs in this case, when all predictors
have non-missing values?

As an alternative, I’ve tried to use the Quntile{rms} function as in my
second chunk of code, but in this case I get an error message (most likely
due to my lack of understanding as well).

library(MASS)

library(survival)

library(rms)

data(gehan)

leuk.cox <-coxph(Surv(time, cens) ~ treat + factor(pair), data = gehan)

leuk_new <- gehan[1:10, ] # take first 10 patients

pred_leuk <- survfit(leuk.cox, newdata=leuk_new)

quantile(pred_leuk, 0.5)$quantile



### alternative using rms

leuk.cox.rms <-cph(Surv(time, cens) ~ treat + factor(pair), data = gehan,
surv = T)

med <- Quantile(leuk.cox.rms)

Predict(leuk.cox.rms, data = leuk_new, fun=function(x)med(lp=x))

>Error in Predict(leuk.cox.rms, data = leuk_new, fun = function(x) med(lp =
x)) :

  predictors(s) not in model: data


Thank you for your help.

Best,

Lars.

[[alternative HTML version deleted]]


**
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Median expected survival

2014-07-10 Thread Marco Barbàra
Hi, Lars.

I don't understand well your question. why don't you simply type

 pred_leuk

Call: survfit(formula = leuk.cox, newdata = leuk_new)

   records n.max n.start events median 0.95LCL 0.95UCL
1   4242  42 30  1   1  23
2   4242  42 30  7   5  NA
3   4242  42 30 15  10  NA
4   4242  42 30 NA  NA  NA
5   4242  42 30  8   5  NA
6   4242  42 30 23  22  NA
7   4242  42 30  8   6  NA
8   4242  42 30 NA  22  NA
9   4242  42 30  6   4  NA
10  4242  42 30 23  17  NA

Yes, the quantile method returns the correct medians. The NAs usually
appear when the unit belongs to a category for which median survival
time has not yet been reached, so there is no way for the model to
estimate the median time. You can see the expected survival curve with
plot(predl_leuk)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Median expected survival

2014-07-10 Thread Lars Bishop
Hi All,

Apologies for the simple question, but I could not find a straightforward
answer based on my limited knowledge of survival analysis.

I’m trying to obtain the predicted median survival time for each subject on
a new dataset from a fitted coxph{survival} or cph{rms} object. Would the
quantile.survfit function (as used below) return the expected median
survival? Why this function returns NAs in this case, when all predictors
have non-missing values?

As an alternative, I’ve tried to use the Quntile{rms} function as in my
second chunk of code, but in this case I get an error message (most likely
due to my lack of understanding as well).

library(MASS)

library(survival)

library(rms)

data(gehan)

leuk.cox <-coxph(Surv(time, cens) ~ treat + factor(pair), data = gehan)

leuk_new <- gehan[1:10, ] # take first 10 patients

pred_leuk <- survfit(leuk.cox, newdata=leuk_new)

quantile(pred_leuk, 0.5)$quantile



### alternative using rms

leuk.cox.rms <-cph(Surv(time, cens) ~ treat + factor(pair), data = gehan,
surv = T)

med <- Quantile(leuk.cox.rms)

Predict(leuk.cox.rms, data = leuk_new, fun=function(x)med(lp=x))

>Error in Predict(leuk.cox.rms, data = leuk_new, fun = function(x) med(lp =
x)) :

  predictors(s) not in model: data


Thank you for your help.

Best,

Lars.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.