Created
June 19, 2016 22:06
-
-
Save agabrielsen/e029a1833b79580832735d0bf58c4bb3 to your computer and use it in GitHub Desktop.
Jarque-Bera Test for Normality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jarquebera <- function(x){ | |
#' Test for normality Jarque-Bera, Bowman-Shenton(1977)) | |
#' | |
#' Calculates Jarque-Bera Normality test & corresponding p-value | |
#' @param x a Nx1 vector | |
#' @return Jarque-Bera statistic | |
#' @export | |
#' @author Alexandros Gabrielsen | |
T=length(x) | |
mu=mean(x) | |
mu3=sum((x-mu)^3)/T | |
mu4=sum((x-mu)^4)/T | |
sig2=((T-1)/T) * var(x) # Population Variance | |
b1=(mu3/(sig2^(3/2)))^2 | |
b2=mu4/(sig2)^2 | |
W=T*( b1/6 + ((b2-3)^2)/24) | |
chi2_pval=1-chis_cdf(W,2) # 1-pchisq(W,2) | |
jb = as.matrix(c(W, chi2_pval)) | |
colnames(jb) = "Jarque-Bera" | |
rownames(jb) = c("JBStat", "Probability") | |
return(jb) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment