Statistics Toolbox | ![]() ![]() |
Syntax
Description
returns the means of each column of X by means = grpstats(
X,group)
group
, where X is a matrix of observations. group
is an array that defines the grouping such that two elements of X are in the same group if their corresponding group
values are the same. The grouping variable group
can be a vector, string array, or cell array of strings. It can also be a cell array containing several grouping variables (such as {G1 G2 G3}
); in that case observations are in the same group if they have common values of all grouping variables.
supplies the standard error of the mean in [means,sem,counts,name] = grpstats(x,group,alpha)
sem
, the number of elements in each group in counts
, and the name of each group in name
. name
is useful to identify and label the groups when the input group
values are not simple group numbers.
plots grpstats(x,group,alpha)
100(1-alpha)
% confidence intervals around each mean.
Example
We assign 100 observations to one of four groups. For each observation we measure five quantities with true means from 1 to 5. grpstats
allows us to compute the means for each group.
group = unidrnd(4,100,1); true_mean = 1:5; true_mean = true_mean(ones(100,1),:); x = normrnd(true_mean,1); means = grpstats(x,group) means = 0.7947 2.0908 2.8969 3.6749 4.6555 0.9377 1.7600 3.0285 3.9484 4.8169 1.0549 2.0255 2.8793 4.0799 5.3740 0.7107 1.9264 2.8232 3.8815 4.9689
![]() | gplotmatrix | gscatter | ![]() |