Optimal window size for contextual outlier detection I am looking for methods to detect univariate contextual outliers in time series data. One example application is data from industrial plants in different (unknown) operation modes or slow trends or shifts but no seasonal effects.
In the following graph visually the contextual outliers above and below the trend can be identified clearly.

Most global outlier detection methods can be used with a sliding window approach. But a method, that automatically derives the optimal window size from the data or even provides an adaptive window size would be beneficial.
 A: I would need more information, but judging solely from your plot, it looks like a simple median filer (not average/mean) would do the job. If your outliers are single ticks, even a median filter of window size 3 would be able to discard them. But if the outliers show well-defined peaks, the window size should be roughly larger than the peak bases.
A: Taking your description as a starting point, using ADWIN combined with kernel density estimation (KDE) could fit the bill.
The ADWIN algorithm automatically adjusts the window size given the level of the signal. After a window size adjustment, one is left with a set of observations in the window that are supposed to have the same level.
Using KDE one can then estimate the density of this set (note: without any distribution assumptions since KDE is non-parametric) and hence detect outliers. If you are unfamiliar with KDE, it is quite simple: Youtube will have you up to speed in 3 minutes.
A reference to this setup can be found here
Let me know how you fare; I would be interested.
