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 [aut, cre]
Maintainer: Yusuke Matsui <[email protected]>
License: MIT + file LICENSE
Version: 0.2.4
Built: 2026-10-03 13:41:53 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 epoch-based wavelet / machine-learning methods) and optionally corrects them via interpolation or NA replacement. An accelerometer channel can additionally gate out high-motion epochs (Taylor et al., 2015).

Usage

edaArtifact(
  x,
  methods = c("threshold", "gradient", "flatline"),
  threshold_range = c(0.001, 60),
  gradient_max = NULL,
  flatline_sec = 5,
  epoch_sec = 5,
  wavelet_k = 5,
  ml_threshold = 0.5,
  acc_channel = NULL,
  acc_threshold = NULL,
  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", "flatline", "wavelet" (per-5 s-epoch stationary-wavelet fine-scale energy outliers), and "ml" (a shipped ridge-logistic classifier on wavelet/derivative epoch features). Default is the first 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).

epoch_sec

Epoch length in seconds for the "wavelet" / "ml" methods and accelerometer gating (default: 5).

wavelet_k

Robust-outlier multiplier for the "wavelet" method; an epoch is flagged when its peak level-1 detail coefficient exceeds median + wavelet_k * MAD across epochs (default: 5).

ml_threshold

Probability threshold for the "ml" method's binary label (default: 0.5).

acc_channel

Optional channel index or label (or several) identifying accelerometer channel(s). When supplied, per-epoch motion energy (variance of the accelerometer magnitude) gates the EDA channels: epochs with energy above acc_threshold are flagged. The accelerometer channels are excluded from EDA artifact detection.

acc_threshold

Motion-energy threshold for accelerometer gating. If NULL (default), computed robustly as median + 3 * MAD of the per-epoch motion energies.

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.

epochs

(only when "wavelet"/"ml" or accelerometer gating is used) A data.frame, one row per EDA channel per epoch, with the epoch bounds and, as applicable, wavelet_flag, ml_prob, ml_flag, motion_energy, and acc_flag.

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

References

Taylor, S., et al. (2015). "Automatic identification of artifacts in electrodermal activity data." IEEE EMBC, 1934-1937. doi:10.1109/EMBC.2015.7318762

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xa <- edaArtifact(x, methods = c("threshold", "gradient"), correct = "none")
S4Vectors::metadata(xa)$eda_artifacts$summary

Dynamic Causal Model for Skin-Conductance Responses

Description

Estimates trial-by-trial latent sudomotor input amplitudes that best explain the skin-conductance signal, in the spirit of the PsPM dynamic causal model for SCR (Bach et al., 2010, 2011). Each event contributes a non-negative latent input whose skin-conductance response is the canonical scrf kernel; the per-event amplitudes are estimated by non-negative least squares against a low-frequency cosine drift basis, and the input timings are optionally refined by a nonlinear local search (the "dynamic" step).

Usage

edaDCM(
  x,
  events,
  channel = 1,
  assay_name = NULL,
  tau1 = 0.75,
  tau2 = 2,
  drift = 6,
  refine_latency = TRUE,
  latency_window = 1.5
)

Arguments

x

A PhysioExperiment object with EDA data.

events

A data.frame with numeric onset (seconds); a condition column is optional and carried through.

channel

EDA channel index or label (default: 1).

assay_name

Input assay (default: defaultAssay(x)).

tau1, tau2

SCR rise/decay time constants in seconds.

drift

Number of cosine drift terms (default: 6).

refine_latency

Logical; refine each event's onset by a local search to improve the fit (default: TRUE).

latency_window

Half-width in seconds of the latency search (default: 1.5).

Details

Unlike edaGLM, which estimates one amplitude per condition, edaDCM estimates one latent input amplitude per event.

Value

A list of class "eda_dcm" with:

estimates

a data.frame with event, onset, onset_refined, amplitude (per-event latent input), and condition if present.

fitted

fitted signal; residuals; r_squared.

References

Bach, D.R., Daunizeau, J., Friston, K.J., & Dolan, R.J. (2010). "Dynamic causal modelling of anticipatory skin conductance responses." Biological Psychology, 85(1), 163-170. doi:10.1016/j.biopsycho.2010.06.007

See Also

edaGLM for the condition-level GLM, scrf for the response kernel.

Examples

ev <- data.frame(onset = c(10, 30, 50, 70))
pe <- edaSimulate(n_time = 1000, sr = 10, scr_count = 4, seed = 1)
fit <- edaDCM(pe, ev, refine_latency = FALSE)
fit$estimates

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", "dda", "cvxeda", "cvxeda_fast"),
  cutoff = 0.05,
  window_sec = 4,
  tau1 = 0.75,
  tau2 = 2,
  alpha = 0.01,
  gamma = 0.1,
  delta_knot = 10,
  qp_sr = 4,
  optimize_tau = FALSE,
  assay_name = NULL,
  output_tonic = "tonic",
  output_phasic = "phasic"
)

