• 博客等级：
• 博客积分：0
• 博客访问：1,379,685
• 关注人气：1,086
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

## Python替代SPSS进行各项统计检验

(2020-04-25 23:11:29)

### 统计学

from scipy.stats import shapiro
data = [21,12,12,23,19,13,20,17,14,19]
stat,p = shapiro(data)
print("stat为：%f" %stat,"p值为：%f" %p)

from scipy.stats import pearsonr
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
corr,p = pearsonr(data1,data2)
print("corr为：%f" %corr,"p值为：%f" %p)

from scipy.stats import chi2_contingency
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p,dof,expected = chi2_contingency(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

T检验

from scipy.stats import ttest_ind
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = ttest_ind(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

from scipy.stats import ttest_rel
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = ttest_rel(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

from scipy.stats import f_oneway
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = f_oneway(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

Mann-Whitney U检验

from scipy.stats import mannwhitneyu
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = mannwhitneyu(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

Wilcoxon符号秩检验

from scipy.stats import wilcoxon
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = wilcoxon(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

Kruskal-wallis H检验.

from scipy.stats import kruskal
data1 = [21,12,12,23,19,13,20,17,14,19]
data2 = [12,11,8,9,10,15,16,17,10,16]
stat,p = kruskal(data1,data2)
print("stat为：%f" %stat,"p值为：%f" %p)

0