STAT-22 · STATISTICS

계층 모형·MCMC·사후 진단Hierarchical models, MCMC and posterior diagnostics

집단 간 정보 공유에서 정확 사후·유한 전이·MH·Gibbs와 계산 오차까지From sharing information across groups to exact posteriors, finite chains, MH/Gibbs and computational error

실습 6종 · 풀이 포함 연습문제 60개6 labs · 60 exercises with solutions

기초Foundations

1. 여러 집단의 정보를 나누어 쓰고 사후분포를 계산한다1. Share information across groups and compute a posterior

자료가 적은 작은 집단의 평균은 크게 흔들릴 수 있습니다. 모든 집단을 하나로 합치면 차이를 잃고, 완전히 따로 추정하면 작은 집단의 정보가 부족합니다. 계층 모형은 집단마다 다른 모수를 두되 공통 상위 분포를 통해 정보를 나누는 한 가지 가정입니다.

그 모형의 사후분포를 손으로 적분하기 어렵다면 MCMC를 쓸 수 있습니다. 하지만 계산 상태 4000개는 실제 관측 4000개가 아닙니다. 먼저 작은 정확 사후를 구하고, 유한 상태 전이표에서 불변분포와 주기성을 배운 뒤, MH·Gibbs와 계산 진단을 연결합니다. AI 과목을 먼저 배웠다고 가정하지 않습니다.

Small groups can have unstable means. Pooling everything loses group differences; fitting separately may leave small groups poorly informed. A hierarchy is one modeling assumption that gives groups distinct parameters while sharing a higher-level distribution.

When posterior integration is difficult, MCMC can help. Yet 4000 computational states are not 4000 actual observations. We start with an exact small posterior, learn finite transition tables, invariance and periodicity, then connect MH, Gibbs and diagnostics. Prior AI coursework is not assumed.

기초Foundations

2. 관측 오차·모형 불확실성·계산 오차를 구별한다2. Separate observation uncertainty, model uncertainty and computation error

관측 자료를 고정하고 사전·우도를 정하면 사후분포는 그 가정에서 정해진 수학적 대상입니다. 사후 표준편차는 모수 불확실성이고, 그 사후 평균을 유한 체인 평균으로 계산한 오차는 Monte Carlo 오차입니다. 체인을 오래 돌리면 후자를 줄일 수 있지만 실제 관측을 늘리거나 모형을 자동 개선하지는 않습니다.

예를 들어 실제 임금 로그 3010개를 사용해도, MCMC의 1000번째 상태는 1000번째 사람의 임금이 아닙니다. 잠재 모수의 계산 상태입니다. 상태를 그린 trace와 원자료 시계열도 다른 그래프입니다. 이 구별을 모든 사례의 단위·축·파일에 유지합니다.

Once records, prior and likelihood are fixed, the posterior is a mathematical target. Its SD describes parameter uncertainty; error from approximating its mean with a finite chain is Monte Carlo error. More computation can reduce the latter without adding observations or validating the model.

For 3010 actual logged wages, the 1000th MCMC state is not the 1000th person’s wage. It is a latent-parameter calculation. Keep traces distinct from source time series in axes, units and files.

기초Foundations

3. 두 집단의 평균과 공통 상위 평균을 둔다3. Use two group means and a shared higher-level mean

집단 j=1, 2의 관측 수 nj는 비음이 아닌 정수이며, 가용 관측 yji가 있다고 합시다. 학습용 정규 모형에서는 집단 평균 θj와 알려진 양의 관측 분산 σ²를 둡니다. θj들은 공통 μ 주위에 양의 집단 간 분산 τ²를 가진 사전으로 연결하고, μ에도 proper 정규 사전을 줍니다.

yji∣θj∼indN(θj,σ2)θ1,θ2∣μ∼indN(μ,τ2)μ∼N(m0,v0)σ2>0,τ2>0,v0>0\begin{gathered}y_{ji}\mid\theta_j\overset{\rm ind}{\sim}N(\theta_j,\sigma^2)\\\theta_1,\theta_2\mid\mu\overset{\rm ind}{\sim}N(\mu,\tau^2)\\\mu\sim N(m_0,v_0)\\\sigma^2>0,\qquad\tau^2>0,\qquad v_0>0\end{gathered}

세 양의 분산은 이 작은 모형에서 알려진 선택값입니다. 현실에서는 추정할 수 있지만 그때는 다른 모형과 계산이 됩니다. 조건부 독립은 선언한 모형 가정이며, 실제 국가나 고객이 독립이라는 검증 결과가 아닙니다.

For groups j=1, 2, let nj be nonnegative integer observation counts. Model available observations with group means θj and known positive observation variance σ². Connect group means through a shared μ and between-group variance τ²; give μ a proper Gaussian prior.

yji∣θj∼indN(θj,σ2)θ1,θ2∣μ∼indN(μ,τ2)μ∼N(m0,v0)σ2>0,τ2>0,v0>0\begin{gathered}y_{ji}\mid\theta_j\overset{\rm ind}{\sim}N(\theta_j,\sigma^2)\\\theta_1,\theta_2\mid\mu\overset{\rm ind}{\sim}N(\mu,\tau^2)\\\mu\sim N(m_0,v_0)\\\sigma^2>0,\qquad\tau^2>0,\qquad v_0>0\end{gathered}

The three variances are known chosen constants in this small model. Estimating them changes the model and computation. Conditional independence is an assumption, not evidence that actual countries or customers are independent.

기초Foundations

4. 완전 풀링·비풀링·부분 풀링은 다른 가정이다4. Complete, no and partial pooling make different assumptions

완전 풀링은 θ1=θ2 같은 공통값을 고정합니다. 비풀링은 집단을 따로 적합합니다. 부분 풀링에서는 다른 θj를 유지하면서 공통 상위 분포로 연결합니다. “집단을 공유한다”는 말이 집단 모수를 동일하게 고정한다는 뜻은 아닙니다.

μ가 주어진 조건에서 θj의 사후 평균은 다음 두 값의 가중평균입니다. 집단 n이 클수록 자기 집단 평균 쪽으로, 관측 분산이 크거나 n이 작을수록 μ 쪽으로 더 갑니다.

E[θj∣μ,y]=wjyˉj+(1−wj)μ,wj=nj/σ2nj/σ2+1/τ2.\begin{aligned} E[\theta_j\mid\mu,y] &=w_j\bar y_j+(1-w_j)\mu,\\ w_j&=\frac{n_j/\sigma^2}{n_j/\sigma^2+1/\tau^2}. \end{aligned}

nj=0이면 그 집단 표본평균은 존재하지 않습니다. 식은 정밀도 n/σ²가 0인 형태로 읽어 해당 데이터 항을 쓰지 않고, 집단 모수는 상위 분포를 통해 사후를 갖습니다. 실습에 입력된 빈 집단 평균 칸은 계산에 사용되지 않는다고 표시합니다.

Complete pooling fixes a common group value; no pooling fits groups separately. Partial pooling retains distinct θj while connecting them through a common higher-level law. Sharing a distribution does not fix group parameters equal.

E[θj∣μ,y]=wjyˉj+(1−wj)μ,wj=nj/σ2nj/σ2+1/τ2.\begin{aligned} E[\theta_j\mid\mu,y] &=w_j\bar y_j+(1-w_j)\mu,\\ w_j&=\frac{n_j/\sigma^2}{n_j/\sigma^2+1/\tau^2}. \end{aligned}

Larger n shifts weight toward the group mean. For n=0, the group mean does not exist; omit its zero-precision data contribution rather than imputing a mean. The upper-level model still supplies a group posterior, and the lab marks its mean input unused.

학부 연결 · 선택Undergraduate bridge · optional

5. 정밀도로 제곱항을 모으면 사후가 보인다5. Collect quadratic terms using precisions

정밀도는 분산의 역수입니다. wj=nj/σ², t=1/τ², r=1/v0라고 놓고 θ벡터=(θ1, θ2, μ)ᵀ를 씁니다. 우도와 사전의 로그를 합쳐 θ와 관련 없는 상수를 떼면 −θᵀQθ/2+hᵀθ 형태입니다.

Q=(w1+t0−t0w2+t−t−t−t2t+r),h=(w1yˉ1, w2yˉ2, rm0)⊤.\begin{aligned} Q&=\begin{pmatrix}w_1+t&0&-t\\0&w_2+t&-t\\-t&-t&2t+r\end{pmatrix},\\ h&=(w_1\bar y_1,\ w_2\bar y_2,\ rm_0)^\top. \end{aligned}

집단 항 (θj−μ)²/τ²를 전개하면 교차 정밀도 −t가 나오는 것을 확인하세요. 분산과 정밀도는 반대 단위이므로 이름을 바꾸어 붙이지 않습니다. 각 좌표의 화폐·연수 단위도 일관되게 정한 뒤 모형 분산을 선택합니다.

Precision is inverse variance. Write wj=nj/σ², t=1/τ², r=1/v0 and parameter vector (θ1, θ2, μ)ᵀ. The log posterior, apart from constants, has form −θᵀQθ/2+hᵀθ.

Q=(w1+t0−t0w2+t−t−t−t2t+r),h=(w1yˉ1, w2yˉ2, rm0)⊤.\begin{aligned} Q&=\begin{pmatrix}w_1+t&0&-t\\0&w_2+t&-t\\-t&-t&2t+r\end{pmatrix},\\ h&=(w_1\bar y_1,\ w_2\bar y_2,\ rm_0)^\top. \end{aligned}

Expanding (θj−μ)² explains the negative off-diagonal precision −t. Precision and variance have reciprocal units. Choose coherent coordinate units before specifying model variances.

학부 연결 · 선택Undergraduate bridge · optional

6. 제곱을 완성해 정확한 공동 사후를 구한다6. Complete the square for an exact joint posterior

이 모형의 Q는 양의 정부호입니다. 임의 비영 벡터 (a, b, c)에 대한 이차형식은 w1a²+w2b²+t(a−c)²+t(b−c)²+rc²입니다. t, r>0이므로 모든 항이 0이면 c=0, a=b=0이어야 합니다. 따라서 두 집단 데이터가 모두 비어도 proper 사전이 공동 분포를 정합니다.

m=Q−1h,u=θ−mq(θ)=−12θ⊤Qθ+h⊤θq(θ)=−12u⊤Qu+Kθ∣y∼N3(m,Q−1)\begin{gathered}m=Q^{-1}h,\qquad u=\theta-m\\q(\theta)=-\tfrac12\theta^\top Q\theta+h^\top\theta\\q(\theta)=-\tfrac12u^\top Qu+K\\\theta\mid y\sim N_3(m,Q^{-1})\end{gathered}

q(θ)는 원래 로그 사후 커널의 이차식이며 K는 θ와 무관한 항입니다. m과 u는 완전제곱의 중심과 중심화 벡터입니다.

K는 θ와 무관한 상수입니다. 정확한 사후 평균과 공분산을 아는 이 예를 계산 실습의 기준으로 씁니다. Q⁻¹의 비대각항은 집단 모수들의 사후 의존을 보여 줍니다. 조건부 독립이 곧 주변 사후 독립이라는 뜻은 아닙니다.

Q is positive definite: its quadratic form is w1a²+w2b²+t(a−c)²+t(b−c)²+rc². With t, r>0, zero requires a=b=c=0. Proper priors therefore define the joint distribution even without group observations.

m=Q−1h,u=θ−mq(θ)=−12θ⊤Qθ+h⊤θq(θ)=−12u⊤Qu+Kθ∣y∼N3(m,Q−1)\begin{gathered}m=Q^{-1}h,\qquad u=\theta-m\\q(\theta)=-\tfrac12\theta^\top Q\theta+h^\top\theta\\q(\theta)=-\tfrac12u^\top Qu+K\\\theta\mid y\sim N_3(m,Q^{-1})\end{gathered}

q(θ) is the original quadratic log-posterior kernel; K is independent of θ. m and u are its center and centered vector.

K is parameter-free. This exact mean/covariance becomes a computational reference. Off-diagonal covariance reveals posterior dependence; conditional independence does not imply marginal posterior independence.

선택 심화Optional extension

7. 상위 평균을 먼저 풀어 부분 풀링을 확인한다7. Solve the higher-level mean first to inspect partial pooling

행렬 역수 계산을 또 다른 방식으로 확인해 봅시다. dj=wj+t라 두면, 정규방정식 첫 두 줄에서 mj=(wj 평균j+t mμ)/dj입니다. 이를 마지막 줄에 넣으면 상위 평균 한 개의 방정식이 됩니다.

S=2t+r−t2(1/d1+1/d2),mμ=rm0+t(w1yˉ1/d1+w2yˉ2/d2)S,mj=(wjyˉj+tmμ)/dj.\begin{aligned} S&=2t+r-t^2(1/d_1+1/d_2),\\ m_\mu&=\frac{rm_0+t(w_1\bar y_1/d_1+w_2\bar y_2/d_2)}S,\\ m_j&=(w_j\bar y_j+t m_\mu)/d_j. \end{aligned}

양의 Q 때문에 S>0입니다. 관측을 쓰지 않는 집단도 mμ를 통해 다른 집단과 연결됩니다. 다만 실제 다른 집단의 자료를 빌려 쓰는 판단은 이 계층·분산 가정에 기대므로, 임의 집단 구분을 자동 정당화하지 않습니다.

Check the inverse by another calculation. With dj=wj+t, the first two normal equations give mj=(wjȳj+t mμ)/dj. Substitute them into the final equation:

S=2t+r−t2(1/d1+1/d2),mμ=rm0+t(w1yˉ1/d1+w2yˉ2/d2)S,mj=(wjyˉj+tmμ)/dj.\begin{aligned} S&=2t+r-t^2(1/d_1+1/d_2),\\ m_\mu&=\frac{rm_0+t(w_1\bar y_1/d_1+w_2\bar y_2/d_2)}S,\\ m_j&=(w_j\bar y_j+t m_\mu)/d_j. \end{aligned}

Positive Q implies S>0. Even an empty group connects through mμ. Borrowing information relies on the hierarchy and variance assumptions, not an automatic justification for any grouping.

기초Foundations

8. 실습 A · 알려진 분산의 작은 계층을 정확히 푼다8. Lab A · Solve a small known-variance hierarchy exactly

두 집단의 n·평균과 세 양의 분산·상위 사전 평균을 고릅니다. Q, h, 사후 평균과 공분산을 읽으세요. 관측 분산을 키우거나 집단 간 분산을 줄일 때 부분 풀링이 어떻게 바뀌는지 비교합니다.

분산은 알려진 선택값이고, n=0인 집단의 평균은 사용하지 않습니다. 표의 사후는 선택 모형 아래의 정확한 정규 계산이며, 현실의 자료 독립성·정규성·사전 적절성을 인증한 것이 아닙니다. 뒤의 Gibbs 계산을 이 정확 기준과 대조합니다.

Choose group counts/means, three positive variances and a hyperprior mean. Inspect Q, h and posterior mean/covariance. Compare pooling as observation variance increases or between-group variance decreases.

Variances are known chosen constants; empty-group means are unused. This is an exact Gaussian calculation under the model, not certification of actual independence, normality or prior suitability. It provides a reference for Gibbs.

기초Foundations

9. 마르코프 전이표를 처음부터 읽는다9. Read a Markov transition table from the beginning

상태가 0과 1인 계산을 생각합시다. 현재 상태가 i일 때 다음 상태가 j일 확률을 Pij라고 씁니다. 이전의 전체 경로를 알아도 현재 상태를 조건으로 주면 다음 상태의 법칙이 P의 같은 행으로 정해지는 것이 마르코프 성질입니다. 이는 현실의 보편 법칙이 아니라 선택한 과정의 성질입니다.

P=(1−aab1−b)0≤a,b≤1\begin{gathered}P=\begin{pmatrix}1-a&a\\b&1-b\end{pmatrix}\\0\le a,b\le1\end{gathered}

각 칸은 음수가 아니고 각 행의 합은 1입니다. 열의 합은 꼭 1일 필요가 없습니다. a=0.2, b=0.3이면 상태 0에서 1로 갈 확률은 0.2이고, 상태 1에서 0으로 갈 확률은 0.3입니다. 행과 열의 방향을 바꾸지 않도록 작은 말 설명을 먼저 붙여 보세요.

For states 0 and 1, let Pij be the probability of next state j given current i. The Markov property means that conditioning on the current state makes the earlier path irrelevant to this next-state law. This is a property of the chosen process, not a universal law of nature.

P=(1−aab1−b)0≤a,b≤1\begin{gathered}P=\begin{pmatrix}1-a&a\\b&1-b\end{pmatrix}\\0\le a,b\le1\end{gathered}

Entries are nonnegative and each row sums to one; columns need not. With a=.2, b=.3, the 0-to 1 probability is.2 and 1-to 0 probability .3. Explain the direction in words before multiplying matrices.

기초Foundations

10. 분포를 한 번 옮기는 것과 경로 한 번을 그리는 것은 다르다10. Propagating a law differs from drawing one path

현재 분포를 행벡터 p0=(1, 0)로 두면 한 번 뒤 분포는 p1=p0P입니다. a=0.2, b=0.3이면 p1=(0.8, 0.2), 두 번 뒤는 (0.7, 0.3)입니다. 첫 상태에서 시작한 한 경로의 상태는 매 시점 0 또는 1이지만, 이 분포 벡터는 두 가능성의 확률입니다.

pt+1=ptPpt=p0PtP0=I\begin{gathered}p_{t+1}=p_tP\\p_t=p_0P^t\\P^0=I\end{gathered}

t=0에는 아직 전이를 하지 않았습니다. 실습의 곡선은 각 시점의 분포를 계산한 것이므로 표본 경로의 관측 빈도로 부르지 않습니다. 난수 경로를 추가한다면 어느 생성기와 seed를 썼는지 따로 기록해야 합니다.

Starting law p0=(1, 0) moves to p1=p0P. For a=.2, b=.3, this is (.8, .2), then (.7, .3). One realized path has state 0 or 1 at each time; the probability vector describes both possibilities.

pt+1=ptPpt=p0PtP0=I\begin{gathered}p_{t+1}=p_tP\\p_t=p_0P^t\\P^0=I\end{gathered}

At t=0, no transition has occurred. Lab curves are calculated probability laws, not empirical path frequencies. A random path would require a separately stated generator and seed.

기초Foundations

11. 불변분포는 한 번 옮겨도 같은 확률벡터다11. An invariant law stays the same after one transition

πP=π이고 π가 확률벡터이면 불변분포라고 합니다. 두 상태에서 a+b>0일 때 방정식을 풀면 π=(b/(a+b), a/(a+b))입니다. a=0.2, b=0.3에서는 (0.6, 0.4)입니다. π에서 시작하면 모든 시점의 주변분포가 같습니다.

이는 각 경로가 같은 상태에 멈춘다는 뜻이 아닙니다. 상태는 계속 이동할 수 있고, 시점별 주변법칙만 같습니다. 또한 임의의 초기 분포에서 π로 간다는 수렴 명제는 불변성만으로 나오지 않습니다. 다음 두 반례에서 조건을 구분합니다.

An invariant probability vector satisfies πP=π. In two states with a+b>0, the solution is (b/(a+b), a/(a+b)); for a=.2, b=.3, it is (.6, .4). Starting from π preserves each marginal law.

Paths need not stop moving. Invariance concerns laws, not frozen states. Convergence from every initial law is another claim and does not follow from invariance alone.

기초Foundations

12. 항등 전이와 흡수 상태에서 유일성을 나누어 본다12. Identity transitions and absorbing states separate uniqueness from reducibility

P=I₂이면 어떤 확률벡터도 불변입니다. 시작한 상태가 그대로라 여러 초기값이 서로 섞이지 않습니다. 불변분포가 존재한다는 사실만으로 하나의 목표가 선택되지 않는 반례입니다.

반면 a=0, b>0이면 상태 0은 흡수이고, 상태 1에서는 매번 0으로 갈 양의 확률이 있습니다. 이때 유일 불변분포는 (1, 0)이고 어떤 초기 분포도 거기로 갑니다. 따라서 가약이라는 사실 자체가 불변분포 비유일성을 뜻하지는 않습니다. 구조를 직접 확인해야 합니다.

With P=I₂, every probability vector is invariant. Paths stay at their starts, so different starts do not mix. Existence of an invariant law does not select one target.

With a=0, b>0, state 0 is absorbing and state 1 can reach it. The unique invariant law is (1, 0), and all initial laws approach it. Reducibility alone therefore does not imply nonuniqueness; inspect the structure.

기초Foundations

13. 상세균형은 불변성의 충분조건이지 필요조건이 아니다13. Detailed balance is sufficient for invariance, not necessary

모든 상태쌍에서 πiPij=πjPji이면 상세균형이라고 합니다. 양방향의 정상 확률 흐름이 같다는 뜻입니다. 상태 j로 향하는 유입을 i에 대해 합치면 ΣiπiPij=πjΣiPji=πj가 되어 불변성이 따라옵니다. 마지막 합은 P의 j번째 행 합입니다.

하지만 세 상태가 0→1→2→0으로만 이동하는 순환에서는 균등 π가 불변이어도 역방향 전이가 0이라 상세균형이 실패합니다. 자기 상태 유지 1/2와 순환 1/2를 섞어도 균등 불변·비상세균형은 유지됩니다. 되돌릴 수 있는 알고리즘이 편리하다는 사실과 모든 올바른 알고리즘이 되돌릴 수 있어야 한다는 주장을 구별합니다.

Detailed balance means πiPij=πjPji for every pair. Summing incoming flows gives ΣiπiPij=πjΣiPji=πj, using row j’s sum. Thus it implies invariance.

A directed three-cycle has uniform invariant law but zero reverse flow, so it is not reversible. Mixing half identity with half directed cycle preserves uniform invariance without detailed balance. Reversibility is convenient, not necessary for every valid invariant algorithm.

기초Foundations

