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