Skip to content

Commit d5a146f

Browse files
20250424 - specify code language for syntax highlighting; try matlab highlighting
1 parent c0afb05 commit d5a146f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

eegERP.Rmd

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The following section describes the MATLAB scripts used to manage HAPPE output f
7676
- 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.
7777
Additional thresholds can also be set for things like number of channels retained, but these are not currently in use.
7878

79-
```
79+
```matlab
8080
% Set quality threshold parameters
8181
trialCutoff = 10;
8282
```
@@ -1194,7 +1194,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
11941194
1. Create a list of all PCA component files in the specified directory.
11951195
This list will contain the full filepaths to each component file which are used to read the data into R.
11961196
1197-
```
1197+
```r
11981198
oddballFilePaths <- list.files(
11991199
path = "Z:/Shared Server/Study Folder/Data/LV2/ERP/PCA Components/Oddball",
12001200
pattern = "*.txt",
@@ -1205,27 +1205,27 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12051205
This list will be used to rename columns in the final composite dataset according to the name of the component file.
12061206
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.
12071207
1208-
```
1208+
```r
12091209
oddballFiles <- list.files(
12101210
path = "Z:/Shared Server/Study Folder/Data/LV2/ERP/PCA Components/Oddball",
12111211
pattern = "*.txt",
12121212
recursive = FALSE)
12131213
```
12141214
1. Read in each component file, skipping the rows containing summary information about the extracted component (the first 7 rows in this example).
12151215
1216-
```
1216+
```r
12171217
oddballData <- lapply(oddballFilePaths, function(x) read_delim(x, delim = "\t", skip = 7))
12181218
```
12191219
12201220
1. "Clean" the list of component file names by removing the file extension (in this case, `.txt`).
12211221
1222-
```
1222+
```r
12231223
componentNames <- oddballFiles %>% str_remove(".txt")
12241224
```
12251225
12261226
1. Give `ID` variable a proper name.
12271227
1228-
```
1228+
```r
12291229
oddballData <- lapply(oddballData, function(x){
12301230
names(x)[length(names(x))] <- "ID"
12311231
return(x)
@@ -1234,7 +1234,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12341234
1. At this stage, the ERP component data are nested within a list of separate data objects.
12351235
We must therefore merge them into a single dataframe object.
12361236
1237-
```
1237+
```r
12381238
oddballDataMerged <- oddballData %>%
12391239
reduce(full_join, by = c("ID"))
12401240
```
@@ -1246,7 +1246,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12461246
* Remove the `ID` variable now that it has been separated into `tcid` and `wave`
12471247
* Convert all values to numeric
12481248
1249-
```
1249+
```r
12501250
oddballDataClean <- oddballDataMerged %>%
12511251
mutate(tcid = substr(ID, 1, 4),
12521252
wave = substr(ID, 6, 7)) %>%
@@ -1256,12 +1256,12 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12561256
```
12571257
1. Update column names of merged data according to the list of PCA component files.
12581258
1259-
```
1259+
```r
12601260
names(oddballDataClean) <- c("tcid", "wave", componentNames)
12611261
```
12621262
1. Save composite data to desired location.
12631263
1264-
```
1264+
```r
12651265
write_csv(oddballDataClean, file = "Z:/Shared Server/Study Folder/Data/REDCap/Composites/erpOddball.csv")
12661266
```
12671267
@@ -1271,7 +1271,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12711271
12721272
1. Read in the grand average waveform data exported from EP Toolkit.
12731273
- We currently process the conditions within a given task separately, so each condition should have its own grand average file.
1274-
```
1274+
```r
12751275
obTgt <- read.table("V:/SRS-ERP-Oddball/Hard/All/4 - EPT Averages/2024-11-05/gave/ob_tgt_gav.txt")
12761276
obFrq <- read.table("V:/SRS-ERP-Oddball/Hard/All/4 - EPT Averages/2024-11-05/gave/ob_frq_gav.txt")
12771277
```
@@ -1280,7 +1280,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12801280
- The grand average data does not have row or column labels, but the columns represent the EEG net channels in numerical order (1-129).
12811281
We can therefore use their column index values to select the desired electrodes; so, the list containing the channel numbers should include ONLY numbers.
12821282
The code that selects these channels out of the full dataset will rely on numerical input.
1283-
```
1283+
```r
12841284
# Set electrode clusters
12851285
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)
12861286

@@ -1293,7 +1293,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
12931293
- Adding a condition label will allow us to combine the two condition-specific datasets into one that can be used for visualizations
12941294
- 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")
12951295

1296-
```
1296+
```r
12971297
# Compute averages
12981298
obTgt_sub$amplitude <- rowMeans(obTgt_sub)
12991299
obFrq_sub$amplitude <- rowMeans(obFrq_sub)
@@ -1306,7 +1306,7 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
13061306
1. Add timing-related information to the data
13071307
- EP Toolkit exports ERP data without timestamps, but arranges it in order of timing
13081308
- We can create a template with the appropriate timestamps and append this column to the amplitude data
1309-
```
1309+
```r
13101310
# Create template
13111311
erpTemplate <- data.frame(
13121312
time = -199:1000
@@ -1317,14 +1317,14 @@ Comparable scripts have also been created for FishShark and Stop Signal tasks.
13171317
obFrqTimes <- cbind(erpTemplate, obFrq_amps)
13181318
```
13191319
1. Combine all conditions into a single data object to be used for plotting
1320-
```
1320+
```r
13211321
oddball <- rbind(obTgtTimes, obFrqTimes) %>%
13221322
select(time, condition, amplitude) %>%
13231323
arrange(time)
13241324
```
13251325

13261326
1. Generate the waveform figures
1327-
```
1327+
```r
13281328
ggplot(
13291329
data = oddball,
13301330
aes(

0 commit comments

Comments
 (0)