factorial_design {rstatix}R Documentation

Build Factorial Designs for ANOVA

Description

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.

Usage

factorial_design(data, dv, wid, between, within, covariate)

Arguments

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)

Value

a list with the following components:

Author(s)

Alboukadel Kassambara, alboukadel.kassambara@gmail.com

See Also

anova_test(), anova_summary()

Examples

# 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)


[Package rstatix version 0.7.2 Index]