# remotes::install_github("craddm/eegUtils")
# devtools::install_github("bnicenboim/eeguana")

library(eegUtils)
library(tidyverse)


top_dir <- '../data-raw/facar_subj_cond_data_preproc'
all_data <- list.files(top_dir, full.names = T)


all_erp <- lapply(all_data, read_tsv)
names(all_erp) <- basename(all_data) %>% str_remove(".txt")

#save the resulting list
save(file="../data-raw/all_erp.Rdata",all_erp)

elec_position <- import_chans("canali.ced")

L'obbiettivo di questo piccolo esercizio è quello di farvi prendere un pò confidenza con i dati sui quali andrete a svolgere i vostri progetti. Nello specifico il dataset sui potenziali evocati che trovate nel folder ERPDataforstudents. I vari file txt includono l'attività per ogni timepoint ed elettrodo per ogni soggetto e per ogni condizione sperimentale.
Quello che vi chiedo di fare è semplicemente replicare le tre immagini qui sotto, che mostrano le waveforms per il canale PO8 tra le varie condizioni (immagine 1), le ampiezze medie della componente N170 misurata tra 140 e 180 millisecondi (immagine 2), e una scalp map dell'attività media nella condizione Faces a 170 ms.

Immagine 1 - Waveform

D=all_erp %>% 
  lapply(., pivot_longer, -time, names_to = "elec", values_to = "amplitude") %>% 
  bind_rows(.id = "tmp_ID") %>% 
   filter(elec == "PO8") %>% 
  separate(tmp_ID, c("ID", "condition"), "_") %>% 
   group_by(condition,time,elec)
dim(D)


D %>% 
  summarise(y = mean(amplitude), se = sd(amplitude)/sqrt(40), ymin = y - se, ymax = y + se) %>% 
  ggplot(aes(x = time, y = y, ymin = ymin, ymax = ymax, color = condition, fill = condition)) +
  geom_ribbon(aes(color = NULL), alpha = .4) +
  geom_line() +
  theme_bw() +
  theme(legend.position = "bottom", legend.title = element_blank()) +
  labs(x = NULL, y = "Mean Amplitude", title = "Waveforms for Channel PO8")

Immagine 2 - Boxplot

D %>% 
  filter(time > 140, time < 180, elec == "PO8") %>% 
    summarise(M = mean(amplitude)) %>% 
  ggplot(aes(condition, y = M, fill = condition)) +
  geom_boxplot() +
  theme_bw() +
  guides(fill = "none") +
  labs(x = NULL, y = "Mean Amplitude", title = "Channel PO8 - Time range 140-180 ms")

Immagine 3

Per realizzare questa immagine servirà la posizione spaziale dei canali. Copia e incollate questa tabella in un file che chiamerete canali.ced.

knitr::kable(elec_position)

La funzione per importare questo file è eegUtils::import_chans(). La funzione per realizzare la mappa topografica è eegUtils::topoplot

channnel_path <- "~/your_path/canali.ced" # Change to your directory
elec_position <- import_chans(channel_path)
elec_position <- import_chans("canali.ced")

all_erp %>% 
  lapply(., pivot_longer, -time, names_to = "elec", values_to = "amplitude") %>% 
  bind_rows(.id = "tmp_ID") %>% 
  separate(tmp_ID, c("ID", "condition"), "_") %>% 
  filter(time > 165, time < 175) %>% 
  mutate(electrode = elec) %>% 
  select(-elec) %>% 
  group_by(electrode) %>%
  summarise(amplitude = mean(amplitude)) %>%
  topoplot(chanLocs = elec_position)


livioivil/eegusta documentation built on May 6, 2024, 9:20 p.m.