% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/binregTSR.R
\name{binregTSR}
\alias{binregTSR}
\title{Two-Stage Randomization for Survival or Competing Risks Data}
\usage{
binregTSR(
  formula,
  data,
  cause = 1,
  time = NULL,
  cens.code = 0,
  response.code = NULL,
  augmentR0 = NULL,
  treat.model0 = ~+1,
  augmentR1 = NULL,
  treat.model1 = ~+1,
  augmentC = NULL,
  cens.model = ~+1,
  estpr = c(1, 1),
  response.name = NULL,
  offset = NULL,
  weights = NULL,
  cens.weights = NULL,
  beta = NULL,
  kaplan.meier = TRUE,
  no.opt = FALSE,
  method = "nr",
  augmentation = NULL,
  outcome = c("cif", "rmst", "rmst-cause"),
  model = "exp",
  Ydirect = NULL,
  return.dataw = 0,
  pi0 = 0.5,
  pi1 = 0.5,
  cens.time.fixed = 1,
  outcome.iid = 1,
  meanCs = 0,
  ...
)
}
\arguments{
\item{formula}{Formula with outcome (see \code{coxph}), typically \code{Event(entry,time,status)~+1+cluster(id)}.}

\item{data}{Data frame containing all variables.}

\item{cause}{Cause of interest for competing risks (default 1).}

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

\item{cens.code}{Censoring code (default 0).}

\item{response.code}{Code of status indicating response at which 2nd randomization occurs.}

\item{augmentR0}{Covariates for augmentation model of the first randomization.}

\item{treat.model0}{Logistic treatment model for the first randomization.}

\item{augmentR1}{Covariates for augmentation model of the second randomization.}

\item{treat.model1}{Logistic treatment model for the second randomization.}

\item{augmentC}{Covariates for censoring augmentation model.}

\item{cens.model}{Stratification for censoring model based on observed covariates.}

\item{estpr}{Logical; estimate randomization probabilities using model (default TRUE).}

\item{response.name}{Name of response variable (reads from \code{treat.model1} if NULL).}

\item{offset}{Not implemented.}

\item{weights}{Not implemented.}

\item{cens.weights}{Can be provided externally.}

\item{beta}{Starting values for optimization.}

\item{kaplan.meier}{Logical; use Kaplan-Meier for censoring weights rather than exp cumulative hazard.}

\item{no.opt}{Not implemented.}

\item{method}{Not implemented.}

\item{augmentation}{Not implemented.}

\item{outcome}{Outcome type: \code{"cif"} (cumulative incidence), \code{"rmst"} (restricted mean survival time), 
or \code{"rmst-cause"} (restricted mean time lost for cause).}

\item{model}{Not implemented, uses linear regression for augmentation.}

\item{Ydirect}{Use this Y instead of outcome constructed inside the program.}

\item{return.dataw}{Logical; return weighted data for all treatment regimes.}

\item{pi0}{Known randomization probabilities for first randomization.}

\item{pi1}{Known randomization probabilities for second randomization.}

\item{cens.time.fixed}{Logical; use time-dependent weights for censoring estimation.}

\item{outcome.iid}{Logical; get iid contribution from outcome model.}

\item{meanCs}{Logical; indicates censoring augmentation is centered by \code{CensAugment.times/n}.}

\item{...}{Additional arguments to lower-level functions.}
}
\value{
An object of class \code{"binregTSR"} containing:
  \item{riskG}{Simple estimator results (coefficient, SE).}
  \item{riskG0}{First randomization augmentation results.}
  \item{riskG1}{Second randomization augmentation results.}
  \item{riskG01}{Both randomizations augmentation results.}
  \item{riskG.iid}{Influence functions for all estimators.}
  \item{varG}{Variance-covariance matrices.}
  \item{MGc}{Censoring martingale contributions.}
  \item{CensAugment.times}{Censoring augmentation terms.}
  \item{dynCens.coef}{Dynamic censoring coefficients.}
  \item{dataW}{Weighted data (if \code{return.dataw=TRUE}).}
}
\description{
Estimates the average treatment effect \eqn{E(Y(i,j))} of treatment regime \eqn{(i,j)} 
under two-stage randomization. The estimator can be augmented using information from 
both randomizations and dynamic censoring augmentation to improve efficiency.
}
\details{
The method solves the estimating equation:
\deqn{ \frac{I(\min(T_i,t) < G_i)}{G_c(\min(T_i,t))} I(T \leq t, \epsilon=1) - AUG_0 - AUG_1 + AUG_C - p(i,j) = 0 }
where:
\itemize{
  \item \eqn{AUG_0 = \frac{A_0(i) - \pi_0(i)}{\pi_0(i)} X_0 \gamma_0} uses covariates from \code{augmentR0}
  \item \eqn{AUG_1 = \frac{A_0(i)}{\pi_0(i)} \frac{A_1(j) - \pi_1(j)}{\pi_1(j)} X_1 \gamma_1} uses covariates from \code{augmentR1}
  \item \eqn{AUG_C = \int_0^t \gamma_c(s)^T (e(s) - \bar e(s)) \frac{1}{G_c(s)} dM_c(s)} is the censoring augmentation
}

Standard errors are estimated using the influence function of all estimators, enabling 
tests of differences to be computed subsequently. The method handles both survival 
data and competing risks data, and supports multiple treatment levels.
}
\examples{
ddf <- mets:::gsim(200,covs=1,null=0,cens=1,ce=2)

bb <- binregTSR(Event(entry,time,status)~+1+cluster(id),ddf$datat,time=2,cause=c(1),
        cens.code=0,treat.model0=A0.f~+1,treat.model1=A1.f~A0.f,
        augmentR1=~X11+X12+TR,augmentR0=~X01+X02,
        augmentC=~A01+A02+X01+X02+A11t+A12t+X11+X12+TR,
        response.code=2)
summary(bb) 
}
\references{
Scheike, T. H. (2024). Two-stage randomization analysis for survival data. mets package documentation.
}
\seealso{
\code{\link{binreg}}, \code{\link{phreg_rct}}
}
\author{
Thomas Scheike
}
