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

\item{times}{Numeric vector of follow-up times for the risk table.}

\item{digits}{Number of digits for displayed follow-up times.}

\item{extend}{Logical. If \code{TRUE}, requested times beyond the observed
follow-up range are retained using the last available Kaplan-Meier risk set.}

\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","km_risk_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 Kaplan-Meier risk table counts.}
  \item{\code{table_display}}{Display data frame used to render the table.}
  \item{\code{fit}}{Fitted \code{survfit} object.}
  \item{\code{time,event,by,times,format,source}}{Metadata fields.}
}
}
\description{
Tabulate the number at risk at selected follow-up times.
}
\details{
The \code{At risk} column gives the number still under observation at each
requested time. The \code{Events} and \code{Censored} columns are interval
counts up to each requested time point as returned by
\code{summary.survfit()}.
}
\examples{
lung_data <- data_lungcancer
lung_data$trt <- factor(lung_data$trt, levels = c(1, 2),
                        labels = c("Standard", "Test"))

km_risk_table(
  data = lung_data,
  time = time,
  event = status,
  by = trt,
  times = c(0, 90, 180, 365)
)

km_risk_table(
  data = lung_data,
  time = "time",
  event = "status",
  times = c(0, 90, 180),
  format = tibble
)

}
