The “ks.test” Function in R
Package: Base R (no specific package required)
Purpose: Performs the Kolmogorov-Smirnov test for comparing the distribution of a sample to a specified distribution.
General Class: Statistical Testing
Required Argument(s):
x: A numeric vector of data values.
Notable Optional Arguments:
y: A character string indicating the distribution to which the sample is compared. Options include "pnorm", "pexp", and others.
alternative: A character string specifying the alternative hypothesis. Options include "two.sided", "less", or "greater".
ks.control: A list of control parameters for the Kolmogorov-Smirnov test.
exact: A logical value indicating whether to compute an exact p-value for small sample sizes. The default is FALSE.
Example:
# Example data for a Kolmogorov-Smirnov test
set.seed(123)
sample_data <- rnorm(100)
# Perform a Kolmogorov-Smirnov test
result <- ks.test(sample_data, "pnorm", mean = 0, sd = 1)
# Display the result
print(result)In this example, the ks.test function is used to perform a Kolmogorov-Smirnov test comparing the distribution of a sample (sample_data) to a standard normal distribution. The result of the test, including the test statistic and p-value, is then printed to the console.