| Title: | Nonparametric Two Sample Test for Equality of Spectral Densities |
| Version: | 0.0.1.0 |
| Description: | Nonparametric method for testing the equality of the spectral densities of two time series of possibly different lengths. The time series are preprocessed with the discrete cosine transform and the variance stabilising transform to obtain an approximate Gaussian regression setting for the log-spectral density function. The test statistic is based on the squared L2 norm of the difference between the estimated log-spectral densities. The test returns the result, the statistic value, and the p-value. It also provides the estimated empirical quantile and null distribution under the hypothesis of equal spectral densities. An example using EEG data is included. For details see Nadin, Krivobokova, Enikeeva (2026), <doi:10.48550/arXiv.2602.10774>. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.1 |
| Imports: | dtt, stats |
| Suggests: | doParallel, foreach, parallel, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-02-19 10:29:13 UTC; nadin |
| Author: | Ilaria Nadin [aut, cre], Tatyana Krivobokova [aut], Farida Enikeeva [aut], Karolina Klockmann [aut] |
| Maintainer: | Ilaria Nadin <ilaria.nadin@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-23 17:00:02 UTC |
sdf.test: Nonparametric Two Sample Test for Equality of Spectral Densities
Description
Nonparametric method for testing the equality of the spectral densities of two time series of possibly different lengths. The time series are preprocessed with the discrete cosine transform and the variance stabilising transform to obtain an approximate Gaussian regression setting for the log-spectral density function. The test statistic is based on the squared L2 norm of the difference between the estimated log-spectral densities. The test returns the result, the statistic value, and the p-value. It also provides the estimated empirical quantile and null distribution under the hypothesis of equal spectral densities. An example using EEG data is included. For details see Nadin, Krivobokova, Enikeeva (2026), doi:10.48550/arXiv.2602.10774.
Author(s)
Maintainer: Ilaria Nadin ilaria.nadin@gmail.com
Authors:
Tatyana Krivobokova
Farida Enikeeva
Karolina Klockmann
EEG Signals
Description
A dataset containing four EEG recordings of a patient under rest or different transcranial Direct Current Stimulations (tDCS).
Usage
eeg_data
Format
A data frame with columns:
- index
Integer index of the measurement (frequency of 250 Hz).
- condition
Can take four values:
"initial_rest", devtools::document()"first_frontal_tDCS","second_frontal_tDCS","posterior_tDCS".- signal
Numeric EEG measurement.
Source
Original: Alexis Pomares, "Dissertation preprocessed EEG dataset", https://www.kaggle.com/datasets/alexispomares/dissertation-preprocessed This version has been preprocessed by selecting specific conditions and removing outliers, for details see (Nadin, Kivobokova, Enikeeva; 2026).
Examples
data(eeg_data)
head(eeg_data)
tail(eeg_data)
str(eeg_data)
X1 <- subset(eeg_data, condition == "first_frontal_tDCS")$signal
Print test
Description
Custom printing function for the class "test".
Usage
## S3 method for class 'test'
print(x, ...)
Arguments
x |
Object of class "test". |
... |
Further arguments passed to or from other methods. |
Value
Invisible x.
Examples
test <- sdf.test(
X1 = rnorm(50), X2 = rnorm(50),
q1 = 2, method1 = "GCV", Te = 10, alpha = 0.05, N = 1000
)
print(test)
test
SDF Test
Description
Performs the test for equality of spectral densities of two time series.
Usage
sdf.test(
X1,
X2,
Te,
alpha,
q1 = 4,
method1 = "GCV",
f1_true = NULL,
q2 = q1,
method2 = method1,
f2_true = f1_true,
N = 10000,
cores = 1,
nulldistr = NULL
)
Arguments
X1 |
Longest time series. |
X2 |
Shortest time series. |
Te |
Integer. Number of bins. |
alpha |
Numeric. Significance level for the test. |
q1 |
Integer. Penalisation order for |
method1 |
Character. Method for selecting the smoothing parameter for
|
f1_true |
Vector or |
q2 |
Integer. Penalization order for |
method2 |
Character. Method for selecting the smoothing parameter for
|
f2_true |
Vector or |
N |
Integer. Number of iterations for null distribution computa-
tion (default |
cores |
Integer. Number of cores for parallel computation of null
distribution (default |
nulldistr |
Vector or |
Value
An object of class "test", which is a list containing the
following components:
-
result: Logical.TRUEif the null hypothesis of equality of spectral densities is accepted by the test,FALSEotherwise. -
S: Value of the statistic. -
quantile: Empirical quantile used for the test. -
p-value: p-value of the test according to the empirical null distribution. -
nulldistr: Vector of empirical null distribution.
References
Nadin, Krivobokova, Enikeeva (2026). Nonparametric two sample test of spectral densities. https://arxiv.org/abs/2602.10774
Examples
# --- Example 1: Using random data ---
test <- sdf.test(
X1 = rnorm(100), X2 = rnorm(80),
q1 = 4, method1 = "GCV", Te = 20, alpha = 0.05, N = 1000
)
test
# --- Example 2: Using random data ---
X1 <- arima.sim(list(order=c(1,0,0),ar=0.5),n = 1200,rand.gen = rnorm, sd = 1)
X2 <- arima.sim(list(order=c(1,0,0),ar=0.8),n = 1000,rand.gen = rnorm, sd = 1)
sdf.test(
X1 = X1, X2 = X2,
q1 = 4, method1 = "GCV", Te = 176, alpha = 0.05
)
# --- Example 3: Using EEG dataset ---
data(eeg_data)
X1 <- subset(eeg_data, condition == "first_frontal_tDCS")$signal
X2 <- subset(eeg_data, condition == "second_frontal_tDCS")$signal
test <- sdf.test(
X1 = X1, X2 = X2,
q1 = 4, method1 = "ML", Te = 2100, alpha = 0.05, cores = 50
)
test