| Statistics Toolbox | Search  Help Desk |
| grpstats | Examples See Also |
Syntax
means = grpstats(X,group) [means,sem,counts] = grpstats(X,group)grpstats(x,group)grpstats(x,group,alpha)
Description
means = grpstats(X,group) returns the means of each column of X by group. X is a matrix of observations. group is a column of positive integers that indicates the group membership of each row in X.
[means,sem,counts] = grpstats(x,group,alpha) supplies the standard error of the mean in sem. counts is the same size as the other outputs. The i-th row of counts contains the number of elements in the i-th group.
grpstats(x,group) displays a plot of the means versus index with 95% confidence intervals about the mean value of for each value of index.
grpstats(x,group,alpha) plots 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
See Also
tabulate, crosstab