View source: R/factorial_design.R
factorial_design | R Documentation |
Provides helper functions to build factorial design for easily
computing ANOVA using the Anova()
function. This might be
very useful for repeated measures ANOVA, which is hard to set up with the
car
package.
factorial_design(data, dv, wid, between, within, covariate)
data |
a data frame containing the variables |
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) |
a list with the following components:
the
specified arguments: dv, wid, between, within
data: the original data (long format) or independent ANOVA. The wide format is returned for repeated measures ANOVA.
idata: an optional data frame giving the levels of factors defining the intra-subject model for multivariate repeated-measures data.
idesign: a one-sided model formula using the “data” in idata and specifying the intra-subject design.
repeated: logical. Value is TRUE when the data is a repeated design.
lm_formula: the formula used to build the
lm
model.
lm_data: the data used to build the lm
model. Can be either in a long format (i.e., the original data for
independent measures ANOVA) or in a wide format (case of repeated measures ANOVA).
model: the lm
model
Alboukadel Kassambara, alboukadel.kassambara@gmail.com
anova_test()
, anova_summary()
# Load data #::::::::::::::::::::::::::::::::::::::: data("ToothGrowth") df <- ToothGrowth head(df) # Repeated measures designs #::::::::::::::::::::::::::::::::::::::::: # Prepare the data df$id <- rep(1:10, 6) # Add individuals id head(df) # Build factorial designs design <- factorial_design(df, dv = len, wid = id, within = c(supp, dose)) design # Easily perform repeated measures ANOVA using the car package res.anova <- Anova(design$model, idata = design$idata, idesign = design$idesign, type = 3) summary(res.anova, multivariate = FALSE) # Independent measures designs #::::::::::::::::::::::::::::::::::::::::: # Build factorial designs df$id <- 1:nrow(df) design <- factorial_design(df, dv = len, wid = id, between = c(supp, dose)) design # Perform ANOVA Anova(design$model, type = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.