Skip to content

fix #905: use the correct mad() normalization #949

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Jan 29, 2025

Make mad() actually follow the definition of median absolute deviation as it is generally defined (eg https://en.wikipedia.org/wiki/Median_absolute_deviation, scipy, matlab, mathematica, ...).

Obviously breaking. Are there any other breaking fixes that could go into the next StatsBase version?

See #905, #97, #347 for more context.

@andreasnoack andreasnoack added the breaking A breaking change that needs a semver major release label Apr 29, 2025
@@ -536,12 +536,12 @@ If `normalize` is set to `true`, the MAD is multiplied by
`1 / quantile(Normal(), 3/4) ≈ 1.4826`, in order to obtain a consistent estimator
of the standard deviation under the assumption that the data is normally distributed.
"""
function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing, constant=nothing)
mad!(Base.copymutable(x); center=center, normalize=normalize, constant=constant)
function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing)
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a breaking change, I think we should remove support for normalize::Nothing since seemingly it's only purpose is to print a deprecation warning.

Suggested change
function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing)
function mad(x; center=nothing, normalize::Bool=false)

@@ -552,24 +552,16 @@ of the standard deviation under the assumption that the data is normally distrib
"""
function mad!(x::AbstractArray;
center=median!(x),
normalize::Union{Bool,Nothing}=true,
constant=nothing)
normalize::Union{Bool,Nothing}=false)
isempty(x) && throw(ArgumentError("mad is not defined for empty arrays"))
c = center === nothing ? median!(x) : center
Copy link
Member

Choose a reason for hiding this comment

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

Is it documented anywhere and actually useful that center::Nothing is supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking change that needs a semver major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants