KS2gof {Dogoftest}R Documentation

Two-Sample Kolmogorov–Smirnov Test with Bootstrap

Description

Performs a two-sample Kolmogorov–Smirnov (KS) test using a bootstrap method to assess whether two independent samples come from the same distribution.

Usage

KS2gof(
  x,
  y,
  alternative = c("two.sided", "less", "greater"),
  nboots = 5000,
  keep.boots = FALSE
)

Arguments

x, y

Numeric vectors of data values for the two independent samples.

alternative

Character string specifying the alternative hypothesis, must be one of "two.sided", "less", or "greater".

nboots

Number of bootstrap resamples used to approximate the null distribution (default: 5000).

keep.boots

Logical; if TRUE, return the vector of bootstrap statistics.

Details

This implementation performs a nonparametric KS test for equality of distributions by resampling under the null hypothesis. It supports one-sided and two-sided alternatives.

If keep.boots = TRUE, the function returns all bootstrap statistics, which can be used for further analysis (e.g., plotting).

If the p-value is zero due to no bootstrap statistic exceeding the observed value, it is adjusted to 1 / (2 * nboots) to avoid a zero p-value.

Value

An object of class "htest" with the following components:

statistic

The observed KS statistic.

p.value

The p-value based on the bootstrap distribution.

alternative

The alternative hypothesis.

method

Description of the test used.

Examples

set.seed(123)
x <- rnorm(100, mean = 0, sd = 4)
y <- rnorm(100, mean = 2, sd = 4)
KS2gof(x, y)


[Package Dogoftest version 0.2 Index]