Skip to content

outliers in time series, winsorizing, frequency domain filtering #943

Open

Description

@josef-pkt

use an ARMA filter to winsorize outlying observations

I don't know how to use a central (back and forward) filter in time domain, but it should be easy in frequency domain.

(Just a thought while fixing TArma as testcase in miscmodels,
With TArma I get almost the same coefficients as with ARMA but smaller bse when the DGP has t-distributed innovations.)

Activity

  1. Padarn commented on Sep 8, 2013

    @Padarn
    Contributor

    Wouldn't one just fit the ARMA model to the time series and then trim the residuals? Or am I misinterpreting what you're suggesting.

  2. josef-pkt commented on Sep 8, 2013

    @josef-pkt
    MemberAuthor

    I don't know what the best way or the literature on this is. The thought was based on outlier identification or outler robust methods for linear models and working on T-Arma which is more robust to heavy tails or outliers than the normal ARMA.

    Essentially it would be an iterative process, estimate, identify and winsorize outliers, estimate again, ...

    Not clear to my:
    do we estimate with the full sample and find residuals in the standard way, or should we use an implied centered filter (apply forecasting and backward casting, "smoothing" in Box-Jenkin IIRC). or
    do we estimate, recursively up to an observation and use prediction error for next observation to construct residuals, winsorize if necessary. estimate with next observation.

  3. Padarn commented on Sep 8, 2013

    @Padarn
    Contributor

    I can't comment on the best practice here, but it would probably be useful if the results from an ARMA model (or just ARMA model + parameters) could be used to filter a series - for example in pre-whitening or as part of the iterative Windsoring you're suggesting. Unless of course this is already available and I'm missing it ...

  4. josef-pkt commented on Aug 29, 2014

    @josef-pkt
    MemberAuthor

    it would probably be useful if the results from an ARMA model (or just ARMA model + parameters) could be used to filter a series

    There was a similar question on stackoverflow recently: apply an ARMA with estimated parameters to a new dataset.

    The filtering is all available in the ArmaProcess class but never fully cleaned up and incompletely tested, and likely not very nice to use.

  5. added this to the 0.7 milestone on Aug 29, 2014
  6. Padarn commented on Aug 29, 2014

    @Padarn
    Contributor

    Is the milestone to clean up the filter to do this?

  7. jseabold commented on Aug 29, 2014

    @jseabold
    Member

    I think there's still an open PR for ArmaProcess to clean it up.

    There's also outlier identification with the X-12 stuff.

  8. josef-pkt commented on Aug 29, 2014

    @josef-pkt
    MemberAuthor

    Yes, ArmaProcess is a separate cleanup.

    I thought here of getting at least started with some functions for tsa outliers (and missing values). The hampel function looks easy.
    My script on the mailing list should work well but I wanted to compare it with what Tsay has in his article. It was also a try for me to get the two-sided filter instead of just forward filtering, IIRC

    Chad's StateSpace models also allows for missing values that could be reused.
    X-12 has only limited frequencies and might not be general enough outside of macro economics or similar, AFAIR. But we should at least get a wrapper for outlier detection for it.

    I haven't looked at any of the seasonal stuff.

  9. josef-pkt commented on Aug 29, 2014

    @josef-pkt
    MemberAuthor

    Besides outlier detection and outlier removal I also thought about estimation with outliers or heavy tails. But that's further off.

    TArma does a bit of it. Other approaches could be based on trimming or winsorizing of outliers or tail observations. That should be useful in finance.

  10. modified the milestones: 0.8, 0.7 on Jul 17, 2015
  11. josef-pkt commented on Apr 13, 2016

    @josef-pkt
    MemberAuthor

    @Leoyzen To continue on tsoutliers frin #2873

    I think what would be useful for applications is to write some wrapper functions that iterate over ARMA or SARIMAX estimation and adjust the models depending on detected outliers.

    for example 3 functions (or possibly 1 function and two extendable classes)

    • outlier_test, detection: similar to outlier test for linear model, take residuals, calculate a robust variance (e.g. MAD or based on interquartile range) and find index of largest residuals, with some threshold for outlier identification, when we have to choose.
    • iterative fitting based on outliers:
      • robust estimation with outlier dummies: add a dummy variable to exog for all detected outliers.
      • winsorized version: clip endog to some threshold based on outlier detection, e.g. proportional to robust estimate of standard error of residuals. In this case forecasting would be based on the "corrected" data and would not propagate outliers.

    This could for example go into a robust module in statsmodels.tsa.

    Other approaches for heavy tailed residual distribution would be using the cauchy or t distribution in the likelihood or implementing weights in the tsa models.
    (I would not get started with weights in tsa because the impact is more difficult to guess. Before refactoring to add weights to tsa models, somebody needs to have a good knowledge or reference to what they are supposed to do. One reference usecase might be GARCH models and heteroscedasticity which are not in my immediate plans because @bashtage is working on it in his arch package.)

  12. josef-pkt commented on Mar 31, 2018

    @josef-pkt
    MemberAuthor

    iterative fitting based on outliers:

    how do we do the trimming?
    we need some helper functions or recipes. I know it can be done, but I'm not able to do it without a few hours or search.

    E.g. I have a SARIMAX model with two dummy variables for two observation (argmin and argmax of the residual in a preliminary estimate, or of "known" outliers.)
    How can I get the conditional prediction for those two observations, so a can compute a winsorized value, shrinkage target or imputed value?
    tsa predict does not allow using a different exog in predict. (I don't find the related issue)
    So, we need to create a new model with adjusted data and predict or smooth with the params that was used in the model with outlier dummies.

    using missing values:
    statespace models can handle missing values, so if we define outlier observations as nan, then we might be able to get the conditional prediction.

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