Code covered by the BSD License  

Highlights from
Group Equally

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.66 KB File ID: #28937

Group Equally

by Ged Ridgway

 

04 Oct 2010

Categorise data into quantiles

| Watch this File

File Information
Description

One can easily split continuous data into two equally sized groups using
  g = x > median(x);
this simple function generalises this idea to more than two roughly equal groups using quantiles/percentiles. It returns a group indicator vector of the same length as the input vector suitable for use with functions like boxplot.

Example:
Given n-by-2 matrix of data X, show distribution of second variable within first variable's quartiles
  g = group_equally(X(:, 1), 4);
  boxplot(X(:, 2), g)

The function is similar to the Stata command "xtile", though might differ due to different definitions of percentiles; this function uses the definition from the reference below.

Reference:
http://www.bmj.com/content/309/6960/996.full

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Doesn't require the Statistics Toolbox, but is probably most useful in conjunction with it.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
categorize Ged Ridgway 04 Oct 2010 12:23:49
categorise Ged Ridgway 04 Oct 2010 12:23:49
split Ged Ridgway 04 Oct 2010 12:23:49
group Ged Ridgway 04 Oct 2010 12:23:49
quantiles Ged Ridgway 04 Oct 2010 12:23:49
quartiles Ged Ridgway 04 Oct 2010 12:23:49
quintiles Ged Ridgway 04 Oct 2010 12:23:49
deciles Ged Ridgway 04 Oct 2010 12:23:49
centiles Ged Ridgway 04 Oct 2010 12:23:49

Contact us at files@mathworks.com