predicting with arma models

1,009 views
Skip to first unread message

Michael Schmidt

unread,
Aug 25, 2011, 1:04:38 PM8/25/11
to pystat...@googlegroups.com
Hi Everyone,

I've just started using this package (much thanks to the writers and contributors!), and I'm hoping someone can help me with using the tools in tsa.arima_model to produce forecasts. 

I start by creating a tsa.arima_model.ARMA object and run a fit on it for a certain model.  So far, so good.  I can get the fitted values for the function, no problem.  But, how can I use the ARMA object to predict n-periods out?  There's not a lot of documentation on this, but it seems like such a useful functionality that it would be included.

Thanks!
Mike

Skipper Seabold

unread,
Aug 25, 2011, 9:28:12 PM8/25/11
to pystat...@googlegroups.com
Are you setup to grab the development version from github? I've added this, but I haven't pushed yet and I can't guarantee that the API won't change before our next release. The following code will give you out of sample forecasts and forecast standard errors. You need to pass your ARMAResults object in place of self, steps is the number of forecast periods, and exog is an optional out-of-sample exogenous matrix, if you need one.

def forecast(self, steps=1, exog=None):
    """
    Out-of-sample forecasts

    Parameters
    ----------
    steps : int
       The number of out of sample forecasts from the end of the
       sample.
    exog : array
        If the model is an ARMAX, you must provide out of sample
        values for the exogenous variables. This should not include
        the constant.

    Returns
    -------
    forecast : array
        Array of out of sample forecasts
    stderr : array
        Array of the standard error of the forecasts.
    """"

    k_trend, k_exog = self.k_trend, self.k_exog
    if exog is None and k_exog > 0:
        raise ValueError("You must provide exog for ARMAX")

    q, p = self.k_ma, self.k_ar
    maparams, arparams = self.maparams[::-1], self.arparams[::-1]

    resid = np.zeros(2*q)
    resid[:q] = self.resid[-q:] #only need last q
    y = self.model.endog
    if k_trend == 1:
        mu = self.params[0] * (1-arparams.sum()) # use expectation
                                                 # not constant
        mu = np.array([mu]*steps) # repeat it so you can slice if exog
    else:
        mu = np.zeros(steps)

    if k_exog > 0:
        mu += np.dot(self.params[k_trend:k_exog+k_trend], exog)


    endog = np.zeros(p+steps-1)
    endog[:p] = y[-p:] #only need p

    forecast = np.zeros(steps)
    for i in range(q):
        fcast = mu[i] + np.dot(arparams,endog[i:i+p]) + \
                      np.dot(maparams,resid[i:i+q])
        forecast[i] = fcast
        endog[i+p] = fcast

    for i in range(i+1,steps-1):
        fcast = mu[i] + np.dot(arparams,endog[i:i+p])
        forecast[i] = fcast
        endog[i+p] = fcast

    #need to do one more without updating endog
    forecast[-1] = mu[-1] + np.dot(arparams,endog[steps-1:])

    #take care of exogenous

    # compute the standard errors
    sigma2 = self.sigma2
    ma_rep = arma2ma(np.r_[1,-arparams[::-1]],
                     np.r_[1, maparams[::-1]], nobs=steps)


    stderr = np.sqrt(sigma2 * np.cumsum(ma_rep**2))
   
    return forecast, stderr

Mike Schmidt

unread,
Aug 26, 2011, 1:09:09 PM8/26/11
to pystatsmodels
Thanks for the response - I'm currently using the version hosted on
sourceforge, which I guess is the stable release, but I can certainly
grab an update. I noticed on github that there's the 'trunk', '0.3-
devel', 'release-0.3' version which have all been recently edited -
are you referring to the "0.3-devel" version?

The other thing that would be great to know, is if there's a way to
include exogenous variables in the vector auto-regressive model? I
guess this is normally referred to as VARX. I didn't see anything for
this in the stable release on soruceforge, but is it possible that
it's been included in the development version?

Ideally, I'd like something where I could do the fit to my
multivariate model on historical endogenous+exogenous data, then feed
it (separately determined) exogenous forecasts for n-steps out, and
get the n-steps out forecasts for the endogenous variables

Thanks again!


On Aug 25, 8:28 pm, Skipper Seabold <jsseab...@gmail.com> wrote:
> On Thu, Aug 25, 2011 at 1:04 PM, Michael Schmidt <elmicker...@gmail.com>

