Skip to contents

trend_test() tests for a monotone trend in the hazard across groups that have a natural order, such as disease stages or dose levels. Each group gets a numeric score, and the test asks whether the observed minus expected event counts line up with the scores. When the groups are ordered, it has more power than logrank_test(), which looks for any difference.

Usage

trend_test(
  formula,
  data,
  weights,
  subset,
  na.action = stats::na.omit,
  scores = NULL,
  rho = 0,
  gamma = 0
)

Arguments

formula

A formula with a Surv() response on the left and one grouping variable on the right, such as Surv(time, status) ~ ph.ecog. A strata() term stratifies the test.

data

A data frame holding the variables in formula.

weights

Optional case weights, a column of data or a numeric vector.

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.

scores

The score of each group, in the order of the groups (factor levels or sorted values, as for kaplan_meier()), or named by the group values. The default gives the groups the scores 0, 1, 2, and so on.

rho, gamma

The Fleming-Harrington weight exponents, each at least 0. The default of 0 for both is the log-rank test.

Value

A greenwood_test object, as from logrank_test(), with 1 degree of freedom. Its groups table also has the score of each group.

Details

With scores \(c\), observed minus expected counts \(U\), and their variance \(V\) (as in logrank_test(), with the same rho, gamma, and strata), the statistic is \((c^\top U)^2 / c^\top V c\), which has a chi-square distribution with 1 degree of freedom. Without ties it equals the score test for the scores as a covariate in a Cox model. Adding a constant to every score, or multiplying them all by one, doesn't change the test.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2),
  ecog = c(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2)
)
trend_test(Surv(time, status) ~ ecog, data = lung)
#> <greenwood_test> Surv(time, status) ~ ecog
#> Log-rank test for trend
#> 
#>        n observed expected score
#> ecog=0 4        4 1.521140     0
#> ecog=1 4        4 3.617208     1
#> ecog=2 4        2 4.861652     2
#> 
#> Chi-squared = 6.199 on 1 degree of freedom, p = 0.0128

# Scores that grow faster from one grade to the next
trend_test(Surv(time, status) ~ ecog, data = lung, scores = c(0, 1, 4))
#> <greenwood_test> Surv(time, status) ~ ecog
#> Log-rank test for trend
#> 
#>        n observed expected score
#> ecog=0 4        4 1.521140     0
#> ecog=1 4        4 3.617208     1
#> ecog=2 4        2 4.861652     4
#> 
#> Chi-squared = 4.802 on 1 degree of freedom, p = 0.0284