Dr.Vinay Pitchika
2013-Nov-20 20:01 UTC
[R] How to stop Kaplan-Meier curve at a time point
Hello R users
I have a question with Kaplan-Meier Curve with respect to my research. We
have done a retrospective study on fillings in the tooth and their survival
in relation to the many influencing factors. We had a long follow-up time
(upto 8yrs for some variables). However, we decided to stop the analysis at
the 6year follow up time, so that we can have uniform follow-up time for
all the variables.
I did play a bit with the formula and tried to stop the Kaplan-Meier curve
at my desired time (2190days)or roughly 6 years. However, my question is I
want to find the significance (log rank test) at this time point between
the two curves; because I am not able to find a way to stop the survfit at
this time point with my knowledge. Below is the code I used.
Gender2<-survfit(Surv(Survival_days, Outcome)~Gender)
plot (Gender2, xmax=2190, mark.time=FALSE, col=c(1:2), xlab="Survival time
(Days)", ylab="Survival probability", main="Gender") #
mark.time=FALSE will
remove the censoring lines in the graph. If censoring lines are needed,
then remove the mark.time section in the formula.
legend("topright",c("Females", "Males"),
col=(1:2), lwd=0.5)
Am sure, the code in the first line has to be modified. Please help me with
this and I will be very thankful to you.
Thanks in advance
Regards
Vinay
[[alternative HTML version deleted]]
On Nov 20, 2013, at 12:01 PM, Dr.Vinay Pitchika wrote:> Hello R users > > I have a question with Kaplan-Meier Curve with respect to my research. We > have done a retrospective study on fillings in the tooth and their survival > in relation to the many influencing factors. We had a long follow-up time > (upto 8yrs for some variables). However, we decided to stop the analysis at > the 6year follow up time, so that we can have uniform follow-up time for > all the variables. > > I did play a bit with the formula and tried to stop the Kaplan-Meier curve > at my desired time (2190days)or roughly 6 years. However, my question is I > want to find the significance (log rank test) at this time point between > the two curves; because I am not able to find a way to stop the survfit at > this time point with my knowledge. Below is the code I used. > > Gender2<-survfit(Surv(Survival_days, Outcome)~Gender)I'm assuming that you have a dataframe with those variables and have attached it. If so, then: dfrm <- detach(said_df) # If not, then: dfrm <- data.frame(Survival_days, Outcome, Gender) Gender2<-survfit(Surv(Survival_days, Outcome)~Gender, data=dfrm, subset = Survival_days < 6*365.25 )> > plot (Gender2, xmax=2190, mark.time=FALSE, col=c(1:2), xlab="Survival time > (Days)", ylab="Survival probability", main="Gender") # mark.time=FALSE will > remove the censoring lines in the graph. If censoring lines are needed, > then remove the mark.time section in the formula. > > legend("topright",c("Females", "Males"), col=(1:2), lwd=0.5) > > Am sure, the code in the first line has to be modified. Please help me with > this and I will be very thankful to you. >David Winsemius Alameda, CA, USA
One solution is to format the data as if the follow-up period ended on day 2190. For example, TTT <- Survival_days DDD <- Outcome DDD[ TTT>2190 ] <- 0 TTT[ TTT>2190 ] <- 2190 survfit(Surv(TTT, DDD) ~ Gender) -tgs On Wed, Nov 20, 2013 at 3:01 PM, Dr.Vinay Pitchika <dr.vinay.muc@gmail.com>wrote:> Hello R users > > I have a question with Kaplan-Meier Curve with respect to my research. We > have done a retrospective study on fillings in the tooth and their survival > in relation to the many influencing factors. We had a long follow-up time > (upto 8yrs for some variables). However, we decided to stop the analysis at > the 6year follow up time, so that we can have uniform follow-up time for > all the variables. > > I did play a bit with the formula and tried to stop the Kaplan-Meier curve > at my desired time (2190days)or roughly 6 years. However, my question is I > want to find the significance (log rank test) at this time point between > the two curves; because I am not able to find a way to stop the survfit at > this time point with my knowledge. Below is the code I used. > > Gender2<-survfit(Surv(Survival_days, Outcome)~Gender) > > plot (Gender2, xmax=2190, mark.time=FALSE, col=c(1:2), xlab="Survival time > (Days)", ylab="Survival probability", main="Gender") # mark.time=FALSE will > remove the censoring lines in the graph. If censoring lines are needed, > then remove the mark.time section in the formula. > > legend("topright",c("Females", "Males"), col=(1:2), lwd=0.5) > > Am sure, the code in the first line has to be modified. Please help me with > this and I will be very thankful to you. > > Thanks in advance > > Regards > Vinay > > [[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. >[[alternative HTML version deleted]]
Here is the simplest answer that I know.
outcome6 <- ifelse(Survival_days > 2190, 0, Outcome)
survfit(Surv(Survival_days, outcome6) ~ Gender)
This assumes that the variable Outcome is coded as 0/1. If it were instead
FALSE/TRUE
then change the 0 to "FALSE" in the first line.
The logrank test adds a term to the computation at each death time, so changing
all the
deaths after time 2160 to "censored" effectively ignores any
information after that point.
There is no need to modify the time variable.
David W's suggestion to add "subset = (Survival_days <= 2190) was
incorrect, effectively
removing all of the most successful outcomes from the study. It will thus lead
to an
underestimate of tooth survival. (This was a surprise - David usually bats 1000
on
survival questions, and I greatly appreciate his input to this list.)
Terry Therneau
(author of the package)
On 11/21/2013 05:00 AM, r-help-request at r-project.org
wrote:> Hello R users
>
> I have a question with Kaplan-Meier Curve with respect to my research. We
> have done a retrospective study on fillings in the tooth and their survival
> in relation to the many influencing factors. We had a long follow-up time
> (upto 8yrs for some variables). However, we decided to stop the analysis at
> the 6year follow up time, so that we can have uniform follow-up time for
> all the variables.
>
> I did play a bit with the formula and tried to stop the Kaplan-Meier curve
> at my desired time (2190days)or roughly 6 years. However, my question is I
> want to find the significance (log rank test) at this time point between
> the two curves; because I am not able to find a way to stop the survfit at
> this time point with my knowledge. Below is the code I used.
>
> Gender2<-survfit(Surv(Survival_days, Outcome)~Gender)
>
> plot (Gender2, xmax=2190, mark.time=FALSE, col=c(1:2), xlab="Survival
time
> (Days)", ylab="Survival probability",
main="Gender") # mark.time=FALSE will
> remove the censoring lines in the graph. If censoring lines are needed,
> then remove the mark.time section in the formula.
>
> legend("topright",c("Females", "Males"),
col=(1:2), lwd=0.5)
>
> Am sure, the code in the first line has to be modified. Please help me with
> this and I will be very thankful to you.
>
> Thanks in advance
The functions 'age.window' and 'cal.window' in the package 'eha' are designed to perform 'rectangular cuts' in the Lexis diagram. So, in your case,> require(eha) > dat <- data.frame(enter = rep(0, length(Survival_days), exit Survival_days, event = Outcome) > dat.1 <- age.window(dat, c(0, 2190))and 'dat.1' is your right-censored data set. G?ran Brostr?m On 11/21/2013 07:36 AM, Thomas Stewart wrote:> One solution is to format the data as if the follow-up period ended on day > 2190. For example, > > TTT <- Survival_days > DDD <- Outcome > > DDD[ TTT>2190 ] <- 0 > TTT[ TTT>2190 ] <- 2190 > > survfit(Surv(TTT, DDD) ~ Gender) > > -tgs > > > > On Wed, Nov 20, 2013 at 3:01 PM, Dr.Vinay Pitchika > <dr.vinay.muc at gmail.com>wrote: > >> Hello R users >> >> I have a question with Kaplan-Meier Curve with respect to my research. We >> have done a retrospective study on fillings in the tooth and their survival >> in relation to the many influencing factors. We had a long follow-up time >> (upto 8yrs for some variables). However, we decided to stop the analysis at >> the 6year follow up time, so that we can have uniform follow-up time for >> all the variables. >> >> I did play a bit with the formula and tried to stop the Kaplan-Meier curve >> at my desired time (2190days)or roughly 6 years. However, my question is I >> want to find the significance (log rank test) at this time point between >> the two curves; because I am not able to find a way to stop the survfit at >> this time point with my knowledge. Below is the code I used. >> >> Gender2<-survfit(Surv(Survival_days, Outcome)~Gender) >> >> plot (Gender2, xmax=2190, mark.time=FALSE, col=c(1:2), xlab="Survival time >> (Days)", ylab="Survival probability", main="Gender") # mark.time=FALSE will >> remove the censoring lines in the graph. If censoring lines are needed, >> then remove the mark.time section in the formula. >> >> legend("topright",c("Females", "Males"), col=(1:2), lwd=0.5) >> >> Am sure, the code in the first line has to be modified. Please help me with >> this and I will be very thankful to you. >> >> Thanks in advance >> >> Regards >> Vinay >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at 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. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >