# Judging flatness of time-series

I have multiple short (say, length <100 points) time-series as exemplified below. All the series are made of values measured in the same units. I need to find some criterion for judging their "flatness". Preferably, I'd like to find single numeric value, so that I can find some decision boundary that let's me distinguish the "flat" time-series (second plot) from the "non-flat" ones (first plot).

By "non-flat" time-series I mean the ones that have relatively short periods of significantly increased values. By "flat" time series I mean the ones that have all the time very similar magnitude of changes. Some kind of slight linear trend may, or may not, be present in the series. Can you suggest something? I tried multiple approaches starting from simple ones (using variance), to more sophisticated ones (using methods for change-point analysis), but without satisfactory results.

• Interesting. Could you tell what drawbacks variance and other methods had? Knowing that it could be easier to think in the right direction. – Richard Hardy Jan 27 '17 at 10:09
• @RichardHardy I'd need to go into too many unimportant details. I levae this open-ended and ask for suggestions. Basically things like changepoint analysis in many cases did not found changepoints or found too many of them, and using stuff like variance leads to other problems (clustered peaks are not recognized). – Tim Jan 27 '17 at 14:48
• I wonder how that happens with clustered peaks (don't have the intuition). – Richard Hardy Jan 27 '17 at 14:53
• @RichardHardy "not recognized" in the sense that no matter if peaks are clustered, or "chaotic" variance could be similar. – Tim Jan 27 '17 at 14:59
• The obvious response is "use the variance of the data" (or first differences thereof, if you really do mean "changes"), because that is simple and directly measures the characteristics you describe. (Low variance is directly and reliably associated with "all the time very similar magnitude of changes.") Since you surely are aware of this option, could you elaborate on what you perceive to be its shortcomings and how exactly a good solution would improve on it? – whuber Jan 27 '17 at 19:41

I would consider the following protocol, which I would call quick-and-dirty. Code is from R.

a) Determine a linear model

mod<-lm(signal ~ t)

to see if there is evidence for a trend. See if the coefficients have p-values satisfying $$p \le 0.025$$, or some other suitably small $$\alpha/2$$.

b) Subtract the model elements that are significant at your chosen $$\alpha/2$$.

c) Considering only the residuals obtained from part b, determine if a non-trivial auto-correlation exists.

plot(acf(residuals))

If there is no evidence of autocorrelation with lag $$d > 0$$, namely, that for all $$d$$, $$ACF < 1.96/(T-d)$$, as described by @RichardHardy here, where $$T$$ is the number of points in the sample, then then you may conclude "flat," or really "featureless."

If there is evidence of autocorrelation with lag $$d>0$$ then you may conclude, provisionally, "not flat" pending analysis of other models in which you test if "bumps" in the time series meet your criterion for being "well-formed" or "coherent".

End quick and dirty.

A related question is whether a time series is stationary. You didn't ask that, but if you had, there would be more to say. Regardless, for short time series, it is hard to conclude demonstrate non-stationarity on any meaningfully long time scale.

So quick-and-dirty is probably the way to go.

I can imagine a report that summarizes statistically significant model structures for each time series. This report would contain information like the #of step/level shifts encountered, the # of positive pulses , the # of negative pulses , the # of deterministic trends , a pointer indicating a stochastic trend ,# of break points in error variance etc. . This information could then be post-processed for purposes of distinguishing between the characteristic of 'flatness' . I have programmed a number of these summary reports which enable contrasts to be made. This is a feature of AUTOBOX which I have helped to develop and it might be useful for you to see them as an example of what you could possibly implement.

• I think @Tim wants a simple metric or heuristic for one characteristic, not a full-blown multi-measure health check or machine service! – Nick Cox Jan 27 '17 at 18:01
• you are probably right ..however it might be reasonable to subjectively combine/weigh. a number of attributes in order to to come up with a measure of "flatness". – IrishStat Jan 27 '17 at 20:34