1 Set up R environment.

library(tidyverse)
library(ggplot2)
library(ggpubr)
library(plyr)
library(magick)
library(png)
library(EBImage)
library(lme4)
library(lmerTest)

2 Set the R working drectory to the main experiment directory.

setwd("/Users/adambarnas/Box/MetaAwareness/data/")  

3 Read in the individual subject files.

tbl_all <- list.files(path = "./Wolfe2_Recontact", pattern = "*.csv", full.names = T, ignore.case = F) %>%
  map_df(~read.csv(., colClasses=c("gender..m.f."="character", "a"="character", "tp_a"="character")))
tbl_all = subset(tbl_all, select = c(user_resp.keys,user_resp.rt,workerId,image_a))
col_idx <- grep("workerId", names(tbl_all))
tbl_all <- tbl_all[, c(col_idx, (1:ncol(tbl_all))[-col_idx])]
tbl_all <- data.frame(na.omit(tbl_all))
tbl_all <- tbl_all %>%
separate(image_a,into=c('database', 'image'), sep = "([\\_])", extra = "merge")
tbl_all$image <- lapply(tbl_all$image, gsub, pattern='-a_w_outline.jpg', replacement='')
tbl_all <- tbl_all %>%  
    mutate(image = as.character(image))

4 Compute average likelihood rating.

tbl_all_subj_avg <- tbl_all %>%
  group_by(workerId,image) %>%
  dplyr::summarize(average = mean(user_resp.keys)) %>%
  spread(image,average) %>% 
  mutate(subj_avg = rowMeans(.[-1], na.rm = TRUE))
mean(tbl_all_subj_avg$subj_avg)
## [1] 2.939906
tbl_all_img_avg <- data.frame(img_avg = colMeans(tbl_all_subj_avg[,2:255], na.rm = TRUE))
tbl_all_img_avg <- tibble::rownames_to_column(tbl_all_img_avg, "image")

5 Merge Mudsplash and Meta-Awareness data files.

wolfe2_RTs_raw <- read_csv("wolfe2_RTs_raw.csv")
wolfe2_RTs_raw <- wolfe2_RTs_raw[, -c(2,3,6:17,19:21)]
wolfe2_RTs_raw <- wolfe2_RTs_raw[(wolfe2_RTs_raw$workerId %in% tbl_all_subj_avg$workerId),]

tbl_all <- tbl_all[order(tbl_all$workerId, tbl_all$image), , drop = FALSE]
wolfe2_RTs_raw <- wolfe2_RTs_raw[order(wolfe2_RTs_raw$workerId, wolfe2_RTs_raw$image), , drop = FALSE]
wolfe2_RTs_raw <- wolfe2_RTs_raw %>%  
    mutate(image = as.character(image))

wolfe2_RTs_likelihood <- left_join(tbl_all, wolfe2_RTs_raw, by = c("workerId", "image"))
colnames(wolfe2_RTs_likelihood)[2] <- "likelihood_rating"
colnames(wolfe2_RTs_likelihood)[3] <- "likelihood_rt"
colnames(wolfe2_RTs_likelihood)[7] <- "detection_rt"
wolfe2_RTs_likelihood <- wolfe2_RTs_likelihood[, c(-4)]
colnames(wolfe2_RTs_likelihood)[5] <- "stim_set"
wolfe2_RTs_likelihood <- wolfe2_RTs_likelihood[,c(1,4,5,6,2,3)]

6 Add change_type to dataframe.

wolfe2_change_type<- read_csv("wolfe2_change_type.csv")
wolfe2_RTs_likelihood <- left_join(wolfe2_RTs_likelihood, wolfe2_change_type, by = "image")

7 Compute likelihood rating for each image.

wolfe2_RTs_likelihood %>%
  ggbarplot(x = "image", y = "likelihood_rating", ylab = "Likelihood of Detecting Change", title = "All images (30 per subject)", fill = "#f7a800", add = "mean_se", font.xtickslab = 2, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

wolfe2_RTs_likelihood_no_NA <- wolfe2_RTs_likelihood %>%
  drop_na()
wolfe2_RTs_likelihood_no_NA %>% 
  ggbarplot(x = "image", y = "likelihood_rating", ylab = "Likelihood of Detecting Change", title = "'Correct' images", fill = "#f7a800", add = "mean_se", font.xtickslab = 2, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

write.csv(wolfe2_RTs_likelihood,'Wolfe2_RTs_likelihood.csv', row.names=FALSE)
write.csv(wolfe2_RTs_likelihood_no_NA,'Wolfe2_RTs_likelihood_no_NA.csv', row.names=FALSE)

8 Count number of ratings.

wolfe2_RTs_likelihood_count <- wolfe2_RTs_likelihood_no_NA %>% 
  group_by(workerId,image) %>% 
  dplyr::summarize(counts = n()) %>%
  spread(image,counts) %>%
  mutate(sum = rowSums(.[-1], na.rm = TRUE))
#head(tbl_all_counts,10)

wolfe2_RTs_likelihood_count <- data.frame(count = colSums(wolfe2_RTs_likelihood_count[,2:252], na.rm = TRUE))
wolfe2_RTs_likelihood_count <- tibble::rownames_to_column(wolfe2_RTs_likelihood_count, "image")
wolfe2_RTs_likelihood_count
##                    image count
## 1           001_L_mirror     5
## 2           001_R_mirror     8
## 3           002_L_napkin     7
## 4           002_R_napkin     5
## 5            003_L_ducks     4
## 6            003_R_ducks     7
## 7   004_L_electricalgrid     3
## 8   004_R_electricalgrid    11
## 9           005_L_mirror     6
## 10          005_R_mirror     9
## 11            006_L_vase     5
## 12            006_R_vase     6
## 13            007_L_soap     4
## 14            007_R_soap    10
## 15          008_L_bottle     5
## 16          008_R_bottle    10
## 17          009_L_carpet     5
## 18          009_R_carpet     9
## 19          010_L_candle     2
## 20          010_R_candle     2
## 21          011_L_parfum     5
## 22          011_R_parfum     9
## 23     012_L_tubaccesory     3
## 24     012_R_tubaccesory     6
## 25            013_L_lamp     5
## 26            013_R_lamp     6
## 27            014_L_lamp     5
## 28            014_R_lamp    12
## 29    015_L_ceilinglight     1
## 30    015_R_ceilinglight     2
## 31             016_L_art     6
## 32             016_R_art    11
## 33            017_L_wood     3
## 34            017_R_wood     3
## 35           018_L_plant     7
## 36           018_R_plant    11
## 37      019_L_lamp_sized     8
## 38      019_R_lamp_sized     6
## 39        020_L_walldeco     7
## 40        020_R_walldeco     7
## 41        021_L_keyboard     7
## 42        021_R_keyboard     7
## 43            022_L_lamp     5
## 44            022_R_lamp     5
## 45          023_L_remote     3
## 46          023_R_remote     7
## 47          024_L_towels     6
## 48          024_R_towels     8
## 49            025_L_vase     3
## 50            025_R_vase     8
## 51            026_L_rack     5
## 52            026_R_rack     7
## 53        027_L_soapdish     4
## 54        027_R_soapdish     6
## 55            028_L_vase     6
## 56            028_R_vase     4
## 57           029_L_glass     4
## 58           029_R_glass     8
## 59          030_L_drawer     5
## 60          030_R_drawer     8
## 61             031_L_log     3
## 62             031_R_log     5
## 63          032_L_bottle     7
## 64          032_R_bottle     3
## 65            033_L_vase     4
## 66            033_R_vase    11
## 67          034_L_handle     2
## 68          034_R_handle     5
## 69           035_L_fruit     3
## 70           035_R_fruit     3
## 71            036_L_bowl     3
## 72            036_R_bowl     6
## 73           037_R_towel     4
## 74             038_L_art     5
## 75             038_R_art     9
## 76      039_L_ventilator     1
## 77      039_R_ventilator     7
## 78        040_L_painting     6
## 79        040_R_painting     8
## 80           041_L_fruit     2
## 81           041_R_fruit     3
## 82             042_L_tap     3
## 83             042_R_tap     5
## 84           043_L_clock     6
## 85           043_R_clock    10
## 86           044_L_light     8
## 87           044_R_light     9
## 88       045_L_musicdock     5
## 89       045_R_musicdock     8
## 90          046_L_remote     3
## 91          046_R_remote    12
## 92          047_L_handle     5
## 93          047_R_handle     8
## 94             048_L_art     4
## 95             048_R_art     7
## 96        049_L_painting     7
## 97        049_R_painting    12
## 98            050_L_book     6
## 99            050_R_book     7
## 100            051_L_owl     8
## 101            051_R_owl    10
## 102        052_L_speaker     2
## 103        052_R_speaker     6
## 104         053_L_handle     1
## 105         053_R_handle     3
## 106       054_L_firewood     5
## 107       054_R_firewood    10
## 108         055_R_carpet     1
## 109      056_L_comforter     7
## 110      056_R_comforter     9
## 111            057_L_bin     4
## 112            057_R_bin    10
## 113         058_L_clutch     6
## 114         058_R_clutch     8
## 115            059_L_car     6
## 116            059_R_car     2
## 117         060_L_pillow     8
## 118         060_R_pillow     9
## 119          061_L_glass     6
## 120          061_R_glass     6
## 121        062_L_flowers     6
## 122        062_R_flowers    13
## 123         063_L_laptop     2
## 124         063_R_laptop     3
## 125        064_L_bottles     8
## 126        064_R_bottles     7
## 127             065_L_cd     5
## 128             065_R_cd    11
## 129           066_L_vase     5
## 130           066_R_vase     7
## 131       067_L_painting     4
## 132       067_R_painting     6
## 133         068_L_faucet     7
## 134         068_R_faucet     9
## 135         069_L_things     7
## 136         069_R_things     5
## 137           070_L_lamp     7
## 138           070_R_lamp    11
## 139            071_L_art     5
## 140            071_R_art    19
## 141         072_L_handle     4
## 142         072_R_handle     6
## 143      073_L_coffeemug     4
## 144      073_R_coffeemug     8
## 145           074_L_book     7
## 146           074_R_book     9
## 147          075_L_light     4
## 148          075_R_light     5
## 149           076_L_hook     5
## 150           076_R_hook     4
## 151       077_R_footrest     8
## 152         078_L_faucet     1
## 153         078_R_faucet    10
## 154           079_L_bowl     3
## 155           079_R_bowl     6
## 156          080_L_plant     4
## 157          080_R_plant    13
## 158       081_L_football     3
## 159       081_R_football     4
## 160           082_L_bowl     6
## 161           082_R_bowl    11
## 162           083_L_knob     2
## 163           083_R_knob     4
## 164          084_L_light     5
## 165          084_R_light     9
## 166    085_L_switchboard     3
## 167    085_R_switchboard     7
## 168           086_L_book     4
## 169           086_R_book     8
## 170    087_L_towelhandle     5
## 171    087_R_towelhandle     8
## 172          088_L_clock     4
## 173          088_R_clock     2
## 174         089_L_poster     5
## 175         089_R_poster     7
## 176           090_L_lamp     4
## 177           090_R_lamp     5
## 178   091_L_airfreshener     4
## 179   091_R_airfreshener     3
## 180        092_L_candles     7
## 181        092_R_candles     9
## 182         093_L_switch     5
## 183         093_R_switch     7
## 184         095_L_candle     7
## 185         095_R_candle     6
## 186       096_L_painting     4
## 187       096_R_painting    10
## 188          097_L_light     6
## 189          097_R_light     7
## 190       098_L_slippers     7
## 191       098_R_slippers    12
## 192         099_L_sconce     8
## 193         099_R_sconce     9
## 194         100_L_mirror     4
## 195         100_R_mirror    13
## 196            101_L_cup     6
## 197            101_R_cup    11
## 198    102_L_shoppingbag     8
## 199    102_R_shoppingbag    12
## 200           103_L_hook     2
## 201           103_R_hook     2
## 202         104_L_bottle     5
## 203         104_R_bottle     9
## 204            105_L_hat     6
## 205            105_R_hat     6
## 206 106_L_toweldispenser     9
## 207 106_R_toweldispenser     8
## 208         107_L_shirts     4
## 209         107_R_shirts    13
## 210            108_L_boa     7
## 211            108_R_boa     9
## 212         109_L_pillow     5
## 213         109_R_pillow     7
## 214          110_L_plant     2
## 215          110_R_plant    10
## 216            111_L_pot     5
## 217            111_R_pot    11
## 218         112_L_basket     7
## 219         112_R_basket     9
## 220          113_L_plant     5
## 221          113_R_plant     6
## 222           114_L_bird     5
## 223           114_R_bird     9
## 224            115_L_pot     6
## 225            115_R_pot     6
## 226         116_L_basket     4
## 227         116_R_basket     7
## 228    117_L_plant_sized     4
## 229    117_R_plant_sized     4
## 230          118_L_shoes     6
## 231          118_R_shoes    10
## 232       119_L_painting     6
## 233       119_R_painting    11
## 234            120_L_art     4
## 235            120_R_art     7
## 236            121_L_car     5
## 237            121_R_car    10
## 238          122_L_chair     3
## 239          122_R_chair     5
## 240            123_L_pot     5
## 241            123_R_pot     6
## 242           124_L_vase     3
## 243           124_R_vase     7
## 244           125_L_sofa     6
## 245           125_R_sofa    10
## 246        126_L_candles     2
## 247        126_R_candles    10
## 248          127_L_light     4
## 249          127_R_light     7
## 250            128_L_pot     5
## 251            128_R_pot     3

9 Mixed effects model and correlation.

9.1 Raw RT

fit_raw <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image), data=wolfe2_RTs_likelihood_no_NA)
summary(fit_raw)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image)
##    Data: wolfe2_RTs_likelihood_no_NA
## 
## REML criterion at convergence: 9304.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5060 -0.4500 -0.1301  0.1555  7.8443 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept)  1.729   1.315   
##  workerId (Intercept)  9.621   3.102   
##  Residual             19.063   4.366   
## Number of obs: 1560, groups:  image, 251; workerId, 71
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        11.2254     0.5175 196.0359  21.694  < 2e-16 ***
## likelihood_rating  -0.4365     0.1103 847.2097  -3.957 8.23e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.640
corr <- wolfe2_RTs_likelihood_no_NA %>% 
  group_by(image) %>% 
  dplyr::summarize(detection_rt = mean(detection_rt), likelihood_rating = mean(likelihood_rating))

