导航
Jarque Bera test
JB
检验主要检验样本数据的skewness
和kurtosis
是否与正态分布相匹配,统计检验的结果是非负的,如果检验值比0大很多,那么表示样本数据不符合normal distribution
.
JB
检验的统计量定义为
J
B
=
n
6
(
S
2
+
1
4
(
K
−
3
)
2
)
JB=\frac{n}{6}(S^2+\frac{1}{4}(K-3)^2)
JB=6n(S2+41(K−3)2)
其中,
n
n
n表示样本数量,或者自由度(d.o.f
),
S
S
S表示样本skewness
,
K
K
K表示样本kurtosis
:
{
S
=
μ
^
3
σ
^
3
=
1
n
∑
i
=
1
n
(
x
i
−
x
ˉ
)
3
(
1
n
∑
i
=
1
n
(
x
i
−
x
ˉ
)
2
)
3
2
K
=
μ
^
4
σ
^
4
=
1
n
∑
i
=
1
n
(
x
i
−
x
ˉ
)
4
(
1
n
∑
i
=
1
n
(
x
i
−
x
ˉ
)
)
2
\begin{cases} S=\frac{\hat{\mu}_3}{\hat{\sigma}^3}=\frac{\frac{1}{n}\sum_{i=1}^n(x_i-\bar{x})^3}{(\frac{1}{n}\sum_{i=1}^n(x_i-\bar{x})^2)^{\frac{3}{2}}}\\ K=\frac{\hat{\mu}_4}{\hat{\sigma}_4}=\frac{\frac{1}{n}\sum_{i=1}^n(x_i-\bar{x})^4}{(\frac{1}{n}\sum_{i=1}^n(x_i-\bar{x}))^2} \end{cases}
⎩⎨⎧S=σ^3μ^3=(n1∑i=1n(xi−xˉ)2)23n1∑i=1n(xi−xˉ)3K=σ^4μ^4=(n1∑i=1n(xi−xˉ))2n1∑i=1n(xi−xˉ)4
如果数据采样自一个正态分布的总体,那么JB
检验渐近于
χ
(
2
)
\chi(2)
χ(2)分布,假设检验的零假设为一个联合假设(joint hypothesis
):偏度为0且超额峰度为0.
If the data comes from a normal distribution, the JB statistic asymptotically has a
chi-squared distribution
withtwo degrees of freedom
,so the statistic can be used to test the hypothesis that the data are from anormal distribution
. Thenull hypothesis
is a joint hypothesis of the skewness being zero and the excess kurtosis being zero. Samples from a normal distribution have an expected skewness of0
and an expected excess kurtosis of0
. As the definition of JB shows, any deviation from this increases theJB statistic
.
Scipy.stats.jarque_bera
scipy.stats.jarque_bera(x)
Parameter:
x: array_like // obsverations of a random variable
Returns:
jb_value: float, the test statistic
p: the p-value for the hypothesis test
statsmodels.stats.stattools.jarque_bera
statsmodels.stats.stattools.jarque_bera(resids, axis=0)
Parameters:
resids: array_like // data to test for normality
axis: int
Returns:
JB: float, the Jarque-Bera test statistic
JBpv: float, the pvalue of test statistic
skew: estimated skewness of the data
kurtosis: estimated kurtosis of the data
industry 12 portfolio JB test
对美国12个行业指数returns
进行JB检验
def JB_test(df, ind_names):
if df is None or ind_names is None: raise Exception('Data Frame is None')
for ind_name in ind_names:
ind_returns = df[ind_name]
jb_ans = JB(ind_returns)
# print(jb_ans)
_jbstats, _pvalue = jb_ans.statistic, jb_ans.pvalue
print(f'{ind_name}\t{_jbstats}\t{_pvalue}')
参考资料
python数据正态性检验
Jarque Bera test. wiki
JB正态性检验
scipy jarque_bera