Load the sample data.

The column vector, `species`

, consists of iris flowers of three different species: setosa, versicolor, 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.

Fit a repeated measures model, where the measurements are the responses and the species is the predictor variable.

rm =
RepeatedMeasuresModel with properties:
Between Subjects:
BetweenDesign: [150x5 table]
ResponseNames: {'meas1' 'meas2' 'meas3' 'meas4'}
BetweenFactorNames: {'species'}
BetweenModel: '1 + species'
Within Subjects:
WithinDesign: [4x1 table]
WithinFactorNames: {'Measurements'}
WithinModel: 'separatemeans'
Estimates:
Coefficients: [3x4 table]
Covariance: [4x4 table]

Display the coefficients.

ans=*3×4 table*
meas1 meas2 meas3 meas4
________ ________ ______ ________
(Intercept) 5.8433 3.0573 3.758 1.1993
species_setosa -0.83733 0.37067 -2.296 -0.95333
species_versicolor 0.092667 -0.28733 0.502 0.12667

`fitrm`

uses the `'effects'`

contrasts, which means that the coefficients sum to 0. The `rm.DesignMatrix`

has one column of 1s for the intercept, and two other columns `species_setosa`

and `species_versicolor`

, which are as follows:

$$species\_setosa=\{\begin{array}{c}1,\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}setosa\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\\ 0,\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}versicolor\\ -1,\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}virginica\phantom{\rule{1em}{0ex}}\end{array}$$

and

$$species\_versicolor=\{\begin{array}{c}0,\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}setosa\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{1em}{0ex}}\\ 1,\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}versicolor\\ -1,\phantom{\rule{1em}{0ex}}if\phantom{\rule{0.2777777777777778em}{0ex}}virginica\phantom{\rule{1em}{0ex}}\end{array}.$$

Display the covariance matrix.

ans=*4×4 table*
meas1 meas2 meas3 meas4
________ ________ ________ ________
meas1 0.26501 0.092721 0.16751 0.038401
meas2 0.092721 0.11539 0.055244 0.03271
meas3 0.16751 0.055244 0.18519 0.042665
meas4 0.038401 0.03271 0.042665 0.041882

Display the error degrees of freedom.

The error degrees of freedom is the number of observations minus the number of estimated coefficients in the between-subjects model, e.g. 150 – 3 = 147.