% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/survival_prob.R
\name{survival_prob}
\alias{survival_prob}
\title{Kaplan-Meier survival probability table}
\usage{
survival_prob(
  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 survival
probabilities. Quoted and bare names are accepted.}

\item{times}{Numeric vector of follow-up times at which survival probability
should be estimated.}

\item{digits}{Number of digits for percentages and survival probabilities.}

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

\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_prob", ...)}
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 survival probabilities.}
  \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{
Estimate Kaplan-Meier survival probabilities at user-specified follow-up
times, such as 30-day, 6-month, or 1-year survival.
}
\details{
Survival probabilities are estimated from \code{survival::survfit()} at the
requested follow-up times. Events and censored counts 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"))

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

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

}
