February 9, 2013 at 13:21
srv()
srv.R (click to download)
This function plots Kaplan-Meier estimator based curves, and computes log-rank p-value, as frequently requested in survival analysis. It is essentially a wrapper for the survival package designed to produce usable results in a single call.
Usage
source("http://bioinformatics.ovsa.fr/files/srv.R")
srv(time, event, group, subset, limit=NA, graph=TRUE, test=TRUE, ...)
Arguments
time : Numeric vector of follow-up times in a consistent time unit (month, week, years ...).
event : Logical vector determining for each individual its status at the end of the follow-up. Overall survival considers only the death as an event (TRUE), censored individuals (lost of sight) are FALSE.
group : Vector (preferably a factor) determining for each individual the group it belongs to. The groups are plotted separately on the same graphic, and the p-value returned assesses the difference between them.
subset : Optional vector, if provided it will be used to subset time, event and group. See [ for further details on allowed values.
limit : Single numeric value, if not NA follow-ups will be truncated at this value (for plotting and p-value computation). No event will be considered for the truncated individuals, considering that at limit the event that may have been observed later did not occurred yet.
graph : Single logical value, whether to plot the Kaplan-Meier curves or not (for invisible computation).
test : Single logical value, whether to compute log-rank p-value and add it to the plot's legend or not.
... : Other arguments are dispatched to plot.default (and thus to par), legend or plot.survfit according to their names.
Value
Returns a list, with at least a survfit element (see survival::survfit() for more details).
If test is TRUE, p.value and method elements are also present.
Example : Generate dummy survival data
time = runif(30, 1, 20)
event = sample(c(TRUE,FALSE), 30, replace=TRUE)
group = c(rep("A", 10), rep("B", 20))
Example : Minimal call
srv(time, event, group)
Example : Customised plot
srv(time, event, group, xlab="Time (months)", ylab="Overall Survival (%)", yscale=100, las=1, x="bottomleft")
This function plots Kaplan-Meier estimator based curves, and computes log-rank p-value, as frequently requested in survival analysis. It is essentially a wrapper for the survival package designed to produce usable results in a single call.
Usage
source("http://bioinformatics.ovsa.fr/files/srv.R")
srv(time, event, group, subset, limit=NA, graph=TRUE, test=TRUE, ...)
Arguments
time : Numeric vector of follow-up times in a consistent time unit (month, week, years ...).
event : Logical vector determining for each individual its status at the end of the follow-up. Overall survival considers only the death as an event (TRUE), censored individuals (lost of sight) are FALSE.
group : Vector (preferably a factor) determining for each individual the group it belongs to. The groups are plotted separately on the same graphic, and the p-value returned assesses the difference between them.
subset : Optional vector, if provided it will be used to subset time, event and group. See [ for further details on allowed values.
limit : Single numeric value, if not NA follow-ups will be truncated at this value (for plotting and p-value computation). No event will be considered for the truncated individuals, considering that at limit the event that may have been observed later did not occurred yet.
graph : Single logical value, whether to plot the Kaplan-Meier curves or not (for invisible computation).
test : Single logical value, whether to compute log-rank p-value and add it to the plot's legend or not.
... : Other arguments are dispatched to plot.default (and thus to par), legend or plot.survfit according to their names.
Value
Returns a list, with at least a survfit element (see survival::survfit() for more details).
If test is TRUE, p.value and method elements are also present.
Example : Generate dummy survival data
time = runif(30, 1, 20)
event = sample(c(TRUE,FALSE), 30, replace=TRUE)
group = c(rep("A", 10), rep("B", 20))
Example : Minimal call
srv(time, event, group)
Example : Customised plot
srv(time, event, group, xlab="Time (months)", ylab="Overall Survival (%)", yscale=100, las=1, x="bottomleft")