Class: RepeatedMeasuresModel

Generate new random response values given predictor values




ysim = random(rm,tnew) generates random response values from the repeated measures model rm using the predictor variables from table tnew.

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.

tnew — New datatable used to create rm (default) | table

New data including the values of the response variables and the between-subject factors used as predictors in the repeated measures model, rm, specified as a table. tnew must contain all of the between-subject factors used to create rm.

Output Arguments

expand all

ysim — Random response valuesn-by-r matrix

Random response values random generates, returned as an n-by-r matrix, where n is the number of rows in tnew, and r is the number of repeated measures in rm.


expand all

Randomly Generate New Response Values

Load the sample data.

load fisheriris

The column vector speciesconsists 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),...
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);

Randomly generate new response values.

ysim = random(rm);

random uses the predictor values in the original sample data you use to fit the repeated measures model rm in table t.

Randomly Generate Response Values Using New Data

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);

Define a table with new values for the predictor variables.

tnew = table(16,93,{'B'},{'Male'},'VariableNames',{'Age','IQ','Group','Gender'})
tnew = 

    Age    IQ    Group    Gender
    ___    __    _____    ______

    16     93    'B'      'Male'

Randomly generate new response values using the values in the new table tnew.

ysim = random(rm,tnew)
ysim =

  159.0920  114.8927   -6.5618   46.9944   38.6707   -5.6725   70.8690   11.7813


random computes ysim by creating predicted values and adding random noise values. For each row, the noise has a multivariate normal distribution with covariance the same as rm.Covariance.

See Also


Was this topic helpful?