Learn R Programming

survMisc (version 0.5.6)

gof: goodness of fit test for a coxph object

Description

goodness of fit test for a coxph object

Usage

gof(x, ...)

# S3 method for coxph gof(x, ..., G = NULL)

Arguments

x

An object of class coxph

...

Additional arguments (not implemented)

G

Number of groups into which to divide risk score. If G=NULL (the default), uses closest integer to $$G = \max(2, \quad \min(10, \quad \frac{ne}{40}))$$ where \(ne\) is the number of events overall.

Value

A list with elements:

groups

A data.table with one row per group \(G\). The columns are

n

Number of observations

e

Number of events

exp

Number of events expected. This is $$exp = \sum e_i - M_i$$ where \(e_i\) are the events and \(M_i\) are the martingale residuals for each observation \(i\)

z

\(Z\) score, calculated as $$ Z = \frac{e - exp}{\sqrt{exp}}$$

p

\(p\)-value for \(Z\), which is $$ p = 2. \code{pnorm}(-|z|)$$ where pnorm is the normal distribution function with mean \(\mu =0\) and standard deviation \(\sigma =1\) and \(|z|\) is the absolute value.

lrTest

Likelihood-ratio test. Tests the improvement in log-likelihood with addition of an indicator variable with \(G-1\) groups. This is done with survival:::anova.coxph. The test is distributed as chi-square with \(G-1\) degrees of freedom

Details

In order to verify the overall goodness of fit, the risk score \(r_i\) for each observation \(i\) is given by $$r_i = \hat{\beta} X_i$$ where \(\hat{\beta}\) is the vector of fitted coefficients and \(X_i\) is the vector of predictor variables for observation \(i\).

This risk score is then sorted and 'lumped' into a grouping variable with \(G\) groups, (containing approximately equal numbers of observations).

The number of observed (\(e\)) and expected (\(exp\)) events in each group are used to generate a \(Z\) statistic for each group, which is assumed to follow a normal distribution with \(Z \sim N(0,1)\).

The indicator variable indicG is added to the original model and the two models are compared to determine the improvement in fit via the likelihood ratio test.

References

Default value for \(G\) as per: May S, Hosmer DW 2004. A cautionary note on the use of the Gronnesby and Borgan goodness-of-fit test for the Cox proportional hazards model. Lifetime Data Analysis 10(3):283--91. 10.1023/B:LIDA.0000036393.29224.1d

Changes to the pbc dataset in the example are as detailed in: Fleming T, Harrington D 2005. Counting Processes and Survival Analysis. New Jersey: Wiley and Sons. Chapter 4, section 4.6, pp 188. 10.1002/9781118150672

Examples

Run this code
# NOT RUN {
data("pbc", package="survival")
pbc <- pbc[!is.na(pbc$trt), ]
## make corrections as per Fleming
pbc[pbc$id==253, "age"] <-  54.4
pbc[pbc$id==107, "protime"] <-  10.7
### misspecified; should be log(bili) and log(protime) instead
c1 <- coxph(Surv(time, status==2) ~
            age + log(albumin) + bili + edema + protime,
            data=pbc)
gof(c1, G=10)
gof(c1)

# }

Run the code above in your browser using DataLab