Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: zero-size array to reduction operation maximum which has no identity in SVAR Mode

I'm trying to fit a Structural Vector Autoregression (SVAR) model using statsmodels in Python, but I'm encountering the following error ValueError: zero-size array to reduction operation maximum which has no identity.

There is my code:

import pandas as pd
import numpy as np
from statsmodels.tsa.vector_ar.svar_model import SVAR

df_sample = pd.DataFrame(
    {
    'Product_1': np.random.rand(240) * 10000,
    'Product_2': np.random.rand(240) * 10000,
    'Product_3': np.random.rand(240) * 10000
    }, 
    index=pd.date_range(start='2019-11-16', periods=240, freq='W-SAT'))

A = np.array([
    [1, 0, 0],
    [np.nan, 1, 0],
    [np.nan, np.nan, 1]
], dtype='U')

# Fit SVAR
model = SVAR(df_sample, svar_type='A', A=A)
res = model.fit(maxlags=4)
like image 454
PeCaDe Avatar asked Dec 06 '25 03:12

PeCaDe


1 Answers

Its as a result its needed to have an 'E' notation instead of np.nan this will solve the issue, it can be checked trhough the reproducible example:

import pandas as pd 
import numpy as np 
from statsmodels.tsa.vector_ar.svar_model import SVAR 
 
df_sample_test = pd.DataFrame( 
   {
   'Product_1': np.random.rand(240) * 10000,
   'Product_2': np.random.rand(240) * 10000,
   'Product_3': np.random.rand(240) * 10000
   }, 
   index=pd.date_range(start='2019-11-16', periods=240, freq='W-SAT'))
 
A_test = np.array([ 
   [1, 0, 0],
   ['E', 1, 0],
   ['E', 'E', 1]
], dtype=object) 
 
# Fit SVAR 
model_test = SVAR(df_sample_test, svar_type='A', A=A_test) 
res_test = model.fit(maxlags=4)
like image 55
PeCaDe Avatar answered Dec 08 '25 16:12

PeCaDe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!