JT趋势检验
计算公式
符号
| 符号 | 含义 |
|---|---|
| k | 按组序排列的组数 |
| ni | 第 i 组的样本量 |
| N | 合计样本量 |
| U | Jonckheere-Terpstra 统计量 |
| yia | 第 i 组第 a 个观测 |
| Ra | 观测 a 在合并样本中的平均秩 |
| ta | 与观测 a 同值的观测个数(含自身) |
| qa、sa | 结校正的中间量 |
| ai、bi | 第 i 组之前、之后各组的样本量之和 |
| epair、eshare | 组对部分与组内秩部分的系数 |
| Φ(·) | 标准正态分布的累积分布函数 |
核心公式
公式 (1.1):按组序的组对比较累加
\[
U=\sum_{1\le i\lt j\le k}\sum_{a=1}^{n_i}\sum_{b=1}^{n_j}\left[I\left(y_{ia}\lt y_{jb}\right)+\frac12I\left(y_{ia}=y_{jb}\right)\right]
\]
公式 (1.2):期望与结校正方差
\[
E(U)=\frac{N^2-\sum_{i=1}^{k}n_i^2}{4}
\]
公式 (1.3):结校正的精确零分布方差
\[
\begin{aligned}
q_a&=\frac{N-t_a}{4},\qquad s_a=\frac{2R_a-N-1}{2},\\
e_{\mathrm{pair}}&=\frac{N^2-\sum_{i=1}^{k}n_i^2}{N(N-1)},\\
e_{\mathrm{share}}&=\sum_{i=1}^{k}\frac{n_i}{N}\cdot\frac{(b_i-a_i)^2-(N-n_i)}{(N-1)(N-2)},\\
\mathrm{Var}(U)&=e_{\mathrm{pair}}\cdot\frac12\sum_{a=1}^{N}q_a+e_{\mathrm{share}}\sum_{a=1}^{N}\left(s_a^2-q_a\right)
\end{aligned}
\]
公式 (1.4):z 值与双侧 p
\[
z=\frac{U-E(U)}{\sqrt{\mathrm{Var}(U)}},\qquad p=2\left[1-\Phi(|z|)\right]
\]
参考文献
- Jonckheere, A. R. (1954). A distribution-free k-sample test against ordered alternatives. Biometrika, 41(1/2), 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., & Wolfe, D. A. (1999). Nonparametric Statistical Methods (2nd ed.). Wiley.
算法参数
| 参数 | 取值 | 默认 | 影响 |
|---|---|---|---|
| 组序 | 各组取值或标签的一个完整排列 | 类别升序 | 只改变趋势方向与 z 的符号,不改变 U 的绝对值;数据中的组序为 1、2、3。 |
| 缺失处理 | 成对剔除 / 按列表剔除 | 成对剔除 | 成对剔除时每个因变量用自己的有效样本;按列表剔除时所有变量共用一批样本。 |
验证报告
数据与 R 包
提示词
按 G 的 1、2、3 组序,对 Y 做 Jonckheere-Terpstra 趋势检验,给出 U、E(U)、方差、z、双侧 p 与各组中位数,结果保留 10 位小数。
R 代码
options(digits = 15)
library(PMCMRplus)
d <- read.csv("jonckheere_terpstra.csv")
r <- jonckheereTest(d$Y, d$G, alternative = "two.sided")
print(r, digits = 15)
ns <- table(d$G); N <- sum(ns)
e <- (N^2 - sum(ns^2)) / 4
cat("U", r$estimates, "E", e, "z", r$statistic,
"var", ((r$estimates - e) / r$statistic)^2, "p", r$p.value, "\n")
cat("medians", tapply(d$Y, d$G, median), "\n")
对比结果
| 指标 | SPSSAU | R | 差值 |
|---|---|---|---|
| 样本量 1 | 30 | 30 | 0 |
| 样本量 2 | 30 | 30 | 0 |
| 样本量 3 | 30 | 30 | 0 |
| 统计量 U | 1772.0000000000 | 1772.0000000000 | 0 |
| 期望 E(U) | 1350.0000000000 | 1350.0000000000 | 0 |
| 方差 | 18225.0000000000 | 18225.0000000000 | 0 |
| z 值 | 3.1259259259 | 3.1259259259 | 2.59e−11 |
| 双侧 p 值 | 1.772462e−3 | 1.772462e−3 | 3.49e−9 |
| 中位数 1 | 43.1159445000 | 43.1159445000 | 0 |
| 中位数 2 | 43.8892225000 | 43.8892225000 | 0 |
| 中位数 3 | 48.1687850000 | 48.1687850000 | 0 |
结论:U、E(U)、方差、z、双侧 p 与三组中位数均与 R 一致。本数据各观测互不相同(无结),ta=1、qa=(N−1)/4,式 (1.3) 即化为无结形式;R 的 PMCMRplus 包采用同一正态近似口径。
引用SPSSAU. JT趋势检验:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/general/jonckheere_terpstra.html.