Package 'PhysioEDA'

Title: Electrodermal Activity Analysis for PhysioExperiment Objects
Description: Provides electrodermal activity (EDA / skin conductance) analysis functions for PhysioExperiment objects. Includes preprocessing (filtering, downsampling), artifact detection and correction, tonic/phasic decomposition (highpass, median, CDA, cvxEDA), SCR peak detection, feature extraction, data transformations, signal quality assessment, visualization, and event-related SCR analysis.
Authors: Yusuke Matsui
Maintainer: Yusuke Matsui <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2026-06-15 03:36:06 UTC
Source: https://github.com/x-biosignal/PhysioEDA

Help Index


Detect and Correct EDA Artifacts

Description

Identifies artifacts in electrodermal activity (EDA) signals using one or more detection methods (threshold, gradient, flatline) and optionally corrects them via interpolation or NA replacement.

Usage

edaArtifact(
  x,
  methods = c("threshold", "gradient", "flatline"),
  threshold_range = c(0.001, 60),
  gradient_max = NULL,
  flatline_sec = 5,
  correct = "interpolate",
  assay_name = NULL,
  output_assay = "cleaned"
)

Arguments

x

A PhysioExperiment object containing EDA data.

methods

Character vector of detection methods to apply. Any combination of "threshold", "gradient", and "flatline". Default is all three.

threshold_range

Numeric vector of length 2 giving the acceptable range of EDA values in microsiemens (default: c(0.001, 60)). Values outside this range are flagged as artifacts.

gradient_max

Maximum allowable absolute gradient in microsiemens per sample. If NULL (default), computed as 10 / samplingRate(x) (equivalent to 10 uS/sec).

flatline_sec

Minimum duration in seconds of a constant-value segment to be flagged as a flatline artifact (default: 5).

correct

Correction strategy: "interpolate" (linear interpolation across artifact regions), "na" (replace with NA), or "none" (detection only, no correction). Default is "interpolate".

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

output_assay

Name for the corrected output assay (default: "cleaned"). Only used when correct != "none".

Value

A modified PhysioExperiment with artifact information stored in metadata(x)$eda_artifacts, a list containing:

mask

Logical matrix (time x channels) where TRUE indicates an artifact sample.

summary

A data.frame with columns channel, method, n_artifacts, and pct giving artifact counts per channel per detection method.

If correct != "none", the corrected signal is stored in the output_assay.

References

Kleckner, I.R., et al. (2018). "Simple, transparent, and flexible automated quality assessment procedures for ambulatory electrodermal activity data." IEEE Transactions on Biomedical Engineering, 65(7), 1460-1467. doi:10.1109/TBME.2017.2758643

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

edaQuality for signal quality assessment, edaFilter for frequency-domain filtering, edaDecompose for tonic/phasic decomposition


Decompose EDA into Tonic and Phasic Components

Description

Separates an electrodermal activity (EDA) signal into its slow-varying tonic component (skin conductance level, SCL) and fast-varying phasic component (skin conductance responses, SCR).

Usage

edaDecompose(
  x,
  method = c("highpass", "median", "cda", "cvxeda"),
  cutoff = 0.05,
  window_sec = 4,
  tau1 = 0.75,
  tau2 = 2,
  alpha = 0.01,
  gamma = 0.1,
  assay_name = NULL,
  output_tonic = "tonic",
  output_phasic = "phasic"
)

Arguments

x

A PhysioExperiment object containing EDA data.

method

Decomposition method: "highpass", "median", "cda", or "cvxeda". Default is "highpass".

cutoff

Cutoff frequency in Hz for the highpass method (default: 0.05).

window_sec

Window length in seconds for the median method (default: 4).

tau1

SCR rise time constant in seconds for CDA/cvxEDA (default: 0.75).

tau2

SCR decay time constant in seconds for CDA/cvxEDA (default: 2.0).

alpha

L1 sparsity penalty for cvxEDA (default: 0.01). Ignored by other methods.

gamma

Smoothness weight for cvxEDA tonic component (default: 0.1). Ignored by other methods.

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

output_tonic

Name for the tonic output assay (default: "tonic").

output_phasic

Name for the phasic output assay (default: "phasic").

Details

Four methods are available:

highpass

FFT-based highpass/lowpass separation at a cutoff frequency.

median

Sliding median filter for tonic extraction.

cda

Continuous Decomposition Analysis (Benedek & Kaernbach, 2010). Deconvolution with a Bateman impulse response, Gaussian smoothing, and non-negativity constraint on the driver signal.

cvxeda

Convex optimization-based decomposition (Greco et al., 2016). Iterative ADMM approach with Wiener deconvolution and L1 sparsity on the driver signal.

Value

A modified PhysioExperiment with new assays:

tonic

The slow-varying skin conductance level (SCL) component.

phasic

The fast-varying skin conductance response (SCR) component.

driver

(CDA and cvxEDA only) The sudomotor nerve activity driver signal.

Decomposition parameters are stored in metadata(x)$eda_decompose.

References

Benedek, M., & Kaernbach, C. (2010). "A continuous measure of phasic electrodermal activity." Journal of Neuroscience Methods, 190(1), 80-91. doi:10.1016/j.jneumeth.2010.04.028

Greco, A., et al. (2016). "cvxEDA: A convex optimization approach to electrodermal activity processing." IEEE Transactions on Biomedical Engineering, 63(4), 797-804. doi:10.1109/TBME.2015.2474131

See Also

edaPeaks for SCR peak detection on the phasic signal, edaFeatures for feature extraction, plotDecompose for visualizing decomposition results


Downsample EDA Signal

Description

Reduces the sampling rate of an EDA signal by first applying an anti-aliasing lowpass filter at half the target sampling rate, then decimating the signal.

Usage

edaDownsample(x, target_sr, assay_name = NULL)

Arguments

x

A PhysioExperiment object containing EDA data.

target_sr

Target sampling rate in Hz. Must be lower than the current sampling rate.

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

Value

A new PhysioExperiment with the downsampled signal in the "raw" assay and the sampling rate set to the actual achieved rate. Events are preserved. Downsampling parameters are stored in metadata(x)$eda_downsample (a list with original_sr, target_sr, factor, original_n_time, and new_n_time).

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

edaFilter for frequency-domain filtering, edaArtifact for artifact detection and correction


Event-Related SCR Analysis

Description

Performs event-related skin conductance response (ER-SCR) analysis by extracting SCR features time-locked to experimental events. For each event, the function searches for an SCR onset within a specified window and, if found, computes amplitude, latency, rise time, and 50 percent recovery time.

Usage

edaErscr(
  x,
  event_type = NULL,
  onset_window = c(1, 4),
  peak_window = c(0.5, 5),
  amplitude_min = 0.01,
  assay_name = NULL
)

Arguments

x

A PhysioExperiment object containing EDA data and events.

event_type

Character string specifying the event type to analyze. If NULL (default), all events are used.

onset_window

Numeric vector of length 2 giving the valid SCR onset latency window in seconds relative to event onset (default: c(1, 4)).

peak_window

Numeric vector of length 2 giving the minimum and maximum time from SCR onset to peak in seconds (default: c(0.5, 5)).

amplitude_min

Minimum SCR amplitude in microsiemens to be considered a valid response (default: 0.01).

assay_name

Name of the assay to use. If NULL, uses "phasic" if available, otherwise the default assay.

Value

A data.frame with one row per event per channel containing columns:

event_index

Integer index of the event.

event_onset

Numeric onset time of the event in seconds.

channel

Character name of the channel.

scr_present

Logical indicating whether a valid SCR was detected.

scr_amplitude

Numeric SCR amplitude (peak minus onset), or NA.

scr_latency

Numeric latency from event to SCR onset in seconds, or NA.

scr_rise_time

Numeric time from SCR onset to peak in seconds, or NA.

scr_recovery_time

Numeric time for 50 percent recovery from peak, or NA.

References

Bach, D.R., et al. (2010). "Modelling event-related skin conductance responses." International Journal of Psychophysiology, 75(3), 349-356. doi:10.1016/j.ijpsycho.2010.01.005

See Also

edaPeaks for general SCR peak detection, edaDecompose for tonic/phasic decomposition (run first), edaFeatures for summary feature extraction, plotPeaks for visualizing SCR peaks


Extract EDA Features per Channel

Description

Computes summary features from electrodermal activity data, including skin conductance response (SCR) statistics and skin conductance level (SCL) measures. Requires tonic/phasic decomposition to have been performed (via edaDecompose).

Usage

edaFeatures(x, peaks = NULL, window = NULL, assay_name = NULL)

Arguments

x

A PhysioExperiment object containing EDA data.

peaks

Optional pre-computed peaks data.frame from edaPeaks. If NULL, peaks are computed automatically using the gradient method.

window

Optional numeric vector of length 2 giving the time window in seconds as c(start_sec, end_sec) to restrict analysis.

assay_name

Name of the input assay for peak detection. If NULL, uses defaultAssay(x).

Value

A data.frame with one row per channel and the following columns:

channel

Character channel label.

scr_count

Integer number of detected SCR peaks.

scr_rate_per_min

Numeric SCR count per minute.

mean_amplitude

Numeric mean SCR peak amplitude in microsiemens (0 if no peaks detected).

mean_scl

Numeric mean tonic skin conductance level.

scl_sd

Numeric standard deviation of the tonic signal.

auc_phasic

Numeric area under the phasic curve (positive values only, in uS*s), or NA if no phasic assay exists.

ns_scr_freq

Numeric non-specific SCR frequency (per minute).

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

Benedek, M., & Kaernbach, C. (2010). "A continuous measure of phasic electrodermal activity." Journal of Neuroscience Methods, 190(1), 80-91. doi:10.1016/j.jneumeth.2010.04.028

See Also

edaDecompose for tonic/phasic decomposition (run first), edaPeaks for SCR peak detection, edaErscr for event-related SCR analysis


Filter EDA Signal

Description

Applies a frequency-domain (FFT-based) filter to an EDA signal. Supports lowpass, highpass, and bandpass filter types using a smooth quadratic transition in the frequency domain.

Usage

edaFilter(
  x,
  type = c("lowpass", "highpass", "bandpass"),
  cutoff,
  order = 2,
  assay_name = NULL,
  output_assay = "filtered"
)

Arguments

x

A PhysioExperiment object containing EDA data.

type

Filter type: "lowpass", "highpass", or "bandpass".

cutoff

Cutoff frequency in Hz. A single numeric value for lowpass or highpass, or a numeric vector of length 2 (c(low, high)) for bandpass.

order

Filter steepness parameter controlling the smoothness of the frequency transition (default: 2). Higher values produce sharper rolloff.

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

output_assay

Name for the output assay (default: "filtered").

Value

A modified PhysioExperiment with filtered data stored in the output_assay and filter parameters recorded in metadata(x)$eda_filter (a list with type, cutoff, order, assay_name, and output_assay).

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

edaDownsample for decimation with anti-aliasing, edaArtifact for artifact detection and correction, edaDecompose for tonic/phasic decomposition


Detect Skin Conductance Response (SCR) Peaks

Usage

edaPeaks(
  x,
  method = c("gradient", "threshold"),
  amplitude_min = 0.01,
  rise_time_min = 0.1,
  rise_time_max = 5,
  assay_name = NULL
)

Arguments

x

A PhysioExperiment object containing EDA data.

method

Detection method: "gradient" (first-derivative zero-crossing) or "threshold" (amplitude threshold). Default is "gradient".

amplitude_min

Minimum SCR amplitude in microsiemens (default: 0.01).

rise_time_min

Minimum rise time in seconds (default: 0.1).

rise_time_max

Maximum rise time in seconds (default: 5.0).

assay_name

Name of the input assay. If NULL, uses "phasic" if available, otherwise defaultAssay(x).

Value

A data.frame with one row per detected SCR and the following columns:

channel

Character channel label.

onset_sample

Integer sample index of SCR onset.

onset_sec

Numeric onset time in seconds.

peak_sample

Integer sample index of SCR peak.

peak_sec

Numeric peak time in seconds.

amplitude

Numeric SCR amplitude in microsiemens (peak minus onset).

rise_time

Numeric rise time from onset to peak in seconds.

recovery_time

Numeric 50\

Returns an empty data.frame with the same columns if no peaks are found.

Identifies SCR peaks in an EDA signal using either a gradient-based zero-crossing method or an amplitude threshold method. Returns onset, peak, amplitude, rise time, and recovery time for each detected SCR.

Bach, D.R., et al. (2010). "Modelling event-related skin conductance responses." International Journal of Psychophysiology, 75(3), 349-356. doi:10.1016/j.ijpsycho.2010.01.005

Benedek, M., & Kaernbach, C. (2010). "A continuous measure of phasic electrodermal activity." Journal of Neuroscience Methods, 190(1), 80-91. doi:10.1016/j.jneumeth.2010.04.028

edaDecompose for tonic/phasic decomposition (run first), edaFeatures for summary feature extraction, plotPeaks for peak visualization, edaErscr for event-related SCR analysis


Assess EDA Signal Quality

Description

Computes per-channel signal quality metrics for electrodermal activity data, including basic statistics, flatline detection, artifact estimation, and an overall quality score.

Usage

edaQuality(x, assay_name = NULL)

Arguments

x

A PhysioExperiment object containing EDA data.

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

Value

A data.frame with one row per channel and the following columns:

channel

Channel label

mean_sc

Mean skin conductance

sd_sc

Standard deviation of skin conductance

min_sc

Minimum skin conductance

max_sc

Maximum skin conductance

pct_negative

Percentage of samples <= 0

pct_flatline

