Confidence interval
এই পাঠে যা শিখবেন
- CI-র সঠিক ব্যাখ্যা — frequentist interpretation
- t-distribution থেকে CI গণনা
- Bootstrap CI — distribution assumption ছাড়া
- ৪টি common misinterpretation
১ · কেন CI দরকার?
একটি sample mean — point estimate। কিন্তু এটি একটি single number — কতটা uncertainty সেটা বলে না। Confidence IntervalConfidence Interval (CI)একটি interval যা population parameter "ধারণ" করার expected coverage probability নিয়ে আসে। ৯৫% CI মানে — যদি একই procedure বহুবার চালানো হয়, ৯৫% interval true parameter ধারণ করবে। সেই uncertainty দেখায়।
উদাহরণ: bKash এজেন্টদের দৈনিক transaction sample থেকে $\bar{x}$ = ১৪,২০০ BDT। কিন্তু true population mean কত? CI বলবে — "৯৫% confidence-এ মান ১৩,৫০০ থেকে ১৪,৯০০-এর মধ্যে"।
২ · CI গাণিতিক রূপ
৯৫% CI for mean (large $n$):
$$\bar{x} \pm 1.96 \cdot \frac{\sigma}{\sqrt{n}}$$
ছোট $n$ (n < ৩০)-এ — t-distribution:
$$\bar{x} \pm t_{\alpha/2, \, n-1} \cdot \frac{s}{\sqrt{n}}$$
যেখানে $s$ = sample std, এবং $t$ critical value normal-এর চেয়ে কিছুটা বড় (n বাড়ার সাথে দু'টো মেলে)।
১) Point estimate ($\bar{x}$) — center।
২) Critical value ($z_{0.025}$ = ১.৯৬, বা $t$) — confidence level।
৩) Standard error ($s/\sqrt{n}$) — sample-to-sample variability।
৩ · ৯৫% মানে আসলে কী
সঠিক ব্যাখ্যা (frequentist): যদি একই study বহুবার চালানো হয় — প্রতিবার নতুন sample, একই procedure — তবে ৯৫% interval true parameter ধারণ করবে।
ভুল ব্যাখ্যা:
- "৯৫% probability parameter এই interval-এ" — ভুল। Parameter fixed; interval random।
- "৯৫% sample data এই interval-এ" — ভুল। ওটা prediction interval, ভিন্ন।
- "৯৫% CI বড় হলে কম confident" — সাবধান। প্রকৃতপক্ষে — বড় CI মানে বেশি uncertainty।
৪ · Bootstrap CI
BootstrapBootstrapBradley Efron (১৯৭৯) আবিষ্কৃত — sample থেকে with-replacement resample করে statistic-এর distribution-এর অনুমান। Distribution-free, যেকোনো statistic-এর জন্য। — distribution assumption ছাড়া CI। Sample থেকে with-replacement বহুবার resample, প্রতিটির statistic ক্যালকুলেট, percentile।
Algorithm:
- Original sample-এর size $n$।
- সেই sample থেকে $n$টি data point with-replacement বাছুন (একই row একাধিকবার আসতে পারে) — এক bootstrap sample।
- সেই bootstrap sample-এর statistic ($\bar{x}$, median, ...) হিসাব।
- Step ২-৩ ১,০০০-১০,০০০ বার পুনরাবৃত্তি।
- ২.৫ ও ৯৭.৫ percentile = ৯৫% CI।
সুবিধা:
- Distribution assumption নেই।
- যেকোনো statistic-এর CI — median, IQR, correlation, ratio।
- Skewed CI (asymmetric) সঠিকভাবে capture।
৫ · t-distribution বনাম bootstrap
t-distribution-ভিত্তিক:
- Mean-এর জন্য ভাল।
- Symmetric assumption।
- Small sample-এ designed।
- Quick formula।
Bootstrap:
- Mean, median, ratio, anything।
- Distribution-free।
- Computationally heavier।
- Asymmetric distribution-এ accurate।
৬ · ৪টি common misinterpretation
- (১) "৯৫% probability": "৯৫% probability parameter এই interval-এ" — ভুল। Frequentist-এ parameter fixed; CI random।
- (২) "Future sample": "৯৫% future sample এই interval-এ" — ভুল। ওটা prediction interval।
- (৩) "Overlap → no difference": দু'টি গ্রুপের CI overlap করলেই difference insignificant — সবসময় না। Direct test (t-test) করুন।
- (৪) "Wider = always worse": Wider CI মানে বেশি uncertainty — কিন্তু সেটাই কখনো-কখনো honest। Narrow CI from biased data বেশি বিভ্রান্তিকর।
৭ · scipy দিয়ে t-CI
import numpy as np
from scipy import stats
np.random.seed(42)
# Pathao ride duration sample (in minutes)
sample = np.array([12, 15, 18, 22, 13, 17, 20, 25, 14, 19,
16, 21, 11, 23, 18, 15, 17, 20, 19, 16])
n = len(sample)
mean = sample.mean()
se = sample.std(ddof=1) / np.sqrt(n)
t_crit = stats.t.ppf(0.975, df=n-1)
ci_low = mean - t_crit * se
ci_high = mean + t_crit * se
print(f"n : {n}")
print(f"mean : {mean:.2f} min")
print(f"SE : {se:.2f}")
print(f"t-critical: {t_crit:.3f}")
print(f"95% CI : ({ci_low:.2f}, {ci_high:.2f}) min")
৮ · Bootstrap CI
import numpy as np
np.random.seed(0)
# Daraz order values (right-skewed) - small sample
orders = np.array([320, 450, 280, 1200, 380, 520, 750, 410,
290, 600, 350, 480, 2500, 410, 380])
# Bootstrap median CI
n_boot = 10_000
boot_medians = np.array([
np.median(np.random.choice(orders, size=len(orders), replace=True))
for _ in range(n_boot)
])
ci_low = np.percentile(boot_medians, 2.5)
ci_high = np.percentile(boot_medians, 97.5)
print(f"Sample median : {np.median(orders):.0f} BDT")
print(f"Bootstrap 95% CI : ({ci_low:.0f}, {ci_high:.0f}) BDT")
print(f"Bootstrap mean of medians: {boot_medians.mean():.0f}")
ভাবনার প্রশ্ন
প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।
প্র ০১ "৯৫% confidence" বলতে আসলে কী বোঝায়? "প্যারামিটার এই interval-এ থাকার সম্ভাবনা ৯৫%" — এটি কেন ভুল frequentist interpretation?
এটি statistics-এর সবচেয়ে subtle এবং বহুল-ভুল interpretation। বুঝলে — আপনি real-statistician।
Frequentist framework:
- Population parameter $\mu$ — একটি fixed (unknown) সংখ্যা।
- Sample random — তাই sample-derived CI random।
- "Random" parameter নয়, interval।
- Probability statements parameter-এর উপর করা যায় না — কারণ $\mu$-র "probability" নেই।
সঠিক ব্যাখ্যা:
- একই procedure ১০০ বার apply (নতুন sample প্রতিবার) → ৯৫টি interval $\mu$ ধারণ করবে, ৫টি miss।
- আপনার কাছে যে interval আছে — সেটা "৯৫% lucky" group-এ আছে কি না জানা যায় না।
- Property of the procedure, not of any specific interval।
ভুল interpretation কেন আকর্ষণীয়:
- "৯৫% probability" intuitive — যা মন চায়।
- News, pop-stats সবসময় এই language ব্যবহার করে।
- Bayesian framework-এ — এটা সঠিক (credible interval)।
Bayesian বনাম Frequentist:
- Bayesian: parameter random (prior distribution), data fixed। "৯৫% probability $\mu \in [a,b]$" — সঠিক।
- Frequentist: parameter fixed, data random। "৯৫% confidence" — interval property।
- Numerical CI দু'টি প্রায়ই প্রায় একই — কিন্তু interpretation ভিন্ন।
Practical implication:
- Communicating CI: "If we repeated the study, ~95% of intervals would contain the true value" — সঠিক frequentist।
- Bayesian credible interval নাক চাইলে — Bayesian model বানান।
- Most published CI frequentist — তাই sloppy interpretation common।
মূল উপলব্ধি: "৯৫%" interval-এর property নয় — procedure-এর property। এটা subtle, কিন্তু statistics-এ probability-র দার্শনিক মূল।
প্র ০২ Bootstrap CI কেন কখনো কখনো parametric (t) CI-এর চেয়ে preferred? কখন bootstrap-ই ব্যর্থ হয়?
Bootstrap (Efron, ১৯৭৯) — modern statistics-এর সবচেয়ে গুরুত্বপূর্ণ একটি innovation। কিন্তু এটিও silver bullet না।
Bootstrap-এর সুবিধা:
- Distribution-free: Normality assumption লাগে না — যেকোনো source-এ কাজ করে।
- Any statistic: mean, median, ratio, IQR, correlation, R² — সব।
- Asymmetric CI: Skewed distribution-এ — left-right asymmetric CI সঠিকভাবে capture।
- Easy to communicate: "Resample data, see how stat varies" — intuitive।
- Complex pipeline: Bias correction, model output — bootstrap সব handle।
কখন parametric (t) prefer:
- Sample size large + roughly symmetric → t-CI সমান accurate, much faster।
- Mean-এর CI standard reporting — formula-ই enough।
- Real-time dashboard — bootstrap latency unacceptable।
Bootstrap কখন ব্যর্থ:
-
(১) Extreme statistics: max, min — bootstrap distribution discrete ও biased।
উদাহরণ: sample max-এর bootstrap CI underestimate true max। - (২) Heavy tail / infinite variance: Cauchy, $\alpha < 2$ Pareto — bootstrap unreliable।
- (৩) Time series / dependent data: Plain bootstrap independence assume। Block bootstrap দরকার — autocorrelation preserve।
- (৪) Very small n: n < ১০ — only $n^n$ resample possible, distribution discrete ও poor approximation।
- (৫) Censored / truncated data: Survival data — special bootstrap variants প্রয়োজন।
Bootstrap variants:
- Percentile: সরল 2.5–97.5%। Skewed-এ accurate।
- Basic / pivot: mirror-image — কখনো percentile-এর চেয়ে ভাল।
- BCa (bias-corrected and accelerated): Bias correction। Most accurate but complex।
- Bootstrap-t: studentize করে বেশি accurate।
Practical recommendation:
- Daraz-এর median order CI: bootstrap (skewed)।
- Pathao-এর mean ride time CI (n > ১০০): t-CI।
- A/B test conversion difference: t-CI বা proportion-CI।
- Correlation CI: bootstrap (Fisher-z-এর alternative)।
মূল উপলব্ধি: Bootstrap powerful কিন্তু not magical। Right tool right place।
প্র ০৩ আপনি Daraz-এর marketing manager-কে দেখাচ্ছেন: "Group A-এর mean order ৫০০ BDT, ৯৫% CI [৪২০, ৫৮০]; Group B-এর ৪৬০ BDT, CI [৩৮০, ৫৪০]"। তিনি বললেন "একটা ৫০০ আরেকটা ৪৬০ — তো A বেশি!"। আপনি কী বলবেন?
এটি data scientist-এর দৈনিক চ্যালেঞ্জ — non-statistician decision-makers-এর সাথে uncertainty communicate করা।
সমস্যা — overlap of CIs:
- Group A: [৪২০, ৫৮০]।
- Group B: [৩৮০, ৫৪০]।
- ৪২০-৫৪০ দু'টোতেই overlap। অর্থাৎ — দু'টোর mean একই হতেও পারে।
আপনি যা বলবেন:
- "স্যার, point estimate-এ ৪০ BDT পার্থক্য — কিন্তু uncertainty বিবেচনায় এই পার্থক্য statistically significant নাও হতে পারে।"
- "দু'টি CI overlap করছে — মানে আমরা confident না বলতে যে A আসলেই B-এর চেয়ে বেশি।"
- "আমি direct comparison test (t-test) করে দেখি — যদি p < ০.০৫ তবেই business-decision নেওয়া উচিত।"
কেন CI-overlap rule সম্পূর্ণ না:
- CI overlap থাকলেও difference significant হতে পারে (rare but possible)।
- CI overlap না থাকলে — significant (always)।
- সর্বদা — direct difference-এর CI/test করুন।
Difference-এর CI:
- $\bar{x}_A - \bar{x}_B = 40$ BDT।
- SE of difference = $\sqrt{\text{SE}_A^2 + \text{SE}_B^2}$।
- ৯৫% CI on difference: $40 \pm 1.96 \cdot \text{SE}_\text{diff}$।
- যদি এই CI ০ ধারণ করে — significant না।
Decision framework:
- Statistical significance: p-value, CI on diff।
- Practical significance: ৪০ BDT difference business-meaningful কি?
- Sample size: যদি ছোট — আরো sample collect।
- Cost-benefit: A-implementation cost বেশি? — তাহলে strong evidence চাই।
Communication tips:
- Visual — দু'টি CI bar plot দেখান।
- "What-if" — "A-কে আসলে ৩০ BDT লাভে move করতে হলে কত sample চাই?"
- Plain language — "uncertainty" ভাল term, "noise" ও।
Manager-এর response:
- সাধারণ reply: "আচ্ছা, তবে আরো ২ সপ্তাহ test চালাই।"
- Eager reply: "Sample double করতে পারি কি?"
- Frustrated reply: "Stat irrelevant, আমার gut বলে A!" — political conversation।
মূল উপলব্ধি: Number alone misleading; uncertainty আবশ্যক। Data scientist-এর সবচেয়ে বড় skill — uncertainty সম্প্রচার করা।
প্র ০৪ "৯৯% CI কি ৯৫%-এর চেয়ে বেশি ভাল?" — আপনার client এই প্রশ্ন করেছেন। কীভাবে ব্যাখ্যা করবেন? কখন কোনটা?
এটি common confusion — "higher percent" সবসময় "better" না।
সমস্যা — wider CI মানে কম informative:
- ৯৫% CI: $\bar{x} \pm 1.96 \cdot \text{SE}$।
- ৯৯% CI: $\bar{x} \pm 2.58 \cdot \text{SE}$ — ৩১% wider।
- ৯৯.৯% CI: $\bar{x} \pm 3.29 \cdot \text{SE}$ — ৬৮% wider।
Trade-off:
- উচ্চ confidence = wider interval = কম useful।
- "১০০% CI" = (-∞, ∞) — completely useless।
- "০% CI" = single point = unrealistic certainty।
কখন ৯৫%:
- Default in social science, business, ML।
- Routine A/B test, dashboard metrics।
- Exploratory analysis।
কখন ৯৯%:
- High-stakes decision: drug trial, financial risk model।
- Multiple comparisons (Bonferroni adjustment): 20 test, প্রতিটিতে ৯৯.৭৫% (i.e., α/n)।
- Regulatory: FDA, financial compliance — ৯৯%+ standard।
কখন ৯০% বা কম:
- Exploratory phase — quick directional signal।
- Resource-constrained — sample বাড়ানো ব্যয়সাধ্য।
- Multiple parallel experiments — false-positive cost কম।
Confidence level কি change হবে?
- Pre-registered: study design-এর আগে fix। p-hacking-এর বিরুদ্ধে।
- Post-hoc: "ও, ৯৫%-এ significant না, ৯০% try করি" — সাবধান। Garbage statistics।
Bangladesh-specific:
- BBS national survey — ৯৫% CI standard।
- Drug regulatory (DGDA) — ৯৯% common।
- bKash-এর fraud model deployment — ৯৯% (false positive cost বেশি)।
- Daraz-এর product recommendation — ৯০% even (rapid iteration)।
Communicating to client:
- "৯৯% CI বেশি conservative — কিন্তু wider, কম actionable।"
- "Decision-cost-এর উপর depend — ভুল decision-এ কত খরচ?"
- "Standard practice ৯৫% — যদি আপনার domain regulatory issue থাকে — ৯৯%।"
মূল উপলব্ধি: Confidence level — risk tolerance-এর reflection। One-size-fits-all নেই; context dictate করে।
অনুশীলন
-
হিসাব করুন: n=৬৪, $\bar{x}$ = ১০০, $s$ = ১৬। ৯৫% CI কত? n=৪ হলে কী?
- n=৬৪: SE = ১৬/৮ = ২। CI = ১০০ ± ১.৯৬×২ ≈ (৯৬.১, ১০৩.৯)।
- n=৪: SE = ১৬/২ = ৮। t(df=৩, .০২৫) = ৩.১৮২। CI = ১০০ ± ২৫.৪৬ ≈ (৭৪.৫, ১২৫.৫)। অনেক wider!
-
scipy দিয়ে: ৩০টি random number normal(50, 10) থেকে — t-CI গণনা করুন।
import numpy as np from scipy import stats np.random.seed(0) x = np.random.normal(50, 10, 30) mean, se = x.mean(), stats.sem(x) ci = stats.t.interval(0.95, df=29, loc=mean, scale=se) print(f"mean={mean:.2f}, 95% CI={ci}")True mean ৫০ — CI সাধারণত এই মান ধারণ করবে। বহুবার চালালে ~৯৫% সময়।
-
ভাবুন: Pathao A/B test-এ control conversion ১০%, treatment ১২%। CI overlap করছে। Manager-কে কী বলবেন? Sample size বাড়ালে কী হবে?
প্র ০৩-এ details। সংক্ষেপে: difference-এর সরাসরি CI/test দেখান, ০ ধারণ করছে কি না দেখুন। Sample size বাড়ালে CI সংকীর্ণ হয়ে significance detect সম্ভব। Effect size + cost-of-decision-এর উপর recommendation নির্ভর।
আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ
- পাঠ ১২ · t-test পরবর্তী পাঠ CI ও hypothesis test — দু'টি একই coin-এর দু'পিঠ।
- পাঠ ১০ · Sampling ও CLT আগের পাঠ CI-র গাণিতিক ভিত্তি — CLT।
- পাঠ ১৫ · A/B testing এই পাঠের সাথে সম্পর্কিত A/B test result CI দিয়েই report — practical CI।
- সব AI Courses দেখুন ABCL TECH Python, ML, DL, NLP, CV, GenAI, RL, MLOps — সব AI কোর্স একসাথে।