Skip to content

BUG: ARIMAX predict when exog is too long #2472

Closed

Description

@josef-pkt

see discussion starting here #2470 (comment)

summary: if exog is longer than what is required for the prediction, then the first slice is used. According to Chad the last observation for this is incorrect.
However, if we want to forecast or predict with a later start, and we accidentally used the full exog, then we get incorrect prediction.

My suggestion is to raise a ValueError if exog has the incorrect length.
As alternative and more userfriendly, we could use the pandas index to find the correct slice of the exog that corresponds to start, end dates, if available.

update: #2472 fixed the incorrect last value, but doesn't raise or warn if exog is too long.

current behavior (after 2472)
If the exog is longer than necessary, then the first observations are used up to the required length. The remaining observations of exog are ignored.
I think this is independent of whether the exog is a pandas DataFrame that would have the matching index. I still think that this will be a "surprise" for many users.

Activity

  1. added this to the 0.7 milestone on Jun 25, 2015
  2. josef-pkt commented on Jun 25, 2015

    @josef-pkt
    MemberAuthor

    @jseabold Do you have an opinion on this and know where to fix it?

  3. ChadFulton commented on Jun 25, 2015

    @ChadFulton
    Member

    Right now SARIMAX raises a ValueError if exog is not the right shape. I suppose we should keep them in sync whatever the decision is.

  4. josef-pkt commented on Jun 25, 2015

    @josef-pkt
    MemberAuthor

    @ChadFulton solution almost works, except mu[steps - 2] (I don't know why index is shifted

    line 354

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

    then I get exactly the same prediction with a correct length exog and an exog that has the same observations at the beginning of the array.

  5. josef-pkt commented on Jun 25, 2015

    @josef-pkt
    MemberAuthor

    Doing this change, I get a test failure in the last predicted value in

    test_arima_predict_exog():
        # check 625 and 626
        arima_forecasts = read_csv(current_path + "/results/"
                                "results_arima_exog_forecasts_mle.csv")
    
    (Pdb) np.column_stack((x[-5:], y[-5:], x[-5:] - y[-5:]))
    array([[  2.05101116e+00,   2.05101100e+00,   1.55481706e-07],
           [  2.04487943e+00,   2.04487900e+00,   4.27216359e-07],
           [  2.03874670e+00,   2.03874700e+00,  -2.98787707e-07],
           [  2.03261383e+00,   2.03261400e+00,  -1.73223410e-07],
           [  2.03130208e+00,   2.02648100e+00,   4.82108311e-03]])
    

    @jseabold Do you remember where the "results_arima_exog_forecasts_mle.csv" values come from?

  6. ChadFulton commented on Jun 25, 2015

    @ChadFulton
    Member

    @ChadFulton solution almost works, except mu[steps - 2] (I don't know why index is shifted

    line 354

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

    then I get exactly the same prediction with a correct length exog and an exog that has the same observations at the beginning of the array.

    For me, it only works with steps - 1.

  7. josef-pkt commented on Jun 27, 2015

    @josef-pkt
    MemberAuthor

    I switched to a different example and now I also need mu[steps - 1]. Most likely I didn't understand what I was doing in the previous example.

    Now, I'm comparing with Stata, and have agreement at print precision 8 digits (7 decimals) in predict. For a ARMA(1,0,1) in levels of loginv ~ loggdp + logcons with our datasets.macrodata

  8. modified the milestones: 0.8, 0.7 on Jun 29, 2015
  9. josef-pkt commented on Jun 29, 2015

    @josef-pkt
    MemberAuthor

    still open but not prio-high and something to look into for 0.8

  10. self-assigned this
    on Jul 23, 2019
  11. added a commit that references this issue on Jul 24, 2019
    d9f4b2b
  12. modified the milestones: 0.8, 0.11 on Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions