You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The data for testing whether the time series in the second column Granger causes the time series in the first column.
So it seems to visit possible to compute the GC using more time series. However: the following code:
import numpy as np
import statsmodels.api as sm
# Generate example data
nobs = 100
X1 = np.random.randn(nobs)
X2 = np.random.randn(nobs)
X3 = np.random.randn(nobs)
X4 = np.random.randn(nobs)
X5 = np.random.randn(nobs)
# Create numpy array with shape (nobs, 5)
data = np.column_stack((X1, X2, X3, X4, X5))
# Compute Granger causality tests for all pairs of variables and lags up to 2
maxlag = 2
results = sm.tsa.stattools.grangercausalitytests(data, maxlag, verbose=False)
# Print the p-values for the Granger causality tests
for lag in range(1, maxlag+1):
print(f"Lag {lag}:")
for i in range(data.shape[1]):
for j in range(data.shape[1]):
if i != j:
print(f"X{i+1} -> X{j+1}: p-value = {results[lag][i+1][j]['ssr_ftest'][1]}")
raise the following error:
ValueError: wrong shape for coefs
The text was updated successfully, but these errors were encountered:
According to the documentation:
The data for testing whether the time series in the second column Granger causes the time series in the first column.
So it seems to visit possible to compute the GC using more time series. However: the following code:
raise the following error:
ValueError: wrong shape for coefs
The text was updated successfully, but these errors were encountered: