How to Perform a Repeated Measures ANOVA By Hand


repeated measures ANOVA is used to determine whether or not there is a statistically significant difference between the means of three or more groups in which the same subjects show up in each group.

This tutorial explains how to perform a one-way repeated measures ANOVA by hand.

Example: One-Way Repeated Measures ANOVA by Hand

Researchers want to know if three different drugs lead to different reaction times. To test this, they measure the reaction time (in seconds) of five patients on each drug. The results are shown below:

Since each patient is measured on each of the three drugs, we will use a one-way repeated measures ANOVA to determine if the mean reaction time differs between drugs.

Use the following steps to perform the repeated measures ANOVA by hand:

Step 1: Calculate SST.

First, we will calculate the total sum of squares (SST), which can be found using the following formula:

SST = s2total(ntotal-1)

where:

  • s2total: the variance for the entire dataset
  • ntotal: the total number of observations in the entire dataset

In this example we calculate SST to be: (64.2667)(15-1) = 899.7

Step 2: Calculate SSB

Next, we will calculate the between sum of squares (SSB), which can be found using the following formula:

SSB = Σnj(xxtotal)2

where:

  • Σ: a greek symbol that means “sum”
  • nj: the total number of observations in the jth group
  • xj: the mean of the jth group
  • xtotal: the mean of the entire dataset

In this example we calculate SSB to be: (5)(26.4-22.533)2 +(5)(25.6-22.533)2 + (5)(15.6-22.533)2362.1

Step 3: Calculate SSS.

Next, we will calculate the subject sum of squares (SSS), which can be found using the following formula:

SSS =(Σr2k/c) – (N2/rc)

where:

  • Σ: a greek symbol that means “sum”
  • r2k: squared sum of the kth patient
  • N: the grand total of the entire dataset
  • r: total number of patients
  • c: total number of groups

In this example we calculate SSS to be: ((74+ 422 + 62+ 922 + 682)/3) – (3382/(5)(3)) = 441.1

Step 4: Calculate SSE.

Next, we will calculate the error sum of squares (SSE), which can be found using the following formula:

SSE = SST – SSB – SSS

In this example we calculate SSE to be: 899.7 – 362.1 – 441.1 = 96.5

Step 5: Fill in the Repeated measures ANOVA table.

Now that we have SSB, SSS, and SSE, we can fill in the repeated measures ANOVA table:

Source Sum of Squares (SS) df Mean Squares (MS) F
Between 362.1 2 181.1 15.006
Subject 441.1 4 110.3
Error 96.5 8 12.1

Here is how we calculated the various numbers in the table:

  • df between: #groups – 1 = 3 – 1 = 2
  • df subject: #participants – 1 = 5 – 1 = 4
  • df error: df between * df subject = 2*4 = 8 
  • MS between: SSB / df between = 362.1 / 2 = 181.1
  • MS subject: SSS / df subject = 441.1 / 4 = 110.3
  • MS error: SSE / df error = 96.5 / 8 = 12.1
  • F: MS between / MS error = 181.1 / 12.1 = 15.006

Step 6: Interpret the results.

The F test statistic for this one-way repeated measures ANOVA is 15.006. To determine if this is a statistically significant result, we must compare this to the F critical value found in the F distribution table with the following values:

  • α (significance level) = 0.05
  • DF1 (numerator degrees of freedom) = df between = 2
  • DF2 (denominator degrees of freedom) = df error = 8

We find that the F critical value is 4.459.

Since the F test statistic in the ANOVA table is greater than the F critical value in the F distribution table, we reject the null hypothesis. This means we have sufficient evidence to say that there is a statistically significant difference between the mean response times of the drugs.

10 Replies to “How to Perform a Repeated Measures ANOVA By Hand”

  1. Hello
    There seems to be an error in the formula step 3
    SSS =(Σ rk^2/c) – (N^2/rc) : N should be Grand Total (as in the calculation), not number of obs. as explained underneath the formula
    and in the following calculation:
    ((742 + 422 + 622 + 922 + 682)/3) – (3382/(6)(3)) = 441.1:
    should be:
    ((742 + 422 + 622 + 922 + 682)/3) – (3382/(5)(3)) = 441.1

    1. Two-way ANOVA with repetitions (also known as **repeated measures ANOVA**) is a statistical method used to analyze the effect of two categorical independent variables on a continuous dependent variable, while accounting for **within-subject variability**. This is particularly useful when measurements are repeated for the same subjects under different conditions.

      ### When to Use Two-Way ANOVA with Repetitions
      – **Two Independent Variables:** You have two categorical independent variables (factors). For example:
      – Factor A: Treatment type (e.g., Drug A, Drug B)
      – Factor B: Time (e.g., Day 1, Day 2, Day 3)
      – **Repetition:** You measure the dependent variable (response) multiple times for the same subjects across all combinations of the two factors.

      ### Objectives
      1. **Main Effects:**
      – Determine if each independent variable has a significant effect on the dependent variable.
      2. **Interaction Effect:**
      – Examine if there’s a combined effect of the two factors on the dependent variable.
      3. **Subject Variability:**
      – Account for variability due to repeated measurements within subjects.

      ### Assumptions
      1. **Normality:** The dependent variable is approximately normally distributed for each group.
      2. **Sphericity:** Variances of the differences between conditions (repeated measures) are equal.
      – This is tested using **Mauchly’s Test of Sphericity.**
      – If violated, use corrections like **Greenhouse-Geisser** or **Huynh-Feldt.**
      3. **Homogeneity of Variances:** The variance of the dependent variable is equal across groups.
      4. **Independence:** Observations within each group are independent of one another.

      ### Steps to Perform Two-Way ANOVA with Repetitions
      #### 1. **Define Hypotheses**
      – **Main Effect A:** \( H_0: \mu_A = \mu_B \) (No effect of Factor A)
      – **Main Effect B:** \( H_0: \mu_B = \mu_C \) (No effect of Factor B)
      – **Interaction Effect:** \( H_0: \text{No interaction between Factors A and B} \)

      #### 2. **Calculate the ANOVA Table**
      – The table includes:
      – **Sum of Squares (SS):** Total variance decomposed into components (main effects, interaction, error).
      – **Degrees of Freedom (df):** Associated with each effect.
      – **Mean Squares (MS):** Variance estimates (SS/df).
      – **F-statistics and p-values:** Used to test hypotheses.

      #### 3. **Post-Hoc Analysis**
      – If the main effects or interaction are significant, perform post-hoc tests (e.g., Tukey’s HSD) to pinpoint the specific groups with differences.

      #### 4. **Report Results**
      – Include:
      – Main effects (F, df, p-value).
      – Interaction effect (F, df, p-value).
      – Post-hoc results (if applicable).

      ### Example in Python
      Here’s a basic Python implementation using **statsmodels**:

      “`python
      import pandas as pd
      import numpy as np
      import statsmodels.api as sm
      from statsmodels.stats.anova import AnovaRM

      # Example data: subjects measured under 2 treatments (A, B) and 3 time points
      data = {
      ‘Subject’: np.repeat(np.arange(1, 11), 6),
      ‘Treatment’: np.tile(np.repeat([‘A’, ‘B’], 3), 10),
      ‘Time’: np.tile([‘T1’, ‘T2’, ‘T3’], 20),
      ‘Response’: np.random.randn(60) # Replace with actual data
      }
      df = pd.DataFrame(data)

      # Perform Repeated Measures ANOVA
      anova = AnovaRM(df, ‘Response’, ‘Subject’, within=[‘Treatment’, ‘Time’])
      result = anova.fit()

      print(result)
      “`

      ### Example in R
      For those who use R, the `aov()` function or `ezANOVA()` from the `ez` package is helpful:

      “`R
      library(ez)

      # Example data frame
      data <- data.frame( Subject = rep(1:10, each = 6), Treatment = rep(c("A", "B"), each = 3, times = 10), Time = rep(c("T1", "T2", "T3"), times = 20), Response = rnorm(60) # Replace with actual data ) # Run two-way ANOVA with repetitions anova_result <- ezANOVA( data = data, dv = .(Response), wid = .(Subject), within = .(Treatment, Time) ) print(anova_result) ``` --- ### Key Takeaways - **Interpret Results Carefully:** Focus on the significance of main effects and interaction. - **Check Assumptions:** Always validate assumptions before drawing conclusions. - **Visualization:** Use interaction plots to visualize the effects and interactions. If you have specific data or need help interpreting results, feel free to share more details!

  2. Is your SST a different formula then what others use? I’m seeing:

    SST = Sum(x – xbar_total)^2 on other websites.

    1. Hi Sarah…Great question — and yes, **SST** (Total Sum of Squares) can be presented using slightly different **formulations**, but they all fundamentally calculate the same thing: **the total variability in the data**.

      Let’s break this down clearly:

      ### ✅ What is SST?

      **SST** measures the total variation in all observations around the **grand mean** (𝑥̄_total).
      So regardless of how it’s written, it’s capturing:
      > *“How far is each data point from the overall mean?”*

      ### ✅ Common Formula You Saw:

      \[
      SST = \sum (x_{ij} – \bar{x}_{..})^2
      \]

      Where:
      – \(x_{ij}\) is each individual observation
      – \(\bar{x}_{..}\) is the grand mean (mean of all values across all groups and subjects)

      This is the standard textbook way of defining SST — and **yes**, this is the correct and most common formula.

      ### ❓Are There Other Equivalent Forms?

      Yes! Some authors or sources might **reorganize the SST** using other formulas — for instance, using:
      – Raw scores squared minus correction factor
      – Matrix notation (especially in stats software)
      – Partitions that add up to SST: SSB (between groups) + SSW (within groups), or more specific:
      – SSA (effect of treatment/time)
      – SSS (effect of subject)
      – SSE (error)

      So you might see SST = SSA + SSS + SSE
      — which is still correct, just broken into components.

      ### 🔍 Why the Confusion?

      Sometimes people mislabel one of the **component sums of squares** as the total SST. For example:
      – They might call **SSA** (treatment sum of squares) the “SST”
      – Or calculate the **within-subject variation only**

      So it’s always good to **check the context** in which the formula is being used.

      ### ✅ Final Word

      If you’re doing **repeated measures ANOVA by hand**, stick with:
      \[
      SST = \sum (x_{ij} – \bar{x}_{..})^2
      \]

      That’s the **true total sum of squares** — from which you can then partition the variability as needed.

Leave a Reply

Your email address will not be published. Required fields are marked *