2×2 within 의 D 변수 형성 — 세 효과의 multivariate 검정

Maxwell Ch.14.1 2×2 Within D Variable Formation

\(2 \times 2\) within-subjects 설계의 세 효과 (\(A\) main, \(B\) main, \(A \times B\) interaction) 에 대한 D variable 의 형성 절차, paired t-test (자유도 1) 의 동치성, 직교 분해의 의미를 정리한다. 가장 단순한 2×2 사례에서 multivariate within 분석의 핵심 원리를 명확히 보여주며, 이는 일반 \(a \times b\) 확장 (G-MAX14-2) 의 직접 기반이다.

Experimentation
DOE
저자

Kwangmin Kim

공개

2026년 05월 08일

1 \(2 \times 2\) Within 설계

정의: 2×2 Within-Subjects Design

각 피험자 \(i = 1, \ldots, n\) 가 4 개 셀 모두에서 측정. 셀 평균 \(\bar Y_{jk}\) (\(j, k \in \{1, 2\}\)).

세 효과: - \(A\) main: \(\bar Y_{1\cdot} - \bar Y_{2\cdot}\) — 행 marginal 차이. - \(B\) main: \(\bar Y_{\cdot 1} - \bar Y_{\cdot 2}\) — 열 marginal 차이. - \(A \times B\): \((\bar Y_{11} - \bar Y_{12}) - (\bar Y_{21} - \bar Y_{22})\) — 차이의 차이.

각 효과 자유도 1 → D variable 1 차원 → paired \(t\)-test.

2 모형

\[ Y_{ijk} = \mu + \alpha_j + \beta_k + (\alpha\beta)_{jk} + \pi_i + (\alpha\pi)_{ij} + (\beta\pi)_{ik} + (\alpha\beta\pi)_{ijk} + \varepsilon_{ijk} \]

random effects: - \(\pi_i\): subject random. - \((\alpha\pi)_{ij}, (\beta\pi)_{ik}\): subject × main effect interaction. - \((\alpha\beta\pi)_{ijk}\): subject × interaction (residual).

각 fixed effect 의 검정 분모는 자기 효과 × subject 의 random interaction.

3 D Variables 의 형성

각 피험자 \(i\) 에 대해:

3.1 \(A\) main 의 D variable

\(A\) levels 를 평균하지 않고 직접 차이:

\[ D_i^{(A)} = \frac{Y_{i,1,1} + Y_{i,1,2}}{2} - \frac{Y_{i,2,1} + Y_{i,2,2}}{2} \]

또는 동치 (정수 contrast):

\[ D_i^{(A)} = (Y_{i,1,1} + Y_{i,1,2}) - (Y_{i,2,1} + Y_{i,2,2}) \]

(분모 2 제거 — 검정 결과 동일.)

이는 across \(B\) 평균을 차이 낸 형태. \(A = 1\) vs \(A = 2\) 의 효과.

3.2 \(B\) main 의 D variable

\[ D_i^{(B)} = \frac{Y_{i,1,1} + Y_{i,2,1}}{2} - \frac{Y_{i,1,2} + Y_{i,2,2}}{2} \]

across \(A\) 평균. \(B = 1\) vs \(B = 2\) 효과.

3.3 \(A \times B\) 의 D variable

\[ D_i^{(AB)} = (Y_{i,1,1} - Y_{i,1,2}) - (Y_{i,2,1} - Y_{i,2,2}) \]

또는 동치:

\[ D_i^{(AB)} = Y_{i,1,1} - Y_{i,1,2} - Y_{i,2,1} + Y_{i,2,2} \]

이는 “\(A=1\) 에서 \(B\) 의 효과” 와 “\(A=2\) 에서 \(B\) 의 효과” 의 차이. 즉 “\(B\) 의 효과가 \(A\) levels 에 따라 다른가” 를 잡는다.

3.4 직교 contrast 의 vector 표현

8 개 cell 평균을 vector 로 정렬:

\[ \mathbf{Y}_i = (Y_{i,1,1}, Y_{i,1,2}, Y_{i,2,1}, Y_{i,2,2})^T \]

