Clear Filters
Clear Filters

Mean function of timeseries with NaN

1 view (last 30 days)
Vito Melisurgo
Vito Melisurgo on 16 Jul 2018
Commented: Vito Melisurgo on 17 Jul 2018
First I define a simple timeseries with NaN value:
x=timeseries([5 5 5 5 NaN],[1 2.5 3.8 4 4.2]);
Then I expect that mean value (time weighted) would be 5.
But the result of
mean(x,'Weighting','time') is 5.9414
Why?

Answers (1)

dpb
dpb on 16 Jul 2018
MATLAB determines weighting by:
Attaching a weighting to each time value, depending on its order, as follows:
First time point — The duration of the first time interval (t(2) - t(1)).
Time point that is neither the first nor last time point — The duration between the midpoint of the previous time interval to the midpoint of the subsequent time interval ((t(k + 1) - t(k))/2 + (t(k) - t(k - 1))/2).
Last time point — The duration of the last time interval (t(end) - t(end - 1)).
Normalizing the weighting for each time by dividing each weighting by the mean of all weightings.
I didn't try to compute what those would be for your time vector, but the net result appears to result in 5.9 for the weighted answer.
  1 Comment
Vito Melisurgo
Vito Melisurgo on 17 Jul 2018
Thank you for your answer. First it should be divided eventually for sum and not mean, when applying any kind of weigthing the sum of all wiegths must be 1. The problem rises when NaN is present, it is not excluded from calcultation and for timeseries mean it seems there is not an option 'omitnan' as it is for simple mean applied to a Vector/matrix.

Sign in to comment.

Categories

Find more on Time Series in Help Center and File Exchange

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!