Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: The computed initial MA coefficients are not invertible You should induce invertibility

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.

like image 813
Michael Avatar asked Oct 15 '18 11:10

Michael


1 Answers

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.

like image 118
Raghav Avatar answered Nov 14 '22 23:11

Raghav