Documentation Center

  • Trial Software
  • Product Updates

grpstats

Class: RepeatedMeasuresModel

Compute descriptive statistics of repeated measures data by group

Syntax

  • statstbl = grpstats(rm,g) example
  • statstbl = grpstats(rm,g,stats) example

Description

example

statstbl = grpstats(rm,g) returns the count, mean, and variance for the data used to fit the repeated measures model rm, grouped by the factors, g.

example

statstbl = grpstats(rm,g,stats) returns the statistics specified by stats for the data used to fit the repeated measures model rm, grouped by the factors, g.

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 contain NaNs.

Input Arguments

expand all

rm — Repeated measures modelRepeatedMeasuresModel object

Repeated measures model, returned as a RepeatedMeasuresModel object.

For properties and methods of this object, see RepeatedMeasuresModel.

g — Name of grouping factor or factorsstring | cell array of strings

Name of grouping factor or factors, specified as a string or cell array of strings.

Example: 'Drug'

Example: {'Drug','Sex'}

Data Types: char

stats — Statistics to computestring | function handle | cell array of multiple strings and function handles

Statistics to compute, specified as one of the following:

  • String specifying the name of the statistics to compute. Names can be one of the following.

    NameDescription
    '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 cell array of strings and function handles.

Example: @median

Example: @skewness

Example: 'gname'

Example: {'gname','range','predci'}

Data Types: char | function_handle | cell

Output Arguments

expand all

statstbl — Statistics values for each grouptable

Statistics values for each group, returned as a table.

Examples

expand all

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 = 

      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 = 

      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 = 

    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  

See Also

|

Was this topic helpful?