- Suppose we measure reaction times in milliseconds for two groups: trained and untrained.
2025
data.table outputhead(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 outputtail(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
# Calculating means and SEMs
summary_dt <- dt[, .(mean_rt = mean(reaction_time),
sem = sd(reaction_time)/.N^0.5), by = group]
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(0.9)) +
labs(title = "Reaction Time by Group",
x = "Group",
y = "Reaction Time (ms)") +
theme_minimal(base_size = 15)
x <- dt[group == "Trained", reaction_time]
y <- dt[group == "Untrained", reaction_time]
t_test_result <- t.test(x,
y,
alternative = "two.sided",
conf.level = 0.95,
var.equal = F,
paired = F,
mu = 0,
)
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
# t.test unfortunately does not return effect size so # we need a little help to get it library(effsize) es = cohen.d(x, y, hedges.correction = TRUE) print(es)
## ## Hedges's g ## ## g estimate: -1.327685 (large) ## 95 percent confidence interval: ## lower upper ## -1.8912199 -0.7641495
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. 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, i \(t(56.56) = -5.21, p = 2.8e-06, g = -1.33\), suggesting that cognitive training may enhance processing speed in tasks similar to ours.
data.table outputhead(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 outputtail(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
# 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()
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
es = cohen.d(dt$rt_before, dt$rt_after, paired = TRUE, hedges.correction = TRUE)
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. 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, g = 0.83\), suggesting that cognitive training may enhance processing speed.
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?
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?