p_ks.test: p-value from Kolmogorov-Smirnov one- or two-sample simulation

View source: R/p_ks.test.R

p_ks.testR Documentation

p-value from Kolmogorov-Smirnov one- or two-sample simulation

Description

Generates one or two sets of continuous data group-level data and returns a p-value under the null that the groups were drawn from the same distribution (two sample) or from a theoretically known distribution (one sample).

Usage

p_ks.test(
  n,
  p1,
  p2,
  n2_n1 = 1,
  two.tailed = TRUE,
  parent = NULL,
  return_analysis = FALSE,
  ...
)

Arguments

n

sample size per group, assumed equal across groups

p1

a function indicating how the data were generated for group 1

p2

(optional) a function indicating how the data were generated for group 2. If omitted a one-sample test will be evaluated provided that parent is also specified

n2_n1

sample size ratio. Default uses equal sample sizes

two.tailed

logical; should a two-tailed or one-tailed test be used?

parent

the cumulative distribution function to use (e.g., pnorm). Specifying this input will construct a one-sample test setup

return_analysis

logical; return the analysis object for further extraction and customization?

...

additional arguments to be passed to the parent distribution function from ks.test, as well as any other relevant parameter to ks.test (e.g., exact = TRUE)

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

See Also

gen_t.test

Examples


# two-sample test from two Gaussian distributions with different locations
p1 <- function(n) rnorm(n)
p2 <- function(n) rnorm(n, mean=-.5)
p_ks.test(n=100, p1, p2)

# return analysis model
p_ks.test(n=100, p1, p2, return_analysis=TRUE)

# one-sample data from chi-squared distribution tested
#   against a standard normal distribution
pc <- function(n, df=15) (rchisq(n, df=df) - df) / sqrt(2*df)
p_ks.test(n=100, p1=pc, parent=pnorm, mean=0, sd=1)


  # empirical power estimates
  p_ks.test(n=100, p1, p2) |> Spower()
  p_ks.test(n=100, p1=pc, parent=pnorm, mean=0, sd=1) |> Spower()




Spower documentation built on Nov. 28, 2025, 1:06 a.m.