The Courtroom, the Medicine & the FactoryCourtroom, दवा और Factory法庭、药物与工厂
Imagine you are a judge. A person stands before you, accused of a crime. In India and in most modern legal systems, the court starts from one strong assumption: the accused is innocent until proven guilty. The prosecution must bring the proof. Unless the evidence is too strong to be explained by chance or coincidence, the verdict must be not guilty.
मान लीजिए आप judge हैं। आपके सामने एक व्यक्ति है जिस पर अपराध का आरोप है। India और ज़्यादातर आधुनिक क़ानूनी व्यवस्थाओं में अदालत एक मज़बूत मान्यता से शुरू करती है: दोष साबित होने तक आरोपी बेगुनाह है। सबूत लाने का काम prosecution का है। जब तक सबूत इतना मज़बूत न हो कि उसे संयोग से समझाया न जा सके, फ़ैसला बेगुनाह ही होगा।
想象你是一名法官。一个人站在你面前,被控犯罪。在印度和大多数现代法律体系中,法庭从一个强有力的假设出发:被告在被证明有罪之前是无罪的。举证责任在控方。除非证据强到无法用巧合解释,否则判决必须是无罪。
Notice that the judge does not prove innocence. The judge only asks: "Is the evidence strong enough to reject the assumption of innocence?" A "not guilty" verdict does not mean "proven innocent". This is exactly how hypothesis testing works in statistics.
ध्यान दें, judge बेगुनाही साबित नहीं करता। Judge सिर्फ़ पूछता है: "क्या सबूत इतना मज़बूत है कि बेगुनाही की मान्यता को reject किया जाए?" "Not guilty" का मतलब "बेगुनाह साबित" नहीं है। Statistics में hypothesis testing ठीक इसी तरह काम करता है।
注意,法官并不证明无罪。法官只问:“证据是否强到足以推翻无罪假设?”“无罪判决”并不等于“已证明清白”。统计学中的假设检验正是这样运作的。
| CourtroomCourtroom法庭 | Hypothesis testHypothesis test假设检验 |
|---|---|
| Presumption of innocenceबेगुनाही की मान्यता无罪推定 | H₀ (null hypothesis)(null hypothesis)(原假设) |
| The prosecution's claim: guiltyProsecution का दावा: दोषी控方主张:有罪 | H₁ (alternative hypothesis)(alternative hypothesis)(备择假设) |
| Evidenceसबूत证据 | Sample data → test statistic → p-valueSample data → test statistic → p-value样本数据 → 检验统计量 → p 值 |
| "Beyond reasonable doubt""संदेह से परे"“排除合理怀疑” | p < α (e.g. 0.05)p < α (जैसे 0.05)p < α(如 0.05) |
| Guilty / not guiltyदोषी / दोषी नहीं有罪 / 无罪 | Reject H₀ / fail to reject H₀H₀ reject / H₀ reject नहीं拒绝 H₀ / 不拒绝 H₀ |
| Innocent person jailedबेगुनाह को सज़ा无辜者入狱 | Type I error (α)Type I error (α)第一类错误(α) |
| Guilty person goes freeदोषी छूट जाता है罪犯逍遥法外 | Type II error (β)Type II error (β)第二类错误(β) |
A drug company says a new drug lowers blood pressure more than the current one. Is the improvement real, or luck in the trial? A factory manager thinks her machine makes bolts heavier than the 50 g specification. How many bolts must she weigh? An e-commerce team runs an A/B test: Button A converts at 4.2%, Button B at 4.7%. Is the difference real or just noise? All three use one tool: hypothesis testing.
एक दवा कंपनी कहती है कि नई दवा मौजूदा दवा से ज़्यादा blood pressure घटाती है। क्या सुधार असली है, या trial में किस्मत? एक factory manager को लगता है कि उसकी मशीन 50 g specification से भारी bolts बनाती है। उसे कितने bolts तौलने होंगे? एक e-commerce team A/B test चलाती है: Button A 4.2% पर convert करता है, Button B 4.7% पर। क्या अंतर असली है या बस शोर? तीनों एक ही tool इस्तेमाल करते हैं: hypothesis testing।
一家制药公司声称新药降血压的效果优于现有药物。这种改善是真实的,还是试验中的运气?一位工厂经理怀疑她的机器生产的螺栓比 50 g 的规格更重。她需要称多少个螺栓?一个电商团队做 A/B 测试:按钮 A 转化率 4.2%,按钮 B 4.7%。这个差异是真的还是噪声?三者都用同一个工具:假设检验。
Hypothesis testing is a formal way to decide whether sample data give enough evidence against a specific claim about a population. It is used in clinical trials, quality control, A/B testing and a large share of published research.
Hypothesis testing यह तय करने का औपचारिक तरीका है कि क्या sample data population के किसी ख़ास दावे के ख़िलाफ़ काफ़ी सबूत देता है। इसका इस्तेमाल clinical trials, quality control, A/B testing और बहुत सारी प्रकाशित research में होता है।
假设检验是一种正式方法,用来判断样本数据是否提供了足够证据来反驳关于总体的某个具体论断。它被用于临床试验、质量控制、A/B 测试以及大量已发表的研究。
What Is a Hypothesis Test?Hypothesis Test क्या है?什么是假设检验?
A statistical hypothesis is a testable claim about a population parameter — a mean, a proportion, a difference. The test uses sample data to judge that claim. Everything rests on one question:
Statistical hypothesis किसी population parameter के बारे में जाँचने लायक़ दावा है — mean, proportion, या अंतर। Test sample data से उस दावे को परखता है। सब कुछ एक सवाल पर टिका है:
统计假设是关于总体参数(均值、比例、差异)的可检验论断。检验用样本数据来评判这个论断。一切都基于一个问题:
"If H₀ were true, how likely is it to see data at least this extreme just by chance?"
That probability is the p-value. If it is smaller than a threshold set in advance — the significance level α — we call the result statistically significant and reject H₀. If not, we fail to reject H₀.
"अगर H₀ सच होता, तो सिर्फ़ संयोग से कम से कम इतना extreme data दिखने की कितनी संभावना है?"
यही संभावना p-value है। अगर यह पहले से तय सीमा — significance level α — से छोटी है, तो नतीजा statistically significant है और हम H₀ reject करते हैं। नहीं तो, हम H₀ reject नहीं करते।
“如果 H₀ 为真,仅凭偶然看到至少这么极端的数据的可能性有多大?”
这个概率就是 p 值。如果它小于事先设定的阈值 —— 显著性水平 α —— 就称结果统计显著,并拒绝 H₀。否则,不拒绝 H₀。
- The default assumptionडिफ़ॉल्ट मान्यता默认假设
- "No effect, no difference""कोई effect नहीं, कोई अंतर नहीं"“没有效应,没有差异”
- Contains =, ≤ or ≥=, ≤ या ≥ रखता है含 =、≤ 或 ≥
- We look for evidence against itहम इसके ख़िलाफ़ सबूत ढूँढते हैं我们寻找反驳它的证据
- What we want to showजो हम दिखाना चाहते हैं我们想证明的
- "There is an effect""Effect है"“存在效应”
- Contains ≠, < or >≠, < या > रखता है含 ≠、< 或 >
- Supported only if H₀ is rejectedसिर्फ़ H₀ reject होने पर समर्थन只有拒绝 H₀ 才得到支持
- p < α → reject H₀p < α → H₀ rejectp < α → 拒绝 H₀
- p ≥ α → fail to reject H₀p ≥ α → H₀ reject नहींp ≥ α → 不拒绝 H₀
- α = 0.05 is the common defaultα = 0.05 आम डिफ़ॉल्ट हैα = 0.05 是常用默认值
- Never say "accept H₀""H₀ accept" कभी न कहें永远不说“接受 H₀”
Hypothesis Testing in Pictures — Understand Before the Mathsतस्वीरों में Hypothesis Testing — गणित से पहले समझें图解假设检验 — 先理解,再算数
Three pictures hold the whole idea. First: where does our result fall if H₀ is true? Second: what can go wrong? Third: how big are those risks?
तीन तस्वीरों में पूरा विचार है। पहली: अगर H₀ सच है, तो हमारा नतीजा कहाँ गिरता है? दूसरी: क्या ग़लत हो सकता है? तीसरी: वे जोखिम कितने बड़े हैं?
三张图概括了全部思想。第一:如果 H₀ 为真,我们的结果落在哪里?第二:可能出什么错?第三:这些风险有多大?
Null vs Alternative Hypothesis — In DepthNull vs Alternative Hypothesis — विस्तार से原假设 vs 备择假设 — 深入理解
H₀ and H₁ are two competing statements. They must not overlap, and together they must cover every possibility. Writing them correctly is the most important skill in hypothesis testing.
H₀ और H₁ दो प्रतिस्पर्धी कथन हैं। वे एक-दूसरे पर overlap नहीं करते, और मिलकर हर संभावना को कवर करते हैं। इन्हें सही लिखना hypothesis testing का सबसे ज़रूरी हुनर है।
H₀ 和 H₁ 是两个相互竞争的陈述。它们不能重叠,并且合起来要覆盖所有可能。正确写出它们是假设检验中最重要的技能。
| Aspectपहलू方面 | H₀ — null— null— 原假设 | H₁ — alternative— alternative— 备择假设 |
|---|---|---|
| Roleभूमिका角色 | The default, status-quo claim; assumed true until the data say otherwiseडिफ़ॉल्ट दावा; data के कुछ और कहने तक सच माना जाता है默认的现状论断;在数据表明相反之前视为真 | What the researcher wants to showResearcher जो दिखाना चाहता है研究者想证明的 |
| Signचिह्न符号 | =, ≤, ≥ | ≠, >, < |
| Outcomeनतीजा结果 | Never "proved" — only rejected or not rejectedकभी "साबित" नहीं — सिर्फ़ reject या नहीं永远不会被“证明” —— 只有拒绝或不拒绝 | Supported when H₀ is rejectedH₀ reject होने पर समर्थन拒绝 H₀ 时得到支持 |
| Drug trialDrug trial药物试验 | μ_new = μ_old | μ_new > μ_old (drug is better)(दवा बेहतर)(新药更好) |
| Factory boltFactory bolt工厂螺栓 | μ = 50 g | μ ≠ 50 g (off specification)(specification से हटा)(偏离规格) |
The three test typesतीन तरह के tests三种检验类型
| Test typeTest type检验类型 | H₀ | H₁ | Rejection regionRejection region拒绝域 | Questionसवाल问题 |
|---|---|---|---|---|
| Two-tailedTwo-tailed双侧 | μ = μ₀ | μ ≠ μ₀ | Both tails (α/2 each)दोनों tails (हर एक में α/2)两侧(各 α/2) | "Is the mean different from 50 g?""क्या mean 50 g से अलग है?"“均值是否不同于 50 g?” |
| Right-tailedRight-tailed右侧 | μ ≤ μ₀ | μ > μ₀ | Right tail only (α)सिर्फ़ दाईं tail (α)仅右侧(α) | "Is the mean more than 50 g?""क्या mean 50 g से ज़्यादा है?"“均值是否大于 50 g?” |
| Left-tailedLeft-tailed左侧 | μ ≥ μ₀ | μ < μ₀ | Left tail only (α)सिर्फ़ बाईं tail (α)仅左侧(α) | "Is the mean less than 50 g?""क्या mean 50 g से कम है?"“均值是否小于 50 g?” |
Beginners often put their own claim in H₀. Do the opposite. H₀ is the sceptic's position: "nothing has changed, there is no effect". The thing you want to establish goes in H₁. You collect evidence against H₀, just as a prosecutor builds a case against the presumption of innocence.
शुरुआती लोग अक्सर अपना दावा H₀ में रख देते हैं। इसका उल्टा करें। H₀ शक करने वाले की स्थिति है: "कुछ नहीं बदला, कोई effect नहीं"। जो आप साबित करना चाहते हैं, वह H₁ में जाता है। आप H₀ के ख़िलाफ़ सबूत जुटाते हैं, जैसे prosecutor बेगुनाही की मान्यता के ख़िलाफ़ केस बनाता है।
初学者常把自己的主张放进 H₀。要反过来。H₀ 是怀疑者的立场:“什么都没变,没有效应”。你想确立的东西放在 H₁。你收集反驳 H₀ 的证据,就像检察官针对无罪推定构建案件。
Significance Level α and the p-valueSignificance Level α और p-value显著性水平 α 与 p 值
Before collecting data, choose the significance level α: the largest risk of wrongly rejecting a true H₀ that you will accept. After collecting data, compute the p-value. Then compare the two.
Data जुटाने से पहले significance level α चुनें: सच्चे H₀ को ग़लती से reject करने का सबसे बड़ा जोखिम जो आप स्वीकार करेंगे। Data जुटाने के बाद p-value निकालें। फिर दोनों की तुलना करें।
收集数据之前,选定显著性水平 α:你愿意接受的、错误拒绝真实 H₀ 的最大风险。收集数据之后,计算 p 值。然后比较两者。
❌ "The probability that H₀ is true." — False.
❌ "The probability that the result is due to chance." — False.
❌ "The size or importance of the effect." — False.
❌ "p = 0.06 means there is no effect." — False; it means the evidence is not strong enough.
✅ p-value means: assuming H₀ is true, the probability of data at least this extreme. With a huge n, a tiny, useless effect can give a very small p. Always report an effect size too.
❌ "H₀ के सच होने की संभावना।" — ग़लत।
❌ "नतीजा संयोग से आने की संभावना।" — ग़लत।
❌ "Effect का आकार या महत्व।" — ग़लत।
❌ "p = 0.06 मतलब कोई effect नहीं।" — ग़लत; इसका मतलब है सबूत काफ़ी मज़बूत नहीं।
✅ p-value का मतलब: यह मानकर कि H₀ सच है, कम से कम इतना extreme data मिलने की संभावना। बहुत बड़े n पर छोटा, बेकार effect भी बहुत छोटा p दे सकता है। हमेशा effect size भी बताएँ।
❌ “H₀ 为真的概率。”—— 错。
❌ “结果由偶然造成的概率。”—— 错。
❌ “效应的大小或重要性。”—— 错。
❌ “p = 0.06 说明没有效应。”—— 错;它只说明证据不够强。
✅ p 值的意思是:假设 H₀ 为真,得到至少这么极端数据的概率。n 很大时,微小而无用的效应也能得到很小的 p。一定要同时报告效应量。
H₀: μ = 50 g, with s = 2.8 g. Move the sample mean and the sample size. The orange area is the p-value; the red area is α. When the orange area fits inside the red area, p < α and we reject H₀. Try changing the test type too.
H₀: μ = 50 g, s = 2.8 g. Sample mean और sample size बदलें। नारंगी area p-value है; लाल area α है। जब नारंगी area लाल के अंदर आ जाए, तब p < α और हम H₀ reject करते हैं। Test type भी बदलकर देखें।
H₀:μ = 50 g,s = 2.8 g。拖动样本均值和样本量。橙色面积是 p 值;红色面积是 α。当橙色面积落在红色区域内时,p < α,拒绝 H₀。也试试改变检验类型。
Type I & Type II Errors — The Cost of Being WrongType I और Type II Errors — ग़लत होने की क़ीमत第一类与第二类错误 — 犯错的代价
However carefully you design a test, two kinds of error are always possible. Think of a medical test: a Type I error is a false positive (the test says "disease" but you are healthy); a Type II error is a false negative (the test says "healthy" but you are ill).
Test कितनी भी सावधानी से design करें, दो तरह की ग़लतियाँ हमेशा संभव हैं। एक medical test सोचें: Type I error false positive है (test "बीमारी" कहता है पर आप स्वस्थ हैं); Type II error false negative है (test "स्वस्थ" कहता है पर आप बीमार हैं)।
无论检验设计得多仔细,两种错误总是可能发生。想想医学检测:第一类错误是假阳性(检测说“有病”,其实你很健康);第二类错误是假阴性(检测说“健康”,其实你病了)。
| Error typeError type错误类型 | Also calledदूसरा नाम又称 | ProbabilityProbability概率 | What happenedक्या हुआ发生了什么 | Real-world costअसली क़ीमत现实代价 |
|---|---|---|---|---|
| Type I errorType I error第一类错误 | False positiveFalse positive假阳性 | α (you choose it)α (आप चुनते हैं)α(由你设定) | Rejected H₀, but H₀ was trueH₀ reject किया, पर H₀ सच था拒绝了 H₀,但 H₀ 为真 | Approving a drug that does not workबेअसर दवा को मंज़ूरी批准了无效的药 |
| Type II errorType II error第二类错误 | False negativeFalse negative假阴性 | β (depends on n, effect size, σ and α)β (n, effect size, σ और α पर निर्भर)β(取决于 n、效应量、σ 和 α) | Kept H₀, but H₀ was falseH₀ रखा, पर H₀ ग़लत था保留了 H₀,但 H₀ 为假 | Dropping a drug that really worksअसरदार दवा को छोड़ देना放弃了真正有效的药 |
| PowerPower检验力 | SensitivitySensitivity灵敏度 | 1 − β | Correctly rejected a false H₀ग़लत H₀ को सही reject किया正确拒绝了错误的 H₀ | Detecting a real effect — usually planned at 80% or moreअसली effect पकड़ना — आम तौर पर 80% या ज़्यादा发现真实效应 —— 通常设计为 80% 或更高 |
Making α smaller (0.05 → 0.01) makes Type I errors rarer — but, with the same data, it increases β, because you now need stronger evidence to reject H₀. The main way to reduce both is a larger sample. Clinical trials therefore fix α (often 0.05 two-sided) and a target power (often 80–90%) and use them to work out the trial size before the first patient joins.
α छोटा करने (0.05 → 0.01) से Type I errors कम होते हैं — पर उसी data के साथ β बढ़ता है, क्योंकि अब H₀ reject करने के लिए ज़्यादा मज़बूत सबूत चाहिए। दोनों घटाने का मुख्य तरीका है बड़ा sample। इसलिए clinical trials α (अक्सर 0.05 two-sided) और target power (अक्सर 80–90%) तय करते हैं, और पहले मरीज़ के जुड़ने से पहले ही trial का आकार निकाल लेते हैं।
把 α 调小(0.05 → 0.01)会让第一类错误更少 —— 但在同样的数据下,β 会增大,因为现在需要更强的证据才能拒绝 H₀。同时降低两者的主要办法是增大样本。所以临床试验会先确定 α(常为双侧 0.05)和目标检验力(常为 80–90%),在第一位患者入组前就算出试验规模。
Blue curve: where x̄ lands if H₀ is true (μ = 50). Purple curve: where x̄ lands in the real world. Move the true mean, n and α. Watch the red (α), orange (β) and green (power) areas change. For simplicity this uses a z-test with σ = 2.8 g.
नीला curve: H₀ सच होने पर x̄ कहाँ गिरता है (μ = 50)। बैंगनी curve: असली दुनिया में x̄ कहाँ गिरता है। असली mean, n और α बदलें। लाल (α), नारंगी (β) और हरे (power) areas को बदलते देखें। आसानी के लिए यह σ = 2.8 g वाला z-test इस्तेमाल करता है।
蓝色曲线:若 H₀ 为真(μ = 50),x̄ 落在哪里。紫色曲线:真实世界中 x̄ 落在哪里。调整真实均值、n 和 α,观察红色(α)、橙色(β)和绿色(检验力)面积的变化。为简单起见,这里用 σ = 2.8 g 的 z 检验。
The Universal 5-Step Frameworkसार्वभौमिक 5-Step ढाँचा通用五步框架
Every hypothesis test, whichever test you use, follows the same five steps.
हर hypothesis test, चाहे कोई भी test हो, यही पाँच steps मानता है।
无论使用哪种检验,每个假设检验都遵循同样的五个步骤。
Specification: μ₀ = 50 g. The engineer suspects the machine is off. She weighs n = 25 bolts.
H₀: μ = 50 g (on spec) | H₁: μ ≠ 50 g (off spec — two-tailed)
Specification: μ₀ = 50 g. Engineer को शक है कि मशीन गड़बड़ है। वह n = 25 bolts तौलती है।
H₀: μ = 50 g (spec पर) | H₁: μ ≠ 50 g (spec से हटा — two-tailed)
规格:μ₀ = 50 g。工程师怀疑机器有偏差。她称了 n = 25 个螺栓。
H₀:μ = 50 g(符合规格)| H₁:μ ≠ 50 g(偏离规格 —— 双侧)
α = 0.05. σ is unknown → one-sample t-test (bolt weights are roughly normal).
α = 0.05. σ अज्ञात → one-sample t-test (bolts का वज़न लगभग normal है)।
α = 0.05。σ 未知 → 单样本 t 检验(螺栓重量大致正态)。
x̄ = 51.2 g, s = 2.8 g, n = 25, df = 24.
t = (x̄ − μ₀) / (s / √n) = (51.2 − 50) / (2.8 / 5) = 1.2 / 0.56 = t = 2.143
x̄ = 51.2 g, s = 2.8 g, n = 25, df = 24.
t = (x̄ − μ₀) / (s / √n) = (51.2 − 50) / (2.8 / 5) = 1.2 / 0.56 = t = 2.143
x̄ = 51.2 g,s = 2.8 g,n = 25,df = 24。
t = (x̄ − μ₀) / (s / √n) = (51.2 − 50) / (2.8 / 5) = 1.2 / 0.56 = t = 2.143
Two-tailed p-value (df = 24, t = 2.143) = 0.0425
Critical value t* = ±2.064
p = 0.0425 < α = 0.05 → reject H₀, and |2.143| > 2.064 ✓
Two-tailed p-value (df = 24, t = 2.143) = 0.0425
Critical value t* = ±2.064
p = 0.0425 < α = 0.05 → H₀ reject, और |2.143| > 2.064 ✓
双侧 p 值(df = 24,t = 2.143)= 0.0425
临界值 t* = ±2.064
p = 0.0425 < α = 0.05 → 拒绝 H₀,且 |2.143| > 2.064 ✓
At the 5% level there is enough evidence that the mean bolt weight differs from 50 g (t(24) = 2.14, p = 0.042). The machine runs about 1.2 g heavy (95% CI 50.04 to 52.36 g), so it should be checked and recalibrated. Note that p is close to 0.05 — a second batch would make the case stronger.
5% level पर इतना सबूत है कि bolts का औसत वज़न 50 g से अलग है (t(24) = 2.14, p = 0.042)। मशीन लगभग 1.2 g भारी चल रही है (95% CI 50.04 से 52.36 g), इसलिए इसे जाँचकर recalibrate करना चाहिए। ध्यान दें कि p, 0.05 के पास है — दूसरा batch केस को और मज़बूत करेगा।
在 5% 水平上,有足够证据表明螺栓平均重量不同于 50 g(t(24) = 2.14,p = 0.042)。机器大约偏重 1.2 g(95% 置信区间 50.04 到 52.36 g),应检查并重新校准。注意 p 接近 0.05 —— 再测一批会让结论更有力。
Always give: (1) the significance level, (2) the direction of the finding, (3) the test statistic and p-value in brackets, (4) the effect size or a confidence interval, (5) what it means in practice.
Never write: "We proved H₁" or "H₀ is false".
Write: "There is enough evidence at α = 0.05 to reject H₀ in favour of H₁" — or "There is not enough evidence to reject H₀".
हमेशा बताएँ: (1) significance level, (2) नतीजे की दिशा, (3) brackets में test statistic और p-value, (4) effect size या confidence interval, (5) व्यवहार में इसका मतलब।
कभी न लिखें: "हमने H₁ साबित किया" या "H₀ ग़लत है"।
लिखें: "α = 0.05 पर H₁ के पक्ष में H₀ reject करने के लिए काफ़ी सबूत है" — या "H₀ reject करने के लिए काफ़ी सबूत नहीं है"।
始终给出:(1)显著性水平,(2)结论的方向,(3)括号中的检验统计量和 p 值,(4)效应量或置信区间,(5)实际含义。
不要写:“我们证明了 H₁”或“H₀ 是错的”。
要写:“在 α = 0.05 水平上有足够证据拒绝 H₀、支持 H₁” —— 或“没有足够证据拒绝 H₀”。
One-tailed vs Two-tailed TestsOne-tailed vs Two-tailed Tests单侧检验 vs 双侧检验
Choose one-tailed or two-tailed before you look at the data. Switching afterwards to get a smaller p-value is a form of p-hacking.
One-tailed या two-tailed data देखने से पहले चुनें। छोटा p-value पाने के लिए बाद में बदलना p-hacking का एक रूप है।
在看数据之前就选定单侧还是双侧。看完结果再换,以求更小的 p 值,是 p-hacking 的一种形式。
| Propertyगुण性质 | Two-tailed testTwo-tailed test双侧检验 | One-tailed testOne-tailed test单侧检验 |
|---|---|---|
| H₁ containsH₁ मेंH₁ 含 | ≠ (not equal)≠ (बराबर नहीं)≠(不等于) | > or < (one direction)> या < (एक दिशा)> 或 <(单一方向) |
| Rejection regionRejection region拒绝域 | Both tails (α/2 each)दोनों tails (हर एक में α/2)两侧(各 α/2) | One tail (α)एक tail (α)一侧(α) |
| Critical z at α = 0.05α = 0.05 पर critical zα = 0.05 时的临界 z | ±1.960 | +1.645 orया或 −1.645 |
| Effect in the "wrong" direction"ग़लत" दिशा में effect“反方向”的效应 | Can still be detectedफिर भी पकड़ा जा सकता है仍能检测到 | Can never be detectedकभी नहीं पकड़ा जा सकता永远检测不到 |
| Harder to reject?Reject करना मुश्किल?更难拒绝? | Yes — more conservativeहाँ — ज़्यादा सावधान是 —— 更保守 | No — easier in the chosen directionनहीं — चुनी दिशा में आसान否 —— 在选定方向上更容易 |
| Recommended default?Default के रूप में?推荐默认? | Yesहाँ是 | Only if the other direction truly does not matter, decided in advanceसिर्फ़ जब दूसरी दिशा सच में मायने न रखे, और पहले से तय हो仅当另一方向确实无关紧要,且事先确定 |
Python ImplementationPython ImplementationPython 实现
Checking the worked exampleहल किए उदाहरण की जाँच验证例题
from scipy import stats
import numpy as np
# Worked example from summary numbers
x_bar, s, n, mu_0 = 51.2, 2.8, 25, 50
t = (x_bar - mu_0) / (s / np.sqrt(n))
p = 2 * stats.t.sf(abs(t), df=n - 1)
t_crit = stats.t.ppf(0.975, df=n - 1)
print(f"t = {t:.4f}, p (two-tailed) = {p:.4f}, t* = ±{t_crit:.4f}")
One-sample t-test — factory boltsOne-sample t-test — factory bolts单样本 t 检验 —— 工厂螺栓
import numpy as np
from scipy import stats
np.random.seed(7)
# 25 bolt weight measurements (grams)
bolt_weights = np.random.normal(loc=51.2, scale=2.8, size=25)
mu_0 = 50 # H₀: μ = 50 g
alpha = 0.05
# Two-tailed one-sample t-test
t_stat, p_value = stats.ttest_1samp(bolt_weights, popmean=mu_0)
x_bar = np.mean(bolt_weights)
s = np.std(bolt_weights, ddof=1)
se = s / np.sqrt(len(bolt_weights))
df = len(bolt_weights) - 1
t_crit = stats.t.ppf(1 - alpha/2, df=df)
print(f"x̄ = {x_bar:.4f} g | s = {s:.4f} g | SE = {se:.4f}")
print(f"t_stat = {t_stat:.4f}")
print(f"t_crit = ±{t_crit:.4f} (df={df}, α={alpha})")
print(f"p_value = {p_value:.4f}")
if p_value < alpha:
print(f"\np={p_value:.4f} < α={alpha} → REJECT H₀")
print("Mean bolt weight differs significantly from 50 g")
else:
print(f"\np={p_value:.4f} ≥ α={alpha} → FAIL TO REJECT H₀")
These 25 simulated bolts have x̄ = 51.35 g, a little different from the worked example, so t and p differ too. The decision is the same.
इन 25 simulated bolts का x̄ = 51.35 g है, हल किए उदाहरण से थोड़ा अलग, इसलिए t और p भी अलग हैं। फ़ैसला वही है।
这 25 个模拟螺栓的 x̄ = 51.35 g,与例题略有不同,所以 t 和 p 也不同,但结论相同。
One-tailed test — drug trial (right-tailed)One-tailed test — drug trial (right-tailed)单侧检验 —— 药物试验(右侧)
import numpy as np
from scipy import stats
np.random.seed(42)
# Blood pressure reduction (mmHg) for 30 trial patients
# H₀: μ ≤ 10 | H₁: μ > 10 (right-tailed)
bp_reduction = np.random.normal(loc=12.5, scale=4.0, size=30)
mu_0, alpha = 10, 0.05
# SciPy ≥ 1.6: ask for the one-tailed test directly
t_stat, p_one = stats.ttest_1samp(bp_reduction, popmean=mu_0,
alternative='greater')
print(f"Mean reduction: {np.mean(bp_reduction):.2f} mmHg")
print(f"t-statistic: {t_stat:.4f}")
print(f"p (one-tailed): {p_one:.4f}")
if p_one < alpha:
print("\nREJECT H₀ — mean reduction is significantly greater than 10 mmHg")
else:
print("\nFAIL TO REJECT H₀")
alternative='greater' gives the right-tailed p-value directly. The older trick — halve the two-tailed p when t > 0 — gives the same answer.
alternative='greater' सीधे right-tailed p-value देता है। पुरानी तरकीब — t > 0 होने पर two-tailed p को आधा करना — वही जवाब देती है।
alternative='greater' 直接给出右侧 p 值。旧方法 —— t > 0 时把双侧 p 减半 —— 结果相同。
A/B test — two proportionsA/B test — दो proportionsA/B 测试 —— 两个比例
import numpy as np
from scipy import stats
np.random.seed(0)
# A/B test: 500 visitors per button
# H₀: p_A = p_B | H₁: p_A ≠ p_B (two-tailed)
clicks_A = np.random.binomial(1, 0.042, 500)
clicks_B = np.random.binomial(1, 0.047, 500)
def two_prop_ztest(x1, n1, x2, n2):
p1, p2 = x1 / n1, x2 / n2
p_pool = (x1 + x2) / (n1 + n2)
se = np.sqrt(p_pool * (1 - p_pool) * (1/n1 + 1/n2))
z = (p1 - p2) / se
return z, 2 * stats.norm.sf(abs(z))
z, p = two_prop_ztest(clicks_A.sum(), 500, clicks_B.sum(), 500)
print(f"Button A rate: {clicks_A.mean()*100:.2f}%")
print(f"Button B rate: {clicks_B.mean()*100:.2f}%")
print(f"z = {z:.4f}, p-value = {p:.4f}")
# How many visitors per button would we need?
# (to detect 4.2% vs 4.7% with α = 0.05 and 80% power)
p1, p2 = 0.042, 0.047
za, zb = stats.norm.ppf(0.975), stats.norm.ppf(0.80)
n_needed = (za + zb)**2 * (p1*(1-p1) + p2*(1-p2)) / (p1 - p2)**2
print(f"\nVisitors needed per button: about {np.ceil(n_needed):,.0f}")
In this run, Button A (truly 4.2%) even looked better than Button B (truly 4.7%): 5.40% vs 4.60%. With 500 visitors per button, random noise is far bigger than a 0.5-point difference. To detect it with 80% power you need about 26,700 visitors per button. For yes/no data like clicks, use a two-proportion z-test or a chi-square test rather than a t-test.
इस run में Button A (असल में 4.2%) Button B (असल में 4.7%) से बेहतर दिखा: 5.40% vs 4.60%. हर button पर 500 visitors के साथ random शोर 0.5-point के अंतर से बहुत बड़ा है। इसे 80% power से पकड़ने के लिए हर button पर लगभग 26,700 visitors चाहिए। Clicks जैसे हाँ/नहीं data के लिए t-test की जगह two-proportion z-test या chi-square test इस्तेमाल करें।
在这次运行中,按钮 A(真实 4.2%)甚至看起来更好:5.40% 对按钮 B(真实 4.7%)的 4.60%。每个按钮只有 500 名访客时,随机噪声远大于 0.5 个百分点的差异。要以 80% 检验力检测到它,每个按钮约需 26,700 名访客。对于点击这类是/否数据,应使用双比例 z 检验或卡方检验,而不是 t 检验。
Effect size — Cohen's dEffect size — Cohen's d效应量 —— Cohen 的 d
import numpy as np
from scipy import stats
def cohen_d(group1, group2):
"""Pooled Cohen's d for two independent groups."""
n1, n2 = len(group1), len(group2)
s1, s2 = np.std(group1, ddof=1), np.std(group2, ddof=1)
pooled_std = np.sqrt(((n1-1)*s1**2 + (n2-1)*s2**2) / (n1+n2-2))
return (np.mean(group1) - np.mean(group2)) / pooled_std
rng = np.random.default_rng(42)
for n in [30, 100_000]:
control = rng.normal(10.0, 4, n)
treated = rng.normal(10.1 if n > 1000 else 12.5, 4, n)
t_stat, p_val = stats.ttest_ind(treated, control, equal_var=False)
d = cohen_d(treated, control)
size = ("negligible" if abs(d) < 0.2 else "small" if abs(d) < 0.5
else "medium" if abs(d) < 0.8 else "large")
print(f"n = {n:>7,} per group: p = {p_val:.2g}, d = {d:.3f} ({size})")
Both results are "significant", but they mean very different things. With 30 people per group, d = 0.91 is a large, important effect. With 100,000 per group, p is tiny but d = 0.03 — an effect too small to matter for any patient.
दोनों नतीजे "significant" हैं, पर इनके मतलब बहुत अलग हैं। हर group में 30 लोगों पर d = 0.91 एक बड़ा, ज़रूरी effect है। हर group में 100,000 पर p बहुत छोटा है पर d = 0.03 — इतना छोटा effect कि किसी मरीज़ के लिए मायने नहीं रखता।
两个结果都“显著”,但含义截然不同。每组 30 人时,d = 0.91 是大而重要的效应。每组 100,000 人时,p 极小但 d = 0.03 —— 小到对任何患者都无关紧要。
Simulation — false positives, power and p-hackingSimulation — false positives, power और p-hacking模拟 —— 假阳性、检验力与 p-hacking
import numpy as np
from scipy import stats
rng = np.random.default_rng(1)
alpha, reps, n = 0.05, 10_000, 20
# 1) H₀ is TRUE: both groups come from the same population
a = rng.normal(0, 1, (reps, n)); b = rng.normal(0, 1, (reps, n))
p = stats.ttest_ind(a, b, axis=1, equal_var=False).pvalue
print(f"H₀ true → significant in {np.mean(p < alpha)*100:.1f}% of studies (Type I rate)")
# 2) Real effect d = 0.5: same test, how often do we detect it?
b2 = rng.normal(0.5, 1, (reps, n))
p2 = stats.ttest_ind(b2, a, axis=1, equal_var=False).pvalue
print(f"d = 0.5 → significant in {np.mean(p2 < alpha)*100:.1f}% of studies (power)")
# 3) p-hacking: test 20 unrelated outcomes, report any p < 0.05
any_hit = 1 - (1 - alpha)**20
print(f"20 outcomes, no real effect → P(at least one 'significant') = {any_hit*100:.0f}%")
With no real effect, about 5% of studies are still "significant" — exactly α. With a medium effect (d = 0.5) and 20 people per group, the power is only about 34%: two out of three such studies miss a real effect. About 64 per group are needed for 80% power. And testing 20 outcomes gives a 64% chance of at least one false "discovery".
असली effect न होने पर भी लगभग 5% studies "significant" आती हैं — ठीक α. Medium effect (d = 0.5) और हर group में 20 लोगों पर power सिर्फ़ लगभग 34% है: ऐसी तीन में से दो studies असली effect से चूकती हैं। 80% power के लिए हर group में लगभग 64 लोग चाहिए। और 20 outcomes जाँचने पर कम से कम एक झूठी "खोज" का chance 64% है।
没有真实效应时,仍约有 5% 的研究“显著” —— 正好是 α。中等效应(d = 0.5)、每组 20 人时,检验力只有约 34%:三项这样的研究中有两项会漏掉真实效应。要达到 80% 检验力,每组约需 64 人。而检验 20 个指标,至少出现一个虚假“发现”的概率是 64%。
Each study compares two groups with a t-test. Choose the true effect d and the group size, then look at where the p-values land. With d = 0 every red bar is a false positive; with d > 0 the green bar is the power.
हर study दो groups की t-test से तुलना करती है। असली effect d और group size चुनें, फिर देखें कि p-values कहाँ गिरते हैं। d = 0 पर हर लाल bar false positive है; d > 0 पर हरा bar power है।
每项研究用 t 检验比较两组。选择真实效应 d 和每组人数,看看 p 值落在哪里。d = 0 时红柱全是假阳性;d > 0 时绿柱就是检验力。
stats.ttest_ind() uses equal_var=True (Student's t-test) by default, which assumes both groups have the same variance. Pass equal_var=False to use Welch's t-test. When variances are equal it loses almost no power; when they differ — especially with unequal group sizes — it keeps the Type I error rate close to α, while Student's test can go badly wrong.
stats.ttest_ind() डिफ़ॉल्ट रूप से equal_var=True (Student's t-test) लेता है, जो मानता है कि दोनों groups का variance बराबर है। Welch's t-test के लिए equal_var=False दें। Variances बराबर हों तो यह लगभग कोई power नहीं खोता; अलग हों — ख़ासकर group sizes अलग हों — तो यह Type I error rate को α के पास रखता है, जबकि Student's test बहुत ग़लत हो सकता है।
stats.ttest_ind() 默认 equal_var=True(Student t 检验),假设两组方差相等。传入 equal_var=False 即使用 Welch t 检验。方差相等时它几乎不损失检验力;方差不等时 —— 尤其两组人数不同 —— 它能让第一类错误率保持在 α 附近,而 Student 检验可能严重出错。
Choosing the Right Test — Quick Referenceसही Test चुनना — Quick Reference选择正确的检验 — 速查表
| Scenarioस्थिति场景 | TestTest检验 | H₀ exampleH₀ उदाहरणH₀ 示例 | Python functionPython functionPython 函数 |
|---|---|---|---|
| 1 group vs a known value1 group vs ज्ञात value1 组 vs 已知值 | One-sample t-testOne-sample t-test单样本 t 检验 | μ = 50 | stats.ttest_1samp(data, 50) |
| 2 independent groups2 स्वतंत्र groups2 个独立组 | Welch's t-test | μ₁ = μ₂ | stats.ttest_ind(a, b, equal_var=False) |
| Same group before & afterवही group पहले और बाद同一组前后对比 | Paired t-testPaired t-test配对 t 检验 | μ_diff = 0 | stats.ttest_rel(before, after) |
| 3+ independent groups3+ स्वतंत्र groups3 个及以上独立组 | One-way ANOVAOne-way ANOVA单因素方差分析 | μ₁ = μ₂ = μ₃ | stats.f_oneway(g1, g2, g3) |
| One proportion vs a benchmarkएक proportion vs benchmark一个比例 vs 基准 | Binomial testBinomial test二项检验 | P = 0.50 | stats.binomtest(k, n, p=0.5) |
| Two proportions (A/B test)दो proportions (A/B test)两个比例(A/B 测试) | Two-proportion z-testTwo-proportion z-test双比例 z 检验 | P₁ = P₂ | statsmodels … proportions_ztest(counts, nobs) |
| Two categorical variablesदो categorical variables两个分类变量 | Chi-square testChi-square test卡方检验 | Independentस्वतंत्र相互独立 | stats.chi2_contingency(table) |
| Skewed data, 2 groupsSkewed data, 2 groups偏斜数据,2 组 | Mann-Whitney U | Same distributionएक जैसा distribution分布相同 | stats.mannwhitneyu(a, b) |