| tabsurv | R Documentation |
Performs descriptive survival analysis, Kaplan-Meier/Aalen-Johansen estimates, optional life tables, cumulative incidence at selected times, incidence rate, log-rank tests, Cox regression, proportional-hazards diagnostics, RMST, competing-risk Fine-Gray models, and counting-process/recurrent-event Cox models.
tabsurv(
time,
event,
vars = NULL,
by = NULL,
data = NULL,
failure = NULL,
compete = NULL,
id = NULL,
start = NULL,
unit = NULL,
followup = NULL,
km = NULL,
lifetable = FALSE,
at = NULL,
risk = NULL,
cuminc = NULL,
rate = NULL,
scale = 100,
logrank = NULL,
rr = NULL,
rd = NULL,
irr = NULL,
cox = NULL,
adjusted = NULL,
multi = NULL,
strata = NULL,
cluster = NULL,
frailty = NULL,
finegray = NULL,
recurrent = FALSE,
rmst = NULL,
tau = NULL,
ph = NULL,
interaction = FALSE,
superby = NULL,
ci = 0.95,
digit = 2,
p_digit = 3,
effect_digit = 2,
missing = FALSE,
plot = NULL,
title = NULL,
show = TRUE,
console = FALSE,
ai = FALSE,
ties = c("efron", "breslow", "exact"),
report = c("auto", "brief", "full", "custom"),
plot_args = list(),
interpretation = FALSE,
export = NULL,
file = NULL,
open = FALSE,
strict = FALSE
)
time |
Follow-up or stop-time variable, supplied without quotes. |
event |
Event/status variable, supplied without quotes. |
vars |
Optional predictor specification created by |
by |
Optional grouping variable for survival curves and comparisons.
Hierarchical syntax is supported: in |
data |
Optional data frame. When omitted, active R4VN data are used. |
failure |
Value of |
compete |
Optional competing-event value(s). When supplied, |
id |
Optional subject identifier for counting-process/recurrent data. |
start |
Optional start/entry time. When supplied, |
unit |
Optional display unit such as "day", "month", or "year". |
followup |
Estimate median follow-up using reverse Kaplan-Meier when possible.
With |
km |
Fit Kaplan-Meier (ordinary survival) or Aalen-Johansen (competing risks). |
lifetable |
Show a detailed life table at every observed time. The
default is |
at |
Optional time points for survival/risk/rate summaries. With
|
risk |
Report cumulative risk at |
cuminc |
Optional numeric time points at which cumulative incidence is
required, for example |
rate |
|
scale |
Rate multiplier, e.g. 100 for events per 100 person-time units. |
logrank |
Perform a log-rank test when |
rr, rd |
Compare cumulative risks between two |
irr |
Compare incidence rates between two |
cox |
Fit crude Cox models for variables in |
adjusted |
FALSE/NULL, TRUE (adjust each focal predictor for all other focal
predictors), or a |
multi |
FALSE/NULL, TRUE (all |
strata |
Optional stratification variable for Cox regression. |
cluster |
Optional clustering variable for robust Cox variance. |
frailty |
Optional shared-frailty variable. Do not combine with |
finegray |
Fit a Fine-Gray subdistribution hazards model when |
recurrent |
FALSE/TRUE or "ag". TRUE is Andersen-Gill and requires
|
rmst |
Compute restricted mean survival time. |
tau |
Restriction time for RMST. Defaults to the largest common curve time. |
ph |
Test the proportional-hazards assumption with |
interaction |
Optional |
superby |
Optional outer subgroup variable retained for backward compatibility.
For new code, multiple ordered outer strata can be supplied directly in
|
ci |
Confidence level, default 0.95. |
digit, p_digit, effect_digit |
Display digits. |
missing |
Show missing/exclusion information when printing. |
plot |
Draw a survival/CIF curve using |
title |
Optional title. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the traditional result in the Console. Default |
ai |
Prepare a compact de-identified interpretation payload in |
ties |
Cox tie method: "efron", "breslow", or "exact". |
report |
Reporting profile: |
plot_args |
Named list of additional arguments passed to |
interpretation |
Add a cautious, deterministic interpretation table.
The default is |
export |
Optional export format accepted by |
file |
Optional export filename. Its extension may also determine the export format. |
open |
Open the exported file when supported. |
strict |
If |
An object of class r4vn_surv. Backward-compatible components are
retained, with a consistent reporting contract in $descriptive,
$estimates, $tests, $diagnostics, $interpretation, $tables,
$plots, $models, $metadata, and $call.
if (requireNamespace("survival", quietly = TRUE)) {
# Reproducible two-group data from the survival package.
d <- survival::lung
d$death <- as.integer(d$status == 2)
d$group <- factor(d$sex, levels = c(1, 2),
labels = c("Male", "Female"))
# 1. Complete two-group report. This includes the log-rank test.
km <- tabsurv(
time, death, by = group, data = d, failure = 1,
unit = "day", at = c(90, 180, 365, 540),
report = "auto", plot = FALSE, show = FALSE
)
km$logrank
km$tests$logrank
km$logrank$p
# 2. Cumulative incidence at 6, 12, and 24 months.
d$month <- d$time / 30.4375
ci_month <- tabsurv(
month, death, by = group, data = d, failure = 1,
cuminc = c(6, 12, 24), report = "custom", show = FALSE
)
ci_month$cuminc
# 3. Detailed life table and interpretation are both opt-in.
km_detail <- tabsurv(
time, death, by = group, data = d, failure = 1,
at = c(90, 180, 365, 540),
lifetable = TRUE, interpretation = TRUE, show = FALSE
)
head(km_detail$lifetable)
km_detail$interpretation
# 4. A compact KM plus log-rank analysis without automatic extras.
km_simple <- tabsurv(
time, death, by = group, data = d, failure = 1,
report = "custom", km = TRUE, logrank = TRUE,
plot = FALSE, show = FALSE
)
# 5. Explicit two-group effect measures and RMST.
km_compare <- tabsurv(
time, death, by = group, data = d, failure = 1,
at = c(90, 180, 365, 540), risk = TRUE,
rr = TRUE, rd = TRUE, rate = "all", irr = TRUE,
rmst = TRUE, tau = 365, show = FALSE
)
km_compare$risk_compare
km_compare$irr
km_compare$rmst
# 6. Publication graphs, including risk tables, are documented in ?gsurv.
# Keeping graphics out of this example also keeps tabsurv() examples fast
# and executable on non-interactive CRAN check devices.
# 7. With competing risks, use the Aalen-Johansen CIF, not 1-KM.
set.seed(2026)
n <- 180
t1 <- rexp(n, 0.07)
t2 <- rexp(n, 0.05)
tc <- runif(n, 4, 30)
tm <- pmin(t1, t2, tc)
dcr <- data.frame(
time = tm,
status = ifelse(tm == t1, 1L, ifelse(tm == t2, 2L, 0L)),
group = factor(rep(c("A", "B"), each = n / 2))
)
cif <- tabsurv(
time, status, by = group, data = dcr,
failure = 1, compete = 2, cuminc = c(6, 12, 24),
report = "custom", show = FALSE
)
cif$cuminc
# See ?gsurv for publication CIF graphs and risk tables.
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.