% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/phreg.R
\name{survivalG}
\alias{survivalG}
\alias{survivalGtime}
\title{G-Estimator for Cox and Fine-Gray Models}
\usage{
survivalG(
  x,
  data,
  time = NULL,
  Avalues = NULL,
  varname = NULL,
  same.data = TRUE,
  First = FALSE
)
}
\arguments{
\item{x}{Object of class \code{"phreg"} or \code{"cifreg"}.}

\item{data}{Data frame for risk averaging. Must be part of the data used for fitting unless \code{same.data=FALSE}.}

\item{time}{Time point for estimation.}

\item{Avalues}{Values to compare for the first covariate \eqn{A}.}

\item{varname}{Name of the variable to be treated as the treatment/exposure variable (default is the first variable).}

\item{same.data}{Logical; assumes the same data is used for fitting and averaging.}

\item{First}{Logical; if \code{TRUE}, uses only the first record for G-averaging (useful for start-stop structures).}
}
\value{
An object of class \code{"survivalG"} containing:
\item{risk}{Standardized risk estimates.}
\item{risk.iid}{Influence functions for the risk estimates.}
\item{difference}{Pairwise differences in risks.}
\item{ratio}{Risk ratios.}
\item{survival.ratio}{Survival ratios (for \code{phreg}).}
\item{survival.difference}{Survival differences (for \code{phreg}).}
}
\description{
Computes the G-estimator (G-formula) for standardized survival or cumulative incidence estimates:
\deqn{ \hat S(t, A=a) = n^{-1} \sum_i \hat S(t, A=a, Z_i) }
}
\details{
Based on a \code{phreg} or \code{cifreg} object. Provides influence functions for these risk estimates,
allowing for standard error computation.

If the first covariate is a factor, contrasts between all levels are computed automatically.
If it is continuous, specific values must be provided via \code{Avalues}.
}
\examples{
data(bmt)
bmt$time <- bmt$time + runif(408) * 0.001
bmt$event <- (bmt$cause != 0) * 1
bmt$id <- 1:408
dfactor(bmt) <- tcell.f ~ tcell

# Fine-Gray model
fg1 <- cifreg(Event(time, cause) ~ tcell.f + platelet + age, bmt,
              cause = 1, cox.prep = TRUE, propodds = NULL)
summary(survivalG(fg1, bmt, 50))

\donttest{ ## Reduce Ex.Timings
# Cox model
ss <- phreg(Surv(time, event) ~ tcell.f + platelet + age, bmt)
summary(survivalG(ss, bmt, 50))

# Stratified Cox model
ss <- phreg(Surv(time, event) ~ strata(tcell.f) + platelet + age, bmt)
summary(survivalG(ss, bmt, 50))

# Time-varying G-estimates
sst <- survivalGtime(ss, bmt, n = 50)
plot(sst)

# Among treated (specify id to link influence functions)
ss <- phreg(Surv(time, event) ~ tcell.f + platelet + age + cluster(id), bmt)
summary(survivalG(ss, subset(bmt, tcell == 1), 50))
}
}
\author{
Thomas Scheike
}
