% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cifreg.R
\name{cifreg}
\alias{cifreg}
\alias{vecAllStrata}
\alias{diffstrata}
\alias{FGprediid}
\alias{indexstratarightR}
\alias{gofFG}
\title{Cumulative Incidence Function (CIF) Regression}
\usage{
cifreg(
  formula,
  data,
  propodds = 1,
  cause = 1,
  cens.code = 0,
  no.codes = NULL,
  death.code = NULL,
  ...
)
}
\arguments{
\item{formula}{Formula with an 'Event' outcome.}

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

\item{propodds}{Logical; if \code{1} (default), fits the logit link model. If \code{NULL}, fits the Fine-Gray model.}

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

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

\item{no.codes}{Event codes to be ignored when identifying competing causes (useful for administrative censoring).}

\item{death.code}{Codes for death (terminal events). If \code{NULL}, defaults to all remaining codes (excluding \code{cause}, \code{cens.code}, and \code{no.codes}).}

\item{...}{Additional arguments passed to \code{recreg}.}
}
\value{
An object of class \code{"cifreg"} (extending \code{"phreg"}) containing:
\item{coef}{Estimated coefficients.}
\item{var}{Robust variance-covariance matrix.}
\item{iid}{Influence functions for the coefficients.}
\item{cumhaz}{Cumulative incidence estimates.}
\item{propodds}{Indicator of the link function used.}
}
\description{
Fits a regression model for the cumulative incidence function (CIF) in the presence of competing risks.
Supports two link functions:
\itemize{
\item \code{propodds=1} (default): Logistic link model (logit of CIF), providing Odds Ratio (OR) interpretations.
\item \code{propodds=NULL}: Fine-Gray (cloglog) regression model, providing subdistribution hazard ratio interpretations.
}
}
\details{
For the Fine-Gray model, the score equations are:
\deqn{ \int (X - E(t)) Y_1(t) w(t) dM_1 }
summed over clusters and returned as \code{iid.naive} (multiplied by the inverse of the second derivative).
Here, \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 Y_{i1}(t) w_i(t) \exp(X_i^T \beta)}.

The full influence function (IID decomposition) for the beta coefficients includes a censoring term:
\deqn{ \int (X - E(t)) Y_1(t) w(t) dM_1 + \int q(s)/p(s) dM_c }
which is returned as the \code{iid} component.

For the logistic link model, standard errors may be slightly underestimated because uncertainty from the
recursive baseline estimation is not fully accounted for. For smaller datasets, it is recommended to use
the \code{prop.odds.subdist} function from the \pkg{timereg} package (which uses more efficient weights)
or to bootstrap the standard errors.
}
\examples{
## data with no ties
data(bmt,package="mets")
bmt$time <- bmt$time+runif(nrow(bmt))*0.01
bmt$id <- 1:nrow(bmt)

## logistic link  OR interpretation
or=cifreg(Event(time,cause)~tcell+platelet+age,data=bmt,cause=1)
summary(or)
par(mfrow=c(1,2))
plot(or)
nd <- data.frame(tcell=c(1,0),platelet=0,age=0)
por <- predict(or,nd)
plot(por)

## approximate standard errors 
por <-mets:::predict.phreg(or,nd)
plot(por,se=1)

## Fine-Gray model
fg=cifregFG(Event(time,cause)~tcell+platelet+age,data=bmt,cause=1)
summary(fg)
##fg=recreg(Event(time,cause)~tcell+platelet+age,data=bmt,cause=1,death.code=2)
##summary(fg)
plot(fg)
nd <- data.frame(tcell=c(1,0),platelet=0,age=0)
pfg <- predict(fg,nd,se=1)
plot(pfg,se=1)

## bt <- iidBaseline(fg,time=30)
## bt <- IIDrecreg(fg$cox.prep,fg,time=30)

## not run to avoid timing issues
## gofFG(Event(time,cause)~tcell+platelet+age,data=bmt,cause=1)

sfg <- cifregFG(Event(time,cause)~strata(tcell)+platelet+age,data=bmt,cause=1)
summary(sfg)
plot(sfg)

### predictions with CI based on iid decomposition of baseline and beta
### these are used in the predict function above
fg <- cifregFG(Event(time,cause)~tcell+platelet+age,data=bmt,cause=1)
Biid <- iidBaseline(fg,time=20)
pfg1 <- FGprediid(Biid,nd)
pfg1
}
\seealso{
\code{\link{cifregFG}}, \code{\link{recreg}}, \code{\link{gofFG}}
}
\author{
Thomas Scheike
}
