-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormality.py
More file actions
25 lines (17 loc) · 881 Bytes
/
Copy pathnormality.py
File metadata and controls
25 lines (17 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from scipy import stats
import numpy as np
alpha = 0.05
array = np.random.random(250)*2 - 1
print('Data has a normal distribution?')
shapiro = stats.shapiro(array)
print('Shapiro:', 'YES' if shapiro.pvalue > alpha else 'NO')
ntest = stats.normaltest(array)
print('Normal Test:', 'PROBABELY' if ntest.pvalue > alpha else 'NO')
ks = stats.kstest(array, stats.norm(array.mean(), array.std()).cdf)
print('Kolmogorov–Smirnov:', 'YES' if ks.pvalue > alpha else 'NO')
anderson = stats.anderson(array, 'norm')
print('Anderson (alpha=0.05):', 'YES' if anderson.statistic <= anderson.critical_values[2] else 'NO')
def normality_statistic(sample):
return stats.shapiro(sample).statistic
monte_carlo = stats.monte_carlo_test(array, stats.norm.rvs, normality_statistic)
print('Monte-Carlo (shapiro based):', 'YES' if monte_carlo.pvalue > alpha else 'NO')