Plot cumulative incidence estimates with a risk table and estimates below the figure.
add_cuminc_risktable(
cuminc,
survfit,
timepts,
lg,
numgrps,
line = 3,
at = -1,
col.list = 1
)
cmprsk::cuminc()
object
survival::survfit()
object
a numeric vector of time points of the estimates to display. E.g. c(0,1,2,3,4,5) or seq(0,12,by=2)
legend label for each cumulative incidence curve to be displayed. E.g. c("Male", "Female")
the number of groups of the stratification variable: 1 is no stratification, can stratify up to 3 groups
to adjust position of risk table. A lower value will shift table up, a larger value will shift table down; default is 3
to adjust position of left margin. Default is -1.
list of colors for legend text Should match the colors of plot legend. Default is 1 (black).
if (FALSE) { # interactive()
library(cmprsk)
library(survival)
data(pbc)
# recode time
pbc$time.y <- pbc$time / 365.25
# recode status- switch competing events
pbc$status2 <- ifelse(pbc$status > 0, ifelse(pbc$status == 1, 2, 1), 0)
# recode stage for 3 groups
pbc$stage.3g <- ifelse(pbc$stage %in% c(1,2), "1-2", as.character(pbc$stage))
# Example 1 -------------------------------------
# CIR and KM for no strata
cif1 <- cuminc(ftime = pbc$time.y, fstatus = pbc$status2)
km1 <- survfit(Surv(pbc$time.y, pbc$status2 == 1) ~ 1)
# Plot and add risk table for no strata (numgrps=1)
windows(5, 5)
par(mfrow = c(1, 1),
mar = c(12.5, 5.7, 2, 2),
mgp = c(2, 0.65, 0))
plot(cif1,
curvlab = c("recurred", "died"),
xlim = c(0, 12), xaxt = "n")
axis(1, at = seq(0, 12, 3))
add_cuminc_risktable(cif1, km1,
timepts = seq(0, 12, 3),
lg = "",
numgrps = 1)
# Example 2 -------------------------------------
cif2 <- cuminc(ftime = pbc$time.y,
fstatus = pbc$status2,
group = pbc$sex)
km2 <- survfit(Surv(pbc$time.y, pbc$status2 == 1) ~ pbc$sex)
# Plot and add risk table for 2 groups (numgrps=2)
windows(5, 5)
par(mfrow = c(1, 1),
mar = c(12.5, 5.7, 2, 2),
mgp = c(2, 0.65, 0))
plot(cif2,
curvlab = c("male", "female", "", ""),
lty = c(1, 2, 0, 0),
xlim = c(0, 12),
xaxt = "n", col = c(1, 2, 0, 0))
axis(1, at = seq(0, 12, 3))
add_cuminc_risktable(cif2, km2,
timepts = seq(0, 12, 3),
lg = c("male", "female"),
numgrps = 2, col.list = c(1,2))
# Example 3 -------------------------------------
cif3 <- cuminc(ftime = pbc$time.y,
fstatus = pbc$status2,
group = pbc$stage.3g)
km3 <- survfit(Surv(pbc$time.y, pbc$status2 == 1) ~ pbc$stage.3g)
windows(6,6)
par(mfrow = c(1, 1),
mar = c(14, 5.7, 2, 2), # change bottom margin
mgp = c(2, 0.65, 0))
plot(cif3,
curvlab = c("1-2", "3", "4", rep("",3)),
lty = c(1, 2, 3, rep(0, 3)),
xlim = c(0, 12),
xaxt = "n", col = c(1, 2, 4, rep(0, 3)))
axis(1, at = seq(0, 12, 3))
add_cuminc_risktable(cif3, survfit = km3,
timepts = seq(0, 12, 3),
lg = c("1-2", "3", "4"),
numgrps = 3, col.list = c(1,2,4))
}