Percentage of signal in flatline segments (runs of consecutive near-zero differences longer than 1 second)

pct_artifact

Percentage of gradient-based artifact samples

snr_db

Estimated signal-to-noise ratio in dB (capped at 60)

quality_score

Overall quality score from 0 to 100

quality_label

"good" (>= 70), "acceptable" (>= 40), or "poor"

References

Kleckner, I.R., et al. (2018). "Simple, transparent, and flexible automated quality assessment procedures for ambulatory electrodermal activity data." IEEE Transactions on Biomedical Engineering, 65(7), 1460-1467. doi:10.1109/TBME.2017.2758643

See Also

edaArtifact for artifact detection and correction, edaFilter for frequency-domain filtering, edaDecompose for tonic/phasic decomposition


Simulate Synthetic EDA Signals

Description

Generates synthetic electrodermal activity (EDA) signals with known tonic (SCL) and phasic (SCR) components for testing and demonstration. SCRs are modeled as biexponential impulse responses (Bateman function).

Usage

edaSimulate(
  n_time = 6000,
  n_channels = 1,
  sr = 10,
  scr_count = 5,
  scl_level = 5,
  scr_amplitude = 0.5,
  noise_sd = 0.01,
  seed = NULL
)

Arguments

n_time

Number of time points (default: 6000).

n_channels

Number of EDA channels (default: 1).

sr

Sampling rate in Hz (default: 10).

scr_count

Number of SCRs to embed (default: 5).

scl_level

Baseline skin conductance level in microsiemens (default: 5.0).

scr_amplitude

Mean SCR amplitude in microsiemens (default: 0.5).

noise_sd

Standard deviation of Gaussian noise (default: 0.01).

seed

Random seed for reproducibility (default: NULL).

Value

A PhysioExperiment object with a single "raw" assay containing the simulated EDA signal (time x channels matrix). Channel metadata has type = "EDA" and unit = "uS". The sampling rate is set to sr.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

Benedek, M., & Kaernbach, C. (2010). "A continuous measure of phasic electrodermal activity." Journal of Neuroscience Methods, 190(1), 80-91. doi:10.1016/j.jneumeth.2010.04.028

See Also

edaDecompose for tonic/phasic decomposition, edaPeaks for SCR detection, edaFilter for signal filtering


Transform EDA Data

Description

Applies a mathematical transformation to EDA signal data. Common transformations include log and square root (to reduce skewness of SCR amplitudes), z-score standardization, and range normalization. Transformation parameters are stored in metadata so that edaUntransform can reverse the operation.

Usage

edaTransform(
  x,
  method = c("log", "sqrt", "zscore", "range"),
  assay_name = NULL,
  output_assay = NULL
)

Arguments

x

A PhysioExperiment object containing EDA data.

method

Transformation method: "log", "sqrt", "zscore", or "range".

assay_name

Name of the input assay. If NULL, uses defaultAssay(x).

output_assay

Name for the output assay. If NULL, defaults to "{method}_transformed".

Value

A modified PhysioExperiment with the transformed assay added and transformation parameters stored in metadata(x)$eda_transform.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

edaUntransform for reversing the transformation, edaFeatures for feature extraction, edaDecompose for tonic/phasic decomposition


Reverse EDA Transformation

Description

Reverses a transformation previously applied by edaTransform, using parameters stored in metadata(x)$eda_transform.

Usage

edaUntransform(x, assay_name = NULL, output_assay = NULL)

Arguments

x

A PhysioExperiment object that has been transformed via edaTransform.

assay_name

Name of the transformed assay to reverse. If NULL, uses the output_assay recorded in the transform metadata.

output_assay

Name for the untransformed output assay. If NULL, defaults to "untransformed".

Value

A modified PhysioExperiment with the untransformed assay added.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

edaTransform for applying the initial transformation, edaDecompose for tonic/phasic decomposition


Create a Simulated EDA PhysioExperiment

Description

Generates a synthetic electrodermal activity (EDA) PhysioExperiment object with known tonic (SCL) and phasic (SCR) components. Useful for testing, demonstrations, and vignettes.

Usage

make_eda(n_time = 6000, n_channels = 1, sr = 10)

Arguments

n_time

Number of time points (default: 6000).

n_channels

Number of EDA channels (default: 1).

sr

Sampling rate in Hz (default: 10).

Value

A PhysioExperiment object with a single "raw" assay containing simulated EDA data. Channel metadata has type = "EDA" and unit = "uS".

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

make_eda_with_scr for EDA with stimulus events, edaSimulate for the underlying simulation function, edaDecompose for tonic/phasic decomposition

Examples

