Get startedGet started for free

Independent t-tests, the easy way

As you saw in the last chapter, the t.test() function makes it easy to perform t-tests. This applies for independent t-tests in addition to dependent t-tests.

For an independent t-test, we specify these arguments to t.test():

  • x: Column of data containing the first group's intelligence scores
  • y: Column of data containing the second group's intelligence scores
  • var.equal: Whether to assume the variance is equal in both groups. We do make this assumption here, so it should be TRUE

Note that we don't have to use the paired argument for an independent t-test, since this is the default behavior of the t.test() function. Check out ?t.test for more info.

To compute Cohen's d quickly, use cohensD() with three arguments:

  • x: Column of data containing the first group's intelligence scores
  • y: Column of data containing the second group's intelligence scores
  • method: Version of Cohen's d to compute, which should be "pooled" in this case

You should get the same values you got "by hand" in the previous exercises.

This exercise is part of the course

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

View Course

Exercise instructions

The wm_t08 and wm_t19 datasets have been loaded into your workspace.

  • Apply t.test() to test whether there's a significant difference between groups who trained for 19 days verses those who trained for only 8 days. Recall that intelligence score gains are contained in the gain column of each data frame. Don't save the result.
  • Apply cohensD() to compute Cohen's d. Use the same columns as inputs for x and y. Don't save the result.

Hands-on interactive exercise

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

## The subsets wm_t08 and wm_t19 are preloaded in your workspace

# Conduct an independent t-test 


# Calculate Cohen's d
Edit and Run Code