Performing the Kolmogorov-Smirnov test
A one-sample Kolmogorov-Smirnov test is used to compare a sample with a reference probability. A two-sample Kolmogorov-Smirnov test compares the cumulative distributions of two datasets. In this recipe, we will demonstrate how to perform the Kolmogorov-Smirnov test with R.
mtcars has already been loaded into a data frame within an R session. As the
ks.test function is originated from the
stats package, make sure the
stats library is loaded.
How to do it...
Perform the following steps:
- Validate whether the dataset, x (generated with the
rnormfunction), is distributed normally with a one-sample Kolmogorov-Smirnov test:
> x = rnorm(50) > ks.test(x,"pnorm") One-sample Kolmogorov-Smirnov ...