StatKmband | R Documentation |
Adds confidence bands to a Kaplan Meier Estimate of Survival
StatKmband
stat_kmband(
mapping = NULL,
data = NULL,
geom = "kmband",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
trans = "identity",
firstx = 0,
firsty = 1,
type = "kaplan-meier",
error = "tsiatis",
conf.type = "log",
conf.lower = "usual",
start.time = 0,
conf.int = 0.95
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use display the data |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
trans |
Transformation to apply to the survival probabilities. Defaults to "identity". Other options include "event", "cumhaz", "cloglog", or define your own using trans_new. |
firstx, firsty |
the starting point for the survival curves. By default, the plot program obeys tradition by having the plot start at (0,1). |
conf.int |
to control significance level which is 0.95 by default |
... |
Other arguments passed to |
An object of class StatKmband
(inherits from Stat
, ggproto
, gg
) of length 4.
This stat is for computing the confidence intervals for the Kaplan-Meier survival estimate for
right-censored data. It requires the aesthetic mapping x
for the
observation times and status
which indicates the event status,
0=alive, 1=dead or 1/2 (2=death). Logical status is not supported.
a data.frame with additional columns:
x |
x in data |
ymin |
Lower confidence
limit of KM curve, if |
ymax |
Upper confidence limit of KM curve |
stat_kmband
understands the following aesthetics (required aesthetics
are in bold):
time
The survival times
status
The censoring indicator, see Surv for more information.
alpha
color
linetype
size
sex <- rbinom(250, 1, .5)
df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex)
ggplot(df, aes(time = time, status = status, color = factor(sex))) +
stat_km()
## Examples illustrating the options passed to survfit.formula
p1 <- ggplot(df, aes(time = time, status = status))
p1 + stat_km() + stat_kmband(conf.int = .99)
p1 + stat_km() + stat_kmband(error = "tsiatis")
p1 + stat_km() + stat_km(conf.type = "log-log")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.