Hypothesis testing and summarize how hypothesis testing using python (scipy)

Several common hypothesis testing are summarized as follows:

Hypothesis testing Name

Z test

t test

 χ2 test

F test

Null hypothesis 

   H 0 : μ≥μ 0    H 0 : μ≤μ 0    H 0 : [mu] = [mu] 0 (sample population mean)            

   H 0 : [mu] . 1 - [mu] 2 ≧ 0 H 0 : [mu] . 1 - [mu] 2 ≦ 0 H 0 : [mu] . 1 - [mu] 2 = 0 (two ensemble average)

   H 0 : [mu] D ≧ 0 H 0 : [mu] D ≦ 0 H 0 : [mu] D = 0 (the difference between the front and rear two generally mean)

H 0 : [sigma] 2 ≥σ 0 2 H 0 : [sigma] 2 ≤σ 0 2 H 0 : [sigma] 2 = [sigma] 0 2 (and sample population variance)                  

        H 0 : [sigma] . 1 2 ≤σ 2 2 H 0 : [sigma] . 1 2 = [sigma] 2 2 (two overall variance, i.e. the homogeneity of variance)          

H 0 : two categorical variables are independent   (independence test)

H 0 : Overall obey a probability distribution   (goodness of fit test)

H 0 : equal to the population mean   (ANOVA) --- commonly used and three or more generally

Alternative hypothesis

   H A : [mu] <[mu] 0    H A : [mu]> [mu] 0    H A : [mu] [mu] ≠ 0 (sample population mean)           

H A : [mu] . 1 - [mu] 2 <0 H A : [mu] . 1 - [mu] 2 > 0 H A : [mu] . 1 - [mu] 2 ≠ 0 (two ensemble average)

H A : [mu] D <0 H A : [mu] D > 0 H A : [mu] D ≠ 0 (difference between front and rear two generally mean)

 H A : [sigma] 2 <[sigma] 0 2 H A : [sigma] 2 > [sigma] 0 2 H A : [sigma] 2 ≠ [sigma] 0 2 (and sample population variance)                  

              H A : [sigma] . 1 2 > [sigma] 2 2 H A : [sigma] . 1 2 ≠ [sigma] 2 2 (two population variance)          

H A : two categorical variables are not independent   (independence test)

H A : Overall not obey a probability distribution   (goodness of fit test)

H A : population means are not all equal   (analysis of variance)

Inspection type

     Left and right tail end of a two-tailed

  Left and right tail end of a two-tailed

Inspection prerequisite

 σ is known, the sample greater than or equal 30

  σ unknown sample is less than 30 (when the total normal distribution), the sample is greater than or equal to 30 (when the total is not a normal distribution)

no

The overall approximate normal distribution (two overall variance)

The overall approximate normal distribution, similar to the overall variance (ANOVA)

Test statistics

(Sample and the population mean)

 (Two population mean)

 

(Sample and the population mean)

(Two population mean,

Independent samples, two population variances are not equal)

(Two population mean,

Independent samples, two equal population variance)

(Two overall mean difference before and after,

Paired samples)

(Sample and the population variance)

(Independence test)

(Goodness of fit test)

(Two overall variance)

(ANOVA)

Decision Making

A threshold method: If the -Z ≤ Z [alpha] , the null hypothesis is rejected (left-tailed)

          If Z ≥ Z [alpha] , the null hypothesis is rejected (right-tailed)

If the -Z ≤ Z [alpha] / 2 or Z ≥ Z [alpha] / 2 , the null hypothesis is rejected (two-tailed)

(If the confidence interval does not contain [mu] 0 , the null hypothesis is rejected)

p-value method: if the p-value ≤α, the null hypothesis is rejected

A threshold method: if -t ≤ T [alpha] , the null hypothesis is rejected (left-tailed)

          If T ≥ T [alpha] , the null hypothesis is rejected (right-tailed)

If -t ≤ T [alpha] / 2 or T ≥ T [alpha] / 2 , the null hypothesis is rejected (two-tailed)

(If the confidence interval does not contain [mu] 0 , the null hypothesis is rejected)

p-value method: if the p-value ≤α, the null hypothesis is rejected

临界值法:如果χ2 ≤ χ2(1-α),则拒绝原假设(左尾)

          如果χ2 ≥ χ2α,则拒绝原假设(右尾)

如果χ2 ≤ χ2(1-α) 或 χ2 ≥ χ2α,则拒绝原假设(双尾)

(如果置信区间不包含σ02,则拒绝原假设)

p值法:如果p值≤α,则拒绝原假设

临界值法:如果F ≥ Fα,则拒绝原假设(右尾)

如果F ≥ Fα/2,则拒绝原假设(双尾)

p值法:如果p值≤α,则拒绝原假设

 

注:p值法可以显示实际显著性,而临界值法不能。

python命令

 

1,单样本t检验scipy.stats.ttest_1samp (a, popmean)

返回:t检验统计量的具体值和相应的p值(双尾)

2,配对t检验scipy.stats.ttest_rel(a,b)

返回:t检验统计量的具体值和相应的p值(双尾)

3,独立样本t检验

scipy.stats.ttest_ind (a, b, equal_var=True)  scipy.stats.ttest_ind_from_stats (mean1, std1,nobs1,mean2, std2,nobs2, equal_var=True) --- 方差相等

scipy.stats.ttest_ind(a, b, equal_var=False)  scipy.stats.ttest_ind_from_stats (mean1, std1,nobs1,mean2,std2,nobs2, equal_var=False)--- 方差不相等

返回:t检验统计量的具体值和相应的p值(双尾)

1,拟合优度检验scipy.stats.chisquare (f_obsf_exp=Noneddof=0)

返回:卡方统计量的具体值和相应的p值

2,独立性检验scipy.stats.chi2_contingency (observed, correction=True)

返回:卡方统计量的具体值,相应的p值,自由度, 期望频率

1,方差齐性检验scipy.stats.levene (sample1,sample2,...)

返回:F统计量的具体值和相应的p值 

2,单因素方差分析scipy.stats.f_oneway (sample1,sample2,...)

 返回:F统计量的具体值和相应的p值 

 

其他检验:

1,正态性检验:scipy.stats.shapiro(x)

 

返回:检验统计量的具体值和相应的p值

 

Guess you like

Origin www.cnblogs.com/HuZihu/p/11442833.html