Hypothesis Testing

In null hypothesis significant testing, we are testing the validity of a claim about a population against a counter claim using sample data.

Null Hypothesis, H0: A hypothesis claiming no difference between sample and population

Alternative Hypothesis, HA: A hypothesis contradicting H0, which is usually what we're trying to prove.

 Do Not Reject H0Reject H0
H0 is TrueCorrect Decision (True Negative)Type I Error (False Positive)
H0 is FalseType II Error (False Negative)Correct Decision (True Positive)

Test Statistic, T: A statistic used to test our hypothesis.

Significance Level, α: Probability threshold of rejection of H0. This is the probability of getting a type I error.

p-value: The probability of observing a statistic as extreme or more extreme than the one observed under the assumption that H0 is true.

Power of the Test: Probability of rejecting H0 when HA is true.

α=p(rejectH0|H0)=p(Type I Error)=p(False Positive)
1α=p(do not rejectH0|HA)=p(True Negative)
β=p(do not rejectH0|HA)=p(Type II Error)=p(False Negative)
1β=p(rejectH0|HA)=p(True Positive)=Power of the Test

z-Test

Setup & Assumptions

Null Hypothesis

H0:μ=μ0

Alternative Hypothesis

HA:μ>μ0,μ<μ0,orμμ0

Test Statistic

z=x¯μ0σ/n

Null Distribution

Standard Normal Distribution:ZN(0,1)

p-Value

Test Typep-valuePythonR
Left-tailedP{Zz}scipy.stats.norm.cdf(z, 0, 1)pnorm(z, 0, 1)
Right-tailedP{Zz}1 - scipy.stats.norm.cdf(z, 0, 1)1 - pnorm(z, 0, 1)
Two-tailedP{|Z||z|}2 * (1 - scipy.stats.norm.cdf(abs(z), 0, 1))2 * (1 - pnorm(abs(z), 0, 1))

z-Test: Two Samples

Setup & Assumptions

Null Hypothesis

H0:μxμy=μ0

Alternative Hypothesis

HA:μxμy>μ0,μxμy<μ0,orμxμyμ0

Test Statistic

z=x¯y¯μ0σp

where σp2 is the pooled population variance:

σp2=σx2n+σy2m

Null Distribution

Standard Normal Distribution:ZN(0,1)

p-Value

Test Typep-valuePythonR
Left-tailedP{Zz}scipy.stats.norm.cdf(z, 0, 1)pnorm(z, 0, 1)
Right-tailedP{Zz}1 - scipy.stats.norm.cdf(z, 0, 1)1 - pnorm(z, 0, 1)
Two-tailedP{|Z||z|}2 * (1 - scipy.stats.norm.cdf(abs(z), 0, 1))2 * (1 - pnorm(abs(z), 0, 1))

t-Test

Setup & Assumptions

Null Hypothesis

H0:μ=μ0

Alternative Hypothesis

HA:μ>μ0,μ<μ0,orμμ0

Test Statistic

t=x¯μ0s/n

Null Distribution

t-Distribution:Tt(n1)

p-Value

Test Typep-valuePythonR
Left-tailedP{Tt}scipy.stats.t.cdf(t, n - 1)pt(t, n - 1)
Right-tailedP{Tt}1 - scipy.stats.t.cdf(t, n - 1)1 - pt(t, n - 1)
Two-tailedP{|T||t|}2 * (1 - scipy.stats.t.cdf(abs(t), n - 1))2 * (1 - pt(abs(t), n - 1))

t-Test: Two Samples with Equal Variances

Setup & Assumptions

Null Hypothesis

H0:μxμy=μ0

Alternative Hypothesis

HA:μxμy>μ0,μxμy<μ0,orμxμyμ0

Test Statistic

t=x¯y¯μ0sp1n+1m

where sp2 is the pooled sample variance:

sp2=(n1)sx2+(m1)sy2n+m2

Null Distribution

t-Distribution:Tt(n+m2)

p-Value

Test Typep-valuePythonR
Left-tailedP{Tt}scipy.stats.t.cdf(t, n + m - 2)pt(t, n + m - 2)
Right-tailedP{Tt}1 - scipy.stats.t.cdf(t, n + m - 2)1 - pt(t, n + m - 2)
Two-tailedP{|T||t|}2 * (1 - scipy.stats.t.cdf(abs(t), n + m - 2))2 * (1 - pt(abs(t), n + m - 2))

t-Test: Two Samples with Unequal Variances

Setup & Assumptions

Null Hypothesis

H0:μxμy=μ0

Alternative Hypothesis

HA:μxμy>μ0,μxμy<μ0,orμxμyμ0

Test Statistic

t=x¯y¯μ0sp1n+1m

where sp2 is the pooled sample variance:

sp2=sx2+sy2

Null Distribution

t-Distribution:Tt(df)

where df is the degrees of freedom, defined by,

df=(sx2/n+sy2/m)2(sx2/n)2/(n1)+(sy2/m)2/(m1)

where a is the nearest integer of a.

