You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中对整洁格式的数据执行MANOVA分析

Hey there! Let's walk through how to run your 2×3 mixed-design MANOVA step by step—since each participant answered 3 questions, you've got a repeated measures component here that we need to account for properly.

Step 1: Reshape Your Data to Wide Format

MANOVA requires each repeated measure (your 3 questions) to be a separate column. If you're using the tidyverse, pivot_wider is the perfect tool to convert your long-format data to the required wide format:

library(tidyverse)

# Convert long data to wide format
wide_data <- your_raw_data %>%
  pivot_wider(
    id_cols = c(id, init_cont, family),
    names_from = qnumber,
    values_from = value,
    names_prefix = "q"  # Renames columns to q1, q2, q3 for clarity
  )

This will give you a data frame where each row represents one participant, with columns id, init_cont, family, q1, q2, q3.

Step 2: Fit the MANOVA Model

Next, we'll build the model to test the effects of your between-subjects factors (init_cont and family) on the set of dependent variables (the 3 question scores).

Base R manova() Approach

# Define the model formula: DVs ~ between-subjects factors + Error term for repeated measures
manova_model <- manova(cbind(q1, q2, q3) ~ init_cont * family + Error(id), data = wide_data)

# View results with Pillai's trace (robust to assumption violations)
summary(manova_model, test = "Pillai")

The Error(id) term accounts for the repeated measures structure (each participant is measured 3 times). Pillai's trace is recommended here because it’s more reliable when your data slightly violates MANOVA assumptions.

Using car Package for Enhanced Output

For more detailed, publication-ready results and Type III sums of squares (standard for factorial designs), use the car package's Anova() function:

library(car)

# Fit model with Type III sums of squares
manova_car <- Anova(manova_model, type = "III")

# Print formatted results
print(manova_car)
Step 3: Interpret & Follow Up on Results
  • First, check for significant effects: look at the p-values for init_cont (main effect), family (main effect), and init_cont:family (interaction effect).
  • If any effect is significant, follow up with:
    • Univariate ANOVAs to identify which specific question scores are driving the effect:
      # Example ANOVA for q1
      anova_q1 <- aov(q1 ~ init_cont * family + Error(id), data = wide_data)
      summary(anova_q1)
      
    • Post-hoc tests (like Tukey's HSD) to explore pairwise differences in significant main effects or interactions:
      # Tukey's HSD for family main effect (if significant)
      tukey_family <- TukeyHSD(aov(q1 ~ family + Error(id), data = wide_data))
      print(tukey_family)
      
Key Assumptions to Validate

Before trusting your results, confirm these MANOVA assumptions:

  • Multivariate normality: Test with Shapiro-Wilk on each dependent variable, or visual checks like Q-Q plots.
  • Homogeneity of covariance matrices: Use Box's M test (note: it's sensitive to sample size, so use caution with large datasets).
  • Sphericity: For repeated measures, use Mauchly's test—if violated, adjust degrees of freedom with Greenhouse-Geisser or Huynh-Feldt corrections.

内容的提问来源于stack exchange,提问作者melbez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:57:00