Thread Subject: Calculating MAD statistic using grpstats

Subject: Calculating MAD statistic using grpstats

From: Iwona

Date: 20 Nov, 2009 08:05:09

Message: 1 of 3

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

Subject: Calculating MAD statistic using grpstats

From: Tom Lane

Date: 20 Nov, 2009 20:03:26

Message: 2 of 3

>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

Subject: Calculating MAD statistic using grpstats

From: Iwona

Date: 24 Nov, 2009 05:01:42

Message: 3 of 3

Thanks Tom. That's a handy tip for other functions other than grpstats.

Iwona

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com