1 D Variable 의 형성
\(a\) 시점/처치를 \(a-1\) 차원 차이 점수로 변환한 vector.
Type 1 — 첫 시점 기준: \[ D_j = Y_{j+1} - Y_1, \quad j = 1, \ldots, a-1 \]
Type 2 — 직교 contrast 기반 (예: trend 계수): \[ D_j = \sum_k c_j^{(k)} Y_k, \quad j = 1, \ldots, a-1 \] 여기서 \(c^{(j)}\) 는 직교 다항식 또는 임의의 직교 contrast.
두 type 은 같은 \(T^2\) 값을 준다 (linear transformation 불변).
2 변환의 통계적 의미
원래 \(\mathbf{Y} \in \mathbb{R}^a\) 의 covariance matrix \(\Sigma\) 가 sphericity 를 만족하지 않을 수 있다.
D variable 로 변환: \[ \mathbf{D} = \mathbf{C} \mathbf{Y} \] (\(\mathbf{C}\) 는 \((a-1) \times a\) contrast matrix.)
\(\mathbf{D}\) 의 covariance 는 \(\Sigma_D = \mathbf{C} \Sigma \mathbf{C}^T\). 이 새 행렬은 어떤 형태든 가능 (제약 없음).
→ multivariate 검정은 \(\Sigma_D\) 의 일반 형태를 가정. sphericity 가정 불필요.
이것이 univariate (Σ 에 sphericity 제약) vs multivariate (Σ_D 자유) 의 차이.
3 Hotelling \(T^2\) 통계량
One-sample multivariate test of \(\mu_D = 0\):
\[ T^2 = n \, \bar{\mathbf{D}}^T \mathbf{S}_D^{-1} \bar{\mathbf{D}} \]
여기서: - \(\bar{\mathbf{D}}\): \(\mathbf{D}\) 의 표본 평균 vector (\(a-1\) 차원). - \(\mathbf{S}_D\): \(\mathbf{D}\) 의 표본 covariance matrix (\((a-1) \times (a-1)\)).
\(F\) 분포로 변환: \[ F = \frac{n - (a-1)}{(a-1)(n-1)} T^2 \sim F(a-1, n-a+1) \]
4 직관
\(a = 2\) 일 때: - \(D_1 = Y_2 - Y_1\) - \(T^2 = n \bar D^2 / s_D^2 = (\bar D / (s_D / \sqrt n))^2 = t^2\)
즉 Hotelling \(T^2\) 가 paired \(t^2\) 의 정확한 일반화. 일반 \(a\) 차원으로 확장한 것이 multivariate 검정.
\(a\) 차원에서: \[ T^2 = n (\bar{\mathbf{D}} - \mu_0)^T \mathbf{S}_D^{-1} (\bar{\mathbf{D}} - \mu_0) \]
이는 vector 의 표준화 거리의 제곱 — Mahalanobis distance 의 표본 형태.
5 가설 데이터
\(n = 15\) 환자, \(a = 3\) 시점 (1주, 2주, 4주). \(Y\) = SBP.
가상 평균 vector: \((140, 132, 125)\). 시점 1 → 2 의 변화 \(-8\), 시점 1 → 4 의 변화 \(-15\).
5.1 Type 1 D variables
\(\mathbf{D} = (D_1, D_2)^T = (Y_2 - Y_1, Y_3 - Y_1)\).
\(\bar{\mathbf{D}} = (-8, -15)^T\).
\(\mathbf{S}_D = \begin{pmatrix} 16 & 12 \\ 12 & 25 \end{pmatrix}\) (가상).
5.2 Hotelling \(T^2\) 계산
\(\mathbf{S}_D^{-1}\) 계산: 행렬식 \(= 16 \times 25 - 144 = 256\), inverse: \[ \mathbf{S}_D^{-1} = \frac{1}{256} \begin{pmatrix} 25 & -12 \\ -12 & 16 \end{pmatrix} \]
\[ \mathbf{S}_D^{-1} \cdot \bar{\mathbf{D}} = \frac{1}{256} \begin{pmatrix} 25(-8) + (-12)(-15) \\ -12(-8) + 16(-15) \end{pmatrix} = \frac{1}{256} \begin{pmatrix} -20 \\ -144 \end{pmatrix} \]
\[ \bar{\mathbf{D}}^T \mathbf{S}_D^{-1} \bar{\mathbf{D}} = \frac{1}{256}((-8)(-20) + (-15)(-144)) = \frac{160 + 2160}{256} = 9.06 \]
\[ T^2 = 15 \times 9.06 = 135.9 \]
\(F\) 변환: \[ F = \frac{15 - 2}{2 \times 14} \times 135.9 = \frac{13}{28} \times 135.9 = 63.1 \]
자유도 \((2, 13)\), \(p < 0.001\). 매우 강한 처치 효과.
6 직교 변환
위 \(D\) 변수 (linear) 대신 직교 다항식 contrast 사용:
\[ D_1 = (Y_3 - Y_1) / \sqrt 2 \quad (\text{linear}) \] \[ D_2 = (Y_1 - 2 Y_2 + Y_3) / \sqrt 6 \quad (\text{quadratic}) \]
\(T^2\) 값은 동일 (linear transformation 불변). 하지만 각 차원이 직교적 의미를 가져 해석이 쉬움 — 어느 차원이 처치 효과의 주된 원천인지 (linear vs quadratic) 진단 가능.
6.1 Type 1 vs Type 2 의 동치성
linear transformation 으로: \[ \mathbf{D}^{(2)} = \mathbf{A} \mathbf{D}^{(1)} \]
\(T^2\) 의 invariance 정리: \[ T^2(\mathbf{D}^{(1)}) = n (\bar{\mathbf{D}}^{(1)})^T \mathbf{S}^{-1} \bar{\mathbf{D}}^{(1)} \] \[ T^2(\mathbf{D}^{(2)}) = T^2(\mathbf{A}\mathbf{D}^{(1)}) = T^2(\mathbf{D}^{(1)}) \]
(생략된 계산 — invariance 의 선형 대수 결과.)
같은 \(T^2\), 같은 검정.
7 Python 코드
import numpy as np
import pandas as pd
from scipy import stats
np.random.seed(2026)
n = 15
a = 3
# 데이터 생성: 3 시점, 처치 효과
records = []
for subj in range(n):
pi = np.random.normal(0, 7)
means = [140, 132, 125]
for t in range(a):
y = means[t] + pi + np.random.normal(0, 4)
records.append({"subject": subj, "time": t, "Y": y})
data = pd.DataFrame(records)
wide = data.pivot(index="subject", columns="time", values="Y")
# Type 1: D variables = differences from time 0
D1 = wide.iloc[:, 1] - wide.iloc[:, 0]
D2 = wide.iloc[:, 2] - wide.iloc[:, 0]
D = pd.DataFrame({"D1": D1, "D2": D2})
D_bar = D.mean().values
S_D = D.cov().values
T2 = n * D_bar @ np.linalg.inv(S_D) @ D_bar
F_stat = (n - a + 1) / ((a - 1) * (n - 1)) * T2
p_val = 1 - stats.f.cdf(F_stat, a - 1, n - a + 1)
print(f"=== Hotelling T² (Type 1 D) ===")
print(f"D mean: {D_bar}")
print(f"T² = {T2:.3f}")
print(f"F({a-1}, {n-a+1}) = {F_stat:.3f}, p = {p_val:.4f}")
# Type 2: orthogonal polynomial contrasts
c_lin = np.array([-1, 0, 1]) / np.sqrt(2)
c_quad = np.array([1, -2, 1]) / np.sqrt(6)
D_lin = wide.values @ c_lin
D_quad = wide.values @ c_quad
D_ortho = pd.DataFrame({"D_lin": D_lin, "D_quad": D_quad})
D_bar_o = D_ortho.mean().values
S_D_o = D_ortho.cov().values
T2_o = n * D_bar_o @ np.linalg.inv(S_D_o) @ D_bar_o
F_o = (n - a + 1) / ((a - 1) * (n - 1)) * T2_o
print(f"\n=== Hotelling T² (Type 2 orthogonal) ===")
print(f"D mean: {D_bar_o}")
print(f"T² = {T2_o:.3f}, F = {F_o:.3f}")
print("(should be same T² as Type 1)")
# 각 차원의 univariate t-test
for col in D_ortho.columns:
t, p = stats.ttest_1samp(D_ortho[col], 0)
print(f" {col}: t = {t:.2f}, p = {p:.4f}")8 신뢰구간 — Multivariate
\(\bar{\mathbf{D}}\) 의 100(1-α)% 신뢰 영역 (ellipsoid):
\[ \{\mathbf{d}: n (\mathbf{d} - \bar{\mathbf{D}})^T \mathbf{S}_D^{-1} (\mathbf{d} - \bar{\mathbf{D}}) \le \frac{(a-1)(n-1)}{n - a + 1} F_{\alpha; a-1, n-a+1}\} \]
\(a-1\) 차원 ellipsoid 내부.
각 차원 별 신뢰구간 (Bonferroni 보정):
\[ \bar D_j \pm t_{\alpha/(2(a-1)), n-1} \cdot \frac{s_{D_j}}{\sqrt n} \]
9 가정과 한계
- 다변량 정규성: 각 \(D_j\) 가 정규.
- 표본 충분: \(n > a\) 필수 (covariance 추정).
- 차이의 직교 vs 비직교: 같은 \(T^2\), 해석 차이.
- 결측 데이터: listwise.
10 사후 분석
\(T^2\) 가 유의하면 어느 차원에서 효과가 있는지 follow-up:
각 차원의 univariate t-test: \[ t_j = \frac{\bar D_j}{s_{D_j} / \sqrt n} \]
Bonferroni 보정: \(\alpha / (a-1)\).
Holm-Bonferroni: step-down 절차.
Roy-Bose simultaneous CI: 모든 linear combination 의 신뢰 구간.
11 ML 매핑
ML 모델 평가에서 다중 metric (accuracy, precision, recall, F1):
Subject (dataset): 10 datasets
D variable: (Δaccuracy, Δprecision, Δrecall, ΔF1) — 모델 A vs 모델 B 의 차이
각 dataset 의 4 metric 의 차이 → 4 차원 D variable.
Hotelling \(T^2\): “모델 A 가 모델 B 와 다른가?” (multivariate).
이는 ML 의 multi-metric 비교의 통계적 표준. 단일 metric 별 비교의 다중 비교 부담 회피.
12 본 시리즈
G-MAX13-0 개관
G-MAX13-1 D Variable + Hotelling T² ← 현재 글
G-MAX13-2 Wilks Λ + Pillai + Roy
G-MAX13-3 Univariate vs Multivariate
13 관련 주제
선행 지식
후속 주제
다른 카테고리 연결
- Math — 선형대수 (matrix inverse) (placeholder)
14 더 읽을 거리
- Hotelling, H. (1931). “The generalization of Student’s ratio.” Annals of Mathematical Statistics 2(3): 360-378 — Hotelling \(T^2\) 원조.
- Anderson, T. W. (2003). “An Introduction to Multivariate Statistical Analysis” (3rd ed). Wiley — multivariate 의 표준 reference.
- Tabachnick, B. G., Fidell, L. S. (2019). “Using Multivariate Statistics” (7th ed). Pearson.
- Maxwell, S. E., Delaney, H. D. (2004). “Designing Experiments and Analyzing Data.”