########################################################### # LOAD DATA AND LIBRARIES ########################################################### library(plyr) library(tidyverse) library(gridExtra) library(data.table) library(grid) #install.packages("remotes") #remotes::install_github("wilkelab/cowplot") library(cowplot) #source("CI-Functions.R") source("CI-Functions-Bonferroni.R") defaultpath <- dirname(rstudioapi::getActiveDocumentContext()$path) setwd(defaultpath) create_row <- function(data_base, current_task, measure_name, mycolor) { col_name <- paste0("mean_", measure_name, sep="") elements <- data_base setnames(elements, old=c("measure"), new=c(col_name)) elements <- spread(elements, key = block, value = col_name) setnames(elements, old=c("1", "3"), new=c("First","Last")) ######### # stats # ######### data <- elements if (mean (data$First) == 0 ) { techniqueA <- c(0.000000,0.000000,0.000000) } else { techniqueA <- bootstrapMeanCI(data$First) } if (mean (data$Last) == 0 ) { techniqueB <- c(0.000000,0.000000,0.000000) } else { techniqueB <- bootstrapMeanCI(data$Last) } analysisData <- c() analysisData$name <- c("Last","First") analysisData$pointEstimate <- c(techniqueB[1], techniqueA[1]) analysisData$ci.max <- c(techniqueB[3], techniqueA[3]) analysisData$ci.min <- c(techniqueB[2], techniqueA[2]) datatoprint <- data.frame(factor(analysisData$name),analysisData$pointEstimate, analysisData$ci.min, analysisData$ci.max) colnames(datatoprint) <- c("vis", col_name, "lowerBound_CI", "upperBound_CI ") #We use the name mean_error for the value of the mean even though it's not a error, it's just to parse the data for the plot path = paste0("plots/order_session/individual/") filename = paste0("orderfirst_last_", measure_name, "_means_", current_task, sep="") #write.table(datatoprint, paste0(path, "printed_",filename,".txt",seq=""), sep=",",row.names=FALSE) mean_plot <- barChart(datatoprint, analysisData$name, nbTechs = 2, ymin = 0, ymax = 50, "", "", mycolor=mycolor) #ggsave(paste0(path,"plot_",filename,".pdf",seq=""), mean_plot, device = "pdf", width=5, height=2) # CIs with adapted alpha value for multiple comparisons not needed here # checks for situations where error rate is 0 everywhere, else Bootstrap if (mean(data$Last) == 0 & mean(data$First) == 0) { diffBA <- c(0.000000,0.000000,0.000000,8,0.000000,0.000000) } else { diffBA = bootstrapMeanCI_corr(data$Last - data$First, 1) } analysisData <- c() analysisData$name <- c("Last-First") analysisData$pointEstimate <- c(diffBA[1]) analysisData$ci.max <- c(diffBA[3]) analysisData$ci.min <- c(diffBA[2]) analysisData$level <- c(diffBA[4]) analysisData$ci_corr.max <- c(diffBA[6]) analysisData$ci_corr.min <- c(diffBA[5]) datatoprint <- data.frame(factor(analysisData$name), analysisData$pointEstimate, analysisData$ci.max, analysisData$ci.min, analysisData$level, analysisData$ci_corr.max, analysisData$ci_corr.min) colnames(datatoprint) <- c("technique", col_name, "lowerBound_CI", "upperBound_CI", "corrected_CI", "lowerBound_CI_corr", "upperBound_CI_corr") #We use the name mean_error for the value of the mean even though it's not a error, it's just to parse the data for the plot path = paste0("plots/order_session/individual/") filename = paste0("orderfirst_last_", measure_name, "_diffs_",current_task) #write.table(datatoprint, paste0(path,"printed_",filename,".txt",seq=""), sep=",",row.names=FALSE) diff_plot <- barChart(datatoprint, analysisData$name, nbTechs = 1, ymin = -20, ymax = 20, "", "", mycolor=mycolor) #ggsave(paste0(path,"plot_",filename,".pdf",seq=""), diff_plot, device = "pdf", width=5, height=2) row <- grid.arrange(mean_plot, diff_plot, ncol=2) return(row) } all_data <- read.table("user_answers_ms.csv", header=T, sep=",") # Remove training #all_data <- all_data %>% filter(question_config != 'T') %>% # mutate(vis=case_when(vis == 'Symbol' ~ "Gly", # vis == 'Dorling' ~ "Dor", # vis == 'Barchart' ~ "Bar")) all_data$vis <- revalue(all_data$vis, c("Symbol"="Gly")) all_data$vis <- revalue(all_data$vis, c("Dorling"="Dor")) all_data$vis <- revalue(all_data$vis, c("Barchart"="Bar")) # Summarize by task data_base <- all_data %>% select(user, vis, block, question_code, time, is_correct) data_base <- data_base %>% group_by(user, question_code, vis, block) %>% summarise(time=mean(time), error=sum(is_correct=='False')/3) data_base <- data_base %>% mutate(time=time/1000, error=error*100) all_plots <- list() vis_techs <- c('Bar', 'Dor', 'Gly') for(j in 1:3) { this_vis <- vis_techs[[j]] this_data_base <- data_base %>% filter(vis==this_vis) this_data_base <- this_data_base %>% filter(block!=2) this_data_base <- this_data_base %>% group_by(question_code, block) %>% summarise(time=mean(time), error=mean(error)) data_time <- this_data_base %>% ungroup %>% select(question_code, block, time) setnames(data_time, old = c('time'), new = c('measure')) row_time <- create_row(data_time, this_vis, 'time', 'dodgerblue2') data_error <-this_data_base %>% ungroup %>% select(question_code, block, error) setnames(data_error, old = c('error'), new = c('measure')) row_error <-create_row(data_error, this_vis, 'time', 'darkorange3') #this uses error but not in the name, for some reason I got error title <- this_vis this_grid <- grid.arrange(row_time, row_error, ncol=1, top = textGrob(title, gp=gpar(fontsize=20,font=3))) all_plots[[j]] <- this_grid filename <- paste0("plots/order_session/individual/all_orderfirstlast_time_error_", this_vis, ".pdf", sep="") #ggsave(filename = filename, this_grid, device = "pdf", width=10, height=8) } p <- do.call("grid.arrange", c(all_plots, ncol=3)) filename <- "plots/order_session/all_orderfirstlast_time_error_vis.pdf" ggsave(filename = filename, p, device = "pdf", width=15, height=4)