Skipper Seabold

unread,
Aug 26, 2011, 1:19:23 PM8/26/11
to pystat...@googlegroups.com
On Fri, Aug 26, 2011 at 1:09 PM, Mike Schmidt <elmic...@gmail.com> wrote:
> Thanks for the response - I'm currently using the version hosted on
> sourceforge, which I guess is the stable release, but I can certainly
> grab an update.  I noticed on github that there's the 'trunk', '0.3-
> devel', 'release-0.3' version which have all been recently edited -
> are you referring to the "0.3-devel" version?
>

Hmm, are you looking at github or launchpad? I don't think there's
this distinction on github? We are hosting the code now on github at
https://github.com/statsmodels/statsmodels

You have two options, one click on the download button then either
grab the tarball or the zip. That will be the source of the most
current code. Note that the forecast stuff isn't merged into master
yet, but I'll do that shortly.

Or you could install git. You can find instructions for installing it
here, http://statsmodels.sourceforge.net/dev/git_notes.html#getting-started-with-git

You shouldn't need any of the other information on that page unless
you want to contribute. Then you just need to do

http://statsmodels.sourceforge.net/install.html#obtaining-the-source

to get the source.

> The other thing that would be great to know, is if there's a way to
> include exogenous variables in the vector auto-regressive model?  I
> guess this is normally referred to as VARX.  I didn't see anything for
> this in the stable release on soruceforge, but is it possible that
> it's been included in the development version?
>

I don't think VAR is setup for exogenous variables yet. Wes? I'm going
to be looking at this over the coming days, and I'll let you know when
it's up.

> Ideally, I'd like something where I could do the fit to my
> multivariate model on historical endogenous+exogenous data, then feed
> it (separately determined) exogenous forecasts for n-steps out, and
> get the n-steps out forecasts for the endogenous variables
>

Sure.

> Thanks again!

No problem. Good to know it's getting used. Will try to accommodate
the feature requests.

Skipper

Mike Schmidt

unread,
Aug 26, 2011, 1:37:24 PM8/26/11
to pystatsmodels
Great, thanks for the info - getting a working VARX model would really
make my day :) Please let me know if there's anything I can do to
help with this project.

Cheers,
Mike

On Aug 26, 12:19 pm, Skipper Seabold <jsseab...@gmail.com> wrote:
> On Fri, Aug 26, 2011 at 1:09 PM, Mike Schmidt <elmicker...@gmail.com> wrote:
> > Thanks for the response - I'm currently using the version hosted on
> > sourceforge, which I guess is the stable release, but I can certainly
> > grab an update.  I noticed on github that there's the 'trunk', '0.3-
> > devel', 'release-0.3' version which have all been recently edited -
> > are you referring to the "0.3-devel" version?
>
> Hmm, are you looking at github or launchpad? I don't think there's
> this distinction on github? We are hosting the code now on github athttps://github.com/statsmodels/statsmodels
>
> You have two options, one click on the download button then either
> grab the tarball or the zip. That will be the source of the most
> current code. Note that the forecast stuff isn't merged into master
> yet, but I'll do that shortly.
>
> Or you could install git. You can find instructions for installing it
> here,http://statsmodels.sourceforge.net/dev/git_notes.html#getting-started...

josef...@gmail.com

unread,
Aug 26, 2011, 1:42:23 PM8/26/11
to pystat...@googlegroups.com

As far as I could see, VAR doesn't take exog, but it includes trend in
some parts and exogs could be treated in a similar way.

Does SVAR do anything with exogs or trend?

Josef

Bart Baker

unread,
Aug 26, 2011, 1:45:50 PM8/26/11
to pystat...@googlegroups.com

No, not yet. Neither SVAR nor VAR are setup to take exogenous variables yet.

Bart

josef...@gmail.com

unread,
Aug 26, 2011, 1:48:03 PM8/26/11
to pystat...@googlegroups.com
On Fri, Aug 26, 2011 at 1:37 PM, Mike Schmidt <elmic...@gmail.com> wrote:
> Great, thanks for the info - getting a working VARX model would really
> make my day :)  Please let me know if there's anything I can do to
> help with this project.

Best help to get started with a feature request would be a test case.
We are always short in test cases, and adding features, or writing new
functionality is much easier and faster if we don't have to go and
hunt for test examples.

Thanks and Cheers,

Josef

Skipper Seabold

unread,
Aug 26, 2011, 6:44:35 PM8/26/11
to pystat...@googlegroups.com
On Fri, Aug 26, 2011 at 1:19 PM, Skipper Seabold <jsse...@gmail.com> wrote:
> You have two options, one click on the download button then either
> grab the tarball or the zip. That will be the source of the most
> current code. Note that the forecast stuff isn't merged into master
> yet, but I'll do that shortly.
>

The ARMAResults class now has a forecast method, if you want to grab
the source. It returns the forecast, forecast errors, and the
confidence intervals. I can't guarantee the API won't change once we
hook the TSA models into pandas better before the next release, FYI.

Mike Schmidt

unread,
Aug 27, 2011, 1:35:52 AM8/27/11
to pystatsmodels
> The ARMAResults class now has a forecast method, if you want to grab
> the source. It returns the forecast, forecast errors, and the
> confidence intervals. I can't guarantee the API won't change once we
> hook the TSA models into pandas better before the next release, FYI.

Great, thanks, I'll check that out a.s.a.p.

>Best help to get started with a feature request would be a test case.
>We are always short in test cases, and adding features, or writing new
>functionality is much easier and faster if we don't have to go and
>hunt for test examples.

I'd be happy to - I'll upload a .npz file tomorrow with part of my
dataset

Mike Schmidt

unread,
Aug 31, 2011, 1:12:13 PM8/31/11
to pystatsmodels
Hi Everyone - I haven't forgotten about this, and I will upload data
a.s.a.p - only problem right now is that I'm in New England and, well,
Irene stole all of my internets. Crappy connections in public
libraries only for now.

Michael Schmidt

unread,
Sep 8, 2011, 11:52:59 AM9/8/11
to pystatsmodels
Hi All,

I've found and attached a *.npz file with sample data that naturally lend themselves to a VARX model.  The numpy arrays in the file are called 'endog' and 'exog', and each are shaped (214, 24).  The endogenous data are taken from the United Illuminating company's (public) webpage, and represent hourly power consumption by residential customers from 6/1/2010 to 12/31/2010.  The exogenous data are the regional power consumption for all of New England, and are also publicly available and cover the same date range.

The reason why I think a VARX model would be appropriate here instead of simply flattening the dataset and using ARMAX, is because each hourly load is not only correlated with the previous hour(s) but also with the previous day(s).  Also, in practice, one would always interested in a full 24 hour's worth of load information, as I happen to know that the forecasts are always quoted this way, and that traders buy and sell power in the n-days-ahead markets, and so solar installers thus need to be able to forecast by day.  The vectorial nature of the dataset naturally lends itself to a VARX model, using the regional load forecast as the exogneous variable. 

As an aside, one could probably also use a seasonal ARMAX model, using 24-hour lags, but this does not appear to be implemented yet.

So, I think having use of a VARX model would be ideal for this and many other situations, where the user could feed the model n-days ahead worth of regional forecasts and obtain n-days worth of sub-regional forecasts.

Thanks again to everyone working on this project!
Mike
varx_example.npz

Skipper Seabold

unread,
Sep 8, 2011, 12:38:03 PM9/8/11
to pystat...@googlegroups.com

Ah, this will be a nice example. Will have a look at VARX (and
probably seasonality in ARMAX) soon. As always patches welcome.

If you get ambitious and want to make a proper 'dataset' out of this,
there are instructions here.

http://statsmodels.sourceforge.net/devel/dev/dataset_notes.html#adding-a-dataset

Thanks,

Skipper

Michael Schmidt

unread,
Sep 8, 2011, 1:01:22 PM9/8/11
to pystat...@googlegroups.com
I should also point out that I've subtracted off the mean, and scaled each variable by its standard deviation.  I doubt that will matter too much for testing purposes, but just wanted to make everyone aware of it.

Michael Schmidt

unread,
Sep 21, 2011, 12:08:25 PM9/21/11
to pystat...@googlegroups.com
I've just had a chance to re-install the code and try using ARMAResults.forecast, but I can't seem to find it.  I'm using version 0.3.1, and there doesn't appear to be a forecast method in ARMAResults.

To be more precise, that's the one in scikits.statmodels.tsa.arima_model, and which I got by fitting an scikits.statsmodels.tsa.arima_model.ARMA object (just in case there were multiple definitions of these things).

I've also tried using the code snippet you posted earlier in this convo, but I'm getting an out-of-range index error.

Any help would be much appreciated!

Mike

Skipper Seabold

unread,
Sep 21, 2011, 12:14:20 PM9/21/11
to pystat...@googlegroups.com
On Wed, Sep 21, 2011 at 12:08 PM, Michael Schmidt <elmic...@gmail.com> wrote:
> I've just had a chance to re-install the code and try using
> ARMAResults.forecast, but I can't seem to find it.  I'm using version 0.3.1,
> and there doesn't appear to be a forecast method in ARMAResults.
>

It's not in the last release. It's only in master. You'll have to
install from github.

> To be more precise, that's the one in scikits.statmodels.tsa.arima_model,
> and which I got by fitting an scikits.statsmodels.tsa.arima_model.ARMA
> object (just in case there were multiple definitions of these things).
>
> I've also tried using the code snippet you posted earlier in this convo, but
> I'm getting an out-of-range index error.
>

It *should* work, though there could've been a bug. Can you try using this one

https://github.com/statsmodels/statsmodels/blob/master/scikits/statsmodels/tsa/arima_model.py#L674

Just pull it out to a function and pass your ARMAResults instance for
the self argument.

If you still get the error can you post some code to reproduce?

Skipper

Michael Schmidt

unread,
Sep 21, 2011, 12:31:04 PM9/21/11
to pystat...@googlegroups.com

It *should* work, though there could've been a bug. Can you try using this one

https://github.com/statsmodels/statsmodels/blob/master/scikits/statsmodels/tsa/arima_model.py#L674

Just pull it out to a function and pass your ARMAResults instance for
the self argument.

If you still get the error can you post some code to reproduce?

Skipper

Yep, still getting an index error.  I've attached code and data to reproduce this error.  I copied and pasted your forecast code from the above link into the *.py file, and I added a main function to drive it.

The problem occurs in the loop at line 75 of my code:


for i in range(q):
        fcast = mu[i] + np.dot(arparams,endog[i:i+p]) + \
            np.dot(maparams,resid[i:i+q])
        forecast[i] = fcast
        endog[i+p] = fcast

at the last line where you set endog.  In my example, I'm using an ARMA(1,2) model, so p=1, q=2.  A few lines earlier, you have:

endog = np.zeros(p+steps-1)

but with steps = 1, this is length 1, but the loop over q (above) will be out of range for any value of q > 0.

On Wed, Sep 21, 2011 at 11:14 AM, Skipper Seabold <jsse...@gmail.com> wrote:
On Wed, Sep 21, 2011 at 12:08 PM, Michael Schmidt <elmic...@gmail.com> wrote:
> I've just had a chance to re-install the code and try using
> ARMAResults.forecast, but I can't seem to find it.  I'm using version 0.3.1,
> and there doesn't appear to be a forecast method in ARMAResults.
>

It's not in the last release. It's only in master. You'll have to
install from github.

Ok, I'll try that next, thanks

Mike
arma_forecast_fail.py
example_data.npz

Skipper Seabold

unread,
Sep 21, 2011, 12:46:51 PM9/21/11
to pystat...@googlegroups.com
On Wed, Sep 21, 2011 at 12:31 PM, Michael Schmidt <elmic...@gmail.com> wrote:
>
>> It *should* work, though there could've been a bug. Can you try using this
>> one
>>
>>
>> https://github.com/statsmodels/statsmodels/blob/master/scikits/statsmodels/tsa/arima_model.py#L674
>>
>> Just pull it out to a function and pass your ARMAResults instance for
>> the self argument.
>>
>> If you still get the error can you post some code to reproduce?
>>
>> Skipper
>
> Yep, still getting an index error.  I've attached code and data to reproduce
> this error.  I copied and pasted your forecast code from the above link into
> the *.py file, and I added a main function to drive it.
>
> The problem occurs in the loop at line 75 of my code:
>
> for i in range(q):

I think you can change this to

for i in range(min(q,steps-1)):

and it will work, though I'm not yet sure if it'll be robust without
thinking more. I've rewritten all of the predict stuff for tsa in the
pandas-integration branch, and this is the last thing that I haven't
done. ARMA is still in-sample only, so I'm going to hold off on
patching this until I am doing it with the new machinery. I am going
to update it soon though, hopefully towards the end of the week, and I
will add test cases to make sure this is covered adequately. Thanks
for the report, and please let me know if there's anymore trouble.

Skipper

Michael Schmidt

unread,
Sep 21, 2011, 1:17:00 PM9/21/11
to pystat...@googlegroups.com
I just made the change you suggested, and now that part's fine, but the code fails on the next block (line 77 of my script):

/..../arma_forecast_fail.py in forecast(self, steps, exog, alpha)
     75         endog[i+p] = fcast
     76
---> 77     for i in range(i+1,steps-1):
     78         fcast = mu[i] + np.dot(arparams,endog[i:i+p])
     79         forecast[i] = fcast

UnboundLocalError: local variable 'i' referenced before assignment

Is the range supposed to be from 1 to steps-1, or are these for loops supposed to be nested?  I made sure that the block-indentation in my script is the same as what's at:

https://github.com/statsmodels/statsmodels/blob/master/scikits/statsmodels/tsa/arima_model.py#L674

Mike

Skipper Seabold

unread,
Sep 21, 2011, 1:28:07 PM9/21/11
to pystat...@googlegroups.com
On Wed, Sep 21, 2011 at 1:17 PM, Michael Schmidt <elmic...@gmail.com> wrote:
> I just made the change you suggested, and now that part's fine, but the code
> fails on the next block (line 77 of my script):
>
> /..../arma_forecast_fail.py in forecast(self, steps, exog, alpha)
>      75         endog[i+p] = fcast
>      76
> ---> 77     for i in range(i+1,steps-1):
>      78         fcast = mu[i] + np.dot(arparams,endog[i:i+p])
>      79         forecast[i] = fcast
>
> UnboundLocalError: local variable 'i' referenced before assignment
>
> Is the range supposed to be from 1 to steps-1, or are these for loops
> supposed to be nested?  I made sure that the block-indentation in my script
> is the same as what's at:
>

No, they're not supposed to be nested. Just put i = 0 under if q.
Corner cases...this is why I was waiting for the dates machinery to be
in place to really do prediction in the tsa models. It makes it a bit
easier to keep everything straight.

if q:
i = 0 # in case q == steps == 1


resid = np.zeros(2*q)
resid[:q] = self.resid[-q:] #only need last q

You also need these imports at the top of your script

from scikits.statsmodels.tsa.arima_process import arma2ma
from scipy.stats import norm

panghuanzhi

unread,
Apr 8, 2012, 9:18:13 AM4/8/12
to pystat...@googlegroups.com
predicting with arma models
Michael Schmidt <elmickerino@...>
2011-08-25 17:04:38 GMT


Hi, Mike and Skipper, I am trying predicting using ARMA too. During study, I
want
to estimate ARMA parameters using Powell. So it's appreciate to anticipate
your discussion on predicting using arma_model package. Yet I have little
experience on Python programme, so it's a little difficult for me to use
arma_model package. Further it seems difficult to find demos or examples for
arma_model use at this time. So could you pass me some examples or links of
examples about ARMA predicting? Thanks.

Skipper Seabold

unread,
Apr 8, 2012, 11:02:33 AM4/8/12
to pystat...@googlegroups.com

Hi,

You'll find an example here:
http://statsmodels.sourceforge.net/devel/examples/generated/ex_arma2.html

To predict, you can just do

pred = arma_res.predict(start="1999-8-31", end="2000-8-31")

Or if you don't use pandas.

arma_mod2 = ARMA(y.values, freq='M')
arma_res2 = arma_mod2.fit(order=(2,2), trend='nc', disp=-1)
pred = arma_res2.predict(start=230, end=248)

I just fixed a small buglet with ARMA predict in master, so you'll
need to use master or wait until this evening when I am able to put up
a new release candidate.

Skipper

panghuanzhi

unread,
Apr 9, 2012, 3:31:50 AM4/9/12
to pystat...@googlegroups.com
Skipper Seabold <jsseabold@...> writes:

