Description Usage Arguments Value Examples
View source: R/compare_means.R
Performs one or multiple mean comparisons.
1 2 3 4 5 6 7 8 9 10 11 |
formula |
a formula of the form It's also possible to perform the test for multiple response variables at
the same time. For example, |
data |
a data.frame containing the variables in the formula. |
method |
the type of test. Default is wilcox.test. Allowed values include:
|
paired |
a logical indicating whether you want a paired test. Used only
in |
group.by |
a character vector containing the name of grouping variables. |
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).
|
symnum.args |
a list of arguments to pass to the function
In other words, we use the following convention for symbols indicating statistical significance:
|
p.adjust.method |
method for adjusting p values (see
Note that, when the |
... |
Other arguments to be passed to the test function. |
return a data frame with the following columns:
.y.
: the y variable used in the test.
group1,group2
: the compared groups in the pairwise tests.
Available only when method = "t.test"
or method = "wilcox.test"
.
p
: the p-value.
p.adj
: the adjusted p-value. Default for p.adjust.method = "holm"
.
p.format
: the formatted p-value.
p.signif
: the significance level.
method
: the statistical test used to compare groups.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # Load data
#:::::::::::::::::::::::::::::::::::::::
data("ToothGrowth")
df <- ToothGrowth
# One-sample test
#:::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ 1, df, mu = 0)
# Two-samples unpaired test
#:::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ supp, df)
# Two-samples paired test
#:::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ supp, df, paired = TRUE)
# Compare supp levels after grouping the data by "dose"
#::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ supp, df, group.by = "dose")
# pairwise comparisons
#::::::::::::::::::::::::::::::::::::::::
# As dose contains more thant two levels ==>
# pairwise test is automatically performed.
compare_means(len ~ dose, df)
# Comparison against reference group
#::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ dose, df, ref.group = "0.5")
# Comparison against all
#::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ dose, df, ref.group = ".all.")
# Anova and kruskal.test
#::::::::::::::::::::::::::::::::::::::::
compare_means(len ~ dose, df, method = "anova")
compare_means(len ~ dose, df, method = "kruskal.test")
|
Loading required package: ggplot2
Loading required package: magrittr
# A tibble: 1 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <dbl> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len 1 null model 1.664007e-11 1.664007e-11 1.7e-11 **** Wilcoxon
# A tibble: 1 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len OJ VC 0.06449067 0.06449067 0.064 ns Wilcoxon
# A tibble: 1 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len OJ VC 0.004312554 0.004312554 0.0043 ** Wilcoxon
# A tibble: 3 x 9
dose .y. group1 group2 p p.adj p.format p.signif method
<dbl> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 0.5 len OJ VC 0.023186427 0.04637285 0.023 * Wilcoxon
2 1.0 len OJ VC 0.004030367 0.01209110 0.004 ** Wilcoxon
3 2.0 len OJ VC 1.000000000 1.00000000 1.000 ns Wilcoxon
# A tibble: 3 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len 0.5 1 7.020855e-06 1.404171e-05 7.0e-06 **** Wilcoxon
2 len 0.5 2 8.406447e-08 2.521934e-07 8.4e-08 **** Wilcoxon
3 len 1 2 1.772382e-04 1.772382e-04 0.00018 *** Wilcoxon
# A tibble: 2 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len 0.5 1 7.020855e-06 7.020855e-06 7.0e-06 **** Wilcoxon
2 len 0.5 2 8.406447e-08 1.681289e-07 8.4e-08 **** Wilcoxon
# A tibble: 3 x 8
.y. group1 group2 p p.adj p.format p.signif method
<chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
1 len .all. 0.5 5.078788e-05 0.0001523636 5.1e-05 **** Wilcoxon
2 len .all. 1 7.640429e-01 0.7640429386 0.76404 ns Wilcoxon
3 len .all. 2 1.791243e-04 0.0003582486 0.00018 *** Wilcoxon
# A tibble: 1 x 6
.y. p p.adj p.format p.signif method
<chr> <dbl> <dbl> <chr> <chr> <chr>
1 len 9.532727e-16 9.532727e-16 9.5e-16 **** Anova
# A tibble: 1 x 6
.y. p p.adj p.format p.signif method
<chr> <dbl> <dbl> <chr> <chr> <chr>
1 len 1.475207e-09 1.475207e-09 1.5e-09 **** Kruskal-Wallis
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.