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

Fix machine error negative values on m2 #238

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jarque_bera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function JarqueBeraTest(y::AbstractVector{T}) where T<:Real
m4r += yi^4 / n
end
# compute central moments (http://mathworld.wolfram.com/CentralMoment.html)
m2 = -m1r^2 + m2r
m2 = abs(-m1r^2 + m2r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the (dis)advantages of this approach are compared with

Suggested change
m2 = abs(-m1r^2 + m2r)
m2 = max(-m1r^2 + m2r, 0)

Copy link
Author

@viraltux viraltux Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just about to pull a request for that option! It is better. At least mathematically more pleasant. Unless abs is faster than max... but probably not.

And now I am thinking that in the example that fails the second moment is not exactly zero which means that abs in that scenario is more precise than max that would set the second moment to exactly zero.

Now I think I should revert back to abs again! Okay, I'll sleep on it.

m3 = 2 * m1r^3 - 3 * m1r * m2r + m3r
m4 = -3 * m1r^4 + 6 * m1r^2 * m2r - 4 * m1r * m3r + m4r

Expand Down