outliers_epoch: Select outlier epochs

View source: R/outliers_epoch.R

outliers_epochR Documentation

Select outlier epochs

Description

Function for selecting outlier epochs for one subject and one sensor in chosen time points. Epochs are marked as outliers based on one of the following criteria: interquartile range criterion, percentile approach or Hampel filter method.

Usage

outliers_epoch(
  data,
  amplitude = "signal",
  subject = NULL,
  sensor = NULL,
  time = NULL,
  method,
  k_iqr = 1.5,
  k_mad = 3,
  p = 0.975,
  print_tab = TRUE
)

Arguments

data

A data frame, tibble or a database table with input data, required columns: subject, sensor, time, epoch and the column with EEG amplitude named as in amplitude parameter.

amplitude

A character specifying the name of the column from input data with an EEG amplitude values. Default is "signal".

subject

An integer or character ID of selected subject.

sensor

An integer or character ID of selected sensor.

time

A vector with time range for outliers detection. If not defined, the outliers are searched for all time points in the dataset.

method

A character denoting the method used for outlier detection. The options are: "iqr" for interquartile range (IQR) criterion, "percentile" for percentile method and "hampel" for Hampel filter method. See details for further information about methods.

k_iqr

A positive numeric value denoting the scaling factor used in the IQR criterion. Default value is k_iqr = 1.5.

k_mad

A positive numeric value denoting the scaling factor used in the Hampel filter method. Default value is k_mad = 3.

p

A probability value from [0,1] interval determining percentile to the percentile method (according to probs argument in quantile() function). The default value is set to 0.975 for the interval formed by the 2.5 and 97.5 percentiles.

print_tab

Logical. Indicates, whether result table should be printed in console. Default is TRUE.

Details

The input data frame or database table must contain at least following columns: subject - a column with subject IDs, sensor - a column with sensor labels, time - a column with time point numbers, signal (or other name specified in amplitude parameter) - a column with measured EEG signal values.

The outlier detection method is chosen through method argument. The possibilities are

  • iqr: The interquartile range criterion, values outside the interval [lower quartile - k_iqr * IQR, upper quartile + k_iqr * IQR] are considered as outliers. IQR denotes interquartile range and k_iqr the scaling factor.

  • percentile: The percentile method, values outside the interval defined by the chosen percentiles are considered as outliers. Note: chosing small pleads to marking too many (or all) values.

  • hampel: The Hampel filter method, values outside the interval [median - k_mad * MAD, median + k_mad * MAD] are considered as outliers. MAD denotes median absolute deviation and k_mad the scaling factor. Each of the above methods operates independently per time point, not globally across time.

Value

A list with following components:

epoch_table

A data frame with epoch ID and the number of time points in which the epoch was evaluated as outlier. (Only epochs with occurrence of outliers in at least one time point are included.)

outliers_data

A data frame with subset of data corresponding to the outliers found. (The full record for each flagged point from epoch_table.)

With the setting print_tab = TRUE, the epoch_table is also printed to the console.

Examples

# Outlier epoch detection for subject 2, electrode E45 for the whole time range with IQR method
outliers_epoch(epochdata, amplitude = "signal", subject = 2, sensor = "E45", method = "iqr")
# From the result table we see that epochs 14 and 15 were marked as outliers in 50 cases out of 50

# Outlier epoch detection for subject 2, electrode E45 for the whole time range
# using percentile method with 1 and 99 percentiles
outliers_epoch(epochdata, amplitude = "signal", subject = 2, sensor = "E45",
 method = "percentile", p = 0.99)

diegr documentation built on Nov. 5, 2025, 5:25 p.m.