Created
August 5, 2022 02:13
-
-
Save JohnDeJesus22/0ef1ec00e7a4bb93df0d287c0e36d8a9 to your computer and use it in GitHub Desktop.
jb_scratch.py
This file contains 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
def jb_test_statistic(column): | |
""" | |
Function for creating JB test statistic equation from pandas dataframe column | |
""" | |
# have all nulls removed, get the data length, and convert column values to an array | |
column = column.dropna() | |
n = column.shape[0] | |
column_values = column.values | |
# compute mean and mean diffs | |
mean = column_values.mean() | |
mean_diff = column_values - mean | |
# compute sample skewness | |
skew_numerator = (1/n) * sum(mean_diff**3) | |
skew_denominator = ((1/n) * sum(mean_diff**2))**(3/2) | |
s = skew_numerator/skew_denominator | |
# compute sample kurtosis | |
kurtosis_numerator = (1/n) * sum(mean_diff**4) | |
kurtosis_denominator = ((1/n) * sum(mean_diff**2))**2 | |
k = kurtosis_numerator/kurtosis_denominator | |
# compute JB test statistic | |
jb = (n/6) * (s**2 + (1/4)*(k - 3)**2) | |
return jb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment