2024

Sample Data

  • Suppose we measure reaction times in milliseconds for two groups: trained and untrained.

data.table output

head(dt)
##    subject_id   group reaction_time
##         <int>  <char>         <num>
## 1:          1 Trained      471.9762
## 2:          2 Trained      488.4911
## 3:          3 Trained      577.9354
## 4:          4 Trained      503.5254
## 5:          5 Trained      506.4644
## 6:          6 Trained      585.7532

data.table output

tail(dt)
##    subject_id     group reaction_time
##         <int>    <char>         <num>
## 1:         55 Untrained      538.7115
## 2:         56 Untrained      625.8235
## 3:         57 Untrained      472.5624
## 4:         58 Untrained      579.2307
## 5:         59 Untrained      556.1927
## 6:         60 Untrained      560.7971

Experiment design

  • Clear from the previous two slides that different subject IDs are assigned to the two groups, indicating that this is a between-subjects design.

Visualizing the data

# Calculating means and SEMs
summary_dt <- dt[, .(mean_rt = mean(reaction_time),
                    sem = sd(reaction_time)/.N^0.5), by = group]

# Creating the plot
g <- ggplot(summary_dt, aes(x=group, y=mean_rt, colour=group)) + 
    geom_pointrange(aes(ymin=mean_rt-sem, ymax=mean_rt+sem),
                    position=position_dodge(.9)) +
    labs(title="Reaction Time by Group", 
         x="Group",
         y="Reaction Time (ms)") +
    theme_minimal()

Perform a t-Test

x <- dt[group == "Trained", reaction_time]
y <- dt[group == "Untrained", reaction_time]
t_test_result <- t.test(x, y)
print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -5.2098, df = 56.559, p-value = 2.755e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -84.82713 -37.71708
## sample estimates:
## mean of x mean of y 
##  497.6448  558.9169

Results in a sentence

In a study examining the effects of cognitive training on reaction time, subjects who underwent the training demonstrated significantly faster reaction times compared to untrained subjects. Specifically, the trained subjects had a mean reaction time of 497.64 ms (SD = 49.05 ms), whereas the untrained subjects had a mean reaction time of 558.92 ms (SD = 41.76 ms). The difference was statistically significant, \(t(56.56) = -5.21, p = 2.8e-06\), suggesting that cognitive training may enhance processing speed in tasks similar to ours.

How to report p-values

  • If the p-value is less than \(0.001\), report it as \(p < 0.001\).
  • If the p-value is less than \(0.01\), report it as \(p < 0.01\).
  • If the p-value is less than \(0.05\), report it as \(p < 0.05\).
  • Otherwise, report the exact p-value to two decimal places.
  • Always check journal guidelines for specific requirements.

Sample Data

  • Suppose we measure reaction times in milliseconds for the same subjects before and after undergoing cognitive training.

data.table output

head(dt)
##    subject_id rt_before rt_after
##         <int>     <num>    <num>
## 1:          1  521.9762 521.3232
## 2:          2  538.4911 485.2464
## 3:          3  627.9354 544.7563
## 4:          4  553.5254 543.9067
## 5:          5  556.4644 541.0791
## 6:          6  635.7532 534.4320

data.table output

tail(dt)
##    subject_id rt_before rt_after
##         <int>     <num>    <num>
## 1:         25  518.7480 488.7115
## 2:         26  465.6653 575.8235
## 3:         27  591.8894 422.5624
## 4:         28  557.6687 529.2307
## 5:         29  493.0932 506.1927
## 6:         30  612.6907 510.7971

Experiment Design

  • Given the repeated measures on the same subjects (before and after training), this is a within-subjects design.

Visualizing the Data

# Calculating differences
dt[, difference := rt_after - rt_before]

# Creating the plot
g1 <- ggplot(dt, aes(x=factor(subject_id), y=difference)) +
     geom_bar(stat="identity") +
     labs(title="Change in Reaction Time After Training",
          x="Subject",
          y="Difference in Reaction Time (ms)") +
     theme_minimal()

g2 <- ggplot(dt, aes(x=0, y=difference)) +
     geom_boxplot() +
     labs(title="Change in Reaction Time After Training",
          x="",
          y="Difference in Reaction Time (ms)") +
     theme_minimal()

Perform a Repeated Measures t-Test

t_test_result <- t.test(dt$rt_before, dt$rt_after, paired = TRUE)
print(t_test_result)
## 
##  Paired t-test
## 
## data:  dt$rt_before and dt$rt_after
## t = 3.0634, df = 29, p-value = 0.004691
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  12.87202 64.58378
## sample estimates:
## mean difference 
##         38.7279

Results in a Sentence

In a repeated measures study examining the effects of cognitive training on reaction time, a significant decrease in reaction time was observed after the training. Specifically, the mean decrease in reaction time was -38.73 ms (SD = 69.24 ms). The decrease was statistically significant, \(t(29) = 3.06, p = 0.0047\), suggesting that cognitive training may enhance processing speed.

Question

Consider the following code:

# Calculating means and SEMs
summary_dt <- dt[, .(x_mean = mean(reaction_time),
                     x_err = sd(reaction_time)/sqrt(.N)), by = group]

# Creating the plot
g <- ggplot(summary_dt, aes(x=group, y=x_mean, colour=group)) + 
    geom_pointrange(aes(ymin=x_mean - x_err, ymax=x_mean + x_err),
                    position=position_dodge(.9)) +
    labs(title="Reaction Time by Group", 
         x="Group",
         y="Reaction Time (ms)") +
    theme_minimal()

What do the error bars represent in the plot?

  • 95% confidence intervals
  • The standard deviation of the data
  • The standard error of the mean the data
  • The range of the data
Answer The error bars represent the standard error of the mean.

Question

Consider the following scenario:

In a double-blind placebo-controlled study investigating the impact of a novel nootropic on memory retention, participants exhibited a notable improvement in their memory test scores following a month-long supplementation period. Specifically, the average increase in memory test scores was 12 points (\(SD = 3.5\) points). This improvement was statistically significant, \(t(48) = 5.76, p < 0.001\), indicating that the nootropic may significantly bolster memory functions.

How many participants were enrolled in the study?

Answer The degrees of freedom for a one-sample t-test are \(n-1\), so \(n = 49\) participants were enrolled in the study.