View source: R/compare_means.R
compare_means | R Documentation |
Performs one or multiple mean comparisons.
compare_means( formula, data, method = "wilcox.test", paired = FALSE, group.by = NULL, ref.group = NULL, symnum.args = list(), p.adjust.method = "holm", ... )
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.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.