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] 3.003772
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_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: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 16
## 2 image-002 9
## 3 image-003 13
## 4 image-004 15
## 5 image-005 7
## 6 image-006 10
## 7 image-007 15
## 8 image-008 12
## 9 image-009 13
## 10 image-010 16
## 11 image-011 12
## 12 image-012 9
## 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 13
## 21 image-021 10
## 22 image-022 6
## 23 image-023 7
## 24 image-024 8
## 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 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 7
## 51 image-077 9
## 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 7
## 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 8
## 98 image-124 7
## 99 image-125 11
## 100 image-126 12
## 101 image-127 9
## 102 image-128 9
## 103 image-129 5
## 104 image-130 9
## 105 image-131 7
## 106 image-132 8
## 107 image-133 11
## 108 image-134 10
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: 7382.2
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9496 -0.4666 -0.1651 0.1499 6.7043
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 2.888 1.699
## workerId (Intercept) 9.046 3.008
## Residual 35.087 5.923
## Number of obs: 1130, groups: image, 111; workerId, 49
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 12.892271 0.852979 310.103153 15.114
## likelihood_rating -0.500480 0.216380 826.544101 -2.313
## change_typedisappear -1.241752 1.093402 521.004701 -1.136
## likelihood_rating:change_typedisappear 0.004485 0.310468 888.142532 0.014
## Pr(>|t|)
## (Intercept) <2e-16 ***
## likelihood_rating 0.021 *
## change_typedisappear 0.257
## likelihood_rating:change_typedisappear 0.988
## ---
## 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.518 0.520
## 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 = 49", 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 = 49", 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: 7336.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9845 -0.4767 -0.1677 0.1439 6.8106
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 2.305 1.518
## workerId (Intercept) 8.687 2.947
## Residual 34.379 5.863
## Number of obs: 1128, groups: image, 110; workerId, 49
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 13.0407 0.8319 312.0208 15.676
## likelihood_rating -0.5954 0.2123 815.7503 -2.805
## change_typedisappear -1.2932 1.0652 558.6712 -1.214
## likelihood_rating:change_typedisappear 0.0714 0.3045 874.7920 0.234
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00515 **
## change_typedisappear 0.22527
## likelihood_rating:change_typedisappear 0.81470
## ---
## 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.517 0.525
## 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 = 49", 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 = 49", 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: -828.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.2601 -0.5947 -0.1643 0.3743 4.3560
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 0.00228 0.04775
## workerId (Intercept) 0.01086 0.10422
## Residual 0.02319 0.15229
## Number of obs: 1130, groups: image, 111; workerId, 49
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 1.042199 0.024447 226.365867 42.630
## likelihood_rating -0.015815 0.005665 871.809578 -2.792
## change_typedisappear -0.040780 0.028591 548.793891 -1.426
## likelihood_rating:change_typedisappear 0.004619 0.008068 933.509661 0.572
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00536 **
## change_typedisappear 0.15434
## likelihood_rating:change_typedisappear 0.56713
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lklhd_ chng_t
## liklhd_rtng -0.705
## chng_typdsp -0.472 0.512
## lklhd_rtn:_ 0.426 -0.601 -0.885
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 = 49", add = "reg.line", cor.coef = TRUE, cor.coeff.args = list(method = "pearson", label.x = 1, label.y = 1.7), conf.int = TRUE, xlim = c(1, 5), ylim = c(.75, 1.75), 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 = 49", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(0.75, 1.75), label = "image", font.label = c(5, "plain", "black")) + stat_cor(aes(color = change_type), label.x = 1, label.y = c(1.7, 1.6), 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: -844.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.2815 -0.5953 -0.1735 0.3695 4.3911
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 0.002009 0.04482
## workerId (Intercept) 0.010644 0.10317
## Residual 0.022965 0.15154
## Number of obs: 1128, groups: image, 110; workerId, 49
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 1.045052 0.024126 225.063524 43.317
## likelihood_rating -0.017716 0.005613 860.548323 -3.156
## change_typedisappear -0.041934 0.028166 570.291001 -1.489
## likelihood_rating:change_typedisappear 0.006036 0.007989 922.005008 0.756
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## likelihood_rating 0.00165 **
## change_typedisappear 0.13710
## likelihood_rating:change_typedisappear 0.45011
## ---
## 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.514
## lklhd_rtn:_ 0.428 -0.603 -0.889
corr %>%
filter(image!="image-116") %>%
ggscatter(y = "log", x = "likelihood_rating", ylab = "Raw Change Detection RT (sec)", xlab = "Likelihood of Detecting Change", title = "N = 49", 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(.75, 1.5))
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 = 49", add = "reg.line", conf.int = TRUE, xlim = c(1, 5), ylim = c(.75, 1.5)) + stat_cor(aes(color = change_type), label.x = 1, label.y = c(1.4, 1.5), method = "pearson")