########################################################### # LOAD DATA AND LIBRARIES ########################################################### library(plyr) library(tidyverse) library(gridExtra) library(data.table) #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 %>% select(user, block, measure) %>% arrange(user, block) #View(elements) setnames(elements, old=c("measure"), new=c(col_name)) elements <- spread(elements, key = block, value = col_name) setnames(elements, old=c("1","2", "3"), new=c("First","Second", "Third")) ######### # stats # ######### data <- elements if (mean (data$First) == 0 ) { techniqueA <- c(0.000000,0.000000,0.000000) } else { techniqueA <- bootstrapMeanCI(data$First) } if (mean (data$Second) == 0 ) { techniqueB <- c(0.000000,0.000000,0.000000) } else { techniqueB <- bootstrapMeanCI(data$Second) } if (mean (data$Third) == 0 ) { techniqueC <- c(0.000000,0.000000,0.000000) } else { techniqueC <- bootstrapMeanCI(data$Third) } analysisData <- c() analysisData$name <- c("Third","Second","First") analysisData$pointEstimate <- c(techniqueC[1], techniqueB[1], techniqueA[1]) analysisData$ci.max <- c(techniqueC[3], techniqueB[3], techniqueA[3]) analysisData$ci.min <- c(techniqueC[2], 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/") filename = paste0("order_", 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 = 3, 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$Second) == 0 & mean(data$First) == 0) { diffBA <- c(0.000000,0.000000,0.000000,8,0.000000,0.000000) } else { diffBA = bootstrapMeanCI_corr(data$Second - data$First, 1) } if (mean(data$Third) == 0 & mean(data$Second) == 0) { diffCB <- c(0.000000,0.000000,0.000000,8,0.000000,0.000000) } else { diffCB = bootstrapMeanCI_corr(data$Third - data$Second, 1) } if (mean(data$Third) == 0 & mean(data$First)) { diffCA <- c(0.000000,0.000000,0.000000,8,0.000000,0.000000) } else { diffCA = bootstrapMeanCI_corr(data$Third - data$First, 1) } analysisData <- c() analysisData$name <- c("Third-First","Third-Second","Second-First") analysisData$pointEstimate <- c(diffCA[1], diffCB[1], diffBA[1]) analysisData$ci.max <- c(diffCA[3], diffCB[3], diffBA[3]) analysisData$ci.min <- c(diffCA[2], diffCB[2], diffBA[2]) analysisData$level <- c(diffCA[4], diffCB[4], diffBA[4]) analysisData$ci_corr.max <- c(diffCA[6], diffCB[6], diffBA[6]) analysisData$ci_corr.min <- c(diffCA[5], diffCB[5], 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/") filename = paste0("order_", 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 = 3, 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")) # 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, block) %>% summarise(time=mean(time), error=sum(is_correct=='False')/3) data_base <- data_base %>% mutate(time=time/1000, error=error*100) data_time <- data_base %>% group_by(user, block) %>% summarise(measure=mean(time)) row_time <- create_row(data_time, "all", 'time', 'dodgerblue2') data_error <- data_base %>% group_by(user, block) %>% summarise(measure=mean(error)) row_error <-create_row(data_error, "all", 'time', 'darkorange3') #this uses error but not in the name, for some reason I got error grid <- grid.arrange(row_time, row_error, ncol=1) filename <- "plots/order_session/all_time_error.pdf" ggsave(filename = filename, grid, device = "pdf", width=10, height=6)