Arguments

x

A PhysioExperiment object containing EDA data.

method

Decomposition method: "highpass", "median", "cda", "dda", "cvxeda", or "cvxeda_fast". 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.

delta_knot

Tonic spline knot spacing in seconds for the "cvxeda" QP (default: 10).

qp_sr

Target rate (Hz) at which the "cvxeda" QP is solved; the signal is decimated towards this rate for tractability (default: 4).

optimize_tau

Logical; for "cda" / "dda", optimise the decay constant tau2 to minimise the driver's negative energy (default: FALSE).

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

Six 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 a non-negativity constraint on the driver signal; optional tau2 optimisation.

dda

Discrete Decomposition Analysis (Benedek & Kaernbach, 2010): the continuous CDA driver is reduced to a sparse impulse train (one impulse per significant SCR) and reconvolved.

cvxeda

Convex optimization decomposition (Greco et al., 2016), solved as a quadratic program: a cubic-knot spline tonic basis and a sparse, non-negative sudomotor driver through a biexponential system, with L1 sparsity on the driver and L2 smoothness on the tonic. Requires the quadprog solver; degrades gracefully to the Wiener approximation if it is unavailable.

cvxeda_fast

Fast Wiener/ADMM approximation of cvxEDA (no solver dependency); the original iterative approximation.

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 variants only) The sudomotor nerve activity driver signal.

Decomposition parameters are stored in metadata(x)$eda_decompose; for method = "cvxeda" this also records the per-channel solver engine ("qp" or "wiener_fallback") and final QP objective.

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xd <- edaDecompose(x, method = "highpass")
SummarizedExperiment::assayNames(xd)

# cvxEDA solves a quadratic program via the quadprog Suggests dependency
xc <- edaDecompose(x, method = "cvxeda")

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xd <- edaDownsample(x, target_sr = 5)
samplingRate(xd)

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

Examples

x <- make_eda_with_scr(n_time = 1200, sr = 10, n_events = 4)
x <- edaDecompose(x)
edaErscr(x)

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,
  ns_scr_amplitude_min = 0.05
)

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

ns_scr_amplitude_min

Minimum SCR amplitude (in uS) to count a peak as a non-specific SCR (default 0.05, the standard threshold).

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_count

Integer count of non-specific SCRs (amplitude >= ns_scr_amplitude_min).

ns_scr_freq

Numeric non-specific SCR frequency (per minute): ns_scr_count / duration_min.

cda_nscr

Integer number of significant SCRs in the CDA/DDA driver, or NA if no driver assay exists.

cda_ampsum

Numeric sum of the CDA/DDA driver SCR amplitudes (uS), or NA.

cda_iscr

Numeric integrated SCR: time-integral of the phasic driver (uS*s), or NA.

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
x <- edaDecompose(x)
edaFeatures(x)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xf <- edaFilter(x, type = "lowpass", cutoff = 1)
SummarizedExperiment::assayNames(xf)

PsPM-style GLM for Skin-Conductance Responses

Description

Fits a general linear model of the skin-conductance signal against event-related regressors, each a stick function at the event onsets convolved with the canonical skin-conductance response function (scrf; Bach & Friston, 2013). Events are grouped into conditions; each condition yields an amplitude estimate (beta) with a standard error and t statistic. A low-frequency cosine drift basis absorbs the tonic level. Optionally, a temporal-derivative basis is added per condition to accommodate response latency differences.

Usage

edaGLM(
  x,
  events,
  conditions = NULL,
  channel = 1,
  assay_name = NULL,
  tau1 = 0.75,
  tau2 = 2,
  basis = c("canonical", "derivative"),
  drift = 6
)

Arguments

x

A PhysioExperiment object with EDA data.

events

A data.frame with numeric onset (seconds) and a condition column grouping events.

conditions

Optional character vector selecting/ordering the conditions (default: the unique conditions in events).

channel

EDA channel index or label to model (default: 1).

assay_name

Input assay (default: defaultAssay(x)).

tau1, tau2

SCR rise/decay time constants in seconds.

basis

"canonical" (SCRF only) or "derivative" (SCRF plus its temporal derivative per condition).

drift

