1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
library(plyr)
library(dplyr)
library(MPDiR)
library(quickpsy)
library(fitdistrplus)
library(ggplot2)

source("1-read-and-calculate_errors_time_1.R") # to read global values


# set directory where script is
sourceDir <- dirname (rstudioapi::getActiveDocumentContext()$path) 
defaultpath <- sourceDir

#remove(list = ls())
print(defaultpath)
setwd(defaultpath)

filename <- "results/all_data.csv"
dataFile <- read.csv(filename)

# aggregating all possible percentages per movement speed
  aggregatedstable <- ddply(dataFile,
                      c("participant_id","speed_duration"), 
                      summarise,
                      mean_abs_error=mean(abs_error),
                      mean_true_error=mean(true_error),
                      mean_time_taken=mean(time_taken_type_ms)
   )
  
write.csv(aggregatedstable, file="results/aggregated.csv")


##################################################################


# aggregating per movement speed but for each percentage seperately
aggregatedstable2 <- ddply(dataFile,
                          c("participant_id","speed_duration","correct_answer"), 
                          summarise,
                          mean_abs_error=mean(abs_error),
                          mean_true_error=mean(true_error),
                          mean_time_taken=mean(time_taken_type_ms)
)

write.csv(aggregatedstable2, file="results/aggregated_per_percentage.csv")


for(c in correct_answer){
  tmp <- aggregatedstable2 [which (aggregatedstable2$correct_answer == c),]
  tmp_file_name <- sprintf("results/aggregated_%d.csv", c)
  write.csv(tmp, file=tmp_file_name)
}