Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Plotting Kaplan-Meier Survival Plots in R

$
0
0

I'm trying to plot a Kaplan-Meier survival plot in R, but I'm having some trouble.

I'm quite new to R, so forgive my terrible code.

library(survival)
data_time = c(0.19,0.75,0.27,0.26,0.22,0.91,0.21,0.091,0.19,0.37,0.093,0.92,0.046,0.93,042)
data_event = c(1,1,1,1,0,0,1,1,0,0,0,1,1,1,0)
surv_object = Surv(time = data_time, event = data_event)
survfit(surv_object)

This of course gives me an error: "The survfit function requires a formula as its first argument".

I've split the data into two vectors, the first for the life-length, and the second for whether or not that specific data point was censored or not, with 0 meaning not censored, and 1 meaning censored.

I thought the Surv function was supposed to produce the formula required for the survfit function, with the default being the Kaplan-Meier.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>