Vector autoregressive (VAR) model fitting with different lag operator

399 views Asked by At

I am a Master 2 student in computational neuroscience. I'm at the very end of my analysis and I have a problem with the application of a VAR model (vector autoregressive model). It is a rather complex problem to solve and it concerns the test of different lags operators on the data. For me the problem comes when I try to compute the cholesky factorization on a covariance matrix with negative numbers . :

I may have found a solution but I can't include it in the python function that deploys the model ("VAR"). If someone has ten minutes to help me, please write me. Thanks for your attention :)

for i in [1,2,3,4,6,8,9,10,12,13,14,15,16,17,18,19,20]: print(i)

df_entropie_G1_w_diff = df_entropie_G1_w.iloc[i,2145:].diff()

df_RMSE_G1_w_diff = df_g1_RMSE_w.iloc[i,2145:].diff()

df_var_G1_w_diff = df_var_G1_w.iloc[i,2145:].diff()


df_data = pd.concat([df_entropie_G1_w_diff,df_RMSE_G1_w_diff,df_var_G1_w_diff],axis = 1)

df_data = df_data.diff().dropna()


df_data = df_data.T

df_data = df_data.reset_index()

del df_data['index']

df_data = df_data.T

df_data['Time'] = pd.to_timedelta(np.arange(537), unit='s')

df_data.index = df_data['Time']

del df_data['Time']

Arrange names of columns

df_data_T = df_data.T 

df_data_T = df_data_T.reset_index()

del df_data_T['index']


df_data_T = df_data_T.T


df_data = df_data_T.rename(columns={0:'Entropie',1:'RMSE',2:'Var'})


model = VAR(df_data)
liste_aic = []
liste_bic = []
liste_fpe = []
liste_hqic = []


for a in range(0,25,1):
    result = model.fit(a)
    print('Lag Order =', a)
    print('AIC : ', result.aic)
    print('BIC : ', result.bic)
    print('FPE : ', result.fpe)
    print('HQIC: ', result.hqic, '\n')
    liste_aic.append(result.aic)
    liste_bic.append(result.bic)
    liste_fpe.append(result.fpe)
    liste_hqic.append(result.hqic)
    

1 Lag Order = 0 AIC : -59.6358271069015 BIC : -59.61188298346849 FPE : 1.260344786813777e-26 HQIC: -59.626460351200464

Lag Order = 1 /opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/base/tsa_model.py:578: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting. warnings.warn('An unsupported index was provided and will be' Traceback (most recent call last):

File "", line 139, in print('AIC : ', result.aic)

File "/opt/anaconda3/lib/python3.8/site-packages/statsmodels/base/wrapper.py", line 34, in getattribute obj = getattr(results, attr)

File "/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/vector_ar/var_model.py", line 2139, in aic return self.info_criteria['aic']

File "pandas/_libs/properties.pyx", line 33, in pandas._libs.properties.CachedProperty.get

File "/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/vector_ar/var_model.py", line 2120, in info_criteria ld = logdet_symm(self.sigma_u_mle)

File "/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tools/linalg.py", line 28, in logdet_symm c, _ = linalg.cho_factor(m, lower=True)

File "/opt/anaconda3/lib/python3.8/site-packages/scipy/linalg/decomp_cholesky.py", line 152, in cho_factor c, lower = _cholesky(a, lower=lower, overwrite_a=overwrite_a, clean=False,

File "/opt/anaconda3/lib/python3.8/site-packages/scipy/linalg/decomp_cholesky.py", line 37, in _cholesky raise LinAlgError("%d-th leading minor of the array is not positive "

LinAlgError: 3-th leading minor of the array is not positive definite

0

There are 0 answers