library(tidyverse)
library(ggplot2)
library(ggpubr)
library(plyr)
Set the R working drectory to the main experiment directory.
setwd("/Users/adambarnas/Box/CogStyles_IB")
Read in the individual subject files (saved automatically on the server as csv files).
Get a count of the number of subjects.
nrow(tbl_all %>% distinct(ID,.keep_all = FALSE))
## [1] 14
Split up the cognitive styles stimuli nomenclature to task, answer, and number. Filter the two cognitive styles tasks.
tbl_all_cog_style <- tbl_all %>%
separate(stim1,into=c('task', 'answer', 'number')) %>%
filter(task == 'matching' | task == 'embedded')
tbl_all_cog_style = subset(tbl_all_cog_style, select = -c(ITI,stimFormat,button1,keyboard,key,responseWindow,head,responseType,randomPick,responseOptions,pageBreak,required,responseCode,correct))
In the matching figures task, subjects were instructed to press ‘F’ if the two complex shapes were the same and ‘J’ if the two complex shapes were different. Trials will be labeled 1 for correct responses (‘F’ for same objects and ‘J’ for different objects) and 0 for incorrect responses (‘F’ for different objects and ‘J’ for same objects).
In the embedded figures task, subjects were instructed to press ‘F’ if the simple shape is within the complex shape and ‘J’ if the the simple shape is not within the complex shape. Trials will be labeled 1 for correct responses (‘F’ for simple within complex and ‘J’ for simple not within complex) and 0 for incorrect responses (‘F’ simple not within complex and ‘J’ simple within complex).
tbl_all_cog_style$acc = "filler"
for (i in 1:length(tbl_all_cog_style$ID)){
if (tbl_all_cog_style$task[i] == "matching"){
if (tbl_all_cog_style$answer[i] == "same"){
if (tbl_all_cog_style$response[i] == "f"){
tbl_all_cog_style$acc[i] = 1
} else {
tbl_all_cog_style$acc[i] = 0
}
} else {
if (tbl_all_cog_style$response[i] == "j"){
tbl_all_cog_style$acc[i] = 1
} else {
tbl_all_cog_style$acc[i] = 0
}
}
}
if (tbl_all_cog_style$task[i] == "embedded"){
if (tbl_all_cog_style$answer[i] == "yes"){
if (tbl_all_cog_style$response[i] == "f"){
tbl_all_cog_style$acc[i] = 1
} else {
tbl_all_cog_style$acc[i] = 0
}
} else {
if (tbl_all_cog_style$response[i] == "j"){
tbl_all_cog_style$acc[i] = 1
} else {
tbl_all_cog_style$acc[i] = 0
}
}
}
}
tbl_all_cog_style_acc <- tbl_all_cog_style %>%
group_by(ID,task,acc) %>%
dplyr::summarize(counts = n()) %>%
spread(acc,counts) %>%
mutate(total = rowSums(.[3:4], na.rm = TRUE))
colnames(tbl_all_cog_style_acc) <- c("ID", "task", "inacc", "acc", "total")
tbl_all_cog_style_acc[is.na(tbl_all_cog_style_acc)] <- 0
tbl_all_cog_style_acc$rate <- tbl_all_cog_style_acc$acc / tbl_all_cog_style_acc$total
tbl_all_cog_style_acc %>%
ggbarplot("ID", "rate", fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), ylab = "Accuracy", ylim = c(0, 1), position = position_dodge(0.8)) + rotate_x_text() + geom_hline(yintercept = .5, linetype = 2)
tbl_all_cog_style_acc %>%
ggbarplot("task", "rate", add = "mean_se",fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), ylab = "Accuracy", ylim = c(0, 1), position = position_dodge(0.8)) + geom_hline(yintercept = .5, linetype = 2)
embedded_chance <- tbl_all_cog_style_acc %>%
filter(task =="embedded")
embedded_chance <-t.test(embedded_chance$rate, mu = .50, alternative="greater")
embedded_chance
##
## One Sample t-test
##
## data: embedded_chance$rate
## t = 12.64, df = 13, p-value = 5.589e-09
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.8117122 Inf
## sample estimates:
## mean of x
## 0.8625
matching_chance <- tbl_all_cog_style_acc %>%
filter(task =="matching")
matching_chance <-t.test(matching_chance$rate, mu = .50, alternative="greater")
matching_chance
##
## One Sample t-test
##
## data: matching_chance$rate
## t = 15.751, df = 13, p-value = 3.773e-10
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.8185731 Inf
## sample estimates:
## mean of x
## 0.8589286
tbl_all_cog_style_acc %>%
with(t.test(rate~task,paired=TRUE))
##
## Paired t-test
##
## data: rate by task
## t = 0.14219, df = 13, p-value = 0.8891
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.05069155 0.05783441
## sample estimates:
## mean of the differences
## 0.003571429
tbl_all_cog_style_rts <- tbl_all_cog_style %>%
filter(acc == 1)
tbl_all_cog_style_rts %>%
ggbarplot("ID", "RT", fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), add = "median", position = position_dodge(0.8), ylab = "Median RT (ms)", ylim = c(0,8000)) + rotate_x_text()
tbl_all_cog_style_rts %>%
ggbarplot("task", "RT", add = "median",fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), position = position_dodge(0.8), order = c("embedded", "matching"), ylab = "Median RT (ms)", ylim = c(0,5000))
tbl_all_cog_style_rts_median <- tbl_all_cog_style_rts %>%
group_by(ID,task) %>%
dplyr::summarize(median_rt = median(RT, na.rm=TRUE))
tbl_all_cog_style_rts_median %>%
with(t.test(median_rt~task,paired=TRUE))
##
## Paired t-test
##
## data: median_rt by task
## t = -3.491, df = 13, p-value = 0.003982
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -3344.0149 -787.3423
## sample estimates:
## mean of the differences
## -2065.679
The wholist-analytic ratio is calculated by dividing the median response latency to items in the matching figures task (wholist) by the median response latency to items in the embedded figures task (analytic) A ratio of below 1 indicates that an individual responded relatively faster to the matching figure items, corresponding to a wholist profile; a ratio of above 1 indicates that an individual responded relatively faster to the embedded figure items, corresponding to a analytic profile.
tbl_all_cog_style_rts_median <- tbl_all_cog_style_rts_median %>%
spread(task, median_rt)
tbl_all_cog_style_rts_median$ratio <- tbl_all_cog_style_rts_median$matching / tbl_all_cog_style_rts_median$embedded
tbl_all_cog_style_rts_median$style = "filler"
for (i in 1:length(tbl_all_cog_style_rts_median$ID)){
if (tbl_all_cog_style_rts_median$ratio[i] > 1){
tbl_all_cog_style_rts_median$style[i] = "analytic"
} else {
tbl_all_cog_style_rts_median$style[i] = "wholist"
}
}
tbl_all_cog_style_rts_median %>%
ggbarplot("ID", "ratio", fill = "#f7a800", color = "#f7a800", ylab = "Median wholist-analytic ratio") + rotate_x_text() + geom_hline(yintercept = 1, linetype = 2)
table(tbl_all_cog_style_rts_median$style)
##
## analytic wholist
## 11 3
tbl_all_IB <- tbl_all %>%
filter(grepl('Did you notice|item', head))
tbl_all_IB = subset(tbl_all_IB, select = -c(stim1,ITI,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
tbl_all_notice <- tbl_all_IB %>%
filter(grepl('items', head))
table(tbl_all_notice$response)
##
## No Not sure Yes
## 4 2 8
tbl_all_event <- tbl_all_IB %>%
filter(grepl('moved', head))
table(tbl_all_event$response)
##
## +
## 1
## I didn't see anything unusual
## 1
## I feel like I saw the + a few times but did not pay attention to its movement
## 1
## I might have seen a + sign but I don't really remember.
## 1
## I noticed the plus sign moving across the screen. It moved from right to left across the center line.
## 1
## I think I saw + but I am not sure how it moved.
## 1
## I'm not sure, but the + might have moved with the letters.
## 1
## it was the plus sign (+) and it moved from the right hand side towards the left hand side of the screen.
## 1
## n/a
## 1
## Plus sign horizontally
## 1
## the + moves horizontally passing the center of the box.
## 1
## The cross on the right.
## 1
## the plus sign, moved from right to left, down the horizontal line
## 1
## Ts and Ls
## 1
tbl_all_expecting <- tbl_all %>%
filter(grepl('Before', head))
tbl_all_expecting = subset(tbl_all_expecting, select = -c(stim1,ITI,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
table(tbl_all_expecting$response)
##
## No Yes
## 10 4
tbl_all_familiarity <- tbl_all %>%
filter(grepl('gorilla', head))
tbl_all_familiarity = subset(tbl_all_familiarity, select = -c(stim1,ITI,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
table(tbl_all_familiarity$response)
##
## No Yes
## 2 12
tbl_log_reg <- merge(tbl_all_cog_style_rts_median, tbl_all_notice, by = "ID")
tbl_log_reg = subset(tbl_log_reg, select = -c(rowNo,type,head,timestamp,RT,correct))
tbl_log_reg[tbl_log_reg == "Yes"] <- 1
tbl_log_reg[tbl_log_reg == "No"] <- 0
tbl_log_reg[tbl_log_reg == "Not sure"] <- 0
names(tbl_log_reg)[names(tbl_log_reg)=="response"] <- "notice"
tbl_log_reg$notice <- as.numeric(tbl_log_reg$notice)
log_reg <- glm(notice ~ ratio, data = tbl_log_reg, family = binomial(link = "logit"))
summary(log_reg)
##
## Call:
## glm(formula = notice ~ ratio, family = binomial(link = "logit"),
## data = tbl_log_reg)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.0915 -0.9788 0.6345 0.8678 1.5148
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.3935 1.2636 -1.103 0.270
## ratio 0.7784 0.5418 1.437 0.151
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 19.121 on 13 degrees of freedom
## Residual deviance: 16.642 on 12 degrees of freedom
## AIC: 20.642
##
## Number of Fisher Scoring iterations: 4
plot <- ggplot(tbl_log_reg, aes(x=ratio, y=notice)) + geom_point() + stat_smooth(method="glm", method.args=list(family="binomial"), se=TRUE, color="#f7a800") + theme_classic((base_size = 15))
suppressMessages(print(plot))