reref: Rereference Data

View source: R/reref.R

rerefR Documentation

Rereference Data

Description

Compute the average reference or a new common reference for data.

Usage

reref(
  x,
  fs = 1,
  sensors = setdiff(colnames(x), "t"),
  oldref = NULL,
  newref = "robust",
  saveref = FALSE,
  interp = c("post-reference", "pre-reference", "none"),
  estmean = c("median", "huber", "mean"),
  sl = getLocationsfromLabels(colnames(x[, sensors])),
  maxIter = 4
)

Arguments

x

input time series, specified as a numeric matrix or vector. In case of a vector it represents a single signal; in case of a matrix each column is a signal. Alternatively, an object of class ctd

fs

sampling frequency of x in Hz. Default: 1. Overruled if x is a ctd object, in which case the sampling frequency is fs(x).

sensors

vector of sensor names or numbers that are used for the calculations (hence they must contain EEG data). Default: all.

oldref

vector of sensor names or numbers that formed the original reference. If specified, the old reference signal is reconstructed back into the data object (added if it was not present in the data). Ignored if x is an object of class ctd and contains a "ref" attribute. Default: NULL.

newref

signals that form the new reference, either specified as a character vector of signal names (colnames(ctd_obj)), or as a vector of numerical values. If more than one signal is specified, then the average of these signals will form the new reference. Alternatively, specifying "robust" (default) computes an average reference with iterative detection and interpolation of bad channels, and "average" removes the average of the reference channels with no interpolation.

saveref

logical indication whether to save to new reference as a

interp

For newref = "robust", specifies whether to perform final channel interpolation. If "post-reference" (Dafault), after a final robust reference is computed, the channels are re-interpolated and the reference is corrected. In "pre-reference", reref incrementally adds to the bad channel list and interpolates before computing the reference. If the initial estimate of the reference is poor, this is not a good approach. In the "none" option, reref removes the reference but does not interpolate. Bad channels remain in the signal. You may choose to remove them during post-processing.

estmean

For newref = "robust", statistic used for estimation of the mean; one of "median" (default), "huber" or "mean". Median and mean are the obvious statistics; "huber" uses the Huber M-estimator of location with median absolute deviation (MAD) scale, which is computationally expensive.

sl

For newref = "robust", sensor locations of x, specified as a data frame according to sensorlocs format. Alternatively, a matrix with named columns x, y, and z representing the sensor locations. Default: obtained from the sensor names given by the column names of x. Only used in case "when" is either "before" or "after".

maxIter

maximum number of iterations used for detecting noisy channels and recomputing the reference. Default: 4. Only used in case "newref" is "robust".

Details

The function reref computes the mean of the new reference sensors and subtracts that from the channels specified in sensors. If the data were originally referenced with respect to a sensor that is not present in the data, then this sensor will be added, and it can be used in the new reference.

Robust statistics can be used to compute the new reference (median or Huber mean instead of arithmetic mean). In addition, reref can use an iterative procedure to remove bad channels before or after re-referencing, which makes the re-referencing even more robust to outlier sensors. The detection of noisy sensors is done using the noisysensors function, using the default setup.

Value

A list containing the following elements:

y

An object of the same class as the input, containing the re-referenced data. Signals not included in sensors are copied to the output object. If saveref = TRUE then the new reference is added as a separate data channel (column). If the old reference was specified through the oldref parameters, and it was not also present in the data, then it is also added.

fs

the sampling frequency of y

sensors

the sensors that reref operated on (on input)

oldref

the original reference sensor(s)

newref

the new reference sensor(s)

saveref

logical indicating whether the new reference is saved

estmean

for robust referencing, the initial estimate of the mean

interp

for robust referencing the instant of interpolating noisy sensors, either before or after re-referencing

iterations

for robust referencing, the number of iterations performed to detect noisy reference sensors

bad

a list of sensors that were marked as bad by different criteria (see noisysensors)

Author(s)

Geert van Boxtel, G.J.M.vanBoxtel@gmail.com, based on Matlab code of the PREP pipeline by Nima Bigdely-Shamlo and colleagues.

References

Bigdely-Shamlo, N., Mullen, T.,, Kothe, C.,, Su, K.-M., and Robbins, K. A. (2015). The PREP pipeline: standardized preprocessing for large-scale EEG analysis. Frontiers in Neuroinformatics, 9, Article 16, https://www.frontiersin.org/article/10.3389/fninf.2015.00016.

Huber, P.J. (1981) Robust Statistics. Wiley.

See Also

noisysensors, huber

Examples


avgref <- reref(EEGdata, sensors = 1:29, oldref = "M1",
                newref = "average")
lmref <- reref(EEGdata, sensors = 1:29, oldref = "M1", 
                newref = "M1 M2")

## Not run: 
rref <- reref(EEGdata, 1:29, "M1", "robust")

## End(Not run)


gjmvanboxtel/eegr documentation built on May 20, 2023, 4:26 a.m.