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.994363
tbl_all_img_avg <- data.frame(img_avg = colMeans(tbl_all_subj_avg[,2:113], 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$stim_set = "wolfe1"
wolfe1_change_type<- read_csv("Wolfe1_change_type.csv")
wolfe1_RTs_likelihood <- left_join(wolfe1_RTs_likelihood, wolfe1_change_type, by = "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)
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:112], 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 16
## 2 image-002 10
## 3 image-003 13
## 4 image-004 15
## 5 image-005 7
## 6 image-006 10
## 7 image-007 16
## 8 image-008 12
## 9 image-009 13
## 10 image-010 16
## 11 image-011 12
## 12 image-012 10
## 13 image-013 8
## 14 image-014 14
## 15 image-015 10
## 16 image-016 8
## 17 image-017 4
## 18 image-018 9
## 19 image-019 16
## 20 image-020 14
## 21 image-021 10
## 22 image-022 6
## 23 image-023 7
## 24 image-024 8
## 25 image-025 11
## 26 image-026 17
## 27 image-027 2
## 28 image-028 12
## 29 image-029 11
## 30 image-030 7
## 31 image-031 9
## 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 12
## 39 image-040 14
## 40 image-041 8
## 41 image-042 7
## 42 image-043 12
## 43 image-044 6
## 44 image-045 9
## 45 image-046 8
## 46 image-047 8
## 47 image-048 4
## 48 image-049 12
## 49 image-050 13
## 50 image-076 8
## 51 image-077 10
## 52 image-078 10
## 53 image-079 11
## 54 image-080 12
## 55 image-081 9
## 56 image-082 13
## 57 image-083 9
## 58 image-084 8
## 59 image-085 7
## 60 image-086 7
## 61 image-087 10
## 62 image-088 12
## 63 image-089 11
## 64 image-090 9
## 65 image-091 5
## 66 image-092 14
## 67 image-093 11
## 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 8
## 75 image-101 15
## 76 image-102 3
## 77 image-103 11
## 78 image-104 6
## 79 image-105 10
## 80 image-106 12
## 81 image-107 15
## 82 image-108 13
## 83 image-109 9
## 84 image-110 11
## 85 image-111 12
## 86 image-112 10
## 87 image-113 12
## 88 image-114 10
## 89 image-115 12
## 90 image-116 2
## 91 image-117 17
## 92 image-118 7
## 93 image-119 20
## 94 image-120 14
## 95 image-121 9
## 96 image-122 17
## 97 image-123 9
## 98 image-124 7
## 99 image-125 11
## 100 image-126 12
## 101 image-127 9
## 102 image-128 10
## 103 image-129 5
## 104 image-130 9
## 105 image-131 7
## 106 image-132 8
## 107 image-133 12
## 108 image-134 10
## 109 image-135 18
## 110 image-136 11
## 111 image-137 12
fit_raw <- lmer(detection_rt ~ likelihood_rating * change_type + (1 | workerId) + (1 | image), data=wolfe1_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 * change_type + (1 | workerId) +
## (1 | image)
## Data: wolfe1_RTs_likelihood_no_NA
##
## REML criterion at convergence: 7446
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9533 -0.4687 -0.1638 0.1513 6.7281
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 2.823 1.680
## workerId (Intercept) 8.930 2.988
## Residual 34.860 5.904
## Number of obs: 1141, groups: image, 111; workerId, 50
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 12.87387 0.84115 314.79585 15.305
## likelihood_rating -0.50469 0.21460 827.38563 -2.352
## change_typedisappear -1.29888 1.08364 514.75457 -1.199
## likelihood_rating:change_typedisappear 0.01888 0.30826 885.55157 0.061
## Pr(>|t|)
## (Intercept) <2e-16 ***
## likelihood_rating 0.0189 *
## change_typedisappear 0.2312
## likelihood_rating:change_typedisappear 0.9512
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lklhd_ chng_t
## liklhd_rtng -0.773
## chng_typdsp -0.517 0.519
## lklhd_rtn:_ 0.470 -0.606 -0.891
corr <- wolfe1_RTs_likelihood_no_NA %>%
group_by(image) %>%
dplyr::summarize(detection_rt = mean(detection_rt), likelihood_rating = mean(likelihood_rating))
corr <- left_join(corr, wolfe1_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 = 50", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 40), conf.int = TRUE, xlim = c(1, 5), ylim = c(5, 50), label = "image", font.label = c(5, "plain", "black"))
corr %>%
ggscatter(y = "detection_rt", x = "likelihood_rating", color = "change_type", palette = c("#0d2240", "#00a8e1", "#f7a800", "#E31818", "#dfdddc"), ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(5, 50), label = "image", font.label = c(5, "plain", "black")) + stat_cor(aes(color = change_type), label.x = 1, label.y = c(35, 40), method = "pearson")
Here, I am dropping image-116 from the analyses. It is an obvious outlier.
wolfe1_RTs_likelihood_no_NA_no_outlier <- wolfe1_RTs_likelihood_no_NA %>%
filter(image != "image-116")
fit_raw_no_outlier <- lmer(detection_rt ~ likelihood_rating * change_type + (1 | workerId) + (1 | image), data=wolfe1_RTs_likelihood_no_NA_no_outlier)
summary(fit_raw_no_outlier)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: detection_rt ~ likelihood_rating * change_type + (1 | workerId) +
## (1 | image)
## Data: wolfe1_RTs_likelihood_no_NA_no_outlier
##
## REML criterion at convergence: 7399.9
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9883 -0.4793 -0.1656 0.1447 6.8351
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 2.248 1.499
## workerId (Intercept) 8.584 2.930
## Residual 34.155 5.844
## Number of obs: 1139, groups: image, 110; workerId, 50
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 13.0203 0.8203 316.8578 15.872
## likelihood_rating -0.5994 0.2105 816.2745 -2.847
## change_typedisappear -1.3495 1.0555 551.9441 -1.279
## likelihood_rating:change_typedisappear 0.0855 0.3023 871.5177 0.283
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00452 **
## change_typedisappear 0.20158
## likelihood_rating:change_typedisappear 0.77739
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lklhd_ chng_t
## liklhd_rtng -0.776
## chng_typdsp -0.516 0.523
## lklhd_rtn:_ 0.474 -0.608 -0.897
corr %>%
filter(image!="image-116") %>%
ggscatter(y = "detection_rt", x = "likelihood_rating", ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", 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, 25))
corr %>%
filter(image!="image-116") %>%
ggscatter(y = "detection_rt", x = "likelihood_rating", color = "change_type", palette = c("#0d2240", "#00a8e1", "#f7a800", "#E31818", "#dfdddc"), ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(5, 25)) + stat_cor(aes(color = change_type), label.x = 1, label.y = c(23, 25), method = "pearson")
fit_log <- lmer(log10(detection_rt) ~ likelihood_rating * change_type + (1 | workerId) + (1 | image), data=wolfe1_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 * change_type + (1 |
## workerId) + (1 | image)
## Data: wolfe1_RTs_likelihood_no_NA
##
## REML criterion at convergence: -840.2
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.2594 -0.5963 -0.1705 0.3775 4.3582
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 0.002187 0.04677
## workerId (Intercept) 0.010696 0.10342
## Residual 0.023166 0.15220
## Number of obs: 1141, groups: image, 111; workerId, 50
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 1.042806 0.024094 231.743398 43.280
## likelihood_rating -0.016294 0.005627 869.243094 -2.896
## change_typedisappear -0.043869 0.028353 543.962383 -1.547
## likelihood_rating:change_typedisappear 0.005389 0.008023 928.820991 0.672
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00388 **
## change_typedisappear 0.12240
## likelihood_rating:change_typedisappear 0.50199
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lklhd_ chng_t
## liklhd_rtng -0.707
## chng_typdsp -0.472 0.511
## lklhd_rtn:_ 0.427 -0.601 -0.886
corr <- wolfe1_RTs_likelihood_no_NA %>%
group_by(image) %>%
dplyr::summarize(detection_rt = mean(detection_rt), likelihood_rating = mean(likelihood_rating))
corr <- left_join(corr, wolfe1_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 = 50", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 1.6), conf.int = TRUE, xlim = c(1, 5), ylim = c(.8, 1.6), label = "image", font.label = c(5, "plain", "black"))
corr %>%
ggscatter(y = "log", x = "likelihood_rating", color = "change_type", palette = c("#0d2240", "#00a8e1", "#f7a800", "#E31818", "#dfdddc"), ylab = "Log Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(0.8, 1.6), label = "image", font.label = c(5, "plain", "black")) + stat_cor(aes(color = change_type), label.x = 1, label.y = c(1.6, 1.5), method = "pearson")
Here, I am dropping image-116 from the analyses. It is an obvious outlier.
wolfe1_RTs_likelihood_no_NA_no_outlier <- wolfe1_RTs_likelihood_no_NA %>%
filter(image != "image-116")
fit_log_no_outlier <- lmer(log10(detection_rt) ~ likelihood_rating * change_type + (1 | workerId) + (1 | image), data=wolfe1_RTs_likelihood_no_NA_no_outlier)
summary(fit_log_no_outlier)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: log10(detection_rt) ~ likelihood_rating * change_type + (1 |
## workerId) + (1 | image)
## Data: wolfe1_RTs_likelihood_no_NA_no_outlier
##
## REML criterion at convergence: -856
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.2807 -0.6008 -0.1771 0.3706 4.3936
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 0.001924 0.04387
## workerId (Intercept) 0.010486 0.10240
## Residual 0.022939 0.15146
## Number of obs: 1139, groups: image, 110; workerId, 50
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 1.045671 0.023778 230.395075 43.976
## likelihood_rating -0.018198 0.005574 857.913899 -3.265
## change_typedisappear -0.045062 0.027930 564.962736 -1.613
## likelihood_rating:change_typedisappear 0.006809 0.007943 916.937171 0.857
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00114 **
## change_typedisappear 0.10722
## likelihood_rating:change_typedisappear 0.39158
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lklhd_ chng_t
## liklhd_rtng -0.708
## chng_typdsp -0.471 0.514
## lklhd_rtn:_ 0.429 -0.603 -0.890
corr %>%
filter(image!="image-116") %>%
ggscatter(y = "log", x = "likelihood_rating", ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", 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(.8, 1.4))
corr %>%
filter(image!="image-116") %>%
ggscatter(y = "log", x = "likelihood_rating", color = "change_type", palette = c("#0d2240", "#00a8e1", "#f7a800", "#E31818", "#dfdddc"), ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 50", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(.8, 1.4)) + stat_cor(aes(color = change_type), label.x = c(1, 2.5), label.y = c(1.4, 1.4), method = "pearson")