Skip to content
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

StatsBase.mean ~= NaNMath.mean #60

Closed
CMGreenspon opened this issue Aug 31, 2022 · 2 comments
Closed

StatsBase.mean ~= NaNMath.mean #60

CMGreenspon opened this issue Aug 31, 2022 · 2 comments

Comments

@CMGreenspon
Copy link

CMGreenspon commented Aug 31, 2022

NaNMath.mean and StatsBase.mean do not produce the same result

using NaNMath
using StatsBase
temp = rand(100)
NaNMath.mean(temp) == StatsBase.mean(temp)

This will evaluate to false.
This seems to be true after digit 15:
round(mean(temp),digits=16) == round(NaNMath.mean(temp),digits=16)
Any idea why?

@jd-foster
Copy link
Contributor

The difference between the two is only at most the floating point round-off error, and is an inevitable part of computation in finite precision arithmetic. You can see the variation by something like

A = Float64[]
for i in 1:1000
    temp = rand(100);
    push!(A, NaNMath.mean(temp) - StatsBase.mean(temp))
 end
[minimum(A), maximum(A)]

and compare this to eps().

@mlubin
Copy link
Collaborator

mlubin commented Sep 2, 2022

Agreed with @jd-foster. It's unreasonable to expect exact equality in this case.

@mlubin mlubin closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants