anova_test | R Documentation |
Provides a pipe-friendly framework to perform different types of ANOVA tests, including:
Independent measures ANOVA: between-Subjects designs,
Repeated measures ANOVA: within-Subjects designs
Mixed ANOVA: Mixed within within- and between-Subjects designs, also known as split-plot ANOVA and
The function is an easy to use wrapper around Anova()
and
aov()
. It makes ANOVA computation handy in R and It's
highly flexible: can support model and formula as input. Variables can be
also specified as character vector using the arguments dv, wid,
between, within, covariate
.
The results include ANOVA table, generalized effect size and some assumption checks.
anova_test( data, formula, dv, wid, between, within, covariate, type = NULL, effect.size = "ges", error = NULL, white.adjust = FALSE, observed = NULL, detailed = FALSE ) get_anova_table(x, correction = c("auto", "GG", "HF", "none")) ## S3 method for class 'anova_test' print(x, ...) ## S3 method for class 'anova_test' plot(x, ...)
data |
a data.frame or a model to be analyzed. |
formula |
a formula specifying the ANOVA model similar to
aov. Can be of the form Examples of supported formula include:
If the formula doesn't contain any within vars, a linear model is directly fitted and passed to the ANOVA function. For repeated designs, the ANOVA variables are parsed from the formula. |
dv |
(numeric) dependent variable name. |
wid |
(factor) column name containing individuals/subjects identifier. Should be unique per individual. |
between |
(optional) between-subject factor variables. |
within |
(optional) within-subjects factor variables |
covariate |
(optional) covariate names (for ANCOVA) |
type |
the type of sums of squares for ANOVA. Allowed values are either
1, 2 or 3. |
effect.size |
the effect size to compute and to show in the ANOVA results. Allowed values can be either "ges" (generalized eta squared) or "pes" (partial eta squared) or both. Default is "ges". |
error |
(optional) for a linear model, an lm model object from which the
overall error sum of squares and degrees of freedom are to be calculated.
Read more in |
white.adjust |
Default is FALSE. If TRUE, heteroscedasticity correction is applied to the coefficient of covariance matrix. Used only for independent measures ANOVA. |
observed |
Variables that are observed (i.e, measured) as compared to experimentally manipulated. The default effect size reported (generalized eta-squared) requires correct specification of the observed variables. |
detailed |
If TRUE, returns extra information (sums of squares columns, intercept row, etc.) in the ANOVA table. |
x |
an object of class |
correction |
character. Used only in repeated measures ANOVA test to specify which correction of the degrees of freedom should be reported for the within-subject factors. Possible values are:
|
... |
additional arguments |
The setting in anova_test()
is done in such a way that it
gives the same results as SPSS, one of the most used commercial software. By
default, R uses treatment contrasts, where each of the levels is compared to
the first level used as baseline. The default contrast can be checked using
options('contrasts')
. In the function anova_test()
, the
following setting is used
options(contrasts=c('contr.sum','contr.poly'))
, which gives
orthogonal contrasts where you compare every level to the overall mean. This
setting gives the same output as the most commonly used commercial
softwares, like SPSS. If you want to obtain the same result with the
function car::Anova()
as the one obtained with
rstatix::anova_test()
, then don't forget to set
options(contrasts=c('contr.sum','contr.poly'))
.
return an object of class anova_test
a data frame containing
the ANOVA table for independent measures ANOVA.
However, for repeated/mixed measures ANOVA, a list containing the following
components are returned: ANOVA table, Mauchly's Test for Sphericity,
Sphericity Corrections. These table are described more in the documentation
of the function anova_summary()
.
The returned object has an attribute called args
, which is a
list holding the arguments used to fit the ANOVA model, including: data, dv,
within, between, type, model, etc.
anova_test()
: perform anova test
get_anova_table()
: extract anova table from an object of class
anova_test
. When within-subject factors are present, either
sphericity corrected or uncorrected degrees of freedom can be reported.
Alboukadel Kassambara, alboukadel.kassambara@gmail.com
anova_summary()
, factorial_design()
# Load data #::::::::::::::::::::::::::::::::::::::: data("ToothGrowth") df <- ToothGrowth # One-way ANOVA test #::::::::::::::::::::::::::::::::::::::::: df %>% anova_test(len ~ dose) # Grouped One-way ANOVA test #::::::::::::::::::::::::::::::::::::::::: df %>% group_by(supp) %>% anova_test(len ~ dose) # Two-way ANOVA test #::::::::::::::::::::::::::::::::::::::::: df %>% anova_test(len ~ supp*dose) # Two-way repeated measures ANOVA #::::::::::::::::::::::::::::::::::::::::: df$id <- rep(1:10, 6) # Add individuals id # Use formula df %>% anova_test(len ~ supp*dose + Error(id/(supp*dose))) # or use character vector df %>% anova_test(dv = len, wid = id, within = c(supp, dose)) # Extract ANOVA table and apply correction #::::::::::::::::::::::::::::::::::::::::: res.aov <- df %>% anova_test(dv = len, wid = id, within = c(supp, dose)) get_anova_table(res.aov, correction = "GG") # Use model as arguments #::::::::::::::::::::::::::::::::::::::::: .my.model <- lm(yield ~ block + N*P*K, npk) anova_test(.my.model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.