random
Generate new random response values given predictor values
Syntax
Description
Examples
Randomly Generate New Response Values
Load the sample data.
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);
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 through as responses. The table within
includes the within-subject variables and . This is simulated data.
Fit a repeated measures model, where the repeated measures through 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=1×4 table
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 = 1×8
46.2252 66.8003 -40.4987 -1.9930 27.5213 -37.9809 4.8905 -3.7568
Input Arguments
rm
— Repeated measures model
RepeatedMeasuresModel
object
Repeated measures model, returned as a RepeatedMeasuresModel
object.
For properties and methods of this object, see RepeatedMeasuresModel
.
tnew
— New data
table 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
Algorithms
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
.
Version History
Introduced in R2014a
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)