Jarque-Bera Test in R
To perform Jarque-Bera Test in R there are a function called jarque.bera.test() . There are some steps that we need to follow.
Step 1: Load the Required Package
Firstly install and load the tseries package. Install it using install.packages(“tseries”) and then load it using library(tseries).
Step 2 : Prepare the Data
Ensure that the data is properly prepared and stored in a format that R can recognize. This may involve loading a dataset from a file or creating a vector or matrix of data within R.
Step 3: Call the Function
Use the jarque.bera.test() function, passing the data as an argument.
Here is the example tseries library, which contains the jarque.bera.test() function.
# Load required library
library(tseries)
# Generate some random data
data <- rnorm(100)
# Perform the Jarque-Bera test
jb_test <- jarque.bera.test(data)
# Print the test result
print(jb_test)
Output:
Jarque Bera Test data: data X-squared = 0.013514, df = 2, p-value = 0.9933
Firstly load the tseries library, which contains the jarque.bera.test() function for performing the Jarque-Bera test.
- It generates a vector of 100 random numbers from a standard normal distribution using rnorm(100).
- The Jarque-Bera test is then applied to the generated data using jarque.bera.test(data).
- The result of the test is stored in the variable jb_test.
- Finally, the test result is printed using print(jb_test), which displays the test statistic and the p-value.
- The Jarque-Bera test was performed on the given data.
- The test statistic (X-squared) is 0.013514.
- The degrees of freedom (df) is 2.
- The p-value associated with the test is 0.9933.
Since the p-value is greater than the common significance levels (e.g., 0.05), we fail to reject the null hypothesis of normality. This suggests that there is no strong evidence to suggest that the data significantly deviates from a normal distribution.
Jarque-Bera test using the moments package in R
Here is another example of performing the Jarque-Bera test using the moments package in R.
# Install and load required library
install.packages("moments")
library(moments)
# Generate some random data
data <- rnorm(100)
# Perform the Jarque-Bera test
jb_test <- jarque.test(data)
# Print the test result
print(jb_test)
Output:
Jarque-Bera Normality Test data: data JB = 0.45895, p-value = 0.795 alternative hypothesis: greater
First install and load the moments package which contains the jarque.test() function.
- Random data is generated using the rnorm() function, which creates a vector of random numbers from a normal distribution.
- The Jarque-Bera test is applied to the generated data using jarque.test(data).
- The result of the test is stored in the variable jb_test.
- Finally, the test result is printed, showing the test statistic, p-value, skewness, and kurtosis.
Jarque-Bera statistic: This is the test statistic for the Jarque-Bera test. It quantifies the departure of the sample skewness and kurtosis from the skewness and kurtosis of a normal distribution. Here, the JB statistic is 0.15467.
- p-value: The p-value indicates the probability of observing a test statistic as extreme as, or more extreme than, the one calculated from the sample data under the assumption that the null hypothesis is true. A higher p-value, such as 0.9256 in this case, suggests weak evidence against the null hypothesis. It means that there is no strong evidence to reject the null hypothesis that the data comes from a normal distribution.
- Alternative hypothesis: In this case, the alternative hypothesis is specified as “greater”, which means that the test is one-tailed, and the alternative hypothesis is that the data are greater than expected under a normal distribution.
Uses of the Jarque-Bera Test in R
- Normality Check: JB test assesses whether data follows a normal distribution.
- Quality Control: Used in finance, economics, and other fields to detect anomalies in data.
- Model Validation: Ensures that statistical models meet the assumption of normality for accurate results.
- Robustness Checks: Part of sensitivity analysis to verify the robustness of research findings.
- Guide for Analysis: Helps decide between parametric and non-parametric methods based on data distribution.
- Data Preprocessing: Guides preprocessing steps like data transformations for better analysis.
How to Conduct a Jarque-Bera Test in R
In this article, we will discuss What is the Jarque-Bera Test and how we perform the Jarque-Bera Test in R Programming Language.