Skip to content

Instantly share code, notes, and snippets.

@airalcorn2
Last active December 22, 2016 00:05
Show Gist options
  • Save airalcorn2/49f3828e8a5b02614649f4d9f779f1dc to your computer and use it in GitHub Desktop.
Save airalcorn2/49f3828e8a5b02614649f4d9f779f1dc to your computer and use it in GitHub Desktop.
Kolmogorov–Smirnov statistic experiment.
# Michael A. Alcorn ([email protected])
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import numpy as np
import statsmodels.api as sm # recommended import according to the docs
import matplotlib.pyplot as plt
sample = np.random.uniform(0, 1, 50)
from scipy.stats import kstest
F = "uniform"
trials = 10000
for samples in [100, 1000]:
Ds = []
x_Ds = []
for i in range(trials):
G = np.random.uniform(size = samples)
D = kstest(G, F).statistic
Ds.append(D)
ecdf = sm.distributions.ECDF(G)
x = np.linspace(min(G), max(G))
y = ecdf(x)
x_D = x[np.abs(y - x).argmax()]
x_Ds.append(x_D)
# plt.step(x, y)
# plt.plot([0, 1], [0, 1], "k-")
# plt.show()
sns.distplot(Ds)
plt.show()
sns.distplot(x_Ds)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment