# Jarque–Bera test

In statistics, the Jarque–Bera test is a goodness-of-fit test of whether sample data have the skewness and kurtosis matching a normal distribution. The test is named after Carlos Jarque and Anil K. Bera. The test statistic is always nonnegative. If it is far from zero, it signals the data do not have a normal distribution.
The test statistic JB is defined as
    ${\mathit {JB}}={\frac {n}{6}}\left(S^{2}+{\frac {1}{4}}(K-3)^{2}\right)$
where n is the number of observations (or degrees of freedom in general); S is the sample skewness, K is the sample kurtosis :
    $S={\frac {{\hat {\mu }}_{3}}{{\hat {\sigma }}^{3}}}={\frac {{\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{3}}{\left({\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{2}\right)^{3/2}}},$
    $K={\frac {{\hat {\mu }}_{4}}{{\hat {\sigma }}^{4}}}={\frac {{\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{4}}{\left({\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{2}\right)^{2}}},$
where ${\hat {\mu }}_{3}$ and ${\hat {\mu }}_{4}$ are the estimates of third and fourth central moments, respectively, ${\bar {x}}$ is the sample mean, and ${\hat {\sigma }}^{2}$ is the estimate of the second central moment, the variance.
If the data comes from a normal distribution, the JB statistic asymptotically has a chi-squared distribution with two degrees of freedom, so the statistic can be used to test the hypothesis that the data are from a normal distribution. The null 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 of 0 and an expected excess kurtosis of 0 (which is the same as a kurtosis of 3). As the definition of JB shows, any deviation from this increases the JB statistic.
For small samples the chi-squared approximation is overly sensitive, often rejecting the null hypothesis when it is true. Furthermore, the distribution of p-values departs from a uniform distribution and becomes a right-skewed unimodal distribution, especially for small p-values. This leads to a large Type I error rate. The table below shows some p-values approximated by a chi-squared distribution that differ from their true alpha levels for small samples.
    Calculated p-values equivalents to true alpha levels at given sample sizes True α level20305070100 0.1 0.3070.2520.2010.1830.1560 0.05 0.14610.1090.0790.0670.062 0.025 0.0510.03030.0200.0160.0168 0.01 0.00640.00330.00150.00120.002
(These values have been approximated using Monte Carlo simulation in Matlab)
In MATLAB's implementation, the chi-squared approximation for the JB statistic's distribution is only used for large sample sizes (> 2000). For smaller samples, it uses a table derived from Monte Carlo simulations in order to interpolate p-values.

## History

The statistic was derived by Carlos M. Jarque and Anil K. Bera while working on their Ph.D. Thesis at the Australian National University.

## Jarque–Bera test in regression analysis

According to Robert Hall, David Lilien, et al. (1995) when using this test along with multiple regression analysis the right estimate is:
    ${\mathit {JB}}={\frac {n-k}{6}}\left(S^{2}+{\frac {1}{4}}(K-3)^{2}\right)$
where n is the number of observations and k is the number of regressors when examining residuals to an equation.

## Implementations

* ALGLIB includes an implementation of the Jarque–Bera test in C++, C#, Delphi, Visual Basic, etc.
* gretl includes an implementation of the Jarque–Bera test
* Julia includes an implementation of the Jarque-Bera test JarqueBeraTest in the HypothesisTests package.
* MATLAB includes an implementation of the Jarque–Bera test, the function "jbtest".
* Python statsmodels includes an implementation of the Jarque–Bera test, "statsmodels.stats.stattools.py".
* R includes implementations of the Jarque–Bera test: jarque.bera.test in the package tseries, for example, and jarque.test in the package moments.
* Wolfram includes a built in function called, JarqueBeraALMTest and is not limited to testing against a Gaussian distribution.