2026-10-19

The Research Question

Working Memory and Attention

Working memory allows us to temporarily maintain and use information. Attention helps us select and focus on relevant information.

Research question: Are higher working-memory scores associated with higher attention scores?

We will investigate this question using simulated data and correlation.

Our Simulated Participants

We will create data for 60 fictional participants.

  • Working-memory scores range from 0 to 100.
  • Attention scores range from 0 to 100.
  • Each row represents one fictional participant.

These data are simulated for learning purposes. They are not measurements from real people.

library(ggplot2)
library(plotly)

set.seed(301)

n <- 60

working_memory <- round(
  pmin(pmax(rnorm(n, mean = 70, sd = 12), 30), 100)
)

attention <- round(
  pmin(pmax(
    70 + 0.55 * (working_memory - 70) +
      rnorm(n, mean = 0, sd = 10),
    30
  ), 100)
)

cognitive_data <- data.frame(
  participant = 1:n,
  working_memory = working_memory,
  attention = attention
)

head(cognitive_data)
##   participant working_memory attention
## 1           1             73        84
## 2           2             36        51
## 3           3             73        71
## 4           4             75        75
## 5           5             68        46
## 6           6             78        83

Understanding Correlation

Correlation describes the direction and strength of a linear relationship between two variables.

The correlation coefficient is represented by \(r\).

  • Positive values indicate a positive relationship.
  • Negative values indicate a negative relationship.
  • Values near zero indicate little linear association.

Important: Correlation alone cannot establish cause and effect.

The Correlation Coefficient

The Pearson correlation coefficient measures how two variables vary together.

\[ r = \frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2 \sum_{i=1}^{n}(y_i-\bar{y})^2}} \]

Where:

  • \(x_i\) = working-memory score for participant \(i\)
  • \(y_i\) = attention score for participant \(i\)
  • \(\bar{x}\) and \(\bar{y}\) = the respective sample means
  • \(n\) = number of participants

Interpreting the Correlation

The correlation coefficient ranges from \(-1\) to \(+1\).

\[ -1 \leq r \leq 1 \]

  • \(r > 0\): positive linear relationship
  • \(r < 0\): negative linear relationship
  • \(r \approx 0\): little linear relationship

The closer \(r\) is to either \(-1\) or \(+1\), the stronger the linear relationship tends to be.

Correlation does not prove causation.

Calculating the Correlation

We can use the cor() function in R to calculate the Pearson correlation coefficient.

r_value <- cor(
  cognitive_data$working_memory,
  cognitive_data$attention
)

round(r_value, 3)
## [1] 0.453

The result summarizes the direction and strength of the linear relationship between the two scores in our simulated sample.

Visualizing the Relationship

## `geom_smooth()` using formula = 'y ~ x'

Distribution of Working-Memory Scores

Explore the Scores Interactively

What Did We Find?

Our simulated data showed a positive correlation between working-memory scores and attention scores.

The Pearson correlation coefficient was r = 0.453, indicating a moderate positive linear relationship.

In this dataset, participants with higher working-memory scores tended to have higher attention scores.

However, correlation does not establish causation. We cannot conclude that better working memory causes better attention.

Important: These results come from simulated data, not real participants.

Conclusion

  • Our simulated data showed a moderate positive correlation between working memory and attention (\(r = 0.453\)).
  • Higher working-memory scores tended to occur alongside higher attention scores.
  • Correlation describes an association, not cause and effect.
  • Future research could examine whether this relationship appears in real participants using validated cognitive tests.

Takeaway: Statistical analysis helps us identify patterns, but we must interpret results in context.