/examples/tsa/ex_arma2.py
http://github.com/statsmodels/statsmodels · Python · 28 lines · 15 code · 4 blank · 9 comment · 0 complexity · ffd5654e06850a487a3579dd9c254894 MD5 · raw file
- """
- Autoregressive Moving Average (ARMA) Model
- """
- import numpy as np
- import statsmodels.api as sm
- # Generate some data from an ARMA process
- from statsmodels.tsa.arima_process import arma_generate_sample
- np.random.seed(12345)
- arparams = np.array([.75, -.25])
- maparams = np.array([.65, .35])
- # The conventions of the arma_generate function require that we specify a
- # 1 for the zero-lag of the AR and MA parameters and that the AR parameters
- # be negated.
- arparams = np.r_[1, -arparams]
- maparam = np.r_[1, maparams]
- nobs = 250
- y = arma_generate_sample(arparams, maparams, nobs)
- # Now, optionally, we can add some dates information. For this example,
- # we'll use a pandas time series.
- import pandas
- dates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)
- y = pandas.TimeSeries(y, index=dates)
- arma_mod = sm.tsa.ARMA(y, freq='M')
- arma_res = arma_mod.fit(order=(2,2), trend='nc', disp=-1)