Within Groups Factorial ANOVA

Description

Performs a within-groups factorial ANOVA using the jmv package, with two repeated-measures factors. Supports any k x j design (not limited to 2x2). Returns within-subjects effects for both main effects and the interaction (each with separate error terms), descriptive statistics for all cells, and estimated marginal means. All numeric values stored unrounded.

Usage

anova_factwg_answers(
  data,
  dv_vars,
  iv1_name = "Factor1",
  iv2_name = "Factor2",
  iv1_labels = NULL,
  iv2_labels = NULL
)

Arguments

data A data frame in wide format (one row per subject).
dv_vars Character vector. Names of the DV columns, ordered as described above. Must have length = length(iv1_labels) * length(iv2_labels).
iv1_name Character string. Label for the first WG factor (default: "Factor1").
iv2_name Character string. Label for the second WG factor (default: "Factor2").
iv1_labels Character vector or NULL. Display labels for the levels of IV1. Defaults to c("Level1", "Level2").
iv2_labels Character vector or NULL. Display labels for the levels of IV2. Defaults to c("Level1", "Level2").

Details

Data must be in wide format with one column per cell of the k x j design (k * j columns total). The columns should be ordered to match the crossing of IV1 levels x IV2 levels, with IV2 varying fastest:

For a 2x3 design (IV1 has 2 levels, IV2 has 3 levels): Column 1 = IV1_Level1 + IV2_Level1 Column 2 = IV1_Level1 + IV2_Level2 Column 3 = IV1_Level1 + IV2_Level3 Column 4 = IV1_Level2 + IV2_Level1 Column 5 = IV1_Level2 + IV2_Level2 Column 6 = IV1_Level2 + IV2_Level3

Value

A list with elements (all numeric values unrounded):

ANOVA
List with MainEffect_IV1, MainEffect_IV2, Interaction, each containing F, p_value, df, ss, ms. Also Error_IV1, Error_IV2, Error_Interaction each with ss, df, ms. Plus n_obs.
Descriptives
Tibble with cell-level descriptive statistics including iv1_level, iv2_level, dv_var, mean, sd, n, sem, iv1_label, iv2_label.
EMMs
List with IV1 and IV2 tibbles of estimated marginal means.
FactorInfo
List with iv1_name, iv2_name, iv1_labels, iv2_labels, dv_vars, n_obs.

Examples

library("psych350lab")

library(psych350data)
# Within-groups factorial ANOVA: height_gap x age_grp (both repeated measures)
# This requires data in wide format with 6 columns (3 x 2 design)
wg_results <- anova_factwg_answers(
  data = superman_smes,
  dv_vars = c("emotional_impact_min_min", "emotional_impact_min_avg",
              "emotional_impact_avg_min", "emotional_impact_avg_avg",
              "emotional_impact_big_min", "emotional_impact_big_avg"),
  iv1_name = "Height Gap",
  iv2_name = "Age Group",
  iv1_labels = c("Minimal", "Average", "Big"),
  iv2_labels = c("Minimal", "Average")
)