Help with mean absolute deviation function (MAD).

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help with mean absolute deviation function (MAD).

Daniel Carrera
Hello,

My "mad" function seems to be broken. Maybe I just don't know how to use it right:

julia> using StatsBase

julia> @doc mad
  No documentation found.

  StatsBase.mad is a generic Function.

  # 2 methods for generic function "mad":
  mad{T<:Real}(v::Range{T<:Real}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:180
  mad{T<:Real}(v::AbstractArray{T<:Real,N}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> mad([1,2,3,4])
ERROR: InexactError()
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:184
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:183
 in mad at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> 



Does anyone know what's happening? Also, I am confused by the "constant" parameter. The documentation says:

mad(x[center][; constant=1.4826])

Compute the median absolute deviation of x.

One can optionally supply the center. By default, constant=1.4826 for consistent estimation of the standard deviation of a normal distribution.




Does this mean that, by default, the mad() function doesn't give you the MAD, bunt instead it gives you MAD*1.4826 ?

Thanks for the help.

Cheers,
Daniel.




--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with mean absolute deviation function (MAD).

j verzani
It seems `mad` calls `mad!` with a copy. The mad! function reuses the copied vector for storage. As the differences from the median are not integers you get an assignment error. That's fussy and should be easily addressed. The multiplier is also done by default in R so that the units of spread for mad and sd are similar.

On Wednesday, July 27, 2016 at 5:50:02 AM UTC-4, Daniel Carrera wrote:
Hello,

My "mad" function seems to be broken. Maybe I just don't know how to use it right:

julia> using StatsBase

julia> @doc mad
  No documentation found.

  StatsBase.mad is a generic Function.

  # 2 methods for generic function "mad":
  mad{T<:Real}(v::Range{T<:Real}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:180
  mad{T<:Real}(v::AbstractArray{T<:Real,N}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> mad([1,2,3,4])
ERROR: InexactError()
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:184
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:183
 in mad at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> 



Does anyone know what's happening? Also, I am confused by the "constant" parameter. The documentation says:

mad(x[center][; constant=1.4826])<a href="http://statsbasejl.readthedocs.io/en/latest/scalarstats.html#mad" title="Permalink to this definition" style="color:rgb(64,64,64);display:inline-block;font-weight:normal;font-stretch:normal;line-height:1;font-family:inherit;font-size:14.4px" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstatsbasejl.readthedocs.io%2Fen%2Flatest%2Fscalarstats.html%23mad\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1iTwxBJ6sUP-jONX8dZNVie1NDQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstatsbasejl.readthedocs.io%2Fen%2Flatest%2Fscalarstats.html%23mad\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1iTwxBJ6sUP-jONX8dZNVie1NDQ&#39;;return true;">

Compute the <a href="http://en.wikipedia.org/wiki/Median_absolute_deviation" style="color:rgb(155,89,182)" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMedian_absolute_deviation\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLC8Hfv_5mAJm1Cvf16XbcKqqPuA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMedian_absolute_deviation\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLC8Hfv_5mAJm1Cvf16XbcKqqPuA&#39;;return true;">median absolute deviation of x.

One can optionally supply the center. By default, constant=1.4826 for consistent estimation of the standard deviation of a normal distribution.




Does this mean that, by default, the mad() function doesn't give you the MAD, bunt instead it gives you MAD*1.4826 ?

Thanks for the help.

Cheers,
Daniel.




--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with mean absolute deviation function (MAD).

Daniel Carrera
Thanks.

Why can't the MAD just be implemented as `mad(x) = median(abs(x - median(x)))` ?

Cheers,
Daniel.

On 27 July 2016 at 15:49, j verzani <[hidden email]> wrote:
It seems `mad` calls `mad!` with a copy. The mad! function reuses the copied vector for storage. As the differences from the median are not integers you get an assignment error. That's fussy and should be easily addressed. The multiplier is also done by default in R so that the units of spread for mad and sd are similar.

On Wednesday, July 27, 2016 at 5:50:02 AM UTC-4, Daniel Carrera wrote:
Hello,

My "mad" function seems to be broken. Maybe I just don't know how to use it right:

julia> using StatsBase

julia> @doc mad
  No documentation found.

  StatsBase.mad is a generic Function.

  # 2 methods for generic function "mad":
  mad{T<:Real}(v::Range{T<:Real}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:180
  mad{T<:Real}(v::AbstractArray{T<:Real,N}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> mad([1,2,3,4])
ERROR: InexactError()
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:184
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:183
 in mad at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> 



Does anyone know what's happening? Also, I am confused by the "constant" parameter. The documentation says:

mad(x[center][; constant=1.4826])

Compute the median absolute deviation of x.

One can optionally supply the center. By default, constant=1.4826 for consistent estimation of the standard deviation of a normal distribution.




Does this mean that, by default, the mad() function doesn't give you the MAD, bunt instead it gives you MAD*1.4826 ?

Thanks for the help.

Cheers,
Daniel.




--
You received this message because you are subscribed to a topic in the Google Groups "julia-stats" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-stats/zQDssmSjdyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with mean absolute deviation function (MAD).

Andreas Noack
median(abs(x - median(x))) probably creates three temporaries which is the reason to do this in place. The mad function should promote integers to floats before calling mad!. Please file an issue.

On Wed, Jul 27, 2016 at 9:55 AM, Daniel Carrera <[hidden email]> wrote:
Thanks.

Why can't the MAD just be implemented as `mad(x) = median(abs(x - median(x)))` ?

Cheers,
Daniel.

On 27 July 2016 at 15:49, j verzani <[hidden email]> wrote:
It seems `mad` calls `mad!` with a copy. The mad! function reuses the copied vector for storage. As the differences from the median are not integers you get an assignment error. That's fussy and should be easily addressed. The multiplier is also done by default in R so that the units of spread for mad and sd are similar.

On Wednesday, July 27, 2016 at 5:50:02 AM UTC-4, Daniel Carrera wrote:
Hello,

My "mad" function seems to be broken. Maybe I just don't know how to use it right:

julia> using StatsBase

julia> @doc mad
  No documentation found.

  StatsBase.mad is a generic Function.

  # 2 methods for generic function "mad":
  mad{T<:Real}(v::Range{T<:Real}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:180
  mad{T<:Real}(v::AbstractArray{T<:Real,N}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> mad([1,2,3,4])
ERROR: InexactError()
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:184
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:183
 in mad at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> 



Does anyone know what's happening? Also, I am confused by the "constant" parameter. The documentation says:

mad(x[center][; constant=1.4826])

Compute the median absolute deviation of x.

One can optionally supply the center. By default, constant=1.4826 for consistent estimation of the standard deviation of a normal distribution.




Does this mean that, by default, the mad() function doesn't give you the MAD, bunt instead it gives you MAD*1.4826 ?

Thanks for the help.

Cheers,
Daniel.




--
You received this message because you are subscribed to a topic in the Google Groups "julia-stats" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-stats/zQDssmSjdyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with mean absolute deviation function (MAD).

Daniel Carrera

On 27 July 2016 at 15:59, Andreas Noack <[hidden email]> wrote:
median(abs(x - median(x))) probably creates three temporaries which is the reason to do this in place. The mad function should promote integers to floats before calling mad!. Please file an issue.

On Wed, Jul 27, 2016 at 9:55 AM, Daniel Carrera <[hidden email]> wrote:
Thanks.

Why can't the MAD just be implemented as `mad(x) = median(abs(x - median(x)))` ?

Cheers,
Daniel.

On 27 July 2016 at 15:49, j verzani <[hidden email]> wrote:
It seems `mad` calls `mad!` with a copy. The mad! function reuses the copied vector for storage. As the differences from the median are not integers you get an assignment error. That's fussy and should be easily addressed. The multiplier is also done by default in R so that the units of spread for mad and sd are similar.

On Wednesday, July 27, 2016 at 5:50:02 AM UTC-4, Daniel Carrera wrote:
Hello,

My "mad" function seems to be broken. Maybe I just don't know how to use it right:

julia> using StatsBase

julia> @doc mad
  No documentation found.

  StatsBase.mad is a generic Function.

  # 2 methods for generic function "mad":
  mad{T<:Real}(v::Range{T<:Real}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:180
  mad{T<:Real}(v::AbstractArray{T<:Real,N}, args...) at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> mad([1,2,3,4])
ERROR: InexactError()
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:184
 in mad! at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:183
 in mad at /home/daniel/.julia/v0.4/StatsBase/src/scalarstats.jl:179

julia> 



Does anyone know what's happening? Also, I am confused by the "constant" parameter. The documentation says:

mad(x[center][; constant=1.4826])

Compute the median absolute deviation of x.

One can optionally supply the center. By default, constant=1.4826 for consistent estimation of the standard deviation of a normal distribution.




Does this mean that, by default, the mad() function doesn't give you the MAD, bunt instead it gives you MAD*1.4826 ?

Thanks for the help.

Cheers,
Daniel.




--
You received this message because you are subscribed to a topic in the Google Groups "julia-stats" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-stats/zQDssmSjdyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "julia-stats" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-stats/zQDssmSjdyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...