Function to divide x
(e.g. age, or predicted survival at time
u
created by survest
) into g
quantile groups, get
Kaplan-Meier estimates at time u
(a scaler), and to return a
matrix with columns x
=mean x
in quantile, n
=number
of subjects, events
=no. events, and KM
=K-M survival at
time u
, std.err
= s.e. of -log K-M. Confidence intervals
are based on -log S(t). Instead of supplying g
, the user can
supply the minimum number of subjects to have in the quantile group
(m
, default=50). If cuts
is given
(e.g. cuts=c(0,.1,.2,...,.9,.1)
), it overrides m
and
g
. Calls Therneau's survfitKM
in the survival
package to get Kaplan-Meiers estimates and standard errors.
groupkm(x, Srv, m=50, g, cuts, u,
pl=FALSE, loglog=FALSE, conf.int=.95, xlab, ylab,
lty=1, add=FALSE, cex.subtitle=.7, ...)
matrix with columns named x
(mean predictor value in interval), n
(sample size
in interval), events
(number of events in interval), KM
(Kaplan-Meier
estimate), std.err
(standard error of -log KM
)
variable to stratify
a Surv
object - n x 2 matrix containing survival
time and event/censoring
1/0 indicator. Units of measurement come from the "units" attribute
of the survival time variable. "Day" is the default.
desired minimum number of observations in a group
number of quantile groups
actual cuts in x
, e.g. c(0,1,2)
to use [0,1), [1,2].
time for which to estimate survival
TRUE to plot results
set to TRUE
to plot log(-log(survival))
instead of survival
defaults to .95
for 0.95 confidence bars. Set to FALSE
to suppress bars.
if pl=TRUE
, is x-axis label. Default is label(x)
or name of calling argument
if pl=TRUE
, is y-axis label. Default is constructed from u
and time units
attribute.
line time for primary line connecting estimates
set to TRUE
if adding to an existing plot
character size for subtitle. Default is .7
. Use FALSE
to
suppress subtitle.
plotting parameters to pass to the plot and errbar functions
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50))
d.time <- -log(runif(n))/h
label(d.time) <- 'Follow-up Time'
e <- ifelse(d.time <= cens,1,0)
d.time <- pmin(d.time, cens)
units(d.time) <- "Year"
groupkm(age, Surv(d.time, e), g=10, u=5, pl=TRUE)
#Plot 5-year K-M survival estimates and 0.95 confidence bars by
#decile of age. If omit g=10, will have >= 50 obs./group.
Run the code above in your browser using DataLab