grpstats

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 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`.```

Examples

collapse all

`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 ```

`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

collapse all

Repeated measures model, returned as a `RepeatedMeasuresModel` object.

For properties and methods of this object, see `RepeatedMeasuresModel`.

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`

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.

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 string array or cell array of character vectors and function handles.

Example: `@median`

Example: `@skewness`

Example: `'gname'`

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

Output Arguments

collapse all

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 contain `NaN`s.

Version History

Introduced in R2014a