% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/recreg.R
\name{recreg}
\alias{recreg}
\alias{marks}
\alias{scalecumhaz}
\alias{GLprediid}
\alias{IIDrecreg}
\title{Recurrent Events Regression with Terminal Event}
\usage{
recreg(
  formula,
  data,
  cause = 1,
  death.code = 2,
  cens.code = 0,
  cens.model = ~1,
  weights = NULL,
  offset = NULL,
  Gc = NULL,
  wcomp = NULL,
  marks = NULL,
  augmentation.type = c("lindyn.augment", "lin.augment"),
  ...
)
}
\arguments{
\item{formula}{Formula with an 'Event' outcome.}

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

\item{cause}{Cause of interest (default is 1).}

\item{death.code}{Codes for the terminal event/death (default is 2).}

\item{cens.code}{Code for censoring (default is 0).}

\item{cens.model}{Formula for a stratified Cox model without covariates used to estimate censoring probabilities.}

\item{weights}{Weights for the score equations.}

\item{offset}{Offsets for the model.}

\item{Gc}{Censoring weights for the time argument. If \code{NULL}, these are calculated using a Kaplan-Meier estimator
(should then provide \eqn{G_c(T_i-)}).}

\item{wcomp}{Weights for composite outcomes (e.g., when \code{cause=c(1,3)}, \code{wcomp} might be \code{c(1,2)}).}

\item{marks}{A mark value vector from the data frame, specifying the mark value at all events.}

\item{augmentation.type}{Type of augmentation when an augmentation model is given (options: \code{"lindyn.augment"}, \code{"lin.augment"}).}

\item{...}{Additional arguments passed to lower-level functions.}
}
\value{
An object of class \code{"recreg"} (extending \code{"phreg"}) containing:
\item{coef}{Estimated coefficients.}
\item{var}{Robust variance-covariance matrix.}
\item{iid}{Influence functions for the coefficients.}
\item{cumhaz}{Cumulative hazard estimates.}
\item{se.cumhaz}{Standard errors for cumulative hazard.}
}
\description{
Fits a Ghosh-Lin IPCW (Inverse Probability of Censoring Weighted) Cox-type model for recurrent events
in the presence of a terminal event (e.g., death).
}
\details{
For the Cox-type model, the expectation is modeled as:
\deqn{ E(dN_1(t)|X) = \mu_0(t) dt \exp(X^T \beta) }
by solving Cox-type IPCW weighted score equations:
\deqn{ \int (Z - E(t)) w(t) dN_1(t) }
where \deqn{w(t) = G(t) (I(T_i \wedge t < C_i)/G_c(T_i \wedge t))},
\deqn{E(t) = S_1(t)/S_0(t)}, and \deqn{S_j(t) = \sum X_i^j w_i(t) \exp(X_i^T \beta)}.

The IID decomposition of the beta coefficients takes the form:
\deqn{ \int (Z - E) w(t) dM_1 + \int q(s)/p(s) dM_c }
and is returned as the \code{iid} component.

Events, deaths, and censorings are specified via a start-stop structure and the \code{Event} call.
The function identifies these via a status vector and cause codes, censoring codes (\code{cens.code}),
and death codes (\code{death.code}). See examples and vignettes for details.
}
\examples{
## data with no ties
data(hfactioncpx12)
hf <- hfactioncpx12
hf$x <- as.numeric(hf$treatment) 
dd <- data.frame(treatment=levels(hf$treatment),id=1)

gl <- recreg(Event(entry,time,status)~treatment+cluster(id),data=hf,cause=1,death.code=2)
summary(gl)
head(iid(gl))
pgl <- predict(gl,dd,se=1); 
plot(pgl,se=1)

## censoring stratified after treatment 
gls <- recreg(Event(entry,time,status)~treatment+cluster(id),data=hf,
cause=1,death.code=2,cens.model=~strata(treatment))
summary(gls)

glss <- recreg(Event(entry,time,status)~strata(treatment)+cluster(id),data=hf,
cause=1,death.code=2,cens.model=~strata(treatment))
summary(glss)
plot(glss)

## IPCW at 2 years 
ll2 <- recregIPCW(Event(entry,time,status)~treatment+cluster(id),data=hf,
cause=1,death.code=2,time=2,cens.model=~strata(treatment))
summary(ll2)

ll2i <- recregIPCW(Event(entry,time,status)~-1+treatment+cluster(id),data=hf,
cause=1,death.code=2,time=2,cens.model=~strata(treatment))
summary(ll2i)
}
\seealso{
\code{\link{recregIPCW}}
}
\author{
Thomas Scheike
}