14. 갈 수 있다는 말은 여러 걸음의 양의 확률 경로를 뜻한다14. Reachability means a positive-probability path in some number of steps

유한 상태 연쇄가 불가약이면 어느 상태에서 다른 어느 상태로도 유한 걸음의 양의 확률 경로가 있습니다. 한 걸음 Pij가 모두 양수일 필요는 없습니다. 세 상태 순환은 한 걸음에 한 방향만 가지만 모두 서로 도달 가능하여 불가약입니다.

유한 불가약 연쇄에는 유일한 양의 불변분포가 있습니다. 무한·연속 상태공간에는 추가 재귀성 같은 조건이 필요하므로 이 유한 정리를 그대로 옮기지 않습니다. 실습의 정해진 작은 전이표에서 확인한 성질과 일반 MCMC의 수학적 수렴 보장을 구분합니다.

A finite chain is irreducible when every state can reach every other through a finite positive-probability path. Every one-step entry need not be positive. A directed three-cycle is irreducible despite sparse transitions.

A finite irreducible chain has a unique positive invariant distribution. Infinite or continuous spaces need additional recurrence conditions; the finite theorem does not transfer automatically to general MCMC.

기초Foundations

15. 번갈아 가는 연쇄는 불변분포가 있어도 진동한다15. An alternating chain can have an invariant law yet oscillate

P=[[0, 1], [1, 0]]은 불가약이고 π=(1/2, 1/2)가 유일 불변입니다. 그러나 (1, 0)에서 시작하면 주변분포는 (1, 0), (0, 1)을 계속 번갈아 가집니다. 상태로 돌아오는 가능한 걸음 수는 2, 4, 6, …라 그 최대공약수인 주기는 2입니다.

불가약 연쇄에서 가능한 귀환 시간의 최대공약수가 1이면 비주기입니다. 자기 유지 양의 확률이 있는 상태를 포함한 불가약 유한 연쇄는 비주기입니다. 세 상태 순환은 주기 3이고, 절반 자기 유지를 섞은 lazy 순환은 비주기입니다. π에서 시작한 주기 연쇄의 주변법칙이 일정할 수 있다는 것과, 모든 시작에서 수렴한다는 것을 구분합니다.

The alternating matrix [[0, 1], [1, 0]] is irreducible with unique invariant law (.5, .5). From (1, 0), marginals alternate forever. Return times 2, 4, 6, …have gcd two, its period.

An irreducible chain is aperiodic when return-time gcd is one. A positive self-loop suffices in a finite irreducible chain. A directed three-cycle has period three; adding half holding makes it aperiodic. Stationary marginals from a special start differ from convergence from every start.

학부 연결 · 선택Undergraduate bridge · optional

16. 유한 불가약·비주기의 결론과 적용 범위16. The finite irreducible-aperiodic theorem and its scope

유한 상태 연쇄가 불가약·비주기이면 유일 불변분포 π가 있고, 모든 초기 확률벡터 p0에서 p0Pᵗ→π입니다. 유한 상태에서는 각 확률의 수렴과 전체 변동거리 수렴이 연결됩니다. π에서 시작하면 처음부터 불변이고, 다른 시작에서는 초기 효과가 줄어듭니다.

∥pt−π∥TV=12∑i∣pt,i−πi∣.\|p_t-\pi\|_{\rm TV}=\frac12\sum_i|p_{t,i}-\pi_i|.

이 정리는 유한 시점 t=100이 충분하다는 보편 숫자를 주지 않습니다. 전이 확률이 아주 작으면 수렴이 느릴 수 있습니다. 또 가약이어도 특정한 흡수 구조에서는 수렴할 수 있으므로 두 조건을 모든 수렴의 필요조건이라고 부르지 않습니다.

선택 심화로 정량 연결을 보겠습니다. 어떤 m에서 모든 Pᵐij≥δ>0이고 상태 수가 N이면 ε=Nδ≤1입니다. 각 행에서 공통 균등질량 ε를 떼면 남는 전이는 전체 변동거리를 늘리지 않아, 두 초기법칙 사이 거리가 m걸음마다 최대 1−ε배로 줄어듭니다. ε=1이면 한 블록 뒤 같은 균등법칙입니다. 유한 불가약·비주기 전이에서 이런 m이 존재한다는 것은 별도 유한 연쇄 정리이며, 작은 화면 실험으로 증명하는 것은 아닙니다.

A finite irreducible aperiodic chain has a unique invariant π, and p0Pᵗ→π for every initial law. In finite spaces, coordinate convergence gives total-variation convergence.

∥pt−π∥TV=12∑i∣pt,i−πi∣.\|p_t-\pi\|_{\rm TV}=\frac12\sum_i|p_{t,i}-\pi_i|.

The theorem supplies no universal sufficient time such as 100 steps. Very small transitions can make convergence slow. These convenient sufficient conditions are not necessary for every convergent reducible absorbing example.

For an optional quantitative bridge, suppose every entry of Pᵐ is at least δ>0 in N states. Put ε=Nδ≤1. Removing the same uniform mass ε from each row leaves a Markov remainder, which cannot increase total variation. Distances between initial laws therefore shrink by at most 1−ε per block. If ε=1, one block gives the same uniform law. Existence of such an m for finite irreducible aperiodic chains is a separate finite-chain theorem, not a conclusion from a plotted experiment.

학부 연결 · 선택Undergraduate bridge · optional

17. 주변분포의 수렴과 경로 평균의 수렴은 다른 질문이다17. Marginal convergence and path-average convergence ask different questions

유한 불가약 연쇄에서는 어떤 초기 상태에서든 경로 평균 T⁻¹Σt=1T f(Xt)가 π 아래 기대값 Σiπif(i)로 거의 확실수렴하는 법칙이 있습니다. 유한 상태의 유한한 f라 적분 가능성은 자동입니다. 이 평균 법칙에는 비주기성까지 필요하지 않습니다.

예를 들어 두 상태 번갈음 연쇄는 주변분포가 진동하지만, 0과 1 방문 비율은 각각 1/2로 갑니다. 반면 한 상태에 영원히 머무는 항등 연쇄의 경로 평균은 시작값에 묶입니다. “한 경로를 오래 평균하면 어떤 목표라도 맞힌다”는 주장은 잘못입니다. 일반 상태공간의 평균 법칙에는 별도 재귀·적분 조건이 필요합니다.

A finite irreducible chain obeys an almost-sure path-average law for every finite-valued f: the average tends to Σiπif(i), from any start. Aperiodicity is not additionally required for this average theorem.

The alternating two-state chain has oscillating marginals but visit proportions approaching one half. Identity transitions instead leave averages tied to the start. Long averaging does not guarantee every desired target. General-state versions need separate recurrence and integrability conditions.

기초Foundations

18. 실습 B · 전이표·불변법칙·진동을 함께 본다18. Lab B · Inspect transitions, invariant laws and oscillation

두 상태 a, b와 시작분포 또는 항등·번갈음·세 상태 순환·lazy 순환을 고릅니다. 0부터 t까지의 확률벡터, 선택 불변분포와의 전체 변동거리, 상세균형 잔차를 보세요. 시작벡터의 합은 정확히 1이어야 하며 임의로 재정규화하지 않습니다.

항등에서는 표시한 균등 불변분포가 하나의 예일 뿐 유일하지 않습니다. 가약 흡수 예의 유일성과, 주기 예의 주변 진동도 따로 확인합니다. 긴 소수 입력×많은 걸음에는 정확 계산 예산 제한이 있을 수 있으며, 그것은 법칙이 수학적으로 존재하지 않는다는 뜻이 아닙니다.

Choose a, b and initial law or identity, alternating, directed-cycle and lazy-cycle presets. Read time-indexed probability laws, total variation to the selected invariant law and detailed-balance residuals. Initial probabilities must sum exactly to one; the lab does not silently normalize them.

The displayed uniform invariant law for identity is one example, not unique. Distinguish absorbing reducible uniqueness and periodic oscillation. Precision-times-step limits concern exact computation budget, not mathematical existence.

기초Foundations

19. 사후를 불변분포로 가진 계산 연쇄를 만든다19. Construct a computational chain with the posterior as invariant law

MCMC의 목표는 사후 π를 불변분포로 갖는 전이를 설계하고, 적절한 조건 아래 그 경로로 사후 적분을 근사하는 것입니다. 매 시점이 독립 사후 표본일 필요는 없습니다. 정규화 상수를 몰라도 비율만으로 전이를 만들 수 있는 방법이 있습니다.

하지만 목표 사후가 proper인지, 상태들이 서로 도달 가능한지, 경로 평균 법칙이 적용되는지, 유한 계산에서 모드를 놓쳤는지 따로 확인해야 합니다. 불변성 증명은 중요한 한 단계이며 전체 계산 성공의 인증은 아닙니다. 먼저 작은 유한 목표에서 그 단계를 손으로 보겠습니다.

MCMC designs transitions preserving a posterior π, then approximates posterior integrals using paths under suitable conditions. Draws need not be independent. Some constructions need only density ratios, not a known normalizing constant.

Still check posterior propriety, reachability, an applicable average law and finite exploration. Invariance is one important step, not a certificate of overall computational success. We begin with a small finite target.

기초Foundations

20. Metropolis–Hastings는 제안과 수락을 나눈다20. Metropolis–Hastings separates proposing from accepting

양의 목표 가중치 wi와 제안 전이 Qij가 있다고 합시다. 현재 i에서 j를 제안한 뒤 다음 확률로 수락합니다. 수락하지 않으면 i에 남습니다. 실제 전이에는 이 거절 질량도 포함됩니다.

α(i,j)=min⁡ ⁣{1,wjQjiwiQij}Pij=Qijα(i,j)(i≠j)Pii=1−∑j≠iPij\begin{gathered}\alpha(i,j)=\min\!\left\{1,\frac{w_jQ_{ji}}{w_iQ_{ij}}\right\}\\P_{ij}=Q_{ij}\alpha(i,j)\quad(i\ne j)\\P_{ii}=1-\sum_{j\ne i}P_{ij}\end{gathered}

첫 식은 Qᵢⱼ>0인 실제 가능한 제안에서 씁니다. 0 확률 제안의 분기와 대각 거절확률은 앞 설명대로 구별합니다.

서로 다른 상태 i≠j에서 πi=wi/Σw라 두면 πiPij=min(πiQij, πjQji)로 양방향이 같습니다. 대각의 상세균형은 자명하고, Pii에는 거절 후 머무름도 포함되므로 그 min식을 대각에 적용하지 않습니다. 따라서 상세균형과 불변성이 성립합니다. 같은 상태를 제안해 수락한 것과 다른 상태 이동에 성공한 것도 다른 횟수이므로 수락률 정의를 기록합니다.

Given positive target weights wi and proposal matrix Q, propose j from current i, then accept with the following probability. Rejection retains i and must be included in the transition:

α(i,j)=min⁡ ⁣{1,wjQjiwiQij}Pij=Qijα(i,j)(i≠j)Pii=1−∑j≠iPij\begin{gathered}\alpha(i,j)=\min\!\left\{1,\frac{w_jQ_{ji}}{w_iQ_{ij}}\right\}\\P_{ij}=Q_{ij}\alpha(i,j)\quad(i\ne j)\\P_{ii}=1-\sum_{j\ne i}P_{ij}\end{gathered}

The first formula applies to possible proposals with Qᵢⱼ>0. Keep zero-probability proposal branches and diagonal rejection mass distinct as described above.

For distinct states i≠j and πi=wi/Σw, the stationary flow is min(πiQij, πjQji), symmetric in i, j. Diagonal balance is automatic; do not apply that min formula to Pii, which also includes rejection. This proves detailed balance and invariance. Record whether acceptance counts include proposals to the same state; acceptance and movement are different.

기초Foundations

21. 비대칭 제안에서는 목표 비율만 쓰면 틀릴 수 있다21. An asymmetric proposal needs the Hastings correction

wi=(1, 4, 1)이고 Q01=1/2, Q10=1/4라 합시다. 0→1의 목표 비율은 4지만 제안 역비는 1/2이므로 수락은 1입니다. 반대 1→0에서는 목표 비율 1/4에 역제안비 2를 곱해 수락 1/2입니다.

정상 흐름은 π0Q01α01=(1/6)(1/2)=1/12이고 π1Q10α10=(4/6)(1/4)(1/2)=1/12입니다. 목표 비율만 사용해 반대 수락을 1/4로 만들면 흐름이 맞지 않습니다. 대칭 Q에서만 제안 비율이 상쇄된다는 범위를 기억합니다.

Let w=(1, 4, 1), Q01=1/2, Q10=1/4. Forward target ratio four is multiplied by reverse-proposal ratio one half, giving acceptance one. Backward acceptance is (1/4)×2=1/2.

Both stationary flows equal 1/12. Ignoring the Hastings factor would make backward acceptance 1/4 and break that balance. Proposal ratios cancel only for symmetric proposals.

기초Foundations

22. 영확률 제안과 영 목표 상태의 해석을 나눈다22. Separate impossible proposals from zero-target states

Qij=0인 선택은 실제로 제안되지 않는 가지입니다. 그 가지의 조건부 수락 비율을 0/0으로 계산해 확률 0이라고 채우지 않습니다. 실제 전이 Pij는 0이고, 가정하지 않은 조건부 수락 커널은 미정의로 표시할 수 있습니다.

이 장의 작은 실습은 모든 wi>0으로 범위를 제한합니다. 영 목표 질량이 있는 일반 MH에서는 목표 지지집합과 시작 상태, 영질량 가지의 커널 버전을 별도로 정해야 합니다. 실습이 영 가중치를 받지 않는 것은 그런 사후가 수학적으로 존재하지 않는다는 뜻이 아닙니다. 역제안 Qji=0이지만 Qij>0인 가지는 이 양의 목표 설정에서 수락 0입니다.

If Qij=0, the selected proposal never occurs. Do not fill an undefined conditional acceptance ratio with zero merely from 0/0. The actual transition is zero; an unspecified acceptance kernel on that impossible branch can remain undefined.

The lab restricts all target weights to be positive. General MH with zero target mass needs separate support, start and zero-mass-kernel conventions. Rejecting zero weights is a supported-scope choice, not nonexistence of such posteriors. A possible forward proposal with zero reverse proposal has acceptance zero in this positive-target setting.

기초Foundations

23. 실습 C · 역제안 인자와 거절 후 머무름을 확인한다23. Lab C · Inspect reverse proposals and staying after rejection

세 양의 목표 가중치, 행합 1의 3×3 제안표, 현재·제안 상태와 균등 probe u∈[0, 1)를 고릅니다. 목표 비·역제안 비·수락·실제 전이 P와 정상 흐름을 차례로 계산해 보세요. u<α일 때 수락하므로 α=0에는 u=0도 수락하지 않습니다.

선택한 u는 임의로 지정한 탐색값이며 무작위 반복 표본이라고 부르지 않습니다. 높은 수락률이 빠른 혼합이나 독립성을 뜻하지 않습니다. 매우 작은 이동만 자주 수락해도 전체 사후의 중요한 영역을 오래 못 볼 수 있습니다.

Choose three positive target weights, a3×3 row-stochastic proposal, current/proposed states and uniform probe u∈[0, 1). Read target ratio, Hastings factor, acceptance, full P and stationary flows. Acceptance uses u<α, so even u=0 does not accept α=0.

A chosen probe is not a random sample path. High acceptance does not establish fast mixing or independence; many accepted tiny moves can still miss important posterior regions.

학부 연결 · 선택Undergraduate bridge · optional

24. 정규 계층의 완전 조건부분포를 구한다24. Derive the full conditionals of the Gaussian hierarchy

앞의 공동 사후에서 한 좌표와 관련된 제곱항만 모으면 다른 좌표를 고정한 완전 조건부분포를 얻습니다. 집단 좌표와 상위 평균의 조건부는 다음과 같습니다. 각 정규의 두 번째 인수는 분산입니다.

sj2=1/(wj+t)mj=sj2(wjyˉj+tμ)sμ2=1/(2t+r)mμ=sμ2{t(θ1+θ2)+rm0}θj∣μ,y∼N(mj,sj2)μ∣θ1,θ2,y∼N(mμ,sμ2)\begin{gathered}s_j^2=1/(w_j+t)\\m_j=s_j^2(w_j\bar y_j+t\mu)\\s_\mu^2=1/(2t+r)\\m_\mu=s_\mu^2\{t(\theta_1+\theta_2)+rm_0\}\\\theta_j\mid\mu,y\sim N(m_j,s_j^2)\\\mu\mid\theta_1,\theta_2,y\sim N(m_\mu,s_\mu^2)\end{gathered}

mⱼ,sⱼ²와 m_μ,s_μ²는 원래 두 전조건부 정규분포의 평균·분산을 각각 짧게 쓴 것입니다.

여기서는 μ를 알면 두 집단 좌표가 조건부 독립입니다. μ를 적분한 주변 사후에서는 서로 의존할 수 있습니다. “조건부 분산”을 공동 공분산 대각과 같은 값으로 복사하지 않습니다. 기준값이 같은 데이터라도 조건을 준 정보가 다르기 때문입니다.

Collect the quadratic terms for one coordinate while fixing the others. The second normal argument below is variance:

sj2=1/(wj+t)mj=sj2(wjyˉj+tμ)sμ2=1/(2t+r)mμ=sμ2{t(θ1+θ2)+rm0}θj∣μ,y∼N(mj,sj2)μ∣θ1,θ2,y∼N(mμ,sμ2)\begin{gathered}s_j^2=1/(w_j+t)\\m_j=s_j^2(w_j\bar y_j+t\mu)\\s_\mu^2=1/(2t+r)\\m_\mu=s_\mu^2\{t(\theta_1+\theta_2)+rm_0\}\\\theta_j\mid\mu,y\sim N(m_j,s_j^2)\\\mu\mid\theta_1,\theta_2,y\sim N(m_\mu,s_\mu^2)\end{gathered}

mⱼ,sⱼ² and m_μ,s_μ² abbreviate the means and variances of the original two full conditional normal laws.

Group coordinates are independent conditional on μ, but can be dependent after integrating it out. Do not copy conditional variances into marginal covariance diagonals; the conditioning information differs.

학부 연결 · 선택Undergraduate bridge · optional

25. 한 좌표의 조건부 갱신은 공동 사후를 보존한다25. A full-conditional coordinate update preserves the joint posterior

현재 (θj, θ−j)가 공동 π를 따른다고 가정해 봅시다. θ−j를 그대로 두고 θj를 π(θj|θ−j)에서 다시 뽑으면, 새 공동 분포는 π(θ−j)π(θj|θ−j)=π입니다. 이것이 Gibbs의 한 좌표 갱신이 불변성을 갖는 이유입니다.

이 불변 갱신들을 차례로 합성해도 π를 보존합니다. 합성한 systematic sweep이 반드시 상세균형을 갖는 것은 아니지만 불변성은 유지됩니다. 또한 이 증명은 현재가 π일 때 보존됨을 보인 것이지, 아무 시작점에서 한 번 갱신하면 정확 π가 된다는 뜻은 아닙니다. 수렴에는 전체 전이 구조의 추가 조건을 확인해야 합니다.

Suppose the current vector has joint law π. Keep other coordinates and redraw θj from π(θj|θ−j). Its new joint law is π(θ−j)π(θj|θ−j)=π. This proves invariance of one Gibbs update.

Composing invariant updates still preserves π. A systematic sweep need not itself satisfy detailed balance. Preservation from stationarity does not mean one update from any arbitrary start is an exact joint draw; convergence requires further conditions.

기초Foundations

26. 한 sweep에서는 이미 바꾼 새 값을 다음 조건에 쓴다26. A systematic sweep uses newly updated coordinates

순서를 θ1→θ2→μ로 정합니다. 두 집단 업데이트는 현재 μ를 쓰고, 마지막 μ 업데이트는 방금 바꾼 두 θ를 씁니다. 모든 좌표가 서로 의존하는 일반 모형에서 옛 값만 동시에 넣어 갱신하면 같은 Gibbs 전이가 아닐 수 있습니다.

조건부 N(m, v)의 계산 probe는 m+√v z입니다. z=0이면 조건부 평균이고, z=1이면 그 평균보다 조건부 SD 하나 위입니다. 이 선택 probe는 실제 정규 난수 추출이 아닙니다. 반복 시뮬레이션에서는 정상적인 생성기와 seed·워밍업·저장 규칙을 별도로 정합니다.

Use order θ1→θ2→μ. Group updates use current μ; the final μ update uses both fresh θ values. Simultaneously updating from all old coordinates can define a different transition in a dependent model.

A numerical normal probe is m+√v z. Zero gives the conditional mean; one gives one conditional SD above it. Chosen probes are not random Gaussian draws. A repeated simulation needs its own generator, seed, warmup and retention rules.

기초Foundations

27. 실습 D · 조건부 평균·분산과 갱신 순서를 추적한다27. Lab D · Trace conditional means, variances and update order

실습 A의 같은 정규 모형에 시작 상태 3개와 표준정규 probe 3개를 넣습니다. 각 단계의 정확 조건부 평균·분산과 선택 수치값, 갱신 뒤 상태를 읽으세요. probe를 모두 0으로 두면 조건부 평균만 따라가는 결정적 계산입니다.

루트 분산과 수치 덧셈에는 부동소수점 근사가 사용됩니다. 한 sweep 결과를 독립 공동 사후 표본이라고 부르지 않습니다. 후반 실제 사례는 별도로 기록한 생성기·seed의 반복 경로를 사용하며, 정확 공동 사후를 아는 기준과 그 계산 오차를 대조합니다.

Use the same model as Lab A, three starting coordinates and three standard-normal probes. Read exact conditional mean/variance, numerical value and state after each update. All-zero probes follow conditional means deterministically.

Square roots and additions use numerical approximations. One sweep is not an independent joint posterior draw. Actual-data cases use separately recorded repeated simulations and compare computational error with known exact targets.