Test Typep-valuePythonR
Left-tailedP{Tt}scipy.stats.t.cdf(t, df)pt(t, df)
Right-tailedP{Tt}1 - scipy.stats.t.cdf(t, df)1 - pt(t, df)
Two-tailedP{|T||t|}2 * (1 - scipy.stats.t.cdf(abs(t), df))2 * (1 - pt(abs(t), df))

F-Test for Equal Means (One Way ANOVA)

Setup & Assumptions

Null Hypothesis

H0:μ1=μ2=...=μn

Alternative Hypothesis

HA:μiμjfor somei,j

Test Statistic

v=MSbMSw

where,

Mean Squared Sum Within Sets,MSw=SSwn(m1)Mean Squared Sum Between Sets,MSb=SSbn1Squared Sum Within Sets,SSw=i=1nj=1m(xijxi¯)2=i=1n(m1)si2Squared Sum Between Sets,SSb=i=1nm(xi¯x¯)2Squared Sum Total,SSt=i=1nj=1m(xijx¯)2SSt=SSw+SSb

Null Distribution

F-Distribution:VF(n1,n(m1))
Test Typep-valuePythonR
Right-tailedP{Vv}1 - scipy.stats.f.cdf(v, n - 1, n * (m - 1))1 - pf(v, n - 1, n * (m - 1))

F-Test for Equal Variances

Setup & Assumptions

Null Hypothesis

H0:σx=σy

Alternative Hypothesis

HA:σx>σy,σx<σyorσxσy

Test Statistic

v=sx2sy2

Null Distribution

F-Distribution:VF(n1,m1)

p-Value

Test Typep-valuePythonR
Left-tailedP{Vv}scipy.stats.f.cdf(v, n - 1, m - 1)pf(v, n - 1, m - 1)
Right-tailedP{Vv}1 - scipy.stats.f.cdf(v, n - 1, m - 1)1 - pf(v, n - 1, m - 1)
Two-tailedP{|V||v|}2 * min(1 - scipy.stats.f.cdf(v, n - 1, m - 1), scipy.stats.f.cdf(v, n - 1, m - 1))2 * min(1 - pf(v, n - 1, m - 1), pf(v, n - 1, m - 1))

χ2-Test for Variance

Setup & Assumptions

Null Hypothesis

H0:σ=σ0

Alternative Hypothesis

HA:σ>σ0,σ<σ0orσσ0

Test Statistic

u=(n1)s2σ02

Null Distribution

χ2-Distribution:Uχ2(n1)

p-Value

Test Typep-valuePythonR
Left-tailedP{Uu}scipy.stats.chi2.cdf(u, n - 1)pchisq(u, n - 1)
Right-tailedP{Uu}1 - scipy.stats.chi2.cdf(u, n - 1)1 - pchisq(u, n - 1)
Two-tailedP{|U||u|}2 * min(1 - scipy.stats.chi2.cdf(u, n - 1), scipy.stats.chi2.cdf(u, n - 1))2 * min(1 - pchisq(u, n - 1), pchisq(u, n - 1))

χ2-Test for Goodness of Fit: Single Specific Distribution

Setup & Assumptions

Null Hypothesis

H0:xifollows distribution{pi}i=1K

Alternative Hypothesis

HA:xidoes not follow distribution{pi}i=1K

Test Statistic

u=i=1K(Oinpi)2npi

Null Distribution

χ2-Distribution:Uχ2(K1)

p-Value

Test Typep-valuePythonR
Right-tailedP{Uu}1 - scipy.stats.chi2.cdf(u, K - 1)1 - pchisq(u, K - 1)

χ2-Test for Goodness of Fit: Statistical Model

Setup & Assumptions

Null Hypothesis

H0:xifollows model{(p1(θ),p2(θ),...,pK(θ)):θΘ}

Alternative Hypothesis

HA:xidoes not follow model{(p1(θ),p2(θ),...,pK(θ)):θΘ}

Test Statistic

u=k=1K(Oknpk(θ^))2npk(θ^)

where θ^ is the maximum likelihood estimate of θ under H0.

Null Distribution

χ2-Distribution:Uχ2(K1dim(Θ))

where dim(Θ) is the dimension of the parameter space Θ.

p-Value

Test Typep-valuePythonR
Right-tailedP{Uu}1 - scipy.stats.chi2.cdf(u, K - 1 - dim)1 - pchisq(u, K - 1 - dim)

χ2-Test for Goodness of Fit: Independence

Setup & Assumptions

Null Hypothesis

H0:X & Y are independentpk,l=pk,.×p.,l

Alternative Hypothesis

H0:X & Y are NOT independentpk,lpk,.×p.,lfor somek,l

Test Statistic

u=k=1Kl=1L(Ok,lnp^k,.p^.,l)2np^k,.p^.,l

Null Distribution

χ2-Distribution:Uχ2((K1)(L1))

p-Value

Test Typep-valuePythonR
Right-tailedP{Uu}1 - scipy.stats.chi2.cdf(u, (K - 1) * (L - 1)1 - pchisq(u, (K - 1) * (L - 1))