Get startedGet started for free

The systematic between-groups variance

To understand everything a bit better, you will calculate the F-ratio for a repeated measures design by yourself in the next exercises.

First, you will need the systematic between-groups variance. This is the same as in the between-groups design--the variance due to grouping by condition--so it shouldn't be totally new to you, but it can't hurt to refresh your memory.

Recall that the formula for systematic sum of squares is $$\begin{aligned} ss_a = n \sum(y_j - y_t)^2 \end{aligned} $$ where \(y_j\) are the group means, \(y_t\) is the grand mean and \(n\) is the number of items in each group with \(j\) the number of groups.

The formula for systematic variance is then $$ \begin{aligned} ms_a & = \frac{ss_a}{df_a} \end{aligned}$$ where \(df\) stands for the degrees of freedom which are set equal to the number of groups minus one.

You will keep working with the working memory example. The dataset wm is still loaded in your workspace.

This exercise is part of the course

Intro to Statistics with R: Repeated measures ANOVA

View Course

Exercise instructions

  • Define the number of subjects n for each condition.
  • Calculate the group means for IQ gains iq by condition using the tapply() function. The tapply() function is used to group the observations for iq by the variable cond, then apply a function (in this case mean()) to each group. The first argument should be the column of data for which you want to calculate means and the second argument should be the column of data that defines the groups.
  • You also need the grand mean y_t to calculate the sum of squares. Use the mean() function to get this.
  • Now you have all the ingredients to calculate the between-groups sum of squares, ss_cond, by applying the first formula above.
  • Finally, calculate the systematic variance, ms_cond, using the second formula. You'll need to define the degrees of freedom, df, first.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

## Calculate the systematic variance due to conditions

# Define number of subjects for each condition
n <- 

# Calculate group means
y_j <- tapply(___, ___, mean)

# Calculate the grand mean
y_t <- 

# Calculate the sum of squares
ss_cond <- 

# Define the degrees of freedom for conditions
df <- 

# Calculate the mean squares (variance)
ms_cond <- 
Edit and Run Code