 |
Normality tests using Anderson-Darling method
Source code name: "normalit_tests.py"
Programming language: Python
Topic: Statistics/Tests
DMelt Version 1.4. Last modified: 02/07/1972. License: Pro
https://datamelt.org/code/cache/normalit_tests_3553.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Create two distributions. One is a Normal distribution. The second is non-Normal.
# Run normality tests are used to determine if a data set is well-modeled by a normal distribution,
# and to compute how likely it is for normally distributed.
# Calculate: Normality tests using Anderson-Darling. You can also do , Cramer-Von Mises, D'Agostino-Pearson, Jarque Bera, Kolmogorov-Lilliefors, Shapiro-Francia, Shapiro-Wilk.
# This example calculates the p-value using R.B. D'Augostino and M.A. Stephens, Eds., 1986, Goodness-of-Fit Techniques, Marcel Dekker.
from java.awt import Color
from java.util import Random
from jhplot import *
from math import *
c1 = HPlotJa("Canvas")
c1.setGTitle("Normality tests")
c1.setAutoRange()
c1.visible()
h1 = H1D("Histo1",40, -3, 3.0)
h1.setColor(Color.blue)
h2 = H1D("Histo2",40, -3, 3.0)
r = Random()
data1=[]
data2=[]
for i in range(1000):
r1=r.nextGaussian()
h1.fill(r1)
data1.append(r1)
r2=2*r.nextDouble()
h2.fill(r2)
data2.append(r2)
h1.setErrAll(1)
h2.setErrAll(0)
c1.draw(h1)
c1.draw(h2)
import math
def pvalue(AD):
if (AD>0.6): return math.exp(1.2937-5.709*AD+0.0186*(AD*AD))
if (AD>0.34 and AD<0.6): return math.exp(0.9177-4.279*AD-1.38*(AD*AD))
if (0.2>AD and AD<=0.34): return 1-math.exp(-8.318 + 42.796*AD- 59.938*(AD*AD))
if AD<0.2: 1-math.exp(-13.436 + 101.14*AD- 223.73*(AD*AD))
return 0
from jdistlib.disttest import NormalityTest
w1=NormalityTest.anderson_darling_statistic(data1)
w2=NormalityTest.anderson_darling_statistic(data2)
print "anderson_darling for Gaussian=",w1
print "anderson_darling_statistic for Non-Gaussian=",w2
print "p-value for Gaussian=",pvalue(w1)
print "p-value for Non-Gaussian=",pvalue(w2)
You see the box below because you did not login.