Skip to content

Commit 8bb08f2

Browse files
20250424 - show code chunks by default
1 parent d5a146f commit 8bb08f2

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

eegERP.Rmd

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
22
title: "EEG and ERP Processing and Analysis"
3+
output:
4+
html_document:
5+
code_folding: show
36
---
47

58
```{r setup, include = FALSE}
69
knitr::opts_chunk$set(
710
echo = TRUE,
811
error = TRUE,
9-
comment = "")
12+
comment = "",
13+
class.source = "fold-show")
1014
```
1115

1216
# Extracting Behavioral Data from `E-Prime`
@@ -76,7 +80,7 @@ The following section describes the MATLAB scripts used to manage HAPPE output f
7680
- In the second section of our script file, we set our "threshold" for the minimum number of trials that need to be retained after pre-processing for a subject's data to be eligible for PCA.
7781
Additional thresholds can also be set for things like number of channels retained, but these are not currently in use.
7882

79-
```matlab
83+
```
8084
% Set quality threshold parameters
8185
trialCutoff = 10;
8286
```
@@ -1194,7 +1198,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
11941198
1. Create a list of all PCA component files in the specified directory.
11951199
This list will contain the full filepaths to each component file which are used to read the data into R.
11961200
1197-
```r
1201+
```{r, eval = FALSE}
11981202
oddballFilePaths <- list.files(
11991203
path = "Z:/Shared Server/Study Folder/Data/LV2/ERP/PCA Components/Oddball",
12001204
pattern = "*.txt",
@@ -1205,27 +1209,27 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12051209
This list will be used to rename columns in the final composite dataset according to the name of the component file.
12061210
For this reason, the naming convention of each component files is crucial; this will determine how the corresponding column of the composite datafile is named.
12071211
1208-
```r
1212+
```{r, eval = FALSE}
12091213
oddballFiles <- list.files(
12101214
path = "Z:/Shared Server/Study Folder/Data/LV2/ERP/PCA Components/Oddball",
12111215
pattern = "*.txt",
12121216
recursive = FALSE)
12131217
```
12141218
1. Read in each component file, skipping the rows containing summary information about the extracted component (the first 7 rows in this example).
12151219
1216-
```r
1220+
```{r, eval = FALSE}
12171221
oddballData <- lapply(oddballFilePaths, function(x) read_delim(x, delim = "\t", skip = 7))
12181222
```
12191223
12201224
1. "Clean" the list of component file names by removing the file extension (in this case, `.txt`).
12211225
1222-
```r
1226+
```{r, eval = FALSE}
12231227
componentNames <- oddballFiles %>% str_remove(".txt")
12241228
```
12251229
12261230
1. Give `ID` variable a proper name.
12271231
1228-
```r
1232+
```{r, eval = FALSE}
12291233
oddballData <- lapply(oddballData, function(x){
12301234
names(x)[length(names(x))] <- "ID"
12311235
return(x)
@@ -1234,7 +1238,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12341238
1. At this stage, the ERP component data are nested within a list of separate data objects.
12351239
We must therefore merge them into a single dataframe object.
12361240
1237-
```r
1241+
```{r, eval = FALSE}
12381242
oddballDataMerged <- oddballData %>%
12391243
reduce(full_join, by = c("ID"))
12401244
```
@@ -1246,7 +1250,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12461250
* Remove the `ID` variable now that it has been separated into `tcid` and `wave`
12471251
* Convert all values to numeric
12481252
1249-
```r
1253+
```{r, eval = FALSE}
12501254
oddballDataClean <- oddballDataMerged %>%
12511255
mutate(tcid = substr(ID, 1, 4),
12521256
wave = substr(ID, 6, 7)) %>%
@@ -1256,12 +1260,12 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12561260
```
12571261
1. Update column names of merged data according to the list of PCA component files.
12581262
1259-
```r
1263+
```{r, eval = FALSE}
12601264
names(oddballDataClean) <- c("tcid", "wave", componentNames)
12611265
```
12621266
1. Save composite data to desired location.
12631267
1264-
```r
1268+
```{r, eval = FALSE}
12651269
write_csv(oddballDataClean, file = "Z:/Shared Server/Study Folder/Data/REDCap/Composites/erpOddball.csv")
12661270
```
12671271
@@ -1271,7 +1275,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12711275
12721276
1. Read in the grand average waveform data exported from EP Toolkit.
12731277
- We currently process the conditions within a given task separately, so each condition should have its own grand average file.
1274-
```r
1278+
```{r, eval = FALSE}
12751279
obTgt <- read.table("V:/SRS-ERP-Oddball/Hard/All/4 - EPT Averages/2024-11-05/gave/ob_tgt_gav.txt")
12761280
obFrq <- read.table("V:/SRS-ERP-Oddball/Hard/All/4 - EPT Averages/2024-11-05/gave/ob_frq_gav.txt")
12771281
```
@@ -1280,7 +1284,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12801284
- The grand average data does not have row or column labels, but the columns represent the EEG net channels in numerical order (1-129).
12811285
We can therefore use their column index values to select the desired electrodes; so, the list containing the channel numbers should include ONLY numbers.
12821286
The code that selects these channels out of the full dataset will rely on numerical input.
1283-
```r
1287+
```{r, eval = FALSE}
12841288
# Set electrode clusters
12851289
obElectrodes <- c(58, 59, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, 81, 82, 83, 84, 89, 80, 91, 95, 96, 101)
12861290
@@ -1293,7 +1297,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12931297
- Adding a condition label will allow us to combine the two condition-specific datasets into one that can be used for visualizations
12941298
- For ease of plotting, name the conditions the way that you would like them to appear on the figure (i.e., "Target" instead of "tgt")
12951299

1296-
```r
1300+
```{r, eval = FALSE}
12971301
# Compute averages
12981302
obTgt_sub$amplitude <- rowMeans(obTgt_sub)
12991303
obFrq_sub$amplitude <- rowMeans(obFrq_sub)
@@ -1306,7 +1310,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
13061310
1. Add timing-related information to the data
13071311
- EP Toolkit exports ERP data without timestamps, but arranges it in order of timing
13081312
- We can create a template with the appropriate timestamps and append this column to the amplitude data
1309-
```r
1313+
```{r, eval = FALSE}
13101314
# Create template
13111315
erpTemplate <- data.frame(
13121316
time = -199:1000
@@ -1317,14 +1321,14 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
13171321
obFrqTimes <- cbind(erpTemplate, obFrq_amps)
13181322
```
13191323
1. Combine all conditions into a single data object to be used for plotting
1320-
```r
1324+
```{r, eval = FALSE}
13211325
oddball <- rbind(obTgtTimes, obFrqTimes) %>%
13221326
select(time, condition, amplitude) %>%
13231327
arrange(time)
13241328
```
13251329

13261330
1. Generate the waveform figures
1327-
```r
1331+
```{r, eval = FALSE}
13281332
ggplot(
13291333
data = oddball,
13301334
aes(

0 commit comments

Comments
 (0)