이 글은 Phase J 시리즈의 네 번째 글이자, Hernan Ch.4 시리즈의 마지막 글. Matching 을 stratification 의 극단 으로서, 그리고 adjustment 의 또 다른 도구 로서 다룬다.
1 진입 직관 — Stratification 의 극단
이전 글들에서 stratification 으로 confounding 보정과 effect modification 식별을 다뤘다. Matching 은 stratification 의 극단적 형태:
Stratification: \(L\) 의 몇 개 stratum 으로 분할 (예: 연령 4 그룹).
Matching: 각 처치 환자에 대조 환자 1 명 (또는 K 명) 짝짓기 — 사실상 N 개의 매우 작은 stratum.
목표 동일: \(L\) 이 같은 환자끼리 비교 → confounding 통제.
비유: 식당 메뉴 비교. 층화: “남자 vs 여자, 청년 vs 중년” 4 그룹 평균 점수. 매칭: “내 친구 김씨 (남, 30, 직장인) 와 비슷한 사람 1 명씩 짝지어 두 메뉴 점수 비교”. 매칭이 더 정밀하지만 짝짓기 어려움.
2 정의: Matching
각 처치 환자 \(i\) (with \(A_i = 1\)) 에 대해 대조 환자 \(j\) (with \(A_j = 0\)) 를 \(L\) 이 같거나 비슷한 으로 짝짓기. 이렇게 짝지어진 matched cohort 에서 처치 효과 추정.
2.1 두 종류
Exact matching:
\(L_i = L_j\) — 정확히 동일한 confounder 값.
Caliper / Approximate matching:
\(|L_i - L_j| < \delta\) — 어떤 거리 함수 내. 연속 변수에서 흔함.
2.2 매칭 비율
- 1:1 matching: 각 처치에 대조 1 명
- 1:K matching: 각 처치에 대조 K 명 (효율 향상)
- Variable ratio: 처치마다 다른 K
수식 직관: 매칭 후 cohort 에서 L 분포가 처치/대조 동일 — exchangeability 자동 (조건부 무작위 시험과 비슷).
3 Stratification 과 Matching 의 등가성
3.1 Hernan 의 통찰
“매칭 후의 분석 = 각 매치된 pair 를 별도 stratum 으로 보는 stratified analysis.”
3.2 수식 비교
Stratification (continuous L 의 K 분할):
\[ \widehat{ATE} = \sum_{k=1}^K w_k \cdot (\bar{Y}_{T,k} - \bar{Y}_{C,k}) \]
Matching (N pairs):
\[ \widehat{ATE}_{\text{matched}} = \frac{1}{N} \sum_{i=1}^N (Y_{T,i} - Y_{C,i}) \]
즉 매칭은 N 개의 stratum (각 1 처치 + 1 대조) 으로 보는 stratification.
3.3 왜 매칭 vs 층화
| 측면 | Stratification | Matching |
|---|---|---|
| L 구간 | 큰 (K=4~10) | 매우 작은 (K=N) |
| 데이터 활용 | 모든 데이터 사용 | 매칭 안 된 환자 제외 |
| Confounder 보정 | 부분적 | 완전 (exact matching) |
| Sample size 효율 | 좋음 | 낮음 (제외 많음) |
| Continuous L 처리 | 구간 분할 (정보 손실) | Caliper (좋음) |
4 Propensity Score Matching — Rosenbaum & Rubin (1983)
4.1 동기
Confounder \(L\) 이 다차원 (예: 100 개 변수) 이면 exact matching 거의 불가능. 모든 차원에서 같은 환자 찾기 희박.
4.2 해결책
Propensity Score \(e(L) = \Pr(A=1 | L)\) — 처치 받을 확률 의 단일 score.
Theorem (Rosenbaum-Rubin 1983): \(L\) 에서 conditional exchangeability 가 성립하면 propensity score \(e(L)\) 에서도 성립.
즉 고차원 L 대신 1 차원 e(L) 으로 매칭 가능. 차원의 저주 회피.
4.3 절차
1. Propensity score 추정:
logistic regression: e(L) = P(A=1 | L)
2. Matching:
각 처치 환자에 e(L) 가장 가까운 대조 환자 짝짓기
3. Balance check:
매칭 후 L 의 분포가 처치/대조 비슷한지 확인 (standardized mean difference)
4. 효과 추정:
matched cohort 에서 단순 비교 (paired t-test, McNemar 등)
4.4 사례 — 흡연 vs 폐암 시험
관찰 연구. 흡연자 5000 명, 비흡연자 5000 명. Confounder \(L\): 연령·성별·직업·생활 습관 등 50 개 변수.
- Logistic regression 으로 e(L) = P(흡연 | L) 추정
- 각 흡연자에 e(L) 가장 가까운 비흡연자 1 명씩 짝짓기 (caliper 0.05)
- Matched cohort 에서 흡연자 vs 비흡연자 폐암 발생률 비교
4.5 한계
모든 confounder 측정 가정 (no unmeasured confounding). 측정되지 않은 confounder 가 있으면 matching 도 biased.
5 Greedy vs Optimal Matching
5.1 Greedy (Nearest Neighbor)
각 처치 환자에 순차적으로 가장 가까운 대조 환자 짝짓기. 이미 매칭된 대조 환자 제외.
장점: 단순·빠름.
단점: 처치 환자 순서에 따라 결과 다름. 후반 매칭 환자에 남은 대조군의 잘 안 맞는 사람.
5.2 Optimal Matching
전체 매칭 거리 합 최소화 — Hungarian algorithm 등.
장점: 더 좋은 매칭 품질.
단점: 계산 복잡 — 큰 데이터에서 어려움.
5.3 1:K Matching
각 처치에 대조 K 명 매칭 (보통 K=2~5). 통계적 효율 향상 — variance 감소.
Trade-off: K 증가 시 덜 좋은 매칭 포함 → bias 증가 가능.
6 Matched Analysis — 통계 도구
6.1 Paired Comparison
매칭 후 각 pair 의 차이 를 계산. paired t-test, Wilcoxon signed-rank 등.
6.2 McNemar Test (이분 결과)
처치/대조 의 결과가 불일치한 pair 만 사용:
| 처치 결과 대조 결과 | + | - |
|---|---|---|
| + | a | b |
| - | c | d |
McNemar χ² = \((b - c)^2 / (b + c)\). 불일치 pair 의 비대칭 검정.
Phase B 에서 다룸 (B26). Case-control matching 의 표준 도구.
6.3 Conditional Logistic Regression
Continuous covariates 또는 Multiple matched controls 시. 각 matched set 내에서 conditional likelihood.
Phase B (B26) 에서 case-control matching 의 도구. Phase J 에서 코호트 matching 에도 동일 적용.
7 IP Weighting vs Matching — 비교
7.1 IP Weighting (Phase D)
Inverse propensity weighting: 각 환자에 \(1/e(L_i)\) (처치) 또는 \(1/(1-e(L_i))\) (대조) 가중. Pseudo-population 에서 confounding 통제.
7.2 Matching
Matched cohort 에서 직접 비교.
7.3 차이
| 측면 | IP Weighting | Matching |
|---|---|---|
| 데이터 활용 | 모든 환자 | 매칭된 환자만 |
| Sample size | 효율적 | 손실 (특히 caliper 좁으면) |
| Extreme weight | 위험 (e≈0 또는 1) | 자동 제외 |
| 추정 모집단 | 전체 모집단 (ATE) | Matched 모집단 (ATT 또는 비슷한 것) |
| Variance | 보통 더 큼 | 보통 더 작음 |
7.4 Hernan 의 권고
“어느 한 방법만이 우월하지 않다. 데이터 특성·연구 질문에 따라 선택. 둘 다 시도하고 결과 비교 권장.”
8 Matching 의 한계 — 추정 가능한 모집단
8.1 핵심 통찰
Matched cohort 는 원래 모집단의 일부. 따라서 추정된 효과는 원래 모집단의 ATE 가 아닌 ATT 또는 matched 모집단의 평균.
8.2 Hernan 의 강조
“Matching ⇒ ATT (average treatment effect on the treated) 또는 비슷한 추정. 전체 모집단의 ATE 와 다를 수 있음.”
8.3 사례
50,000 명 모집단 — 처치 5,000 명, 대조 45,000 명. 각 처치 환자에 1 대조 매칭 → matched cohort 10,000 명.
매칭된 대조 5,000 명 은 전체 대조 45,000 명을 대표 안 함 — 처치자와 비슷한 특성 (propensity score 분포). 따라서 매칭된 cohort 에서 추정된 효과는 처치자에 대한 효과 (ATT).
8.4 Effect Modification 과 연결
만약 effect modification 이 propensity score 와 상관 이면 ATT ≠ ATE. Targeting 결정에 ATT 가 더 적합 (정책: “이 처치를 받는 사람들의 효과는?”).
9 사례 종합 — Smoking Cessation Trial
9.1 시험 (Hernan 의 NHEFS 데이터, Ch.12 에서 깊이)
NHEFS (National Health and Nutrition Examination Survey Epidemiologic Follow-up Study). 흡연 중단 의 체중 변화 효과 추정.
9.2 도전
관찰 연구. 흡연 중단을 결정 한 사람들이 연령·건강·동기 등에서 비흡연 지속자와 다름. Confounding.
9.3 매칭 절차
- 9 변수 (성별·연령·인종·교육·운동·체중·평소 흡연·천식·기관지염) 로 propensity score 추정
- Greedy 1:1 matching (caliper 0.1)
- Matched cohort 에서 체중 변화 비교
- McNemar test 또는 paired t-test
9.4 결과
매칭 전: 흡연 중단자 평균 체중 변화 +5 kg, 지속자 +1 kg. 단순 차이 +4 kg — biased (중단자가 평균 연령 더 많음 등).
매칭 후: +3 kg — bias 부분 보정. IP weighting 결과 (Hernan Ch.12) 와 비슷.
10 시뮬레이션 — Matching 의 효과
import numpy as np
from scipy import stats
np.random.seed(42)
# 시나리오: confounder L 이 처치와 결과 모두 영향
n = 5000
L = np.random.normal(0, 1, n) # confounder (continuous)
# 처치: L 에 의존
prob_treat = 1 / (1 + np.exp(-(0.5 * L)))
A = (np.random.random(n) < prob_treat).astype(int)
# 결과: L 와 A 의 함수 (true effect = 0.50)
true_effect = 0.50
Y = 1.0 * L + true_effect * A + np.random.normal(0, 1, n)
# Naive (조정 없음)
naive_te = Y[A == 1].mean() - Y[A == 0].mean()
print(f"[Matching 의 효과 — confounder L 통제]\n")
print(f"진짜 효과 = {true_effect:.2f}")
print(f"Naive (조정 없음): TE = {naive_te:.3f} — biased")
# Stratification (L 을 5 분할)
print(f"\n[Stratification (5 분할)]")
quintiles = np.percentile(L, [20, 40, 60, 80])
strata = np.digitize(L, quintiles)
strat_te = 0
for s in range(5):
mask = strata == s
n_s = mask.sum()
if n_s > 10 and (A[mask] == 1).sum() > 0 and (A[mask] == 0).sum() > 0:
te_s = Y[mask & (A == 1)].mean() - Y[mask & (A == 0)].mean()
strat_te += te_s * n_s / n
print(f"Stratified TE = {strat_te:.3f}")
# Propensity Score (logistic regression)
from sklearn.linear_model import LogisticRegression
ps_model = LogisticRegression()
ps_model.fit(L.reshape(-1, 1), A)
ps = ps_model.predict_proba(L.reshape(-1, 1))[:, 1]
# 1:1 Greedy Matching (nearest PS)
print(f"\n[1:1 Greedy Matching by Propensity Score]")
treated_idx = np.where(A == 1)[0]
control_idx = np.where(A == 0)[0]
matched_pairs = []
control_used = set()
for ti in treated_idx:
target_ps = ps[ti]
candidates = [ci for ci in control_idx if ci not in control_used]
if not candidates:
break
distances = np.abs(ps[candidates] - target_ps)
best = candidates[distances.argmin()]
if distances.min() < 0.05: # caliper
matched_pairs.append((ti, best))
control_used.add(best)
print(f"매칭 성공 수: {len(matched_pairs)}")
matched_diffs = [Y[t] - Y[c] for t, c in matched_pairs]
matched_te = np.mean(matched_diffs)
print(f"Matched TE = {matched_te:.3f}")
# IP Weighting
print(f"\n[IP Weighting]")
ipw = np.where(A == 1, 1/ps, 1/(1-ps))
ipw_te = (Y * A * ipw).sum() / (A * ipw).sum() - (Y * (1-A) * ipw).sum() / ((1-A) * ipw).sum()
print(f"IP Weighted TE = {ipw_te:.3f}")
print(f"\n→ Matching, Stratification, IP Weighting 모두 진짜 효과 ({true_effect}) 근처 회복")
print(f"→ Naive (조정 없음) 은 biased")
print(f"→ 세 방법 모두 confounding 통제 가능 — 데이터 특성에 따라 선택")결과 해석:
- Naive: 진짜 효과 0.50 보다 더 큰 추정 (예: 1.0+) — confounding bias.
- Stratification: 부분 보정 (예: 0.6).
- Matching: 좋은 보정 (예: 0.52).
- IP Weighting: 좋은 보정 (예: 0.48).
세 방법 모두 confounding 통제 가능. 차이는 세부 trade-off.
11 Matching 의 효과 modification 과 연결
11.1 매칭 후 분석에서
Matched cohort 에서 sub-group 별 효과 분석 — effect modification 식별.
그러나 매칭 후 sub-group 의 sample size 작음 — power 부족 가능.
11.2 권장
Matching 으로 전체 평균 추정 + 별도 stratification 또는 모델 로 effect modification 분석.
12 결론 — Ch.4 시리즈의 종합
Matching 은 stratification 의 극단. Confounding 통제와 effect modification 식별의 또 다른 도구. IP weighting 과 비슷한 유연성, 다른 trade-off.
핵심 메시지:
- Matching = 극한적 stratification — N 개의 작은 stratum
- Propensity Score (Rosenbaum-Rubin 1983) — 다차원 confounder 통합
- Greedy vs Optimal: 단순함 vs 품질
- McNemar, Conditional Logistic — matched analysis 통계
- IP Weighting 과 비교 — 둘 다 시도 권장
- 추정 모집단의 변화 — Matching ⇒ ATT 경향
- Effect modification — 매칭 후 별도 분석
Ch.4 시리즈 (4 편) 종합:
- J-HER4-0: Effect modification 의 정의 + 의의
- J-HER4-1: Heterogeneity 와 stratification 식별
- J-HER4-2: 3 가지 가치 (transportability·targeting·mechanism) + adjustment
- J-HER4-3: Matching 으로서의 보정 — 이 글
다음 글부터 Ch.5 Interaction 시리즈 (4 편).
13 관련 주제
선행 지식
- Effect Modification — Ch.4 개관
- Heterogeneity 와 Stratification
- Why Care + Adjustment
- (Phase B-26) Case-control matching, McNemar test
- (Phase D) IP weighting (Hernan Ch.12)
Phase J 후속 글
- HER Ch.5 — Interaction (placeholder)
- ML HTE — Meta-learners (placeholder)
14 참고문헌
- Hernán, M. A. & Robins, J. M. (2020). Causal Inference: What If, Chapter 4. Chapman & Hall/CRC.
- Rosenbaum, P. R. & Rubin, D. B. (1983). The central role of the propensity score in observational studies for causal effects. Biometrika 70, 41-55.
- Rubin, D. B. (1973). Matching to remove bias in observational studies. Biometrics 29, 159-183.
- Stuart, E. A. (2010). Matching methods for causal inference: A review and a look forward. Statistical Science 25, 1-21.
- Austin, P. C. (2011). An introduction to propensity score methods for reducing the effects of confounding in observational studies. Multivariate Behav. Res. 46, 399-424.
- Greenland, S. & Morgenstern, H. (1989). Matched cohort studies. Stat. Med. 8, 1-15.