Klein § 6.5 — Ch.6 Exercises 7 문제 풀이

Group A Kernel Smoothing — Ex 6.1 6-MP relapse 3 kernel 비교 (uniform·Epanechnikov·biweight) at 12·5 months · Ex 6.2 allogeneic BMT leukemia-free uniform b=5 mo at 1·3·5·7·9·11·13 mo · Ex 6.3 kidney dialysis 2 군 biweight b=5 mo at 3·10 mo / Group B Excess Mortality — Ex 6.4 black female kidney transplant + 1990 US census 표준 (multiplicative B̂(t) + additive Â(t) + corrected S^C) · Ex 6.5 autologous BMT vs chemotherapy reference Exponential λ=0.045 (B̂ + Â) / Group C Bayesian NPMLE — Ex 6.6 breast cancer immunoperoxidase 9 명 + Dirichlet α(t,∞) = 6 exp(-0.1 t^0.5) + beta H_0 = 0.1 t^0.5 · Ex 6.7 tongue cancer diploid 28 명 + Dirichlet α(t,∞) = 4/(1 + 0.15 t^0.5) + beta H_0 = ln(1 + 0.15 t^0.5) / Ch.6 시리즈 마무리 + Ch.7 예고 (log-rank 등 hypothesis testing)

Klein & Moeschberger Ch.6 의 7 exercises 풀이 가이드. § 6.1~6.4 가 도구를 정의했다면, § 6.5 의 7 문제는 그 도구를 다양한 데이터에 통합 적용. Ch.6 시리즈 마지막 deep-dive. 7 문제 3 그룹 분류: (1) Kernel Smoothing — Ex 6.1 (6-MP 21명 relapse, 3 kernel 비교) + Ex 6.2 (allogeneic BMT 50명, uniform b=5 mo 7시점) + Ex 6.3 (kidney dialysis 119명 2 군 비교, biweight b=5 mo). (2) Excess Mortality — Ex 6.4 (black female kidney transplant 59명 + 1990 US census, multiplicative + additive 두 모형) + Ex 6.5 (autologous BMT vs chemotherapy reference Exp λ=0.045, 두 모형). (3) Bayesian NPMLE — Ex 6.6 (breast cancer immunoperoxidase 9명, Dirichlet α = 6 exp(-0.1 t^0.5) + beta H_0 = 0.1 t^0.5) + Ex 6.7 (tongue cancer diploid 28명, Dirichlet α = 4/(1+0.15 t^0.5) + beta H_0 = ln(1+0.15 t^0.5)). 각 문제 풀이 패턴: (a) 데이터 + 적절한 도구 식별 → (b) 식 적용 (식 6.2.4·6.3.2·6.3.6·6.4.1·6.4.2) → (c) 손계산 또는 R 코드 결과 → (d) 임상 해석. Klein 본문 결과 비교 + 도구 매핑. Ch.6 시리즈 통합 7 가지 교훈: (1) NA 점프의 평활 (kernel smoothing) — § 6.1~6.2, (2) Epanechnikov MSE optimal (Hodges-Lehmann 1956), (3) Gasser-Müller 1979 boundary kernel, (4) Cross-validation optimal bandwidth (Ramlau-Hansen 1983), (5) SMR 의 시간-변동 일반화 (Breslow 1975), (6) Cancer relative survival (S^C = Ŝ/S*), (7) Bayesian conjugate prior (Dirichlet + beta process) 의 closed form + Gibbs sampler 일반화. Ch.7 예고 — Hypothesis Testing: log-rank · Wilcoxon · Tarone-Ware · stratified · Renyi · Cramer-von Mises 등. § 7.2 one-sample log-rank 의 Iowa psychiatric 검정 (χ² = 24.76, p ≈ 0) 으로 § 6.3 의 excess mortality 결과를 통계적 검정으로 확정. NA framework 의 직접 연장.

Statistics
Survival Analysis
Klein-Moeschberger
Exercises
Topics-Univariate
저자

Kwangmin Kim

공개

2026년 04월 28일

1 들어가며 — Ch.6 시리즈의 마무리

주제
Ch.6 Overview 4 절 조망
§ 6.1~6.2 Kernel Hazard Smoothing
§ 6.3~6.4 Excess Mortality + Bayesian NPMLE
§ 6.5 (본 편) 7 Exercises 풀이 + Ch.6 마무리
§ 6.5 의 한 줄 요약

“Ch.6 의 7 exercises 는 § 6.1~6.4 의 모든 도구를 다양한 데이터에 통합 적용 — kernel smoothing 3 문제 (Ex 6.1·6.2·6.3) + excess mortality 2 문제 (Ex 6.4·6.5) + Bayesian NPMLE 2 문제 (Ex 6.6·6.7). 각 문제의 핵심은 (a) 적절한 도구 식별 → (b) 식 적용 (6.2.4 / 6.3.2 / 6.3.6 / 6.4.1 / 6.4.2) → (c) 결과 해석. Ch.6 시리즈의 마무리 + Ch.7 (hypothesis testing) 으로의 자연스러운 연결.”

2 7 문제 분류표

Ex 데이터 도구 n
6.1 6-MP 21명 relapse Kernel smoothing 3 kernel 비교 21
6.2 Allogeneic BMT leukemia-free Kernel smoothing (uniform b=5 mo) 50
6.3 Kidney dialysis 2 군 infection Kernel smoothing (biweight b=5 mo) 119
6.4 Black female kidney transplant Excess mortality + 1990 US census 59
6.5 Autologous BMT vs chemotherapy Excess mortality + Exp λ=0.045 ~50
6.6 Breast cancer immunoperoxidase Bayesian Dirichlet + beta process 9
6.7 Tongue cancer diploid Bayesian Dirichlet + beta process 28

3 Group A — Kernel Smoothing

3.1 Ex 6.1 — 6-MP Relapse, 3 Kernel 비교

데이터 (Klein § 1.2)

Freireich (1963) 6-MP 군 21 명. 사건 (재발) 9 건, censoring 12 건.

    1. \(t = 12\) months (\(\approx 52\) weeks) 에서 hazard rate 추정 — uniform kernel + bandwidth 6 months (\(\approx 26\) weeks).
    1. Epanechnikov 와 비교.
    1. Biweight 와 비교.
    1. \(t = 5\) months (\(\approx 22\) weeks) 시점 (boundary 영역) 에서 3 kernel.
풀이 패턴 — § 6.2 의 식 6.2.4·6.2.5

Step 1: § 4.2 의 NA 추정량 \(\widetilde{H}(t)\) 와 점프 \(\Delta\widetilde{H}(t_i) = d_i/Y_i\) 계산.

  • 6-MP 데이터의 9 사건 시점 (주): 6, 7, 10, 13, 16, 22, 23 (Klein Table 4.1A).
  • 점프: \(\Delta\widetilde{H}(6) = 3/21\), \(\Delta\widetilde{H}(7) = 1/17\), …

Step 2: \(t = 52\) weeks 시점 (\(b = 26\) weeks 사용) — symmetric kernel 영역 (\(b \leq t \leq t_D - b\)\(26 \leq 52 \leq 12\)? — 마지막 사건 \(t_D = 23\) 이라 \(t_D - b = -3\)).

\(t = 52\) 가 right boundary 영역 (\(t > t_D - b\)). 식 6.2.6~6.2.8 의 asymmetric kernel 사용.

  • \(q = (t_D - t)/b = (35 - 52)/26 < 0\) — 데이터 범위 밖, 추정 무의미.

대안: \(t = 12\) months ≈ 52 weeks 가 데이터 범위 밖 (마지막 censoring 35+ 주). 따라서 BHK exponential tail 후 평활. 또는 더 작은 \(t\) 에서 추정.

예: \(t = 22\) weeks (\(\approx 5\) months):

  • Symmetric 영역인지 확인: \(b = 26\)\(b \leq t \leq t_D - b\)\(26 \leq 22\)? No.
  • \(t = 22 < b = 26\)left boundary.
  • \(q = t/b = 22/26 = 0.846\).

식 6.2.6~6.2.8 의 asymmetric kernel 적용.

Klein 본문 결과 (Ex 6.1 답):

  • \(t = 5\) months 의 Uniform: \(\widehat{h}(5) \approx 0.04\) /month.
  • Epanechnikov: 약간 더 매끄러움.
  • Biweight: 가장 매끄러움.

→ 3 kernel 결과 비슷, 차이는 평활 정도.

R 코드 (Ex 6.1)
library(muhaz)
library(KMsurv)

# 6-MP 21 명
data(drug6mp)  # 또는 직접 입력
times <- c(6, 6, 6, 6, 7, 9, 10, 10, 11, 13, 16, 17, 19, 20,
           22, 23, 25, 32, 32, 34, 35)
events <- c(1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0,
            1, 1, 0, 0, 0, 0, 0)

# 3 kernel 비교 at t=22 weeks (≈ 5 months)
for (k in c("uniform", "epanechnikov", "biweight")) {
  fit <- muhaz(times = times, delta = events,
               max.time = 35, bw.method = "fixed",
               bw.smooth = 26, kern = k, b.cor = "left")
  h_22 <- approx(fit$est.grid, fit$haz.est, xout = 22)$y
  cat(k, ": h(22) =", round(h_22, 5), "\n")
}

3.2 Ex 6.2 — Allogeneic BMT Leukemia-Free Survival

데이터 (Klein § 1.4 Table 1.4)

50 명 advanced AML/HOD/NHL allogeneic BMT 의 leukemia-free 생존. Auto vs Allo.

문제: Allo 군의 hazard rate 를 1·3·5·7·9·11·13 months 에서 uniform kernel (\(b = 5\) months) 로 추정. Plot 후 hazard 모양 해석.

풀이 패턴

각 시점에서 식 6.2.4 적용. Boundary 처리:

  • \(t = 1\) (\(t < b = 5\)): left boundary, \(q = 1/5 = 0.2\).
  • \(t = 3\) (\(t < b\)): left boundary, \(q = 3/5 = 0.6\).
  • \(t = 5\) (\(t = b\)): symmetric 영역 시작.
  • \(t = 7, 9, 11, 13\): symmetric 영역.

각 시점에서 NA 점프들의 가중 평균.

예상 결과:

  • 1~3 months 매우 높은 hazard (post-BMT 초기 위험).
  • 5~9 months 점진적 감소.
  • 11~13 months 안정.

Hazard 모양: Decreasing — Weibull \(\alpha < 1\) 또는 Gompertz negative aging 후보.

→ R muhaztimes = c(1, 3, 5, 7, 9, 11, 13) 에서 추정.

3.3 Ex 6.3 — Kidney Dialysis 2 군 비교

데이터 (Klein § 1.4)

119 명 dialysis 환자: surgical 43 + percutaneous 76. 첫 infection 까지 시간.

문제: 두 군의 hazard rate 를 biweight kernel (\(b = 5\) months) 로: * (a) \(t = 3\) months 에서 추정. * (b) \(t = 10\) months 에서 추정.

풀이 패턴 + 임상 함의
  • \(t = 3\) (\(t < b = 5\)): left boundary 처리.
  • \(t = 10\): symmetric 영역 가능 (마지막 사건 시점에 따라).

Klein § 1.4 의 PH 위반 정전 사례:

  • Percutaneous 군의 hazard 가 첫 0.5 month 에 집중 (early infection).
  • Surgical 군은 안정적 hazard.

\(t = 3\) 시점: * Percutaneous: 매우 낮음 (이미 early infection 다 발생). * Surgical: 적당.

\(t = 10\) 시점: * 두 군 모두 낮음 (대부분 사건 발생 완료).

핵심 학습: Hazard rate 의 시간 패턴이 PH 가정 위반 (Ch.4·5 KM 만으로는 보이지 않음) 을 시각적으로 확인. → Ch.7 의 weighted log-rank 또는 Ch.9 의 time-varying coefficient 모델 동기.

4 Group B — Excess Mortality (§ 6.3)

4.1 Ex 6.4 — Black Female Kidney Transplant

데이터 (Klein § 1.7)

OSU 1982-1992 의 863 명 kidney transplant 중 black female 59 명. Death time + age at transplant.

참조 인구: 1990 US census 의 black female all-cause mortality (Klein Table 2.1).

문제 (a)~(e): B̂(t), 분산, Â(t), 분산, S^C(t) plot.

풀이 패턴 — § 6.3 의 multiplicative + additive

Step 1 — \(\theta_j(t)\) 계산:

각 환자 \(j\) 의 transplant 시점 age \(a_j\) 와 sex (모두 black female).

\(\theta_j(t) = \lambda_{BF}(a_j + t)\) (Klein Table 2.1 의 1990 US black female hazard).

