Get startedGet started for free

Preliminary statistics

For independent t-tests you will revisit the working memory dataset from the previous chapter. In this dataset, subjects were randomly assigned to four different training groups that trained for 8, 12, 17 and 19 days, respectively (column cond in wm_t).

The scores for each subject were recorded before and after undergoing the training regime. You are interested in determining if there is a significant difference in the gain in intelligence scores between groups that trained for different lengths of time.

This exercise is part of the course

Intro to Statistics with R: Student's T-test

View Course

Exercise instructions

The wm_t dataset has been loaded into your workspace.

  • Print wm_t to the console to refresh your memory of its contents.
  • Create a subset of the data for each training group and save each in a variable called wm_t##, where ## is 08, 12, 17 or 19.
  • View summary statistics for each subset using the describe() function from the psych package, which has been loaded for you. The gain row tells you the gain in intelligence test scores before and after training.
  • Create a boxplot using the ggplot2 package to visualize differences in the group means. This code has been provided for you, so you just need to run it as-is.
  • Use leveneTest() to perform Levene's test for homogeneity of variance. This will check if all groups contain an equivalent amount of variance, which is a necessary precondition for the use of pooled standard deviation in the t-statistic for independent groups. Note that the function uses a formula interface, so pass wm_t$gain to the left of ~ and wm_t$cond to the right.

Hands-on interactive exercise

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

# View the wm_t dataset


# Create subsets for each training time
wm_t08 <- ___
wm_t12 <- ___
wm_t17 <- ___
wm_t19 <- ___

# Summary statistics for the change in training scores before and after training





# Create a boxplot of the different training times
ggplot(wm_t, aes(x = cond, y = gain, fill = cond)) + geom_boxplot()

# Levene's test
leveneTest(wm_t$___ ~ wm_t$___)
Edit and Run Code