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 = "./Rensink_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', NA), sep = "([\\_\\-])")
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.633333
tbl_all_img_avg <- data.frame(img_avg = colMeans(tbl_all_subj_avg[,2:49], na.rm = TRUE))
tbl_all_img_avg <- tibble::rownames_to_column(tbl_all_img_avg, "image")
Add change_type to dataframe.
rensink_change_type<- read_csv("Rensink_change_type.csv")
rensink_RTs_likelihood <- left_join(rensink_RTs_likelihood, rensink_change_type, by = "image")
Compute likelihood rating for each image.
rensink_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 = 8, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

rensink_RTs_likelihood_no_NA <- rensink_RTs_likelihood %>%
drop_na()
rensink_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 = 8, sort.val = c("asc")) + rotate_x_text() + theme(legend.position = "none")

write.csv(rensink_RTs_likelihood,'Rensink_RTs_likelihood.csv', row.names=FALSE)
write.csv(rensink_RTs_likelihood_no_NA,'Rensink_RTs_likelihood_no_NA.csv', row.names=FALSE)
Count number of ratings
rensink_RTs_likelihood_count <- rensink_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)
rensink_RTs_likelihood_count <- data.frame(count = colSums(rensink_RTs_likelihood_count[,2:49], na.rm = TRUE))
rensink_RTs_likelihood_count <- tibble::rownames_to_column(rensink_RTs_likelihood_count, "image")
rensink_RTs_likelihood_count
## image count
## 1 Amish 9
## 2 Army 8
## 3 Barns 8
## 4 BarnTrack 8
## 5 Barrels 7
## 6 Beach 11
## 7 Birds 9
## 8 Boat 8
## 9 Bus 9
## 10 Cactus 9
## 11 Camel 10
## 12 CanalBridge 8
## 13 Castle 5
## 14 Chopper 9
## 15 Cockpit 8
## 16 Description 6
## 17 Dinner 8
## 18 Diver 11
## 19 Eating 8
## 20 Egypt 8
## 21 FarmByPond 5
## 22 Farmer 9
## 23 Fishing 9
## 24 Floatplane 8
## 25 Fountain 10
## 26 Harbor 9
## 27 Horizon 8
## 28 Ice 7
## 29 Kayak 10
## 30 Kayaker 8
## 31 Kids 8
## 32 Lake 11
## 33 Market 6
## 34 Marling 8
## 35 Mosque 10
## 36 NotreDame 12
## 37 Nurses 8
## 38 Obelisk 9
## 39 OtherDiver 6
## 40 Pilots 9
## 41 Seal 11
## 42 Soldiers 9
## 43 Station 9
## 44 SummerLake 9
## 45 Turtle 6
## 46 Water 9
## 47 Window 8
## 48 Wine 9
Mixed effects model and correlation.
fit0 <- lmer(detection_rt ~ likelihood_rating + (1 | workerId) + (1 | image) + (1 | change_type), data=rensink_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) +
## (1 | change_type)
## Data: rensink_RTs_likelihood_no_NA
##
## REML criterion at convergence: 1839.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.1786 -0.4009 -0.1123 0.2428 4.5075
##
## Random effects:
## Groups Name Variance Std.Dev.
## image (Intercept) 6.160e-01 0.7848466
## workerId (Intercept) 4.494e+00 2.1198231
## change_type (Intercept) 1.137e-07 0.0003372
## Residual 4.315e+00 2.0772608
## Number of obs: 407, groups: image, 48; workerId, 16; change_type, 3
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 8.43202 0.66336 32.07326 12.711 4.57e-14 ***
## likelihood_rating -0.09611 0.09990 251.45136 -0.962 0.337
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## liklhd_rtng -0.551
corr <- rensink_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 = 16", 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, 15))