각 D variable 은 이 vector 의 직교 contrast:

\[ \mathbf{c}^{(A)} = (1, 1, -1, -1) \] \[ \mathbf{c}^{(B)} = (1, -1, 1, -1) \] \[ \mathbf{c}^{(AB)} = (1, -1, -1, 1) \]

세 vector 가 두 두 직교 (내적 0). 따라서 세 효과의 추정량이 통계적으로 독립.

4 paired \(t\)-test (자유도 1)

각 D variable 의 평균이 0 인지 검정:

\[ t = \frac{\bar D}{s_D / \sqrt n} \]

자유도 \(n - 1\).

자유도 1 의 효과이므로 sphericity 자동 만족 (차이 점수가 1 종류만). ε 조정 불필요.

4.1 ANOVA 와의 동치

\(2 \times 2\) within 의 univariate ANOVA 와 multivariate D variable \(t\)-test 는 정확히 동치.

\(F = t^2\), df \((1, n-1)\).

이는 자유도 1 효과의 multivariate vs univariate 동치성 의 일반 결과.

5 가설 데이터 — 학습 시간 × 형식

5.1 데이터

\(n = 12\) 학생, \(A\) = 학습 시간 (1h, 2h), \(B\) = 학습 형식 (반복, 검색).

가상 셀 평균:

반복 검색
1h 5 6
2h 7 12

5.2 Marginal 평균

\(A\) main: - \(\bar Y_{1\cdot} = (5 + 6)/2 = 5.5\) - \(\bar Y_{2\cdot} = (7 + 12)/2 = 9.5\) - 차이: \(5.5 - 9.5 = -4\) (1h 가 더 낮음).

\(B\) main: - \(\bar Y_{\cdot 1} = (5 + 7)/2 = 6\) (반복) - \(\bar Y_{\cdot 2} = (6 + 12)/2 = 9\) (검색) - 차이: \(6 - 9 = -3\) (반복이 더 낮음).

\(A \times B\): - \((5 - 6) - (7 - 12) = -1 - (-5) = +4\). - “1h 에서 형식 효과 -1, 2h 에서 형식 효과 -5.” 시간이 늘면 형식 효과 더 커짐.

5.3 \(t\) 검정

각 D variable 의 분산 가정. \(n = 12\):

효과 \(\bar D\) \(s_D\) \(t\) \(p\) (양측)
\(A\) \(-4\) 2 \(-4 \times \sqrt{12} / 2 = -6.93\) \(<0.0001\)
\(B\) \(-3\) 1.5 \(-3 \times \sqrt{12} / 1.5 = -6.93\) \(<0.0001\)
\(A \times B\) \(+4\) 2.5 \(4 \times \sqrt{12} / 2.5 = +5.54\) \(0.0002\)

세 효과 모두 강하게 유의.

5.4 해석

  1. \(A\) main: 학습 시간이 늘면 회상 ↑ (4 점).
  2. \(B\) main: 검색 학습이 반복 학습보다 효과 ↑ (3 점).
  3. \(A \times B\): 검색 학습이 시간 증가에 따라 더 빠르게 효과 ↑.

전체적으로 검색 학습 + 긴 시간이 가장 효과적. 짧은 시간에는 두 형식 차이 작음.

6 직관 — 각 D variable 의 의미

6.1 \(D^{(A)}\) 의 의미

각 피험자의 \(A\) levels 별 평균 응답의 차이. 모든 피험자에 대해 평균 → \(A\) 의 marginal 효과.

직관: “이 사람이 \(A=1\) 일 때 평균 응답 - \(A=2\) 일 때 평균 응답.”

6.2 \(D^{(B)}\) 의 의미

각 피험자의 \(B\) levels 별 평균 응답의 차이.

6.3 \(D^{(AB)}\) 의 의미

각 피험자의 “\(A=1\) 에서 \(B\) 효과 - \(A=2\) 에서 \(B\) 효과”. 즉 그 사람의 interaction 강도.

각 사람의 interaction 강도가 0 이 아닌가 (positive 또는 negative) 의 검정.

직관: D variable 이 개인 간 분산을 차감

