-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect calculation of centered moving averages for even length series #14425
Comments
center is a very funny beast. The computation is done then the results are shifted. To be honest we should just remove this. This has been this way for quite a long time. |
actually this is a duplicate of #2953. has been open a long time. |
This is not the same issue. The one you refer to is apparently affecting Also it is easy to fix. It is just an test for length even and then On 14 Oct 2016 9:46 p.m., "Jeff Reback" notifications@github.com wrote:
|
And SPSS, sas, and minitab all calculate centred moving averages correctly. On 14 Oct 2016 11:25 p.m., "simon mackenzie" simonm3@gmail.com wrote:
|
@simonm3 - there's a lot going on in that issue, but changing the centered mean was part of it - this reference, which I think is the approach you expect? I'm guessing centered mean isn't used that often, but if there is a standard approach for double smoothing an even window, and you would like to submit a PR to support that, I think that would be great. |
I guess you can also fairly easily solve it like this?
|
It would have to be:
The current calculation of Also, IMHO, the issue linked to this as a duplicate really is not about even-sized centered windows, it's about some more complex issues. Given how easy it is to fix this, perhaps it's worth reopening it, so someone can fix it with a small PR? |
For even numbered periods the centered moving average is calculated incorrectly. Suppose the period length is 5. Then the center of 5 periods is 3. However if the period length is 4 then the center of the period is 2.5. The value at index 3 should be the average of the values at 2.5 and 3.5. Pandas is showing the 2.5 value at 3 which is incorrect.
EXAMPLE:
a=pd.Series(range(1,6), index=range(1,6))
a.rolling(4, center=True).mean()
1 NaN
2 NaN
3 2.5
4 3.5
5 NaN
The text was updated successfully, but these errors were encountered: