[R] MAD
Deepayan Sarkar
deepayan.sarkar at gmail.com
Mon Sep 17 23:09:35 CEST 2007
On 9/17/07, Nair, Murlidharan T <mnair at iusb.edu> wrote:
>
> I am calculating the median absolute deviation using mad function, and
> it tends to ignore the parameter constant=1, when I am calculating it
> for x=seq(1:5). Am I missing something here?
>
> x<-seq(1:5)
> mad(x)# gives [1] 1.4826
> mad(x, constant=1)# gives [1] 1
> #Here is the long form
> dev.from.median<-abs((x-median(x)))
> dev.from.median # Gives [1] 2 1 0 1 2
> sum(dev.from.median) # Gives [1] 6
> sum(dev.from.median)/length(x) # Gives [1] 1.2
> # The long form does not match the output from the function
>
> # When x<-seq(1:10) they match
> x<-seq(1:10)
> dev.from.median<-abs((x-median(x)))
> sum(dev.from.median)/length(x) # Gives 2.5
> mad(x, constant=1) # Gives 2.5
> #The long form matches the output from the function
>
> Did I miss anything here?
yes; mad := Median (not mean) absolute deviation (from the median, by default).
-Deepayan
More information about the R-help
mailing list