user573347
user573347

Reputation: 975

R: Is the Kolmogorov–Smirnov test capable of comparing samples?

Does anyone know whether the Kolmogorov–Smirnov test is capable of comparing samples?

According to the definition of the Kolmogorov–Smirnov test, it is a nonparametric test for the equality of continuous, one-dimensional probability distributions that can be used to compare a sample with a reference probability distribution (one-sample K–S test), or to compare two samples.

Does anyone know if the code in R is able to compare samples and is not just limited to comparison to a theoretical distribution? And if so, could you please give an example?

Upvotes: 1

Views: 3335

Answers (1)

Joris Meys
Joris Meys

Reputation: 108583

Examples are to be found in the help files of ks.test. (?ks.test) :

Usage

ks.test(x, y, ...,
        alternative = c("two.sided", "less", "greater"),
        exact = NULL)

Arguments

x   a numeric vector of data values.
y   either a numeric vector of data values, or a character string naming a ...

Tells you how to do it, and :

Examples

require(graphics)

x <- rnorm(50)
y <- runif(30)
# Do x and y come from the same distribution?
ks.test(x, y)

is the first example in the help files. Please read them before asking. They're there for a reason, and that reason is not "entertainment of the R-development team".

Upvotes: 7

Related Questions