Step 2 — Q(t) 와 Θ(t):

  • \(Q(t) = \sum_j \theta_j(t) Y_j(t)\) — multiplicative 의 분모.
  • \(\Theta(t) = \sum_j \int_0^t \theta_j(u) Y_j(u)/Y(u) du\) — additive 의 보정.

Step 3 — 식 6.3.2·6.3.6 적용:

  • \(\widehat{B}(t) = \sum_{t_i \leq t} d_i / Q(t_i)\).
  • \(\widehat{A}(t) = \widetilde{H}(t) - \Theta(t)\).

Step 4 — Corrected survival \(S^C(t) = \widehat{S}(t) / S^*(t)\) where \(S^*(t) = \exp(-\Theta(t))\).

예상 결과 (kidney transplant 의 known clinical 패턴):

  • B̂(t) 가 연도별 약 5-10 — transplant 환자가 일반인보다 5-10 배 빠른 사망.
  • Â(t) 가 점진적 증가 → 추가 mortality 가 누적.
  • \(S^C(t)\) 첫 1-2 년 급격히 감소 (post-transplant 초기 위험), 그 이후 안정.

임상 함의: Kidney transplant 후 immunosuppression + 합병증으로 인한 추가 mortality. 관찰의 표준 지표.

R 패키지: relsurv::rs.surv (multiplicative), relsurv::rs.add (additive).

4.2 Ex 6.5 — Autologous BMT vs Chemotherapy Reference

데이터 (Klein § 1.4 Table 1.4)

Allogeneic BMT 의 50 명 autologous part. Reference = chemotherapy 의 hazard rate \(\lambda = 0.045\) (Exponential 가정, 모든 환자 동일).

문제 (a)~(d): B̂(t), 분산, Â(t), 분산.

풀이 패턴

핵심 단순화 — reference \(\theta_j(t) = 0.045\) (모든 \(j\), 모든 \(t\)):

  • \(Q(t) = \sum_j \theta_j(t) Y_j(t) = 0.045 \cdot Y(t)\) — 위험집합 크기 비례.
  • \(\Theta(t) = \sum_j \int_0^t 0.045 \cdot Y_j(u)/Y(u) du = 0.045 \cdot t\) — 시간 비례.

\(\widehat{B}(t)\):

\[ \widehat{B}(t) = \sum_{t_i \leq t} \frac{d_i}{0.045 \cdot Y(t_i)} \]

→ NA \(\widetilde{H}(t)/0.045\) 와 같은 형태.

\(\widehat{A}(t)\):

\[ \widehat{A}(t) = \widetilde{H}(t) - 0.045 \cdot t \]

→ NA 에서 시간 비례 항을 뺌.

예상 결과:

  • Autologous BMT 의 hazard 가 chemotherapy 보다 다른가? — \(\widehat{B}(t)\) 의 기울기 vs 1 비교.
  • \(\widehat{A}(t) > 0\) 이면 BMT 가 추가 위험, \(< 0\) 이면 BMT 가 더 좋음.

임상 함의: Autologous BMT 도입 시 chemotherapy 와의 비교 — historical control 의 정량적 평가.

5 Group C — Bayesian NPMLE (§ 6.4)

5.1 Ex 6.6 — Breast Cancer Immunoperoxidase 9명

데이터 (Klein § 1.5 Table 1.3)

Sedmak (1989) 의 45 명 breast cancer 중 9 명 immunoperoxidase-positive (IH+) part. Time to death (months).

문제:

  1. Dirichlet prior with \(\alpha(t, \infty) = 6 \exp(-0.1 t^{0.5})\).
  2. Beta prior for \(H(t)\) with \(c = 6\), \(H_0(t) = 0.1 t^{0.5}\).
  3. KM 과 비교.
풀이 패턴 — § 6.4 의 closed form

Prior 설정:

  • \(\alpha(t, \infty) = 6 \cdot \exp(-0.1 t^{0.5})\)\(S_0(t) = \exp(-0.1 t^{0.5})\), \(c = 6\).
  • \(H_0(t) = 0.1 t^{0.5}\) — Weibull 형 cumulative hazard (\(\alpha = 0.5\) shape, increasing but decelerating).

Dirichlet — 식 6.4.1:

\[ \widetilde{S}_D(t) = \frac{\alpha(t, \infty) + Y_{i+1}}{\alpha(0, \infty) + n} \prod_{k=1}^i \frac{\alpha(t_k, \infty) + Y_{k+1} + \lambda_k}{\alpha(t_k, \infty) + Y_{k+1}} \]

  • \(\alpha(0, \infty) = 6\) (since \(S_0(0) = 1\)).
  • \(n = 9\).
  • 각 사건 시점 \(t_k\) 에서의 \(Y_k\), \(\lambda_k\) 데이터.

Beta — 식 6.4.2:

\[ \widetilde{S}_B(t) = \exp\left\{-\sum \frac{6 [H_0(t_k) - H_0(t_{k-1})]}{6 + Y_k}\right\} \prod \left[1 - \frac{6 h_0(t_k) + d_k}{6 + Y_k}\right]^{\Delta_k} \]

여기서 \(h_0(t) = dH_0/dt = 0.05 t^{-0.5}\).

예상 결과 vs KM:

  • IH+ 9 명은 매우 작은 표본 — KM 이 거칠고 큰 점프.
  • Bayes 가 prior 정보로 안정화 — 매끄러운 곡선.
  • Beta process 가 Dirichlet 보다 더 매끄러움 (sample path 자연 monotone).

핵심 학습: 작은 표본 (\(n = 9\)) 에서 Bayesian 의 효용 — prior strength \(c = 6\) (“거의 동일한 가짜 표본”) 이 KM 의 noise 를 크게 줄임.

5.2 Ex 6.7 — Tongue Cancer Diploid 28명

데이터 (Klein § 1.11 Table 1.6)

Sickle-Santanello (1988) 의 80 명 tongue cancer 중 diploid 28 명 part. Time to death (weeks).

문제:

  1. Dirichlet prior with \(\alpha(t, \infty) = 4 / (1 + 0.15 t^{0.5})\).
  2. Beta prior with \(c = 4\), \(H_0(t) = \ln(1 + 0.15 t^{0.5})\).
  3. KM 과 비교.
풀이 패턴

Prior 설정:

  • \(\alpha(t, \infty) = 4 / (1 + 0.15 t^{0.5})\)\(S_0(t) = 1/(1 + 0.15 t^{0.5})\) — log-logistic 형 survival.
  • \(H_0(t) = \ln(1 + 0.15 t^{0.5})\) — log-logistic cumulative hazard.
  • \(c = 4\).

일관성 검증: \(H_0 = -\ln S_0\) 이 성립?

\(-\ln S_0(t) = -\ln[1/(1 + 0.15 t^{0.5})] = \ln(1 + 0.15 t^{0.5}) = H_0(t)\) ✓.

→ Dirichlet 와 beta prior 가 같은 prior survival 에서 출발 — 비교 의의 있음.

Ex 6.6 보다 큰 표본 (\(n = 28\)):

  • KM 이 더 안정.
  • Bayes 영향 약화 (n / c = 28/4 = 7 → prior 가 표본의 약 14%).
  • 결과: KM 과 Bayes 가 비슷, 미세한 안정화 효과.

핵심 학습: 표본 크기에 따른 prior 영향:

  • \(n = 9\) (Ex 6.6) → prior 강함 (n/c ≈ 1.5).
  • \(n = 28\) (Ex 6.7) → prior 약함 (n/c ≈ 7).
  • \(n = 100+\) → prior 거의 무관, KM 으로 충분.

실무 가이드: \(n / c\) 비율을 보고 prior 영향 추정. \(n/c < 5\) 면 prior 영향 크고, \(> 20\) 이면 무관.

6 Ch.6 시리즈 통합 7 가지 교훈

Ch.6 핵심 교훈
  1. NA 점프의 평활 (§ 6.1~6.2)\(\Delta\widetilde{H}(t_i) = d_i/Y_i\) 가 hazard 의 거친 추정. Kernel-smoothed estimator 식 6.2.4 로 매끄러운 \(\widehat{h}(t)\) 도출.

  2. Epanechnikov MSE optimal (Hodges-Lehmann 1956) — 3 kernel 중 MSE 관점 최적. Biweight 는 smoother, uniform 은 거침. 실무 표준은 Epanechnikov.

  3. Gasser-Müller 1979 boundary kernel — 시작·끝 영역의 적분 ≠ 1 함정 → asymmetric kernel (식 6.2.6~6.2.8) 로 보정. \(q = t/b\) 또는 \((t_D - t)/b\) 의존.

  4. Cross-validation optimal bandwidth (Ramlau-Hansen 1983) — MISE 의 두 항 (bias² + variance) trade-off 를 데이터로 결정. \(g(b)\) 최소화.

  5. SMR 의 시간-변동 일반화 (§ 6.3 multiplicative) — Breslow 1975 의 단일 SMR 이 시간 일정 가정. B̂(t) 의 기울기가 시간별 \(\beta(t)\) — 환자 그룹 mortality 의 시간 패턴 정량화.

  6. Cancer relative survival — Corrected \(S^C(t) = \widehat{S}(t)/S^*(t)\) 가 cancer epidemiology 의 표준. “환자 고유의 mortality” 분리.

  7. Bayesian conjugate prior — Dirichlet (Ferguson 1973) for \(S\) + Beta process (Hjort 1990) for \(H\) 두 prior 의 closed form Bayes estimator. Gibbs sampler (Gelfand-Smith 1990) 의 일반화로 임의 sampling scheme + regression. \(c \to 0\) 또는 \(n \to \infty\) 면 KM 으로 수렴.

7 Ch.7 예고 — Hypothesis Testing

Ch.4·5·6 가 비모수 추정의 도구를 다뤘다면, Ch.7 은 그 위에 검정 을 쌓는다.

직관 — § 6.3 의 정량 vs § 7.2 의 검정

§ 6.3 의 Iowa psychiatric 분석 (excess mortality):

  • B̂(2) ≈ 25 → “정신질환자가 일반인보다 25 배 빠른 사망”.
  • 정량적 추정 + 95% CI.

§ 7.2 의 one-sample log-rank 검정:

  • \(H_0\): 환자 그룹의 hazard = 표준 인구 hazard.
  • 통계량 \(Z(\tau) = O(\tau) - E(\tau)\) — 관측 사건 수 - 기대 사건 수.
  • Klein Table 7.1 의 Iowa psychiatric: \(O = 15\), \(E = 4.474\).
  • \(\chi^2 = (15 - 4.474)^2 / 4.474 = 24.76\), \(p \approx 0\).

추정 + 검정 의 자연스러운 연결. § 6.3 의 정량 결과 (β ≈ 25) 가 § 7.2 에서 “통계적으로 0 과 다름” 으로 확정.

Ch.7 의 7 절:

주제
7.1 Introduction — NA 기반 검정의 통일 framework
7.2 One-sample log-rank test
7.3 Two-sample log-rank · Wilcoxon · Tarone-Ware
7.4 Trend tests (Jonckheere-Terpstra)
7.5 Stratified tests + matched data
7.6 Renyi tests (crossing hazards)
7.7 Cramer-von Mises + KM-based + median tests

→ Ch.6 의 NA framework 가 Ch.7 의 hypothesis testing 의 직접 토대. 동일한 framework 의 자연스러운 일반화.

8 응용 분야 (Ch.6 통합)

분야 도구 구체적 예시
임상시험 hazard 보고 § 6.2 kernel BMT post-transplant hazard
종양학 relative survival § 6.3 multiplicative Cancer 5 yr 생존률 (일반 인구 보정)
정신건강 mortality § 6.3 multiplicative Iowa psychiatric SMR 25
직업 노출 § 6.3 additive 화학 노출 추가 hazard
Kidney transplant § 6.3 + § 6.2 Black female 표준 mortality 보정
작은 표본 (n<30) § 6.4 Bayesian Phase II 임상시험
Phase II 임상시험 § 6.4 informative prior 기존 약 effect 를 prior 로
의료기기 PMA § 6.4 Bayesian FDA informative prior 가이드

9 코드 예시 통합

9.1 Ex 6.4 풀이 — R relsurv

library(relsurv)
library(KMsurv)
library(survival)

# Black female kidney transplant (가정 데이터)
data(kidtran)  # KMsurv 의 kidney transplant
bf <- subset(kidtran, race == "Black" & gender == "Female")

# 1990 US census black female ratetable
# (실제로는 survexp.us 의 race/sex stratification)
fit_mult <- rs.surv(Surv(time, delta) ~ 1,
                     data = bf,
                     ratetable = survexp.us,
                     rmap = list(age = age * 365.25,
                                  sex = "female",
                                  year = 1990 + year))

plot(fit_mult, xlab = "Years",
     main = "Ex 6.4 — Black Female KT Relative Survival")

# Excess mortality (additive)
fit_add <- rs.add(Surv(time, delta) ~ 1,
                   data = bf,
                   ratetable = survexp.us)
print(fit_add$Aest)  # Â(t) values

9.2 Ex 6.5 풀이 — Reference Exponential

import numpy as np

def excess_mortality_constant_ref(times, events, lambda_ref):
    """
    Reference hazard 가 일정 (예: 0.045) 일 때 B̂ + Â.
    """
    # NA + Greenwood
    sorted_idx = np.argsort(times)
    t_sorted = times[sorted_idx]
    e_sorted = events[sorted_idx]
    event_times = np.unique(t_sorted[e_sorted == 1])

    H_NA = 0
    Theta = 0
    B_hat = 0
    var_B = 0
    var_A = 0

    results = []
    prev_t = 0
    for t in event_times:
        Y = np.sum(t_sorted >= t)
        d = np.sum((t_sorted == t) & (e_sorted == 1))

        H_NA += d / Y                      # NA 점프
        Theta += lambda_ref * (t - prev_t)  # 시간 비례

        Q = lambda_ref * Y                  # 식 6.3.2 분모
        B_hat += d / Q
        var_B += d / Q**2                   # 식 6.3.3
        var_A += d / Y**2                   # 식 6.3.7

        A_hat = H_NA - Theta                # 식 6.3.6

        results.append((t, B_hat, A_hat, np.sqrt(var_B), np.sqrt(var_A)))
        prev_t = t

    return results

# Ex 6.5 — autologous BMT, lambda_ref = 0.045
times = np.array([...])  # autologous BMT 데이터
events = np.array([...])
result = excess_mortality_constant_ref(times, events, lambda_ref=0.045)

9.3 Ex 6.6·6.7 풀이 — Bayesian Closed Form

import numpy as np

def bayes_dirichlet_closed_form(times, events, S_0_func, c):
    """식 6.4.1 — Dirichlet posterior closed form"""
    n = len(times)
    sorted_idx = np.argsort(times)
    t_sorted = times[sorted_idx]
    e_sorted = events[sorted_idx]
    distinct_times = np.unique(t_sorted)

    S_D = []
    prod_factor = 1.0

    for i, t in enumerate(distinct_times):
        Y_curr = np.sum(t_sorted >= t)
        Y_next = np.sum(t_sorted > t)
        d = np.sum((t_sorted == t) & (e_sorted == 1))
        lam = np.sum((t_sorted == t) & (e_sorted == 0))

        alpha_t = c * S_0_func(t)
        alpha_0 = c * S_0_func(0)

        # 식 6.4.1 (간단화)
        first_term = (alpha_t + Y_next) / (alpha_0 + n)
        # ... (full closed form)

        S_D.append((t, first_term))  # 단순화

    return S_D


# Ex 6.6 — IH+ 9명, S_0(t) = exp(-0.1 sqrt(t)), c = 6
S_0_ex66 = lambda t: np.exp(-0.1 * np.sqrt(t))
times_ih = np.array([...])  # IH+ 9 명
events_ih = np.array([...])
result_66 = bayes_dirichlet_closed_form(times_ih, events_ih, S_0_ex66, c=6)


# Ex 6.7 — diploid 28명, S_0(t) = 1/(1 + 0.15 sqrt(t)), c = 4
S_0_ex67 = lambda t: 1 / (1 + 0.15 * np.sqrt(t))
times_dip = np.array([...])
events_dip = np.array([...])
result_67 = bayes_dirichlet_closed_form(times_dip, events_dip, S_0_ex67, c=4)

10 관련 주제

선행 지식

후속 주제

  • Ch.7 — Hypothesis Testing (log-rank · Wilcoxon · Tarone-Ware)
    • § 7.2 의 one-sample log-rank — § 6.3 의 excess mortality 와 직접 연결
  • Ch.8 — Cox Proportional Hazards Model
  • Ch.9 — Cox Refinements

관련 개념

  • 비모수 추정의 정교화 toolkit (smoothing + reference comparison + prior)
  • Cancer epidemiology 의 relative survival (NCI 표준)
  • Bayesian 비모수의 finite sample 안정화
  • Ch.4·5·6 → Ch.7 의 자연스러운 framework 연장

Subscribe

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