]) Construct the empirical CDF and the K-S statistics (Dn+, Dn-, Dn). >>> n = len(x) >>> ecdfs = np.arange(n+1, dtype=float)/n >>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n], ... ecdfs[1:] - cdfs]) >>> with np.printoptions(precision=3): ... print(cols) [[-1.392 0.2 0.082 0.082 0.118] [-0.135 0.4 0.446 0.246 -0.046] [ 0.114 0.6 0.545 0.145 0.055] [ 0.19 0.8 0.575 -0.025 0.225] [ 1.82 1. 0.966 0.166 0.034]] >>> gaps = cols[:, -2:] >>> Dnpm = np.max(gaps, axis=0) >>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}') Dn-=0.246306, Dn+=0.224655 >>> probs = smirnov(n, Dnpm) >>> print(f'For a sample of size {n} drawn from N(0, 1):', ... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}', ... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}', ... sep='\n') For a sample of size 5 drawn from N(0, 1): Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711 Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245 Plot the empirical CDF and the standard normal CDF. >>> import matplotlib.pyplot as plt >>> plt.step(np.concatenate(([-2.5], x, [2.5])), ... np.concatenate((ecdfs, [1])), ... where='post', label='Empirical CDF') >>> xx = np.linspace(-2.5, 2.5, 100) >>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)') Add vertical lines marking Dn+ and Dn-. >>> iminus, iplus = np.argmax(gaps, axis=0) >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r', ... alpha=0.5, lw=4) >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m', ... alpha=0.5, lw=4) >>> plt.grid(True) >>> plt.legend(framealpha=1, shadow=True) >>> plt.show() Úsmirnovia7