3
$\begingroup$

I am trying to regenerate the ARMA parameters from statsmodel in python. The code I am using is:

from statsmodels.tsa.arima_process import arma_generate_sample
import statsmodels.api as sm
arparams = np.array([.75, -.25])
maparams = np.array([.65, .35])
arparams = np.r_[1, -arparams]
maparam = np.r_[1, maparams]
nobs = 250
np.random.seed(2014)
y = arma_generate_sample(arparams, maparams, nobs) #generate ARMA series
res = sm.tsa.arma_order_select_ic(y, ic=['aic', 'bic'], trend='nc')
z = sm.tsa.ARMA(y, (2,2)).fit()
print z.arparams
array([ 0.13178508,  0.08568388])

The regenerated AR params are not same as the one I started with. What am I doing wrong?

$\endgroup$

1 Answer 1

4
$\begingroup$

The logic of your code is all right. However, the variance of the parameters is high because nobs=250 is relatively low. Increase nobs and your parameters will converge toward the parameters you specified eventually.

import statsmodels.api as sm
import numpy as np

# Parameters.
ar = np.array([.75, -.25])
ma = np.array([.65, .35])

# Simulate an ARMA process.
np.random.seed(42)
y = sm.tsa.arma_generate_sample(
    ar=np.r_[1, -ar],
    ma=np.r_[1, ma],
    nsample=10000,
    sigma=1,
)

# Fit ARMA process on the simulates to check coefficients, ACF and PACF.
model = sm.tsa.ARMA(y, (2, 2)).fit(trend='c')

# Plot ACF and PACF of estimated model.
sm.tsa.graphics.plot_acf(y, lags=20, zero=True);
sm.tsa.graphics.plot_pacf(y, lags=20, zero=True);
model.summary()

Reference: McKinney, W., Perktold, J., & Seabold, S. (2011)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.