Code Monkey home page Code Monkey logo

eegutils's Introduction

eegUtils

Repo Status Coverage Status R-CMD-check

DOI

Overview

eegUtils is a package for the processing, manipulation, and plotting of EEG data. It includes functions for importing data from a variety of file formats (including Biosemi, Brain Vision Analyzer, and EEGLAB), many of the typical steps in pre-preprocessing (filtering, referencing, artefact rejection), more advanced processing techniques (time-frequency analysis, ICA), and several types of plot that are common in the field (ERP plots, time-frequency plots, topographical scalp maps). Although it uses custom object classes, it is designed such that these are always translatable to standard R data.frames, and thus can be used with any of the myriad packages and methods that support standard R formats.

Installation

The package is very much under active development and is subject to a lot of changes. As such, it is not currently available on CRAN.

Install the latest released version from Github as below.

#install.packages("remotes")
remotes::install_github("craddm/eegUtils")

To install the latest development version, install from the develop branch as below.

remotes::install_github("craddm/eegUtils@develop")

You can also find the package on Neuroconductor - for more information about installing packages from Neuroconductor, see the Neuroconductor installation tutorial

Usage

The following examples show how to use eegUtils to produce a few common plots of EEG data from some simple included example data.

ERP butterfly plots

library(eegUtils)
#> 
#> Attaching package: 'eegUtils'
#> The following object is masked from 'package:stats':
#> 
#>     filter
plot_butterfly(demo_epochs)

Topographical plots

topoplot(demo_epochs, 
         time_lim = c(.22, .25 ))
#> Using electrode locations from data.
#> Plotting head r 95 mm

Power spectral density

plot_psd(demo_epochs)
#> Removing channel means per epoch...
#> Computing Power Spectral Density using Welch's method.
#> FFT length: 256
#> Segment length: 84
#> Overlapping points: 42 (50% overlap)

Time-frequency analysis

plot_tfr(compute_tfr(demo_epochs,
                     foi = c(4, 30),
                     n_freq = 20,
                     n_cycles = 3))
#> Computing TFR using Morlet wavelet convolution
#> Output frequencies using linear spacing: 4 5.37 6.74 8.11 9.47 10.84 12.21 13.58 14.95 16.32 17.68 19.05 20.42 21.79 23.16 24.53 25.89 27.26 28.63 30
#> Removing channel means per epoch...
#> Returning signal averaged over all trials.

There are many potential processing steps that precede the production of plots like these. For more examples of how to import and process data, or import data from other sources, see the eegUtils website!

Contributing

If you have any bug reports or feature requests, please report them using the Github issue tracker.

If you would like to contribute any code, be that anything from a documentation fix to a whole new feature, then please begin by raising an issue before moving on to file a Github pull request.

You can find a guide to how Github issues and pull requests work here.

Code of Conduct

Please note that the eegUtils project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

eegutils's People

Contributors

craddm avatar erzk avatar muschellij2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eegutils's Issues

Support for file formats other than BDF/EDF

Currently import_raw() only handles BDF/EDF files, thanks to the edfReader package. I'd like to extend support to other file formats, such as those from EGI or Neuroscan systems.

erp_scalp ignoring chan_info

erp_scalp should use chan_info structure when it's available, instead of always trying to overwrite the montage. Needs a broader rework to ensure proper use of canvas space etc.

Installation issue (macOS Catalina problem?)

Hi,

I've just tried to install eegUtils via RStudio (R version 3.6.1) and I got this error:

Error: Failed to install 'eegUtils' from GitHub:
(converted from warning) unable to access index for repository https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6:
cannot open URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/PACKAGES'

I suspect it might be related to the fact that I'm currently using macOS Catalina, since I didn't encounter any error in the past when using eegUtils. What do you think?

Many thanks for your time.
Alberto

Reading EDF/BDF is slow

edfReader seems to be slow considering the size of the files being loaded; replace with custom routines?

Tibble 2.0 issues

Getting warnings when running electrode_locations:

The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0.
Using compatibility `.name_repair`.

handling missing channel information

eeg_FASTER and interp_elecs don't correctly handle channels that are either not in the channel info at all, or have elements missing (e.g. co-ordinates are NA)

epoching data sometimes fails

Epoching data sometimes causes problems when requested time limits don't hit zero at a given sampling rate. E.g. epoch limits of -.3, .75 fail at 256 Hz.

Other montages

I work in a lab that has custom caps and electrode locations. Is it possible to define/enter custom electrode locations so that topoplot() can display maps properly?

rm_baseline() sometimes does not properly respect group_by

Noticed with normal data.frame, not eeg_data class - seems to ignore grouping by epoch sometimes, thus baseline corrects with the average across all epochs instead of the average from each epoch.

edit - seems to be an awkward interaction with data that's already grouped on input.

OSX tests fail

Dear Matt,

The test-ICA.R tests are failing on OSX.

