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
Exercise instructions
- Define the number of subjects
n
for each condition. - Calculate the group means for IQ gains
iq
by condition using thetapply()
function. Thetapply()
function is used to group the observations foriq
by the variablecond
, then apply a function (in this casemean()
) 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 themean()
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 <-