I am doing a time series problem. when I am doing AR model, everything is right.
# Import the module for estimating an ARMA model
from statsmodels.tsa.arima_model import ARMA
# Fit the data to an AR(p) for p = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for p in range(7):
mod = ARMA(data, order=(p,0))
res = mod.fit()
# Save BIC for AR(p)
BIC[p] = res.bic
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of AR Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
However, when I am doing MA model:
# Fit the data to an MA(q) for q = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for q in range(7):
mod = ARMA(data, order=(0,q))
res = mod.fit()
# Save BIC for MA(q)
BIC[q] = res.bic
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of MA Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
I will get:
ValueError: The computed initial MA coefficients are not invertible
You should induce invertibility, choose a different model order, or you can
pass your own start_params.
After reading an answer from non Invertible of a ARIMA model, I solved the error:
# Fit the data to an MA(q) for q = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for q in range(7):
try:
mod = ARMA(data, order=(0,q))
res = mod.fit()
# Save BIC for MA(q)
BIC[q] = res.bic
except:
pass
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of MA Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
However, I really don't understand why it can be solved, that is why I want to ask this question. May someone give a complete answer.
I stumbled here while trying to find solution to invertible problem for my ARIMA(p,d,q) model. I am not too sure if this would apply in your case, but i found my solution in terms that i was trying to input d=0. whereas i had already applied first order difference to input ts to make my series stationary. so when i put d=1,invertibility issue was resolved.
Hope this is of some help. Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With