Skip to content

Wrong error message when fitting a VAR model to a small dataset #2648

Open

Description

@Kristian60

If attempting to fit a statsmodels.VAR model to a DataFrame that is too small, during the choleskey factorization, it will return the error
"ValueError: array must not contain infs or NaNs" that ultimately stems from numpy\lib\function_base.py", line 613, in asarray_chkfinite
"array must not contain infs or NaNs"

An assertion could have been made at an earlier point to capture this error, and give a descriptive roor message.

Activity

  1. josef-pkt commented on Oct 8, 2015

    @josef-pkt
    Member

    Why does the error message mention infs or NaNs? Did you check that you don't have missing values in the DataFrame?

    What's the shape of your data in the call to VAR, and what's the order of the VAR (number of lags) that you want to estimate?

    If it's insufficient number of time points to estimate, and there is no appropriate, informative ValueError, then I agree to adding one.

  2. Kristian60 commented on Oct 8, 2015

    @Kristian60
    Author

    Im was attempting to fit a (99 x 11) DataFrame to a

    model = sm.VAR(data)
    results = model.fit(maxlags=10, ic='aic')
    

    after cleaning the data by

    df = df.dropna()
    

    the problem solved itself when i changed maxlags, or included more datapoints. (ie. 999 x 11)

  3. josef-pkt commented on Oct 8, 2015

    @josef-pkt
    Member

    Did you get a useful error message with the clean data but with time series that are too short?

  4. josef-pkt commented on Oct 8, 2015

    @josef-pkt
    Member

    Usage question: When you dropna, do you have missing values only at the beginning or at the end, or also in between observations?

    The problem with time series is that dropping nans in between observations will shift the time periods and will in most cases not be appropriate.

  5. Kristian60 commented on Oct 8, 2015

    @Kristian60
    Author

    No, it leads be down a wormhole that ends with

    statsmodels\tools\linalg.py
    c, _ = linalg.cho_factor(m, lower=True)
    

    and trough to scipy, that gives me an error, either due to NaN or not getting a positive definit leading minor.

  6. added this to the 0.8 milestone on Oct 8, 2015
  7. josef-pkt commented on Oct 8, 2015

    @josef-pkt
    Member

    @Kristian60 Thanks, so a proper error message is still missing.

  8. Kristian60 commented on Oct 8, 2015

    @Kristian60
    Author

    Yes, the error message is missing.

    I only use dropna to do

    df = np.log(df).diff().dropna()
    

    so I'm only removing the first line of NaNs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions