Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I plot the 'inverse' of a survival function?

I am trying to plot the inverse of a survival function, as the data I'm is actually an increase in proportion of an event over time. I can produce Kaplan-Meier survival plots, but I want to produce the 'opposite' of these. I can kind of get what I want using the following fun="cloglog":

plot(survfit(Surv(Days_until_workers,Workers)~Queen_Number+Treatment,data=xdata),
     fun="cloglog", lty=c(1:4), lwd=2, ylab="Colonies with Workers",
     xlab="Days", las=1, font.lab=2, bty="n")

The 'cloglog' function

But I don't understand quite what this has done to the time (i.e. doesn't start at 0 and distance decreases?), and why the survival lines extend above the y axis.

Would really appreciate some help with this!

Cheers

like image 361
user2236301 Avatar asked Dec 15 '22 12:12

user2236301


1 Answers

Use fun="event" to get the desired output

fit <- survfit(Surv(time, status) ~ x, data = aml)
par(mfrow=1:2, las=1)
plot(fit, col=2:3)
plot(fit, col=2:3, fun="event")

enter image description here

The reason for fun="cloglog" screwing up the axes is that it does not plot a fraction at all. It is instead plotting this according to ?plot.survfit:

"cloglog" creates a complimentary log-log survival plot (f(y) = log(-log(y)) along with log scale for the x-axis)

Moreover, the fun argument is not limited to predefined functions like "event" or "cloglog", so you can easily give it your own custom function.

plot(fit, col=2:3, fun=function(y) 3*sqrt(1-y))
like image 178
Backlin Avatar answered Jan 31 '23 00:01

Backlin