9  Correlation

9.1 Key Concepts

  • Pearson Correlation
  • Spearman Correlation
  • Sum of Cross Products
  • Linear vs. Non-Linear Relationships

9.2 Key Formulas

\[r = \frac{\sum(X - \bar{X})(Y - \bar{Y})}{\sqrt{SS_X \cdot SS_Y}}\]

\[t = r\sqrt{\frac{n-2}{1-r^2}}\]

\[df = n - 2\]

9.3 Code Examples

library(palmerpenguins)
library(tidyverse)

penguins |>
  drop_na(bill_length_mm, flipper_length_mm) |>
  summarise(r = cor(bill_length_mm, flipper_length_mm))
penguins_clean <- penguins |> drop_na(bill_length_mm, flipper_length_mm)

cor.test(penguins_clean$bill_length_mm, penguins_clean$flipper_length_mm)

9.4 Exercises

9.4.1 Conceptual Questions

  1. The main purpose of a Pearson correlation is to:

    A. Test the linear relationship between two continuous variables

    B. Test the monotonic relationship between two continuous variables

    C. Test how the means of two independent groups correlate (using variance information)

    D. Test the generic association between two or more continuous variables

  2. Like other tests we have covered, correlation also involves computing:

    A. SS between

    B. MS within

    C. SS for each variable

    D. All of the above

  3. Why is it important to plot data when examining correlations?

    A. There may be a non-linear relationship not properly characterized by a correlation coefficient

    B. There could be a monotonic but not a linear relationship

    C. There may be outliers

    D. All of the above are reasonable answers

  4. As X increases, so does Y — this is probably a:

    A. Negative correlation

    B. Positive correlation

    C. Spearman rho

    D. Inverse correlation

  5. This correlation metric is less susceptible to outliers:

    A. Spearman rho

    B. Spearman ratio

    C. Pearson r

    D. F-ratio

  6. Which of the following relationships is probably negatively correlated?

    A. Hours slept and number of dreams had

    B. Blood alcohol content and car accident probability

    C. Hours slept and hours standing

    D. None of the above; correlations cannot be less than 0

  7. In a Pearson or Spearman correlation, under the null hypothesis, the expected value of r is approximately:

    A. 0.1

    B. 0.5

    C. −1

    D. 0

  8. TRUE or FALSE: A researcher found that very little sleep (<5 hours) and very much sleep (10+ hours) are both associated with feeling miserable, while moderate sleep (7–9 hours) is associated with feeling good. This U-shaped relationship between sleep and mood is best described as linear.

    A. True

    B. False

  9. TRUE or FALSE: If the correlation between X and Y is r = 0.5, then the correlation between Y and X will be r = −0.5.

    A. True

    B. False

  10. Daily temperature is measured in both Fahrenheit and Celsius for an entire year. When you correlate the two scales:

    A. They are perfectly correlated (r = 1.0)

    B. Plotting them, all points fall on a perfect diagonal line

    C. They are perfectly linearly related

    D. All of the above


9.4.2 Computational Questions

Note: if direction is not specified, use direction implied by hypothesis.

For each problem:

  • Compute all intermediate values step by step: means, deviations, squared deviations, and the sum of cross products
  • Fill in the computation table
  • Compute Pearson r and the corresponding t statistic
  • Find and report the critical t value
  • Report the result: r(df) = r-value, p < or > α
  • Interpret the result in plain language

\[r = \frac{\sum(X - \bar{X})(Y - \bar{Y})}{\sqrt{SS_X \cdot SS_Y}} \qquad t = r\sqrt{\frac{n-2}{1-r^2}} \qquad df = n - 2\]


Problem 1 (n = 5)

A researcher examines the relationship between weekly study hours (X) and exam score (Y) in a sample of five students. Use α = .05, two-tailed.

X <- c(10, 25, 11, 8, 17)   # weekly study hours
Y <- c(12, 19,  9, 6, 21)   # exam score
alpha <- 0.05
Participant X Y X − X̄ Y − Ȳ (X − X̄)² (Y − Ȳ)² (X − X̄)(Y − Ȳ)
1 10 12
2 25 19
3 11 9
4 8 6
5 17 21
Sum
Mean

Compute r, t, and compare to critical t; state decision and interpret:

 

 

 


Problem 2 (n = 7)

A researcher examines whether weekly exercise hours (X) are related to self-reported stress (Y) in a sample of seven college students. Use α = .05, two-tailed.

X <- c(3, 7, 6, 6, 10, 9, 0)   # hours exercised per week
Y <- c(10, 4, 5, 4,  2, 2, 8)  # self-reported stress
alpha <- 0.05
Participant X Y X − X̄ Y − Ȳ (X − X̄)² (Y − Ȳ)² (X − X̄)(Y − Ȳ)
1 3 10
2 7 4
3 6 5
4 6 4
5 10 2
6 9 2
7 0 8
Sum
Mean

Compute r, t, and compare to critical t; state decision and interpret:

 

 

 


Problem 3 (n = 12)

A researcher examines whether weekly video game hours (X) are related to self-reported anxiety (Y). Use α = .05, two-tailed.

X <- c(3, 10, 2, 0, 5, 5, 4, 8, 7, 1, 4, 6)   # hours of video games per week
Y <- c(1,  3, 5, 6, 2, 3, 8, 7, 2, 5, 5, 3)   # self-reported anxiety
alpha <- 0.05
Participant X Y X − X̄ Y − Ȳ (X − X̄)² (Y − Ȳ)² (X − X̄)(Y − Ȳ)
1 3 1
2 10 3
3 2 5
4 0 6
5 5 2
6 5 3
7 4 8
8 8 7
9 7 2
10 1 5
11 4 5
12 6 3
Sum
Mean

Compute r, t, and compare to critical t; state decision and interpret: