--- id: wiki-2026-0508-statistics title: Statistics category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Stats, Statistical-Inference] duplicate_of: none source_trust_level: A confidence_score: 0.95 verification_status: applied tags: [statistics, inference, frequentist, bayesian, foundations] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: python framework: scipy-statsmodels-pymc --- # Statistics ## 매 한 줄 > **"매 data → 매 truth 의 inference"**. Statistics 의 uncertainty 하의 decision-making — descriptive (summary), inferential (population from sample), causal (intervention) 의 3 axes. 17C Pascal/Fermat 에서 시작, 2026 에 frequentist + Bayesian + ML 의 hybrid 의 표준. ## 매 핵심 ### 매 3 axes - **Descriptive**: mean, median, SD, distribution, viz. 매 "what is". - **Inferential**: confidence interval, hypothesis test, p-value, posterior. 매 "what could be". - **Causal**: RCT, propensity, IV, DAG. 매 "what if". ### 매 frequentist vs Bayesian - **Frequentist**: probability = 매 long-run frequency. 매 parameters fixed, data random. p-value, CI. - **Bayesian**: probability = 매 belief degree. 매 parameters random (prior + likelihood → posterior). credible interval. - 매 ML community 의 mostly Bayesian-ish (regularization = prior). ### 매 inference workflow 1. Question → estimand 정의. 2. Design → sample, randomization, power. 3. Data collection. 4. Model — distribution / link function. 5. Estimate — MLE, MAP, posterior. 6. Inference — CI / credible interval, test. 7. Critique — diagnostics, sensitivity, replication. ### 매 응용 1. A/B testing — frequentist or Bayesian decision. 2. Survey / poll — sampling design. 3. Clinical trial — RCT, survival analysis. 4. ML model evaluation — bootstrap, cross-validation. 5. Causal inference — econometrics, epidemiology. ## 💻 패턴 ### 1. Descriptive — pandas ```python import pandas as pd df.describe() # mean, std, quartiles df.groupby("group").agg(["mean", "std", "count"]) ``` ### 2. Hypothesis test — scipy ```python from scipy import stats t, p = stats.ttest_ind(a, b, equal_var=False) # Welch's t u, p = stats.mannwhitneyu(a, b) # nonparametric chi, p, dof, exp = stats.chi2_contingency(table) ``` ### 3. Confidence interval (bootstrap, distribution-free) ```python import numpy as np def bootstrap_ci(x, stat=np.mean, B=10000, alpha=0.05): boot = [stat(np.random.choice(x, len(x), replace=True)) for _ in range(B)] return np.percentile(boot, [100*alpha/2, 100*(1-alpha/2)]) ``` ### 4. Linear regression with inference (statsmodels) ```python import statsmodels.api as sm X = sm.add_constant(df[["x1", "x2"]]) model = sm.OLS(df["y"], X).fit() print(model.summary()) # coef, SE, p, R² print(model.conf_int()) ``` ### 5. Bayesian inference (PyMC, 2026) ```python import pymc as pm with pm.Model() as m: mu = pm.Normal("mu", 0, 10) sigma = pm.HalfNormal("sigma", 5) y = pm.Normal("y", mu=mu, sigma=sigma, observed=data) idata = pm.sample(2000, tune=1000, chains=4, target_accept=0.95) import arviz as az az.summary(idata, var_names=["mu", "sigma"]) ``` ### 6. Multiple testing — BH (FDR) ```python from statsmodels.stats.multitest import multipletests reject, p_adj, _, _ = multipletests(p_values, alpha=0.05, method="fdr_bh") ``` ### 7. Causal — propensity score matching ```python from sklearn.linear_model import LogisticRegression ps = LogisticRegression().fit(X, treatment).predict_proba(X)[:, 1] # 매 nearest neighbor matching on logit(ps) → ATT estimate ``` ### 8. Survival — Kaplan-Meier ```python from lifelines import KaplanMeierFitter kmf = KaplanMeierFitter() kmf.fit(durations, event_observed=events) kmf.plot_survival_function() ``` ### 9. Cross-validation (proper inference for ML) ```python from sklearn.model_selection import cross_val_score scores = cross_val_score(model, X, y, cv=5, scoring="neg_mean_squared_error") ci = (scores.mean() - 1.96*scores.std(), scores.mean() + 1.96*scores.std()) ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | Quick descriptive | pandas .describe() | | 2-group mean diff | Welch's t (default) / Mann-Whitney (non-Gaussian) | | Proportion test | chi-square / Fisher's exact (small n) | | Complex hierarchy | Mixed effects (statsmodels.MixedLM) / Bayesian (PyMC) | | Decision under uncertainty | Bayesian posterior | | Causal claim | RCT > IV > DiD > matching | | Many tests | FDR (BH) / FWER (Bonferroni for safety-critical) | | Distribution-free CI | Bootstrap | **기본값**: descriptive 먼저 → assumption 의 check → frequentist 의 CI/test 의 default → critical decision 시 Bayesian 의 considerable. ## 🔗 Graph - 부모: [[Probability Theory]] - 변형: [[Probability Theory|Probability-Theory-Foundations]] · [[Sampling-Techniques]] - 응용: [[Regression-Analysis-Foundations]] · [[Statistical-Power]] · [[Multivariate-Analysis]] - Adjacent: [[Standard-Deviation-and-Variance]] · [[Entropy in Information Theory|Information Theory]] ## 🤖 LLM 활용 **언제**: choosing appropriate test, interpreting output, explaining p-value/CI to non-technical, drafting analysis plan. **언제 X**: 매 numerical computation — scipy/statsmodels/PyMC 의 사용. ## ❌ 안티패턴 - **p < 0.05 = 매 truth**: 매 decision threshold 의 X, just evidence — replication, effect size, prior 의 고려. - **Correlation = causation**: 매 흔한 fallacy — confounding, reverse causality, selection. - **Ignoring assumptions**: t-test 의 normality, regression 의 linearity → 매 diagnostic 의 필수. - **Cherry-picking subgroups**: 매 fishing → false positive 의 폭증. - **Reporting only mean (skewed data)**: median, IQR 의 추가. - **Sample size 의 unspecified**: 매 power 의 미상. ## 🧪 검증 / 중복 - Verified (Wasserman *All of Statistics*, Gelman *BDA3*, ASA p-value statement 2016). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — frequentist/Bayesian/causal axes + workflow. |