PageRenderTime 122ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/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
 1"""
 2Autoregressive Moving Average (ARMA) Model
 3"""
 4import numpy as np
 5import statsmodels.api as sm
 6
 7# Generate some data from an ARMA process
 8from statsmodels.tsa.arima_process import arma_generate_sample
 9
10np.random.seed(12345)
11arparams = np.array([.75, -.25])
12maparams = np.array([.65, .35])
13
14# The conventions of the arma_generate function require that we specify a
15# 1 for the zero-lag of the AR and MA parameters and that the AR parameters
16# be negated.
17arparams = np.r_[1, -arparams]
18maparam = np.r_[1, maparams]
19nobs = 250
20y = arma_generate_sample(arparams, maparams, nobs)
21
22# Now, optionally, we can add some dates information. For this example,
23# we'll use a pandas time series.
24import pandas
25dates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)
26y = pandas.TimeSeries(y, index=dates)
27arma_mod = sm.tsa.ARMA(y, freq='M')
28arma_res = arma_mod.fit(order=(2,2), trend='nc', disp=-1)