If a time series is unevenly spaced, the simple moving average is not the best option to smooth it out (the window will be larger or narrower depending on the time distance of the events within that interval). Which method would you suggest that can be implemented when the time sampling of data is not constant?
-
$\begingroup$ Perhaps use an adaptive window lenght that is determined by the actual time intervals between points rather than the number of points in a window. $\endgroup$– Richard HardyCommented Oct 16, 2017 at 16:19
-
$\begingroup$ Right, but then the number of points per window would vary dramatically, affecting the analysis. $\endgroup$– RolandCommented Oct 20, 2017 at 9:35
-
$\begingroup$ If my proposal had no effect, I would not have proposed it. The question is what makes sense, not whether the analysis gets affected. Note that what StephanKolassa suggested is very much in the same spirit. There is no way around the fact that the points are unevenly distributed. In the sparse regions, there is little information, period. $\endgroup$– Richard HardyCommented Oct 20, 2017 at 10:04
-
$\begingroup$ By following Stephan's suggestion I can keep the same number of points per window and give them just a different weight. On the other hand, if I implement your suggestion, I would have a very different number of points per window, which, yes, would affect my analysis. With that I mean it would not make sense for the purpose of my work. $\endgroup$– RolandCommented Oct 20, 2017 at 10:31
-
$\begingroup$ OK, I should explain the connection that seemed obvious to me. By Stephan's suggestion, you keep the same number of points with some weighting scheme (e.g. triangular). By my suggestion, you keep the same number of points with a particular weighting scheme: the points too far away in time get a weight of zero, the other ones get a weight of one over the number of such points. $\endgroup$– Richard HardyCommented Oct 20, 2017 at 13:36
1 Answer
The simple moving average can be considered as a weighted average of neighboring data points, where weights are 1 for data points that fall within the window and 0 for data points outside.
More sophisticated averages use triangular weightings. Or other kernels.
This suggests an analogue for irregularly sampled time series: use a weighted average of neighboring points, with weights that depend on how far these points are away from the time point you are averaging for. (This will also give you an interpolated value at a time point that you don't have an original sample for.) The weight function could again be triangular, for instance.
-
$\begingroup$ Thank you! I have just find out that it should be easy to do that in Matlab with :
tsmovavg(vector,'w',weights,dim)
$\endgroup$– RolandCommented Oct 20, 2017 at 9:40