Python verifies that the Jarque-bera conforms to the normal distribution

Source: Internet
Author: User


This article to share the content is Python test jarque-bera is normal distribution, has a certain reference value, the need for friends can refer to

The normal distribution is a normality test of the general distributions. When the sequence obeys a normal distribution, JB statistics:

Gradually obey the distribution. where n is the sample size, the s,k is the skewness and kurtosis of the random variable respectively. The calculation formula is as follows:



Python's sicipy.stats is a function of a call to Skewness and Kurtosis, stats.skew(y) stats.kurtosis(y) where the formula for Kurtosis is

In Excel, the skewness and kurtosis are calculated as follows:

Let's do it all over again. The formula for calculating skewness and skew in Python's scipy library and the establishment of normal distribution test.

Code

Import NumPy as Npimport scipy.stats as Statsdef self_jbtest (y):    # sample size n    n = y.size    y_ = Y-y.mean ()    "" " C4/>M2: Second-order center massive    Skew skewness = three-Step center moment with m2^1.5 ratio    Krut peak = four-order center Mega vs. M2^2    "" "    M2 = Np.mean (y_**2)    skew =  Np.mean (y_**3)/m2**1.5    Krut = Np.mean (y_**4)/m2**2    "" "    calculates the JB statistic and establishes hypothesis test    " ""    JB = N (skew* *2/6 + (krut-3) **2/24)    pvalue = 1-STATS.CHI2.CDF (jb,df=2)    print ("skewness:", Stats.skew (y), skew)    print (" Peak: ", Stats.kurtosis (y) +3,krut)    print (" JB test: ", Stats.jarque_bera (y))    return Np.array ([jb,pvalue]) y1 = Stats.norm.rvs (size=10) y2 = Stats.t.rvs (size=1000,df=4) print (Self_jbtest (y1)) print (Self_jbtest (y2))

Results

=============== restart:c:\users\tinysoft\desktop\jb normality test. py = = ============= skewness: 0.5383125387398069 0.53831253874 Peak: 2.9948926317585918 2.99489263176 JB Test: (0.48297818444514068, 0.78545737133644544) [0.48297818 0.78545737] skewness: -1.0488825341925703-1.04888253419 Peak: 13.40804986639119 13.40804        98664 JB Test: (4697.0050126426095, 0.0) [4697.00501264 0. ]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.