For this exercise, please try to reproduce the results from Experiment 1 of the associated paper (Farooqui & Manly, 2015). The PDF of the paper is included in the same folder as this Rmd file.
Participants (N=21) completed a series of trials that required them to switch or stay from one task to the other. One task was to choose the larger value of the two values if surrounded by a green box. The other task was to choose the value with the larger font if surrounded by a blue box. Subliminal cues followed by a mask were presented before each trial. Cues included “O” (non-predictive cue), “M” (switch predictive cue), and “T” (repeat predictive cue). Reaction times and performance accuracy were measured.
Below is the specific result you will attempt to reproduce (quoted directly from the results section of Experiment 1):
Performance on switch trials, relative to repeat trials, incurred a switch cost that was evident in longer RTs (836 vs. 689 ms) and lower accuracy rates (79% vs. 92%). If participants were able to learn the predictive value of the cue that preceded only switch trials and could instantiate relevant anticipatory control in response to it, the performance on switch trials preceded by this cue would be better than on switch trials preceded by the nonpredictive cue. This was indeed the case (mean RT-predictive cue: 819 ms; nonpredictive cue: 871 ms; mean difference = 52 ms, 95% confidence interval, or CI = [19.5, 84.4]), two-tailed paired t(20) = 3.34, p < .01. However, error rates did not differ across these two groups of switch trials (predictive cue: 78.9%; nonpredictive cue: 78.8%), p = .8.
library(tidyverse) # for data munging
library(knitr) # for kable table formating
library(haven) # import and export 'SPSS', 'Stata' and 'SAS' Files
library(readxl) # import excel files
# #optional packages:
# library(broom)
# This reads all the participants data (each is in a seperate xls file) in and combines them into one dataframe
# Each xls has 250 rows, the rest is their calculations using excel, which we don't want in the data
files <- dir('data/Experiment 1')
data <- data.frame()
id <- 1
for (file in files){
if(file != 'Codebook.xls'){
temp_data <- read_xls(file.path('data/Experiment 1', file))
temp_data$id <- id
id <- id + 1
temp_data <- temp_data[1:250, ]
data <- rbind(data, temp_data)
}
}
data
## # A tibble: 5,250 × 23
## Block_Num…¹ Event…² Prime Prime…³ TaskT…⁴ Trial…⁵ CorrR…⁶ RT RespC…⁷ lnum
## <dbl> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <dbl>
## 1 3 1 O 1 2 0 1 898. TRUE 6
## 2 3 2 T 1 2 1 1 608. TRUE 85
## 3 3 3 M 1 1 2 1 1097 TRUE 96
## 4 3 4 O 1 1 1 0 841. TRUE 42
## 5 3 5 T 1 1 1 1 945 FALSE 16
## 6 3 6 T 1 1 1 1 1020. TRUE 22
## 7 3 7 M 1 2 2 1 1201. TRUE 80
## 8 3 8 T 1 2 1 1 737 TRUE 11
## 9 3 9 O 1 2 1 0 593 TRUE 84
## 10 3 10 T 1 2 1 0 577. TRUE 17
## # … with 5,240 more rows, 13 more variables: rnum <dbl>, lFont <dbl>,
## # swt <dbl>, stay <dbl>, stay_2...15 <dbl>, stay_4...16 <dbl>,
## # swt_2...17 <dbl>, swt_8...18 <dbl>, swt_2...19 <dbl>, swt_8...20 <dbl>,
## # stay_2...21 <dbl>, stay_4...22 <dbl>, id <dbl>, and abbreviated variable
## # names ¹Block_Number, ²Event_Number, ³PrimeVisible, ⁴TaskType, ⁵TrialType,
## # ⁶CorrResp, ⁷RespCorr
Each row is an observation. The data is already in tidy format.
tidy_d <- data %>% select(c("id", "Block_Number", "Event_Number", "TrialType", "TaskType", "RT", "RespCorr", "CorrResp"))
tidy_d
## # A tibble: 5,250 × 8
## id Block_Number Event_Number TrialType TaskType RT RespCorr CorrResp
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <dbl>
## 1 1 3 1 0 2 898. TRUE 1
## 2 1 3 2 1 2 608. TRUE 1
## 3 1 3 3 2 1 1097 TRUE 1
## 4 1 3 4 1 1 841. TRUE 0
## 5 1 3 5 1 1 945 FALSE 1
## 6 1 3 6 1 1 1020. TRUE 1
## 7 1 3 7 2 2 1201. TRUE 1
## 8 1 3 8 1 2 737 TRUE 1
## 9 1 3 9 1 2 593 TRUE 0
## 10 1 3 10 1 2 577. TRUE 0
## # … with 5,240 more rows
Performance on switch trials, relative to repeat trials, incurred a switch cost that was evident in longer RTs (836 vs. 689 ms)
# reproduce the above results here
#trial type 2 seems like it is the switch trial because the RTs are longer
tidy_d %>% group_by(TrialType) %>%
summarize(mean(RT))
## # A tibble: 3 × 2
## TrialType `mean(RT)`
## <dbl> <dbl>
## 1 0 2021.
## 2 1 731.
## 3 2 896.
#wait jk maybe it's task type not trial type
tidy_d %>% group_by(TaskType) %>%
summarize(mean(RT))
## # A tibble: 2 × 2
## TaskType `mean(RT)`
## <dbl> <dbl>
## 1 1 863.
## 2 2 699.
#stay is Trial Type 1, switch is 2
Performance on switch trials, relative to repeat trials, incurred a switch cost that was evident in […] lower accuracy rates (79% vs. 92%)
# reproduce the above results here
#numCorrect <- tidy_d %>% group_by(TrialType) %>%
#count(CorrResp == 1)
#numCorrect
accurracies <- tidy_d %>% group_by(TrialType, CorrResp) %>%
summarize(num = n()) %>%
mutate(percentage = num/sum(num) * 100)
#accurracies <- tidy_d %>%
#group_by(TrialType, CorrResp) %>%
#summarize(numParticipants = n()) %>%
#mutate(percentage = sum(numCorrect)/sum(numParticipants) * 100)
accurracies
## # A tibble: 6 × 4
## # Groups: TrialType [3]
## TrialType CorrResp num percentage
## <dbl> <dbl> <int> <dbl>
## 1 0 0 20 47.6
## 2 0 1 22 52.4
## 3 1 0 2033 51.0
## 4 1 1 1954 49.0
## 5 2 0 608 49.8
## 6 2 1 613 50.2
Now you will analyze Predictive Switch Cues vs Non-predictive Switch Cues. Let’s start with reaction time.
This was indeed the case (mean RT-predictive cue: 819 ms; nonpredictive cue: 871 ms; … )
# reproduce the above results here
tidy_d %>% group_by(TaskType) %>%
summarize(mean(RT))
## # A tibble: 2 × 2
## TaskType `mean(RT)`
## <dbl> <dbl>
## 1 1 863.
## 2 2 699.
Next you will try to reproduce error rates for Switch Predictive Cues vs Switch Non-predictive Cues.
However, error rates did not differ across these two groups of switch trials (predictive cue: 78.9%; nonpredictive cue: 78.8%)
# reproduce the above results here
The first claim is that in switch trials, predictive cues lead to statistically significant faster reaction times than nonpredictive cues.
… the performance on switch trials preceded by this cue would be better than on switch trials preceded by the nonpredictive cue. This was indeed the case (mean RT-predictive cue: 819 ms; nonpredictive cue: 871 ms; mean difference = 52 ms, 95% confidence interval, or CI = [19.5, 84.4]), two-tailed paired t(20) = 3.34, p < .01.
# reproduce the above results here
Next, test the second claim.
However, error rates did not differ across these two groups of switch trials (predictive cue: 78.9%; nonpredictive cue: 78.8%), p = .8.
# reproduce the above results here
Were you able to reproduce the results you attempted to reproduce? If not, what part(s) were you unable to reproduce?
I couldn’t get anything to work and I am giving up after the desiginated 3 hours :(
How difficult was it to reproduce your results?
I feel like it wouldn’t be that difficult but I am sick right now and can’t get it to work. I may figure it out later and update this r pubs.
What aspects made it difficult? What aspects made it easy?
being sick and struggling with R syntax and tidyverse