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