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 = "./Wolfe1_Recontact", pattern = "*.csv", full.names = T, ignore.case = F) %>%
  map_df(~read.csv(., colClasses=c("gender..m.f."="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 = "([\\_])")
tbl_all$image <- lapply(tbl_all$image, gsub, pattern='-a', 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.999677
tbl_all_img_avg <- data.frame(img_avg = colMeans(tbl_all_subj_avg[,2:112], na.rm = TRUE))
tbl_all_img_avg <- tibble::rownames_to_column(tbl_all_img_avg, "image")

5 Merge Mudsplash and Meta-Awareness data files.

wolfe1_RTs_raw <- read_csv("wolfe1_RTs_raw.csv")
wolfe1_RTs_raw <- wolfe1_RTs_raw[, -c(2,3,6:16,18,19)]
wolfe1_RTs_raw <- wolfe1_RTs_raw[(wolfe1_RTs_raw$workerId %in% tbl_all_subj_avg$workerId),]

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

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

6 Add change_type to dataframe.

wolfe1_change_type<- read_csv("Wolfe1_change_type.csv")
wolfe1_RTs_likelihood <- left_join(wolfe1_RTs_likelihood, wolfe1_change_type, by = "image")

7 Compute likelihood rating for each image.

wolfe1_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 = 4, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

wolfe1_RTs_likelihood_no_NA <- wolfe1_RTs_likelihood %>%
  drop_na()
wolfe1_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 = 4, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

write.csv(wolfe1_RTs_likelihood,'Wolfe1_RTs_likelihood.csv', row.names=FALSE)
write.csv(wolfe1_RTs_likelihood_no_NA,'Wolfe1_RTs_likelihood_no_NA.csv', row.names=FALSE)

8 Count number of ratings

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

wolfe1_RTs_likelihood_count <- data.frame(count = colSums(wolfe1_RTs_likelihood_count[,2:109], na.rm = TRUE))
wolfe1_RTs_likelihood_count <- tibble::rownames_to_column(wolfe1_RTs_likelihood_count, "image")
wolfe1_RTs_likelihood_count
##         image count
## 1   image-001    15
## 2   image-002     9
## 3   image-003    12
## 4   image-004    15
## 5   image-005     7
## 6   image-006    10
## 7   image-007    15
## 8   image-008    11
## 9   image-009    11
## 10  image-010    16
## 11  image-011    10
## 12  image-012     9
## 13  image-013     8
## 14  image-014    13
## 15  image-015    10
## 16  image-016     8
## 17  image-017     4
## 18  image-018     8
## 19  image-019    15
## 20  image-020    12
## 21  image-021     9
## 22  image-022     5
## 23  image-023     6
## 24  image-024     7
## 25  image-025    11
## 26  image-026    16
## 27  image-027     2
## 28  image-028    12
## 29  image-029    11
## 30  image-030     7
## 31  image-031     7
## 32  image-032     9
## 33  image-033    10
## 34  image-034    11
## 35  image-035     1
## 36  image-037    11
## 37  image-038     4
## 38  image-039    11
## 39  image-040    13
## 40  image-041     8
## 41  image-042     7
## 42  image-043    12
## 43  image-044     5
## 44  image-045     9
## 45  image-046     8
## 46  image-047     8
## 47  image-048     3
## 48  image-049    10
## 49  image-050    12
## 50  image-076     7
## 51  image-077     9
## 52  image-078    10
## 53  image-079    11
## 54  image-080    10
## 55  image-081     8
## 56  image-082    12
## 57  image-083     9
## 58  image-084     7
## 59  image-085     6
## 60  image-086     7
## 61  image-087    10
## 62  image-088    12
## 63  image-089    10
## 64  image-090     9
## 65  image-091     5
## 66  image-092    14
## 67  image-093     9
## 68  image-094    13
## 69  image-095    14
## 70  image-096     7
## 71  image-097    10
## 72  image-098     8
## 73  image-099    16
## 74  image-100     7
## 75  image-101    14
## 76  image-102     3
## 77  image-103     9
## 78  image-104     5
## 79  image-105     9
## 80  image-106    12
## 81  image-107    13
## 82  image-108    13
## 83  image-109     8
## 84  image-110    11
## 85  image-111    12
## 86  image-112     9
## 87  image-113    12
## 88  image-114    10
## 89  image-115    11
## 90  image-116     2
## 91  image-117    17
## 92  image-118     6
## 93  image-119    19
## 94  image-120    14
## 95  image-121     9
## 96  image-122    17
## 97  image-123     8
## 98  image-124     7
## 99  image-125    11
## 100 image-126    11
## 101 image-127     8
## 102 image-128     8
## 103 image-129     5
## 104 image-130     9
## 105 image-131     7
## 106 image-132     8
## 107 image-133    11
## 108 image-134    10

9 Mixed effects model and correlation.

fit0 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) + (1 | change_type), data=wolfe1_RTs_likelihood_no_NA)
summary(fit0)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) +  
##     (1 | change_type)
##    Data: wolfe1_RTs_likelihood_no_NA
## 
## REML criterion at convergence: 7065
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9559 -0.4648 -0.1640  0.1439  6.6972 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  image       (Intercept)  3.0303  1.7408  
##  workerId    (Intercept)  8.5664  2.9268  
##  change_type (Intercept)  0.7592  0.8713  
##  Residual                35.2588  5.9379  
## Number of obs: 1080, groups:  image, 111; workerId, 47; change_type, 2
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        12.2270     0.9630   4.2979  12.697 0.000143 ***
## likelihood_rating  -0.4735     0.1755 735.8717  -2.699 0.007124 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.568
corr <- wolfe1_RTs_likelihood_no_NA %>% 
  group_by(image) %>% 
  dplyr::summarize(detection_rt = mean(detection_rt), likelihood_rating = mean(likelihood_rating))
corr %>%
  ggscatter(y = "detection_rt", x = "likelihood_rating", ylab = "Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 47", fill = "#f7a800", color = "#f7a800", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 5, label.sep = "\n"), xlim = c(1, 5), ylim = c(0, 50), label = "image", font.label = c(5, "plain", "black"))

Here, I am dropping image-116 from the analyses. It is clearly an outlier and has only one meta-awareness rating.

wolfe1_RTs_likelihood_no_NA_no_outlier <- wolfe1_RTs_likelihood_no_NA %>% 
  filter(image != "image-116")

fit1 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) + (1 | change_type), data=wolfe1_RTs_likelihood_no_NA_no_outlier)
summary(fit1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) +  
##     (1 | change_type)
##    Data: wolfe1_RTs_likelihood_no_NA_no_outlier
## 
## REML criterion at convergence: 7019.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.0054 -0.4670 -0.1655  0.1408  6.8007 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  image       (Intercept)  2.4015  1.5497  
##  workerId    (Intercept)  8.2192  2.8669  
##  change_type (Intercept)  0.5611  0.7491  
##  Residual                34.5400  5.8771  
## Number of obs: 1078, groups:  image, 110; workerId, 47; change_type, 2
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        12.3799     0.8951   5.4951  13.830 1.77e-05 ***
## likelihood_rating  -0.5447     0.1717 725.0270  -3.173  0.00157 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.598
corr %>%
  filter(image!="image-116") %>% 
  ggscatter(y = "detection_rt", x = "likelihood_rating", ylab = "Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 37", fill = "#f7a800", color = "#f7a800", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 5, label.sep = "\n"), xlim = c(1, 5), ylim = c(0, 40))