Learn R Programming

mariposa (version 0.7.3)

factorial_anova: Compare Groups Across Multiple Factors: Factorial ANOVA

Description

factorial_anova() tests whether group means differ across two or more factors simultaneously, including their interactions. It performs a factorial (two-way, three-way) ANOVA using Type III Sum of Squares, matching SPSS UNIANOVA output.

Think of it as:

  • Testing multiple grouping variables at once

  • Detecting interaction effects (do factor combinations matter?)

  • An extension of one-way ANOVA to multiple factors

The test tells you:

  • Whether each factor has a main effect on the outcome

  • Whether factors interact (the effect of one depends on the other)

  • How much variance each factor explains (partial eta squared)

Usage

factorial_anova(data, dv, between, weights = NULL, ss_type = 3)

Value

An object of class "factorial_anova" containing:

anova_table

Tibble with Source, SS, df, MS, F, p, Partial Eta Squared

descriptives

Tibble with cell means, SDs, and Ns for each factor combination

levene_test

Tibble with Levene's test results (F, df1, df2, p)

r_squared

R-squared and Adjusted R-squared

model

The underlying model object for S3 dispatch

call_info

List with metadata (dv, factors, weighted, n_total, n_missing)

Use summary() for the full SPSS-style output with toggleable sections.

Arguments

data

Your survey data (a data frame or tibble)

dv

The numeric dependent variable to analyze (unquoted)

between

Character vector or unquoted variable names specifying the between-subjects factors (2-3 factors). These must be categorical variables (factor, character, or labelled numeric).

weights

Optional survey weights for population-representative results (unquoted variable name)

ss_type

Deprecated; only 3 (Type III, the SPSS default) is implemented. Passing 2 issues a warning and computes Type III.

Details

Understanding the Results

Main Effects: Does each factor independently affect the outcome?

  • Significant main effect = group means differ for that factor

  • Example: Education affects income regardless of gender

Interaction Effects: Does the effect of one factor depend on another?

  • Significant interaction = the pattern differs across factor combinations

  • Example: The gender gap in income varies by education level

Partial Eta Squared (Effect Size):

  • Less than 0.01: Negligible

  • 0.01 to 0.06: Small

  • 0.06 to 0.14: Medium

  • 0.14 or greater: Large

Type III Sum of Squares

Type III SS tests each effect after adjusting for all other effects. This is the standard in SPSS and recommended for unbalanced designs (unequal cell sizes). It uses orthogonal contrasts (contr.sum) internally.

When to Use This

Use factorial ANOVA when:

  • You have one numeric outcome variable

  • You have 2-3 categorical grouping factors

  • You want to test main effects AND interactions

  • Your data is approximately normally distributed within cells

What Comes Next?

If the ANOVA is significant:

  1. Check which effects are significant (main effects vs. interactions)

  2. Use tukey_test() for post-hoc comparisons on main effects

  3. Examine cell means to interpret interaction patterns

  4. Consider effect sizes for practical significance

References

Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences (2nd ed.). Lawrence Erlbaum Associates.

IBM Corp. (2023). IBM SPSS Statistics 29 Algorithms. IBM Corporation.

Maxwell, S. E., & Delaney, H. D. (2004). Designing Experiments and Analyzing Data (2nd ed.). Lawrence Erlbaum Associates.

See Also

oneway_anova for single-factor ANOVA.

tukey_test for post-hoc pairwise comparisons.

levene_test for testing homogeneity of variances.

ancova for ANOVA with covariates.

summary.factorial_anova for detailed output with toggleable sections.

Other hypothesis_tests: ancova(), binomial_test(), chi_square(), chisq_gof(), fisher_test(), friedman_test(), kruskal_wallis(), mann_whitney(), mcnemar_test(), oneway_anova(), t_test(), wilcoxon_test()

Examples

Run this code
# Load required packages and data
library(dplyr)
data(survey_data)

# Two-way ANOVA: income by gender and education
survey_data %>%
  factorial_anova(dv = income, between = c(gender, education))

# Two-way ANOVA with weights
survey_data %>%
  factorial_anova(dv = life_satisfaction, between = c(gender, region),
                  weights = sampling_weight)

# Three-way ANOVA
survey_data %>%
  factorial_anova(dv = income, between = c(gender, region, education))

# Follow up with post-hoc tests
result <- survey_data %>%
  factorial_anova(dv = income, between = c(gender, education))
result %>% tukey_test()
result %>% levene_test()

# --- Three-layer output ---
result              # compact overview
summary(result)     # full detailed output with all sections
summary(result, marginal_means = FALSE)  # hide estimated marginal means

Run the code above in your browser using DataLab