vars — Variables for which to compute the marginal means character vector | cell array of character vectors

Variables for which to compute the marginal means, specified
as a character vector representing the name of a between or within-subjects
factor in rm, or a cell array of character vectors
representing the names of multiple variables. Each between-subjects
factor must be categorical.

For example, if you want to compute the marginal means for the
variables Drug and Gender, then you can specify as follows.

Example: {'Drug','Gender'}

Data Types: char | cell

alpha — Confidence level 0.05 (default) | scalar value in the range of 0 to 1

Confidence level of the confidence intervals for population
marginal means, specified as a scalar value in the range of 0 to 1.
The confidence level is 100*(1–alpha)%.

For example, you can specify a 99% confidence level as follows.

Estimated marginal means, returned as a table. tbl contains
one row for each combination of the groups of the variables you specify
in vars, one column for each variable, and the
following columns.

Column name

Description

Mean

Estimated marginal means

StdErr

Standard errors of the estimates

Lower

Lower limit of a 95% confidence interval for the true population
mean

Upper

Upper limit of a 95% confidence interval for the true population
mean

The table between includes the between-subject
variables age, IQ, group, gender, and eight repeated measures y1
to 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
to 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 the marginal means grouped by the between-subjects
factor Group and the within-subject factor Time.

M = margmean(rm,{'Group''Time'})

M =
Group Time Mean StdErr Lower Upper
_____ ____ _______ ______ ________ _______
A 1 20.03 11.966 -4.7859 44.846
A 2 5.8101 8.0942 -10.976 22.597
A 3 20.694 5.1928 9.9247 31.463
A 4 16.802 5.1693 6.0813 27.522
A 5 13.157 6.2678 0.15862 26.156
A 6 0.38527 5.8028 -11.649 12.42
A 7 8.1398 6.4472 -5.2309 21.51
A 8 11.057 7.6083 -4.7213 26.836
B 1 23.768 11.816 -0.73653 48.273
B 2 16.846 7.9927 0.26973 33.422
B 3 -4.0888 5.1276 -14.723 6.5453
B 4 2.0001 5.1045 -8.5858 12.586
B 5 8.6458 6.1892 -4.1898 21.481
B 6 -9.3054 5.73 -21.189 2.578
B 7 8.8204 6.3663 -4.3825 22.023
B 8 9.4889 7.5129 -6.0918 25.07
C 1 19.951 12.236 -5.4261 45.327
C 2 23.63 8.2771 6.4646 40.796
C 3 -22.121 5.3101 -33.133 -11.109
C 4 -14.307 5.2861 -25.27 -3.3443
C 5 -20.138 6.4094 -33.43 -6.8456
C 6 -28.583 5.9339 -40.889 -16.277
C 7 -25.273 6.5928 -38.946 -11.6
C 8 -21.836 7.7801 -37.971 -5.7009

Display the description for table M.

M.Properties.Description

ans =
Estimated marginal means
Means computed with Age=13.7, IQ=98.2667

Compute Estimated Marginal Means and Confidence Intervals

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

Compute the marginal means grouped by the factor species.

margmean(rm,'species')

ans =
species Mean StdErr Lower Upper
____________ ______ ________ ______ ______
'setosa' 2.5355 0.042807 2.4509 2.6201
'versicolor' 3.573 0.042807 3.4884 3.6576
'virginica' 4.285 0.042807 4.2004 4.3696

StdError field shows the standard errors
of the estimated marginal means. The Lower and Upper fields
show the lower and upper bounds for the 95% confidence intervals of
the group marginal means, respectively. None of the confidence intervals
overlap, which indicates that marginal means differ with species.
You can also plot the estimated marginal means using the plotprofile method.

Compute the 99% confidence intervals for the marginal
means.

margmean(rm,'species','alpha',0.01)

ans =
species Mean StdErr Lower Upper
____________ ______ ________ ______ ______
'setosa' 2.5355 0.042807 2.4238 2.6472
'versicolor' 3.573 0.042807 3.4613 3.6847
'virginica' 4.285 0.042807 4.1733 4.3967