Skip to contents

A nonparametric test for monotonic trends across ordered independent groups, assessing whether observations tend to increase (or decrease) systematically with group order.

Usage

jonckheereTerpstraTest(x, ...)

# S3 method for class 'formula'
jonckheereTerpstraTest(formula, data, subset, na.action = na.pass, ...)

# Default S3 method
jonckheereTerpstraTest(
  x,
  g,
  alternative = c("two.sided", "increasing", "decreasing"),
  method = c("auto", "exact", "permutation", "asymptotic"),
  R = NULL,
  ...
)

Arguments

x

a numeric vector of observations, or a list of numeric vectors.

...

further arguments passed to methods.

formula

a formula of the form response ~ group.

data

an optional data frame containing the variables in formula.

subset

an optional expression specifying a subset of observations, evaluated in data (subset = dose > 0.5), as in kruskal.test().

na.action

a function indicating how missing values are handled. Defaults to na.pass(): the missing values reach the default method, which drops every observation with a missing value or a missing group, as kruskal.test() does.

g

a grouping variable corresponding to x, whose (factor) level order defines the hypothesised ordering; ignored when x is a list.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "increasing" or "decreasing".

method

a character string specifying the inference method, one of "auto" (default), "exact", "permutation" or "asymptotic". "auto" uses exact inference where it is affordable (without ties \(n \le 100\), with ties a cost below \(10^7\) table cells), otherwise the asymptotic approximation.

R

the number of permutations, a single positive integer, required when method = "permutation".

Value

A list with class "htest" containing the following components:

statistic

the value of the Jonckheere-Terpstra statistic.

parameter

the number of groups k and the total sample size n.

p.value

the p-value of the test.

alternative

a character string describing the alternative hypothesis.

method

a character string indicating the test performed and the inference method used.

data.name

a character string giving the names of the data.

Details

The Jonckheere-Terpstra statistic is $$JT = \sum_{k<l} \sum_{ij} \left[ I(X_{ik} < X_{jl}) + \frac{1}{2} I(X_{ik} = X_{jl}) \right]$$ where \(i, j\) index observations from ordered groups \(k, l\). Large values of the statistic indicate increasing trends across groups.

Exact p-values are computed from the exact permutation distribution using dynamic programming recursions implemented in C++, with and without ties.

Without ties the null distribution depends on the group sizes alone and is obtained from the classical recursion; it is offered for total sample sizes \(n \le 100\).

With ties the statistic depends on the data through the table of counts of group by distinct value, which under the null hypothesis follows the multiple hypergeometric distribution with the group sizes and the tie counts as its margins. The distribution is built by splitting off one row of that table at a time, the state being the counts not yet assigned. Its cost grows with \(\prod_a (c_a + 1)\), the \(c_a\) being the tie counts, so it is cheapest where ties are heaviest, and prohibitive where they are few and the sample is large. "auto" therefore turns to the asymptotic approximation beyond a cost of about \(10^7\) table cells, and method = "exact" warns above \(2 \times 10^8\) and falls back to the approximation as well. Note that with ties the statistic and the support of its distribution are half-integral.

For large samples permutation p-values can be computed by permuting group labels under the null hypothesis (method = "permutation"); the number of permutations is controlled by R, and the reported p-value uses the finite-sample correction \((m + 1)/(R + 1)\).

Two-sided p-values are the smaller one-sided p-value doubled, in each of the three methods. The null distribution of the statistic is symmetric only for equal group sizes, so this is not the same as counting the values lying at least as far from the null mean as the observed one.

With method = "asymptotic" (the fallback of "auto" when exact inference does not apply), a normal approximation with the tie-corrected variance of Hollander and Wolfe (1999, Eq. 6.19) is used.

References

Jonckheere, A. R. (1954) A distribution-free k-sample test against ordered alternatives. Biometrika, 41, 133–145.

Terpstra, T. J. (1952) The asymptotic normality and consistency of Kendall's test against trend, when ties are present in one ranking. Indagationes Mathematicae, 14, 327–333.

Hollander, M. and Wolfe, D. A. (1999) Nonparametric Statistical Methods, 2nd ed., New York: Wiley.

Examples

set.seed(1)
g <- ordered(rep(1:4, each = 10))
x <- rnorm(40) + 0.5 * as.numeric(g)

jonckheereTerpstraTest(x, g)
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (exact)
#> 
#> data:  x and g
#> JT = 437, k = 4, n = 40, p-value = 0.0007562
#> alternative hypothesis: two.sided
#> 

# with ties: exact inference as long as it is affordable,
# permutation inference otherwise
x[1:2] <- mean(x[1:2])
jonckheereTerpstraTest(x, g, method = "permutation", R = 2000)
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (permutation, R =
#> 	2000)
#> 
#> data:  x and g
#> JT = 438, k = 4, n = 40, p-value = 0.0009995
#> alternative hypothesis: two.sided
#> 

coffee <- list(
  c_4 = c(447, 396, 383, 410),
  c_2 = c(438, 521, 468, 391, 504, 472),
  c_0 = c(513, 543, 506, 489, 407)
)
jonckheereTerpstraTest(coffee)
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (exact)
#> 
#> data:  x
#> JT = 59, k = 3, n = 15, p-value = 0.01973
#> alternative hypothesis: two.sided
#> 

# Hollander & Wolfe, Example 6.2:
# motivational effect of knowledge of performance
motiv <- list(
  no    = c(40, 35, 38, 43, 44, 41),
  rough = c(38, 40, 47, 44, 40, 42),
  acc   = c(48, 40, 45, 43, 46, 44))

jonckheereTerpstraTest(motiv, alternative = "increasing")
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (exact, ties)
#> 
#> data:  x
#> JT = 79, k = 3, n = 18, p-value = 0.02097
#> alternative hypothesis: increasing
#> 
## exact one-sided p-value 0.0210, the data being tied. Hollander and
## Wolfe report 0.0231 from the tie-free null distribution and 0.0207
## from the tie-corrected normal approximation

jonckheereTerpstraTest(motiv, alternative = "increasing",
                       method = "asymptotic")
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (asymptotic)
#> 
#> data:  x
#> JT = 79, k = 3, n = 18, p-value = 0.02071
#> alternative hypothesis: increasing
#> 

set.seed(42)
jonckheereTerpstraTest(motiv, alternative = "increasing",
                       method = "permutation", R = 10000)
#> 
#> 	Jonckheere-Terpstra test for ordered alternatives (permutation, R =
#> 	10000)
#> 
#> data:  x
#> JT = 79, k = 3, n = 18, p-value = 0.0194
#> alternative hypothesis: increasing
#>