Foundations of Data Science 📂 Inferential Statistics · 3 of 8 157 min read

Hypothesis Testing, Null vs Alternative Hypothesis,

A complete guide to hypothesis testing — from the courtroom analogy that explains the core logic, to formulating H₀ and H₁, understanding p-values and α correctly, the Type I/II error matrix, one-tailed vs two-tailed tests, a full five-step worked example, and Python implementations using SciPy including effect size with Cohen's d.

🌐
SectionSection第 01 节

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 (β)第二类错误(β)
💡
Three Stories, One Frameworkतीन कहानियाँ, एक ढाँचा三个故事,一个框架

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 测试以及大量已发表的研究。


SectionSection第 02 节

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 से उस दावे को परखता है। सब कुछ एक सवाल पर टिका है:

统计假设是关于总体参数(均值、比例、差异)的可检验论断。检验用样本数据来评判这个论断。一切都基于一个问题:

💡
The Central Question of Every Testहर Test का मुख्य सवाल每个检验的核心问题

"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₀。

Null hypothesisNull hypothesis原假设
H₀
  • The default assumptionडिफ़ॉल्ट मान्यता默认假设
  • "No effect, no difference""कोई effect नहीं, कोई अंतर नहीं"“没有效应,没有差异”
  • Contains =, ≤ or ≥=, ≤ या ≥ रखता है含 =、≤ 或 ≥
  • We look for evidence against itहम इसके ख़िलाफ़ सबूत ढूँढते हैं我们寻找反驳它的证据
Alternative hypothesisAlternative hypothesis备择假设
H₁ / Hₐ
  • What we want to showजो हम दिखाना चाहते हैं我们想证明的
  • "There is an effect""Effect है"“存在效应”
  • Contains ≠, < or >≠, < या > रखता है含 ≠、< 或 >
  • Supported only if H₀ is rejectedसिर्फ़ H₀ reject होने पर समर्थन只有拒绝 H₀ 才得到支持
Decision ruleDecision rule决策规则
p vs α
  • 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₀”

SectionSection第 03 节

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₀ 为真,我们的结果落在哪里?第二:可能出什么错?第三:这些风险有多大?

🔍 PICTURE 1 — THE p-VALUE IS AN AREAतस्वीर 1 — p-VALUE एक AREA है图 1 — p 值是一块面积
p-value and rejection region -4 -3 -2 -1 0 1 2 3 4 −t* = −2.064 reject H₀H₀ reject拒绝 H₀ fail to reject H₀ (95%)H₀ reject नहीं (95%)不拒绝 H₀(95%) our t = 2.143हमारा t = 2.143我们的 t = 2.143 t* = 2.064 p/2 = 0.0212 p/2 = 0.0212 Bolt exampleBolt उदाहरण螺栓例子 H₀: μ = 50 g, H₁: μ ≠ 50 gH₀: μ = 50 g, H₁: μ ≠ 50 gH₀:μ = 50 g,H₁:μ ≠ 50 g x̄ = 51.2, s = 2.8, n = 25x̄ = 51.2, s = 2.8, n = 25x̄ = 51.2,s = 2.8,n = 25 p = 0.0425 (orange area)p = 0.0425 (नारंगी area)p = 0.0425(橙色面积) α = 0.05 (red area)α = 0.05 (लाल area)α = 0.05(红色面积) p < α → reject H₀p < α → H₀ rejectp < α → 拒绝 H₀ orange inside red ⇔ p < αनारंगी, लाल के अंदर ⇔ p < α橙色在红色之内 ⇔ p < α The curve shows the t values we would expect if H₀ were true.Curve दिखाता है कि H₀ सच होने पर कौन-से t values आते।曲线表示:若 H₀ 为真,t 值会如何分布。
⚖️ PICTURE 2 — FOUR POSSIBLE OUTCOMESतस्वीर 2 — चार संभावित नतीजे图 2 — 四种可能结果
Decision matrix THE TRUTH (unknown to you)सच्चाई (आपको पता नहीं)真相(你并不知道) H₀ is trueH₀ सच हैH₀ 为真 H₀ is falseH₀ ग़लत हैH₀ 为假 Fail to reject H₀H₀ reject नहीं不拒绝 H₀ Reject H₀H₀ reject拒绝 H₀ YOUR DECISIONआपका फ़ैसला你的决定 YOUR DECISIONआपका फ़ैसला你的决定 ✓ Correct✓ सही✓ 正确 probability 1 − αprobability 1 − α概率 1 − α ⚖️ innocent person freed⚖️ बेगुनाह छूटा⚖️ 无辜者被释放 ✗ Type II error (β)✗ Type II error (β)✗ 第二类错误(β) false negative — missed a real effectfalse negative — असली effect छूटा假阴性 —— 漏掉了真实效应 ⚖️ guilty person freed⚖️ दोषी छूटा⚖️ 罪犯被释放 ✗ Type I error (α)✗ Type I error (α)✗ 第一类错误(α) false positive — "found" an effect that is not therefalse positive — जो effect नहीं, वह "मिला"假阳性 —— “发现”了不存在的效应 ⚖️ innocent person jailed⚖️ बेगुनाह को सज़ा⚖️ 无辜者被判刑 ✓ Correct = power (1 − β)✓ सही = power (1 − β)✓ 正确 = 检验力(1 − β) often planned at 80% or moreअक्सर 80% या ज़्यादा रखा जाता है通常设计为 80% 或更高 ⚖️ guilty person convicted⚖️ दोषी को सज़ा⚖️ 罪犯被定罪
🎯 PICTURE 3 — α, β AND POWER ARE AREAS UNDER TWO CURVESतस्वीर 3 — α, β और POWER दो CURVES के नीचे के AREAS हैं图 3 — α、β 和检验力是两条曲线下的面积
Type I error, Type II error and power 48 g 49 g 50 g 51 g 52 g 53 g critical x̄ = 51.10 gcritical x̄ = 51.10 g临界 x̄ = 51.10 g If H₀ true: μ = 50अगर H₀ सच: μ = 50若 H₀ 为真:μ = 50 If truly μ = 51.2अगर असल में μ = 51.2若实际 μ = 51.2 β = 43% power = 57% α/2 α/2 Red = Type I error (α): H₀ true but rejected. Orange = Type II error (β): H₀ false but kept. Green = power.लाल = Type I error (α): H₀ सच पर reject। नारंगी = Type II error (β): H₀ ग़लत पर रखा। हरा = power.红 = 第一类错误(α):H₀ 为真却被拒绝。橙 = 第二类错误(β):H₀ 为假却被保留。绿 = 检验力。 Bolt example with n = 25: even if the machine really is 1.2 g off, this test catches it only about 57% of the time.n = 25 वाला bolt उदाहरण: मशीन सच में 1.2 g ग़लत हो, तब भी यह test उसे सिर्फ़ लगभग 57% बार पकड़ता है।n = 25 的螺栓例子:即使机器真的偏了 1.2 g,这个检验也只有约 57% 的概率发现它。

SectionSection第 04 节

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?”
⚠️
The Most Common Mistake When Writing HypothesesHypotheses लिखने में सबसे आम ग़लती写假设时最常见的错误

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₀ 的证据,就像检察官针对无罪推定构建案件。


SectionSection第 05 节

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 值。然后比较两者。

