# ObesityTriangulate-Kor (오베시티트라이앵귤레이트코어)

> ⚠️ 본 도구는 연구 가설 생성·문헌 갭 분석 목적의 **연구용·교육용** 도구입니다.
> 임상의사결정·환자 진료에 직접 사용해서는 안 되며, 모든 분석 결과는 추가 검증이 필요합니다.
> 비만 약물·수술 선택은 반드시 자격 있는 임상의와 상담 후 결정해야 합니다.

항비만 intervention 10종 × 25+ outcome 격자에 대해 6-design effect 추정치를 한 grid에 통합하고,
concordance/discordance 정량화, weight-loss-mediated vs weight-loss-independent 분리,
discordance bias 방향 진단, triangulation-targeted 후속 가설·설계 자동 생성을 수행하는
**standalone Streamlit causal triangulation 도구**.

## 핵심 기능 5개

1. **6-design effect ingest + intervention-outcome 온톨로지** — 10 intervention × 25+ outcome (IARC 12 obesity-related cancer 포함)
2. **6-design triangulation grid + weight-loss mediator 분리** — multivariable MR (BMI·WHR·BF%) + mediation analysis
3. **Discordance bias direction 자동 진단** — bariatric preference-based IV (regression discontinuity 옵션)
4. **Triangulation-targeted 후속 가설 + MVMR 설계 카드** — 8가지 design (active comparator new-user / MVMR / negative control / 2×2 factorial / within-subject crossover / bariatric IV / DIO weight-matched / mediation N-of-1)
5. **HTA·규제·KASMBS·OpenClaw 리포트** — docx/markdown/JSON export

## 디렉토리

```
2026-05-29-2-obesity-triangulate-kor/
├── README.md
├── app.py                # Streamlit UI
├── main.py               # CLI (streamlit 없이도 작동)
├── triangulation/
│   ├── __init__.py
│   ├── ontology.py       # intervention-outcome 온톨로지
│   ├── grid.py           # 6-design effect grid + concordance
│   ├── lawlor.py         # Lawlor 2016 5-criterion 채점
│   ├── mvmr.py           # multivariable MR (BMI·WHR·BF%)
│   ├── mediation.py      # weight-loss-mediated 분리
│   ├── bias.py           # bias direction taxonomy + bariatric IV
│   ├── designs.py        # 8 design 카드 추천
│   └── report.py         # docx/md/json 리포트
├── data/
│   ├── effects_sample.csv          # 6-design 큐레이션 (52행)
│   ├── intervention_ontology.csv   # 10+ intervention 세부
│   ├── outcome_ontology.csv        # 25+ outcome (IARC 12 cancer 포함)
│   └── README.md                   # 데이터 출처
├── requirements.txt
└── QA.md
```

## 설치

```bash
# 최소 (CLI만): Python 3.9+ stdlib만으로 작동
python3 main.py --help

# 권장 (UI + 분석)
pip install -r requirements.txt
```

## 사용 — CLI

```bash
# 도움말
python3 main.py --help

# 온톨로지 요약
python3 main.py --summary

# 6-design grid (전체)
python3 main.py --grid

# 단일 pair 분석
python3 main.py --pair "semaglutide" "CV death"

# Weight-loss mediation
python3 main.py --mediation "semaglutide" "CV death"

# Multivariable MR
python3 main.py --mvmr "bariatric_RYGB" "obesity_related_cancer_IARC12"

# 8 design 카드
python3 main.py --designs "tirzepatide" "sarcopenia"

# Discordant pair top-N
python3 main.py --discordant --top 5

# 통합 리포트 (.json / .md / .docx)
python3 main.py --pair "semaglutide" "CV death" --report report.md
```

## 사용 — Streamlit

```bash
streamlit run app.py
```

- 사이드바: outcome 카테고리(CV/cancer/metabolic/MSK/neuro/liver/renal/respiratory) / intervention 필터, CSV 업로드
- 메인 탭: Grid / Pair Detail / Mediation / MVMR / Discordance / Designs / Report

## 데이터 출처

`data/README.md` 참조. 주요 RCT/observational/MR 헤드라인 수치 데모.
일부 source_url은 placeholder이므로 실사용 시 PubMed/DOI 검증 필요.

## 알고리즘 요약

### Concordance score (0~1)
- direction agreement (weighted by design weight) × 0.5
- CI overlap fraction × 0.3
- design diversity (n_designs/6) × 0.2

### Lawlor 5-criterion (Lawlor 2016)
1. 다른 source of bias = design diversity
2. expected bias direction 알려져 있음
3. similar effect size (CI overlap)
4. dose-response coverage
5. magnitude supports causal

### Multivariable MR
3개 adiposity 표현형 (BMI, WHR, BF%) 상관행렬 R의 역행렬을 통한
correlation-weighted conditional effect 분해.

### Mediation
- Difference method: total - direct (active comparator new-user)
- Product-of-coefficients: α (intervention→weight loss) × β (weight loss→outcome, BMI MR proxy)

### Bias taxonomy
7 design × 다중 bias type 매핑 (confounding by indication, healthy-user, detection,
protopathic, immortal time, canalization, pleiotropy, selection for surgery, etc.)

### Bariatric preference-based IV
2SLS ratio estimator로 surgical-candidate selection bias 보정.

## 제약

- 외부 네트워크/API 호출 없음 (로컬 CSV만)
- statsmodels/plotly/python-docx 등은 optional (없으면 stdlib fallback)
- 효과 추정치는 **데모 큐레이션**; 실사용은 ROBINS-I/MERIDIAN 등 정식 SR 결과 필요

## CHANGELOG

- 2026-05-29: 초기 MVP (52 effect rows, 6 design, 10+ intervention, 25+ outcome)