x <- make_eda()
x

Create a Simulated EDA PhysioExperiment with SCR Events

Description

Generates a synthetic electrodermal activity (EDA) PhysioExperiment object with known SCR events time-locked to stimulus markers. The object includes regularly spaced stimulus events stored via PhysioEvents, making it suitable for testing event-related SCR analysis workflows.

Usage

make_eda_with_scr(
  n_time = 6000,
  n_channels = 1,
  sr = 10,
  n_events = 4,
  event_interval = 10
)

Arguments

n_time

Number of time points (default: 6000).

n_channels

Number of EDA channels (default: 1).

sr

Sampling rate in Hz (default: 10).

n_events

Number of stimulus events to embed (default: 4).

event_interval

Interval between events in seconds (default: 10). Note: events are spaced evenly within the usable signal duration rather than at exact fixed intervals.

Value

A PhysioExperiment object with a single "raw" assay containing simulated EDA data and stimulus events accessible via getEvents. Each event has type = "stimulus" and duration = 0.5 seconds.

References

Bach, D.R., et al. (2010). "Modelling event-related skin conductance responses." International Journal of Psychophysiology, 75(3), 349-356. doi:10.1016/j.ijpsycho.2010.01.005

See Also

make_eda for basic EDA without events, edaErscr for event-related SCR analysis, edaSimulate for the underlying simulation function

Examples

x <- make_eda_with_scr()
x

Plot EDA Decomposition

Description

Displays the tonic/phasic decomposition of an EDA signal in a multi-panel layout. Requires that edaDecompose() has been run first so that "tonic" and "phasic" assays exist.

Usage

plotDecompose(
  x,
  channel = 1,
  time_range = NULL,
  main = "EDA Decomposition",
  ...
)

Arguments

x

A PhysioExperiment object with tonic and phasic assays.

channel

Integer or character specifying which channel to plot (default: 1).

time_range

Numeric vector of length 2 giving start and end times in seconds. If NULL, the full signal is plotted.

main

Character string for the overall plot title (default: "EDA Decomposition").

...

Additional arguments passed to plot().

Value

Invisible NULL. Called for its side effect of producing a plot.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

plotEda for basic EDA time series plotting, edaDecompose for performing the decomposition, plotPeaks for SCR peak visualization


Plot EDA Time Series

Description

Plots electrodermal activity signals as time series using base R graphics. Multiple channels are displayed in stacked panels. Optionally overlays vertical event markers.

Usage

plotEda(
  x,
  channels = NULL,
  time_range = NULL,
  assay_name = NULL,
  show_events = TRUE,
  main = "EDA Signal",
  col = NULL,
  ...
)

Arguments

x

A PhysioExperiment object containing EDA data.

channels

Integer or character vector specifying which channels to plot. If NULL (default), all channels are plotted.

time_range

Numeric vector of length 2 giving start and end times in seconds for zooming (e.g., c(10, 30)). If NULL, the full signal is plotted.

assay_name

Name of the assay to plot. If NULL, uses defaultAssay(x).

show_events

Logical; if TRUE (default) and events exist, draws vertical dashed lines at event onsets.

main

Character string for the plot title (default: "EDA Signal").

col

Vector of colors for the channels. If NULL, uses default palette.

...

Additional arguments passed to plot().

Value

Invisible NULL. Called for its side effect of producing a plot.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

plotDecompose for decomposition visualization, plotPeaks for SCR peak visualization, edaDecompose for tonic/phasic decomposition


Plot EDA Signal with SCR Peaks

Description

Plots an EDA signal with detected SCR peaks, onsets, and amplitude lines annotated. If no peaks data.frame is supplied, peaks are computed automatically via edaPeaks.

Usage

plotPeaks(
  x,
  peaks = NULL,
  channel = 1,
  time_range = NULL,
  assay_name = NULL,
  main = "SCR Peaks",
  ...
)

Arguments

x

A PhysioExperiment object containing EDA data.

peaks

A data.frame as returned by edaPeaks, or NULL to compute peaks automatically.

channel

Integer or character specifying which channel to plot (default: 1).

time_range

Numeric vector of length 2 giving start and end times in seconds. If NULL, the full signal is plotted.

assay_name

Name of the assay to plot. If NULL, uses "phasic" if available, otherwise defaultAssay(x).

main

Character string for the plot title (default: "SCR Peaks").

...

Additional arguments passed to plot().

Value

Invisible NULL. Called for its side effect of producing a plot.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer. doi:10.1007/978-1-4614-1126-0

See Also

plotEda for basic EDA time series plotting, plotDecompose for decomposition visualization, edaPeaks for SCR peak detection