highspeed-analysis-setup.R 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # find the path to the root of this project:
  2. if (!requireNamespace("here")) install.packages("here")
  3. if ( basename(here::here()) == "highspeed" ) {
  4. path_root = here::here("highspeed-analysis")
  5. } else {
  6. path_root = here::here()
  7. }
  8. source(file.path(path_root, "code", "highspeed-analysis-source.R"))
  9. # reverting to ggplot2 version 3.2.1 for lemon compatibility
  10. # cf. https://github.com/stefanedwards/lemon/issues/20
  11. #devtools::install_version("ggplot2", version = "3.3.0", repos = "http://cran.us.r-project.org")
  12. # create an array with all required packages:
  13. packages <- c("R.matlab", "ggplot2", "dplyr", "ggpubr", "psyphy", "ggm",
  14. "corrplot", "reshape2", "afex", "polycor", "tinytex", "extrafont",
  15. "viridis", "rjson", "jsonlite", "tidyr", "combinat", "rlist",
  16. "lemon", "doMC", "plyr", "styler", "gridExtra", "grid",
  17. "data.table", "NameNeedle", "textreuse", "stringdist", "emmeans",
  18. "RColorBrewer", "tidyverse", "gtools", "cowplot",
  19. "assertr", "lavaan", "rmarkdown", "readr", "caTools", "bitops",
  20. "broom", "ggridges", "nloptr", "devtools", "bookdown", "rstatix",
  21. "lomb")
  22. # load packages using the load_packages function:
  23. load_packages(packages_list = packages)
  24. # specify paths:
  25. source(file.path(path_root, "code", "highspeed-cluster-permutation.R"))
  26. source(file.path(path_root, "code", "raincloud-plots", "tutorial_R", "R_rainclouds.R"))
  27. source(file.path(path_root, "code", "raincloud-plots", "tutorial_R", "summarySE.R"))
  28. # path to figures created by the analysis code:
  29. path_figures <- file.path(path_root, "figures")
  30. # path to source data created by the analysis code:
  31. path_sourcedata <- file.path(path_root, "sourcedata")
  32. # path to the participants.tsv file (according to BIDS):
  33. # datalad get data/bids/participants.tsv
  34. path_participants <- file.path(path_root, "data", "bids", "participants.tsv")
  35. # path to the events.tsv files (according to BIDS):
  36. path_events <- file.path(path_root, "data", "bids", "*", "*", "func", "*events.tsv")
  37. # path to data from the decoding analysis:
  38. path_pred <- file.path(path_root, "data", "decoding", "decoding", "*", "data", "*decoding.csv")
  39. # path to the data from the mask thresholding:
  40. path_thresh <- file.path(path_root, "data", "decoding", "decoding", "*", "data", "*thresholding.csv")
  41. # path to the data of the voxel patterns:
  42. path_patterns <- file.path(path_root, "data", "decoding", "decoding", "*", "data", "*voxel_patterns_union*.csv")
  43. # Load all [BIDS](http://bids.neuroimaging.io/) events files:
  44. # read all events files and concatenate them in a data table:
  45. # datalad get data/bids/sub-*/ses-*/func/*events.tsv
  46. dt_events <- do.call(rbind, lapply(Sys.glob(path_events), fread))
  47. # add the cue of the current trial and the response accuracy on a given trial:
  48. dt_events[, by = .(subject, condition, trial), ":=" (
  49. trial_cue = stim_label[!is.na(target) & target != 0],
  50. trial_accuracy = accuracy[!is.na(accuracy)]
  51. )]
  52. # read all decoding data files and concatenate them in a data table:
  53. # datalad get data/decoding/decoding/sub-*/data/*_decoding.csv
  54. dt_pred <- do.call(rbind, lapply(Sys.glob(path_pred), data.table::fread))
  55. # prepare data (add additional variables like a speed trial counter etc.)
  56. dt_pred <- prepare_data(dt_pred)
  57. # read all data from the mask thresholding:
  58. # datalad get data/decoding/decoding/*/data/*thresholding.csv
  59. dt_thresh = do.call(rbind, lapply(Sys.glob(path_thresh), data.table::fread))
  60. # read all data from the mask thresholding:
  61. # datalad get data/decoding/decoding/*/data/*voxel_patterns_union*.csv
  62. files_patterns = Sys.glob(path_patterns)
  63. files_patterns = files_patterns[!stringr::str_detect(files_patterns, "hpc")]
  64. #dt_patterns = lapply(files_patterns, data.table::fread)
  65. # create color list for probabilities of individual sequence events:
  66. color_events <- rev(hcl.colors(5, "Zissou 1"))
  67. # define global lmer settings used in all mixed effects lmer models:
  68. lcctrl <- lmerControl(
  69. optimizer = c("bobyqa"), optCtrl = list(maxfun = 500000),
  70. calc.derivs = FALSE)