% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rmst_table.R
\name{rmst_table}
\alias{rmst_table}
\title{Restricted mean survival time table}
\usage{
rmst_table(
  data,
  time,
  event,
  by = NULL,
  tau,
  digits = 1,
  conf.level = 0.95,
  format = c("flextable", "gt", "tibble"),
  theme = c("minimal")
)
}
\arguments{
\item{data}{A \code{data.frame} containing survival time and event status.}

\item{time}{Survival follow-up time. Quoted and bare names are accepted.}

\item{event}{Event indicator. Quoted and bare names are accepted. Numeric
\code{0/1}, numeric \code{1/2}, logical, character, and factor variables
are accepted. For two-level character or factor variables, the second level
is treated as the event.}

\item{by}{Optional grouping variable for separate RMST estimates. Quoted and
bare names are accepted.}

\item{tau}{Restriction time for RMST. For example, \code{tau = 365} reports
mean survival time restricted to the first 365 days of follow-up.}

\item{digits}{Number of digits for displayed survival time summaries.}

\item{conf.level}{Confidence level for RMST confidence intervals.}

\item{format}{Output format. One of \code{"flextable"} (default),
\code{"gt"}, or \code{"tibble"}.}

\item{theme}{Table styling preset.}
}
\value{
A list of class \code{c("gtregression","rmst_table", ...)} with
elements:
\describe{
  \item{\code{table}}{A \code{flextable}, \code{gt_tbl}, or \code{NULL}
  when \code{format = "tibble"}.}
  \item{\code{table_body}}{Tibble with numeric RMST summaries.}
  \item{\code{table_display}}{Display data frame used to render the table.}
  \item{\code{fit}}{Fitted \code{survfit} object.}
  \item{\code{time,event,by,tau,format,source}}{Metadata fields.}
}
}
\description{
Estimate restricted mean survival time (RMST) up to a user-specified follow-up
time. RMST is the average survival time observed within a fixed time window,
such as 365 days.
}
\details{
RMST is estimated from \code{survival::survfit()} using Kaplan-Meier methods
and \code{summary.survfit(rmean = tau)}. When \code{by} has exactly two
groups, the table includes the RMST difference as the second group minus the
first group, with a Wald confidence interval and p-value based on the
reported RMST standard errors.
}
\examples{
lung_data <- data_lungcancer
lung_data$trt <- factor(lung_data$trt, levels = c(1, 2),
                        labels = c("Standard", "Test"))

rmst_table(
  data = lung_data,
  time = time,
  event = status,
  by = trt,
  tau = 365
)

rmst_table(
  data = lung_data,
  time = "time",
  event = "status",
  tau = 180,
  format = tibble
)

}
