It is a bit confusing to understand the distribution of the data. Here, I collected the information I've found from the internet about Anderson Test.You may check the references for detailed information.
import pandas as pd
import numpy as np
import scipy as sc
from matplotlib import pyplot as plt
from scipy.stats import anderson
from scipy.stats import expon
References:
#Create random data
np.random.seed(0)
data = np.random.randint(0, 10, size=50)
# Apply Test
result = anderson(data, dist='norm')
print(result)
#Decide to Reject & Not Reject the Null Hypothesis (null hypothesis is the default value 'norm')
if result[0] > result[1][2]:
print('Null hypothesis can be rejected at', result[2][2], ' %significance level')
else:
print('Null hypothesis cant be rejected.')
# Useful Stats
print('statistics:', np.round(result[0],3))
print('critical value at defined significance level:', result[1][2])
print('Significance Level:', result[2][2])
print("""
The test statistic is {} \n
We can compare this value to each critical value that corresponds to each significance level to see if the test results are significant. \n
For example:The critical value for α = 0.01 is 1.021. \n
Because the test statistic {} is greater than this critical value, the results are significant at a significance level of 0.01. \n
The critical value for α = 0.025 is 0.858. Because the test statistic (1.1926) is greater than this critical value, the results are significant at a significance level of 0.025. \n
And so on. \n
We can see that the test results are significant at every significance level, which means we would reject the null hypothesis of the test no matter which significance level we choose to use.\n
Thus, we have sufficient evidence to say that the sample data is not normally distributed.[1]
""".format(np.round(result[0],3), np.round(result[0],3)))
#generate exponential distribution
exp_data = expon.rvs(scale=100, size=10000)
#create histogram
plt.hist(exp_data, density=True, edgecolor='black')
defined_distribution= 'norm'
test_result = anderson(exp_data, dist=defined_distribution)
if test_result[0] > test_result[1][2]:
print('Null hypothesis: "', defined_distribution, '" can be rejected at', test_result[2][2], ' % significance level.')
else:
print('Null hypothesis cant be rejected. It is ', defined_distribution, 'distribution.')
print('')
print(test_result)
print('')
print('statistics:', np.round(test_result[0],3))
print('critical value at defined significance level:', test_result[1][2])
print('Significance Level:', test_result[2][2])
defined_distribution= 'expon'
test_result = anderson(exp_data, dist=defined_distribution)
if test_result[0] > test_result[1][2]:
print('Null hypothesis can be rejected at', test_result[2][2], ' % significance level.')
else:
print('Null hypothesis cant be rejected. It is "', defined_distribution, '" distribution.')
print('')
print(test_result)
print('')
print('statistics:', np.round(test_result[0],3))
print('critical value at defined significance level:', test_result[1][2])
print('Significance Level:', test_result[2][2])