Within groups sum of squares

To calculate the F-value, you also need the variance within groups. Similar to the last exercise, we'll start by computing the within groups sum of squares, which is equal to the following:

$$\begin{aligned} ss_{s/a} & = \sum(Y_{ij} - y_j)^2 \end{aligned}$$

where \(Y_{ij}\) are the individual scores and \(y_j\) are the group means. Now you are going to apply this formula yourself!

This exercise is part of the course

Intro to Statistics with R: Analysis of Variance (ANOVA)

View Course

Exercise instructions

  • Create a separate vector of IQ gains (wm$iq) for each training group (wm$condition) using the subset() function. The first one has been done for you. Define them in order from the least amount of training to the most amount of training.
  • Now you can easily subtract each subject's IQ gain by its corresponding group mean. You already calculated the group means in the previous exercise, so use this result. The vector containing the four group means is called y_j and will need to be subsetting using [ ] notation to extract each mean.
  • Create a new vector, s_t, to combine s_1, s_2, s_3, and s_4 back into a single vector.
  • Calculate the within groups sum of squares. You just need to square the previous result and sum up the elements of the vector using the sum() function.

Hands-on interactive exercise

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

# Create a separate vector of IQ gains for each training group
y_i1 <- subset(wm$iq, wm$cond == "8 days")
y_i2 <- subset(wm$iq, wm$cond == ___)
y_i3 <- subset(wm$iq, wm$cond == ___)
y_i4 <- subset(wm$iq, wm$cond == ___)

# Subtract group means from the individual values
s_1 <- y_i1 - y_j[1]
s_2 <- ___ - ___
s_3 <- ___ - ___
s_4 <- ___ - ___

# Put everything back together into one vector
s_t <- c(___, ___, ___, ___)

# Calculate the sum of squares using s_t
ss_sa <- ___