library(tidyverse)
library(ggplot2)
library(ggpubr)
library(plyr)
library(magick)
library(png)
library(EBImage)
library(lme4)
library(lmerTest)
setwd("/Users/adambarnas/Box/MetaAwareness/data/")
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))
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.968058
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")
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)]
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)
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 9
## 2 image-002 9
## 3 image-003 11
## 4 image-004 15
## 5 image-005 6
## 6 image-006 8
## 7 image-007 13
## 8 image-008 7
## 9 image-009 9
## 10 image-010 10
## 11 image-011 9
## 12 image-012 8
## 13 image-013 8
## 14 image-014 10
## 15 image-015 8
## 16 image-016 6
## 17 image-017 2
## 18 image-018 6
## 19 image-019 9
## 20 image-020 11
## 21 image-021 5
## 22 image-022 3
## 23 image-023 5
## 24 image-024 6
## 25 image-025 10
## 26 image-026 15
## 27 image-027 1
## 28 image-028 9
## 29 image-029 8
## 30 image-030 5
## 31 image-031 7
## 32 image-032 8
## 33 image-033 8
## 34 image-034 9
## 35 image-037 8
## 36 image-038 3
## 37 image-039 9
## 38 image-040 11
## 39 image-041 6
## 40 image-042 5
## 41 image-043 10
## 42 image-044 4
## 43 image-045 7
## 44 image-046 7
## 45 image-047 7
## 46 image-048 2
## 47 image-049 7
## 48 image-050 10
## 49 image-076 6
## 50 image-077 8
## 51 image-078 8
## 52 image-079 10
## 53 image-080 8
## 54 image-081 6
## 55 image-082 9
## 56 image-083 6
## 57 image-084 5
## 58 image-085 5
## 59 image-086 6
## 60 image-087 7
## 61 image-088 10
## 62 image-089 8
## 63 image-090 4
## 64 image-091 4
## 65 image-092 10
## 66 image-093 7
## 67 image-094 12
## 68 image-095 13
## 69 image-096 5
## 70 image-097 8
## 71 image-098 8
## 72 image-099 13
## 73 image-100 4
## 74 image-101 13
## 75 image-102 3
## 76 image-103 8
## 77 image-104 2
## 78 image-105 6
## 79 image-106 11
## 80 image-107 10
## 81 image-108 11
## 82 image-109 5
## 83 image-110 8
## 84 image-111 9
## 85 image-112 8
## 86 image-113 7
## 87 image-114 7
## 88 image-115 10
## 89 image-116 1
## 90 image-117 14
## 91 image-118 5
## 92 image-119 15
## 93 image-120 11
## 94 image-121 8
## 95 image-122 13
## 96 image-123 7
## 97 image-124 4
## 98 image-125 9
## 99 image-126 8
## 100 image-127 8
## 101 image-128 7
## 102 image-129 4
## 103 image-130 6
## 104 image-131 4
## 105 image-132 5
## 106 image-133 11
## 107 image-134 8
## 108 image-135 13
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: 5413.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.3120 -0.4697 -0.1544 0.1360 6.1342
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 2.119 1.456
## workerId (Intercept) 7.494 2.738
## Residual 28.446 5.334
## Number of obs: 856, groups: image, 110; workerId, 37
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 11.9361 0.7468 150.1841 15.984 < 2e-16 ***
## likelihood_rating -0.5099 0.1784 583.3508 -2.859 0.00441 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## liklhd_rtng -0.729
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 = 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, 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), 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)
## Data: wolfe1_RTs_likelihood_no_NA_no_outlier
##
## REML criterion at convergence: 5376.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.3614 -0.4794 -0.1617 0.1397 6.2208
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 1.89 1.375
## workerId (Intercept) 7.16 2.676
## Residual 27.58 5.251
## Number of obs: 855, groups: image, 109; workerId, 37
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 12.0919 0.7307 150.8948 16.547 < 2e-16 ***
## likelihood_rating -0.5797 0.1751 588.1881 -3.311 0.000988 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## liklhd_rtng -0.731
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))