── 1. Failure: topoplots for ICA work (@test-ICA.R#14)  ───────────────────────
Figures don't match: topographical-plot-for-sobi.svg


── 2. Failure: ICA timecourses work (@test-ICA.R#26)  ─────────────────────────
Figures don't match: timecourse-over-one-component.svg


── 3. Failure: component removal works (@test-ICA.R#39)  ──────────────────────
Figures don't match: removed-one-component.svg


── 4. Failure: component removal works (@test-ICA.R#41)  ──────────────────────
Figures don't match: reconstruct-all.svg

Any idea what is causing this?

Thanks!

Trouble using electrode locations from R package eegkit

I am having trouble with topoplot() when using electrode locations provided in the eegkit R package (data(eegcoord, package = "eegkit")). I assume those locations are fairly standard.

Here's the result when I use those locations, with data d:

topoplot(d)

rplot

I have fixed these issues and made topoplot() load these locations by default if locations are not passed in data. Resulting figure is here (I've added a few options e.g. argument for contours):

topoplot(d, rmax = 10, chan_marker = "name", contour=F)

better

The fixes can be found here: https://github.com/mvuorre/eegUtils. I haven't submitted a pull request because I'm not sure if you'd want to use these electrode locations as default (or if the changes are good overall.) Let me know if you'd like me to submit it, though.

Thanks for the great function(s)!

psd output fixes needed

make sure when epochs are kept that epoch number is numeric and and any epoch labels are included

BIDS compatibility

Now that BIDS-EEG is being formalized, time to start making my data structures more compatible

eeg_combine for eeg_tfr

Fails when unequal number of epochs.
Does not check order of epochs across objects, which causes problems with averaged eeg_tfr objects.
Need to implement much more detailed checking of objects since eeg_tfr uses matrices internally

Installation code wrong in README.md

Just went to install the package by copy/pasting the code from the README.md and got the error Error: 'install_packages' is not an exported object from 'namespace:devtools'. It was easy to fix by replacing the install_packageswith install_github, but I figured you might want to know so you can update the README with the proper command. Thanks for creating/maintaining the package!

eggcap color for multiple electrodes

Hi,
I was trying to select another color for 6 electrodes in 10-20 system; however, r only changes the color for 3 of them. I'm pretty sure it's a minor issue, but since I was not able to solve it, I came here to ask you guys.

`data(eegcoord)
myelectrodes <- rep("light blue",87)
enames <- rownames(eegcoord)
myelectrodes[enames=="A1"] <- "red"
myelectrodes[enames=="A2"] <- "red"
myelectrodes[enames=="C4"] <- "red"
myelectrodes[enames=="F7"] <- "red"
myelectrodes[enames=="O1"] <- "red"
myelectrodes[enames=="O2"] <- "red"

eegcap(electrodes = "10-20", col.point = myelectrodes)`

eeg_filter() should have parameter to adapt demeaning behavior

when using eeg_filter() on non-raw data (e.g., for plotting) it would be handy to manipulate (or at least deactivate) the demeaning feature of the function.
In a concrete case: when lp-filtering epoched data for plotting, epochs with high amplitude slow negative potentials (lasting for the bigger part of the epoch) were "pushed upwards", i.e. baseline signal was constant above x-axis. For such a case, it would be good to be able to either deactivate the demeaning or have a parameter that is forwarded to rm_baseline() to specify the baseline time window (i.e., time_lim).

TODO:

  • Decompose topoplot and other plotting functions into parts and add as ggplot extensions (e.g. geom_topo) as well as monolothic functions mostly done but contours are a problem...
  • Rewrite functions as S3 methods where possible/necessary
  • New object classes for PSD, ICA etc. (new ICA and TFR classes added)
  • Add artefact detection (absolute threshholding, probability measures etc)
  • Implement FASTER (mostly done - only ICA and GA left...)
  • Channel interpolation Spherical spline implemented
  • Improve data browsing speed
  • Allow visualization of artefact rejections
  • Implement multiple ICA methods and browsing of those methods - SOBI, fastica, infomax available
  • Add methods for removal of ICA components
  • Add frequency analyses (PSD added, TFR in progress) - Morlet wavelet TFR added
  • Reducing the number of external Depends to <=20
  • Better tidyverse support - e.g. wrappers around dplyr functions, currently some done for select(), filter(), mutate, and rename
  • Decide on format of channel locations.
  • DOCUMENTATION, DOCUMENTATION, DOCUMENTATION! Vignettes etc...
  • Improve implementation of glm fitting - allow adding baseline as a covariate etc-
  • add boundaries when combining continuous data across files
  • tests for more complex objects (e.g. groups, TFR evokeds etc)
  • Allow log-spacing of frequencies in compute_tfr() and check how plot_tfr() can handle them
  • Improve S3 class documentation

Plot ERPs on the scalp

Hi,

Any plans on implementing a function for a plot that shows a topographic arrangement of ERPs? I've been working on one here, and can send in a pull request if it's a feature you'd like to add to eegUtils.

Here's sample output from the function on my dev branch:

erp_scalp(data, color = "group")

rplot

topoplot does not scale

Topoplots are a great feature of eegUtils, but forcing them to look nice on a 5x5cm figure is a pain (requires hacks using ggplot_build() / ggplot_gtable()). It would be great if topoplot had an optional argument with a scaling factor and have all line weights in contours be based on this factor.

import_raw error when the edf file contains annotations

I imported many edf files without problems using import_raw, but noticed that some files produced an error.

I realized that these files contain annotations. The error does not occur when the code in import_raw:

data <- edfReader::readEdfSignals(edfReader::readEdfHeader(file_name))

is replaced by

data <- edfReader::readEdfSignals(edfReader::readEdfHeader(file_name), signals = "Ordinary")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.