 |
Normality test using Shapiro-Wilk method
Source code name: " shapiro_wilk.py"
Programming language: Python
Topic: Statistics/Tests
DMelt Version 2. Last modified: 02/07/1972. License: Pro
https://datamelt.org/code/cache/ shapiro_wilk_7244.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: Shapiro-Wilk test.
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=1+r.nextDouble()
h2.fill(r2)
data2.append(r2)
h1.setErrAll(1)
h2.setErrAll(0)
c1.draw(h1)
c1.draw(h2)
from com.datumbox.framework.core.statistics.nonparametrics.onesample import ShapiroWilk
w1=ShapiroWilk.shapiroWilkW(data1)
w2= ShapiroWilk.shapiroWilkW(data2)
print "Probability for Normal distribution from Shapiro-Wilk for Gaussian=",1-w1
print "Probability for Normal distribution from Shapiro-Wilk for non-Gaussian=",1-w2
You see the box below because you did not login.