How can a Jarque-Bera test be conducted in R?

A Jarque-Bera test is a statistical test used to determine if a set of data follows a normal distribution. In order to conduct this test in R, first, the data must be loaded into the R environment. Then, the “jarque.bera.test” function from the “tseries” package can be used to perform the test. This function takes in the data as its argument and returns the test statistic, p-value, and a conclusion on whether the data is normally distributed. The p-value is compared to a significance level, typically 0.05, to determine if the null hypothesis of normality can be rejected. If the p-value is less than the significance level, it can be concluded that the data does not follow a normal distribution. On the other hand, if the p-value is greater than the significance level, the null hypothesis cannot be rejected and it can be assumed that the data follows a normal distribution.

Conduct a Jarque-Bera Test in R


The Jarque-Bera test is a goodness-of-fit test that determines whether or not sample data have skewness and kurtosis that matches a .

The test statistic of the Jarque-Bera test is always a positive number and if it’s far from zero, it indicates that the sample data do not have a normal distribution.

The test statistic JB is defined as:

JB  =[(n-k+1) / 6] * [S2 + (0.25*(C-3)2)]

where is the number of observations in the sample, is the number of regressors (k=1 if not used in the context of regression), is the sample skewness, and is the sample kurtosis.

Under the null hypothesis of normality, JB ~ X2(2)

This tutorial explains how to conduct a Jarque-Bera test in R.

Jarque-Bera test in R

To conduct a Jarque-Bera test for a sample dataset, we can use the tseries package:

#install (if not already installed) and load tseries package
if(!require(tseries)){install.packages('tseries')}

#generate a list of 100 normally distributed random variables
dataset <- rnorm(100)

#conduct Jarque-Bera test
jarque.bera.test(dataset)

This generates the following output:

This tells us that the test statistic is 0.67446 and the p-value of the test is 0.7137. In this case, we would fail to reject the null hypothesis that the data is normally distributed.

This result shouldn’t be surprising since the dataset we generated is composed of 100 random variables that follow a normal distribution.

Consider instead if we generated a dataset that was comprised of a list of 100 uniformly distributed random variables:

#install (if not already installed) and load tseries package
if(!require(tseries)){install.packages('tseries')}

#generate a list of 100 uniformly distributed random variables
dataset <- runif(100)

#conduct Jarque-Bera test
jarque.bera.test(dataset)

This generates the following output:

This tells us that the test statistic is 8.0807 and the p-value of the test is 0.01759. In this case, we would reject the null hypothesis that the data is normally distributed. We have sufficient evidence to say that the data in this example is not normally distributed.

This result shouldn’t be surprising since the dataset we generated is composed of 100 random variables that follow a uniform distribution. After all, the data is expected to be uniformly distributed, not normally distributed.

x