% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ks_test.R
\name{ks_test}
\alias{ks_test}
\title{Two-Sample Kolmogorov-Smirnov Test}
\usage{
ks_test(
  data,
  formula,
  comparisons = NULL,
  ref.group = NULL,
  p.adjust.method = "holm",
  alternative = "two.sided",
  exact = NULL,
  detailed = FALSE
)
}
\arguments{
\item{data}{a data.frame containing the variables in the formula.}

\item{formula}{a formula of the form \code{x ~ group} where \code{x} is a
numeric variable giving the data values and \code{group} is a factor with two
or more levels giving the corresponding groups.}

\item{comparisons}{A list of length-2 vectors specifying the groups of interest
to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the
argument is as follow: \code{comparisons = list(c("A", "B"), c("B", "C"))}.}

\item{ref.group}{a character string specifying the reference group. If
specified, for a given grouping variable, each of the group levels will be
compared to the reference group (i.e. control group). If \code{ref.group =
"all"}, pairwise two sample tests are performed for comparing each grouping
variable level against all (i.e. basemean).}

\item{p.adjust.method}{method to adjust p values for multiple comparisons. Used
when pairwise comparisons are performed. Allowed values include "holm",
"hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't
want to adjust the p value (not recommended), use p.adjust.method = "none".}

\item{alternative}{indicates the alternative hypothesis and must be
    one of \code{"two.sided"} (default), \code{"less"}, or
    \code{"greater"}.  You can specify just the initial letter of the
    value, but the argument name must be given in full.
    See \sQuote{Details} for the meanings of the possible values.}

\item{exact}{\code{NULL} or a logical indicating whether an exact
    p-value should be computed.  See \sQuote{Details} for the meaning of
    \code{NULL}.}

\item{detailed}{logical value. Default is FALSE. If TRUE, a detailed result is
shown.}
}
\value{
return a data frame with some of the following columns: \itemize{ \item
 \code{.y.}: the y variable used in the test. \item \code{group1,group2}: the
 compared groups in the pairwise tests. \item \code{n1,n2}: sample counts.
 \item \code{statistic}: the value of the test statistic \code{D} (the maximum
 difference between the two empirical cumulative distribution functions). \item
 \code{p}: p-value. \item \code{p.adj}: the adjusted p-value. \item
 \code{method}: the statistical test used to compare groups. \item
 \code{p.signif, p.adj.signif}: the significance level of p-values and adjusted
 p-values, respectively. \item \code{alternative}: the alternative hypothesis.}

 The \strong{returned object has an attribute called args}, which is a list
 holding the test arguments.
}
\description{
Provides a pipe-friendly framework to perform the two-sample
 Kolmogorov-Smirnov test, comparing the (empirical) distributions of a numeric
 variable between two groups. Wrapper around the R base function
 \code{\link[stats]{ks.test}()}.

 When the grouping factor contains more than two levels, pairwise
 Kolmogorov-Smirnov tests are automatically performed, with p-value
 adjustment.
}
\examples{
# Two-samples test
#:::::::::::::::::::::::::::::::::::::::::
ToothGrowth \%>\% ks_test(len ~ supp)

# Pairwise comparisons (more than two groups)
#:::::::::::::::::::::::::::::::::::::::::
ToothGrowth \%>\% ks_test(len ~ dose)

# Comparison against a reference group
#:::::::::::::::::::::::::::::::::::::::::
ToothGrowth \%>\% ks_test(len ~ dose, ref.group = "0.5")
}
\seealso{
\code{\link{wilcox_test}()}, \code{\link{t_test}()}
}
