Granger causality test for values above a threshold in time series data

9 vues (au cours des 30 derniers jours)
Dinuka Kankanige
Dinuka Kankanige le 22 Août 2023
Modifié(e) : Abhaya le 21 Jan 2025 à 6:19
Hello, I'm trying to perform the Granger causality test for two time series considering the bivariate autoregressive model as
with the condition that Y(t) > a threshold value and Y(t) > Y(t-n). Can we still use the 'gctest' function to incorporate this condition, or is there any other built-in function in MATLAB to use for this specific condition of Granger causality? Your suggestions are much appreciated.
(R2023a)

Réponses (1)

Abhaya
Abhaya le 21 Jan 2025 à 6:16
Modifié(e) : Abhaya le 21 Jan 2025 à 6:19
Hi Dinuka,
We can use MATLAB 'gctest' function to implement Granger causality test. To implement the conditions we have to preprocess the data accordingly. Please refer to the steps given below to achieve it.
  • Step 1: Apply threshold condition - Y(t) > threshold
Y_filtered = Y(Y > threshold)
  • Step 2: Apply lag condition (Y(t) > Y(t-n)) - ensure at least lag points are met
Y_filtered = Y_filtered(2:end) > Y_filtered(1:end-1);
  • Step 3: Perform Granger Causality Test: Use the preprocessed data to conduct the Granger causality test:
[gct, pVal] = gctest(X_filtered, Y_filtered);
Please refer to the following sample code for better understanding.
n = 100;
X = randn(n, 1); % Random time series X
Y = randn(n, 1); % Random time series Y
threshold = 0.5;
Y_filtered = Y(Y > threshold); % Condition 1: Y(t) > threshold
Y_filtered = Y_filtered(Y_filtered(2:end) > Y_filtered(1:end-1)); % Condition 2: Apply accordingly
X_filtered = X(2:end); % Align X with the filtered Y
X_filtered = X_filtered(2:end);
Y_filtered = Y_filtered(2:end);
[gct, pVal] = gctest(X_filtered, Y_filtered);
disp(['Test Statistic: ', num2str(gct)]);
Test Statistic: 0
disp(['p-value: ', num2str(pVal)]);
p-value: 0.96913
For more information on MATLAB 'gctest' please refer to the documentation linked below.
I hope this helps you implement the Granger causality test with your specific conditions!

Catégories

En savoir plus sur Quadratic Programming and Cone Programming dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by