기초Foundations

28. 워밍업을 버렸다는 사실이 초기 효과의 소멸 증명은 아니다28. Discarding warmup does not prove that initial effects have vanished

목표의 먼 곳에서 시작하면 초기 상태가 결과에 큰 영향을 줄 수 있습니다. 초반 일부를 워밍업으로 제외하는 규칙은 그 영향을 줄이려는 선택입니다. 하지만 “500개를 버렸다”만으로 모든 문제의 사후 표본이 정확해지는 것은 아닙니다.

서로 다른 시작의 여러 체인을 비교하고, 모드·꼬리·관심 함수의 이동을 확인합니다. 적응 알고리즘이라면 워밍업에서 바꾼 제안과 저장 단계의 고정 커널도 구분해야 합니다. 이 장의 보관 사례는 선택한 고정 커널·사전 생성 경로이며, HMC 적응의 모든 절차를 구현한 예가 아닙니다.

A distant start can strongly affect early values. Removing a declared warmup portion is an attempt to reduce that effect, not proof that 500 discarded states suffice for every problem.

Compare multiple dispersed starts and inspect modes, tails and relevant functions. Adaptive algorithms also require distinguishing tuning from retained sampling kernels. Our stored cases use specified fixed kernels, not a full implementation of HMC adaptation.

학부 연결 · 선택Undergraduate bridge · optional

29. 저장값의 상관은 평균 계산의 분산에 들어간다29. Correlation among retained values affects mean computation variance

정상상태에서 관심 함수의 분산이 γ0이고, lag h 공분산이 γh라면 길이 T의 평균 분산을 이중합으로 전개할 수 있습니다. 같은 h의 쌍이 T−h개 있다는 점을 셉니다.

AT=∑h=1T−1(T−h)γhVar⁡(fˉT)=Tγ0+2ATT2\begin{gathered}A_T=\sum_{h=1}^{T-1}(T-h)\gamma_h\\\operatorname{Var}(\bar f_T)=\frac{T\gamma_0+2A_T}{T^2}\end{gathered}

독립이면 h>0 공분산이 0이라 γ0/T입니다. 양의 장기 상관은 대체로 계산 평균의 분산을 키우며, 음의 상관은 줄일 수도 있습니다. 이 식은 정상상태와 유한 2차 모멘트를 가정합니다. 초기화가 먼 비정상 유한 경로에 그대로 정확한 보장이라고 붙이지 않습니다.

At stationarity, let γh be lag-h covariance of the function of interest. Counting T−h pairs gives:

AT=∑h=1T−1(T−h)γhVar⁡(fˉT)=Tγ0+2ATT2\begin{gathered}A_T=\sum_{h=1}^{T-1}(T-h)\gamma_h\\\operatorname{Var}(\bar f_T)=\frac{T\gamma_0+2A_T}{T^2}\end{gathered}

Independence reduces it to γ0/T. Positive long-run correlation can inflate variance; negative correlation can reduce it. This identity assumes stationarity and finite second moments, not an arbitrary distant-start finite trace.

기초Foundations

30. 사후 SD와 Monte Carlo SE를 같은 오차 막대로 쓰지 않는다30. Posterior SD and Monte Carlo SE are different error bars

사후 SD가 2인 모수의 사후 평균을 계산한다고 합시다. 정확한 독립 사후 추출 T개라면 평균 계산 SE는 2/√T입니다. 사후 모수의 SD 2는 관측과 모형이 만드는 불확실성이고, 계산 SE는 유한 적분 근사의 오차입니다.

상관된 MCMC에서는 원래 T 대신 관심 함수의 공분산을 반영한 계산 분산이 필요합니다. trace의 표준편차를 √T로 나누어 독립 SE라고 자동 부르지 않습니다. 모델의 가정이 부정확하면 계산 SE가 작아도 과학적 결론이 틀릴 수 있습니다.

If a parameter’s posterior SD is two, an average of T independent exact posterior draws has computational SE 2/√T. Posterior SD describes model/data uncertainty; MCSE describes finite-integration error.

Correlated MCMC requires a variance accounting for function-specific dependence. Do not automatically divide trace SD by √T as though draws were independent. Small computation error cannot repair a poor model.

학부 연결 · 선택Undergraduate bridge · optional

31. 정상 AR(1) 참조로 유한 평균 분산을 계산한다31. Use a stationary AR(1) reference for finite mean variance

사후 N(m, v)를 보존하는 선택 커널 Xₜ₊₁=m+ρ(Xₜ−m)+√(v(1−ρ²))Zₜ₊₁를 생각합니다. |ρ|<1, Z들이 시간에 걸쳐 iid 표준정규이고 초기값·현재까지의 과거와도 독립이며 처음이 정상분포라면 γh=vρʰ입니다. 이는 실제 임금의 시간 상관을 추정한 모형이 아니라 사후를 계산하는 가정 커널입니다.

Xˉ=1MT∑c=1M∑t=1TXctsT=∑h=1T−1(1−h/T)ρhcT=1+2sTVar⁡(Xˉ)=vcTMT\begin{gathered}\bar X=\frac1{MT}\sum_{c=1}^M\sum_{t=1}^TX_{ct}\\s_T=\sum_{h=1}^{T-1}(1-h/T)\rho^h\\c_T=1+2s_T\\\operatorname{Var}(\bar X)=\frac{vc_T}{MT}\end{gathered}

X̄는 서로 독립인 M개 정상 체인의 전체 MT개 값 평균입니다. s_T와 c_T는 원래 유한 길이 보정합을 짧게 쓴 것으로, MT개를 한 연속 체인으로 취급하지 않습니다.

M개 체인이 서로 독립이고 각 T길이일 때의 식입니다. 네 체인을 4T길이 한 경로처럼 이어 붙이지 않습니다. 실제 사례의 시작은 정상분포에서 뽑았다고 확인한 것이 아니므로 이 수치는 명시한 정상 이론 참조이며 유한 시작 효과를 포함한 인증이 아닙니다.

The chosen kernel Xₜ₊₁=m+ρ(Xₜ−m)+√(v(1−ρ²)) Zₜ₊₁ preserves N(m, v). Assume |ρ|<1, iid standard-normal innovations independent of the initial value and the current past, and stationary initialization. Then γh=vρʰ. This is a posterior-computation kernel, not an estimated temporal model of actual wages.

Xˉ=1MT∑c=1M∑t=1TXctsT=∑h=1T−1(1−h/T)ρhcT=1+2sTVar⁡(Xˉ)=vcTMT\begin{gathered}\bar X=\frac1{MT}\sum_{c=1}^M\sum_{t=1}^TX_{ct}\\s_T=\sum_{h=1}^{T-1}(1-h/T)\rho^h\\c_T=1+2s_T\\\operatorname{Var}(\bar X)=\frac{vc_T}{MT}\end{gathered}

X̄ is the pooled mean of MT values from M independent stationary chains. s_T and c_T abbreviate the original finite-length correction; MT values are not treated as one consecutive chain.

This assumes M independent stationary chains of length T, not one concatenated chain of length MT. Stored dispersed starts are not certified stationary; the value is a declared theoretical reference, not a finite-start guarantee.

기초Foundations

32. 이론 AR(1) ESS와 추정 bulk·tail ESS를 구별한다32. Distinguish theoretical AR(1) ESS from estimated bulk and tail ESS

정상 AR(1)의 무한 공분산 합은 τint=1+2Σh≥1ρʰ=(1+ρ)/(1−ρ)입니다. 큰 T 평균의 계산 효율 참조로 N효과≈MT/τint를 쓸 수 있습니다. ρ=0.2, M=4, T=1000이면 약 2666.67이고, ρ=0.995이면 약 10.025입니다.

이는 알려진 ρ를 넣은 정상 이론값입니다. 유한 경로에서 구한 lag1 하나를 ρ의 진실로 대입하거나, 이 숫자를 rank 기반 bulk ESS 또는 tail ESS 추정치라고 부르지 않습니다. 관심 함수마다 상관이 다를 수 있고, 음의 상관이면 이론 ESS가 저장값 수보다 클 수도 있습니다. 일반 ESS 추정기는 별도 가정·절단·수치 방법을 필요로 합니다.

Stationary AR(1) has integrated autocorrelation time τint=(1+ρ)/(1−ρ), giving asymptotic reference ESS≈MT/τint. For M=4, T=1000, it is 2666.67 at ρ=.2 but 10.025 at ρ=.995.

This uses known ρ, not a verified estimate from one finite lag 1 value. It is not estimated rank bulk-ESS or tail-ESS. Dependence is function-specific; negative correlation can produce an ESS larger than the stored count. General ESS estimators require separate assumptions, truncation and numerical methods.

학부 연결 · 선택Undergraduate bridge · optional

33. 체인 안과 체인 사이의 변동을 비교한다33. Compare within-chain and between-chain variation

같은 길이 T≥2의 체인이 M≥2개 있다고 합시다. 각 체인의 평균과 T−1분모 표본분산을 구합니다. 안쪽 변동 W는 그 분산들의 평균이고, 체인 사이 변동 B는 체인 평균들의 M−1분모 표본분산에 T를 곱한 값입니다.

W=1M∑c=1Msc2B=TM−1∑c=1M(xˉc−xˉ)2v^+=T−1TW+BTR^=v^+/W\begin{gathered}W=\frac1M\sum_{c=1}^Ms_c^2\\B=\frac{T}{M-1}\sum_{c=1}^M(\bar x_c-\bar x)^2\\\widehat v^+=\frac{T-1}{T}W+\frac BT\\\widehat R=\sqrt{\widehat v^+/W}\end{gathered}

W>0이어야 마지막 비율이 정의됩니다. 체인 평균이 크게 다르면 R̂가 커질 수 있지만, 평균만 같고 분산·꼬리가 다른 실패를 놓칠 수도 있습니다. 유한 R̂가 1보다 작게 나올 수도 있으며 실습은 임의로 1로 자르지 않습니다.

For M≥2 equal-length chains of T≥2 values, compute each mean and T−1-divisor variance. W averages within-chain variances; B is T times the M−1-divisor variance of chain means.

W=1M∑c=1Msc2B=TM−1∑c=1M(xˉc−xˉ)2v^+=T−1TW+BTR^=v^+/W\begin{gathered}W=\frac1M\sum_{c=1}^Ms_c^2\\B=\frac{T}{M-1}\sum_{c=1}^M(\bar x_c-\bar x)^2\\\widehat v^+=\frac{T-1}{T}W+\frac BT\\\widehat R=\sqrt{\widehat v^+/W}\end{gathered}

The ratio requires W>0. Different chain locations can inflate Rhat, but equal means can hide different scales or tails. Finite values can be below one; the lab does not clamp them to one.

기초Foundations

34. 체인을 반으로 나누면 한 체인 안의 이동도 드러난다34. Splitting exposes changes within a chain

각 체인의 앞·뒤 절반을 별도 체인처럼 보아 위 계산을 적용합니다. 처음에 낮고 나중에 높은 경로는 전체 평균만 보면 다른 체인과 비슷해도, 절반끼리는 차이가 날 수 있습니다. 원 체인 최소 길이 4를 요구하면 각 절반에 분산 계산을 위한 두 값 이상이 있습니다.

홀수 길이에서는 가운데 한 값을 빼고 양끝 floor(T/2)개씩 씁니다. 원 경로를 삭제해 바꾸는 것이 아니라 그 진단의 입력 선택입니다. 평균·trace 표시는 원 저장값 전체를 유지할 수 있으므로, 진단에 쓴 수와 원 저장 수를 따로 표시합니다.

Apply the variance comparison after treating each chain’s first and second halves as separate chains. Within-chain drift can then appear as between-half differences. Minimum original length four leaves at least two values per half.

For odd length, omit the single middle value and use floor(T/2) values at each end. This is diagnostic selection, not source deletion. Overall means and traces can retain all values; report original and diagnostic counts separately.

기초Foundations

35. 전체 순위와 정규 점수로 두꺼운 꼬리의 영향을 줄인다35. Pooled ranks and normal scores reduce sensitivity to heavy tails

분할한 값들을 모아 작은 순서대로 rank를 매기고 동률에는 평균 순위를 줍니다. 전체 사용값 수 S에서 다음의 정규 점수로 바꾼 뒤 split R̂를 계산합니다. Φ⁻¹은 표준정규 분위수 함수입니다.

zs=Φ−1 ⁣(rs−3/8S+1/4).z_s=\Phi^{-1}\!\left(\frac{r_s-3/8}{S+1/4}\right).

예를 들어 (1, 1, 4, 8)의 순위는 (1.5, 1.5, 3, 4)입니다. 동률을 임의로 풀면 같은 이산 상태의 의미를 바꿀 수 있습니다. 순위 변환은 원 모수가 정규분포라는 증명이나 사후 평균 모멘트가 존재한다는 증명이 아닙니다. 이 진단의 값과 원척도 사후 SD를 혼동하지 않습니다.

Pool split draws, assign ranks with average ties and transform them to normal scores before calculating split Rhat. Here S is the number used and Φ⁻¹ the standard-normal quantile.

zs=Φ−1 ⁣(rs−3/8S+1/4).z_s=\Phi^{-1}\!\left(\frac{r_s-3/8}{S+1/4}\right).

Records (1, 1, 4, 8) have ranks (1.5, 1.5, 3, 4). Arbitrarily breaking ties changes discrete-state meaning. Rank transformation neither proves a Gaussian posterior nor establishes existence of original-scale moments. Its diagnostics are not posterior SDs.

기초Foundations

36. 중앙값에서 접으면 체인별 척도 차이도 살핀다36. Folding about the median also checks scale differences

체인들이 평균 근처에서는 비슷해도 한 체인만 아주 좁은 범위에 갇힐 수 있습니다. 전체 중앙값에서의 절대거리 |x−median|를 만들고, 그 거리를 다시 순위·정규 점수로 바꿔 split R̂를 계산합니다. 일반 순위 R̂와 접힌 R̂의 큰 값을 함께 보고합니다.

짝수 저장값 수에서는 중앙 두 값 lo, hi의 평균이 중앙값입니다. 수치 계산에서는 반올림 중앙값을 먼저 빼기보다, 아래쪽에서 [(lo−x)+(hi−x)]/2, 위쪽에서 [(x−lo)+(x−hi)]/2로 계산해 중앙 두 관측이 같은 거리라는 동률을 보존합니다. 이 장은 이 관례를 명시하며 모든 소프트웨어의 비트 단위 일치를 주장하지 않습니다.

접힘의 중앙값은 홀수 길이 체인의 가운데 관측을 제외하기 전, 모든 원 저장값을 모아 구합니다. 접힌 값을 만든 뒤 체인을 분할합니다. 모든 분할 체인이 각각 상수이면 체인 내 분산의 평균 W=0이라 비율이 미정의입니다. 한 체인만 상수라는 말과는 다릅니다. 일부 원 체인이 상수인 경우에도 현대 진단의 성공 신호로 읽지 않도록 이 실습은 최종 rank/fold 지표를 보류합니다. 표시되는 각 성분과 보류 사유를 함께 읽습니다.

Chains can share a location while one is trapped at a narrow scale. Fold draws to absolute deviations from the pooled median, rank-normalize those distances and compute split Rhat. Report the maximum of ordinary rank and folded-rank diagnostics.

For an even count, the median is the average of central values lo, hi. Computing distances through [(lo−x)+(hi−x)]/2 below them and symmetric positive differences above preserves the tie of the central observations without first rounding the midpoint. We state this convention rather than claim bitwise identity with every package.

Compute the folding median from all original retained values before omitting any middle observation for odd-length splitting. Fold first, then split. If every split chain is individually constant, the average within-chain variance W is zero and its ratio is undefined; one constant chain alone does not imply W=0. The lab also withholds its final modern diagnostic if any original chain is constant, avoiding an unwarranted success signal. Read components and withholding reasons together.

기초Foundations

37. 실습 E · 원 경로·분할·순위·접힘과 이론 참조를 본다37. Lab E · Inspect paths, split/rank/fold diagnostics and theoretical references

같은 길이의 여러 짧은 체인을 넣어 원 평균·raw split·rank split·folded split·최종 큰 값·lag1을 확인합니다. 같은 상수와 서로 다른 상수 체인도 넣어 미정의가 어떻게 표시되는지 보세요. 한 개의 작은 R̂를 통과 도장으로 사용하지 않습니다.

평균 lag1은 각 원 체인의 중심화한 인접 곱합을 전체 제곱합으로 나눈 뒤 평균합니다. 이는 알려진 AR(1) ρ와 다릅니다. 선택한 ρ·정상분산을 넣은 이론 ESS/유한 MCSE 참조는 별도 표에 두며, bulk·tail ESS 추정기를 대신 구현한 것처럼 표시하지 않습니다. 근사 정규 분위수·동률 관례·지원 수치 범위도 기록합니다.

Enter several equal-length short chains and inspect means, raw/rank/fold split diagnostics, the maximum and lag 1. Try identical or differently located constant chains to see undefined results. A small Rhat is not a pass certificate.

Each lag 1 uses centered adjacent-product sum divided by the full centered square sum, then averages chains. It is not known AR(1)ρ. Separate theoretical ESS/finite MCSE references from estimated bulk/tail ESS. Retain numerical quantile, tie and supported-range conventions.

기초Foundations

38. 좋아 보이는 유한 진단도 놓친 모드를 증명하지 못한다38. Good-looking finite diagnostics cannot rule out missed modes

모든 체인을 같은 좁은 모드에서 시작하면 그 안에서만 잘 섞여 R̂가 작아도 다른 모드를 전혀 보지 못할 수 있습니다. trace가 평평하면 정확한 상수 목표인지, 전이가 막힌 것인지 원리와 구조를 확인해야 합니다. 값이 움직인다는 사실만으로도 충분하지 않습니다.

관심 함수·꼬리·사후 예측·서로 다른 시작을 함께 살피고, 작은 정확 예제에서 알려진 적분과 비교하세요. 유한 진단은 실패의 증거를 찾는 도구이지 모든 함수에 대한 수렴의 수학적 증명이 아닙니다. 모형 검증과 계산 진단도 분리합니다.

All chains can mix inside one narrow mode and have small Rhat while never discovering another mode. Flat traces need a structural check: an actually constant target and a stuck sampler are different. Movement alone is insufficient too.

Inspect relevant functions, tails, predictions and dispersed starts; compare small examples with known integrals. Finite diagnostics seek evidence of failure, not prove convergence for every function. Model assessment remains separate.

기초Foundations

39. 더 오래 저장하기·thin하기·새 관측 모으기는 다르다39. Longer storage, thinning and collecting observations are different actions

같은 전이와 같은 모델로 더 오래 계산하면 Monte Carlo 정밀도를 높일 수 있습니다. 하지만 매우 느린 모드 이동은 단순 저장 수 증가로 실무 시간 안에 해결되지 않을 수 있습니다. 더 좋은 제안·재표현·다른 알고리즘과 추가 진단을 검토합니다.

매 k번째 상태만 남기는 thinning은 저장량과 간격을 바꿉니다. 그 자체가 모형을 고치거나 놓친 모드를 방문시키거나 독립성을 증명하지 않습니다. 저장·후처리 비용을 줄이는 이유가 있으면 기록하되, 버린 값을 포함한 계산 비용과 비교해야 합니다. 실제 관측을 추가하는 일은 사후 목표 자체를 바꿀 수 있는 별도 행동입니다.

Longer computation under the same model can improve MC precision, but extremely slow mode movement may remain impractical. Better proposals, reparameterization or another algorithm may help, with renewed checks.

Thinning changes storage and spacing. It does not repair the model, force discovery of missing modes or prove independence. Justify storage/processing trade-offs against total computation. Collecting observations is a different action that can change the posterior target itself.

기초Foundations

40. 모수의 사후와 새 관측의 예측분포를 구별한다40. Separate parameter posteriors from predictions of new observations

집단 모수 θj의 사후 분산이 작아도 새 y의 관측 오차 σ²는 남습니다. 같은 집단의 새 관측이 모수 조건부로 기존 자료와 독립인 정규 모형에서는 총분산 법칙으로 예측 분산을 구합니다.

E[ynew∣y]=E[θj∣y],Var⁡(ynew∣y)=σ2+Var⁡(θj∣y).\begin{aligned} E[y_{\rm new}\mid y]&=E[\theta_j\mid y],\\ \operatorname{Var}(y_{\rm new}\mid y) &=\sigma^2+\operatorname{Var}(\theta_j\mid y). \end{aligned}

새 집단을 예측하면 상위 μ와 집단 간 τ²의 변동도 관련됩니다. 어느 집단·어느 수준의 대상을 예측하는지 먼저 적습니다. 사후 모수의 trace를 새 국가나 새 고객의 관측값으로 부르지 않는 이유가 여기에도 있습니다.

A concentrated posterior for θj does not eliminate observation variance σ². Under the model’s conditional independence for a new same-group observation, total variance gives:

E[ynew∣y]=E[θj∣y],Var⁡(ynew∣y)=σ2+Var⁡(θj∣y).\begin{aligned} E[y_{\rm new}\mid y]&=E[\theta_j\mid y],\\ \operatorname{Var}(y_{\rm new}\mid y) &=\sigma^2+\operatorname{Var}(\theta_j\mid y). \end{aligned}

A new group additionally involves upper-level and between-group variation. State the predictive level. Parameter traces are not new observed countries or customers.

선택 심화Optional extension

41. 연속 상태와 improper 사후에는 추가 이론이 필요하다41. Continuous states and improper posteriors require additional theory

유한 전이표의 불가약·비주기 조건을 외웠다고 모든 연속 MCMC가 수렴한다고 결론낼 수는 없습니다. 일반 상태공간에서는 적절한 불가약성·재귀성·적분 가능성 같은 가정이 필요하고, 평균 CLT와 MCSE에는 더 강한 혼합·모멘트 조건이 필요할 수 있습니다.

또 정규화할 수 없는 사후를 목표로 삼으면 정상 확률분포 자체가 없습니다. 개별 조건부분포를 계산할 수 있거나 유한 trace가 안정돼 보인다는 사실만으로 공동 사후가 proper임을 보장하지 않습니다. 이 장의 정규 계층은 양의 proper 사전과 Q의 정부호로 그 점을 먼저 확인했고, 실제 고객의 유한 9노드 사후도 정규화한 기준을 보관합니다.

Finite-chain irreducibility/aperiodicity alone is not a theorem for every continuous MCMC. General-state recurrence, irreducibility and integrability conditions are needed; CLTs and MCSE may require additional mixing and moments.

An unnormalizable posterior has no target stationary probability law. Available conditionals or a stable-looking finite trace do not establish joint propriety. Our Gaussian hierarchy checks proper priors and positive Q; the customer nine-node reference is explicitly normalized.

기초Foundations

42. 계산 검산과 모형 점검을 함께 기록한다42. Record computational checks alongside model checks

먼저 관측 단위·가용 수·화폐 단위·집단 정의를 고정하고, 사전·우도·분산 가정을 적습니다. 작은 정확 사후나 정규화 가능한 격자로 알고리즘을 검산한 뒤, 생성기·seed·업데이트 순서·시작값·워밍업·저장 규칙을 남깁니다.

그 다음 여러 trace·순위·접힘·관심 함수·MC 정밀도를 봅니다. 사전 예측과 사후 예측이 실제 관측 구조를 얼마나 설명하는지 평가하고, 민감한 가정은 다른 사전·집단 정의로 비교합니다. 계산을 정밀하게 했다는 이유로 모델·대표성·인과 설명까지 자동 인정하지 않습니다.

First fix observation units, availability, currency, groups, priors, likelihood and variance assumptions. Check algorithms on small exact posteriors or normalized grids, then retain generators, seeds, update order, starts, warmup and storage rules.

Inspect traces, ranks, folding, relevant functions and MC precision. Evaluate prior/posterior predictions and sensitivity to assumptions. Accurate computation does not automatically establish model adequacy, representativeness or causality.

기초Foundations

43. 실제 16국을 작은 정규 계층의 정확 기준과 비교한다43. Compare sixteen actual countries with an exact Gaussian hierarchy

2024년 실제 16국의 GDP/명을 10000으로 나누고, 기간 기대수명 80년 이상·미만으로 각각 8국을 구분한 사례입니다. GDP 좌표에서 관측 분산 1, 집단 간 분산 1, 상위 μ의 사전 N(3, 4)를 선택합니다. 그 숫자는 학습 가정이며 세계 국가의 생성 과정을 검증한 값이 아닙니다.

정확 공동 사후의 정밀도는 Q=[[9, 0, −1], [0, 9, −1], [−1, −1, 9/4]]입니다. 네 가지 시작의 Gibbs 경로를 생성해 500 sweep을 제외하고 각 1000개를 보관했습니다. 사후 평균·공분산의 정확 유리수와 계산 평균 오차를 대조할 수 있습니다. 국가를 실제로 4000개 새로 관측한 일이 아닙니다.

The case groups actual 2024 GDP/person for sixteen countries by period life expectancy at 80 years, eight per group. Scale GDP by 10000 and choose observation variance one, between-group variance one and hyperprior N(3, 4). These are teaching assumptions, not verified global-country generation.

Exact posterior precision is [[9, 0, −1], [0, 9, −1], [−1, −1, 9/4]]. Four starts generate Gibbs paths;500 warmup sweeps are excluded and 1000 states per chain retained. Exact rational posterior moments permit computational error checks. These are not 4000 newly observed countries.

기초Foundations

44. 실제 로그임금의 같은 사후에 두 상관 커널을 붙인다44. Use two correlated kernels for the same actual log-wage posterior

원 3613행 중 가용 로그 3010개에 알려진 관측 분산 1/4, 사전 N(6, 1/4)를 선택하면 사후 분산은 1/12044이고 사후 평균은 1885411407241/301100000000입니다. 결측 603개는 그대로 보존합니다.

이 같은 정규 사후를 보존하는 ρ=0.2와 0.995의 두 AR 커널을 비교합니다. 높은 ρ의 경로는 많이 저장해도 평균 계산 효율이 낮을 수 있습니다. 정상 이론의 4000개 ESS 참조는 각각 8000/3과 4000/399입니다. 이는 임금의 실제 시간 AR계수를 추정한 결과가 아니며, 원 로그 척도와 계산 경로를 구분해야 합니다.

For 3010 available logs among 3613 rows, choose observation variance 1/4 and prior N(6, 1/4). The posterior variance is 1/12044 and mean 1885411407241/301100000000. Preserve 603 unavailable records.

Compare posterior-preserving AR kernels ρ=.2 and .995. High correlation can make many stored values computationally inefficient. Stationary theoretical ESS references for 4000 values are 8000/3 and 4000/399. These are not estimated temporal AR parameters of actual wages.

기초Foundations

45. 실제 고객의 9개 상위 노드와 Rao–Blackwell 경로45. Nine hypernodes and Rao–Blackwell traces for actual customers

불만·비불만 고객의 실제 이탈 집계는 (200/241,295/2909)입니다. 상위 평균 μ∈{1/4, 1/2, 3/4}, 집중도 κ∈{4, 20,100}의 9개 노드와 균등 노드 사전을 선택합니다. 각 집단 p는 노드 아래 Beta(κμ, κ(1−μ)) 사전을 공유하고, 노드별로 p를 적분해 이항 증거를 계산합니다.

정규화한 9개 사후 질량은 정확 기준입니다. MH 경로에서는 상위 노드를 움직이며, 각 노드의 불만 집단 조건부 사후 평균 (200+κμ)/(241+κ)를 저장합니다. 이는 p 자체를 새로 뽑은 trace가 아니라 조건부 평균 함수의 Rao–Blackwell 계산입니다. 국소 순환 제안은 보관 기간에 체인이 상수가 되는 실패를 보였고, 전역 제안과 비교합니다. 상수 진단을 1로 채우지 않습니다.

Actual churn counts are 200/241 and 295/2909. Choose nine hypernodes μ∈{1/4, 1/2, 3/4}, κ∈{4, 20,100}, with uniform node prior and conditional group Beta(κμ, κ(1−μ)) priors. Integrate group probabilities to obtain node evidences.

The normalized node posterior is an exact reference. MH moves hypernodes and stores conditional complaint-posterior means (200+κμ)/(241+κ), not draws of p itself. These are Rao–Blackwell function traces. Local-cycle proposals produce constant retained chains in this demonstration; compare global proposals and preserve undefined diagnostics.

기초Foundations

46. 실습 F · 보관 경로의 길이와 정확 기준을 함께 읽는다46. Lab F · Compare retained prefixes with exact references

실제 세 사례와 좌표·커널, 저장 prefix 4–1000을 선택합니다. 원 고정 경로의 앞부분을 읽는 것이며 매번 새 난수 체인을 생성하지 않습니다. 평균 오차·raw/rank/fold 진단·lag1과 알려진 기준을 대조하세요.

모든 trace는 실제 자료에 붙인 선택 모형의 계산 결과입니다. 원 행을 바꾸거나 고객 p 표본을 새로 만들지 않습니다. 원자료 수·선택 우도·사전·생성기·seed·워밍업 500·보관 4×1000과, 진단 prefix의 실제 길이를 함께 보존합니다. 유한 진단의 변화는 실제 과학적 가정을 검증한 것이 아닙니다.

Select case, coordinate/kernel and retained prefix 4–1000. Read a prefix of fixed stored paths rather than regenerate random chains. Compare mean error, raw/rank/fold diagnostics, lag 1 and known references.

Traces are computations under chosen models attached to actual records. They do not modify sources or create new customer-p draws. Retain source counts, likelihood, prior, generator, seed, 500 warmup sweeps, 4×1000 stored values and actual diagnostic-prefix length. Finite diagnostics do not verify scientific assumptions.

기초Foundations

47. 국가·개인·고객의 사후·경로·진단을 원자료와 함께 본다47. Read actual sources, posteriors, paths and diagnostics together

국가 사례 · 계층 모형을 손으로 풀고 Gibbs 계산을 대조하기

World Bank 실제 2024년 16국의 1인당 실질 GDP를 10000으로 나눠 x로 둡니다. x 한 단위는 2015년 불변 10,000USD/인입니다. 기간 기대수명 80년 이상·미만 집단은 각각 8국이며 기간 기대수명은 특정 개인 수명 예측이 아닙니다. 이 선택 프레임에 아래 정규 계층모형을 붙이는 것은 학습자의 가정입니다. 16국가가 세계의 무작위 표본이라는 사실이나 두 집단 차이의 인과적 설명이 되지 않습니다.

xig∣θg∼N(θg,1)θg∣μ∼N(μ,1)μ∼N(3,4)\begin{gathered}x_{ig}\mid\theta_g\sim N(\theta_g,1)\\\theta_g\mid\mu\sim N(\mu,1)\\\mu\sim N(3,4)\end{gathered}

공동모형에서는 θ들이 주어졌을 때 관측들이 조건부 독립이고, μ가 주어졌을 때 두 θ가 조건부 독립이라고 가정합니다. 이 곱 구조가 있어야 아래 Q와 조건부 Gibbs 식을 얻습니다. 실제 국가 간 독립성을 확인했다는 뜻은 아닙니다.

기호 N의 두 번째 인자는 분산입니다. 관측 분산과 집단 간 분산을 모두 1로 고정했으며 실제 자료에서 추정한 분산으로 둔갑시키지 않습니다. 정규분포는 음수 GDP에도 질량을 두므로 지지집합까지 현실에 맞는 모형도 아닙니다. 대신 정확 사후를 풀 수 있어 알고리즘 오류를 찾기 좋은 작은 실험입니다. θ₁,θ₀,μ의 순서로 정밀도 Q와 우변 h를 만들면 사후 평균은 Q⁻¹h, 공분산은 Q⁻¹입니다.

Q=(90−109−1−1−19/4)h=(∑g=1xi∑g=0xi3/4)E[ϑ∣x]=Q−1h\begin{gathered}Q=\begin{pmatrix}9&0&-1\\0&9&-1\\-1&-1&9/4\end{pmatrix}\\h=\begin{pmatrix}\sum_{g=1}x_i\\\sum_{g=0}x_i\\3/4\end{pmatrix}\\E[\vartheta\mid x]=Q^{-1}h\end{gathered}
실제 집단 요약과 가정 모형의 정확 사후 · 화면 소수 반올림
매개변수원 관측 수관측 평균사후 평균사후 SD
기대수명≥80 집단 θ₁84.7664334.5808810.342344
기대수명<80 집단 θ₀81.4536151.6361530.342344
상위 평균 μ16해당 없음3.0964590.702247

Gibbs 한 sweep은 두 θ를 현재 μ에서 뽑고 이어 μ를 새 두 θ에서 뽑는 순서입니다. θ_g의 조건부 분산은 1/9, μ의 조건부 분산은 4/9입니다. 별도 시작점 네 개에서 각 1500 sweep을 실행하고 앞 500개를 준비 구간으로 제외합니다. 남은 4000개는 새 국가 관측이 아니라 선택 사후를 근사하는 상관된 계산 상태입니다. 준비 구간 길이 500이 모든 문제에 충분하다는 정리는 아닙니다.

먼저 생각한 뒤 풀이 보기: 집단 평균에서 사후 평균으로 움직인 것은 GDP가 바뀌었다는 뜻인가요?

아닙니다. 원 GDP는 그대로입니다. 사후 평균은 집단 우도와 상위 평균의 조건부 가중 결합입니다. μ를 고정하면 E[θ_g|μ,x]=(합 x_g+μ)/9이고, 다시 μ의 사후 불확실성을 평균합니다. 이 수축은 가정한 분산·사전·집단 구분에 의존합니다. CSV의 Q·Q⁻¹ 곱이 I인지 먼저 확인한 뒤 체인 평균을 정확 사후 평균과 비교하세요.

사람 사례 · 같은 사후분포인데 왜 한 체인은 느릴까?

Card 원 3613개 행 중 가용 3010개의 lwage76은 1976년 시간당 임금(센트)의 원 극단값 정리 로그 변수입니다. 결측 603개를 0으로 채우지 않습니다. 알려진 관측 분산 1/4, 사전 μ~N(6,1/4)를 가정하면 사후 평균 m=(관측 로그합+6)/3011, 분산 v=1/(4×3011)입니다. 실제 iid나 이 분산의 타당성을 검정한 것이 아닙니다. 여기서는 정확 사후를 기준으로 계산 오차를 공부합니다.

Ut=μt−ms=v(1−ρ2)Ut+1=ρUt+sZt+1Zt+1∼N(0,1)∣ρ∣<1\begin{gathered}U_t=\mu_t-m\\s=\sqrt{v(1-\rho^2)}\\U_{t+1}=\rho U_t+sZ_{t+1}\\Z_{t+1}\sim N(0,1)\\|\rho|<1\end{gathered}

Uₜ는 μₜ를 사후 중심 m에서 뺀 값이고 s는 혁신 표준편차입니다. 기존 혁신의 시간 독립성과 과거로부터의 독립 조건은 그대로 필요합니다.

이론의 혁신 Z들은 시간에 걸쳐 iid 표준정규이며 다음 Z는 현재 상태와 독립이라고 가정합니다. 고정 시드 LCG와 역누적함수는 이 전이를 재현하는 수치 예시이지 난수가 실제로 독립이라는 수학적 보증은 아닙니다.

이 AR(1) 전이의 불변분포는 같은 N(m,v)입니다. ρ=0.2와 0.995를 비교하면 두 번째는 이전 상태를 훨씬 많이 기억합니다. 두 실험에는 같은 체인별 난수열을 사용해 차이를 비교하지만 서로 다른 체인 사이에는 별도 시드를 둡니다. 실제 임금의 시계열 자기상관을 ρ로 추정한 것이 아닙니다. ρ는 계산자가 정한 전이 규칙입니다.

4000개 보관 계산 상태의 진단 · 소수 반올림
전이 ρ계산 평균−정확 사후 평균rank/folded R̂관측 lag1정상상태 점근 ESS 참조
1/5-0.000122081.0004500.2101712,666.667
199/200-0.001906251.3171820.99084310.025

ESS 참조는 정상상태의 충분히 긴 독립 4체인에서 4000(1−ρ)/(1+ρ)로 얻는 이론값입니다. 지금 유한 비정상 시작 체인에서 추정한 bulk/tail ESS가 아닙니다. 코드에는 정상 시작을 가정한 유한길이 평균 분산도 별도로 계산합니다. 그것도 선택한 시작점에서 준비 구간 뒤의 실제 오차를 자동 보장하지 않습니다. 사후 SD는 모형의 μ 불확실성, 체인 평균 오차는 계산 불완전성이므로 단위가 같아도 서로 다릅니다.

먼저 생각한 뒤 풀이 보기: R̂가 1에 가까우면 모형도 현실에 맞고 계산도 완벽한가요?

둘 다 보장하지 않습니다. 네 체인을 반으로 나누고 합친 순위의 중간순위·정규 점수를 사용합니다. 중앙값에서 접은 값도 같은 진단을 한 뒤 큰 값을 보고합니다. 유한 체인이 함께 같은 영역에 갇히면 놓칠 수도 있습니다. 상수열이면 분산비가 미정의일 수 있어 1로 꾸미지 않습니다. 여기서는 정확 m을 알고 있으므로 실제 평균 계산 오차도 함께 확인할 수 있습니다.

고객 실무 사례 · 9개 계층 가설의 정확 답과 Metropolis 이동

UCI 실제 3150개 익명 고객에서 불만 있음은 241개 중 이탈 200개, 없음은 2909개 중 295개입니다. 수집 연도나 공개되지 않은 회사명을 만들어 내지 않습니다. 처음 9개월 특성과 12개월 결과의 시간 차이는 관측 설명이며 이탈에 대한 불만의 인과효과가 아닙니다. 이제 집단별 p_g를 공유 상위 모수에 연결하는 별도 베타 계층모형을 가정합니다.

ag=μκ,bg=(1−μ)κpg∣μ,κ∼Beta⁡(ag,bg)μ∈{1/4,1/2,3/4}κ∈{4,20,100}P(μ,κ)=1/9\begin{gathered}a_g=\mu\kappa,\qquad b_g=(1-\mu)\kappa\\p_g\mid\mu,\kappa\sim\operatorname{Beta}(a_g,b_g)\\\mu\in\{1/4,1/2,3/4\}\\\kappa\in\{4,20,100\}\\P(\mu,\kappa)=1/9\end{gathered}

하이퍼 노드 9개는 가설이지 실제 고객 유형 9개를 발견했다는 뜻이 아닙니다. 각 노드에서 p_g를 적분한 순서 있는 이진 자료의 주변우도는 집단별 B(a+s_g,b+n_g−s_g)/B(a,b)의 곱입니다. 같은 자료의 가설 비교에서는 이항 개수 계수가 공통이므로 정규화한 노드 질량은 같습니다. 노드 질량은 정확한 유리수로 정규화했고, 다음 표는 긴 값을 반올림한 것입니다.

가정한 노드의 정확 정규화 사후 질량 · 화면 소수 반올림
상위 μ집중도 κ사후 질량불만 집단 조건부 사후 평균
1/440.293717330.8204082
1/4200.000004240.7854406
1/41000.000000000.6598240
1/240.621399830.8244898
1/2200.000019590.8045977
1/21000.000000000.7331378
3/440.084859010.8285714
3/4200.000000000.8237548
3/41000.000000000.8064516

9개 사후 질량은 모두 양수입니다. 작은 값은 화면의 소수 여덟 자리 반올림 때문에 0.00000000처럼 보일 뿐 정확한 0이 아니며, 다운로드 CSV에는 작은 양의 질량을 지수 표기까지 보존합니다.

국소 제안은 0~8 순환 노드에서 이웃 ±1만 고르고, 전역 제안은 9개 중 균등하게 고릅니다. 두 제안이 대칭이므로 수락 확률은 min(1,새 사후질량/현 사후질량)입니다. 인위적 노드 순서에 따라 국소 전이의 장벽도 달라지며 다른 제안이면 제안확률 비율까지 필요할 수 있습니다. 두 알고리즘의 표적은 같아도 유한 실행 결과는 다를 수 있습니다.

두 제안의 유한 계산 결과 · 반올림, 미정의 진단 보존
제안정확 평균과의 차이rank/folded R̂상수 보관 체인 수
국소 순환-0.00016737미정의 / undefined4
전역 균등0.000083651.0130860

이번 국소 실행은 준비 구간 뒤 각 체인이 한 노드에 멈춰 보관값이 상수이며, 네 체인이 고른 노드가 전부 같지도 않습니다. 체인 내 분산이 0인 R̂ 비율을 1로 바꾸지 않고 미정의·실패 상태로 보고합니다. 그 합친 평균이 정확 평균과 우연히 가깝더라도 혼합 사후의 질량을 잘 탐색했다는 뜻은 아닙니다. 수락률 한 수치만으로 모드 탐색·추정량 정밀도를 판정하지 않습니다.

차트의 세로값은 노드에서 계산한 E[p_불만|노드,자료]입니다. 이것을 노드 체인에 따라 평균하는 Rao–Blackwell 계산은 전체 혼합 사후 평균 약 0.82363676을 목표로 합니다. 이 값들은 새 고객 결과도, p_불만 자체의 사후 추출값도 아닙니다. 조건부 평균만의 체인 분산을 전체 p 사후분산으로 읽으면 조건부 베타 변동을 빠뜨립니다. 별도 CSV에는 전체 혼합 분산까지 정확히 계산했습니다.

먼저 생각한 뒤 풀이 보기: 사후가 9칸이면 MCMC를 꼭 써야 하나요?

아닙니다. 여기서는 전수 계산이 더 직접적입니다. 정확 답이 있는 작은 문제에서 체인 이동·수락·초기값·R̂·평균 오차를 검토한 뒤 큰 문제로 넘어갑니다. 노드를 바꾸거나 모형 가정을 개선하는 것과 체인을 오래 돌려 계산 오차를 줄이는 것은 서로 다른 작업입니다. 네 체인이 비슷하다는 사실은 모형 예측의 교정이나 실제 고객 독립성의 증명이 아닙니다.

Country case · Solve a hierarchy first, then audit Gibbs computation

Use actual 2024 World Bank GDP per person for sixteen selected countries, divided by 10000. One x unit is 10,000 constant-2015 USD/person. There are eight countries in each period-life-expectancy group, at least 80 versus below 80 years; this is not individual lifespan prediction. The normal hierarchy below is a chosen working assumption, not a worldwide random-sample claim or a causal explanation of group differences.

xig∣θg∼N(θg,1)θg∣μ∼N(μ,1)μ∼N(3,4)\begin{gathered}x_{ig}\mid\theta_g\sim N(\theta_g,1)\\\theta_g\mid\mu\sim N(\mu,1)\\\mu\sim N(3,4)\end{gathered}

The joint model assumes observations conditionally independent given their θ values, and the two θ values conditionally independent given μ. This product structure yields Q and the Gibbs conditionals below; actual country independence has not been established.

The second argument of N denotes variance. Observation and between-group variances are both fixed at 1, not estimated from these records. Normal support includes negative GDP, another working-model limitation. Its value here is an exactly solvable computational reference. In coordinate order θ₁, θ₀, μ, form precision Q and linear term h; posterior mean is Q⁻¹h and covariance is Q⁻¹.

