>
y
- Parameters:
- y : float array_like
Absolute deviation between the Empirical CDF (ECDF) and the target CDF,
multiplied by sqrt(n).
- out : ndarray, optional
Optional output array for the function results
- Returns:
- scalar or ndarray
The value(s) of kolmogorov(y)
Notes
kolmogorov is used by stats.kstest in the application of the
Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
function is exposed in scpy.special, but the recommended way to achieve
the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
stats.kstwobign distribution.
Examples
.
sort
(
lap01
.
rvs
(
n
,
random_state
=
rng
))
np
.
mean
(
x
),
np
.
std
(
x
)
(-0.05841730131499543, 1.3968109101997568)
n
gaps
=
np
.
column_stack
([
cdfs
-
ecdfs
[:
n
],
ecdfs
[
1
:]
-
cdfs
])
Dn
=
np
.
max
(
gaps
)
Kn
=
np
.
sqrt
(
n
)
*
Dn
print
(
'Dn=
%f
, sqrt(n)*Dn=
%f
'
%
(
Dn
,
Kn
))
Dn=0.043363, sqrt(n)*Dn=1.371265
print
(
chr
(
10
)
.
join
([
'For a sample of size n drawn from a N(0, 1) distribution:'
,
' the approximate Kolmogorov probability that sqrt(n)*Dn>=
%f
is
%f
'
%
(
Kn
,
kolmogorov
(
Kn
)),
' the approximate Kolmogorov probability that sqrt(n)*Dn<=
%f
is
%f
'
%
(
Kn
,
kstwobign
.
cdf
(
Kn
))]))
For a sample of size n drawn from a N(0, 1) distribution:
the approximate Kolmogorov probability that sqrt(n)*Dn>=1.371265 is 0.046533
the approximate Kolmogorov probability that sqrt(n)*Dn<=1.371265 is 0.953467
.
linspace
(
-
3
,
3
,
100
)
plt
.
plot
(
x3
,
target
.
cdf
(
x3
),
label
=
'CDF for N(0, 1)'
)
plt
.
ylim
([
0
,
1
]);
plt
.
grid
(
True
);
plt
.
legend
();
iminus
,
iplus
=
np
.
argmax
(
gaps
,
axis
=
0
)
plt
.
vlines
([
x
[
iminus
]],
ecdfs
[
iminus
],
cdfs
[
iminus
],
color
=
'r'
,
linestyle
=
'dashed'
,
lw
=
4
)
plt
.
vlines
([
x
[
iplus
]],
cdfs
[
iplus
],
ecdfs
[
iplus
+
1
],
color
=
'r'
,
linestyle
=
'dashed'
,
lw
=
4
)
plt
.
show
()