p-value — precise definitionp-value — सटीक परिभाषाp 值 —— 精确定义
p = P(data at least this extreme | H₀ true)
The probability of a test statistic at least as extreme as the one observed, assuming H₀ is true. A small p means the data would be surprising if H₀ were true — evidence against H₀. It is not the probability that H₀ is true.
कम से कम इतना extreme test statistic मिलने की संभावना, यह मानकर कि H₀ सच है। छोटा p मतलब H₀ सच होने पर data चौंकाने वाला होता — H₀ के ख़िलाफ़ सबूत। यह H₀ के सच होने की संभावना नहीं है।
假设 H₀ 为真时,得到至少与观测值一样极端的检验统计量的概率。p 小说明若 H₀ 为真,这样的数据会令人意外 —— 这是反驳 H₀ 的证据。它不是 H₀ 为真的概率。
Significance level α — the gate set in advanceSignificance level α — पहले से तय दरवाज़ा显著性水平 α —— 事先设定的门槛
α = P(reject H₀ | H₀ true) = P(Type I error)
Set before collecting data. 0.05 is the common default; 0.01 or lower when a false alarm is costly; 0.10 for early, exploratory work. Particle physics asks for "5σ" (about 3 in 10 million).
Data जुटाने से पहले तय करें। 0.05 आम डिफ़ॉल्ट है; जब झूठा alarm महँगा हो तो 0.01 या कम; शुरुआती exploratory काम में 0.10. Particle physics "5σ" (लगभग 1 करोड़ में 3) माँगती है।
在收集数据之前设定。0.05 是常用默认值;误报代价高时用 0.01 或更低;早期探索性工作可用 0.10。粒子物理要求“5σ”(约千万分之三)。
⚠️
What the p-value Does NOT Meanp-value का क्या मतलब नहीं है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。一定要同时报告效应量。

LIVELIVE互动p-value Explorer — The Bolt Machinep-value Explorer — Bolt मशीन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₀。也试试改变检验类型。


SectionSection第 06 节

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% 或更高
🎯
The Error Trade-offErrors का सौदा错误之间的权衡

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%),在第一位患者入组前就算出试验规模。

LIVELIVE互动Errors & Power LabErrors और Power Lab错误与检验力实验室

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 检验。


SectionSection第 07 节

The Universal 5-Step Frameworkसार्वभौमिक 5-Step ढाँचा通用五步框架

Every hypothesis test, whichever test you use, follows the same five steps.

हर hypothesis test, चाहे कोई भी test हो, यही पाँच steps मानता है।

无论使用哪种检验,每个假设检验都遵循同样的五个步骤。

🧭 FIVE STEPSपाँच STEPS五个步骤
Five steps 1 State H₀ and H₁H₀ और H₁ लिखें写出 H₀ 和 H₁ 2 Set α, choose testα तय, test चुनें设定 α,选检验 3 Compute statisticStatistic निकालें计算统计量 4 Find p, compare with αp निकालें, α से तुलना求 p,与 α 比较 5 Conclude in plain wordsआसान शब्दों में निष्कर्ष用通俗语言下结论
🧮 Worked Example — Factory Bolt Weight (One-sample t-test)हल किया उदाहरण — Factory Bolt का वज़न (One-sample t-test)例题 —— 工厂螺栓重量(单样本 t 检验)
Step 1Step 1第 1 步
State the hypotheses.
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)
Hypotheses लिखें।
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(偏离规格 —— 双侧)
Step 2Step 2第 2 步
Set α and choose the test.
α = 0.05. σ is unknown → one-sample t-test (bolt weights are roughly normal).
α तय करें और test चुनें।
α = 0.05. σ अज्ञात → one-sample t-test (bolts का वज़न लगभग normal है)।
设定 α 并选择检验。
α = 0.05。σ 未知 → 单样本 t 检验(螺栓重量大致正态)。
Step 3Step 3第 3 步
Compute the test statistic.
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
Test statistic निकालें।
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
Step 4Step 4第 4 步
Find the p-value and compare.
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 ✓
p-value निकालें और तुलना करें।
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 值并比较。
双侧 p 值(df = 24,t = 2.143)= 0.0425
临界值 t* = ±2.064
p = 0.0425 < α = 0.05 → 拒绝 H₀,且 |2.143| > 2.064 ✓
Step 5Step 5第 5 步
Conclude in plain language.
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 —— 再测一批会让结论更有力。
✅
How to Write a Correct Conclusionसही निष्कर्ष कैसे लिखें如何写出正确的结论

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₀”。


SectionSection第 08 节

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 的一种形式。

📐 REJECTION REGIONS AT α = 0.05α = 0.05 पर REJECTION REGIONSα = 0.05 时的拒绝域
One-tailed vs two-tailed Two-tailed (H₁: μ ≠ μ₀)Two-tailed (H₁: μ ≠ μ₀)双侧(H₁:μ ≠ μ₀) −1.960 2.5% +1.960 2.5% 95% α split across both tailsα दोनों tails में बँटाα 平分到两侧 Right-tailed (H₁: μ > μ₀)Right-tailed (H₁: μ > μ₀)右侧(H₁:μ > μ₀) +1.645 5% 95% all of α in the right tailपूरा α दाईं tail मेंα 全在右侧 Left-tailed (H₁: μ < μ₀)Left-tailed (H₁: μ < μ₀)左侧(H₁:μ < μ₀) −1.645 5% 95% all of α in the left tailपूरा α बाईं tail मेंα 全在左侧
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सिर्फ़ जब दूसरी दिशा सच में मायने न रखे, और पहले से तय हो仅当另一方向确实无关紧要,且事先确定

SectionSection第 09 节

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}")
OUTPUT
t = 2.1429, p (two-tailed) = 0.0425, t* = ±2.0639

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₀")
OUTPUT
x̄ = 51.3478 g | s = 2.6149 g | SE = 0.5230 t_stat = 2.5772 t_crit = ±2.0639 (df=24, α=0.05) p_value = 0.0165 p=0.0165 < α=0.05 → REJECT H₀ Mean bolt weight differs significantly from 50 g

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₀")
OUTPUT
Mean reduction: 11.75 mmHg t-statistic: 2.6586 p (one-tailed): 0.0063 REJECT H₀ — mean reduction is significantly greater than 10 mmHg

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}")
OUTPUT
Button A rate: 5.40% Button B rate: 4.60% z = 0.5804, p-value = 0.5617 Visitors needed per button: about 26,695
⚠️
500 Visitors Cannot Settle 4.2% vs 4.7%500 Visitors से 4.2% vs 4.7% तय नहीं हो सकता500 名访客无法分辨 4.2% 与 4.7%

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})")
OUTPUT
n = 30 per group: p = 0.00081, d = 0.913 (large) n = 100,000 per group: p = 9.4e-13, d = 0.032 (negligible)

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}%")
OUTPUT
H₀ true → significant in 5.1% of studies (Type I rate) d = 0.5 → significant in 34.1% of studies (power) 20 outcomes, no real effect → P(at least one 'significant') = 64%

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%。

LIVELIVE互动Run 1,000 Studies1,000 Studies चलाएँ进行 1,000 项研究

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 时绿柱就是检验力。

d

⚠️
Prefer equal_var=False in ttest_ind()ttest_ind() में equal_var=False बेहतरttest_ind() 中优先使用 equal_var=False

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 检验可能严重出错。


SectionSection第 10 节

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 检验μ = 50stats.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 = 0stats.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.50stats.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 USame distributionएक जैसा distribution分布相同stats.mannwhitneyu(a, b)

SectionSection第 11 节

Golden RulesGolden Rules黄金法则

🎯 Hypothesis Testing — Key RulesHypothesis Testing — मुख्य नियम假设检验 — 关键规则
1
Your research claim goes in H₁ — never in H₀. H₀ is the sceptic's default ("no effect", with =, ≤ or ≥). You gather evidence against it, like a prosecutor against the presumption of innocence.
आपका research दावा H₁ में जाता है — H₀ में कभी नहीं। H₀ शक करने वाले का डिफ़ॉल्ट है ("कोई effect नहीं", =, ≤ या ≥ के साथ)। आप इसके ख़िलाफ़ सबूत जुटाते हैं, जैसे prosecutor बेगुनाही की मान्यता के ख़िलाफ़।
你的研究主张放在 H₁ —— 绝不放在 H₀。H₀ 是怀疑者的默认立场(“没有效应”,含 =、≤ 或 ≥)。你要收集反驳它的证据,就像检察官针对无罪推定。
2
Fix α, the test and the hypotheses before seeing the data. Changing α, switching to a one-tailed test, or trying many tests until one gives p < 0.05 is p-hacking. Test 20 things with no real effect and you have a 64% chance of a false "discovery".
Data देखने से पहले α, test और hypotheses तय करें। α बदलना, one-tailed पर जाना, या तब तक tests आज़माना जब तक p < 0.05 न मिले — यह p-hacking है। बिना असली effect के 20 चीज़ें जाँचें तो झूठी "खोज" का chance 64% है।
在看数据之前就确定 α、检验方法和假设。改 α、换成单侧检验、或反复尝试直到 p < 0.05,都是 p-hacking。在没有真实效应时检验 20 个指标,出现虚假“发现”的概率高达 64%。
3
"Fail to reject H₀" is NOT "accept H₀". A non-significant result means the evidence was not strong enough. H₀ may be true — or the sample may be too small to see a real effect. Plan the power before the study.
"H₀ reject नहीं" का मतलब "H₀ accept" नहीं। Non-significant नतीजे का मतलब है सबूत काफ़ी मज़बूत नहीं था। H₀ सच हो सकता है — या sample असली effect देखने के लिए बहुत छोटा हो सकता है। Power की योजना study से पहले बनाएँ।
“不拒绝 H₀”不等于“接受 H₀”。不显著只说明证据不够强。H₀ 可能为真 —— 也可能样本太小,看不到真实效应。要在研究之前规划检验力。
4
Statistical significance ≠ practical importance. With 100,000 people per group, a difference of d = 0.03 gave p ≈ 10⁻¹². Always report an effect size (Cohen's d, difference in means, odds ratio) and a confidence interval with every p-value.
Statistical significance ≠ व्यावहारिक महत्व। हर group में 100,000 लोगों पर d = 0.03 के अंतर ने p ≈ 10⁻¹² दिया। हर p-value के साथ effect size (Cohen's d, means का अंतर, odds ratio) और confidence interval बताएँ।
统计显著 ≠ 实际重要。每组 100,000 人时,d = 0.03 的差异就得到 p ≈ 10⁻¹²。每个 p 值都要同时报告效应量(Cohen 的 d、均值差、优势比)和置信区间。
5
Use Welch's t-test (equal_var=False) for two independent groups. It loses almost nothing when variances are equal and protects you when they are not.
दो स्वतंत्र groups के लिए Welch's t-test (equal_var=False) लें। Variances बराबर हों तो यह लगभग कुछ नहीं खोता, और अलग हों तो आपको बचाता है।
两个独立组用 Welch t 检验(equal_var=False)。方差相等时几乎没有损失,方差不等时能保护你。
6
Match the test to the data and check its assumptions. t-tests and ANOVA need roughly normal data or a large n. For yes/no data use proportion tests or chi-square. For small, skewed samples use Mann-Whitney U, Kruskal-Wallis or the Wilcoxon signed-rank test.
Data के हिसाब से test चुनें और उसकी मान्यताएँ जाँचें। t-tests और ANOVA को लगभग normal data या बड़ा n चाहिए। हाँ/नहीं data के लिए proportion tests या chi-square. छोटे, skewed samples के लिए Mann-Whitney U, Kruskal-Wallis या Wilcoxon signed-rank test.
根据数据选择检验,并检查其假设。t 检验和方差分析需要数据大致正态或 n 较大。是/否数据用比例检验或卡方检验。小而偏斜的样本用 Mann-Whitney U、Kruskal-Wallis 或 Wilcoxon 符号秩检验。