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.915882
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)]
wolfe2_RTs_likelihood$stim_set = "wolfe2"

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

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: 11005.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5397 -0.4535 -0.1316  0.1687  8.0509 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept)  1.789   1.337   
##  workerId (Intercept)  8.783   2.964   
##  Residual             18.436   4.294   
## Number of obs: 1856, groups:  image, 252; workerId, 85
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        11.0773     0.4652 248.7069  23.812  < 2e-16 ***
## likelihood_rating  -0.4184     0.1020 940.3462  -4.103 4.43e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.654
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 = 85", 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: -2094.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6203 -0.5805 -0.1284  0.3469  4.4287 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept) 0.001855 0.04307 
##  workerId (Intercept) 0.012554 0.11205 
##  Residual             0.015189 0.12324 
## Number of obs: 1856, groups:  image, 252; workerId, 85
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)          0.98894    0.01575  191.03118  62.781  < 2e-16 ***
## likelihood_rating   -0.01229    0.00302 1000.13027  -4.071 5.06e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.572
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 = 85", 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"))