Number of cosine drift terms (default: 6).

Value

A list of class "eda_glm" with:

coefficients

a data.frame with condition, beta, se, t, p (canonical amplitude per condition; NA for a condition dropped due to collinearity).

derivative

(basis = "derivative") the derivative-regressor betas.

fitted

fitted signal; residuals; sigma; df; r_squared; rank; n_regressors; collinear.

References

Bach, D.R., & Friston, K.J. (2013). "Model-based analysis of skin conductance responses." Psychophysiology, 50(1), 15-22. doi:10.1111/j.1469-8986.2012.01483.x

See Also

edaDCM for trial-wise latent input estimation, scrf for the response kernel.

Examples

ev <- data.frame(onset = c(10, 30, 50, 70), condition = c("A", "A", "B", "B"))
pe <- edaSimulate(n_time = 1000, sr = 10, scr_count = 4, seed = 1)
fit <- edaGLM(pe, ev)
fit$coefficients

Detect Skin Conductance Response (SCR) Peaks

Description

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.

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% recovery time in seconds, or NA.

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

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

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), edaFeatures for summary feature extraction, plotPeaks for peak visualization, edaErscr for event-related SCR analysis

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
x <- edaDecompose(x)
head(edaPeaks(x))

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
edaQuality(x)

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. The ground-truth components used to build the signal are stored in metadata(x)$eda_truth as a list with:

tonic

time x channels matrix of the true tonic (SCL) component.

phasic

time x channels matrix of the true phasic (SCR) component.

onsets

a data.frame of the true SCR onsets with columns channel, sample, time_sec, and amplitude.

This lets edaSimulate() serve as a ground-truth oracle for testing decomposition (e.g. edaDecompose with method="cvxeda").

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
x
str(S4Vectors::metadata(x)$eda_truth, max.level = 1)

Sympathetic skin response (SSR) analysis

Description

Extracts the sympathetic skin response evoked by each stimulus from a skin conductance recording: the response onset latency, the baseline-to-peak amplitude, the waveform morphology (monophasic / biphasic) and a present/absent classification. A per-channel summary reports the response rate, mean latency and amplitude, an amplitude-habituation slope across the repeated stimuli, and the clinical absent-SSR flag.

Usage

edaSSR(
  x,
  stimulus_events,
  assay_name = NULL,
  response_window = c(0.5, 8),
  baseline_sec = 2,
  amplitude_min = 0.05,
  recovery_frac = 0.1,
  onset_frac = 0.05,
  morphology_frac = 0.3,
  events_unit = c("auto", "index", "seconds")
)

Arguments

x

A PhysioExperiment object with a skin conductance assay.

stimulus_events

Stimulus times, as sample indices or times in seconds (see events_unit).

assay_name

Input assay (default: defaultAssay(x)).

response_window

Numeric c(start, end) seconds after each stimulus in which the SSR is sought (default c(0.5, 8)).

baseline_sec

Length in seconds of the pre-stimulus window used to estimate and remove the tonic trend (default 2).

amplitude_min

Minimum detrended peak amplitude (uS) for a response to count as present (default 0.05).

recovery_frac

Fraction of the peak amplitude the trace must fall back after the peak for the response to be accepted as phasic (rather than a monotone drift; default 0.1).

onset_frac

Fraction of the SSR amplitude above baseline at which the response onset (and hence latency) is marked (default 0.05).

morphology_frac

Fraction of the SSR amplitude an opposite-going deflection must reach for the response to be classed biphasic (default 0.3).

events_unit

Unit of stimulus_events: "auto" (default), "index" or "seconds".

Details

The tonic trend estimated from the pre-stimulus baseline is subtracted from each response window, so slow skin-conductance drift is neither counted as a response nor mistaken for a biphasic deflection. In the detrended window the phasic peak is located; a response is accepted only if it exceeds amplitude_min and recovers (rises then falls), and the latency is measured from the stimulus to the onset of that phasic deflection (Vetrugno et al. 2003).

Value

An eda_ssr object with responses (one row per stimulus per channel: channel, stimulus, stim_time, present, latency, amplitude, peak_time, morphology) and summary (one row per channel: channel, n_stimuli, n_present, response_rate, mean_latency, mean_amplitude, habituation_slope, ssr_absent).

References

Vetrugno, R. et al. (2003). Sympathetic skin response: basic mechanisms and clinical applications. Clin Auton Res 13(4):256-270.

See Also

edaSympatheticIndex()

Examples

# 3 stimuli at 10, 40 and 70 s, each followed by an SCR
pe <- edaSimulate(n_time = 900, sr = 10, scr_count = 0, seed = 1)
sig <- as.numeric(SummarizedExperiment::assay(pe))
sr <- 10
for (st in c(10, 40, 70)) {
  t <- (seq_along(sig) - 1) / sr - st
  sig <- sig + 0.5 * ifelse(t > 0, (exp(-t / 3) - exp(-t / 0.75)), 0)
}
SummarizedExperiment::assay(pe) <- matrix(sig, ncol = 1)
res <- edaSSR(pe, stimulus_events = c(10, 40, 70), events_unit = "seconds")
res$summary

Electrodermal sympathetic index (EDASymp)

Description

Spectral power of the electrodermal signal in the sympathetic band (0.045-0.25 Hz by default), following Posada-Quintero et al. (2016). The signal is optionally downsampled, its Welch power spectral density is estimated, and the band power is reported both in absolute units and normalised by the total spectral power.

Usage

edaSympatheticIndex(
  x,
  band = c(0.045, 0.25),
  assay_name = NULL,
  resample_hz = 2,
  seg_sec = NULL
)

Arguments

x

A PhysioExperiment object with an electrodermal assay.

band

Numeric c(low, high) sympathetic band in Hz (default c(0.045, 0.25)).

assay_name

Input assay (default: defaultAssay(x)).

resample_hz

Rate (Hz) the signal is downsampled to before spectral estimation (default 2; NULL keeps the native rate). Ignored if it is not below the native sampling rate.

seg_sec

Welch segment length in seconds (NULL = one whole-signal Hann window).

Value

A data frame with one row per channel: channel, edasymp (absolute band power), edasymp_norm (band power / total power, in ⁠[0, 1]⁠, or NA for a constant / zero-power channel), total_power, and the band_low/band_high used.

References

Posada-Quintero, H.F. et al. (2016). Power spectral density analysis of electrodermal activity for sympathetic function assessment. Ann Biomed Eng 44(10):3124-3135.

See Also

edaTVSymp()

Examples

pe <- edaSimulate(n_time = 1200, sr = 4, scr_count = 6, seed = 1)
edaSympatheticIndex(pe)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xt <- edaTransform(x, method = "log")
SummarizedExperiment::assayNames(xt)

Time-varying electrodermal sympathetic index (TVSymp)

Description

A time-resolved sympathetic-tone index built by complex demodulation of the dominant components of the electrodermal signal in the sympathetic band (Posada-Quintero et al. 2016). The two strongest spectral components in the band are demodulated to their instantaneous amplitudes, combined, and normalised to a reproducible trajectory that rises when sympathetic oscillations appear.

Usage

edaTVSymp(
  x,
  band = c(0.08, 0.24),
  assay_name = NULL,
  resample_hz = 2,
  n_components = 2,
  lp_hz = NULL
)

Arguments

x

A PhysioExperiment object with an electrodermal assay.

band

Numeric c(low, high) sympathetic band in Hz (default c(0.08, 0.24)).

assay_name

Input assay (default: defaultAssay(x)).

resample_hz

Rate (Hz) the signal is downsampled to (default 2; NULL keeps the native rate).

n_components

Number of dominant band components to demodulate (default 2).

lp_hz

Low-pass cutoff (Hz) of the demodulation envelope (default 0.5 of the band width).

Value

A data frame with one row per time sample per channel: channel, time_sec, tvsymp (combined instantaneous amplitude) and tvsymp_norm (unit-variance normalised). The dominant component frequencies are attached as the "components" attribute.

References

Posada-Quintero, H.F. et al. (2016). Time-varying analysis of electrodermal activity during exercise. PLoS ONE 11(8):e0161553.

See Also

edaSympatheticIndex()

Examples

pe <- edaSimulate(n_time = 1200, sr = 4, scr_count = 6, seed = 1)
tv <- edaTVSymp(pe)
head(tv)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
xt <- edaTransform(x, method = "log")
xu <- edaUntransform(xt)
SummarizedExperiment::assayNames(xu)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
x <- edaDecompose(x)
plotDecompose(x)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
plotEda(x)

Grand-average event-related skin conductance response (ER-SCR)

Description

Computes and plots the grand-average phasic skin-conductance waveform time-locked to stimulus events, separately per event type (condition), with a confidence-interval band. Each event's epoch over window is baseline corrected against the pre-event baseline interval, epochs are averaged within a condition, and the band is the standard error of the mean scaled to ci_level (Boucsein 2012; Bach event-related SCR averaging). The epoching reuses the event onsets from getEvents() on the same sample grid as edaErscr().

Usage

plotErscrGrandAverage(
  x,
  event_types = NULL,
  window = c(-1, 6),
  baseline = c(-1, 0),
  channel = 1,
  assay_name = NULL,
  ci = c("sem", "none"),
  ci_level = 0.95,
  colors = NULL,
  plot = TRUE,
  ...
)

Arguments

x

A PhysioExperiment object with a skin conductance assay and events.

event_types

Character vector of event types to average and overlay; NULL (default) uses every event type present.

window

Numeric c(pre, post) epoch limits in seconds relative to the event onset (default c(-1, 6)).

baseline

Numeric c(start, end) pre-event baseline interval in seconds subtracted from each epoch, or NULL for no baseline correction (default c(-1, 0)).

channel

Channel index to average (default 1).

assay_name

Input assay (default: defaultAssay(x)).

ci

Confidence band: "sem" (mean +/- z * SEM, default) or "none".

ci_level

Confidence level for the SEM band (default 0.95).

colors

Optional per-condition colours (recycled).

plot

Draw the plot (default TRUE); set FALSE to only compute.

...

Additional arguments passed to plot().

Value

Invisibly, an erscr_grand_average object with grand_average (a tidy data frame of type, time, mean, sd, sem, ci_lower, ci_upper, n_trials), the per-condition baseline-corrected epochs matrices, and the time axis.

References

Boucsein, W. (2012). Electrodermal Activity. 2nd ed. Springer.

See Also

edaErscr()

Examples

x <- make_eda_with_scr()
ga <- plotErscrGrandAverage(x, plot = FALSE)
head(ga$grand_average)

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

Examples

x <- edaSimulate(n_time = 600, sr = 10, seed = 1)
x <- edaDecompose(x)
plotPeaks(x)

Skin-Conductance Response Function (SCRF)

Description

First-class canonical skin-conductance response kernel used throughout PhysioEDA as the single source of the SCR shape (simulation, CDA / cvxEDA deconvolution, and GLM designs). The response is the biexponential (Bateman) function h(t) = exp(-t / tau2) - exp(-t / tau1) for t >= 0 (0 otherwise), optionally augmented with a Gaussian bump for the PsPM-style canonical form (Bach et al., 2010). Both the kernel and its first/second time-derivatives are available (the derivatives drive GLM temporal/dispersion regressors).

Usage

scrf(
  t,
  tau1 = 0.75,
  tau2 = 2,
  form = c("bateman", "pspm_canonical"),
  normalize = c("peak", "area", "none"),
  deriv = 0,
  bump_amp = 0.3,
  bump_center = NULL,
  bump_sd = 0.7
)

Arguments

t

Numeric vector of times in seconds. Values < 0 return 0.

tau1

SCR rise time constant in seconds (default: 0.75).

tau2

SCR decay time constant in seconds (default: 2.0). Must differ from tau1; the canonical shape has tau2 > tau1.

form

Kernel family: "bateman" (pure biexponential) or "pspm_canonical" (biexponential plus a Gaussian bump).

normalize

Normalisation of the kernel: "peak" (unit maximum, the default), "area" (unit integral), or "none" (raw). Derivatives are scaled by the same constant.

deriv

Derivative order to return: 0 (kernel), 1, or 2.

bump_amp

Gaussian bump amplitude, relative to the raw Bateman peak, for form = "pspm_canonical" (default: 0.3; ignored otherwise).

bump_center

Gaussian bump centre in seconds (default: the analytic Bateman peak time).

bump_sd

Gaussian bump standard deviation in seconds (default: 0.7).

Value

A numeric vector the same length as t: the requested derivative of the (optionally normalised) response kernel.

References

Bach, D.R., Flandin, G., Friston, K.J., & Dolan, R.J. (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

scrfPeak for the analytic Bateman maximum, edaSimulate and edaDecompose which consume it.

Examples

t <- seq(0, 15, by = 0.1)
k <- scrf(t)                       # unit-peak Bateman kernel
dk <- scrf(t, deriv = 1)           # its temporal derivative
ck <- scrf(t, form = "pspm_canonical")

Analytic peak of the Bateman SCRF

Description

Returns the closed-form time and amplitude of the maximum of the raw biexponential (Bateman) response used by scrf.

Usage

scrfPeak(tau1 = 0.75, tau2 = 2)

Arguments

tau1

SCR rise time constant in seconds (default: 0.75).

tau2

SCR decay time constant in seconds (default: 2.0).

Value

A list with time (seconds) and amplitude (the raw Bateman value at the peak).

See Also

scrf

Examples

scrfPeak()