Hi,Skipper
1.environment:
python2.6
scipy-0.10.1-win32-superpack-python2.6
numpy-1.6.1-win32-superpack-python2.6
scikits.statsmodels-0.3.1.tar
And the GET START code has passed successfully with warning:
"
Warning (from warnings module):
File "C:\Python26\lib\scikits\statsmodels\tools\tools.py", line 256 "next
release, use explicit prepend", FutureWarning)
FutureWarning: The default of `prepend` will be changed to True in the next
release, use explicit prepend.
"

2.test code(originated from
http://statsmodels.sourceforge.net/devel/examples/generated/ex_arma2.html)
import numpy as np

import scikits.statsmodels.api as sm
##import scikits.statsmodels as sm
from scikits.statsmodels.tsa.arima_process import arma_generate_sample
from scikits.statsmodels.tsa.arima_model import ARMA
arparams = np.array([.75, -.25])

maparams = np.array([.65, .35])
arparams = np.r_[1, -arparams]

maparam = np.r_[1, maparams]

nobs = 250

y = arma_generate_sample(arparams, maparams, nobs)
y
##import pandas
##
##dates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)
##y = pandas.TimeSeries(y, index=dates)

arma_mod = ARMA(y, freq='M')
##throw Error:Traceback (most recent call last):
File "D:\data\python\arma\arma_powell", line 23, in <module>
## arma_mod = ARMA(y, freq='M')
## TypeError: __init__() got an unexpected keyword argument 'freq'
##arma_mod = ARMA(y)##tested no error throwed yet without result;
##arma_res = arma_mod.fit(order=(2,2), trend='nc', disp=-1)
##predict
##arma_mod2 = ARMA(y.values, freq='M')
##arma_res2 = arma_mod2.fit(order=(2,2), trend='nc', disp=-1)
##pred = arma_res2.predict(start=230, end=248)
3 why error:
I have checked the package scikits by open File->Path Browser->%Python26
installed dir%\lib. And found that the class ARMA embeded
in scikits:package->statsmodels:package->tsa:package->arima_model.py->class
ARMA(LikelihoodModel) just had method __init__(self, endog, exog=None):
which refused to accept parameter "freq='M'" and threw the error.
4 solutions?
So it seems that I have to update package to 0.4? Yet I found no 0.4 for
python26,is there? If I would like to keep python26(some other softwares based
on installed python26), is there some solution?
Thanks for response.


Skipper Seabold

unread,
Apr 11, 2012, 12:17:02 AM4/11/12
to pystat...@googlegroups.com

ARMA does not take a freq keyword with 0.3.1.

> ##arma_res = arma_mod.fit(order=(2,2), trend='nc', disp=-1)
> ##predict
> ##arma_mod2 = ARMA(y.values, freq='M')
> ##arma_res2 = arma_mod2.fit(order=(2,2), trend='nc', disp=-1)
> ##pred = arma_res2.predict(start=230, end=248)
> 3 why error:
> I have checked the package scikits by open File->Path Browser->%Python26
> installed dir%\lib. And found that the class ARMA embeded
> in scikits:package->statsmodels:package->tsa:package->arima_model.py->class
> ARMA(LikelihoodModel) just had method __init__(self, endog, exog=None):
> which refused to accept parameter "freq='M'" and threw the error.
> 4 solutions?
> So it seems that I have to update package to  0.4? Yet I found no 0.4 for
> python26,is there? If I would like to keep python26(some other softwares based
> on installed python26), is there some solution?

We just put a new version here

https://github.com/statsmodels/statsmodels/downloads

Let us know if you have any trouble with it.

Skipper

panghuanzhi

unread,
May 17, 2012, 4:58:16 AM5/17/12
to pystat...@googlegroups.com
Skipper Seabold <jsseabold@...> writes:
Hi,Skipper
Recently, I test ARMA.fit() using the following code:

"
import numpy as np
import scikits.statsmodels.api as sm
##import scikits.statsmodels as sm
from statsmodels.tsa.arima_process import arma_generate_sample
from statsmodels.tsa.arima_model import ARMA
x=[2.472,1.135,-0.086,2.342,-2.668,-0.788, -2.408];
arma_mod = ARMA(x)
arma_powell = arma_mod.fit(order=(3,2), trend='nc',
solver='powell',disp=5,full_output=1,xtol=1e-5,ftol=1e-
3,maxfun=1e5,start_direc=np.eye(narparams+nmaparams))
print arma_powell.arparams
print arma_powell.maparams
"
Then throws error:
"
Traceback (most recent call last):
File "D:\data\python\arma\arma_powell", line 129, in <module>
arma_powell = arma_mod.fit(order=(3,2), trend='nc',
solver='powell',disp=5,full_output=1,xtol=1e-5,ftol=1e-
3,maxfun=1e5,start_direc=np.eye(narparams+nmaparams))
File "C:\Python26\lib\site-packages\statsmodels\tsa\arima_model.py", line
580, in fit
start_params = self._fit_start_params((k_ar,k_ma,k), method)
File "C:\Python26\lib\site-packages\statsmodels\tsa\arima_model.py", line
163, in _fit_start_params
start_params = self._fit_start_params_hr(order)
File "C:\Python26\lib\site-packages\statsmodels\tsa\arima_model.py", line
133, in _fit_start_params_hr
armod = AR(endog).fit(ic='bic', trend='nc')
File "C:\Python26\lib\site-packages\statsmodels\tsa\ar_model.py", line 523,
in fit
k_ar = self.select_order(k_ar, ic)
File "C:\Python26\lib\site-packages\statsmodels\tsa\ar_model.py", line 408,
in select_order
maxiter=100, disp=0)
File "C:\Python26\lib\site-packages\statsmodels\tsa\ar_model.py", line 541,
in fit
arfit = OLS(Y,X).fit()
File "C:\Python26\lib\site-packages\statsmodels\regression\linear_model.py",
line 501, in __init__
super(OLS, self).__init__(endog, exog)
File "C:\Python26\lib\site-packages\statsmodels\regression\linear_model.py",
line 394, in __init__
super(WLS, self).__init__(endog, exog)
File "C:\Python26\lib\site-packages\statsmodels\regression\linear_model.py",
line 149, in __init__
super(GLS, self).__init__(endog, exog)
File "C:\Python26\lib\site-packages\statsmodels\base\model.py", line 69, in
__init__
super(LikelihoodModel, self).__init__(endog, exog)
File "C:\Python26\lib\site-packages\statsmodels\base\model.py", line 33, in
__init__
self._data = handle_data(endog, exog)
File "C:\Python26\lib\site-packages\statsmodels\base\data.py", line 306, in
handle_data
return klass(endog, exog=exog)
File "C:\Python26\lib\site-packages\statsmodels\base\data.py", line 21, in
__init__
self._check_integrity()
File "C:\Python26\lib\site-packages\statsmodels\base\data.py", line 101, in
_check_integrity
if len(self.exog) != len(self.endog):
TypeError: len() of unsized object
"
Considering the small sampling, I have tried to reduce the order of ARMA model
to arma(1,2), then code is successfully executed.
So it seems that the order is too high for "x=[2.472,1.135,-0.086,2.342,-
2.668,-0.788, -2.408]" to get right estimation of ARMA(3,2), does it?
If it is true, I just want to know why? Without regard to the precision of
estimation for small sampling, only speak from programming,
it is still possible to estimat params of ARMA(3,2) model for "x=[2.472,1.135,-
0.086,2.342,-2.668,-0.788, -2.408]",
so is there some other consideration to force you decide to terminate
execution under such conditions?
Furthermore, while tracing ARMA.fit(), I am blocked by statsmodels->tsa-
>kalmanf->kalman_loglike.pyd, with .pyd not being able to open. So could I
have a
look at this file in some ways?Thank you.

LiJun

Skipper Seabold

unread,
May 17, 2012, 8:58:04 AM5/17/12
to pystat...@googlegroups.com
The problem is in how we calculate the starting parameters here. We
have to take away pre-sample values and then we're left with a numpy
scalar for some reason, which you can't call len on. I haven't drilled
down to the details, but you can do

arma_powell = arma_mod.fit(order=(3,2), trend='nc', start_params=np.zeros(5))

And it should "work," though the parameters are likely garbage.

> Furthermore, while tracing ARMA.fit(), I am blocked by statsmodels->tsa-
>>kalmanf->kalman_loglike.pyd, with .pyd not being able to open. So could I
> have a
> look at this file in some ways?Thank you.

You'll want to look at the .pyx file. It should be included in the
source. .pyd is the compiled Cython code on Windows.

Skipper
Reply all
Reply to author
Forward
0 new messages