You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
outliers in time series, winsorizing, frequency domain filtering #943
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.)
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.
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 ...
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 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.)
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.
Activity
Padarn commentedon Sep 8, 2013
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.
josef-pkt commentedon Sep 8, 2013
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.
Padarn commentedon Sep 8, 2013
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 ...
josef-pkt commentedon Aug 29, 2014
just a few links
http://www.inside-r.org/packages/cran/pracma/docs/hampel
http://stackoverflow.com/questions/12218584/filtering-seasonal-time-series-outliers
http://exploringdatablog.blogspot.ca/2012/01/moving-window-filters-and-pracma.html
https://github.com/testlnord/trends/blob/master/core/stat/statmodule.py#L24
and I posted a frequency domain filter for interpolating missing values and removing outliers to the mailing list a while ago.
see also Tsay article (???)
josef-pkt commentedon Aug 29, 2014
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.
Padarn commentedon Aug 29, 2014
Is the milestone to clean up the filter to do this?
jseabold commentedon Aug 29, 2014
I think there's still an open PR for ArmaProcess to clean it up.
There's also outlier identification with the X-12 stuff.
josef-pkt commentedon Aug 29, 2014
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.
josef-pkt commentedon Aug 29, 2014
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.
josef-pkt commentedon Apr 13, 2016
@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)
exogfor all detected outliers.endogto 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
robustmodule 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
archpackage.)josef-pkt commentedon Mar 31, 2018
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.