Skip to content

Commit b024df4

Browse files
authored
Merge pull request #98 from craddm/develop
Develop into master for 0.6.3
2 parents 151abbf + 5bedb36 commit b024df4

File tree

217 files changed

+4738
-3388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+4738
-3388
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: eegUtils
22
Type: Package
33
Title: Utilities for Electroencephalographic (EEG) Analysis
4-
Version: 0.6.2
4+
Version: 0.6.3
55
Date: 2021-06-08
66
Authors@R: c(
77
person("Matt", "Craddock", role = c("aut", "cre", "cph"), email = "[email protected]"),

NAMESPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ S3method(erp_image,data.frame)
8282
S3method(erp_image,default)
8383
S3method(erp_image,eeg_ICA)
8484
S3method(erp_image,eeg_epochs)
85+
S3method(erp_image,eeg_evoked)
8586
S3method(erp_image,eeg_tfr)
8687
S3method(events,eeg_data)
8788
S3method(events,eeg_epochs)
@@ -139,6 +140,7 @@ S3method(print,eeg_ICA)
139140
S3method(print,eeg_data)
140141
S3method(print,eeg_epochs)
141142
S3method(print,eeg_evoked)
143+
S3method(print,eeg_group)
142144
S3method(print,eeg_lm)
143145
S3method(print,eeg_stats)
144146
S3method(print,eeg_tfr)
@@ -204,6 +206,7 @@ export(compute_itc)
204206
export(compute_psd)
205207
export(compute_tfr)
206208
export(eeg_FASTER)
209+
export(eeg_ICA)
207210
export(eeg_average)
208211
export(eeg_combine)
209212
export(eeg_decompose)
@@ -315,7 +318,6 @@ importFrom(signal,filtfilt)
315318
importFrom(signal,freqz)
316319
importFrom(stats,cor)
317320
importFrom(stats,cov)
318-
importFrom(stats,fft)
319321
importFrom(stats,median)
320322
importFrom(stats,mvfft)
321323
importFrom(stats,nextn)

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# eegUtils 0.6.2.9000
2+
3+
### Function changes
4+
- Added log spaced frequencies to `compute_tfr()`, with the new `spacing` argument. `plot_tfr` automatically detects the spacing and plots the figure appropriately.
5+
- Added `na.rm` option to `erp_image()` to either keep or plot trials with NA values due to smoothing. By default they'll be removed.
6+
- Added more informative messages for `compute_psd()`.
7+
8+
### Internal changes / bug fixes
9+
10+
- Some minor documentation fixes.
11+
- `plot_tfr()` error when selecting a specific frequency range fixed.
12+
- Switched to new style of `vdiffr` tests
13+
- fixed `erp_image()` smoothing over time instead of epochs.
14+
115
# eegUtils 0.6.2
216

317
### Function changes

R/ar-faster.R

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' An implementation of the FASTER artefact rejection method for EEG by Nolan,
44
#' Whelan & Reilly (2010) FASTER: Fully Automated Statistical Thresholding for
5-
#' EEG artifact Rejection. J Neurosci Methods. Not yet fully implemented.
5+
#' EEG artifact Rejection. J Neurosci Methods.
66
#'
77
#' @author Matt Craddock \email{matt@@mattcraddock.com}
88
#'
@@ -380,3 +380,58 @@ faster_epo_stat <- function(data,
380380
bad_chans <- names(data)[bad_chans]
381381
bad_chans
382382
}
383+
384+
385+
ar_FASTER.eeg_group <- function(data,
386+
exclude = NULL,
387+
test_chans = TRUE,
388+
test_epochs = TRUE,
389+
test_cine = TRUE,
390+
...) {
391+
392+
if (!inherits(data, "eeg_evoked")) {
393+
stop("FASTER for grouped data only works for group ERPs.")
394+
}
395+
396+
397+
all_data <- as.data.frame(data)
398+
all_data <- dplyr::group_by(all_data,
399+
participant_id,
400+
time)
401+
chan_names <- channel_names(data)
402+
all_data <-
403+
dplyr::summarise(
404+
all_data,
405+
dplyr::across(
406+
dplyr::all_of(
407+
chan_names
408+
),
409+
.fns = mean
410+
)
411+
)
412+
413+
channel_means <- colMeans(as.matrix(all_data[chan_names]))
414+
415+
all_data <-
416+
group_by(all_data,
417+
participant_id)
418+
all_data <-
419+
summarise(
420+
all_data,
421+
dplyr::across(
422+
dplyr::all_of(chan_names),
423+
list(vars = var,
424+
maxdiff = ~diff(range(.x)),
425+
mean = mean),
426+
.names = "{.col}__{.fn}"
427+
)
428+
)
429+
tidyr::pivot_longer(
430+
all_data,
431+
cols = !participant_id,
432+
names_to = c("electrode",
433+
"measure"),
434+
values_to = "value",
435+
names_sep = "__"
436+
)
437+
}

R/class_handling.R

Lines changed: 83 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Function to create an S3 object of class "eeg_data".
1+
#' Function to create an S3 object of class `eeg_data`.
22
#'
33
#' @author Matt Craddock \email{matt@@mattcraddock.com}
44
#' @param data Raw data - signals from electrodes/channels.
@@ -87,7 +87,7 @@ validate_eeg_data <- function(.data) {
8787
#' Object creator for eeg_tfr objects.
8888
#'
8989
#' @param data TFR transformed data
90-
#' @param srate Sampling rate in Hz.
90+
#' @param srate Sampling rate in Hz. A numeric value.
9191
#' @param events Event tables
9292
#' @param chan_info Standard channel information.
9393
#' @param reference Reference information
@@ -167,7 +167,7 @@ eeg_group <- function(data,
167167
class = "eeg_group")
168168
}
169169

170-
#' Function to create an S3 object of class "eeg_epochs".
170+
#' Function to create an S3 object of class `eeg_epochs`.
171171
#'
172172
#' @author Matt Craddock \email{matt@@mattcraddock.com}
173173
#' @param data Raw data - signals from electrodes/channels.
@@ -275,19 +275,23 @@ eeg_evoked <- function(data,
275275
}
276276

277277

278-
#' Function to create an S3 object of class "eeg_ICA".
278+
#' Function to create an S3 object of class `eeg_ICA`.
279279
#'
280280
#' @author Matt Craddock \email{matt@@mattcraddock.com}
281281
#' @param mixing_matrix ICA mixing matrix
282282
#' @param unmixing_matrix ICA unmixing matrix
283-
#' @param signals ICA components
283+
#' @param signals ICA component timecourses.
284284
#' @param timings Unique timepoints remaining in the data.
285285
#' @param events event table
286-
#' @param chan_info String of character names for electrodes.
287-
#' @param srate Sampling rate
288-
#' @param epochs Epoch information
289-
#' @param algorithm The method used to calculate the ICA decomposition.
290-
#' @keywords internal
286+
#' @param chan_info A data frame containing electrode labels and coordinates.
287+
#' @param srate Sampling rate in Hz. A numeric value.
288+
#' @param epochs A data frame containing meta-information about the epochs
289+
#' contained in the data, such as participant ID label and condition labels
290+
#' for epochs.
291+
#' @param algorithm The method used to calculate the decomposition.
292+
#' @return An object of class `eeg_ICA`.
293+
#' @author Matt Craddock \email{matt@@mattcraddock.com}
294+
#' @export
291295
eeg_ICA <- function(mixing_matrix,
292296
unmixing_matrix,
293297
signals,
@@ -296,33 +300,85 @@ eeg_ICA <- function(mixing_matrix,
296300
chan_info,
297301
srate,
298302
epochs,
299-
algorithm,
300-
version = utils::packageVersion("eegUtils")) {
303+
algorithm) {
304+
305+
new_eeg_ICA(
306+
mixing_matrix = mixing_matrix,
307+
unmixing_matrix = unmixing_matrix,
308+
signals = signals,
309+
timings = timings,
310+
events = events,
311+
chan_info = chan_info,
312+
srate = srate,
313+
epochs = epochs,
314+
algorithm = algorithm,
315+
version = utils::packageVersion("eegUtils")
316+
)
317+
# class(value) <- c("eeg_ICA", "eeg_epochs")
318+
# value <- list(mixing_matrix = mixing_matrix,
319+
# unmixing_matrix = unmixing_matrix,
320+
# signals = signals,
321+
# timings = timings,
322+
# events = events,
323+
# chan_info = chan_info,
324+
# srate = srate,
325+
# epochs = epochs,
326+
# algorithm = algorithm)
327+
# class(value) <- c("eeg_ICA", "eeg_epochs")
328+
# value
329+
}
301330

302-
value <- list(mixing_matrix = mixing_matrix,
303-
unmixing_matrix = unmixing_matrix,
304-
signals = signals,
305-
timings = timings,
306-
events = events,
307-
chan_info = chan_info,
308-
srate = srate,
309-
epochs = epochs,
310-
algorithm = algorithm)
311-
class(value) <- c("eeg_ICA", "eeg_epochs")
312-
value
331+
332+
new_eeg_ICA <- function(mixing_matrix,
333+
unmixing_matrix,
334+
signals,
335+
timings,
336+
events,
337+
chan_info,
338+
srate,
339+
epochs,
340+
algorithm,
341+
version = utils::packageVersion("eegUtils")) {
342+
343+
stopifnot(is.data.frame(mixing_matrix))
344+
stopifnot(is.data.frame(unmixing_matrix))
345+
stopifnot(is.data.frame(signals))
346+
stopifnot(is.data.frame(timings))
347+
stopifnot(is.data.frame(events))
348+
stopifnot(is.data.frame(epochs))
349+
stopifnot(is.data.frame(chan_info))
350+
stopifnot(is.numeric(srate))
351+
stopifnot(is.character(algorithm))
352+
353+
structure(
354+
list(
355+
mixing_matrix = mixing_matrix,
356+
unmixing_matrix = unmixing_matrix,
357+
signals = signals,
358+
timings = timings,
359+
events = events,
360+
chan_info = chan_info,
361+
srate = srate,
362+
epochs = epochs,
363+
algorithm = algorithm,
364+
version = version
365+
),
366+
class = c("eeg_ICA",
367+
"eeg_epochs")
368+
)
313369
}
314370

315371
set_type <- function(x, label) attr(x, "type") <- label
316372

317-
#' Check if object is of class "eeg_data".
373+
#' Check if object is of class `eeg_data`.
318374
#'
319375
#' @author Matt Craddock \email{matt@@mattcraddock.com}
320376
#' @param x Object to check.
321377
#' @keywords internal
322378

323379
is.eeg_data <- function(x) inherits(x, "eeg_data")
324380

325-
#' Check if object is of class "eeg_epochs".
381+
#' Check if object is of class `eeg_epochs`.
326382
#'
327383
#' @author Matt Craddock \email{matt@@mattcraddock.com}
328384
#' @param x Object to check.
@@ -350,14 +406,14 @@ is.eeg_stats <- function(x) inherits(x, "eeg_stats")
350406

351407
is.eeg_ICA <- function(x) inherits(x, "eeg_ICA")
352408

353-
#' Check if object is of class eeg_tfr
409+
#' Check if object is of class `eeg_tfr`
354410
#'
355411
#' @author Matt Craddock \email{matt@@mattcraddock.com}
356412
#' @param x Object to check.
357413
#' @export
358414
is.eeg_tfr <- function(x) inherits(x, "eeg_tfr")
359415

360-
#' Check if object is of class eeg_group
416+
#' Check if object is of class `eeg_group`
361417
#' @param x Object to check.
362418
#' @export
363419
is.eeg_group <- function(x) inherits(x, "eeg_group")

0 commit comments

Comments
 (0)