1 Set up R environment

library(tidyverse)
library(ggplot2)
library(ggpubr)
library(plyr)

Set the R working drectory to the main experiment directory.

setwd("/Users/adambarnas/Box/CogStyles_IB")  

2 Read-in datafiles

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] 18

3 Cognitive Styles

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))

3.1 Analyze accuracy

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
    }
  }
  }
}

3.2 Plot accuracy

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 = 15.597, df = 17, p-value = 8.324e-12
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
##  0.8319395       Inf
## sample estimates:
## mean of x 
## 0.8736111
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 = 14.77, df = 17, p-value = 1.978e-11
## alternative hypothesis: true mean is greater than 0.5
## 95 percent confidence interval:
##  0.8014245       Inf
## sample estimates:
## mean of x 
## 0.8416667
tbl_all_cog_style_acc %>% 
  with(t.test(rate~task,paired=TRUE))
## 
##  Paired t-test
## 
## data:  rate by task
## t = 1.2023, df = 17, p-value = 0.2457
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.02411098  0.08799987
## sample estimates:
## mean of the differences 
##              0.03194444

3.3 Plot RTs

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.9182, df = 17, p-value = 0.001107
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2848.1293  -854.4262
## sample estimates:
## mean of the differences 
##               -1851.278

3.4 Compute cognitive style ratio

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 
##       15        3

4 IB performance

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))

4.1 Noticers vs. Non-noticers

tbl_all_notice <- tbl_all_IB %>% 
  filter(grepl('items', head))
table(tbl_all_notice$response)
## 
##       No Not sure      Yes 
##        4        3       11

4.2 Unexpected event description

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
205396 it was the plus sign (+) and it moved from the right hand side towards the left hand side of the screen.
205204 I noticed the plus sign moving across the screen. It moved from right to left across the center line.
205060 the plus sign, moved from right to left, down the horizontal line
205420 the + moves horizontally passing the center of the box.
205255 I feel like I saw the + a few times but did not pay attention to its movement
205189 Plus sign horizontally
205057 I might have seen a + sign but I don’t really remember.
204988 I think I saw + but I am not sure how it moved.
205315 Ts and Ls
205408 +
205051 n/a
204949 The cross on the right.
205306 I’m not sure, but the + might have moved with the letters.
205084 I didn’t see anything unusual
205324 I have no idea. Maybe the black letters were erased so we only had to focus on the white letters.
205225 the middle, plus sign
205429 The cross moved horizontally along the line that the letters were crossing.
205432 X

5 Post IB questions

5.1 Expecting an unexpected event

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 
##  14   4

5.2 Familiarity with IB experiments

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 
##   4  14

6 Cognitive style ratio predicting IB

6.1 Logistic regression (Continuous predictor, dichotomous outcome)

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.0053  -1.1672   0.6951   0.9812   1.2756  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.6924     1.0666  -0.649    0.516
## ratio         0.5755     0.4983   1.155    0.248
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 24.057  on 17  degrees of freedom
## Residual deviance: 22.537  on 16  degrees of freedom
## AIC: 26.537
## 
## Number of Fisher Scoring iterations: 4

6.2 Plot

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))