Documentation |
Summary statistics organized by group
statarray = grpstats(tbl,groupvar) returns a table or dataset array with the means for the data groups specified in tbl determined by the values of the grouping variable or variables specified in groupvar.
If there is a single grouping variable, then there is a row in statarray for each value of the grouping variable. grpstats sorts the groups by order of appearance (if the grouping variable is a character array), in ascending numeric order (if the grouping variable is numeric), or in order of the levels (if the grouping variable is categorical).
If groupvar is a cell array of strings containing multiple grouping variable names, or a vector of column numbers, then there is a row in statarray for each observed unique combination of values of the grouping variables. grpstats sorts the groups by the values of the first grouping variable, then the second grouping variable, and so on.
If any variables in tbl (other than those specified in groupvar) are not numeric or logical arrays, then you must specify the names or column numbers of the numeric and logical variables for which you want to calculate means using the name-value pair argument, DataVars.
statarray = grpstats(tbl,groupvar,whichstats) returns the group values for the summary statistics types specified in whichstats.
statarray = grpstats(tbl,groupvar,whichstats,Name,Value) uses additional options specified by one or more Name,Value pair arguments.
means = grpstats(X,group) returns a column vector or matrix with the means of the groups of the data in the matrix or vector X determined by the values of the grouping variable or variables, group. The rows of means correspond to the grouping variable values.
If there is a single grouping variable, then there is a row in means for each value of the grouping variable. grpstats sorts the groups by order of appearance (if the grouping variable is a character array), in ascending numeric order (if the grouping variable is numeric), or in order of the levels (if the grouping variable is categorical).
If group is a cell array of grouping variables, then there is a row in means for each observed unique combination of values of the grouping variables. grpstats sorts the groups by the values of the first grouping variable, then the second grouping variable, and so on.
If X is a matrix, then means is a matrix with the same number of columns as X. Each column of means has the group means for the corresponding column of X.
[stats1,...,statsN] = grpstats(X,group,whichstats) returns column vectors or arrays with group values for the summary statistic types specified in whichstats.
[stats1,...,statsN] = grpstats(X,group,whichstats,'Alpha',alpha) specifies the significance level for confidence and prediction intervals.
grpstats(X,group,alpha) plots the means of the groups of data in the vector or matrix X determined by the values of the grouping variable, group. The grouping variable values are on the horizontal plot axis. Each group mean has 100×(1 – alpha)% confidence intervals.
If X is a matrix, then grpstats plots the means and confidence intervals for each column of X.
If group is a cell array of grouping variables, then grpstats plots the means and confidence intervals for the groups of data in X determined by the unique combinations of values of the grouping variables. For example, if there are two grouping variables, each with two values, there are four possible combinations of grouping variable values. The plot includes only the combinations of values that exist in the input grouping variables (not all possible combinations).