Python में Hypothesis Testing
James Chapman
Curriculum Manager, DataCamp
$p$: population proportion (अज्ञात population पैरामीटर)
$\hat{p}$: sample proportion (sample statistic)
$p_{0}$: मान्य population proportion
$$ z = \frac{\hat{p} - \text{mean}(\hat{p})}{\text{SE}(\hat{p})} = \frac{\hat{p} - p}{\text{SE}(\hat{p})} $$
मान लें $H_{0}$ सही है, तब $p = p_{0}$, इसलिए
$$ z = \dfrac{\hat{p} - p_{0}}{\text{SE}(\hat{p})} $$
$SE_{\hat{p}} = \sqrt{\dfrac{p_{0}*(1-p_{0})}{n}}$ $\rightarrow$ $H_0$ के तहत, $SE_{\hat{p}}$ मान्य $p_0$ और sample size $n$ पर निर्भर है
मान लें $H_{0}$ सही है,
$z = \dfrac{\hat{p} - p_{0}}{\sqrt{\dfrac{p_{0}*(1-p_{0})}{n}}}$
$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}}$
$H_{0}$: Stack Overflow पर 30 से कम उम्र के यूज़र का proportion $=0.5$
$H_{A}$: Stack Overflow पर 30 से कम उम्र के यूज़र का proportion $\neq0.5$
alpha = 0.01
stack_overflow['age_cat'].value_counts(normalize=True)
Under 30 0.535604
At least 30 0.464396
Name: age_cat, dtype: float64
p_hat = (stack_overflow['age_cat'] == 'Under 30').mean()
0.5356037151702786
p_0 = 0.50
n = len(stack_overflow)
2261
$z = \dfrac{\hat{p} - p_{0}}{\sqrt{\dfrac{p_{0}*(1-p_{0})}{n}}}$
import numpy as np
numerator = p_hat - p_0
denominator = np.sqrt(p_0 * (1 - p_0) / n)
z_score = numerator / denominator
3.385911440783663
Left-tailed ("less than"):
from scipy.stats import norm
p_value = norm.cdf(z_score)
Right-tailed ("greater than"):
p_value = 1 - norm.cdf(z_score)
Two-tailed ("not equal"):
p_value = norm.cdf(-z_score) +
1 - norm.cdf(z_score)
p_value = 2 * (1 - norm.cdf(z_score))
0.0007094227368100725
p_value <= alpha
True
Python में Hypothesis Testing