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 data files.

Rensink_RTs_likelihood_no_NA <- read_csv("Rensink_RTs_likelihood_no_NA.csv")
Ma_RTs_likelihood_no_NA <- read_csv("Ma_RTs_likelihood_no_NA.csv")
Wolfe1_RTs_likelihood_no_NA <- read_csv("Wolfe1_RTs_likelihood_no_NA.csv")

tbl_all <- rbind(Rensink_RTs_likelihood_no_NA, Ma_RTs_likelihood_no_NA, Wolfe1_RTs_likelihood_no_NA)

4 Compute average likelihood rating.

tbl_all_subj_avg <- tbl_all %>%
  group_by(workerId,image) %>%
  dplyr::summarize(average = mean(likelihood_rating)) %>%
  spread(image,average) %>% 
  mutate(subj_avg = rowMeans(.[-1], na.rm = TRUE))
mean(tbl_all_subj_avg$subj_avg)
## [1] 3.194087

5 Mixed effects model and correlation.

fit0 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) + (1 | stim_set), data=tbl_all)
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 | stim_set)
##    Data: tbl_all
## 
## REML criterion at convergence: 10459.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7638 -0.4079 -0.1171  0.1196  8.9564 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept)  1.3459  1.160   
##  workerId (Intercept)  7.3509  2.711   
##  stim_set (Intercept)  0.7992  0.894   
##  Residual             20.2159  4.496   
## Number of obs: 1746, groups:  image, 227; workerId, 73; stim_set, 3
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)         10.24440    0.70803    3.23223  14.469 0.000476 ***
## likelihood_rating   -0.29557    0.09915 1069.56265  -2.981 0.002937 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.454
corr <- tbl_all %>% 
  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", 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))

Dropping image-116 (Wolfe1) from the analyses. Obvious outlier.

tbl_all_no_outlier <- tbl_all %>% 
  filter(image != "image-116")

fit1 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image), data=tbl_all_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)
##    Data: tbl_all_no_outlier
## 
## REML criterion at convergence: 10414.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8025 -0.4157 -0.1179  0.1248  9.0539 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  image    (Intercept)  1.272   1.128   
##  workerId (Intercept)  7.614   2.759   
##  Residual             19.780   4.448   
## Number of obs: 1745, groups:  image, 226; workerId, 73
## 
## Fixed effects:
##                    Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)         10.5461     0.4708  223.1123  22.400  < 2e-16 ***
## likelihood_rating   -0.3314     0.0979 1084.1990  -3.385 0.000737 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## liklhd_rtng -0.664
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))