| Title: | 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>. |
| Authors: | Ilaria Nadin [aut, cre], Tatyana Krivobokova [aut], Farida Enikeeva [aut], Karolina Klockmann [aut] |
| Maintainer: | Ilaria Nadin <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.1.0 |
| Built: | 2026-06-07 07:15:15 UTC |
| Source: | https://github.com/cran/sdf.test |
A dataset containing four EEG recordings of a patient under rest or different transcranial Direct Current Stimulations (tDCS).
eeg_dataeeg_data
A data frame with columns:
Integer index of the measurement (frequency of 250 Hz).
Can take four values: "initial_rest", devtools::document()
"first_frontal_tDCS", "second_frontal_tDCS",
"posterior_tDCS".
Numeric EEG measurement.
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).
data(eeg_data) head(eeg_data) tail(eeg_data) str(eeg_data) X1 <- subset(eeg_data, condition == "first_frontal_tDCS")$signaldata(eeg_data) head(eeg_data) tail(eeg_data) str(eeg_data) X1 <- subset(eeg_data, condition == "first_frontal_tDCS")$signal
Custom printing function for the class "test".
## S3 method for class 'test' print(x, ...)## S3 method for class 'test' print(x, ...)
x |
Object of class "test". |
... |
Further arguments passed to or from other methods. |
Invisible x.
test <- sdf.test( X1 = rnorm(50), X2 = rnorm(50), q1 = 2, method1 = "GCV", Te = 10, alpha = 0.05, N = 1000 ) print(test) testtest <- sdf.test( X1 = rnorm(50), X2 = rnorm(50), q1 = 2, method1 = "GCV", Te = 10, alpha = 0.05, N = 1000 ) print(test) test
Performs the test for equality of spectral densities of two time series.
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 )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 )
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 |
An object of class "test", which is a list containing the
following components:
result: Logical. TRUE if the null hypothesis of
equality of spectral densities is accepted by the test,
FALSE otherwise.
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.
Nadin, Krivobokova, Enikeeva (2026). Nonparametric two sample test of spectral densities. https://arxiv.org/abs/2602.10774
# --- 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# --- 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