corr <- left_join(corr, wolfe2_change_type, by = "image")

corr %>%
  ggscatter(y = "detection_rt", x = "likelihood_rating", ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 71", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 25), conf.int = TRUE, xlim = c(1, 5), ylim = c(5, 30), label = "image", font.label = c(5, "plain", "black"))

9.2 Log RT

fit_log <- lmer(log10(detection_rt) ~ likelihood_rating + (1 | workerId) + (1 | image), data=wolfe2_RTs_likelihood_no_NA)
summary(fit_log)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: log10(detection_rt) ~ likelihood_rating + (1 | workerId) + (1 |  
##     image)
##    Data: wolfe2_RTs_likelihood_no_NA
## 
## REML criterion at convergence: -1736.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5938 -0.5823 -0.1239  0.3517  4.5944 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept) 0.00190  0.04359 
##  workerId (Intercept) 0.01368  0.11696 
##  Residual             0.01528  0.12361 
## Number of obs: 1560, groups:  image, 251; workerId, 71
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)         0.991814   0.017557 149.904302  56.492  < 2e-16 ***
## likelihood_rating  -0.012454   0.003245 900.959318  -3.838 0.000132 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.555
corr <- wolfe2_RTs_likelihood_no_NA %>% 
  group_by(image) %>% 
  dplyr::summarize(detection_rt = mean(detection_rt), likelihood_rating = mean(likelihood_rating))

corr <- left_join(corr, wolfe2_change_type, by = "image")

corr$log <- log10(corr$detection_rt)

corr %>%
  ggscatter(y = "log", x = "likelihood_rating", ylab = "Log Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 47", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 1.4), conf.int = TRUE, xlim = c(1, 5), ylim = c(0.75, 1.5), label = "image", font.label = c(5, "plain", "black"))