I want to verify whether Weibull is a good candidate for my distribution in survival analysis.

So I plot log(t) vs log(-log(Kaplan-Meier). But instead of two lines, I get plot where the lines are somehow connected.

Any ideas what am I doing wrong?

fit<-survfit(Surv(Time, Status)~Drug, data=pbc)


enter image description here


Your problem doesn't relate to statistics. plot(fit) works because plot() has the method to draw survfit class. But your arguments aren't specific class and don't have any information about Drug. So, plot() connects all points by one line. You need to treat time, surv, and Drug information.

Here is my example:

fit <- survfit(Surv(time, status) ~ x, data = aml) # using aml as example data

df <- data.frame(time = fit$time, 
                 surv = fit$surv,   # strata has each number of elements.
                 drug = c(rep("a", fit$strata[1]), rep("b", fit$strata[2])))

# plot() draws not data but axes and labs.
plot(log(-log(surv)) ~ log(time), df, type="n", xlab="log(time)", ylab="log(-log(survival))")
lines(log(-log(surv)) ~ log(time), subset(df, drug=="a"), type="s")
lines(log(-log(surv)) ~ log(time), subset(df, drug=="b"), type="s")
points(log(-log(surv)) ~ log(time), df, col=c("red", "blue")[drug]) # to assist you

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.