| Statistics Toolbox™ | ![]() |
means = grpstats(X)
means = grpstats(X,group)
grpstats(x,group,alpha)
[A,B,...] = grpstats(x,group,whichstats)
[...] = grpstats(X,group,whichstats,alpha)
means = grpstats(X) computes the mean of the entire sample without grouping, where X is a matrix of observations.
means = grpstats(X,group) returns the means of each column of X by group. The array, group defines the grouping such that two elements of X are in the same group if their corresponding group values are the same. (See Grouped Data.) The grouping variable group can be a categorical variable, vector, string array, or cell array of strings. It can also be a cell array containing several grouping variables (such as {g1 g2 g3}) to group the values in X by each unique combination of grouping variable values.
grpstats(x,group,alpha) displays a plot of the means versus index with 100(1-alpha)% confidence intervals around each mean.
[A,B,...] = grpstats(x,group,whichstats) returns the statistics specified in whichstats. The input whichstats can be a single function handle or name, or a cell array containing multiple function handles or names. The number of outputs (A,B, ...) must match the number function handles and names in whichstats. The names can be chosen from among the following:
'mean' — mean
'sem' — standard error of the mean
'numel' — count, or number of non-NaN elements
'gname' — group name
'std' — standard deviation
'var' — variance
'meanci' — 95% confidence interval for the mean
'predci' — 95% prediction interval for a new observation
Each function included in whichstats must accept a column vector of data and compute a descriptive statistic for it. For example, @median and @skewness are suitable functions. The function typically returns a scalar value, but may return an nvals-by-1 column vector if the descriptive statistic is not a scalar (a confidence interval, for example). The size of each output A, B, ... is ngroups-by-ncols-by-nvals, where ngroups is the number of groups, ncols is the number of columns in the data X, and nvals is the number of values returned by the function for data from a single group in one column of X. If X is a vector of data, then the size of each output A, B, .... is ngroups-by-nvals.
A function included in whichstats may also be written to accept a matrix of data and compute a descriptive statistic for each column. The function should return either a row vector, or an nvals-by-ncols matrix if the descriptive statistic is not a scalar.
[...] = grpstats(X,group,whichstats,alpha) specifies the confidence level as 100(1-alpha)% for the 'meanci' and 'predci' options. It does not display a plot.
load carsmall
[m,p,g] = grpstats(Weight,Model_Year,...
{'mean','predci','gname'})
n = length(m)
errorbar((1:n)',m,p(:,2)-m)
set(gca,'xtick',1:n,'xticklabel',g)
title('95% prediction intervals for mean weight by year')gscatter, grp2idx, grpstats (dataset)
![]() | grp2idx | grpstats | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |