% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/restricted.mean.R
\name{resmeanIPCW}
\alias{resmeanIPCW}
\alias{rmstIPCW}
\title{Restricted IPCW Mean for Censored Survival Data}
\usage{
resmeanIPCW(formula, data, outcome = c("rmst", "rmtl"), ...)
}
\arguments{
\item{formula}{Formula with an \code{Event} outcome (e.g., \code{Event(time, cause)}).}

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

\item{outcome}{Outcome type: \code{"rmst"} (Restricted Mean Survival Time) or 
\code{"rmtl"} (Restricted Mean Time Lost).}

\item{...}{Additional arguments passed to \code{binreg}, such as \code{time}, \code{cause}, 
\code{cens.model}, \code{model}, \code{type}, etc.}
}
\value{
An object of class \code{"binreg"} containing:
  \item{coef}{Coefficient estimates.}
  \item{se}{Standard errors.}
  \item{var}{Variance-covariance matrix.}
  \item{iid}{Influence function decomposition.}
  \item{naive.var}{Variance under known censoring model (if applicable).}
  \item{time}{Time point used.}
  \item{outcome}{Type of outcome analyzed.}
}
\description{
Provides a fast implementation of Inverse Probability of Censoring Weighting (IPCW) 
regression for a single time point. It fits the model:
\deqn{ E( \min(T, t) | X ) = \exp( X^T \beta) }
or, in the case of competing risks data:
\deqn{ E( I(\epsilon=1) (t - \min(T, t)) | X ) = \exp( X^T \beta) }
which represents the "Years Lost Due to Cause" (RMTL).
}
\details{
The method solves the binomial regression IPCW response estimating equation:
\deqn{ X \left( \frac{\Delta(\min(T,t)) Y}{G_c(\min(T,t))} - \exp( X^T \beta) \right) = 0 }
where \eqn{\Delta(\min(T,t)) = I(\min(T,t) \leq C)} is the indicator of being uncensored 
at the time of interest.

When the status variable is binary, the outcome is assumed to be \eqn{Y = \min(T,t)} (RMST).
If the status has more than two levels (competing risks), the outcome is 
\eqn{Y = (t - \min(T,t)) I(\text{status}=\text{cause})} (RMTL for a specific cause).

The function supports:
\itemize{
  \item \strong{IPCW Adjustment}: Weights by the inverse of the censoring survival probability.
  \item \strong{Augmentation}: Can include an augmentation term (type="II" or "III") to improve efficiency 
    and robustness (Double Robust estimation).
  \item \strong{Variance Estimation}: Based on the influence function, including adjustments for 
    the estimation of the censoring model.
}
}
\examples{
data(bmt); bmt$time <- bmt$time+runif(nrow(bmt))*0.001

# E( min(T;t) | X ) = exp( a+b X) with IPCW estimation 
out <- resmeanIPCW(Event(time,cause!=0)~tcell+platelet+age, bmt,
                time=50, cens.model=~strata(platelet), model="exp")
summary(out)

\donttest{ ## Reduce Ex.Timings
## Weighted GLM version (RMST)
out2 <- logitIPCW(Event(time,cause!=0)~tcell+platelet+age, bmt,
            time=50, cens.model=~strata(platelet), model="exp", outcome="rmst")
summary(out2)

### Time-lost (RMTL)
outtl <- resmeanIPCW(Event(time,cause!=0)~tcell+platelet+age, bmt,
                time=50, cens.model=~strata(platelet), model="exp", outcome="rmtl")
summary(outtl)

### Same as Kaplan-Meier for full censoring model 
bmt$int <- with(bmt, strata(tcell, platelet))
out <- resmeanIPCW(Event(time,cause!=0)~-1+int, bmt, time=30,
                             cens.model=~strata(platelet, tcell), model="lin")
estimate(out)
out1 <- phreg(Surv(time,cause!=0)~strata(tcell,platelet), data=bmt)
rm1 <- resmean_phreg(out1, times=30)
summary(rm1)

### Years lost regression
outl <- resmeanIPCW(Event(time,cause!=0)~-1+int, bmt, time=30, outcome="years-lost",
                             cens.model=~strata(platelet, tcell), model="lin")
estimate(outl)

## Competing risks years-lost for cause 1  
out <- resmeanIPCW(Event(time,cause)~-1+int, bmt, time=30, cause=1,
                            cens.model=~strata(platelet, tcell), model="lin")
estimate(out)
## Same as integrated cumulative incidence 
rmc1 <- cif_yearslost(Event(time,cause)~strata(tcell,platelet), data=bmt, times=30)
summary(rmc1)
}
}
\references{
Scheike, T. and Holst, K. K. (2024). Restricted mean time lost for survival and competing risks data using mets in R. WIP.
}
\seealso{
\code{\link{binreg}}, \code{\link{resmeanATE}}, \code{\link{rmstIPCW}}
}
\author{
Thomas Scheike
}
