Set up R environment
library(tidyverse)
library(ggplot2)
library(ggpubr)
library(plyr)
library(magick)
library(png)
library(EBImage)
library(lme4)
library(lmerTest)
Set the R working drectory to the main experiment directory.
setwd("/Users/adambarnas/Box/MetaAwareness/data/")
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))
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] 3.017315
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")
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)
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 6
## 2 image-002 7
## 3 image-003 11
## 4 image-004 14
## 5 image-005 5
## 6 image-006 8
## 7 image-007 12
## 8 image-008 6
## 9 image-009 7
## 10 image-010 9
## 11 image-011 6
## 12 image-012 7
## 13 image-013 6
## 14 image-014 8
## 15 image-015 5
## 16 image-016 4
## 17 image-017 2
## 18 image-018 6
## 19 image-019 6
## 20 image-020 8
## 21 image-021 2
## 22 image-023 4
## 23 image-024 3
## 24 image-025 9
## 25 image-026 11
## 26 image-028 6
## 27 image-029 6
## 28 image-030 4
## 29 image-031 5
## 30 image-032 5
## 31 image-033 6
## 32 image-034 6
## 33 image-037 6
## 34 image-038 2
## 35 image-039 5
## 36 image-040 8
## 37 image-041 1
## 38 image-042 4
## 39 image-043 8
## 40 image-044 2
## 41 image-045 5
## 42 image-046 5
## 43 image-047 4
## 44 image-048 1
## 45 image-049 5
## 46 image-050 8
## 47 image-076 4
## 48 image-077 7
## 49 image-078 6
## 50 image-079 9
## 51 image-080 6
## 52 image-081 6
## 53 image-082 7
## 54 image-083 5
## 55 image-084 3
## 56 image-085 4
## 57 image-086 6
## 58 image-087 6
## 59 image-088 9
## 60 image-089 7
## 61 image-090 4
## 62 image-091 2
## 63 image-092 8
## 64 image-093 4
## 65 image-094 10
## 66 image-095 10
## 67 image-096 3
## 68 image-097 7
## 69 image-098 6
## 70 image-099 11
## 71 image-100 2
## 72 image-101 11
## 73 image-102 2
## 74 image-103 4
## 75 image-104 2
## 76 image-105 5
## 77 image-106 6
## 78 image-107 8
## 79 image-108 8
## 80 image-109 3
## 81 image-110 4
## 82 image-111 8
## 83 image-112 5
## 84 image-113 5
## 85 image-114 4
## 86 image-115 8
## 87 image-117 12
## 88 image-118 5
## 89 image-119 13
## 90 image-120 8
## 91 image-121 8
## 92 image-122 10
## 93 image-123 3
## 94 image-124 3
## 95 image-125 7
## 96 image-126 5
## 97 image-127 6
## 98 image-128 5
## 99 image-129 3
## 100 image-130 3
## 101 image-131 2
## 102 image-132 3
## 103 image-133 9
## 104 image-134 5
## 105 image-135 10
## 106 image-136 7
## 107 image-137 7
## 108 sum 643
Mixed effects model and correlation.
fit0 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image), 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)
## Data: wolfe1_RTs_likelihood_no_NA
##
## REML criterion at convergence: 3884.9
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.0053 -0.4845 -0.1682 0.1371 7.1142
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 1.197 1.094
## workerId (Intercept) 4.209 2.052
## Residual 21.937 4.684
## Number of obs: 643, groups: image, 107; workerId, 28
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 11.5243 0.7052 136.6586 16.343 < 2e-16 ***
## likelihood_rating -0.5193 0.1747 435.0807 -2.972 0.00312 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## liklhd_rtng -0.771
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 = 28", 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, 25))
