cprep: cprep

View source: R/cprep.R

cprepR Documentation

cprep

Description

PREP pipeline for continuous data

Usage

cprep(
  x,
  fs = 1,
  dtsens = setdiff(colnames(x), "t"),
  detrend = c("highpass", "linear", "mean", "constant", "none"),
  hpcf = 1,
  hptbw = 1,
  hpdev = 0.01,
  lnsens = dtsens,
  lfreq = 50,
  fbw = 2,
  w = 4,
  overlap = 0,
  tbw = 2,
  k = round(tbw * w - 1),
  p = 0.01,
  tau = 100,
  MaxIterLn = 10,
  rrsens = lnsens,
  oldref = NULL,
  newref = "robust",
  saveref = FALSE,
  interp = c("post-reference", "pre-reference", "none"),
  estmean = c("median", "huber", "mean"),
  sl = getLocationsfromLabels(colnames(x[, rrsens])),
  MaxIterRR = 4,
  report = paste(getwd(), "cprep_report.pdf", sep = "/")
)

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)

dtsens

sensors to detrend, specified as positive integers indicating sensors numbers, or as sensor names (colnames of x). Default: all sensors names in x excluding a variable t (if present).

detrend

character string indicating which type of trend removal is performed for line noise removal bad channel detection; one of:

highpass

use a high-pass FIR filter with cutoff frequency specified by the parameter hpcf (default)

linear

remove polynomial linear trend

mean|constant

remove mean

none

no detrending

hpcf

high-pass cutoff frequency in Hz, specified as a positive numeric value. Default: 1 Hz

hptbw

high-pass transition bandwith in Hz, specified as a positive numeric value. For instance, if the high-pass cutoff frequency is 1 Hz, and the transition bandwith is also 1 Hz, the transition band of 1 Hz is located between 0.5 and 1.5 Hz. Default: 1 Hz.

hpdev

deviation from desired stop- and passband of the high-pass filter, specified as a positive numeric value. Default: 0.01

lnsens

sensors to remove line noise from, specified as positive integers indicating sensors numbers, or as sensor names (colnames of x). Default: idetical to dtsens.

lfreq

line frequencies to remove, either specified as a single numeric value, or as a character string. If a single numeric value is specified, then this value will be expanded to include multiples of that frequency (harmonics) up to the Nyquist frequency. If a character string is specified, then the string will be converted to numeric values without further expansion. Default: 50

fbw

frequency bandwidth. Bandwidth centered on each lfreq to scan for significant lines. Default: 2 Hz.

w

length of sliding window (segments) in seconds. Default: 4

overlap

proportion of overlap between the segments. Default: 0

tbw

taper bandwidth, specified as a positive numeric value. Default: 2 Hz

k

number of tapers to use, specified as a positive numeric value. Default: tbw * w - 1

p

significance level cutoff for F-test. Default 0.01

tau

Window overlap smoothing factor. Default: 100

MaxIterLn

Maximum times to iterate line noise removal. Default: 10

rrsens

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

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".

MaxIterRR

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

report

name of PDF file to which a detailed processing report is printed, or NULL to suppress the report. Default: "cprep_report.pdf", saved to the current working directory

Value

A list consisting of the following elements:

y

a ctd object containing the robust referenced data

noisyPre

list containing the output from running noisysensors

on the input data

noisyProst

list containing the output from running noisysensors

on the output data

Author(s)

Original Matlab code by Tim Mullen (2011); ported to R and adapted by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com,

See Also

detrend, removetrend cleanline, link{noisysensors}, reref

Examples

## Not run: 
  rr <- cprep(EEGdata[, 1:29], fs = fs(EEGdata))

## End(Not run)
  

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