% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gof-phreg.R
\name{gofZ_phreg}
\alias{gofZ_phreg}
\alias{cumContr}
\title{Goodness-of-Fit for Cox Covariates (Linearity)}
\usage{
gofZ_phreg(
  formula,
  data,
  vars = NULL,
  offset = NULL,
  weights = NULL,
  breaks = 50,
  equi = FALSE,
  n.sim = 1000,
  silent = 1,
  ...
)
}
\arguments{
\item{formula}{Formula for the Cox regression.}

\item{data}{Data frame.}

\item{vars}{Vector of variable names to test. If NULL, automatically detects continuous 
covariates with more than 2 levels.}

\item{offset}{Offset vector.}

\item{weights}{Weights vector.}

\item{breaks}{Number of break points for the grid (default 50).}

\item{equi}{Logical; if TRUE, uses equidistant breaks; if FALSE, uses quantiles.}

\item{n.sim}{Number of simulations (default 1000).}

\item{silent}{Logical; suppresses timing estimates.}

\item{...}{Additional arguments passed to \code{gofM_phreg}.}
}
\value{
An object of class \code{"gof.phreg"} with type "Zmodelmatrix" containing:
  \item{res}{Matrix of p-values for each tested variable.}
  \item{Zres}{List of \code{gof.phreg} objects, one for each variable.}
  \item{type}{Type of test ("Zmodelmatrix").}
}
\description{
Tests the functional form of continuous covariates in a Cox PH model to check for 
linearity. It computes cumulative residuals evaluated at a grid of covariate values \eqn{z}.
}
\details{
The test statistic is:
\deqn{ U(z, \tau) = \int_0^\tau K(z)^T d \hat M }
where \eqn{K(z)} is a design matrix based on indicator functions \eqn{I(Z_i \leq z_l)} 
for a grid of points \eqn{z_l}.

The p-value is valid but depends on the chosen grid. As the number of break points increases, 
this test converges to the original Lin, Wei, and Ying test for linearity.
}
\examples{
data(TRACE)
set.seed(1)
TRACEsam <- blocksample(TRACE, idvar="id", replace=FALSE, 100)

## Test linearity of continuous covariates
\donttest{ ## Reduce Ex.Timings
m1 <- gofZ_phreg(Surv(time,status==9)~strata(vf)+chf+wmi+age, data=TRACEsam)
summary(m1) 
plot(m1, type="z")
}
}
\seealso{
\code{\link{gofM_phreg}}, \code{\link{cumContr}}
}
\author{
Thomas Scheike and Klaus K. Holst
}
