Skip to contents

grays_test() tests whether the cumulative incidence of one cause differs between groups when there are competing risks. It's the competing-risks counterpart of logrank_test(): where the log-rank test compares hazards, Gray's test compares the subdistribution hazards, which determine the cumulative incidence. Subjects who had a competing event stay in the risk set, down-weighted by how likely they would have been to remain uncensored.

Usage

grays_test(formula, data, subset, na.action = stats::na.omit, cause = 1)

Arguments

formula

A formula with a competing-risks Surv() response on the left and the grouping variables on the right (see aalen_johansen()).

data

A data frame holding the variables in formula.

subset

An optional expression selecting the rows of data to use.

na.action

What to do with rows that have missing values. The default drops them.

cause

The cause to compare, as a state name or as a number (1 for the first cause, the default).

Value

A greenwood_test object with the statistic, the degrees of freedom df, the p_value, the method, and groups, a data frame with one row per group: group, the grouping variables, n, and the observed and expected events of the cause.

Details

The statistic compares the observed events of the cause in each group with the number expected if the groups shared one cumulative incidence curve, and has a chi-square distribution with one fewer degrees of freedom than there are groups. The variance is Gray's (1988).

References

Gray, R. J. (1988). A class of K-sample tests for comparing the cumulative incidence of a competing risk. The Annals of Statistics, 16(3), 1141-1154.

Examples

mgus <- data.frame(
  time = c(30, 45, 60, 72, 80, 95, 110, 120, 130, 150, 160, 180, 200, 210),
  status = c(1, 2, 0, 2, 1, 2, 0, 1, 2, 2, 0, 1, 1, 2),
  sex = rep(c("F", "M"), times = 7)
)
mgus$event <- factor(mgus$status, levels = 0:2, labels = c("censor", "pcm", "death"))
grays_test(Surv(time, event) ~ sex, data = mgus, cause = "pcm")
#> <greenwood_test> Surv(time, event) ~ sex
#> Gray's test (cause = "pcm")
#> 
#>       n observed expected
#> sex=F 7        3 1.647436
#> sex=M 7        2 3.352564
#> 
#> Chi-squared = 1.583 on 1 degree of freedom, p = 0.208