원래 응답 \(Y_{ijk}\) 는 큰 개인 간 분산 (\(\sigma^2_\pi\)) 을 포함.

D variable 은 같은 사람의 다른 cell 차이라 개인 간 분산이 cancel:

\[ D_i^{(A)} = (Y_{i,1,1} + Y_{i,1,2}) - (Y_{i,2,1} + Y_{i,2,2}) \]

\(Y\)\(\pi_i\)\(+\pi_i\) 로 두 번, \(-\pi_i\) 로 두 번 — 합이 0.

→ D variable 의 분산은 \(\pi_i\) 와 무관. 작은 분산 → 큰 검정력.

이것이 within-subjects 의 검정력 이득의 통계적 메커니즘.

7 일반 contrast 표

\(2 \times 2\) within 의 모든 직교 contrast:

효과 \((j, k) = (1,1)\) \((1,2)\) \((2,1)\) \((2,2)\)
Constant (mean) \(+1\) \(+1\) \(+1\) \(+1\)
\(A\) main \(+1\) \(+1\) \(-1\) \(-1\)
\(B\) main \(+1\) \(-1\) \(+1\) \(-1\)
\(A \times B\) \(+1\) \(-1\) \(-1\) \(+1\)

4 개의 contrast 가 두 두 직교. 4 개 cell 평균의 4 자유도를 grand mean + 3 효과로 분해.

8 Python 코드

import numpy as np
import pandas as pd
from scipy import stats

np.random.seed(2026)
n = 12
A_levels = ["1h", "2h"]
B_levels = ["반복", "검색"]
cell_means = {("1h","반복"):5, ("1h","검색"):6, ("2h","반복"):7, ("2h","검색"):12}

records = []
for subj in range(n):
    pi = np.random.normal(0, 2)  # 큰 개인 간 분산
    for a in A_levels:
        for b in B_levels:
            y = cell_means[(a, b)] + pi + np.random.normal(0, 1.2)
            records.append({"subject": subj, "A": a, "B": b, "Y": y})

data = pd.DataFrame(records)
wide = data.pivot_table(index="subject", columns=["A", "B"], values="Y")

# D variables
D_A = ((wide[("1h","반복")] + wide[("1h","검색")]) / 2
       - (wide[("2h","반복")] + wide[("2h","검색")]) / 2)
D_B = ((wide[("1h","반복")] + wide[("2h","반복")]) / 2
       - (wide[("1h","검색")] + wide[("2h","검색")]) / 2)
D_AB = (wide[("1h","반복")] - wide[("1h","검색")]
        - wide[("2h","반복")] + wide[("2h","검색")])

print("=== D variables ===")
for name, D in [("A main", D_A), ("B main", D_B), ("A×B", D_AB)]:
    t, p = stats.ttest_1samp(D, 0)
    print(f"{name}:")
    print(f"  D̄ = {D.mean():+.3f}")
    print(f"  s_D = {D.std(ddof=1):.3f}")
    print(f"  t({n-1}) = {t:.2f}, p = {p:.5f}")
    print(f"  Cohen's d = {D.mean() / D.std(ddof=1):.3f}")
    print()

# 직교성 검증
import numpy as np
c_A = np.array([1, 1, -1, -1]) / 2
c_B = np.array([1, -1, 1, -1]) / 2
c_AB = np.array([1, -1, -1, 1])

print("Orthogonality:")
print(f"  <A, B>  = {c_A @ c_B}")
print(f"  <A, AB> = {c_A @ c_AB}")
print(f"  <B, AB> = {c_B @ c_AB}")

# 검정력 비교 — within vs between
# (가상) between 으로 분석하면 σ²_π 가 잡음으로 들어가 검정력 ↓
# 이를 시뮬레이션
n_sim = 1000
within_sig = []
between_sig = []
for _ in range(n_sim):
    Y_within = []
    for subj in range(n):
        pi = np.random.normal(0, 2)
        for a in A_levels:
            for b in B_levels:
                y = cell_means[(a, b)] + pi + np.random.normal(0, 1.2)
                Y_within.append(y)
    Y_within = np.array(Y_within).reshape(n, 4)
    D_A_sim = Y_within[:, 0] + Y_within[:, 1] - Y_within[:, 2] - Y_within[:, 3]
    _, p_within = stats.ttest_1samp(D_A_sim, 0)
    within_sig.append(p_within < 0.05)

print(f"\nWithin-subjects power for A: {np.mean(within_sig):.3f}")

9 ANOVA 와의 비교

within ANOVA 결과:

Source \(SS\) \(df\) \(MS\) \(F\) \(p\)
\(A\) \(n \bar D_A^2 / 4\) 1 \(t_A^2\) \(<0.0001\)
\(A \times S\) (error) \(n-1\)
\(B\) \(n \bar D_B^2 / 4\) 1 \(t_B^2\) \(<0.0001\)
\(B \times S\) (error) \(n-1\)
\(A \times B\) \(n \bar D_{AB}^2 / 4\) 1 \(t_{AB}^2\) \(0.0002\)
\(A \times B \times S\) (error) \(n-1\)

각 효과의 분모가 자기 subject interaction. multivariate \(t\)-test 와 정확히 동치.

10 효과 크기 (Cohen’s d)

각 D variable 의 표준화 효과 크기:

\[ d = \frac{\bar D}{s_D} \]

within 효과 크기 — 일반 \(d\) 보다 큰 값이 흔함 (subject 간 분산 차감).

효과 Cohen’s \(d\) 해석
\(A\) -2.0 매우 큼
\(B\) -2.0 매우 큼
\(A \times B\) +1.6

11 가정과 한계

  • D variable 의 정규성: 각 차이 점수가 정규.
  • Equal variance (자유도 1): 자동 만족.
  • 결측 시 listwise: 한 cell 결측이면 그 피험자 제거.
  • 순서 효과: counterbalancing 으로 통제 (G-MAX11-3).
  • 반응의 등간격: D variable 이 의미 있으려면 응답이 적어도 interval scale.

12 일반 \(a \times b\) 확장의 미리보기

\(2 \times 2\) 에서는 각 효과가 자유도 1 → paired \(t\)-test.

\(a \times b\) (\(a, b \ge 3\)) 에서는 각 효과의 자유도 > 1 → multivariate Hotelling \(T^2\). 세부는 G-MAX14-2.

13 응용 — 임상 연구

13.1 사례 — 인지 행동 치료 (CBT) 의 효과

요인: - \(A\): 처치 형태 (CBT vs Wait-list control). 각 환자 두 형태 모두 (cross-over). - \(B\): 평가 시점 (사전 vs 사후).

(전형적 within 분석.)

D variables: - \(D^{(A)}\): CBT 동안 평균 응답 - 대기 동안 평균 응답. - \(D^{(B)}\): 사후 평균 응답 - 사전 평균 응답. - \(D^{(AB)}\): CBT 의 사전-사후 변화 - 대기의 사전-사후 변화. 진짜 처치 효과 (Lord’s paradox 회피).

가장 관심: \(D^{(AB)}\). 처치 효과는 시간에 따른 변화의 그룹 차이.

14 본 시리즈의 흐름

G-MAX14-0  Higher-Order Within Multivariate 개관
G-MAX14-1  2×2 Within D Variable Formation  ← 현재 글
G-MAX14-2  a×b Design Extension
G-MAX14-3  Split-Plot Multivariate + Decision
    ↓
G-MAX15 (Multilevel)

15 관련 주제

선행 지식

후속 주제

다른 카테고리 연결

16 더 읽을 거리

  • Maxwell, S. E., Delaney, H. D. (2004). “Designing Experiments and Analyzing Data: A Model Comparison Perspective” (2nd ed). Lawrence Erlbaum — 본 시리즈의 source.
  • O’Brien, R. G., Kaiser, M. K. (1985). “MANOVA method for analyzing repeated measures designs.” Psychological Bulletin 97: 316-333 — multivariate within 의 표준 방법.
  • Hand, D. J., Taylor, C. C. (1987). “Multivariate Analysis of Variance and Repeated Measures.” Chapman & Hall.

Subscribe

Enjoy this blog? Get notified of new posts by email: