# Read in packages
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.0.10     ✔ readr     2.1.4 
## ✔ forcats   1.0.0      ✔ stringr   1.5.0 
## ✔ ggplot2   3.4.2      ✔ tibble    3.1.8 
## ✔ lubridate 1.9.2      ✔ tidyr     1.2.1 
## ✔ purrr     0.3.4      
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(ggpubr)
library(ggforce)
## Warning: package 'ggforce' was built under R version 4.2.3
library(effectsize)
library(lme4)
## Warning: package 'lme4' was built under R version 4.2.3
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 4.2.3
## 
## Attaching package: 'lmerTest'
## 
## The following object is masked from 'package:lme4':
## 
##     lmer
## 
## The following object is masked from 'package:stats':
## 
##     step
library(emmeans)
## Warning: package 'emmeans' was built under R version 4.2.3
library(MuMIn)
## Warning: package 'MuMIn' was built under R version 4.2.3
library(MCMCglmm)
## Warning: package 'MCMCglmm' was built under R version 4.2.3
## Loading required package: coda
## Warning: package 'coda' was built under R version 4.2.3
## Loading required package: ape
## Warning: package 'ape' was built under R version 4.2.3
## 
## Attaching package: 'ape'
## 
## The following object is masked from 'package:ggpubr':
## 
##     rotate
library(mixedpower)
library(dplyr)

# Read in file
Summarized_data <- read.csv("Summarized_data_EM6_FALLpilotV2.csv", header = TRUE)
Summarized_first_trips <- read.csv("Summarized_first_trips_EM6_FALLpilotV2.csv", header = TRUE)

Update condition names!

# We need to systematically rename the columns so that they make sense for this experiment!
library(stringr)

# Apply replacements in condsFile column
Summarized_data <- Summarized_data %>%
  mutate(
    condsFile = str_replace(condsFile, "noDelay", "delayAfterList"),
    condsFile = str_replace(condsFile, "longDelay", "delayBeforeList")
  )

Summarized_first_trips <- Summarized_first_trips %>%
  mutate(
    condsFile = str_replace(condsFile, "noDelay", "delayAfterList"),
    condsFile = str_replace(condsFile, "longDelay", "delayBeforeList")
  )

Get overall summaries!

# Get overall summary statistics
summarized_data_overall <- Summarized_data %>% 
  group_by(participant,condsFile,order) %>% 
  summarise(mean_Trip=mean(nTrip),
            mean_listTime = mean(meanListTime, na.rm = TRUE),
            mean_Correct = mean(meanCorrect, na.rm = TRUE),
            mean_CorBefInc = mean(meanCorBefInc,na.rm =TRUE),
            mean_inCorrect= mean(meanIncorrect, na.rm = TRUE),
            mean_clickeds= mean(meanclickeds, na.rm = TRUE),
            mean_MU = mean(meanMU, na.rm = TRUE)) %>%
  ungroup()
## `summarise()` has grouped output by 'participant', 'condsFile'. You can
## override using the `.groups` argument.
# Same for first trips
summarized_data_overall_first_trips <- Summarized_first_trips %>% 
  group_by(participant,condsFile,order) %>% 
  summarise(mean_Trip=mean(nTrip),
            mean_listTime = mean(meanListTime, na.rm = TRUE),
            mean_Correct = mean(meanCorrect, na.rm = TRUE),
            mean_CorBefInc = mean(meanCorBefInc,na.rm =TRUE),
            mean_inCorrect= mean(meanIncorrect, na.rm = TRUE),
            mean_clickeds= mean(meanclickeds, na.rm = TRUE),
            mean_MU = mean(meanMU, na.rm = TRUE)) %>%
  ungroup()
## `summarise()` has grouped output by 'participant', 'condsFile'. You can
## override using the `.groups` argument.
# multiDataTrialSum IS Summarized data by the way
# Be mindful of trips (1st trip only vs. all)

Get study time data ready…

# Study time Preprocess ------------------------
Summarized_data_FreeResponse <- Summarized_data %>%
  filter(!condsFile %in% c("delayBeforeListClosing", "delayAfterListClosing", "no_costClosing"))

Summarized_first_trips_FreeResponse <- Summarized_first_trips %>%
  filter(!condsFile %in% c("delayBeforeListClosing", "delayAfterListClosing", "no_costClosing"))

study_time_1trip <- Summarized_first_trips_FreeResponse %>%
  group_by(participant, condsFile) %>%
  summarize(mean_StudyTime = mean(meanListTime, na.rm = TRUE), 
            .groups = 'drop')

study_time <- Summarized_data_FreeResponse %>%
  group_by(participant, condsFile) %>%
  summarize(mean_StudyTime = mean(meanListTime, na.rm = TRUE), 
            .groups = 'drop')

Study time plot for ALL trips

# Study time PLOT all trips --------------------

# Calculate means and standard errors
means <- tapply(study_time$mean_StudyTime, study_time$condsFile, mean)
se <- tapply(study_time$mean_StudyTime, study_time$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterList", "delayBeforeList", "no_cost")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 30.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean Study Time, seconds", 
  main = "Mean study time, all trips"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- study_time[study_time$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$mean_StudyTime, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 3, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

Study time plot FIRST trips only

# Study time plot FIRST trips----------------------------------------------------
# Calculate means and standard errors
means <- tapply(study_time_1trip$mean_StudyTime, study_time_1trip$condsFile, mean)
se <- tapply(study_time_1trip$mean_StudyTime, study_time_1trip$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterList", "delayBeforeList", "no_cost")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 30.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean Study Time, seconds", 
  main = "Mean study time, first trips only"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- study_time_1trip[study_time_1trip$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$mean_StudyTime, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 3, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

Study time Closing

Exclusions for Closing!

Unfortunately but interestingly there is a clear divide between the 2 possible strategies participants adopt when they play this game. Most of the time, people check the list multiple times, and don’t overload their memory. But sometimes participants load up all the items in their memory and try to do it all at once. This is exactly what we want to see when we look for heavy-loaders vs. free-loaders! So we should really think hard about the best way to conceptualize and define this difference, because not only was this something I mentioned as an aim in my NDSEG grant but I also think its a novel thing to investigate in a paradigm like this.! Anyways, the down side of this is that there are some Closing trials that should be removed from comparison, because participants did the Closing trial all in one-go and therefore never learned that it was a Closing trial to begin with.

# participant:
# 011, Delay after list 
# 012, No delay
# 013, No delay
# 014, No delay
# 015, Delay after list, Delay before list
# 019, Delay before list
# 022, No delay
# 024, Delay after list, delay before list
# 025, No delay
# 029, ALL Closing
# 030, ALL Closing (this participant did REALLY well memory-wise)

Summarized_data_TotalResponse <- Summarized_data %>%
  filter(!condsFile %in% c("delayBeforeList", "delayAfterList", "no_cost"))

Summarized_data_TotalResponse <- Summarized_data_TotalResponse %>%
  filter(
    !(participant == "pilotv2011" & condsFile == "delayAfterListClosing"),
    !(participant == "pilotv2012" & condsFile == "no_costClosing"),
    !(participant == "pilotv2013" & condsFile == "no_costClosing"),
    !(participant == "pilotv2014" & condsFile == "no_costClosing"),
    !(participant == "pilotv2015" & (condsFile == "delayAfterListClosing" | condsFile == "delayBeforeListClosing")),
    !(participant == "pilotv2019" & condsFile == "delayBeforeListClosing"),
    !(participant == "pilotv2022" & condsFile == "no_costClosing"),
    !(participant == "pilotv2024" & (condsFile == "delayAfterListClosing" | condsFile == "delayBeforeListClosing")),
    !(participant == "pilotv2025" & condsFile == "no_costClosing"),
    participant != "pilotv2029", # Only filtering participant
    participant != "pilotv2030"  # Only filtering participant
  )

Now we continue as normal.

# Study time CLOSING ---------------------------------------
study_time_Closing <- Summarized_data_TotalResponse %>%
  group_by(participant, condsFile) %>%
  summarize(mean_StudyTime = mean(meanListTime, na.rm = TRUE), 
            .groups = 'drop')

means <- tapply(study_time_Closing$mean_StudyTime, study_time_Closing$condsFile, mean)
se <- tapply(study_time_Closing$mean_StudyTime, study_time_Closing$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterListClosing", "delayBeforeListClosing", "no_costClosing")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 40.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean Study Time", 
  main = "Mean study time, Closing trials"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- study_time_Closing[study_time_Closing$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$mean_StudyTime, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 3, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

MU free ALL trips

# MU Free all trips--------------------------------------------

# Average over all trials for each condition, for each Ss
participant_averages_allTrips <- Summarized_data_FreeResponse %>%
  group_by(participant, condsFile) %>%
  summarize(mean_MU = mean(meanMU, na.rm = TRUE), 
            .groups = 'drop')

# Calculate means and standard errors
means <- tapply(participant_averages_allTrips$mean_MU, participant_averages_allTrips$condsFile, mean)
se <- tapply(participant_averages_allTrips$mean_MU, participant_averages_allTrips$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterList", "delayBeforeList", "no_cost")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 10.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean MU(free)", 
  main = "Mean MU(free), all trips"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- participant_averages_allTrips[participant_averages_allTrips$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$mean_MU, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 2, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

MU free FIRST trips

# MU free 1st trips -----------------------------

# Average over all trials for each condition, for each Ss
participant_averages_1stTrips <- Summarized_first_trips_FreeResponse %>%
  group_by(participant, condsFile) %>%
  summarize(mean_MU = mean(meanMU, na.rm = TRUE), 
            .groups = 'drop')

# Calculate means and standard errors
means <- tapply(participant_averages_1stTrips$mean_MU, participant_averages_1stTrips$condsFile, mean)
se <- tapply(participant_averages_1stTrips$mean_MU, participant_averages_1stTrips$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterList", "delayBeforeList", "no_cost")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 10.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean MU(free)", 
  main = "Mean MU(free), 1st trips only"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- participant_averages_1stTrips[participant_averages_1stTrips$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$mean_MU, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 2, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

MU total

# Mu total ------------------------------------------------
# Calculate means and standard errors
means <- tapply(Summarized_data_TotalResponse$meanMU, Summarized_data_TotalResponse$condsFile, mean)
se <- tapply(Summarized_data_TotalResponse$meanMU, Summarized_data_TotalResponse$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterListClosing", "delayBeforeListClosing", "no_costClosing")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(-5, 15.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean MU(total)", 
  main = "Mean MU(total)"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- Summarized_data_TotalResponse[Summarized_data_TotalResponse$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$meanMU, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 2, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")

Trips

# Trips ----------------------------------

avg_trips <- Summarized_data_FreeResponse %>%
  group_by(participant, condsFile) %>%
  summarize(meanTrip = mean(nTrip, na.rm = TRUE), 
            .groups = 'drop')

# Calculate means and standard errors
means <- tapply(avg_trips$meanTrip, avg_trips$condsFile, mean)
se <- tapply(avg_trips$meanTrip, avg_trips$condsFile, function(x) sd(x) / sqrt(length(x)))

# Define the x-axis levels (to match the ggplot2 ordering)
conds_levels <- c("delayAfterList", "delayBeforeList", "no_cost")
x_positions <- 1:length(conds_levels)

# Create an empty plot
plot(
  x_positions, means[conds_levels], 
  type = "n", xaxt = "n", ylim = c(0, 8.0),xlim = c(0.5,3.5),
  xlab = "Condition", ylab = "Mean trips", 
  main = "Mean trips"
)

# Add x-axis labels
axis(1, at = x_positions, labels = conds_levels)

# Add points for each participant
for (i in 1:length(conds_levels)) {
  condition_data <- avg_trips[avg_trips$condsFile == conds_levels[i], ]
  points(rep(x_positions[i], nrow(condition_data)), condition_data$meanTrip, 
         pch = 1, col = "blue")
}

# Add points for the means
points(x_positions, means[conds_levels], pch = 16, col = "black")

# Add error bars for standard errors
segments(
  x_positions, means[conds_levels] - se[conds_levels], 
  x_positions, means[conds_levels] + se[conds_levels],
  col = "black", lwd = 3.6
)

# Add horizontal segments at the means (optional, similar to ggplot2's stat_summary)
segments(
  x_positions - 0.1, means[conds_levels], 
  x_positions + 0.1, means[conds_levels],
  col = "black", lwd = 3.0
)

# Add mean labels for each condition
text(x_positions, means[conds_levels] + 2, 
     labels = round(means[conds_levels], 2), cex = 1.5, col = "red")