% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gof-phreg.R
\name{gof.phreg}
\alias{gof.phreg}
\title{Goodness-of-Fit for Cox PH Regression (Proportionality)}
\usage{
\method{gof}{phreg}(object, n.sim = 1000, silent = 1, robust = NULL, ...)
}
\arguments{
\item{object}{A fitted \code{phreg} object (from \code{mets} or \code{survival}).}

\item{n.sim}{Number of simulations for the resampling procedure (default 1000).}

\item{silent}{Logical; if TRUE, suppresses timing estimates for long jobs.}

\item{robust}{Logical; if TRUE, uses robust martingale-based simulations. 
If NULL, defaults to TRUE if a cluster term is detected in the model call.}

\item{...}{Additional arguments passed to lower-level functions.}
}
\value{
An object of class \code{"gof.phreg"} containing:
  \item{jumptimes}{Event times used in the process.}
  \item{supUsim}{Matrix of simulated supremum values for each covariate.}
  \item{res}{Matrix with observed supremum (\code{Sup|U(t)|}) and p-values.}
  \item{supU}{Observed supremum values.}
  \item{pvals}{Vector of p-values for each covariate.}
  \item{score}{Cumulative score process values over time.}
  \item{simUt}{Simulated score processes.}
  \item{type}{Type of test performed ("prop").}
  \item{robust}{Logical flag indicating if robust simulation was used.}
}
\description{
Performs cumulative score process residual tests for the proportional hazards (PH) 
assumption in Cox regression. The test statistics are based on the cumulative 
score process:
\deqn{ U(t) = \int_0^t (X_i - E(t) ) d \hat M_i(s) }
where \eqn{\hat M_i(s)} are the martingale residuals.
}
\details{
P-values are computed using the Lin, Wei, and Ying (1993) resampling method, which 
simulates the asymptotic distribution of the supremum of the score process under 
the null hypothesis of proportional hazards.

The function supports two types of simulation:
\itemize{
  \item \strong{Standard}: Uses \eqn{dN_i} (counting process increments) for simulation.
  \item \strong{Robust}: Uses \eqn{\hat M_i(t)} (martingale residuals) adjusted for clustering 
    if a \code{cluster()} term is present in the model.
}
}
\examples{
data(sTRACE)

m1 <- phreg(Surv(time,status==9)~vf+chf+diabetes, data=sTRACE) 
gg <- gof(m1)
gg
par(mfrow=c(1,3))
plot(gg)

m1 <- phreg(Surv(time,status==9)~strata(vf)+chf+diabetes, data=sTRACE) 
gg <- gof(m1)

## Robust simulations with cluster
sTRACE$id <- 1:500
m1 <- phreg(Surv(time,status==9)~vf+chf+diabetes+cluster(id), data=sTRACE) 
gg <- gof(m1)
gg
}
\references{
Lin, D. Y., Wei, L. J., & Ying, Z. (1993). Checking the Cox model with cumulative sums of martingale-based residuals. Biometrika, 80(3), 557-572.
}
\seealso{
\code{\link{gofM_phreg}}, \code{\link{gofZ_phreg}}
}
\author{
Thomas Scheike and Klaus K. Holst
}
