| ks_test | R Documentation |
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
ks.test().
When the grouping factor contains more than two levels, pairwise Kolmogorov-Smirnov tests are automatically performed, with p-value adjustment.
See the Datanovia tutorial Normality Test in R for a worked walkthrough.
ks_test(
data,
formula,
comparisons = NULL,
ref.group = NULL,
p.adjust.method = "holm",
alternative = "two.sided",
exact = NULL,
detailed = FALSE
)
data |
a data.frame containing the variables in the formula. |
formula |
a formula of the form |
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: |
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 |
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". |
alternative |
indicates the alternative hypothesis and must be
one of |
exact |
|
detailed |
logical value. Default is FALSE. If TRUE, a detailed result is shown. |
return a data frame with some of the following columns:
.y.: the y variable used in the test.
group1,group2: the
compared groups in the pairwise tests.
n1,n2: sample counts.
statistic: the value of the test statistic D (the maximum
difference between the two empirical cumulative distribution functions).
p: p-value.
p.adj: the adjusted p-value.
method: the statistical test used to compare groups.
p.signif, p.adj.signif: the significance level of p-values and adjusted
p-values, respectively.
alternative: the alternative hypothesis.
The returned object has an attribute called args, which is a list holding the test arguments.
wilcox_test(), t_test()
The Datanovia tutorial: Normality Test in R.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.