**[R] ksmirnov** -- Kolmogorov-Smirnov equality-of-distributions test

__Syntax__

One-sample Kolmogorov-Smirnov test

**ksmirnov** *varname* **=** *exp* [*if*] [*in*]

Two-sample Kolmogorov-Smirnov test

**ksmirnov** *varname* [*if*] [*in*] **,** **by(***groupvar***)** [__e__**xact**]

In the first syntax, *varname* is the variable whose distribution is being
tested, and *exp* must evaluate to the corresponding (theoretical)
cumulative. In the second syntax, *groupvar* must take on two distinct
values. The distribution of *varname* for the first value of *groupvar* is
compared with that of the second value.

__Menu__

**Statistics > Nonparametric analysis > Tests of hypotheses >**
**Kolmogorov-Smirnov test**

__Description__

**ksmirnov** performs one- and two-sample Kolmogorov-Smirnov tests of the
equality of distributions. A one-sample test compares the distribution
of the tested variable with the specified distribution. A two-sample
test tests the equality of the distributions of two samples.

When testing for normality, please see **[R] sktest** and **[R] swilk**.

__Options__

+------+
----+ Main +-------------------------------------------------------------

**by(***groupvar***)** is required. It specifies a binary variable that identifies
the two groups.

**exact** specifies that the exact p-value be computed.

__Examples__

Setup
**. webuse ksxmpl**
**. summarize x**

One-sample test
**. ksmirnov x = normal((x-r(mean))/r(sd))**

Two-sample test
**. ksmirnov x, by(group)**

Two-sample test, exact value
**. ksmirnov x, by(group) exact**

__Stored results__

**ksmirnov** stores the following in **r()**:

Scalars
**r(D_1)** D from line 1
**r(p_1)** p-value from line 1
**r(D_2)** D from line 2
**r(p_2)** p-value from line 2
**r(D)** combined D
**r(p)** combined p-value
**r(p_exact)** exact combined p-value

Macros
**r(group1)** name of group from line 1
**r(group2)** name of group from line 2