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.
Get a count of the number of subjects.
nrow(tbl_all %>% distinct(ID,.keep_all = FALSE))
## [1] 65
Organize data
tbl_all_simple = subset(tbl_all, select = -c(rowNo,responseWindow,presTime,ISI,ITI,stimFormat,button1,keyboard,key,responseType,randomPick,responseOptions,pageBreak,required,if.,then,ITI_ms,ITI_f,ITI_fDuration,presTime_ms,presTime_f,presTime_fDuration,timestamp,responseCode,correct))
tbl_all_simple <- tbl_all_simple %>%
separate(response,into=c('response'))
tbl_all_simple <- tbl_all_simple %>%
separate(RTkeys,into=c('RTkeys'))
tbl_all_simple[tbl_all_simple==""]<-NA
tbl_all_simple$rt<- tbl_all_simple$RTkeys
tbl_all_simple$rt[is.na(tbl_all_simple$rt)] <- tbl_all_simple$RT[is.na(tbl_all_simple$rt)]
tbl_all_simple$rt <- as.numeric(tbl_all_simple$rt)
tbl_all_simple$ID <- as.character(tbl_all_simple$ID)
tbl_all_simple$stim1 <- as.character(tbl_all_simple$stim1)
tbl_all_blank_removed <- tbl_all_simple %>%
filter(stim1 != "blank")
tbl_all_cog_style <- tbl_all_blank_removed %>%
filter(grepl('embedded|matching', stim1))
tbl_all_cog_style[tbl_all_cog_style== "embedded_prompt" ] <- NA
tbl_all_cog_style[tbl_all_cog_style== "matching_prompt" ] <- NA
tbl_all_cog_style[tbl_all_cog_style== "timeout" ] <- NA
tbl_all_cog_style <- tbl_all_cog_style %>%
group_by(ID) %>%
fill(stim1) %>% #default direction down
fill(stim1, .direction = "up")
tbl_all_cog_style_condensed <- tbl_all_cog_style %>%
group_by(ID, stim1) %>%
dplyr::summarise(RT = sum(rt), response = first(na.omit(response)))
Split up the cognitive styles stimuli nomenclature to task, answer, and number. Filter the two cognitive styles tasks.
tbl_all_cog_style_condensed <- tbl_all_cog_style_condensed %>%
separate(stim1,into=c('task', 'answer', 'number'))
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_condensed$acc = "filler"
for (i in 1:length(tbl_all_cog_style_condensed$ID)){
if (tbl_all_cog_style_condensed$task[i] == "matching"){
if (tbl_all_cog_style_condensed$answer[i] == "same"){
if (tbl_all_cog_style_condensed$response[i] == "f"){
tbl_all_cog_style_condensed$acc[i] = 1
} else {
tbl_all_cog_style_condensed$acc[i] = 0
}
} else {
if (tbl_all_cog_style_condensed$response[i] == "j"){
tbl_all_cog_style_condensed$acc[i] = 1
} else {
tbl_all_cog_style_condensed$acc[i] = 0
}
}
}
if (tbl_all_cog_style_condensed$task[i] == "embedded"){
if (tbl_all_cog_style_condensed$answer[i] == "yes"){
if (tbl_all_cog_style_condensed$response[i] == "f"){
tbl_all_cog_style_condensed$acc[i] = 1
} else {
tbl_all_cog_style_condensed$acc[i] = 0
}
} else {
if (tbl_all_cog_style_condensed$response[i] == "j"){
tbl_all_cog_style_condensed$acc[i] = 1
} else {
tbl_all_cog_style_condensed$acc[i] = 0
}
}
}
}
tbl_all_cog_style_condensed_acc <- tbl_all_cog_style_condensed %>%
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_condensed_acc) <- c("ID", "task", "inacc", "acc", "total")
tbl_all_cog_style_condensed_acc[is.na(tbl_all_cog_style_condensed_acc)] <- 0
tbl_all_cog_style_condensed_acc$rate <- tbl_all_cog_style_condensed_acc$acc / tbl_all_cog_style_condensed_acc$total
tbl_all_cog_style_condensed_acc %>%
ggbarplot("ID", "rate", fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), font.xtickslab = 6, ylab = "Accuracy", ylim = c(0, 1), position = position_dodge(0.8)) + rotate_x_text() + geom_hline(yintercept = .5, linetype = 2)
tbl_all_cog_style_condensed_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_sona <- tbl_all_cog_style_condensed_acc %>%
filter(task =="embedded")
embedded_chance_sona <-t.test(embedded_chance_sona$rate, mu = .50, alternative="greater")
embedded_chance_sona
##
## One Sample t-test
##
## data: embedded_chance_sona$rate
## t = 16.99, df = 64, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.7871772 Inf
## sample estimates:
## mean of x
## 0.8184615
matching_chance_sona <- tbl_all_cog_style_condensed_acc %>%
filter(task =="matching")
matching_chance_sona <-t.test(matching_chance_sona$rate, mu = .50, alternative="greater")
matching_chance_sona
##
## One Sample t-test
##
## data: matching_chance_sona$rate
## t = 15.229, df = 64, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.7256833 Inf
## sample estimates:
## mean of x
## 0.7534615
tbl_all_cog_style_condensed_acc %>%
with(t.test(rate~task,paired=TRUE))
##
## Paired t-test
##
## data: rate by task
## t = 4.8539, df = 64, p-value = 8.124e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.0382478 0.0917522
## sample estimates:
## mean of the differences
## 0.065
tbl_all_cog_style_condensed_acc <- subset(tbl_all_cog_style_condensed_acc, select = c(ID, task, rate))
tbl_all_cog_style_condensed_acc_wide <- tbl_all_cog_style_condensed_acc %>%
spread(task,rate)
tbl_all_cog_style_condensed_acc <- tbl_all_cog_style_condensed_acc_wide %>%
filter(embedded > 0.5 & matching > 0.5)
tbl_all_cog_style_condensed_acc <- gather(tbl_all_cog_style_condensed_acc, task, rate, embedded:matching, factor_key=TRUE)
tbl_all_cog_style_condensed_acc %>%
ggbarplot("ID", "rate", fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), font.xtickslab = 6, ylab = "Accuracy", ylim = c(0, 1), position = position_dodge(0.8)) + rotate_x_text() + geom_hline(yintercept = .5, linetype = 2)
tbl_all_cog_style_condensed_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_sona <- tbl_all_cog_style_condensed_acc %>%
filter(task =="embedded")
embedded_chance_sona <-t.test(embedded_chance_sona$rate, mu = .50, alternative="greater")
embedded_chance_sona
##
## One Sample t-test
##
## data: embedded_chance_sona$rate
## t = 29.051, df = 56, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.8414234 Inf
## sample estimates:
## mean of x
## 0.8622807
matching_chance_sona <- tbl_all_cog_style_condensed_acc %>%
filter(task =="matching")
matching_chance_sona <-t.test(matching_chance_sona$rate, mu = .50, alternative="greater")
matching_chance_sona
##
## One Sample t-test
##
## data: matching_chance_sona$rate
## t = 21.68, df = 56, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
## 0.7659282 Inf
## sample estimates:
## mean of x
## 0.7881579
tbl_all_cog_style_condensed_acc %>%
with(t.test(rate~task,paired=TRUE))
##
## Paired t-test
##
## data: rate by task
## t = 5.4236, df = 56, p-value = 1.289e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.04674492 0.10150069
## sample estimates:
## mean of the differences
## 0.07412281
tbl_all_cog_style_condensed_rts <- tbl_all_cog_style_condensed[(tbl_all_cog_style_condensed$ID %in% tbl_all_cog_style_condensed_acc$ID),] %>%
filter(acc == 1)
tbl_all_cog_style_condensed_rts %>%
ggbarplot("ID", "RT", fill = "task", color = "task", palette = c("#0d2240", "#00a8e1"), font.xtickslab = 6, add = "median", position = position_dodge(0.8), ylab = "Median RT (ms)", ylim = c(0,6000)) + rotate_x_text()
tbl_all_cog_style_condensed_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_condensed_rts_median <- tbl_all_cog_style_condensed_rts %>%
group_by(ID,task) %>%
dplyr::summarize(median_rt = median(RT, na.rm=TRUE))
tbl_all_cog_style_condensed_rts_median %>%
with(t.test(median_rt~task,paired=TRUE))
##
## Paired t-test
##
## data: median_rt by task
## t = -15.089, df = 56, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1438.777 -1101.521
## sample estimates:
## mean of the differences
## -1270.149
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_condensed_rts_median <- tbl_all_cog_style_condensed_rts_median %>%
spread(task, median_rt)
tbl_all_cog_style_condensed_rts_median$ratio <- tbl_all_cog_style_condensed_rts_median$matching / tbl_all_cog_style_condensed_rts_median$embedded
tbl_all_cog_style_condensed_rts_median$style = "filler"
for (i in 1:length(tbl_all_cog_style_condensed_rts_median$ID)){
if (tbl_all_cog_style_condensed_rts_median$ratio[i] > 1){
tbl_all_cog_style_condensed_rts_median$style[i] = "analytic"
} else {
tbl_all_cog_style_condensed_rts_median$style[i] = "wholist"
}
}
tbl_all_cog_style_condensed_rts_median %>%
ggbarplot("ID", "ratio", fill = "#f7a800", color = "#f7a800", ylim = c(0,4), font.xtickslab = 6, ylab = "Median wholist-analytic ratio") + rotate_x_text() + geom_hline(yintercept = 1, linetype = 2)
table(tbl_all_cog_style_condensed_rts_median$style)
##
## analytic
## 57
tbl_all_IB <- tbl_all %>%
filter(grepl('Did you notice|item', head))
tbl_all_IB = subset(tbl_all_IB, select = -c(stim1,ITI,ISI,presTime,if.,then,presTime_ms,presTime_f,presTime_fDuration,RTkeys,correct,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
tbl_all_IB <- tbl_all_IB[(tbl_all_IB$ID %in% tbl_all_cog_style_condensed_rts_median$ID),]
tbl_all_counting <- tbl_all %>%
filter(rowNo >= 406 & rowNo <= 433)
tbl_all_counting = subset(tbl_all_counting, select = -c(rowNo,type,timestamp,RT,correct,ISI,ITI,stimFormat,button1,keyboard,key,responseWindow,randomBlock,presTime,head,responseType,randomPick,responseOptions,pageBreak,required,if.,then,ITI_ms,ITI_f,ITI_fDuration,presTime_ms,presTime_f,presTime_fDuration,RTkeys,responseCode))
tbl_all_counting <- tbl_all_counting[(tbl_all_counting$ID %in% tbl_all_cog_style_condensed_rts_median$ID),]
tbl_all_counting <- cbind(tbl_all_counting[c(TRUE, FALSE), ],tbl_all_counting[c(FALSE, TRUE), ])
tbl_all_counting = subset(tbl_all_counting, select = -c(3:5))
tbl_counts <- read_csv("./IB_stims/IB_counting.csv")
tbl_counts_comparison <- full_join(tbl_all_counting, tbl_counts, by = "stim1")
tbl_counts_comparison <- tbl_counts_comparison[complete.cases(tbl_counts_comparison), ]
tbl_counts_comparison$response <- as.numeric(tbl_counts_comparison$response)
tbl_counts_comparison$count <- as.numeric(tbl_counts_comparison$count)
tbl_counts_comparison$error <- (abs(tbl_counts_comparison$response - tbl_counts_comparison$count) / tbl_counts_comparison$count) * 100
tbl_counts_comparison %>%
ggbarplot("ID", "error", fill = "#f7a800", color = "#f7a800", ylim = c(0,150), font.xtickslab = 6, add = "mean_se", ylab = "Mean Error on Midline-crossings Task") + rotate_x_text()
tbl_counts_comparison_average <- tbl_counts_comparison %>%
group_by(ID) %>%
dplyr::summarize(mean_error = mean(error, na.rm=TRUE))
tbl_counts_comparison_average %>%
ggbarplot(y = "mean_error", fill = "#f7a800", color = "#f7a800", ylim = c(0,100), sort.val = c("asc") ,xlab = "Group", add = "mean_se", ylab = "Mean Error on Midline-crossings Task")
–>
tbl_all_notice <- tbl_all_IB %>%
filter(grepl('items', head))
table(tbl_all_notice$response)
##
## No Not sure Yes
## 23 14 20
tbl_all_event <- tbl_all_IB %>%
filter(grepl('moved', head))
tbl_all_event <- cbind.data.frame(tbl_all_event[1], tbl_all_event[6])
knitr::kable(tbl_all_event)
| ID | response |
|---|---|
| A2W02ACKYETLOA | some of letters were moving |
| A1969Q0R4Y0E3J | I am guessing one of those items were present and moved at a slower rate than others. |
| A270HX8LH9LJ8W | I didn’t consciously see one of those items. |
| A171RZ3O028XF6 | maybe the E or plus sign |
| AYFDUTHXE54I | I saw letters T L crossing a center line where as L is in white color. |
| A3IXWFXJC2YKU7 | The large X perhaps |
| A2OPYRV3GLAPS1 | I didn’t notice anything. |
| AD1WGUMVD6KED | I think there was a plus sign somewhere. |
| A1IQUHRI7G63YF | The plus sign appeared on the line |
| A2XQ3CFB5HT2ZQ | no idea |
| AMPMTF5IAAMK8 | an x moved on a horizontal line |
| A2HRUFTA09371Y | #NAME? |
| A3LT7W355XOAKF | x, only a guess, moved the same as the others |
| A17LF7GCAFYMSL | i saw a plus symbol moving from the right hands side to the left |
| A1SHLWKA0UH1IS | I did not notice it. |
| AM8OWAW9TUVLN | I just watched the white ones and forgot what they were |
| A1U4DNYKF6YUY3 | +, moved along the center horizontal line from the right to the left. |
| A3RHJEMZ4EGY2U | It seemed that something was moving faster but I have no idea what it was because I was busy trying to count. |
| A2HJDLSU95MH8Q | no idea, sorry |
| A15XIKX3PI7SLK | I did not notice any of the items. |
| A1YFVXP4A1CXSF | just the plus sign, I thought it stayed in the center |
| A3N0QZ9ZKUCTCQ | Plus sign, moving slowly right to left. |
| A2FOYHZ7HOFKBI | Didn’t see any of the items, I was too focused on the white letters |
| A1W7I6FN183I8F | I did not see those letters/equation appear at all while I was counting. |
| A1P3HHEXWNLJMP | I did not notice it at all. |
| A1JR35HATOEME9 | They moved slower |
| ACKG8OU1KHKO2 | plus sign moved on the left side on the line. |
| AEQ6KLNVTRKKR | The addition sign was moving from right to left across the line in the middle of the screen. |
| AD21ES5UMD77U | I did not see any of the previous items |
| A2OX8TSRCU6NKD | I did not see anything different but if there was my guess was it didn’t move |
| A1N0Q3QP4OMTZ2 | It moved right on the center line, and it was the third image (grey cross). |
| A2I6ZALE49CVSC | It just moved across the screen |
| A279YSE7NB16M0 | no |
| AONN1W54VC8YD | The + symbol moved to left, along the line. |
| A198MSVO1VTAT5 | I didn’t notice it at all. I was watching the L T. |
| A2K287FPB9YFIE | I didn’t pay attention to the dark symbols. |
| A3APKUC67F9IMW | I’m sure I saw crosses but not in the dimensions or rotation that you have there. You got me worried when you hit me right in the gut immediately. |
| A314XJY8V1YL12 | I’m not sure, the T’s and L’s seemed to move in a circle or wave pattern. |
| A22VZZFOP9D3GC | x |
| A2U3H5KUYAQN24 | nope |
| A1QKIA8XRNEXIG | I’m not sure, I didn’t notice any unusual items in the animation |
| A1ROEDVMTO9Y3X | no |
| A1O0BGHFTMPQM0 | DIDN’T NOTICE IT |
| A348NEQKS6VNIB | I saw the x on the screen in the last trial. |
| A3EC3OP6U52JYC | I saw a gray cross move from right to left across the middle of the screen. |
| AKVDK30EEV08C | I didn’t notice anything different. |
| A31JM9RECQGYEX | none of them were present |
| A297OTX4PW0XS3 | The plus symbol moved along the line from one side to the other. |
| AP4FDDWBJW47O | None |
| A2R75YFKVALBXE | Didn’t see it. |
| AFIK3VBMMX6G6 | plus sign, right to left |
| AQN3WMCEA96DQ | I was only paying attention to the white figures. Maybe an X crossed the screen though. just a guess |
| A1Q4ZOXZ0Y7K6I | I saw a gray plus shape moving from right to left on the line |
| A3OP24TYKA619W | i did not see it. too busy concentrating |
| A2POU9TTW177VH | I did not see it |
| A37BGU8FSIP4I6 | T L |
| A2ZDEERVRN5AMC | I was too focused on the purple line. |
tbl_all_expecting <- tbl_all %>%
filter(grepl('Before', head))
tbl_all_expecting = subset(tbl_all_expecting, select = -c(stim1,ITI,ISI,presTime,if.,then,presTime_ms,presTime_f,presTime_fDuration,RTkeys,correct,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
tbl_all_expecting <- tbl_all_expecting[(tbl_all_expecting$ID %in% tbl_all_cog_style_condensed_rts_median$ID),]
table(tbl_all_expecting$response)
##
## No Yes
## 52 5
tbl_all_familiarity <- tbl_all %>%
filter(grepl('gorilla', head))
tbl_all_familiarity = subset(tbl_all_familiarity, select = -c(stim1,ITI,ISI,presTime,if.,then,presTime_ms,presTime_f,presTime_fDuration,RTkeys,correct,stimFormat,button1,keyboard,key,responseWindow,randomBlock,responseType,randomPick,responseOptions,pageBreak,required,ITI_ms,ITI_f,ITI_fDuration,responseCode))
tbl_all_familiarity <- tbl_all_familiarity[(tbl_all_familiarity$ID %in% tbl_all_cog_style_condensed_rts_median$ID),]
table(tbl_all_familiarity$response)
##
## No Yes
## 42 15
tbl_log_reg <- merge(tbl_all_cog_style_condensed_rts_median, tbl_all_notice, by = "ID")
tbl_log_reg = subset(tbl_log_reg, select = -c(rowNo,type,head,timestamp,RT))
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_ratio <- glm(notice ~ ratio, data = tbl_log_reg, family = binomial(link = "logit"))
summary(log_reg_ratio)
##
## Call:
## glm(formula = notice ~ ratio, family = binomial(link = "logit"),
## data = tbl_log_reg)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.9921 -0.9401 -0.9034 1.4096 1.5846
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.1856 1.1899 -0.156 0.876
## ratio -0.2355 0.6369 -0.370 0.712
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 73.871 on 56 degrees of freedom
## Residual deviance: 73.732 on 55 degrees of freedom
## AIC: 77.732
##
## Number of Fisher Scoring iterations: 4
plot <- ggplot(tbl_log_reg, aes(x=ratio, y=notice)) + xlim(1,4) + geom_point() + stat_smooth(method="glm", method.args=list(family="binomial"), se=TRUE, color="#f7a800") + theme_classic((base_size = 15))
suppressMessages(print(plot))
Does not work because there are no ‘wholists’
#log_reg_style <- glm(notice ~ style, data = tbl_log_reg, family = binomial)
#summary(log_reg_style)