Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while doing VAR Model #9188

Open
aiiwnp opened this issue Mar 29, 2024 · 0 comments
Open

Error while doing VAR Model #9188

aiiwnp opened this issue Mar 29, 2024 · 0 comments

Comments

@aiiwnp
Copy link

aiiwnp commented Mar 29, 2024

My code
aic, bic, fpe, hqic = [], [], [], []
model = VAR(CRTA_train)
p = np.arange(1,60)
for i in p:
result = model.fit(i)
aic.append(result.aic)
bic.append(result.bic)
fpe.append(result.fpe)
hqic.append(result.hqic)
lags_metrics_df = pd.DataFrame({'AIC': aic,
'BIC': bic,
'HQIC': hqic,
'FPE': fpe},
index=p)
fig, ax = plt.subplots(1, 4, figsize=(15, 3), sharex=True)
lags_metrics_df.plot(subplots=True, ax=ax, marker='o')
plt.tight_layout()

my error:
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'sqrt'

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
Cell In[101], line 5
3 p = np.arange(1,60)
4 for i in p:
----> 5 result = model.fit(i)
6 aic.append(result.aic)
7 bic.append(result.bic)

File ~/anaconda3/lib/python3.11/site-packages/statsmodels/tsa/vector_ar/var_model.py:695, in VAR.fit(self, maxlags, method, ic, trend, verbose)
687 self.data.xnames = (
688 self.data.xnames[:k_trend]
689 + x_names_to_add
690 + self.data.xnames[k_trend:]
691 )
692 self.data.cov_names = pd.MultiIndex.from_product(
693 (self.data.xnames, self.data.ynames)
694 )
--> 695 return self._estimate_var(lags, trend=trend)

File ~/anaconda3/lib/python3.11/site-packages/statsmodels/tsa/vector_ar/var_model.py:738, in VAR._estimate_var(self, lags, offset, trend)
736 z[:, i] += lags
737 # make the same adjustment for the quadratic term
--> 738 if (np.diff(np.sqrt(z[:, i])) == 1).all():
739 z[:, i] = (np.sqrt(z[:, i]) + lags) ** 2
741 y_sample = endog[lags:]

TypeError: loop of ufunc does not support argument 0 of type float which has no callable sqrt method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant