Skip to content

Commit 86507ee

Browse files
aplavinandreasnoack
authored andcommitted
fix #905: use the correct mad() normalization
1 parent 8d99281 commit 86507ee

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StatsBase"
22
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
33
authors = ["JuliaStats"]
4-
version = "0.34.4"
4+
version = "0.35.0"
55

66
[deps]
77
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"

src/deprecates.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ end
1313

1414
@deprecate norepeats(a::AbstractArray) allunique(a)
1515

16-
@deprecate(mad!(v::AbstractArray{<:Real}, center;
17-
constant::Real = BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701")),
18-
mad!(v, center=center, constant=constant))
19-
2016
### Deprecated January 2019
2117
@deprecate scattermatm(x::DenseMatrix, mean, dims::Int) scattermat(x, mean=mean, dims=dims)
2218
@deprecate scattermatm(x::DenseMatrix, mean, wv::AbstractWeights, dims::Int) scattermat(x, wv, mean=mean, dims=dims)

src/scalarstats.jl

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ function sem(x::AbstractArray, weights::ProbabilityWeights; mean=nothing)
524524
end
525525

526526
# Median absolute deviation
527-
@irrational mad_constant 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701")
527+
@irrational mad_to_std_multiplier 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701")
528528

529529
"""
530-
mad(x; center=median(x), normalize=true)
530+
mad(x; center=median(x), normalize=false)
531531
532532
Compute the median absolute deviation (MAD) of collection `x` around `center`
533533
(by default, around the median).
@@ -536,12 +536,12 @@ If `normalize` is set to `true`, the MAD is multiplied by
536536
`1 / quantile(Normal(), 3/4) ≈ 1.4826`, in order to obtain a consistent estimator
537537
of the standard deviation under the assumption that the data is normally distributed.
538538
"""
539-
function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing, constant=nothing)
540-
mad!(Base.copymutable(x); center=center, normalize=normalize, constant=constant)
539+
function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing)
540+
mad!(Base.copymutable(x); center=center, normalize=normalize)
541541
end
542542

543543
"""
544-
StatsBase.mad!(x; center=median!(x), normalize=true)
544+
StatsBase.mad!(x; center=median!(x), normalize=false)
545545
546546
Compute the median absolute deviation (MAD) of array `x` around `center`
547547
(by default, around the median), overwriting `x` in the process.
@@ -552,24 +552,16 @@ of the standard deviation under the assumption that the data is normally distrib
552552
"""
553553
function mad!(x::AbstractArray;
554554
center=median!(x),
555-
normalize::Union{Bool,Nothing}=true,
556-
constant=nothing)
555+
normalize::Union{Bool,Nothing}=false)
557556
isempty(x) && throw(ArgumentError("mad is not defined for empty arrays"))
558557
c = center === nothing ? median!(x) : center
559558
T = promote_type(typeof(c), eltype(x))
560559
U = eltype(x)
561560
x2 = U == T ? x : isconcretetype(U) && isconcretetype(T) && sizeof(U) == sizeof(T) ? reinterpret(T, x) : similar(x, T)
562561
x2 .= abs.(x .- c)
563562
m = median!(x2)
564-
if normalize isa Nothing
565-
Base.depwarn("the `normalize` keyword argument will be false by default in future releases: set it explicitly to silence this deprecation", :mad)
566-
normalize = true
567-
end
568-
if !isa(constant, Nothing)
569-
Base.depwarn("keyword argument `constant` is deprecated, use `normalize` instead or apply the multiplication directly", :mad)
570-
m * constant
571-
elseif normalize
572-
m * mad_constant
563+
if normalize === true
564+
m * mad_to_std_multiplier
573565
else
574566
m
575567
end

0 commit comments

Comments
 (0)