From: Iwona on
I would like to calculate the MAD statistic (Median Absolute Deviation) for grouped data using the grpstats function. However, the grpstat function won't allow me to input the required syntax for that statistic i.e. mad(X,1)

I can only input 'mad', which calculates MAD based on means i.e. Xmad = grpstats(X,group,{'mad'}). However, I'm after MAD based on medians.

I get an error when I try:
Xmad = grpstats(X,group,{'mad(X,1)'})

Any suggestions?

Iwona
From: Tom Lane on
>I would like to calculate the MAD statistic (Median Absolute Deviation) for
>grouped data using the grpstats function. However, the grpstat function
>won't allow me to input the required syntax for that statistic i.e.
>mad(X,1)
>
> I can only input 'mad', which calculates MAD based on means i.e. Xmad =
> grpstats(X,group,{'mad'}). However, I'm after MAD based on medians.

Iwona, you need to make your own function of one argument. It's easy to do.
Compare these:

>> grpstats(meas,species,{@mad})
ans =
0.2707 0.2874 0.1315 0.0826
0.4214 0.2548 0.3792 0.1571
0.5026 0.2422 0.4400 0.2281
>> grpstats(meas,species,{@(x) mad(x,1)})
ans =
0.2000 0.2500 0.1000 0
0.3500 0.2000 0.3500 0.1500
0.4000 0.2000 0.4500 0.2000

-- Tom


From: Iwona on
Thanks Tom. That's a handy tip for other functions other than grpstats.

Iwona
 | 
Pages: 1
Prev: Newton-Raphson Method
Next: brushless