grpstats
Compute descriptive statistics of repeated measures data by group
Description
Examples
Compute Group Statistics
Load the sample data.
load fisheriris
The column vector, species
consists of iris flowers of three different species: setosa, versicolor, and virginica. The double matrix meas
consists of four types of measurements on the flowers: the length and width of sepals and petals in centimeters, respectively.
Store the data in a table array.
t = table(species,meas(:,1),meas(:,2),meas(:,3),meas(:,4),... 'VariableNames',{'species','meas1','meas2','meas3','meas4'}); Meas = dataset([1 2 3 4]','VarNames',{'Measurements'});
Fit a repeated measures model, where the measurements are the responses and the species is the predictor variable.
rm = fitrm(t,'meas1-meas4~species','WithinDesign',Meas);
Compute group counts, mean, and standard deviation with respect to species.
grpstats(rm,'species')
ans=3×4 table
species GroupCount mean std
______________ __________ ______ ______
{'setosa' } 200 2.5355 1.8483
{'versicolor'} 200 3.573 1.7624
{'virginica' } 200 4.285 1.9154
Now, compute the range of data and 95% confidence intervals for the group means for the factor species. Also display the group name.
grpstats(rm,'species',{'gname','range','predci'})
ans=3×5 table
species gname GroupCount range predci
______________ ______________ __________ _____ ____________________
{'setosa' } {'setosa' } 200 5.7 -1.1185 6.1895
{'versicolor'} {'versicolor'} 200 6 0.088976 7.057
{'virginica' } {'virginica' } 200 6.5 0.4985 8.0715
Statistics for Data Grouped by Two Factors
Load the sample data.
load repeatedmeas
The table between
includes the between-subject variables age, IQ, group, gender, and eight repeated measures y1
through y8
as responses. The table within
includes the within-subject variables w1
and w2
. This is simulated data.
Fit a repeated measures model, where the repeated measures y1
through y8
are the responses, and age, IQ, group, gender, and the group-gender interaction are the predictor variables. Also specify the within-subject design matrix.
rm = fitrm(between,'y1-y8 ~ Group*Gender + Age + IQ','WithinDesign',within);
Compute group counts, mean, standard deviation, skewness, and kurtosis of data grouped by the factors Group
and Gender
.
GS = grpstats(rm,{'Group','Gender'},{'mean','std',@skewness,@kurtosis})
GS=6×7 table
Group Gender GroupCount mean std skewness kurtosis
_____ ______ __________ _______ ______ ________ ________
A Female 40 16.554 21.498 0.35324 3.7807
A Male 40 9.8335 20.602 -0.38722 2.7834
B Female 40 11.261 25.779 -0.49177 4.1484
B Male 40 3.6078 24.646 0.55447 2.7966
C Female 40 -11.335 27.186 1.7499 6.1429
C Male 40 -14.028 31.984 1.7362 5.141
Input Arguments
rm
— Repeated measures model
RepeatedMeasuresModel
object
Repeated measures model, returned as a RepeatedMeasuresModel
object.
For properties and methods of this object, see RepeatedMeasuresModel
.
g
— Name of grouping factor or factors
character vector | string array | cell array of character vectors
Name of grouping factor or factors, specified as a character vector, string array, or cell array of character vectors.
Example: 'Drug'
Example: {'Drug','Sex'}
Data Types: char
| string
| cell
stats
— Statistics to compute
character vector | string scalar | function handle | string array | cell array of multiple character vectors and function handles
Statistics to compute, specified as one of the following:
Character vector or string scalar specifying the name of the statistics to compute. Names can be one of the following.
Name Description 'mean'
Mean 'sem'
Standard error of the mean 'numel'
Count or number of elements 'gname'
Group name 'std'
Standard deviation 'var'
Variance 'min'
Minimum 'max'
Maximum 'range'
Maximum minus minimum 'meanci'
95% confidence interval for the mean 'predci'
95% prediction interval for a new observation Function handle — The function you specify must accept a vector of response values for a single group, and compute descriptive statistics for it. A function should typically return a value that has one row. A function must return the same size output each time
grpstats
calls it, even if the input for some groups is empty.A string array or cell array of character vectors and function handles.
Example: @median
Example: @skewness
Example: 'gname'
Example: {'gname','range','predci'}
Output Arguments
statstbl
— Statistics values for each group
table
Statistics values for each group, returned as a table.
Tips
grpstats
computes results separately for each group. The results do not depend on the fitted repeated measures model. It computes the results on all available data, without omitting entire rows that containNaN
s.
Version History
Introduced in R2014a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)