The Iceman, the Doctor & the Opinion PollIceman, Doctor और Opinion Poll冰人、医生与民意调查
In 1991, two hikers in the Alps found a frozen body — now famous as Ötzi the Iceman. Nobody could go back in time to watch him live. Yet scientists answered two questions with evidence. Radiocarbon dating showed that he died about 5,300 years ago. Studies of his bones and teeth showed that he was about 45 years old when he died. Not a guess. Not a certainty. An estimate with a margin of error.
1991 में Alps में दो hikers को एक जमा हुआ शरीर मिला — आज वह Ötzi the Iceman के नाम से मशहूर है। कोई समय में पीछे जाकर उसे जीते हुए नहीं देख सकता था। फिर भी वैज्ञानिकों ने सबूतों से दो सवालों के जवाब दिए। Radiocarbon dating से पता चला कि उसकी मौत लगभग 5,300 साल पहले हुई। उसकी हड्डियों और दाँतों की जाँच से पता चला कि मौत के समय वह लगभग 45 साल का था। अंदाज़ा नहीं। पक्का भी नहीं। Margin of error के साथ एक estimate।
1991 年,两名徒步者在阿尔卑斯山发现了一具冰冻的遗体 —— 也就是后来著名的冰人奥茨(Ötzi)。没有人能回到过去看他生活。但科学家用证据回答了两个问题。放射性碳定年表明他死于大约 5,300 年前。对他骨骼和牙齿的研究表明,他去世时大约 45 岁。不是瞎猜,也不是确定无疑,而是一个带误差范围的估计。
A doctor measures a patient's blood pressure three times and says: "Your average systolic pressure is 138 mmHg — we should look into it." She did not measure every heartbeat of the patient's life. She took a small sample and made an inference about the patient's true, usual blood pressure.
एक doctor मरीज़ का blood pressure तीन बार मापकर कहती है: "आपका औसत systolic pressure 138 mmHg है — इसकी जाँच करनी चाहिए।" उसने मरीज़ की ज़िंदगी की हर धड़कन नहीं मापी। उसने छोटा sample लिया और मरीज़ के असली, सामान्य blood pressure के बारे में inference किया।
医生给病人测了三次血压,然后说:“你的平均收缩压是 138 mmHg —— 我们应该进一步检查。”她没有测量病人一生中的每一次心跳。她只取了一个小样本,然后推断病人真实的、平时的血压。
Before an election, a poll says: "Party A will get 43% of votes — margin of error ±3%, 95% confidence." That one sentence holds all of estimation theory: a point estimate (43%), an interval estimate (40%–46%), a confidence level (95%) and a margin of error (±3%). This tutorial explains what each number means — and what it does not mean.
चुनाव से पहले एक poll कहता है: "Party A को 43% वोट मिलेंगे — margin of error ±3%, 95% confidence." इस एक वाक्य में पूरी estimation theory है: एक point estimate (43%), एक interval estimate (40%–46%), एक confidence level (95%) और एक margin of error (±3%)। यह tutorial बताता है कि हर संख्या का क्या मतलब है — और क्या मतलब नहीं है।
选举前,一项民调说:“A 党将获得 43% 的选票 —— 误差范围 ±3%,置信水平 95%。”这一句话包含了整个估计理论:点估计(43%)、区间估计(40%–46%)、置信水平(95%)和误差范围(±3%)。本教程解释每个数字的含义 —— 以及它不代表什么。
Estimation theory tells us how to make such estimates, how precise they are, and how much to trust them. It is the engine behind clinical trials, quality control, A/B tests, credit-risk models and most data-driven decisions.
Estimation theory बताती है कि ऐसे estimates कैसे बनाएँ, वे कितने सटीक हैं, और उन पर कितना भरोसा करें। यही clinical trials, quality control, A/B tests, credit-risk models और ज़्यादातर data-आधारित फ़ैसलों का इंजन है।
估计理论告诉我们如何做出这样的估计、它们有多精确、以及该多大程度相信它们。它是临床试验、质量控制、A/B 测试、信用风险模型以及大多数数据驱动决策背后的引擎。
The Two Branches of EstimationEstimation की दो शाखाएँ估计的两大分支
When you have a sample and want to say something about the population, you have two tools. You can give a single best-guess number, or a range of believable values. You almost always need both.
जब आपके पास sample हो और आप population के बारे में कुछ कहना चाहें, तो दो tools हैं। आप एक सबसे अच्छा अनुमान (एक संख्या) दे सकते हैं, या भरोसेमंद values की एक range। लगभग हमेशा दोनों चाहिए।
当你有一个样本、想对总体下结论时,有两种工具:给出一个最佳猜测数值,或给出一个可信数值的范围。你几乎总是两者都需要。
- One number as the best guessसबसे अच्छे अनुमान के रूप में एक संख्या一个数作为最佳猜测
- e.g. x̄ estimates μजैसे x̄, μ का अनुमान如 x̄ 估计 μ
- Simple, but shows no uncertaintyआसान, पर अनिश्चितता नहीं दिखाता简单,但不显示不确定性
- "mean salary = ₹42,000""औसत salary = ₹42,000"“平均工资 = ₹42,000”
- Lower and upper limitsनिचली और ऊपरी सीमा下限和上限
- Shows the uncertaintyअनिश्चितता दिखाता है显示不确定性
- Built from the sampling distributionSampling distribution से बनता है基于抽样分布
- "₹39,500 to ₹44,500""₹39,500 से ₹44,500"“₹39,500 到 ₹44,500”
- How often the method succeedsतरीका कितनी बार सफल होता है方法成功的频率
- NOT the chance μ is in one intervalकिसी एक interval में μ होने का chance नहीं不是 μ 落在某个区间内的概率
- Higher level → wider intervalऊँचा level → चौड़ा interval水平越高 → 区间越宽
- 95% is the usual convention95% आम परंपरा है95% 是常用惯例
A 95% confidence interval does NOT mean "there is a 95% chance that μ is inside this interval". The true mean μ is fixed. Your interval either contains it or it does not. The 95% means: if we repeated the whole sampling process many times, about 95 out of every 100 intervals would contain μ. The confidence is in the method, not in one interval.
95% confidence interval का मतलब यह नहीं कि "μ के इस interval में होने का chance 95% है"। असली mean μ तय है। आपका interval या तो उसे रखता है या नहीं। 95% का मतलब है: अगर हम पूरी sampling प्रक्रिया कई बार दोहराएँ, तो हर 100 में से लगभग 95 intervals μ को शामिल करेंगे। भरोसा तरीके पर है, किसी एक interval पर नहीं।
95% 置信区间并不表示“μ 落在这个区间内的概率是 95%”。真实均值 μ 是固定的,你的区间要么包含它,要么不包含。95% 的意思是:如果把整个抽样过程重复很多次,每 100 个区间中大约有 95 个会包含 μ。置信度属于方法,而不是某一个区间。
Estimation in Pictures — Understand Before the Mathsतस्वीरों में Estimation — गणित से पहले समझें图解估计 — 先理解,再算数
Think of an estimator as an archer. Each sample gives one shot. A good archer hits the centre on average (no bias) and keeps the shots close together (low variance).
Estimator को एक तीरंदाज़ समझें। हर sample एक तीर है। अच्छा तीरंदाज़ औसतन केंद्र पर मारता है (कोई bias नहीं) और तीरों को पास-पास रखता है (कम variance)।
把估计量想象成一名弓箭手。每个样本射出一箭。好弓箭手平均命中靶心(无偏),而且箭彼此靠近(方差小)。
Left: the interval is x̄ ± MoE. Right: 20 real samples of n = 25 from a population with μ = 50 — 19 intervals catch μ, one (red) misses. That is what "95%" looks like.
बाएँ: interval = x̄ ± MoE। दाएँ: μ = 50 वाली population से n = 25 के 20 असली samples — 19 intervals μ को पकड़ते हैं, एक (लाल) चूकता है। "95%" ऐसा दिखता है।
左:区间 = x̄ ± MoE。右:从 μ = 50 的总体中抽取的 20 个 n = 25 的真实样本 —— 19 个区间包含 μ,1 个(红色)没有。这就是“95%”的样子。
Point Estimation — The Best Single GuessPoint Estimation — सबसे अच्छा एक अनुमान点估计 — 最佳单一猜测
A point estimator is a formula (a statistic) that turns sample data into one number — the best guess of an unknown population parameter. The common ones are:
Point estimator एक formula (statistic) है जो sample data को एक संख्या में बदलता है — अज्ञात population parameter का सबसे अच्छा अनुमान। आम estimators ये हैं:
点估计量是一个公式(统计量),把样本数据变成一个数 —— 对未知总体参数的最佳猜测。常见的有:
| Population parameterPopulation parameter总体参数 | SymbolSymbol符号 | Point estimatorPoint estimator点估计量 | FormulaFormula公式 |
|---|---|---|---|
| Population meanPopulation mean总体均值 | μ | Sample meanSample mean样本均值 | x̄ = Σxᵢ / n |
| Population variancePopulation variance总体方差 | σ² | Sample varianceSample variance样本方差 | s² = Σ(xᵢ − x̄)² / (n − 1) |
| Population SDPopulation SD总体标准差 | σ | Sample SDSample SD样本标准差 | s = √s² |
| Population proportionPopulation proportion总体比例 | P | Sample proportionSample proportion样本比例 | p̂ = x / n |
Properties of a good estimatorअच्छे estimator के गुण好估计量的性质
| Propertyगुण性质 | What it meansमतलब含义 | Exampleउदाहरण例子 |
|---|---|---|
| UnbiasednessUnbiasedness无偏性 | On average, the estimator equals the true parameterऔसतन estimator असली parameter के बराबर होता है平均而言,估计量等于真实参数 | E(x̄) = μ, E(s²) = σ² unbiasedunbiased无偏 |
| ConsistencyConsistency一致性 | The estimate gets closer to the truth as n → ∞n → ∞ होने पर अनुमान सच के और पास आता हैn → ∞ 时估计值越来越接近真值 | x̄ → μ as n growsn बढ़ने पर x̄ → μn 增大时 x̄ → μ |
| EfficiencyEfficiency有效性 | The smallest variance among unbiased estimatorsUnbiased estimators में सबसे कम variance无偏估计量中方差最小 | For normal data, x̄ beats the median: Var(median) ≈ 1.57 × Var(x̄) for large nNormal data में x̄, median से बेहतर: बड़े n पर Var(median) ≈ 1.57 × Var(x̄)对正态数据,x̄ 优于中位数:n 较大时 Var(中位数) ≈ 1.57 × Var(x̄) |
| SufficiencySufficiency充分性 | Captures all the information the sample has about the parameterParameter के बारे में sample की सारी जानकारी रखता है包含样本中关于该参数的全部信息 | x̄ is sufficient for μ in a normal population (σ known)Normal population में (σ ज्ञात) x̄, μ के लिए sufficient है正态总体(σ 已知)中 x̄ 对 μ 是充分的 |
We measure deviations from the sample mean x̄, not the true mean μ. The sample mean always sits in the middle of its own data, so the deviations come out a little too small. Dividing by n would underestimate σ² by the factor (n − 1)/n. Dividing by n − 1 fixes this exactly, so E(s²) = σ². Careful: s itself is still slightly biased low (for n = 5, about 6% too small on average). That is normal and accepted — the t-interval already allows for it.
हम deviations sample mean x̄ से नापते हैं, असली mean μ से नहीं। Sample mean हमेशा अपने data के बीच में होता है, इसलिए deviations थोड़े छोटे आते हैं। n से भाग देने पर σ² का (n − 1)/n गुना कम अनुमान आता है। n − 1 से भाग देना इसे ठीक कर देता है, यानी E(s²) = σ²। ध्यान दें: s ख़ुद अब भी थोड़ा नीचे की ओर biased है (n = 5 पर औसतन लगभग 6% छोटा)। यह सामान्य और स्वीकार्य है — t-interval इसका ध्यान पहले से रखता है।
我们是从样本均值 x̄ 而不是真实均值 μ 计算偏差的。样本均值总在自己数据的中间,所以偏差会偏小一点。除以 n 会把 σ² 低估为 (n − 1)/n 倍。除以 n − 1 正好修正了这一点,使 E(s²) = σ²。注意:s 本身仍略微偏低(n = 5 时平均约小 6%)。这是正常的、可以接受的 —— t 区间已经考虑了这一点。
import numpy as np
# Check bias: 100,000 samples of n = 5 from a population with σ = 10 (σ² = 100)
rng = np.random.default_rng(1)
X = rng.normal(50, 10, size=(100_000, 5))
print(f"Average s² with ddof=0 (÷ n) : {X.var(axis=1, ddof=0).mean():6.2f} (true σ² = 100)")
print(f"Average s² with ddof=1 (÷ n − 1): {X.var(axis=1, ddof=1).mean():6.2f} (true σ² = 100)")
print(f"Average s with ddof=1 : {X.std(axis=1, ddof=1).mean():6.2f} (true σ = 10)")
Population: normal with μ = 50, σ = 10 (σ² = 100). Pick an estimator and n, then draw samples. The blue line is the true value; the amber dashed line is the average of all estimates. If they match, the estimator is unbiased. A narrower histogram means a more efficient estimator.
Population: normal, μ = 50, σ = 10 (σ² = 100)। एक estimator और n चुनें, फिर samples निकालें। नीली line असली value है; नारंगी dashed line सारे अनुमानों का औसत है। दोनों मिलें तो estimator unbiased है। पतला histogram मतलब ज़्यादा efficient estimator.
总体:正态分布,μ = 50,σ = 10(σ² = 100)。选择一个估计量和 n,然后抽样。蓝线是真实值;橙色虚线是所有估计值的平均。两者重合就说明无偏。直方图越窄,估计量越有效。
Interval Estimation & Confidence Intervals ⭐Interval Estimation और Confidence Intervals ⭐区间估计与置信区间 ⭐
A point estimate is useful but incomplete. It gives the best guess but says nothing about how uncertain that guess is. A mean salary of ₹42,000 from 10 workers is much less reliable than ₹42,000 from 10,000 workers. An interval estimate shows this by giving a range of believable values for the parameter.
Point estimate उपयोगी है, पर अधूरा। यह सबसे अच्छा अनुमान देता है, पर यह नहीं बताता कि अनुमान कितना अनिश्चित है। 10 workers से मिली ₹42,000 की औसत salary, 10,000 workers से मिली ₹42,000 से बहुत कम भरोसेमंद है। Interval estimate parameter के लिए भरोसेमंद values की range देकर यह दिखाता है।
点估计有用,但不完整。它给出最佳猜测,却没说这个猜测有多不确定。从 10 名工人得到的平均工资 ₹42,000,远不如从 10,000 名工人得到的 ₹42,000 可靠。区间估计通过给出参数的可信数值范围来体现这一点。
A higher confidence level gives a wider interval. A 100% interval for a normal mean would run from −∞ to +∞ — perfectly sure and completely useless. The skill is to pick a level that is trustworthy (often 95%) while keeping the interval narrow enough to act on.
ऊँचा confidence level चौड़ा interval देता है। Normal mean के लिए 100% interval −∞ से +∞ तक होगा — पूरी तरह पक्का और पूरी तरह बेकार। हुनर यह है कि भरोसेमंद level चुनें (अक्सर 95%) और interval को फ़ैसले लायक़ पतला रखें।
置信水平越高,区间越宽。正态均值的 100% 区间会从 −∞ 到 +∞ —— 完全确定,却毫无用处。关键是选择一个可信的水平(通常 95%),同时让区间窄到足以指导行动。
The LED example: x̄ = 1,480 hours. Change n, s and the confidence level. Watch t*, SE and the interval change, and compare the t-interval with a z-interval. Does the interval stay above the 1,400-hour guarantee?
LED उदाहरण: x̄ = 1,480 घंटे। n, s और confidence level बदलें। t*, SE और interval को बदलते देखें, और t-interval की z-interval से तुलना करें। क्या interval 1,400 घंटे की guarantee से ऊपर रहता है?
LED 例子:x̄ = 1,480 小时。调整 n、s 和置信水平,观察 t*、SE 和区间的变化,并比较 t 区间与 z 区间。区间是否一直高于 1,400 小时的保证?
Margin of Error — The ± Number Everyone SeesMargin of Error — वह ± संख्या जो सब देखते हैं误差范围 — 人人都见过的 ± 数字
The margin of error (MoE) is half the width of a confidence interval. It is the ±3% in election polls and the "± x" next to many lab results. It tells you how far the point estimate might reasonably be from the true value, in either direction. It covers random sampling error only — not bias from a bad sample or badly worded questions.
Margin of error (MoE) confidence interval की आधी चौड़ाई है। यह election polls का ±3% है और कई lab results के आगे लिखा "± x"। यह बताता है कि point estimate असली value से किसी भी दिशा में कितना दूर हो सकता है। यह सिर्फ़ random sampling error को कवर करता है — ख़राब sample या ग़लत ढंग से पूछे गए सवालों से आए bias को नहीं।
误差范围(MoE)是置信区间宽度的一半。它就是选举民调里的 ±3%,以及许多化验结果后面的“± x”。它告诉你点估计在两个方向上可能偏离真值多远。它只涵盖随机抽样误差 —— 不包括坏样本或问题措辞不当造成的偏差。
For a proportion at 95% confidence and the worst case p̂ = 0.5, MoE = 1.96 × 0.5 / √n ≈ 1/√n. At n = 1,000 the MoE is about ±3.1% — good enough for most questions at a fair cost. At n = 10,000 it is about ±1.0%: 10 times the people, but only about 3 times the precision. That is why many national polls use roughly 1,000–2,000 people. Beyond that, cost grows much faster than precision.
95% confidence और सबसे बुरे case p̂ = 0.5 पर proportion के लिए MoE = 1.96 × 0.5 / √n ≈ 1/√n। n = 1,000 पर MoE लगभग ±3.1% है — ठीक-ठाक ख़र्च पर ज़्यादातर सवालों के लिए काफ़ी। n = 10,000 पर यह लगभग ±1.0% है: 10 गुना लोग, पर precision सिर्फ़ लगभग 3 गुना। इसीलिए कई national polls लगभग 1,000–2,000 लोग लेते हैं। उसके आगे ख़र्च precision से बहुत तेज़ बढ़ता है।
对于比例,在 95% 置信水平、最坏情况 p̂ = 0.5 时,MoE = 1.96 × 0.5 / √n ≈ 1/√n。n = 1,000 时 MoE 约为 ±3.1% —— 以合理成本足以回答大多数问题。n = 10,000 时约为 ±1.0%:人数多 10 倍,精度只提高约 3 倍。这就是为什么很多全国性民调只用大约 1,000–2,000 人。再往上,成本增长远快于精度。
Set the true support p and the poll size n. The top chart shows the MoE for every n. The bottom chart runs 20 real polls: each bar is p̂ ± MoE. Red bars missed the true p.
असली support p और poll size n चुनें। ऊपर का chart हर n के लिए MoE दिखाता है। नीचे का chart 20 असली polls चलाता है: हर bar p̂ ± MoE है। लाल bars असली p से चूक गए।
设置真实支持率 p 和民调人数 n。上图显示每个 n 对应的 MoE。下图进行 20 次真实民调:每条线是 p̂ ± MoE。红线没有包含真实的 p。
Step by Step: Building a Confidence IntervalStep by Step: Confidence Interval बनाना一步一步构建置信区间
A quality engineer tests 36 LED bulbs from a production line and records how many hours each lasts. She wants a 95% confidence interval for the true average lifespan of all bulbs the line makes.
एक quality engineer production line से 36 LED bulbs जाँचती है और हर bulb कितने घंटे चला, यह लिखती है। उसे line के सभी bulbs की असली औसत उम्र के लिए 95% confidence interval चाहिए।
一位质量工程师从生产线上抽取 36 只 LED 灯泡,记录每只能用多少小时。她想为这条线生产的所有灯泡的真实平均寿命构建一个 95% 置信区间。
| Sample dataSample data样本数据 | ValueValue数值 |
|---|---|
| Sample size (n)Sample size (n)样本量(n) | 36 bulbs36 bulbs36 只 |
| Sample mean (x̄)Sample mean (x̄)样本均值(x̄) | 1,480 hours1,480 घंटे1,480 小时 |
| Sample SD (s)Sample SD (s)样本标准差(s) | 120 hours120 घंटे120 小时 |
| Confidence levelConfidence level置信水平 | 95% |
| σ (population SD)σ (population SD)σ(总体标准差) | Unknown → use the t-intervalअज्ञात → t-interval इस्तेमाल करें未知 → 用 t 区间 |
Degrees of freedom df = n − 1 = 36 − 1 = 35.
For 95% with df = 35: t* = 2.030 (t-table, or
scipy.stats.t.ppf(0.975, df=35)).Degrees of freedom df = n − 1 = 36 − 1 = 35.
95% और df = 35 के लिए: t* = 2.030 (t-table, या
scipy.stats.t.ppf(0.975, df=35))।自由度 df = n − 1 = 36 − 1 = 35。
95%、df = 35 时:t* = 2.030(查 t 表,或
scipy.stats.t.ppf(0.975, df=35))。SE = s / √n = 120 / √36 = 120 / 6 = 20 hours
SE = s / √n = 120 / √36 = 120 / 6 = 20 घंटे
SE = s / √n = 120 / √36 = 120 / 6 = 20 小时
MoE = t* × SE = 2.030 × 20 = 40.6 hours
MoE = t* × SE = 2.030 × 20 = 40.6 घंटे
MoE = t* × SE = 2.030 × 20 = 40.6 小时
Lower = 1,480 − 40.6 = 1,439.4 hours
Upper = 1,480 + 40.6 = 1,520.6 hours
95% CI = (1,439.4, 1,520.6) hours
Lower = 1,480 − 40.6 = 1,439.4 घंटे
Upper = 1,480 + 40.6 = 1,520.6 घंटे
95% CI = (1,439.4, 1,520.6) घंटे
下限 = 1,480 − 40.6 = 1,439.4 小时
上限 = 1,480 + 40.6 = 1,520.6 小时
95% 置信区间 = (1,439.4, 1,520.6) 小时
Narrower (more precise): larger n, smaller s, lower confidence level.
Wider (less precise): smaller n, larger s, higher confidence level.
The lever you control best is usually sample size. Doubling n shrinks the MoE by √2 ≈ 1.41; you need 4 × n to halve it. Try it in the builder above.
पतला (ज़्यादा सटीक): बड़ा n, छोटा s, कम confidence level.
चौड़ा (कम सटीक): छोटा n, बड़ा s, ऊँचा confidence level.
आपके हाथ में सबसे अच्छा lever आम तौर पर sample size है। n दोगुना करने से MoE √2 ≈ 1.41 गुना घटता है; आधा करने के लिए 4 × n चाहिए। ऊपर के builder में आज़माएँ।
更窄(更精确):n 更大、s 更小、置信水平更低。
更宽(不够精确):n 更小、s 更大、置信水平更高。
你最能控制的通常是样本量。n 翻倍,MoE 只缩小 √2 ≈ 1.41 倍;要减半需要 4 × n。在上面的构建器里试试。
Python ImplementationPython ImplementationPython 实现
Point estimationPoint estimation点估计
import numpy as np
from scipy import stats
np.random.seed(42)
# Sample: lifespan of 36 LED bulbs (hours)
sample = np.random.normal(loc=1480, scale=120, size=36)
# Point estimates
x_bar = np.mean(sample) # estimates μ
s = np.std(sample, ddof=1) # estimates σ (n − 1 in the denominator)
n = len(sample)
print(f"Point estimate of μ (sample mean x̄): {x_bar:.2f} hrs")
print(f"Point estimate of σ (sample std s): {s:.2f} hrs")
print(f"Sample size n: {n}")
This simulated sample happens to have x̄ = 1,460.46 and s = 112.34 — not exactly the 1,480 and 120 used to create it. That gap is sampling error, and it is exactly why we need intervals.
इस simulated sample में x̄ = 1,460.46 और s = 112.34 आए — ठीक वही 1,480 और 120 नहीं जिनसे यह बना था। यह अंतर sampling error है, और इसीलिए हमें intervals चाहिए।
这个模拟样本恰好得到 x̄ = 1,460.46、s = 112.34 —— 并不正好等于生成它时用的 1,480 和 120。这个差距就是抽样误差,也正是我们需要区间的原因。
Confidence interval with the SciPy t-distributionSciPy t-distribution से Confidence interval用 SciPy 的 t 分布求置信区间
from scipy import stats
import numpy as np
np.random.seed(42)
sample = np.random.normal(loc=1480, scale=120, size=36)
x_bar = np.mean(sample)
s = np.std(sample, ddof=1)
n = len(sample)
se = s / np.sqrt(n)
# 95% and 99% CI using the t-distribution (σ unknown)
# (SciPy ≥ 1.9 uses 'confidence='; older versions used 'alpha=')
ci_95 = stats.t.interval(confidence=0.95, df=n-1, loc=x_bar, scale=se)
ci_99 = stats.t.interval(confidence=0.99, df=n-1, loc=x_bar, scale=se)
# Critical t* values
t_95 = stats.t.ppf(0.975, df=n-1)
t_99 = stats.t.ppf(0.995, df=n-1)
print(f"Standard Error (SE): {se:.2f} hrs")
print(f"t* for 95% CI (df={n-1}): {t_95:.4f}")
print(f"Margin of Error 95%: ±{t_95 * se:.2f} hrs")
print(f"95% CI: ({ci_95[0]:.2f}, {ci_95[1]:.2f}) hrs")
print(f"99% CI: ({ci_99[0]:.2f}, {ci_99[1]:.2f}) hrs")
The 95% interval (1,422.44, 1,498.47) contains the true mean of 1,480 that we used to generate the data.
95% interval (1,422.44, 1,498.47) में वह असली mean 1,480 है जिससे data बनाया गया।
95% 区间 (1,422.44, 1,498.47) 包含了生成数据时使用的真实均值 1,480。
Confidence interval for a proportionProportion के लिए Confidence interval比例的置信区间
import numpy as np
from scipy import stats
# Scenario: 420 out of 1,000 voters prefer Party A
n = 1000
x = 420 # successes
p_hat = x / n # 0.42
se_prop = np.sqrt(p_hat * (1 - p_hat) / n)
# 95% CI for a proportion (normal approximation — n is large)
z_star = stats.norm.ppf(0.975) # 1.95996...
moe = z_star * se_prop
ci_low = p_hat - moe
ci_hi = p_hat + moe
print(f"Sample proportion p̂: {p_hat:.4f} ({p_hat*100:.1f}%)")
print(f"Standard Error: {se_prop:.4f}")
print(f"Critical z*: {z_star:.4f}")
print(f"Margin of Error: ±{moe:.4f} (±{moe*100:.2f}%)")
print(f"95% CI: ({ci_low*100:.2f}%, {ci_hi*100:.2f}%)")
The simple formula p̂ ± z*√[p̂(1 − p̂)/n] (the Wald interval) works well for large n with p̂ not near 0 or 1. A common check: at least about 10 successes and 10 failures. For small samples it can even give impossible values below 0%. The Wilson interval fixes this:
आसान formula p̂ ± z*√[p̂(1 − p̂)/n] (Wald interval) बड़े n पर ठीक चलता है, जब p̂ 0 या 1 के पास न हो। आम जाँच: कम से कम लगभग 10 successes और 10 failures। छोटे samples में यह 0% से नीचे जैसी असंभव values भी दे सकता है। Wilson interval इसे ठीक करता है:
简单公式 p̂ ± z*√[p̂(1 − p̂)/n](Wald 区间)在 n 大、p̂ 不接近 0 或 1 时效果好。常用检查:成功和失败至少各约 10 次。样本小时,它甚至会给出低于 0% 这样不可能的值。Wilson 区间解决了这个问题:
import numpy as np
from scipy import stats
z_star = stats.norm.ppf(0.975) # 1.96 for a 95% CI
def wald(x, n):
p = x / n
m = z_star * np.sqrt(p * (1 - p) / n)
return p - m, p + m
def wilson(x, n):
p, z2 = x / n, z_star ** 2
centre = (p + z2 / (2 * n)) / (1 + z2 / n)
half = z_star * np.sqrt(p * (1 - p) / n + z2 / (4 * n * n)) / (1 + z2 / n)
return centre - half, centre + half
# Small sample: 2 defective items out of 25 checked
for name, f in [("Wald ", wald), ("Wilson", wilson)]:
lo, hi = f(2, 25)
print(f"{name} 95% CI: ({lo*100:6.2f}%, {hi*100:6.2f}%)")
Required sample sizeज़रूरी sample size所需样本量
import numpy as np
from scipy import stats
z_star = stats.norm.ppf(0.975) # 1.96 for a 95% CI
# Mean: how many bulbs for MoE ≤ 25 hours?
sigma = 120 # guess of σ from a pilot study
desired_moe = 25
n_mean = (z_star * sigma / desired_moe) ** 2
print(f"Required n for MoE ≤ 25 hrs: n ≥ {np.ceil(n_mean):.0f}")
# Proportion: worst case p̂ = 0.5
for moe in [0.05, 0.03, 0.02, 0.01]:
n_prop = (z_star * 0.5 / moe) ** 2
print(f"Required n for ±{moe*100:.0f}% poll: n ≥ {np.ceil(n_prop):,.0f}")
Notice the square-root law again: going from ±2% to ±1% needs four times as many people (2,401 → 9,604).
Square-root law फिर देखें: ±2% से ±1% पर जाने के लिए चार गुना लोग चाहिए (2,401 → 9,604)।
再次看到平方根定律:从 ±2% 到 ±1% 需要四倍的人数(2,401 → 9,604)。
Does "95%" really hold? A coverage checkक्या "95%" सच में सही है? Coverage check“95%”真的成立吗?覆盖率检验
import numpy as np
from scipy import stats
# Does the "95%" really hold? Repeat a study 10,000 times.
rng = np.random.default_rng(0)
mu, sigma, n, reps = 1480, 120, 10, 10_000
hits = {"t-interval (correct)": 0, "z* with s (wrong for small n)": 0}
t_star, z_star = stats.t.ppf(0.975, n - 1), stats.norm.ppf(0.975)
for _ in range(reps):
x = rng.normal(mu, sigma, n)
m, se = x.mean(), x.std(ddof=1) / np.sqrt(n)
hits["t-interval (correct)"] += abs(m - mu) <= t_star * se
hits["z* with s (wrong for small n)"] += abs(m - mu) <= z_star * se
for k, v in hits.items():
print(f"{k:31s}: {v / reps * 100:.1f}% of intervals caught μ")
With n = 10, the correct t-interval catches μ 94.9% of the time. Using z* = 1.96 with s gives intervals that are too narrow, and they catch μ only 91.9% of the time — a "95%" interval that is really about 92%. Try it yourself:
n = 10 पर सही t-interval 94.9% बार μ पकड़ता है। s के साथ z* = 1.96 लेने से intervals बहुत पतले बनते हैं, और वे सिर्फ़ 91.9% बार μ पकड़ते हैं — "95%" interval जो असल में लगभग 92% है। ख़ुद आज़माएँ:
n = 10 时,正确的 t 区间有 94.9% 的时候包含 μ。用 s 配 z* = 1.96 得到的区间太窄,只有 91.9% 的时候包含 μ —— 名为“95%”,实际约 92%。自己试试:
Each line is a 95% interval from a new sample of n values (μ = 50, σ = 10). Blue lines catch μ; red lines miss. Compare the three methods at small n (try n = 3 to 5), then raise n.
हर line n values के नए sample से बना 95% interval है (μ = 50, σ = 10)। नीली lines μ पकड़ती हैं; लाल चूकती हैं। छोटे n पर (n = 3 से 5 आज़माएँ) तीनों तरीकों की तुलना करें, फिर n बढ़ाएँ।
每条线是由一个新的 n 个数值的样本得到的 95% 区间(μ = 50,σ = 10)。蓝线包含 μ;红线没有。先在小 n(试试 n = 3 到 5)下比较三种方法,再增大 n。
Mean, σ unknown (you use s): use the t-interval, at any n. For large n it gives almost the same answer as z, so nothing is lost.
Mean, σ truly known: the z-interval is fine (rare in practice).
Proportion: use z (Wald) for large samples, or Wilson for small samples or p̂ near 0 or 1.
The t-interval assumes roughly normal data or a large enough n. For small, very skewed samples, consider a bootstrap interval instead.
Mean, σ अज्ञात (आप s इस्तेमाल करते हैं): किसी भी n पर t-interval लें। बड़े n पर यह z जैसा ही जवाब देता है, तो कुछ नहीं खोते।
Mean, σ सच में ज्ञात: z-interval ठीक है (असल में कम होता है)।
Proportion: बड़े samples में z (Wald), छोटे samples या 0/1 के पास p̂ पर Wilson.
t-interval मानता है कि data लगभग normal है या n काफ़ी बड़ा है। छोटे, बहुत skewed samples में bootstrap interval पर विचार करें।
均值,σ 未知(用 s):任何 n 都用 t 区间。n 大时它与 z 的结果几乎相同,没有损失。
均值,σ 确实已知:可用 z 区间(实际很少见)。
比例:大样本用 z(Wald),小样本或 p̂ 接近 0 或 1 时用 Wilson。
t 区间假设数据大致正态或 n 足够大。对于小而严重偏斜的样本,可考虑自助法(bootstrap)区间。
Estimation Methods — Comparison TablesEstimation Methods — तुलना Tables估计方法 — 对照表
| Propertyगुण性质 | Point estimationPoint estimation点估计 | Interval estimation (CI)Interval estimation (CI)区间估计(置信区间) |
|---|---|---|
| OutputOutput输出 | One number (x̄, p̂, s)एक संख्या (x̄, p̂, s)一个数(x̄、p̂、s) | A range (lower, upper)एक range (lower, upper)一个范围(下限,上限) |
| Shows uncertainty?अनिश्चितता दिखाता है?显示不确定性? | Noनहीं否 | Yesहाँ是 |
| Easy to communicate?समझाना आसान?容易沟通? | Very easyबहुत आसान非常容易 | Needs explanationसमझाना पड़ता है需要解释 |
| Reflects sample size?Sample size दिखता है?体现样本量? | No — 10 or 10,000 look the sameनहीं — 10 और 10,000 एक जैसे दिखते हैं否 —— 10 和 10,000 看起来一样 | Yes — through SE = s/√nहाँ — SE = s/√n से是 —— 通过 SE = s/√n |
| Useful for decisions?फ़ैसलों में उपयोगी?对决策有用? | Partlyकुछ हद तक部分 | Yesहाँ是 |
| Link to hypothesis testsHypothesis tests से संबंध与假设检验的关系 | Used inside the test statisticTest statistic के अंदर इस्तेमाल用于检验统计量 | A 95% CI that excludes a value ⇔ a two-sided test at α = 0.05 rejects it (same method)जो 95% CI किसी value को बाहर रखे ⇔ α = 0.05 पर two-sided test उसे reject करता है (वही तरीका)95% 置信区间不包含某值 ⇔ α = 0.05 的双侧检验拒绝该值(同一方法) |
| Confidence levelConfidence level置信水平 | z*z*z* | ααα | Tail area each sideहर तरफ़ tail area每侧尾部面积 | Typical useआम इस्तेमाल典型用途 |
|---|---|---|---|---|
| 90% | 1.645 | 0.10 | 5% | Early or exploratory studiesशुरुआती या exploratory studies早期或探索性研究 |
| 95% | 1.960 | 0.05 | 2.5% | Most common conventionसबसे आम परंपरा最常用的惯例 |
| 99% | 2.576 | 0.01 | 0.5% | Medical and high-stakes decisionsMedical और बड़े जोखिम वाले फ़ैसले医疗和高风险决策 |
| 99.9% | 3.291 | 0.001 | 0.05% | When a wrong claim is very costlyजब ग़लत दावा बहुत महँगा हो错误结论代价极高时 |
Golden RulesGolden Rules黄金法则
stats.t.interval(confidence=0.95, df=n-1, loc=x_bar, scale=s/np.sqrt(n)). For large n it matches z anyway.stats.t.interval(confidence=0.95, df=n-1, loc=x_bar, scale=s/np.sqrt(n))। बड़े n पर यह वैसे भी z से मिलता है।stats.t.interval(confidence=0.95, df=n-1, loc=x_bar, scale=s/np.sqrt(n))。n 大时它本来就和 z 一致。np.std(data, ddof=1) divides by n − 1, which makes s² unbiased (s is still slightly low, and that is fine). ddof=0 makes s smaller and the interval too narrow — falsely precise.np.std(data, ddof=1) n − 1 से भाग देता है, जिससे s² unbiased बनता है (s अब भी थोड़ा कम है, और वह ठीक है)। ddof=0 से s छोटा बनता है और interval बहुत पतला — झूठी precision.np.std(data, ddof=1) 除以 n − 1,使 s² 无偏(s 仍略偏小,这没关系)。ddof=0 会让 s 偏小、区间太窄 —— 虚假的精确。n = (z* × σ / MoE)² for a mean, or n = z*² × p(1 − p) / MoE² for a proportion (p = 0.5 if unknown). Finding out afterwards that the CI is too wide wastes time and money.n = (z* × σ / MoE)², proportion के लिए n = z*² × p(1 − p) / MoE² (p अज्ञात हो तो 0.5)। बाद में पता चलना कि CI बहुत चौड़ा है, समय और पैसा बर्बाद करता है।n = (z* × σ / MoE)²,比例用 n = z*² × p(1 − p) / MoE²(p 未知时取 0.5)。事后才发现区间太宽,会浪费时间和金钱。