2021-07-24 python 雅克-贝拉JB正态验证
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.jarque_bera.htmlimport numpy as npimport xlrdimport pandas as pdimport matplotlib.pyplot as pltfrom scipy import interpolate#插值, __vers
·
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.jarque_bera.html
import numpy as np
import xlrd
import pandas as pd
import matplotlib.pyplot as plt
from scipy import interpolate#插值, __version__
from scipy import stats#统计
from scipy.optimize import leastsq ##引入最小二乘法算法
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
def JarqueBera():
'''雅克-贝拉'''
'''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.jarque_bera.html官网'''
rng = np.random.default_rng()
x = rng.normal(0, 1, 100000)
jarque_bera_test = stats.jarque_bera(x)
print(jarque_bera_test)
'''一般p显著水平要大于0.05'''
# Jarque_beraResult(statistic(JB值)=3.3415184718131554, pvalue(显著水平)=0.18810419594996775)
JarqueBera()
Ctrl键点开函数可得,其内部公式
mu = x.mean()
diffx = x - mu
skewness = (1 / n * np.sum(diffx**3)) / (1 / n * np.sum(diffx**2))**(3 / 2.)
kurtosis = (1 / n * np.sum(diffx**4)) / (1 / n * np.sum(diffx**2))**2
jb_value = n / 6 * (skewness**2 + (kurtosis - 3)**2 / 4)
p = 1 - distributions.chi2.cdf(jb_value, 2)
更多推荐
已为社区贡献1条内容
所有评论(0)