コード例 #1
0
def kolmogorov(alpha):
    """
    :param alpha: the scale parameter
    :return: line about accepting or rejecting a hypothesis
    """
    arr = np.random.exponential(scale=1 / alpha, size=n)  # sample of size n from an exponential distribution

    arr = np.sort(arr)  # order statistic
    k = np.array(range(1, len(arr) + 1))

    D = np.maximum(expon.cdf(x=arr, loc=0, scale=1) - (k - 1) / len(arr),
                   k / len(arr) - expon.cdf(x=arr, loc=0, scale=1)).max()

    if np.sqrt(len(arr)) * D < kolmogi(gamma):
        return f'D = {D:0.4f}. \nThe statistical data do NOT CONFLICT with the H0 hypothesis.\n'
    else:
        return f'D = {D:0.4f}. \nThe statistical data do CONFLICT with the H0 hypothesis.\n'
コード例 #2
0
def smirnov(alpha):

    """
    Compute the Kolmogorov-Smirnov statistic on 2 samples.
    :param alpha: the scale parameter
    :return: line about accepting or rejecting a hypothesis
    """
    sample_1 = np.sort(np.random.exponential(scale=1, size=n))
    sample_2 = np.sort(np.random.exponential(scale=1 / alpha, size=int(n / 2)))

    k = np.array(range(1, len(sample_2) + 1))

    D = np.maximum(expon.cdf(x=sample_2, loc=0, scale=1) - (k - 1) / len(sample_2),
                   k / len(sample_2) - expon.cdf(x=sample_2, loc=0, scale=1)).max()

    criteria = kolmogi(gamma) * np.sqrt((1 / n) + (1 / (n / 2)))

    if D < criteria:
        return f'D = {D:0.4f}, criteria = {criteria:0.4f}. \n' \
               f'The statistical data do NOT CONFLICT with the H0 hypothesis.'
    else:
        return f'D = {D:0.4f}, criteria = {criteria:0.4f}. \n' \
               f'The statistical data do CONFLICT with the H0 hypothesis.'
コード例 #3
0
ファイル: test_kolmogorov.py プロジェクト: ElDeveloper/scipy
 def _k_ki(_p):
     return kolmogorov(kolmogi(_p))
コード例 #4
0
ファイル: test_kolmogorov.py プロジェクト: ElDeveloper/scipy
 def test_nan(self):
     assert_(np.isnan(kolmogi(np.nan)))
コード例 #5
0
ファイル: test_kolmogorov.py プロジェクト: ElDeveloper/scipy
 def _ki_k(_x):
     return kolmogi(kolmogorov(_x))
コード例 #6
0
 def _k_ki(_p):
     return kolmogorov(kolmogi(_p))
コード例 #7
0
 def test_nan(self):
     assert_(np.isnan(kolmogi(np.nan)))
コード例 #8
0
 def _ki_k(_x):
     return kolmogi(kolmogorov(_x))
コード例 #9
0
from scipy.special import kolmogi

alpha = [0.1, 0.05, 0.025, 0.01]
lmb = kolmogi(alpha)

res = '\\begin{tabular}{|c|c|c|c|c|}\n \\hline \n$\\alpha$ & '
for a in alpha[:-1]:
    res += f'{a} & '
res += f'{alpha[-1]} \\\\\n \\hline \n'
res += '$\\lambda_{\\alpha}$ & '

for l in lmb[:-1]:
    res += f'{l:.3f} & '
res += f'{lmb[-1]:.3f} \\\\\n \\hline \n'

res += "\\end{tabular}"

with open(".\\tables\\kolmogorov_table_raw.tex", "w") as fin:
    fin.write(res)