Documentation

grpstats

Class:RepeatedMeasuresModel

Compute descriptive statistics of repeated measures data by group

Syntax

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

Description

example

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

example

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

Input Arguments

expand all

Repeated measures model, returned as aRepeatedMeasuresModelobject.

For properties and methods of this object, seeRepeatedMeasuresModel.

Name of grouping factor or factors, specified as a character vector or cell array of character vectors.

Example:'Drug'

Example:{'Drug','Sex'}

Data Types:char

Statistics to compute, specified as one of the following:

  • Character vector 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 timegrpstatscalls it, even if the input for some groups is empty.

  • A cell array of character vectors and function handles.

Example:@median

Example:@skewness

Example:'gname'

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

Data Types:char|function_handle|cell

Output Arguments

expand all

Statistics values for each group, returned as a table.

Examples

expand all

Load the sample data.

loadfisheriris

The column vector,speciesconsists of iris flowers of three different species: setosa, versicolor, and virginica. The double matrixmeasconsists 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

Load the sample data.

loadrepeatedmeas

The tablebetweenincludes the between-subject variables age, IQ, group, gender, and eight repeated measuresy1throughy8as responses. The tablewithinincludes the within-subject variablesw1andw2. This is simulated data.

Fit a repeated measures model, where the repeated measuresy1throughy8are 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 factorsGroupandGender.

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

Tips

  • grpstatscomputes 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 containNaNs.

See Also

|

Was this topic helpful?