Q=(90−109−1−1−19/4)h=(∑g=1xi∑g=0xi3/4)E[ϑ∣x]=Q−1h\begin{gathered}Q=\begin{pmatrix}9&0&-1\\0&9&-1\\-1&-1&9/4\end{pmatrix}\\h=\begin{pmatrix}\sum_{g=1}x_i\\\sum_{g=0}x_i\\3/4\end{pmatrix}\\E[\vartheta\mid x]=Q^{-1}h\end{gathered}
Observed summaries and chosen-model exact posterior · rounded
ParameterSource recordsObserved meanPosterior meanPosterior SD
Life≥80 group θ₁84.7664334.5808810.342344
Life<80 group θ₀81.4536151.6361530.342344
Hyper-mean μ16Not applicable3.0964590.702247

One Gibbs sweep updates both θ values from the current μ, then updates μ from the new θ values. Their conditional variances are 1/9 and 4/9 respectively. Run four deliberately distinct starts for 1500 sweeps each, excluding the first 500 as warmup. The retained 4000 states are correlated computations targeting the chosen posterior, not newly observed countries. A warmup length of 500 is not a universal adequacy theorem.

Think first, then reveal: Does movement from observed group mean to posterior mean change actual GDP?

No. Source GDP remains unchanged. Given μ, E[θ_g|μ,x]=(sum x_g+μ)/9; averaging over posterior μ produces partial pooling. Its strength depends on chosen variances, prior and grouping. Verify Q Q⁻¹=I in the CSV before comparing chain averages with exact posterior means.

Person case · Why can the same posterior have a slow chain?

Among Card’s 3613 original records, 3010 available lwage76 values are source-trimmed logs of 1976 hourly wages in cents/hour. Preserve 603 missing values. Under chosen known observation variance 1/4 and prior μ~N(6,1/4), posterior mean is m=(observed log sum+6)/3011 and variance v=1/(4×3011). These assumptions do not establish actual iid sampling or the correctness of that variance. The exact posterior provides a computational reference.

Ut=μt−ms=v(1−ρ2)Ut+1=ρUt+sZt+1Zt+1∼N(0,1)∣ρ∣<1\begin{gathered}U_t=\mu_t-m\\s=\sqrt{v(1-\rho^2)}\\U_{t+1}=\rho U_t+sZ_{t+1}\\Z_{t+1}\sim N(0,1)\\|\rho|<1\end{gathered}

Uₜ is μₜ centered at posterior mean m; s is the innovation standard deviation. The existing time-independence and independence-from-the-past assumptions still apply.

The theoretical innovations Z are iid standard normal over time, with each next Z independent of the current state. A fixed-seed LCG plus inverse CDF is a reproducible numerical illustration of that transition, not a mathematical certification of truly independent random numbers.

This AR(1) transition has invariant distribution N(m,v) for both ρ=.2 and .995. The latter remembers its previous state much more strongly. Use common innovations across the two kernel settings, but separate chain seeds. These ρ values are chosen algorithm settings, not estimated temporal autocorrelation of actual wages.

Diagnostics of 4000 retained computational states · rounded
Kernel ρMC mean minus exact posterior meanRank/folded R̂Empirical lag1Stationary asymptotic ESS reference
1/5-0.000122081.0004500.2101712,666.667
199/200-0.001906251.3171820.99084310.025

The ESS reference is the stationary long-run formula 4000(1−ρ)/(1+ρ) for four independent chains. It is not an estimated bulk/tail ESS for these finite, nonstationary starts. A separate finite-length mean-variance reference also assumes stationary starts; it does not certify actual post-warmup error here. Posterior SD concerns model uncertainty about μ, while chain-mean error concerns incomplete computation, even though their units match.

Think first, then reveal: Does R̂ near 1 prove both computational perfection and model validity?

Neither is guaranteed. Split each chain, pool midranks, transform them to normal scores, and also diagnose absolute deviations from the pooled median; report the larger result. Finite chains can jointly miss regions. Constant draws may make the variance ratio undefined; do not replace that result with 1. Here the known exact m lets us also inspect actual mean computation error.

Customer-practice case · Nine exact hierarchy weights and Metropolis movement

Actual UCI records contain 200 churn events among 241 customers with complaints, versus 295 among 2909 without. Do not invent a collection year or undisclosed company name. First-nine-month attributes and month-12 outcomes describe observation timing, not the causal effect of complaints. Introduce a separate Beta hierarchy connecting group probabilities through shared hyperparameters.

ag=μκ,bg=(1−μ)κpg∣μ,κ∼Beta⁡(ag,bg)μ∈{1/4,1/2,3/4}κ∈{4,20,100}P(μ,κ)=1/9\begin{gathered}a_g=\mu\kappa,\qquad b_g=(1-\mu)\kappa\\p_g\mid\mu,\kappa\sim\operatorname{Beta}(a_g,b_g)\\\mu\in\{1/4,1/2,3/4\}\\\kappa\in\{4,20,100\}\\P(\mu,\kappa)=1/9\end{gathered}

The nine hypernodes are chosen hypotheses, not nine discovered customer types. Integrating out p_g gives ordered-data evidence as the product of B(a+s_g,b+n_g−s_g)/B(a,b) across groups. Binomial count coefficients would be common across hypotheses for the same data and cancel in normalized node weights. We normalize exact rational weights; the table rounds their displayed values.

Exactly normalized chosen-node posterior weights · rounded
Hyper-mean μConcentration κPosterior massConditional complaint-group posterior mean
1/440.293717330.8204082
1/4200.000004240.7854406
1/41000.000000000.6598240
1/240.621399830.8244898
1/2200.000019590.8045977
1/21000.000000000.7331378
3/440.084859010.8285714
3/4200.000000000.8237548
3/41000.000000000.8064516

All nine posterior masses are positive. Tiny values may display as 0.00000000 after rounding to eight decimal places, but are not exact zeros. The downloadable CSV preserves those small positive masses in scientific notation.

The local proposal moves ±1 around a cycle of nodes 0–8; the global proposal selects any node uniformly. Both are symmetric, so acceptance is min(1,new posterior weight/current weight). Artificial node ordering affects local barriers; other proposals may also require proposal-probability ratios. Both kernels target the same posterior while finite-run performance can differ.

Finite-run results for two proposals · rounded, undefined diagnostics preserved
ProposalError against exact meanRank/folded R̂Constant retained chains
Local cycle-0.00016737미정의 / undefined4
Global uniform0.000083651.0130860

In this local run, each retained chain stays at one node and is constant; the four chains do not all occupy the same node. Report the zero-within-variance R̂ ratio as undefined/failing rather than replacing it with 1. A pooled mean that happens to be close to the exact mean does not establish exploration of the posterior mass. Acceptance rate alone does not assess mode exploration or estimator precision.

The plotted quantity is E[p_complaint|node,data]. Averaging these conditional means along the hypernode chain is Rao–Blackwell computation targeting the full-mixture mean, approximately 0.82363676. These are neither new customer outcomes nor draws of p_complaint itself. Their variance omits conditional Beta variation and is not the full posterior variance of p. A separate CSV calculates that full mixture variance exactly.

Think first, then reveal: Is MCMC necessary for nine posterior cells?

No. Enumeration is more direct here. Use a small exact problem to audit movement, acceptance, starts, R̂ and mean error before tackling a large problem. Changing model assumptions differs from running longer to reduce computational error. Agreement among chains proves neither predictive calibration nor actual customer independence.

기초Foundations

48. 계층 도입·진단 원논문·계산 정의를 좁혀 읽는다48. Read hierarchical introductions, diagnostic research and calculation definitions

계층의 첫 대조는 Stan User’s Guide의 Hierarchical regression 첫 설명과 Hierarchical priors 도입입니다. 이 장은 분산을 고정한 작은 proper 정규 모형을 직접 풀었습니다. 일반 소프트웨어 예제의 암묵 사전이나 전체 모형을 그대로 채택한 것은 아닙니다.

진단은 Vehtari 등의 2021년 원논문 §3.1·§4.1–4.2와 식 14에서 분할·평균 동률 순위·접힘과 한계를 읽습니다. posterior의 rhat 설명과 연결하되, 유한 진단을 수렴 증명으로 읽지 않습니다. 알려진 AR(1) ESS 참조와 bulk·tail 추정의 정의도 나누어 봅니다.

재현 보고서에는 모형과 계산 커널을 따로 적고, 전이 보존·적용 이론·생성 경로·불확실성과 MC 오차를 구분하세요. 작은 정확 사후에서 검산한 뒤 더 복잡한 모형으로 확장하는 습관이 핵심입니다.

Python · R · 원자료·단위·가공·출처

Start with the opening hierarchical-regression and hierarchical-prior explanations in Stan’s guide. Our small known-variance proper Gaussian model is derived independently, not a wholesale adoption of software examples or implicit priors.

For diagnostics, read Vehtari et al.(2021), §3.1, §4.1–4.2 and equation 14, then posterior’s rhat documentation. Compare split chains, average tied ranks, folding and limitations. Keep theoretical AR(1) ESS separate from estimated bulk/tail ESS.

State model and computation kernel separately. Report invariance, theorem scope, generated paths, posterior uncertainty and MC error. Check small exact references before moving to harder models.

Python · R · Inputs, units, transformations and sources

Python·R 코드 실행 방법Run the Python/R companions

자료 묶음을 풀고 코드와 실제데이터 폴더를 함께 두세요. 터미널에서 코드 파일이 있는 폴더로 이동해 아래 명령을 실행합니다. 코딩이 처음이라면 손계산과 웹 실습을 먼저 하고, 데이터 사이언스 입문에서 코드를 배운 뒤 돌아와도 됩니다.Extract the bundle, keeping the scripts beside the data folder. In a terminal, enter the script folder and run the commands below. Beginners can complete hand calculations and browser labs first, returning to code after studying introductory data science.

python stat22-reproduce.py
Rscript --vanilla --encoding=UTF-8 stat22-reproduce.R

결과 파일은 각 코드에 지정된 결과 폴더에 저장됩니다. CSV 원자료는 덮어쓰지 않습니다.Result files are saved in the result directory specified by each script; the input CSVs are not overwritten.

영상·학자·함께 읽기Videos, thinkers and guided reading

본문의 질문을 넓히는 선택 학습입니다. 영상을 보기 전 질문을 먼저 읽고, 자신의 답을 쓴 뒤 해설과 비교하세요. 자료의 언어·선수 지식은 각 항목에 표시했습니다.Optional extensions to the chapter. Read the question first, write your answer, then compare with the explanation. Language and prerequisites are indicated below.

MIT · 생성 모형의 베이지안 계산MIT · Bayesian computation in generative models

MIT OCW · Luke Hewitt, November 13, 2018 tutorial

근사 사후 계산의 큰 지도를 본 뒤 이 장의 작은 정확 사후와 대조합니다. MCMC가 새로운 관측을 만들거나 가정의 타당성을 보증하는 도구인지 먼저 구분해 보세요.Use the overview of approximate Bayesian computation to situate these small exact references. Distinguish posterior computation from collecting observations or validating assumptions.

교재 안의 YouTube 플레이어에서 재생합니다. 원영상에서 제공하는 자막은 플레이어의 CC·설정에서 선택할 수 있습니다.Playback stays in this chapter’s YouTube player. Available captions can be selected through CC/settings.

보고 읽은 뒤 답하기Respond after watching/reading 정확 사후를 아는 예제에서 MCMC를 쓰는 학습 이유는?Why use MCMC when an exact posterior is available?

생각을 점검하는 해설Check your reasoning

알고리즘의 평균 오차·이동·진단을 정확 기준과 대조할 수 있기 때문입니다. 실제 분석에서 작은 정확 예제를 먼저 검사하는 습관으로 연결합니다.It permits direct checks of mean error, movement and diagnostics against a known reference before using harder models.

아키 베흐타리 · 베이지안 워크플로와 진단Aki Vehtari · Bayesian workflow and diagnostics

Aalto University · author profile

저자의 계산 베이지안 분석·모형 평가·진단 연구를 읽고, 사후 계산의 신뢰성과 모형의 적절성을 따로 평가하는 이유를 연결합니다.Read the author’s work on Bayesian computation, model assessment and diagnostics, linking computational reliability with separate assessment of model adequacy.

공식 자료 읽기 ↗Read official resource ↗

보고 읽은 뒤 답하기Respond after watching/reading 체인을 오래 돌리는 것만으로 잘못 고른 우도가 고쳐질까요?Will a longer chain repair a poorly chosen likelihood?

생각을 점검하는 해설Check your reasoning

아닙니다. 계산 오차와 모형 오차는 별도이며 자료·사전·우도·검증 질문을 다시 살펴야 합니다.No. Computational and model error are different; revisit data, priors, likelihood and validation questions.

Stan · 완전 풀링·비풀링·계층 연결Stan · Pooling and hierarchical connections

Stan User’s Guide · Hierarchical regression/prior introductions

Hierarchical regression의 첫 설명과 Hierarchical priors 도입을 읽습니다. 같은 상위 분포를 공유하는 것과 모든 집단 값을 같게 고정하는 것을 구별하고, 본문은 분산을 고정한 더 작은 가정 모형임을 확인합니다.Read the opening explanations of hierarchical regression and hierarchical priors. Sharing a higher-level distribution is not fixing all group parameters equal; this chapter uses a smaller hierarchy with chosen fixed variances.

공식 자료 읽기 ↗Read official resource ↗

보고 읽은 뒤 답하기Respond after watching/reading 계층모형이면 어떤 집단 구분도 자동으로 합리적일까요?Does hierarchy make any grouping automatically appropriate?

생각을 점검하는 해설Check your reasoning

아닙니다. 집단 정의·측정·사전·모형 점검이 필요하며 집단 간 인과 설명도 따로 필요합니다.No. Group definitions, measurement, priors and model checks still need justification, as do causal explanations.

원논문 · 순위·접힘을 이용한 R̂와 진단의 한계Original paper · Rank/folded R̂ and diagnostic limits

Vehtari, Gelman, Simpson, Carpenter and Bürkner · 2021

§3.1과 §4.1–4.2의 분할·중간순위·접힘을 읽고 식14의 정규 점수 변환을 코드와 대조합니다. 이 장은 bulk/tail ESS 추정기를 임의 대용하지 않고 AR(1)의 이론 참조를 따로 표시합니다.Read split-chain variance, midranks and folding in §3.1 and §4.1–4.2, checking equation 14 against code. This chapter labels theoretical AR(1) ESS references separately rather than presenting them as estimated bulk/tail ESS.

공식 자료 읽기 ↗Read official resource ↗

보고 읽은 뒤 답하기Respond after watching/reading 4000개 저장값이면 독립 표본4000개와 정보량이 같나요?Do 4000 stored states necessarily carry the information of 4000 independent draws?

생각을 점검하는 해설Check your reasoning

아닙니다. 상관·초기값·모드 누락이 계산 정밀도에 영향을 줍니다. 여러 진단과 정확 예제 점검을 함께 사용해도 유한 진단이 수렴 증명은 아닙니다.No. Dependence, starts and missed modes affect precision. Multiple diagnostics and exact-case checks help, but finite diagnostics are not proofs of convergence.

연습문제 · 계산에서 설명과 증명까지Exercises: calculation, explanation and proof

먼저 혼자 풀고 풀이를 여세요. 숫자와 함께 단위·포함 기준·계산 이유를 확인하세요.Attempt each problem before opening its solution. Check units, inclusion rules and the reason for the calculation.

1. 실제 관측과 계산 상태Observations versus computational states

실제 16국 자료에 사후 Gibbs 체인 4개를 각 1000개 보관했습니다. 국가 수·계산 수·사후 SD·평균 MCSE를 구별하세요.

Using sixteen actual countries, you retain four posterior Gibbs chains of 1000 states. Distinguish counts, posterior SD and mean MCSE.

풀이와 확인할 이유Solution and explanation

실제 국가는 16개이고 계산 상태는 4000개입니다. 사후 SD는 선택 모형에서 모수의 불확실성, MCSE는 그 사후 적분을 유한 경로로 근사하는 오차입니다. 저장 상태를 실제 국가로 세지 않으며 계산을 늘리는 것이 원자료를 늘리는 일도 아닙니다.

There are sixteen countries and 4000 computational states. Posterior SD describes parameter uncertainty under the model; MCSE describes numerical integration error. More stored states do not collect countries.

2. 계층의 조건부 독립Conditional independence in a hierarchy

θ₁, θ₂가 μ를 주면 독립 N(μ, τ²)이고 μ의 분산이 v₀>0입니다. 자료 관측 전 Cov(θ₁, θ₂)를 구하고 주변 독립인지 답하세요.

Given μ, let θ₁, θ₂ be independent N(μ, τ²), with Var(μ)=v₀>0. Before observing data, find Cov(θ₁, θ₂). Are they marginally independent?

풀이와 확인할 이유Solution and explanation

총공분산으로 E[Cov(θ₁, θ₂|μ)]+Cov(E[θ₁|μ], E[θ₂|μ])=0+v₀입니다. 따라서 양의 공분산이 남아 주변에서 독립이 아닙니다. 공유 μ를 적분하면 연결이 생깁니다.

Total covariance gives 0+Var(μ)=v₀. Positive covariance rules out marginal independence. Integrating the shared μ creates dependence.

3. 부분 풀링의 가중치A partial-pooling weight

정규 계층 모형에서 n=4, σ²=4, τ²=1, μ=3, 집단 평균 5입니다. θ의 조건부 사후 평균과 분산을 구하세요.

In the Gaussian hierarchical model, with n=4, σ²=4, τ²=1, μ=3 and group mean five, find the conditional posterior mean and variance of θ.

풀이와 확인할 이유Solution and explanation

데이터 정밀도 n/σ²=1, 사전 정밀도 1/τ²=1입니다. 평균은 (1×5+1×3)/2=4이고 분산은 1/2입니다. 이는 μ를 고정한 조건부 사후이며 μ의 불확실성까지 적분한 주변 분산은 아닙니다.

Data and prior precisions are both one. The mean is four and variance 1/2. These are conditional on μ, not the marginal variance after integrating its uncertainty.

4. 빈 집단의 평균 칸An empty group’s mean input

정규 계층에서 n₁=0, τ²>0이고 μ를 조건으로 줍니다. θ₁의 조건부 사후와 입력 평균의 역할은 무엇인가요?

In the Gaussian hierarchy, n₁=0, τ²>0 and μ is conditioned on. What is θ₁’s conditional posterior and the role of its mean input?

풀이와 확인할 이유Solution and explanation

집단 우도 항이 없으므로 θ₁|μ, y는 N(μ, τ²)입니다. 빈 집단 표본평균은 존재하지 않아 입력 칸은 사용하지 않습니다. 0을 관측 평균으로 추정한 것이 아니라 데이터 정밀도가 0인 것입니다.

With no group likelihood, it is N(μ, τ²). The sample mean does not exist and is unused. Zero data precision is not an estimated zero mean.

5. 정밀도 교차항의 부호The sign of a precision cross term

집단 사전 항 −(θ₁−μ)²/(2τ²)을 전개하세요. −θᵀQθ/2 표기에서 Q₁μ의 부호는 무엇인가요?

Expand −(θ₁−μ)²/(2τ²). In −θᵀQθ/2, what is Q₁μ?

풀이와 확인할 이유Solution and explanation

전개하면 −θ₁²/(2τ²)+θ₁μ/τ²−μ²/(2τ²)입니다. 대칭 Q의 교차항은 −Q₁μ θ₁μ이므로 Q₁μ=−1/τ²입니다. 공분산의 교차항 부호와 정밀도의 부호를 혼동하지 않습니다.

The expansion gives −θ₁²/(2τ²)+θ₁μ/τ²−μ²/(2τ²). The precision cross term is −Q₁μθ₁μ, so Q₁μ=−1/τ².

6. 빈 두 집단에도 proper인 이유Why two empty groups can still have a proper law

n₁=n₂=0, τ²>0, v₀>0의 정규 계층에서 Q의 이차형식 t(a−c)²+t(b−c)²+rc²를 사용해 정부호성을 확인하세요.

For n₁=n₂=0, τ², v₀>0, use t(a−c)²+t(b−c)²+rc² to verify positive precision.

풀이와 확인할 이유Solution and explanation

t, r가 양수라 각 항이 음수가 아닙니다. 합이 0이면 c=0이고 a=c, b=c라 모두 0입니다. 따라서 비영 벡터에는 양수이고 proper 공동 정규 사전·사후가 존재합니다. 우도 정보가 없다는 것과 분포가 미정의인 것은 다릅니다.

All terms are nonnegative. Zero forces c=0, then a=b=0. Thus every nonzero vector gives a positive value. No likelihood information is different from an undefined proper prior/posterior.

7. 작은 공동 사후의 정확 평균An exact small posterior mean

n₁=n₂=1, σ²=τ²=v₀=1, m₀=0, 집단 평균 (2, 0)입니다. Q=[[2, 0, −1], [0, 2, −1], [−1, −1, 3]], h=(2, 0, 0)에서 사후 평균을 구하세요.

For n₁=n₂=1, σ²=τ²=v₀=1, m₀=0 and group means (2, 0), solve Qm=h with Q=[[2, 0, −1], [0, 2, −1], [−1, −1, 3]], h=(2, 0, 0).

풀이와 확인할 이유Solution and explanation

첫 두 식은 θ₁=(2+μ)/2, θ₂=μ/2입니다. 마지막 식 −θ₁−θ₂+3μ=0에 대입하면 μ=1/2입니다. 따라서 평균은 (5/4, 1/4, 1/2)입니다. 두 집단 값이 동일하게 고정된 것은 아니지만 상위 평균으로 서로 연결됩니다.

The first equations give m₁=(2+mμ)/2, m₂=mμ/2. Substitution into the last yields mμ=1/2, hence mean (5/4, 1/4, 1/2). Partial pooling does not fix the groups equal.

8. 작은 사후 공분산과 조건부 분산Marginal versus conditional posterior variance

Q=[[2, 0, −1], [0, 2, −1], [−1, −1, 3]]에서 Q⁻¹=[[5/8, 1/8, 1/4], [1/8, 5/8, 1/4], [1/4, 1/4, 1/2]]입니다. θ₁의 주변 분산과 μ를 고정한 조건부 분산을 비교하세요.

Given Q=[[2, 0, −1], [0, 2, −1], [−1, −1, 3]], its inverse has diagonal (5/8, 5/8, 1/2) and off-diagonals (1/8, 1/4, 1/4). Compare θ₁’s marginal variance with its variance given μ.

풀이와 확인할 이유Solution and explanation

주변 분산은 대각 5/8입니다. μ를 고정하면 θ₁ 조건부 정밀도는 Q₁₁=2라 조건부 분산은 1/2입니다. 차이 1/8은 μ를 통한 변동이며, 공동 공분산 대각을 조건부 분산으로 복사하면 안 됩니다.

The marginal variance is 5/8. Conditional precision is Q₁₁=2, giving variance 1/2. The extra 1/8 comes through uncertain μ. Do not copy marginal diagonals into conditional distributions.

9. 전이표의 행 읽기Read transition rows

P=[[0.8, 0.2], [0.3, 0.7]]입니다. 상태 1에서 다음이 0일 확률과, 초기 상태 0에서 경로 0→1→0의 확률을 구하세요.

For P=[[.8, .2], [.3, .7]], find the 1-to 0 probability and probability of path 0→1→0 from state zero.

풀이와 확인할 이유Solution and explanation

첫 확률은 P₁₀=0.3입니다. 시간동질 마르코프 전이에서 해당 경로 확률은 P₀₁P₁₀=0.2×0.3=0.06입니다. 연속한 상태가 독립이라서 곱한 것이 아니라 조건부 경로 분해를 사용했습니다.

The first is .3. The path probability is .2×.3=.06 under the homogeneous Markov law. This uses conditional path factorization, not independence of successive states.

10. 한 번·두 번의 주변분포One and two marginal steps

P=[[4/5, 1/5], [3/10, 7/10]], p₀=(1, 0)입니다. p₁, p₂를 계산하세요.

For P=[[4/5, 1/5], [3/10, 7/10]] and p₀=(1, 0), compute p₁, p₂.

풀이와 확인할 이유Solution and explanation

p₁=(4/5, 1/5)입니다. p₂의 첫 성분은 (4/5)²+(1/5)(3/10)=7/10, 둘째는 3/10입니다. 이는 법칙의 이동이며 한 경로가 두 상태를 동시에 갖는다는 뜻이 아닙니다.

p₁=(4/5, 1/5). The next first probability is 16/25+3/50=7/10, so p₂=(7/10, 3/10). These are laws, not one path simultaneously occupying both states.

11. 두 상태 불변분포A two-state invariant law

P=[[1−a, a], [b, 1−b]], 0≤a, b≤1, a+b>0입니다. 불변분포를 풀고 a=1/5, b=3/10을 대입하세요.

For P=[[1−a, a], [b, 1−b]], 0≤a, b≤1, a+b>0, solve for the invariant law and substitute a=1/5, b=3/10.

풀이와 확인할 이유Solution and explanation

정상 흐름 식 π₀a=π₁b와 합 1을 풀면 π=(b/(a+b), a/(a+b))입니다. 대입하면 (3/5, 2/5)입니다. πP를 직접 곱해 같은 값인지 확인할 수 있습니다.

Use π₀a=π₁b and sum one to obtain (b/(a+b), a/(a+b)). The chosen values give (3/5, 2/5).

12. 상세균형의 합 지표The summation index in detailed balance

모든 i, j에서 πiPij=πjPji이고 P는 행확률 전이표입니다. 상태 j로 들어오는 흐름을 합쳐 πP=π를 증명하세요.

For pairwise detailed balance and a row-stochastic P, sum flows into fixed state j to prove invariance.

풀이와 확인할 이유Solution and explanation

j를 고정하고 i를 합합니다. 우변의 ΣiPji는 j번째 행의 합이라 1입니다.

∑iπiPij=πj∑iPji=πj.\sum_i\pi_iP_{ij}=\pi_j\sum_iP_{ji}=\pi_j.

Fix j and sum over i. The right-hand sum is row j’s sum, one.

∑iπiPij=πj∑iPji=πj.\sum_i\pi_iP_{ij}=\pi_j\sum_iP_{ji}=\pi_j.

13. 상세균형이 필요조건은 아니다Detailed balance is not necessary

세 상태가 0→1→2→0으로 결정적으로 움직입니다. 균등 π의 불변성과 상세균형을 각각 확인하세요.

A deterministic three-cycle moves 0→1→2→0. Check uniform invariance and detailed balance.

풀이와 확인할 이유Solution and explanation

순환은 균등 질량을 다른 칸으로 옮길 뿐이라 πP=π입니다. 그러나 π₀P₀₁=1/3이고 π₁P₁₀=0이라 상세균형은 실패합니다. 불변성과 가역성을 같은 조건으로 부르지 않습니다.

The cycle permutes equal masses, so uniform π is invariant. But flow 0-to 1 is 1/3 and reverse flow zero, violating detailed balance.

14. 유일하지만 주기적인 불변법칙Unique but periodic

P=[[0, 1], [1, 0]], p₀=(1, 0)입니다. π·주기·pₜ의 극한을 구하세요.

For P=[[0, 1], [1, 0]] and p₀=(1, 0), find the invariant law, period and marginal limit.

풀이와 확인할 이유Solution and explanation

유일 불변분포는 (1/2, 1/2), 주기는 2입니다. 짝수 t에는 (1, 0), 홀수에는 (0, 1)이라 주변법칙은 수렴하지 않습니다. π에서 시작하면 처음부터 π라는 사실과 모순되지 않습니다.

The unique invariant law is (.5, .5), period two. Marginals alternate and have no limit from this start. Stationary initialization would be a different statement.

15. 가약이지만 유일한 흡수 목표Reducible with a unique absorbing target

a=0, b=1/2의 두 상태 전이에서 p₀=(0, 1)입니다. t번 뒤 상태 1 확률과 유일 불변분포를 구하세요.

For two-state a=0, b=1/2 and p₀=(0, 1), find P(Xₜ=1) and the unique invariant law.

풀이와 확인할 이유Solution and explanation

상태 1에 남으려면 매번 확률 1/2의 머무름을 이어야 하므로 pₜ, ₁=2⁻ᵗ입니다. 상태 0은 흡수라 불변분포는 유일하게 (1, 0)이고 거기로 수렴합니다. 가약과 비유일은 같은 뜻이 아닙니다.

The remaining mass is 2⁻ᵗ. State zero is absorbing, and the unique invariant law is (1, 0). Reducibility does not imply nonuniqueness.

16. 항등 전이의 목표 모호함An identity kernel does not select a target

P=I₂에서 선택한 π=(1/2, 1/2)와 초기 p₀=(1, 0)가 있습니다. π가 불변이면 pₜ→π인가요?

For P=I₂, selected π=(.5, .5) and p₀=(1, 0), does π’s invariance imply pₜ→π?

풀이와 확인할 이유Solution and explanation

아닙니다. 모든 분포가 불변이고 pₜ는 (1, 0) 그대로입니다. π는 하나의 불변 예이지만 그 연쇄가 특정 π를 선택해 주지 않습니다. 초기분포에 따른 불변성과 유일 목표 수렴을 구별합니다.

No. Every law is invariant and pₜ remains (1, 0). The selected π is one invariant example, not a uniquely selected limit.

17. 불가약은 모든 한 걸음이 양수라는 뜻일까Does irreducible require all one-step entries positive?

세 상태 순환에서 P₀₂=0입니다. 그래도 불가약인 이유와 lazy 순환의 주기를 설명하세요.

The directed three-cycle has P₀₂=0. Why is it irreducible, and what is the period after adding positive self-holding?

풀이와 확인할 이유Solution and explanation

0에서 2로는 두 걸음 0→1→2로 도달합니다. 모든 상태쌍에 유한 양의 확률 경로가 있어 불가약입니다. 순환에 양의 자기 유지를 섞으면 귀환 시간 1을 갖는 상태가 생겨 불가약 전체의 주기는 1입니다.

State two is reachable from zero in two steps. Every pair has a finite positive path. Positive self-holding gives return time one, so the irreducible lazy chain is aperiodic.

18. 주변 진동과 경로 평균Oscillating marginals and path averages

0, 1을 번갈아 방문하는 두 상태 연쇄에서 f(x)=x의 길이 T 경로 평균과 극한을 구하세요.

For a chain alternating 0 and 1 and f(x)=x, find its length-T average and limit.

풀이와 확인할 이유Solution and explanation

두 방문 수는 많아야 1개 차이라 평균은 T가 짝수면 1/2, 홀수면 시작에 따라 (T±1)/(2T)입니다. 따라서 평균은 1/2로 갑니다. 시점별 주변분포가 진동해도 경로 평균 법칙은 성립할 수 있습니다.

Visit counts differ by at most one. The average is 1/2 for even T and (T±1)/(2T) for odd T, so it tends to 1/2 despite oscillating marginals.

19. 느린 두 상태 혼합Slow mixing in two states

a=b=0.0001, p₀=(1, 0)입니다. 고유값 1−a−b를 이용한 pₜ의 첫 성분과 균등 π까지의 전체 변동거리를 쓰세요.

Let a=b=.0001, p₀=(1, 0). Use eigenvalue 1−a−b to give P(Xₜ=0) and total variation to uniform π.

풀이와 확인할 이유Solution and explanation

비정상 성분은 (1−a−b)ᵗ=0.9998ᵗ로 줄어듭니다. pₜ, ₀=1/2+(1/2)0.9998ᵗ이고 TV=(1/2)0.9998ᵗ입니다. 불가약·비주기여도 고정된 짧은 계산이 충분하다고 할 수 없습니다.

The nonstationary component shrinks as.9998ᵗ. Thus P(Xₜ=0)=.5+.5(.9998ᵗ), and TV=.5(.9998ᵗ). Irreducibility/aperiodicity do not guarantee an arbitrary short run is enough.

20. 불변성만 계산한 검산What does an invariance check establish?

한 전이표에서 πP=π를 정확히 확인했습니다. 이것만으로 초기 상태와 무관한 수렴·독립 저장값·유한 MCSE 보장이 모두 나오나요?

You verify πP=π exactly. Does that alone establish convergence from every start, independent stored values and finite MCSE guarantees?

풀이와 확인할 이유Solution and explanation

아닙니다. 도달 가능성·주기·적용 가능한 평균 법칙·정상성·모멘트와 공분산 통제 등을 따로 확인합니다. 항등이나 주기 연쇄가 불변성만으로 부족한 예입니다. 독립성은 불변성의 결론도 아닙니다.

No. Reachability, periodicity, average-law conditions, stationarity, moments and covariance control are separate. Identity/periodic examples demonstrate the gap, and invariance does not imply independence.

21. 비대칭 제안의 수락비Acceptance with an asymmetric proposal

목표 가중치 w=(1, 4, 1), 제안 Q=[[1/2, 1/2, 0], [1/4, 1/2, 1/4], [0, 1/2, 1/2]]입니다. MH의 α₀₁과 α₁₀을 구하세요.

For target weights w=(1, 4, 1) and Q=[[1/2, 1/2, 0], [1/4, 1/2, 1/4], [0, 1/2, 1/2]], find MH acceptances α₀₁ and α₁₀.

풀이와 확인할 이유Solution and explanation

목표 질량의 정규화 상수는 비에서 소거됩니다. 제안의 역방향 확률도 넣어야 합니다.

α01=min⁡ ⁣(1,4(1/4)1(1/2))=1,α10=min⁡ ⁣(1,1(1/2)4(1/4))=12.\begin{aligned} \alpha_{01}&=\min\!\left(1,\frac{4(1/4)}{1(1/2)}\right)=1,\\ \alpha_{10}&=\min\!\left(1,\frac{1(1/2)}{4(1/4)}\right)=\frac12. \end{aligned}

가중치 비만 쓴 α₁₀=1/4는 이 비대칭 제안에서 틀립니다.

The target normalizer cancels, but the reverse proposal does not.

α01=min⁡ ⁣(1,4(1/4)1(1/2))=1,α10=min⁡ ⁣(1,1(1/2)4(1/4))=12.\begin{aligned} \alpha_{01}&=\min\!\left(1,\frac{4(1/4)}{1(1/2)}\right)=1,\\ \alpha_{10}&=\min\!\left(1,\frac{1(1/2)}{4(1/4)}\right)=\frac12. \end{aligned}

Using only the target ratio would incorrectly give α₁₀=1/4.

22. 거절이 대각 칸에 더해진다Rejections add to the diagonal

w=(1, 4, 1)과 Q=[[1/2, 1/2, 0], [1/4, 1/2, 1/4], [0, 1/2, 1/2]]인 MH에서 가운데 상태 1의 P₁₀, P₁₂, P₁₁을 구하세요.

For MH with w=(1, 4, 1) and Q=[[1/2, 1/2, 0], [1/4, 1/2, 1/4], [0, 1/2, 1/2]], find P₁₀, P₁₂, P₁₁.

풀이와 확인할 이유Solution and explanation

두 바깥 제안은 각각 수락확률 1/2이므로 P₁₀=P₁₂=(1/4)(1/2)=1/8입니다. 행합이 1이어야 하므로 P₁₁=3/4입니다. 이는 Q₁₁=1/2에 바깥 제안 거절확률 1/4이 더해진 값입니다. πᵢPᵢⱼ=min(πᵢQᵢⱼ, πⱼQⱼᵢ)는 서로 다른 상태의 흐름 식이며 대각에 그대로 대입하지 않습니다.

Each outward proposal accepts with probability 1/2, so both off-diagonals are 1/8. The diagonal is 1−1/8−1/8=3/4, including rejected outward proposals. It exceeds Q₁₁=1/2. The minimum-flow identity applies to distinct states, not generally to diagonal entries.

23. MH의 불변 흐름을 손으로 검산Check an MH invariant flow by hand

π=(1/6, 4/6, 1/6), P=[[1/2, 1/2, 0], [1/8, 3/4, 1/8], [0, 1/2, 1/2]]입니다. 0↔1의 흐름과 (πP)₁을 계산하세요.

For π=(1/6, 4/6, 1/6) and P=[[1/2, 1/2, 0], [1/8, 3/4, 1/8], [0, 1/2, 1/2]], compute the 0↔1 flows and (πP)₁.

풀이와 확인할 이유Solution and explanation

양방향 흐름은 각각 (1/6)(1/2)=(4/6)(1/8)=1/12입니다. 가운데 유입은 1/12+1/2+1/12=2/3=π₁입니다. 나머지 상태도 같은 방식으로 검산할 수 있습니다. 이 보존 확인 자체는 짧은 경로의 정확한 평균을 보장하지 않습니다.

Both flows are 1/12. Inflow to state one is 1/12+1/2+1/12=2/3=π₁. This checks preservation, not the accuracy of an arbitrary short-run average.

24. 영확률 제안과 정확한 수락 경계An impossible proposal and an acceptance boundary

MH에서 Q₀₂=0입니다. 사용자가 0→2를 선택할 때 조건부 수락확률을 0으로 추정해야 할까요? 별도로 가능한 제안의 α=1/2, u=1/2라면 u<α 규칙의 결과는?

In MH, Q₀₂=0. Should selecting 0→2 estimate its conditional acceptance as zero? Separately, what happens for a possible proposal with α=1/2, u=1/2 under u<α?

풀이와 확인할 이유Solution and explanation

Q₀₂=0인 제안은 그 상태에서 일어나지 않으므로 실제 조건부 수락비는 미정의로 표시합니다. 전이 P₀₂=0과 수락비 미정의를 나누어 읽습니다. 가능한 제안에서 u=α이면 엄격 부등식 u<α가 거짓이므로 거절합니다. 연속 균등 난수에서 경계 한 점은 확률 0이지만 선택 probe의 규칙은 명확해야 합니다.

The zero-probability proposal has no uniquely defined conditional acceptance ratio here; display it as undefined. Its transition probability is zero. For a possible proposal, u=α fails the strict test and is rejected. The boundary has zero probability under a continuous uniform draw, but a selected probe still needs an explicit rule.

25. 제안은 순환해도 MH는 갇힐 수 있다A cycling proposal can yield a trapped MH chain

세 상태 목표 π가 모두 양수이고, Q는 결정적 0→1→2→0 제안입니다. MH 전이와 그 불변성을 설명하세요.

The target is positive on three states and Q proposes the deterministic cycle 0→1→2→0. Describe the MH kernel and its invariance.

풀이와 확인할 이유Solution and explanation

모든 비대각 제안의 역방향 Qⱼᵢ가 0이라 수락확률이 0입니다. 따라서 P=I₃입니다. 어떤 π라도 불변이지만 시작 상태를 떠나지 않습니다. 제안 그래프의 도달 가능성만으로 실제 수락 뒤 연쇄의 불가약성을 대신할 수 없습니다.

Every reverse proposal probability is zero, so all off-diagonal proposals are rejected and P=I₃. The target is invariant, but the chain never leaves its start. Proposal reachability does not replace reachability of the accepted kernel.

26. 상수배 목표를 써도 되는 이유Why a common target multiplier is harmless

MH의 양의 목표 가중치 wᵢ를 공통 c>0배로 바꾸었습니다. 수락확률이 바뀌나요? 서로 다른 cᵢ를 각 상태에 곱하면 어떤가요?

Multiply every positive MH target weight by the same c>0. Does acceptance change? What if multipliers cᵢ differ by state?

풀이와 확인할 이유Solution and explanation

공통 c는 목표 비의 분자·분모에서 소거되어 같은 수락과 전이가 됩니다. 상태별 cᵢ는 일반적으로 비를 바꿔 다른 목표를 만듭니다. 정규화 상수를 몰라도 된다는 사실이 상대 가중치를 마음대로 바꿔도 된다는 뜻은 아닙니다.

A common c cancels from the ratio, leaving the same kernel. State-dependent multipliers generally change relative weights and hence the target. An unknown normalizer is harmless; arbitrary relative reweighting is not.

27. 정규 전조건부를 제곱완성Complete the square for a Gaussian full conditional

정규 계층에서 n₁=1, σ²=τ²=1, 집단 평균 2이고 μ를 조건으로 줍니다. θ₁의 전조건부를 유도하세요.

In the Gaussian hierarchy, n₁=1, σ²=τ²=1, the group mean is two, and μ is conditioned on. Derive θ₁’s full conditional.

풀이와 확인할 이유Solution and explanation

θ₁에 관련한 로그 항은 −[(2−θ₁)²+(θ₁−μ)²]/2입니다. θ₁의 이차계수는 2, 선형항은 2+μ입니다.

m1=(2+μ)/2,θ1∣μ,y∼N ⁣(m1,12).\begin{aligned} m_1&=(2+\mu)/2,\\ \theta_1\mid\mu,y&\sim N\!\left(m_1,\frac12\right). \end{aligned}

다른 집단 θ₂는 μ를 주면 이 식에 직접 들어가지 않습니다. μ를 갱신할 때 두 집단의 정보가 다시 연결됩니다.

Its log terms are −[(2−θ₁)²+(θ₁−μ)²]/2. The precision is two and linear coefficient 2+μ.

θ1∣μ,y∼N ⁣(2+μ2,12).\theta_1\mid\mu,y\sim N\!\left(\frac{2+\mu}{2},\frac12\right).

The other group does not enter directly given μ; updating μ reconnects their information.

28. 한 Gibbs sweep는 공동 평균과 다르다One Gibbs sweep is not the joint posterior mean

작은 정규 계층의 전조건부가 θ₁~N((2+μ)/2, 1/2), θ₂~N(μ/2, 1/2), μ~N((θ₁+θ₂)/3, 1/3)입니다. (0, 0, 0)에서 순서대로 각 정규 probe z=0을 선택한 한 sweep 결과는?

Use full conditionals θ₁~N((2+μ)/2, 1/2), θ₂~N(μ/2, 1/2), μ~N((θ₁+θ₂)/3, 1/3). Starting at (0, 0, 0), select z=0 at each update in this order. What is one sweep?

풀이와 확인할 이유Solution and explanation

먼저 θ₁=1, 다음 θ₂=0, 마지막에는 갱신한 θ₁을 사용하여 μ=1/3입니다. 따라서 (1, 0, 1/3)입니다. 공동 사후 평균 (5/4, 1/4, 1/2)와 다릅니다. probe 0은 전조건부 평균을 선택한 수치 실험이며 무작위 사후 표본도, 한 번에 사후를 정확히 그린 것도 아닙니다.

Updates give θ₁=1, θ₂=0, then μ=1/3 using the fresh first coordinate. The result (1, 0, 1/3) differs from the joint posterior mean (5/4, 1/4, 1/2). Zero probes select conditional means; they are neither random posterior draws nor one exact joint draw.

29. 전조건부 갱신이 목표를 보존한다A full-conditional update preserves the target

공동 밀도 π(x, y)가 있고, x|y를 π의 전조건부에서 새로 그리며 y는 유지합니다. 원 상태가 π이면 새 상태도 π임을 적분으로 보이세요.

Let π(x, y) be a joint density. Replace x by a draw from its π full conditional given y, keeping y. Prove preservation when the old state has law π.

풀이와 확인할 이유Solution and explanation

기존 x를 적분하면 πY(y)가 남습니다. 새 x의 조건부를 곱하면 공동 목표가 복원됩니다.

πnew(x′,y)=[∫π(x,y) dx]π(x′∣y)=πY(y)π(x′∣y)=π(x′,y).\begin{aligned} \pi_{\rm new}(x',y) &=\left[\int\pi(x,y)\,dx\right]\pi(x'\mid y)\\ &=\pi_Y(y)\pi(x'\mid y)=\pi(x',y). \end{aligned}

조건부는 적절한 버전을 쓰며 목표가 실제 확률분포여야 합니다. 임의로 만든 조건부 식들이 항상 같은 공동분포를 갖는다는 주장은 아닙니다.

Integrate out the old x, then multiply the conditional density.

πnew(x′,y)=[∫π(x,y) dx]π(x′∣y)=πY(y)π(x′∣y)=π(x′,y).\begin{aligned} \pi_{\rm new}(x',y) &=\left[\int\pi(x,y)\,dx\right]\pi(x'\mid y)\\ &=\pi_Y(y)\pi(x'\mid y)=\pi(x',y). \end{aligned}

This uses compatible conditionals of a proper joint law and appropriate versions. Arbitrarily chosen conditional formulas need not specify that same joint law.

30. 순서 합성은 불변이지만 꼭 가역은 아니다A composition is invariant but need not be reversible

각 전이 K₁, K₂가 π를 보존합니다. K₁ 뒤 K₂를 적용한 전이도 보존함을 쓰고, 상세균형까지 자동인지 답하세요.

Each kernel K₁, K₂ preserves π. Show that applying K₁ then K₂ preserves π. Is detailed balance automatic?

풀이와 확인할 이유Solution and explanation

행법칙 표기로 πK₁K₂=(πK₁)K₂=πK₂=π입니다. 따라서 여러 좌표의 systematic Gibbs sweep도 각 단계가 목표를 보존하면 목표를 보존합니다. 그러나 가역 연산자의 곱이 순서를 바꾸어도 같다는 보장은 없으므로 전체 sweep의 상세균형은 자동 결론이 아닙니다. 불변성과 가역성을 다시 나눕니다.

πK₁K₂=(πK₁) K₂=πK₂=π. This proves invariance of a systematic Gibbs sweep. Reversible operators need not commute, so their composition need not be reversible. Invariance and detailed balance remain distinct.

31. 평균 주변값만 넣은 예측 분산A plug-in predictive variance misses parameter uncertainty

정규 계층에서 θ₁|자료의 평균 5/4, 분산 5/8이고 새 관측은 θ₁를 주면 기존 자료와 독립 N(θ₁, 1)입니다. 사후예측 평균·분산과 plug-in 분산을 비교하세요.

The posterior of θ₁ has mean 5/4, variance 5/8. Given θ₁, a new observation is N(θ₁, 1), independent of past data. Find predictive moments and compare a plug-in variance.

풀이와 확인할 이유Solution and explanation

총기대값으로 예측 평균은 5/4입니다. 총분산으로 1+5/8=13/8입니다. θ₁를 사후 평균에 고정한 plug-in은 관측 분산 1만 남겨 모수 불확실성을 빠뜨립니다. 이 값들은 선택 정규 모형의 예측이며 실제 외부 집단 타당성은 별도입니다.

The predictive mean is 5/4. Total variance gives 1+5/8=13/8. Fixing θ₁ at its posterior mean leaves only variance one, omitting parameter uncertainty. These are predictions under the chosen Gaussian model.

32. 상관된 평균의 정확 분산Derive the exact variance of a correlated average

정상 체인 Y₁, …, Y_T에서 Var(Yt)=v이고 Cov(Yt, Yt+h)=γh입니다. 평균 분산을 모든 쌍의 합에서 유도하세요.

For a stationary chain with Var(Yt)=v and Cov(Yt, Yt+h)=γh, derive the variance of its length-T mean.

풀이와 확인할 이유Solution and explanation

대각항 T개와 각 거리 h의 두 방향 T−h개를 묶습니다.

Var⁡(YˉT)=1T2∑s,t=1TCov⁡(Ys,Yt)=Tv+2∑h=1T−1(T−h)γhT2.\begin{aligned} \operatorname{Var}(\bar Y_T) &=\frac{1}{T^2}\sum_{s,t=1}^T\operatorname{Cov}(Y_s,Y_t)\\ &=\frac{Tv+2\sum_{h=1}^{T-1}(T-h)\gamma_h}{T^2}. \end{aligned}

정상성은 공분산을 시차만의 함수로 쓰게 합니다. 정상성이 없는 시작에서 같은 공식을 근거 없이 적용하지 않습니다.

There are T diagonal terms and twice T−h pairs at each lag.

Var⁡(YˉT)=1T2∑s,t=1TCov⁡(Ys,Yt)=Tv+2∑h=1T−1(T−h)γhT2.\begin{aligned} \operatorname{Var}(\bar Y_T) &=\frac{1}{T^2}\sum_{s,t=1}^T\operatorname{Cov}(Y_s,Y_t)\\ &=\frac{Tv+2\sum_{h=1}^{T-1}(T-h)\gamma_h}{T^2}. \end{aligned}

Stationarity permits lag-only covariances. A nonstationary start requires separate treatment.

33. 네 체인을 한 긴 체인으로 붙이면 안 되는 이유Why four chains are not one concatenated long chain

독립인 정상 AR(1) 체인이 M=4개, 각 T=2개이며 v=1, ρ=1/2입니다. 모든 8개 값의 평균 분산을 구하세요.

There are M=4 independent stationary AR(1) chains, each T=2, with v=1, ρ=1/2. Find the variance of the mean of all eight values.

풀이와 확인할 이유Solution and explanation

한 체인의 길이 2 평균 분산은 (2+2ρ)/4=3/4입니다. 네 독립 체인 평균을 다시 평균하므로 4로 나누어 3/16입니다. 체인 경계의 값들은 독립이라 한 길이 8 AR 경로로 붙인 시차 공분산을 넣지 않습니다.

Each chain mean has variance (2+2ρ)/4=3/4. Averaging four independent chain means gives 3/16. Cross-chain boundaries do not carry the lag covariance of a single length-eight AR path.

34. 양·음 상관과 이론 ESSPositive/negative correlation and theoretical ESS

양의 유한 주변분산을 갖는 정상 AR(1)에서 |ρ|<1이고 충분히 긴 총 저장 수를 S라 합시다. ρ=1/5와 ρ=−1/2의 τint와 점근 ESS 참조를 구하세요.

For stationary AR(1) with positive finite marginal variance, |ρ|<1 and a long total draw count S, find integrated autocorrelation time and asymptotic ESS references for ρ=1/5 and −1/2.

풀이와 확인할 이유Solution and explanation

기하급수 합으로 τint=1+2Σh≥1ρʰ=(1+ρ)/(1−ρ)입니다. ρ=1/5이면 τint=3/2, ESS≈2S/3입니다. ρ=−1/2이면 τint=1/3, ESS≈3S입니다. 음의 상관으로 평균 분산이 줄 수 있어 이론 ESS가 저장 수보다 커도 모순이 아닙니다. 이는 알려진 모형의 점근 분산 참조이며 실제 경로의 bulk·tail ESS 추정이 아닙니다.

The geometric sum gives τint=(1+ρ)/(1−ρ). It is 3/2 at ρ=1/5, so ESS≈2S/3; it is 1/3 at ρ=−1/2, so ESS≈3S. Negative correlation may reduce mean variance below an iid reference. These are known-model asymptotic references, not estimated bulk/tail ESS from observed paths.

35. 사후 SD와 계산 MCSE는 서로 다른 불확실성이다Posterior SD and mean MCSE measure different objects

모수 θ의 사후 SD가 2이고, 독립 사후 추출 S=400개 평균으로 E[θ|자료]를 근사합니다. 이 이상적 모형의 MCSE와, 계산을 1600개로 늘릴 때 바뀌는 것을 설명하세요.

A parameter has posterior SD two. Approximate its posterior mean with S=400 independent posterior draws. Find this idealized MCSE and explain increasing S to 1600.

풀이와 확인할 이유Solution and explanation

독립 추출 평균의 MCSE는 2/√400=0.1입니다. 1600개에서는 0.05로 줄지만 목표 사후 SD 2는 계산 횟수 때문에 줄지 않습니다. 두 값의 물리 단위는 θ와 같지만, 사후 분포의 폭과 그 평균을 근사한 계산 오차라는 대상이 다릅니다. 실제 MCMC에는 상관을 반영해야 합니다.

MCSE is 2/√400=.1; at 1600 it is.05. The target posterior SD remains two. Both use θ’s units, but one describes posterior spread and the other numerical error of the estimated posterior mean. Correlated MCMC requires covariance adjustment.

36. 옛 값을 동시에 넣은 병렬 갱신의 반례A counterexample to simultaneous stale-value updates

목표 N₂(0, [[1, ρ], [ρ, 1]]), |ρ|<1에서 옛 값으로 x₁′=ρx₂+ε₁, x₂′=ρx₁+ε₂를 동시에 만듭니다. 혁신들은 서로와 옛 상태에 독립 N(0, 1−ρ²)입니다. 목표에서 시작한 새 공분산은?

The target is N₂(0, [[1, ρ], [ρ, 1]]), |ρ|<1. Simultaneously set x₁′=ρx₂+ε₁, x₂′=ρx₁+ε₂ using old values. Innovations are mutually independent N(0, 1−ρ²), independent of the old state. What is the new covariance from a target start?

풀이와 확인할 이유Solution and explanation

각 새 분산은 ρ²+(1−ρ²)=1이지만 교차 공분산은 ρ²Cov(x₂, x₁)=ρ³입니다. ρ=0.8이면 0.512로 목표 0.8과 다릅니다. 순차 갱신에서는 x₂′=ρx₁′+ε₂로 최신 값을 써서 Cov(x₁′, x₂′)=ρVar(x₁′)=ρ를 보존합니다. 각각의 조건부 공식을 알고 있다는 것만으로 동시 갱신이 같은 Gibbs 커널은 아닙니다.

Both marginal variances remain one, but cross-covariance becomes ρ²Cov(x₂, x₁)=ρ³. At ρ=.8 this is.512 rather than .8. Sequential updating uses x₂′=ρx₁′+ε₂ and preserves covariance ρVar(x₁′)=ρ. Knowing the conditional formulas does not validate simultaneous stale-value substitution.

37. 작은 raw Rhat 손계산Calculate a small raw Rhat

이미 분할된 M=2개 체인이 각각 (0, 2), (2, 4)이고 각 길이 L=2입니다. 불편 체인 내 분산 평균 W, 체인 간 B=LΣm(평균m−전체평균)²/(M−1), V⁺, Rhat를 계산하세요.

Two already split chains are (0, 2) and (2, 4), each length L=2. Compute W, the mean unbiased within-chain variance; B=LΣm(mean_m−grand mean)²/(M−1); V⁺; and Rhat.

풀이와 확인할 이유Solution and explanation

체인 평균은 1, 3이고 전체 평균은 2입니다. 두 불편 분산이 각각 2라 W=2입니다. B=2(1+1)=4이며 V⁺=(L−1)W/L+B/L=3입니다. 따라서 Rhat=√(3/2)입니다. 체인 사이 위치 차이가 체인 내 변동에 비해 큼을 나타내지만 이 수치 하나가 정확한 초기 편향을 계산해 주지는 않습니다.

Means are one and three, grand mean two. Both within variances are two, so W=2. B=4, V⁺=(L−1) W/L+B/L=3, and Rhat=√(3/2). It signals between-chain disagreement but does not quantify exact initialization bias.

38. 상수 체인의 비율을 성공으로 채우지 않는다Do not fill a constant-chain ratio with success

분할 체인 (1, 1), (1, 1) 또는 (1, 1), (3, 3)을 raw Rhat 식에 넣으면 W와 B는? 각각 Rhat=1이나 큰 유한수로 채워도 되나요?

For split chains (1, 1), (1, 1), or (1, 1), (3, 3), what are W and B? May the undefined Rhat be filled with one or an arbitrary large finite value?

풀이와 확인할 이유Solution and explanation

두 경우 모두 W=0입니다. 첫 경우 B=0이어서 0/0이고, 둘째 B>0이어서 유한한 분산비가 아닙니다. 이 실습은 둘 다 정의된 유한 Rhat로 보고하지 않습니다. 정확한 상수 검사 전에 부동소수점 누적 오차로 가짜 작은 W를 만들고 거대한 유한값을 반환해서도 안 됩니다. 상수 경로 자체와 계산 상태를 함께 보고합니다.

W=0 in both cases. The first has B=0 and a0/0 ratio; the second has B>0 and no finite ratio. Neither is reported as a defined finite Rhat. Exact constant checks must precede floating accumulation that could create spurious tiny W. Report the constant paths and diagnostic status.

39. 홀수 분할에서 무엇을 버리는가What does odd-length splitting omit?

길이 5 원 체인 (10, 20, 30, 40, 50)을 이 장의 split 규칙으로 나누세요. 원 평균과 접힘 중앙값에도 30을 삭제하나요?

Split the original length-five chain (10, 20, 30, 40, 50) by this chapter’s rule. Is thirty also removed from the original mean and folding median?

풀이와 확인할 이유Solution and explanation

분할 체인은 (10, 20), (40, 50)이고 가운데 30은 split 진단에만 제외됩니다. 원 경로와 원 평균에는 5개 모두 남습니다. 접힘 중앙값도 모든 원 저장값을 모아 먼저 구한 뒤, 접힌 값을 split합니다. 진단 전처리 때문에 실제 원 경로를 지우거나 원자료 분모를 바꾸지 않습니다.

The halves are (10, 20) and (40, 50); thirty is omitted only for split diagnostics. The original trace and mean retain all five values. Folding uses the pooled median of all original retained values before splitting. Diagnostic preprocessing does not delete the source trace.

40. 동률에는 평균 순위를 준다Use average ranks for ties

모은 값 (1, 1, 4, 8)의 순위를 매기고, z=Φ⁻¹((r−3/8)/(S+1/4))에 들어갈 네 확률을 구하세요. S=4입니다.

Rank pooled values (1, 1, 4, 8), then find the four probabilities in z=Φ⁻¹((r−3/8)/(S+1/4)), S=4.

풀이와 확인할 이유Solution and explanation

두 1은 순위 1과 2를 공유하여 각각 1.5입니다. 다음은 3, 4입니다. 정규 점수 확률은 (9/34, 9/34, 21/34, 29/34)입니다. 동률을 원 배열 순서로 임의 분리하면 값이 같은 관측에 다른 점수를 주게 됩니다. 분모 S+1/4와 원 논문의 정의를 보존합니다.

Ranks are (1.5, 1.5, 3, 4), giving probabilities (9/34, 9/34, 21/34, 29/34). Breaking ties by array position would assign unequal scores to equal values. Preserve the specified S+1/4 convention.

41. 평균이 같아도 척도가 다르다Equal means can hide unequal scales

한 체인은 대략 −0.1~0.1, 다른 체인은 −10~10을 대칭으로 방문하여 두 평균이 0입니다. 평균 비교만으로 충분하지 않은 이유와 접힘의 역할을 설명하세요.

One chain visits roughly −.1 to.1 and another −10 to 10 symmetrically, both with mean zero. Why is mean agreement insufficient, and what does folding add?

풀이와 확인할 이유Solution and explanation

체인 사이 평균이 같아도 하나가 좁은 영역에 갇혀 있을 수 있습니다. 모은 중앙값 근처에서 절대거리로 접으면 두 체인의 거리 분포가 크게 달라집니다. 접힌 순위 진단이 척도 차이를 드러낼 수 있습니다. 다만 두 체인이 같은 잘못된 좁은 영역에 함께 갇힌 경우에는 이것도 놓칠 수 있어 하나의 진단을 완전한 증명으로 쓰지 않습니다.

One chain may be trapped in a narrow region despite equal means. Absolute distances from a pooled center have different distributions, which folded-rank diagnostics can detect. If both chains are trapped in the same wrong region, even this check can fail; it is not a complete proof.

42. 짝수 중앙값의 접힘 동률Preserve the central tie when folding

원값 (0, 2, 8, 10)의 중앙 두 값 lo=2, hi=8입니다. 접힌 거리를 구하고 중앙 두 값의 동률을 보존해야 하는 이유를 쓰세요.

Original values are (0, 2, 8, 10), with central lo=2, hi=8. Find folded distances and explain why the central tie matters.

풀이와 확인할 이유Solution and explanation

수학적 중앙값은 5이고 거리는 (5, 3, 3, 5)입니다. 중앙 두 관측은 항상 같은 거리입니다. 수치 구현에서 중앙값을 먼저 반올림해 빼면 그 동률이 깨질 수 있으므로 이 장은 중앙 쌍 차이를 평균하는 계산 관례를 명시합니다. 관례는 원값을 바꾸는 것이 아니라 접힘 파생값의 반올림 순서를 정합니다.

The mathematical median is five and distances are (5, 3, 3, 5). The central observations are equidistant. Rounding a midpoint before subtraction can break this tie numerically, so we state the central-pair difference convention. It changes calculation order, not the original values.

43. Rhat를 1 아래에서 자르지 않는 이유Why not clamp every Rhat below one?

이미 분할된 두 체인이 모두 (0, 2)입니다. W=2, B=0, L=2에서 raw Rhat를 구하세요. 1보다 작다는 이유로 음의 불확실성인가요?

Two already split chains both equal (0, 2). With W=2, B=0, L=2, find raw Rhat. Does a result below one imply negative uncertainty?

풀이와 확인할 이유Solution and explanation

V⁺=(1/2)2+0=1이라 Rhat=1/√2입니다. 유한 분산비 정의에서는 1 아래 값이 가능하며 음의 분산이 아닙니다. 원 정의를 1로 잘라 바꾸지 않습니다. 두 경로의 일치도 목표를 정확히 탐색했다는 증명은 아닙니다.

V⁺=1 and Rhat=1/√2. A finite variance ratio can fall below one without any negative variance. Preserve the definition rather than clamp it. Matching paths still do not prove correct exploration.

44. warmup을 늘리면 자동 정상이 되는가Does more warmup automatically create stationarity?

비정상 시작의 MCMC에서 앞 500개를 버리고 1000개를 저장했습니다. 남은 상태가 정확 정상·독립이라는 결론이 나오나요? thinning도 함께 설명하세요.

Discard 500 states from a nonstationary MCMC start and retain 1000. Does that prove the remainder is stationary and independent? Discuss thinning too.

풀이와 확인할 이유Solution and explanation

고정된 삭제 수만으로 그 결론은 나오지 않습니다. 초기 효과 감소는 커널·시작·혼합 성질에 달렸고 저장값 사이 상관도 남을 수 있습니다. thinning은 저장·전달 비용에 도움이 될 수 있지만 독립성을 자동 보장하지 않으며 같은 총 전이 비용에서 정보를 버릴 수 있습니다. 버린 구간·총 전이·보관 간격·진단과 오차 평가를 함께 보고합니다.

No fixed discard count proves those properties. Initialization effects and dependence depend on the kernel and mixing. Thinning can reduce storage costs, but does not automatically produce independence and may discard information at fixed transition cost. Report discarded length, total transitions, retention interval and precision assessment.

45. 유한 진단이 모형 타당성을 검정하지는 않는다Finite diagnostics do not validate the model

네 체인의 Rhat가 1.01 근처이고 계산 평균이 안정적입니다. 이것으로 사전 선택·결측 처리·인과 효과·실제 자료의 대표성까지 검증됐나요?

Four chains have Rhat near 1.01 and stable averages. Does this validate priors, missingness handling, causal effects and data representativeness?

풀이와 확인할 이유Solution and explanation

아닙니다. 진단은 선택한 목표분포를 계산하는 경로의 일부 문제를 살핍니다. 모형·관측과정·대표성·인과 식별은 다른 질문입니다. 정확 사후 계산도 잘못 선택한 모형의 사후를 정확히 계산할 수 있습니다. 사전·사후예측, 자료 생성과정, 민감도와 과학적 근거를 별도로 확인합니다.

No. Diagnostics inspect aspects of computing the chosen target. Model adequacy, observation processes, representativeness and causal identification are separate. An accurately computed posterior can belong to an unsuitable model. Check predictions, sensitivity and substantive assumptions separately.

46. 실제 국가 척도와 경로 상태Scale in the actual-country model

2024년 16국 GDP/명을 10000으로 나누어 기대수명 기준 8국씩 두 집단에 넣고 정규 계층을 가정했습니다. 사후 모수 θ=4.5와 실제 국가 수·단위를 해석하세요.

Divide 2024 GDP per capita for sixteen countries by 10000, form two eight-country life-expectancy groups and assume a Gaussian hierarchy. Interpret posterior θ=4.5, source count and units.

풀이와 확인할 이유Solution and explanation

θ=4.5는 선택 모형에서 GDP/명 45000의 척도입니다. 원 GDP 지표는 2015년 고정 USD/명이며 모수도 해당 척도로 역변환합니다. 실제 국가는 16개입니다. 기대수명으로 나눈 집단과 계층 가정은 기술적 비교이지 기대수명 정책의 인과 미분이나 세계 전체의 무작위 표집 설계가 아닙니다.

θ=4.5 corresponds to 45000 constant 2015 USD per person under the chosen model. There are sixteen source countries. Grouping and hierarchical assumptions describe this comparison, not a causal policy derivative or random sampling of the entire world.

47. 실제 국가 주변 분산을 조건부와 나눈다Separate marginal and conditional variances in the country case

실제 16국 작업 모형에서 Q=[[9, 0, −1], [0, 9, −1], [−1, −1, 9/4]], 사후 공분산의 θ₁ 대각은 77/657, μ 대각은 36/73입니다. 두 좌표의 전조건부 분산과 주변 분산을 비교하세요.

In the sixteen-country working model, Q=[[9, 0, −1], [0, 9, −1], [−1, −1, 9/4]]. Marginal variances are 77/657 for θ₁ and 36/73 for μ. Compare full-conditional variances.

풀이와 확인할 이유Solution and explanation

전조건부 분산은 각각 1/Q₁₁=1/9, 1/Qμμ=4/9입니다. 주변 분산 77/657, 36/73은 다른 좌표의 불확실성을 적분하여 더 큽니다. θ₁에서는 77/657−1/9=4/657이고 μ에서는 36/73−4/9=32/657입니다. 이 단위는 GDP/명을 10000으로 나눈 척도의 제곱입니다.

Conditional variances are 1/9 and 4/9. Marginal variances integrate the other coordinates and are larger, by 4/657 and 32/657 respectively. Units are the squared scaled GDP-per-capita units.

48. 실제 로그임금의 가용 분모The available log-wage denominator

원 남성 기록 3613개 중 로그임금이 가용한 것은 3010개입니다. 분산 1/4의 iid 정규 작업 우도와 사전 N(6, 1/4)에서 모평균의 사후 분산을 구하고 603개를 설명하세요.

Of 3613 original male records, 3010 have an available logged wage. Use an iid Gaussian working likelihood with variance 1/4 and prior N(6, 1/4). Find the posterior mean-parameter variance and interpret 603 unavailable outcomes.

풀이와 확인할 이유Solution and explanation

사전 정밀도는 4, 우도 정밀도는 3010/(1/4)=12040입니다. 합 정밀도 12044라 사후 분산은 1/12044입니다. 603개 비관측 로그임금을 0으로 넣지 않았고 그 집단의 분포가 식별된 것도 아닙니다. 이 계산의 iid·정규·고정 분산은 추가 가정입니다.

Prior precision is four and likelihood precision 12040, so posterior variance is 1/12044. The 603 unavailable logs were not filled with zero, and their distribution is not identified by this computation. The iid Gaussian known-variance likelihood is an added assumption.

49. 로그 모평균의 지수는 임금 산술평균인가Is exponentiating a log mean an arithmetic wage mean?

선택 정규 모형에서 로그임금 평균 μ의 사후 평균만 exp로 바꾸었습니다. 이것이 곧 원 임금의 사후예측 산술평균인가요?

Exponentiate only the posterior mean of a log-wage mean μ. Is this automatically the posterior predictive arithmetic mean wage?

풀이와 확인할 이유Solution and explanation

아닙니다. exp(E[μ|자료])와 E[exp(μ)|자료]도 비선형성 때문에 다릅니다. 개별 로그임금 Y의 예측이 N(m, V)라면 E[exp(Y)|자료]=exp(m+V/2)로 관측 변동과 모수 불확실성을 모두 포함해야 합니다. 원 자료의 로그 단위와 수준 통화 환산도 별도로 보존합니다. 이 모형 관계를 실제 임금분포의 검증된 사실로 바꾸지 않습니다.

No. Even exp(E[μ|data]) differs from E[exp(μ)|data]. If an individual predictive log outcome is N(m, V), its level mean is exp(m+V/2), including outcome and parameter variation. Preserve original logged units and any currency conversion. This is a model relation, not a verified fact about actual wage distributions.

50. 실제 AR 참조에서 점근 ESS 비교Compare asymptotic ESS references in the log-wage case

3010개 가용 로그임금으로 만든 고정 사후를 목표로 네 체인 각 1000개를 저장합니다. 알려진 정상 AR 참조 ρ=1/5와 ρ=199/200에서 총 4000개에 대한 점근 ESS를 구하세요.

Four 1000-state chains target a fixed posterior based on 3010 available logs. For known stationary AR references ρ=1/5 and 199/200, find asymptotic ESS for 4000 states.

풀이와 확인할 이유Solution and explanation

첫 τint=3/2라 ESS≈8000/3≈2666.67입니다. 둘째 τint=399라 ESS≈4000/399≈10.0251입니다. 같은 저장 수여도 평균 정밀도가 크게 다릅니다. 이 수들은 정상 AR 가정의 점근 참조이며, 분산된 실제 시작 경로의 유한 ESS를 정확 인증한 값도 일반 bulk/tail 추정도 아닙니다.

Autocorrelation times are 3/2 and 399, giving ESS references 8000/3≈2666.67 and 4000/399≈10.0251. Equal stored counts can have very different mean precision. These are stationary-model asymptotic references, not exact finite ESS certificates for dispersed starts or estimated bulk/tail ESS.

51. 실제 로그 사후의 유한 정상 평균 참조A finite stationary mean reference for the log posterior

v=1/12044인 사후를 목표로 서로 독립인 정상 AR 체인 네 개를 각 T=1000개 보관합니다. ρ=1/5와 199/200에서 유한 평균 분산의 식을 적고, 각각 약 3.1122862×10⁻⁸, 6.6408514×10⁻⁶이라는 참조의 범위를 설명하세요.

The posterior variance is v=1/12044. Four independent stationary AR chains each retain T=1000 states. Give the finite mean-variance formula for ρ=1/5 and 199/200, and interpret approximate values 3.1122862×10⁻⁸ and 6.6408514×10⁻⁶.

풀이와 확인할 이유Solution and explanation

독립 체인 평균을 평균하므로 한 체인 평균 분산을 4로 나눕니다.

sT=∑h=1T−1(1−h/T)ρhVar⁡(Yˉ)=v4T(1+2sT)\begin{gathered}s_T=\sum_{h=1}^{T-1}(1-h/T)\rho^h\\\operatorname{Var}(\bar Y)=\frac v{4T}(1+2s_T)\end{gathered}

s_T는 원래 유한 길이 자기상관 보정합입니다. 분모 4는 독립인 네 체인 평균을 합치는 데서 나옵니다.

주어진 두 근삿값은 이 유한 합의 값입니다. vτint/(4T)는 긴 T의 점근 근사라 유한 합과 정확히 같지 않습니다. 실제 저장 경로는 분산된 시작을 썼으므로 이 정상 참조를 그 경로의 정확 오차분산이라고 부르지 않습니다.

Average independent chain means, dividing one-chain variance by four.

sT=∑h=1T−1(1−h/T)ρhVar⁡(Yˉ)=v4T(1+2sT)\begin{gathered}s_T=\sum_{h=1}^{T-1}(1-h/T)\rho^h\\\operatorname{Var}(\bar Y)=\frac v{4T}(1+2s_T)\end{gathered}

s_T denotes the original finite-length autocorrelation sum. The divisor four comes from pooling four independent chain means.

The supplied values evaluate this finite sum. Replacing it by vτint/(4T) is asymptotic. Dispersed stored starts are not certified stationary, so this reference is not their exact error variance.

52. 실제 고객 자료의 조건부 Beta 한 점One conditional Beta node for actual customers

실제 민원 집단은 241기록 중 이탈 200, 나머지 집단은 2909기록 중 이탈 295입니다. 집단별 p를 주면 모든 결과가 집단 안·사이에서 독립 Bernoulli(p)라는 작업 우도를 씁니다. 선택 노드 μ=1/4, κ=4에서 두 p의 사전이 독립 Beta(κμ, κ(1−μ))라면 조건부 사후 평균은?

Actual counts are 200 churns among 241 complaint records and 295 among 2909 other records. Given the group-specific rates, all outcomes are independent within and across groups with Bernoulli laws at their respective rates. At chosen node μ=1/4, κ=4, use independent Beta(κμ, κ(1−μ)) priors. Find conditional posterior means.

풀이와 확인할 이유Solution and explanation

사전은 각각 Beta(1, 3)입니다. 민원 집단 사후는 Beta(201, 44)라 평균 201/245, 나머지는 Beta(296, 2617)라 평균 296/2913입니다. 이 값은 고정 노드 조건부 평균이고 아홉 노드를 혼합한 전체 사후 평균과는 다릅니다. 관측 집단 차이의 인과 효과도 아닙니다.

Priors are Beta(1, 3). Posteriors are Beta(201, 44) and Beta(296, 2617), with means 201/245 and 296/2913. These condition on one node; they are not the full nine-node posterior mixture means or causal group effects.

53. 조건부 평균 경로는 p의 사후 추출이 아니다A conditional-mean trace is not a posterior draw of p

고객 계층에서 J가 정확한 노드 사후법칙을 따르고 g(J)=E[p|J, 자료]입니다. g(J)의 이론적 기대값과 분산은 p의 사후 평균·분산을 모두 재현하나요?

Let J follow the exact posterior node law and g(J)=E[p|J, data]. Do the theoretical expectation and variance of g reproduce both posterior moments of p?

풀이와 확인할 이유Solution and explanation

평균은 반복기대값으로 같습니다. 그러나 총분산은 다음 두 항입니다.

Var⁡(p∣y)=E[Var⁡(p∣J,y)∣y]+Var⁡(g(J)∣y).\begin{aligned} \operatorname{Var}(p\mid y) &=E[\operatorname{Var}(p\mid J,y)\mid y]\\ &\quad+\operatorname{Var}(g(J)\mid y). \end{aligned}

g만의 분산은 첫 항을 빠뜨립니다. 유한 경로 평균은 이 이론적 기대값을 근사하며 정확히 같다고 보장되지 않습니다. 그 경로의 히스토그램을 p 전체 사후로 소개하면 안 됩니다. 이 분산 감소 항등식이 임의 Markov 커널의 평균 MCSE 개선율까지 자동 정하는 것은 아닙니다.

The means agree by iterated expectation, but total variance has two terms.

Var⁡(p∣y)=E[Var⁡(p∣J,y)∣y]+Var⁡(g(J)∣y).\begin{aligned} \operatorname{Var}(p\mid y) &=E[\operatorname{Var}(p\mid J,y)\mid y]\\ &\quad+\operatorname{Var}(g(J)\mid y). \end{aligned}

The g law omits the first term. A finite trace mean approximates its theoretical expectation without equaling it exactly. Its histogram is not the full posterior of p. This one-draw variance decomposition alone does not quantify asymptotic MCSE improvement for every Markov kernel.

54. 노드 사후 가중치의 정규화Normalize posterior node weights

고객 두 집단의 고정 성공·실패 수가 (sⱼ, fⱼ)이고, 아홉 노드 ℓ의 사전 확률이 1/9입니다. 노드 조건부로 두 p는 독립 Beta(aℓ, bℓ), aℓ=κℓμℓ>0, bℓ=κℓ(1−μℓ)>0입니다. p들을 주면 모든 집단의 결과는 각 집단 안·사이에서 독립 Bernoulli이며 해당 집단의 성공확률은 pⱼ입니다. p들을 적분한 노드 가중치 식을 적으세요.

Two customer groups have fixed successes/failures (sⱼ, fⱼ). Nine nodes have prior mass 1/9. Conditional on node ℓ, the two rates are independent Beta(aℓ, bℓ), where aℓ=κℓμℓ>0, bℓ=κℓ(1−μℓ)>0. Given the rates, all outcomes are independent within and across groups with their respective Bernoulli probabilities pⱼ. Write integrated posterior node weights.

풀이와 확인할 이유Solution and explanation

각 집단의 Beta 사전과 이진 우도를 적분하면 Beta 함수의 비입니다. 집단들은 노드를 조건으로 독립이라는 가정을 사용합니다.

w~ℓ=19∏jB(aℓ+sj,bℓ+fj)B(aℓ,bℓ),wℓ=w~ℓ/∑r=19w~r.\begin{aligned} \widetilde w_\ell &=\frac19\prod_j \frac{B(a_\ell+s_j,b_\ell+f_j)}{B(a_\ell,b_\ell)},\\ w_\ell&=\widetilde w_\ell\Big/\sum_{r=1}^9\widetilde w_r. \end{aligned}

순서 자료 대신 성공 횟수 법칙을 쓰면 이항계수가 더해지지만 모든 노드에 공통이라 정규화에서 소거됩니다. 매우 작은 양의 가중치를 계산 화면의 0과 혼동하지 않습니다.

Conditional independence across groups and Beta integration give

w~ℓ=19∏jB(aℓ+sj,bℓ+fj)B(aℓ,bℓ),wℓ=w~ℓ/∑r=19w~r.\begin{aligned} \widetilde w_\ell &=\frac19\prod_j \frac{B(a_\ell+s_j,b_\ell+f_j)}{B(a_\ell,b_\ell)},\\ w_\ell&=\widetilde w_\ell\Big/\sum_{r=1}^9\widetilde w_r. \end{aligned}

A count likelihood adds binomial coefficients common to all nodes, so they cancel in normalization. Mathematically positive tiny weights must not be identified with displayed zero.

55. 기준 사후 평균과 유한 경로의 차이Compare a reference posterior mean with finite trace means

실제 고객 자료의 선택 계층에서 민원 집단 p의 사후 평균은 약 0.8236367579474313입니다. local 경로 평균 0.8234693877551020, global 경로 평균 0.8237204081632653의 부호 있는 오차를 구하고 비교의 한계를 쓰세요.

For the chosen actual-customer model, the complaint-rate posterior mean is about .8236367579474313. Stored local/global means are .8234693877551020 and .8237204081632653. Find signed errors and state limits.

풀이와 확인할 이유Solution and explanation

local 오차는 약 −0.0001673701923293, global은 +0.0000836502158340입니다. 이 저장 경로에서는 global의 절대 평균 오차가 작습니다. 그러나 단 한 번의 실현 오차를 반복 MCSE나 모든 함수·미래 실행의 성능 순위로 일반화하지 않습니다. 기준은 실제 자료에 선택한 모형의 사후 평균이지 알려진 실제 이탈 모수는 아닙니다.

Errors are approximately −.0001673701923293 and +.0000836502158340. Global has smaller realized absolute mean error here. One realization is not repeated MCSE or a universal performance ranking across functions and future runs. The reference is the chosen model’s posterior mean, not a known real-world churn parameter.

56. 작은 평균 오차여도 상수 체인은 문제다A small mean error does not rescue constant traces

고객 local 커널의 네 보관 체인이 각각 상수이고 전체 평균은 기준과 약 0.00017 차이입니다. 이 작은 차이로 정상 탐색·좋은 Rhat를 주장해도 되나요?

Four retained customer local-kernel chains are individually constant, yet the pooled mean is only about .00017 from reference. Does this establish stationary exploration or a good Rhat?

풀이와 확인할 이유Solution and explanation

아닙니다. 서로 다른 노드의 상수 경로가 우연히 평균에서 상쇄될 수 있습니다. 체인 내 변동이 없어 유한 분산비 진단을 계산할 수 없고 전체 사후 탐색 근거도 없습니다. 정확 평균 하나에 가까운 것은 그 함수의 이번 실현 평균만 설명합니다. 원 경로·노드 이동·다른 함수와 목표 질량을 함께 확인해야 합니다.

No. Different trapped nodes can cancel in a pooled average. Zero within-chain variation leaves finite variance-ratio diagnostics undefined and does not establish exploration. Proximity of one realized function mean is a narrower fact. Inspect movement, other functions and target mass.

57. 작은 공통질량에서 정량 수렴으로From a common mass to quantitative convergence

N개 유한 상태의 전이에서 어떤 m에 대해 모든 Pᵐij≥δ>0이고 ε=Nδ<1입니다. Pᵐ의 각 행을 εu+(1−ε)Rᵢ로 쓰고, 두 법칙의 TV가 한 블록마다 수축함을 보이세요. u는 균등법칙입니다.

In N finite states, suppose all Pᵐij≥δ>0 and ε=Nδ<1. Write each row as εu+(1−ε) Rᵢ for uniform u, and prove blockwise TV contraction.

풀이와 확인할 이유Solution and explanation

각 칸에서 δ를 뺀 뒤 1−ε로 나누면 음이 아닌 행합 1의 R이 됩니다. 공통 균등 성분은 두 법칙의 차이에서 소거됩니다.

pPm−qPm=(1−ε)(pR−qR),∥pPm−qPm∥TV≤(1−ε)∥p−q∥TV.\begin{aligned} pP^m-qP^m&=(1-\varepsilon)(pR-qR),\\ \|pP^m-qP^m\|_{\rm TV} &\le(1-\varepsilon)\|p-q\|_{\rm TV}. \end{aligned}

마지막 성질은 삼각부등식과 행합 1로 확인합니다.

∥pR−qR∥TV=12∑j∣∑i(pi−qi)Rij∣≤12∑i∣pi−qi∣∑jRij=∥p−q∥TV.\begin{aligned} \|pR-qR\|_{\rm TV} &=\frac12\sum_j\left|\sum_i(p_i-q_i)R_{ij}\right|\\ &\le\frac12\sum_i|p_i-q_i|\sum_jR_{ij}\\ &=\|p-q\|_{\rm TV}. \end{aligned}

q=π이면 k블록 뒤 거리 상계가 (1−ε)ᵏ배가 됩니다. ε=1은 R로 나누지 않고 한 블록 뒤 모든 행이 u인 별도 경우입니다.

Subtract δ from each entry and divide by 1−ε to obtain a stochastic R. The common component cancels between probability laws.

pPm−qPm=(1−ε)(pR−qR),∥pPm−qPm∥TV≤(1−ε)∥p−q∥TV.\begin{aligned} pP^m-qP^m&=(1-\varepsilon)(pR-qR),\\ \|pP^m-qP^m\|_{\rm TV} &\le(1-\varepsilon)\|p-q\|_{\rm TV}. \end{aligned}

The final property follows from the triangle inequality and unit row sums.

∥pR−qR∥TV=12∑j∣∑i(pi−qi)Rij∣≤12∑i∣pi−qi∣∑jRij=∥p−q∥TV.\begin{aligned} \|pR-qR\|_{\rm TV} &=\frac12\sum_j\left|\sum_i(p_i-q_i)R_{ij}\right|\\ &\le\frac12\sum_i|p_i-q_i|\sum_jR_{ij}\\ &=\|p-q\|_{\rm TV}. \end{aligned}

For q=π, the bound contracts by (1−ε)ᵏ after k blocks. If ε=1, all rows equal u after one block and no division by 1−ε is used.

58. 단위 환산과 진단의 수학적 불변성Units and mathematical diagnostic invariance

국가 모수 경로 X를 Y=10000X로 단위를 되돌립니다. 사후 SD·평균 MCSE·raw Rhat는 어떻게 바뀌나요? 순위·접힘 진단도 정확 연산에서 설명하세요.

Restore country units using Y=10000X. What changes in posterior SD, mean MCSE and raw Rhat? Discuss rank/fold diagnostics under exact arithmetic.

풀이와 확인할 이유Solution and explanation

SD와 MCSE는 10000배, 분산은 10⁸배입니다. W와 B가 같은 제곱 배율로 바뀌므로 raw Rhat 비는 같습니다. 양의 척도 변환은 순위를 보존하고 중앙값 절대거리도 공통 배율이라 rank/fold 진단도 수학적으로 같습니다. 다만 수치 저장 반올림이 서로 다른 값을 합치거나 동률을 깨면 구현 결과가 달라질 수 있어 원값과 변환 관례를 보존합니다.

SD and MCSE multiply by 10000; variances by 10⁸. W and B share that squared factor, leaving raw Rhat unchanged. Positive scaling preserves ranks and scales all median distances equally, so rank/fold diagnostics are mathematically unchanged. Numerical storage can merge distinct values or disturb ties, so retain originals and state conventions.

59. 선택 probe·난수 생성·유한 경로를 나눈다Separate selected probes, random generation and stored paths

실습에서 z=(0, 1, −1)을 골라 Gibbs 한 sweep를 계산했습니다. 다른 실제 사례는 명시한 LCG로 저장한 네 경로를 읽습니다. 두 결과를 각각 무엇이라고 보고해야 하나요?

You select z=(0, 1, −1) for one Gibbs sweep. Actual-case labs instead read four stored paths made with a specified LCG. How should the two be reported?

풀이와 확인할 이유Solution and explanation

첫 결과는 선택한 표준정규 probe를 넣은 수치 갱신 예입니다. 사용자가 고른 세 숫자를 독립 정규 난수라고 주장하지 않습니다. 두 번째는 기록된 생성기·시드·균등 매핑·정규 변환·warmup·보관 규칙으로 만든 고정 계산 경로입니다. 재현 가능성과 진정한 무한 난수의 이론 법칙, 유한 경로가 목표에서 정확 추출됐다는 주장은 서로 다릅니다.

The first is a numerical update at selected standard-normal probes, not three independently random normal observations. The second is a fixed computational path with recorded generator, seed, mapping, normal transform, warmup and retention rules. Reproducibility, an ideal infinite random law and exact target sampling are distinct claims.

60. 작은 계층 분석 보고서 설계Design a reproducible small hierarchical analysis report

새로운 작은 집단 자료에 계층 MCMC를 적용하려 합니다. 관측 단위·모형·커널·오차·검증·한계를 포함한 재현 보고서의 순서를 제안하세요.

Plan a report for hierarchical MCMC with new small-group data. Include observational units, model, kernel, error, checks and limitations.

풀이와 확인할 이유Solution and explanation

먼저 실제 행·집단·결측·단위와 연구 표적을 적습니다. 다음 우도·조건부 독립·proper 사전·고정 또는 추정할 척도를 명시합니다. 가능한 작은 정확 사후로 식을 검산합니다. 커널·제안·최신 갱신 순서·시작·생성기·warmup·보관을 기록합니다. 여러 경로와 함수별 평균·순위·접힘·MC 정밀도를 확인하되 진단을 증명으로 쓰지 않습니다. 마지막에 사전·사후예측과 모형·결측 민감도, 대표성·인과·계산 한계를 따로 보고합니다.

State source rows, groups, missingness, units and target. Specify likelihood, conditional independence, proper priors and fixed or estimated scales. Check formulas against a tractable posterior. Record kernel, proposal, fresh-update order, starts, generator, warmup and retention. Inspect multiple paths and function-specific means, ranks, folding and MC precision without treating diagnostics as proof. Report predictive checks, prior/model/missingness sensitivity and representativeness, causal and computational limits separately.

자료와 출처Data and sources

실제 자료 사례Actual-data cases · 원자료·단위·결측·변환·출처Inputs, units, missingness, transformations and sources

자료별 확보일·원행 식별·단위·이용 조건은 출처 기록을 확인하세요. 학습 사본은 제공처의 현재 최신 자료와 다를 수 있습니다.Consult each source record for retrieval dates, row identifiers, units and terms. Teaching copies can differ from current provider releases.

자료사전·출처·이용 조건Data dictionary, sources and terms