% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/phreg.R
\name{phreg}
\alias{phreg}
\alias{robust_phreg}
\title{Fast Cox Proportional Hazards Regression}
\usage{
phreg(formula, data, offset = NULL, weights = NULL, ...)
}
\arguments{
\item{formula}{Formula with a 'Surv' or 'Event' outcome (similar to \code{coxph}).}

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

\item{offset}{Offsets for the Cox model linear predictor.}

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

\item{...}{Additional arguments passed to lower-level functions (e.g., optimization controls).}
}
\value{
An object of class \code{"phreg"} containing:
\item{coef}{Vector of estimated coefficients.}
\item{var}{Robust variance-covariance matrix.}
\item{beta.iid}{Influence functions for the regression coefficients.}
\item{cumhaz}{Matrix of cumulative hazard estimates (time, cumhaz).}
\item{se.cumhaz}{Matrix of standard errors for the cumulative hazard.}
\item{cox.prep}{List containing preprocessed data for the Cox model.}
\item{opt}{Optimization results (if optimization was performed).}
\item{call}{The matched call.}
}
\description{
Fits a Cox proportional hazards model using a fast C++ backend.
Robust variance (sandwich estimator) is the default variance estimate in the summary.
}
\details{
The influence functions (IID decomposition) follow the numerical order of the given cluster variable.
Ordering the results by `$id` will align the IID terms with the original dataset order.
}
\examples{
data(TRACE)
dcut(TRACE) <- ~.
# Fit model with clustering
out1 <- phreg(Surv(time, status == 9) ~ wmi + age + strata(vf, chf) + cluster(id), data = TRACE)
summary(out1)

# Plotting baselines
par(mfrow = c(1, 2))
plot(out1)

# Computing robust variance for baseline
rob1 <- robust_phreg(out1)
plot(rob1, se = TRUE, robust = TRUE)

# IID decomposition for regression parameters
head(iid(out1))

# IID decomposition for baseline at a specific time-point
Aiiid <- iid(out1, time = 30)
head(Aiiid)

# Combined IID decomposition (beta and baseline)
dd <- iidBaseline(out1, time = 30)
head(dd$beta.iid)
head(dd$base.iid)

# Stratified model
outs <- phreg(Surv(time, status == 9) ~ strata(vf, wmicat.4) + cluster(id), data = TRACE)
summary(outs)
par(mfrow = c(1, 2))
plot(outs)
}
\seealso{
\code{\link{plot.phreg}}, \code{\link{predict.phreg}}, \code{\link{robust_phreg}}
}
\author{
Klaus K. Holst, Thomas Scheike
}
