Main Content

RepeatedMeasuresModel

Repeated measures model object

Description

A RepeatedMeasuresModel object represents a model fitted to data with multiple measurements per subject. The object comprises data, fitted coefficients, covariance parameters, design matrix, error degrees of freedom, and between- and within-subjects factor names for a repeated measures model. You can perform an ANOVA on the data using the anova function for between-subject factors or the ranova function for within-subject factors.

Creation

Fit a repeated measures model and create a RepeatedMeasuresModel object using fitrm.

Properties

expand all

Design for between-subject factors and values of repeated measures, stored as a table.

Data Types: table

Model for between-subjects factors, stored as a character vector. This character vector is the text representation to the right of the tilde in the model specification you provide when fitting the repeated measures model using fitrm.

Data Types: char

Names of variables used as between-subject factors in the repeated measures model, rm, stored as a cell array of character vectors.

Data Types: cell

Names of variables used as response variables in the repeated measures model, rm, stored as a cell array of character vectors.

Data Types: cell

Values of the within-subject factors, stored as a table.

Data Types: table

Model for within-subjects factors, stored as a character vector.

You can specify WithinModel as a character vector or a string scalar using dot notation: Mdl.WithinModel = newWithinModelValue.

Names of the within-subject factors, stored as a cell array of character vectors.

Data Types: cell

Values of the estimated coefficients for fitting the repeated measures as a function of the terms in the between-subjects model, stored as a table.

fitrm defines the coefficients for a categorical term using 'effects' coding, which means coefficients sum to 0. There is one coefficient for each level except the first. The implied coefficient for the first level is the sum of the other coefficients for the term.

You can display the coefficient values as a matrix rather than a table using coef = r.Coefficients{:,:}.

You can display marginal means for all levels using the margmean method.

Data Types: table

Estimated response covariances, that is, covariance of the repeated measures, stored as a table. fitrm computes the covariances around the mean returned by the fitted repeated measures model rm.

You can display the covariance values as a matrix rather than a table using coef = r.Covariance{:,:}.

Data Types: table

Error degrees of freedom, stored as a scalar value. DFE is the number of observations minus the number of estimated coefficients in the between-subjects model.

Data Types: double

Object Functions

ranovaAnalysis of variance for within-subject effects in a repeated measures model
anovaAnalysis of variance for between-subject effects in a repeated measures model
mauchlyMauchly’s test for sphericity
epsilonEpsilon adjustment for repeated measures anova
multcompareMultiple comparison of estimated marginal means
manovaMultivariate analysis of variance
coeftestLinear hypothesis test on coefficients of repeated measures model
grpstatsCompute descriptive statistics of repeated measures data by group
margmean Estimate marginal means
plotPlot data with optional grouping
plotprofile Plot expected marginal means with optional grouping
predictCompute predicted values given predictor values
random Generate new random response values given predictor values

Examples

collapse all

Load the sample data.

load fisheriris

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.

t = table(species,meas(:,1),meas(:,2),meas(:,3),meas(:,4),...
'VariableNames',{'species','meas1','meas2','meas3','meas4'});
Meas = table([1 2 3 4]','VariableNames',{'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)
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.

rm.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={1,ifsetosa0,ifversicolor-1,ifvirginica

and

species_versicolor={0,ifsetosa1,ifversicolor-1,ifvirginica.

Display the covariance matrix.

rm.Covariance
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.

rm.DFE
ans = 
147

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.

More About

expand all

Version History

Introduced in R2014a

See Also