0%

统计学中的Z值

在统计结果中经常出现的Z值是个什么东西?

标准分数(Standard Score,又称z-score,中文称为Z-分数或标准化值)在统计学中是一种无因次值,就是一种纯数字标记,是借由从单一(原始)分数中减去母体的平均值,再依照母体(母集合)的标准差分割成不同的差距,按照z值公式,各个样本在经过转换后,通常在正、负五到六之间不等。来源

Z值的计算公式为:$$z=\frac{(x-\mu)}{\sigma}$$,其中:x为某一特征值;$\mu$为总体均值;$\sigma$为总体标准差。在实际中都是通过抽样来估计总体,则Z值的计算公式为:$$z=\frac{(x-\frac{}{x})}{s}$$ 其中:x为某一特征值;$\frac{}{x}$为样本均值;s为样本的标准差。

练习:继续以统计学与pandas学习(三) 中学生期末考试成绩为例。30号同学成绩分别为:语文75、数学74、英语77.5、物理75、化学66、政治93、总分460.5。通过Z值的计算就可以看出该学生的成绩距离均值的程度,也可以看出哪个成绩相对更好一些。

1
2
3
4
5
6
7
8
9
10
11
12
import pandas as pd
from scipy.stats import norm

df = pd.read_excel('201706.xls',index_col=0)
cdf_chinese = norm.cdf ((75-df['chinese'].mean())/df['chinese'].std())
cdf_math = norm.cdf ((74-df['math'].mean())/df['math'].std())
cdf_english = norm.cdf ((77.5-df['english'].mean())/df['english'].std())
cdf_physics = norm.cdf ((75-df['physics'].mean())/df['physics'].std())
cdf_chemistry = norm.cdf ((66-df['chemistry'].mean())/df['chemistry'].std())
cdf_politics = norm.cdf ((93-df['politics'].mean())/df['politics'].std())
cdf_total = norm.cdf ((460.5-df['total'].mean())/df['total'].std())
print('语文:',cdf_chinese,'数学:',cdf_math,'英语:',cdf_english,'物理:',cdf_physics,'化学:',cdf_chemistry,'政治:',cdf_politics,'总分:',cdf_total)

输出:

1
2
3
4
5
6
7
语文: 0.512762574277   # 超过班内51.28%的学生
数学: 0.576380249822 # 超过班内57.64%的学生
英语: 0.671241471981 # 超过班内67.12%的学生
物理: 0.700283612352 # 超过班内70%的学生
化学: 0.669569880727 # 超过班内66.96%的学生
政治: 0.779138294084 # 超过班内77.91%的学生
总分: 0.669346076075 # 超过班内66.93%的学生

Z值的计算,也可以使用scipy.stats.mstats.zscore,如:
1
2
from scipy import stats
norm.cdf(stats.zscore(df['chinese']))

结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
array([  8.96025975e-01,   8.65604972e-01,   8.48299141e-01,
9.49773804e-01, 8.65604972e-01, 8.65604972e-01,
8.29572844e-01, 6.88765709e-01, 7.40772681e-01,
8.29572844e-01, 6.61173316e-01, 7.87884941e-01,
7.40772681e-01, 7.87884941e-01, 7.15336201e-01,
7.40772681e-01, 7.87884941e-01, 4.82270298e-01,
7.40772681e-01, 7.40772681e-01, 8.29572844e-01,
6.61173316e-01, 5.73622936e-01, 7.87884941e-01,
6.03452153e-01, 6.88765709e-01, 6.61173316e-01,
6.88765709e-01, 4.82270298e-01, 5.12856042e-01,
7.64980832e-01, 3.91843157e-01, 7.87884941e-01,
7.15336201e-01, 6.32687652e-01, 6.32687652e-01,
4.82270298e-01, 7.15336201e-01, 5.43366317e-01,
3.34364528e-01, 6.61173316e-01, 6.61173316e-01,
3.34364528e-01, 5.73622936e-01, 4.21588634e-01,
7.87884941e-01, 3.34364528e-01, 6.32687652e-01,
4.21588634e-01, 3.62717037e-01, 4.82270298e-01,
3.52826712e-02, 1.87265855e-01, 2.55283562e-01,
3.91843157e-01, 9.51160910e-03, 4.21588634e-01,
2.97181714e-02, 5.12856042e-01, 3.34364528e-01,
1.01783707e-01, 1.87265855e-01, 4.16744340e-02,
1.31766684e-01, 1.67346517e-01, 1.98788044e-05,
1.42005497e-02, 1.48846960e-01, 4.89734172e-02])