% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/survival_summary.R
\name{survival_summary}
\alias{survival_summary}
\title{Kaplan-Meier survival summary table}
\usage{
survival_summary(
  data,
  time,
  event,
  by = NULL,
  digits = 1,
  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 Kaplan-Meier summaries.
Quoted and bare names are accepted.}

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

\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","survival_summary", ...)}
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 Kaplan-Meier 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,format,source}}{Metadata fields.}
}
}
\description{
Summarise Kaplan-Meier follow-up with total N, events, censoring, and median
survival with a 95% confidence interval.
}
\details{
Median survival is estimated from \code{survival::survfit()}. If the median
survival time is not reached during follow-up, the display table shows
\code{"Not reached"}.
}
\examples{
lung_data <- data_lungcancer
lung_data$trt <- factor(lung_data$trt, levels = c(1, 2),
                        labels = c("Standard", "Test"))

survival_summary(
  data = lung_data,
  time = time,
  event = status,
  by = trt
)

survival_summary(
  data = lung_data,
  time = "time",
  event = "status",
  format = tibble
)

}
