Main Content

margmean

Estimate marginal means

Description

tbl = margmean(rm,vars) returns the estimated marginal means for the variables vars, in the table tbl.

example

tbl = margmean(rm,vars,'alpha',alpha) returns the 100*(1–alpha)% confidence intervals for the marginal means.

example

Examples

collapse all

Load the sample data.

load repeatedmeas

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 factors Group and Gender.

M = margmean(rm,{'Group' 'Gender'})
M=6×6 table
    Group    Gender     Mean      StdErr     Lower       Upper 
    _____    ______    _______    ______    ________    _______

      A      Female     15.946    5.6153      4.3009     27.592
      A      Male       8.0726    5.7236     -3.7973     19.943
      B      Female     11.758    5.7091    -0.08189     23.598
      B      Male       2.2858    5.6748      -9.483     14.055
      C      Female    -8.6183     5.871     -20.794     3.5574
      C      Male      -13.551    5.7283     -25.431    -1.6712

Display the description for table M.

M.Properties.Description
ans = 
    'Estimated marginal means
     Means computed with Age=13.7, IQ=98.2667'

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.

rm = fitrm(t,'meas1-meas4~species','WithinDesign',Meas);

Compute the marginal means grouped by the factor species.

margmean(rm,'species')
ans=3×5 table
       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=3×5 table
       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

Input Arguments

collapse all

Repeated measures model, returned as a RepeatedMeasuresModel object.

For properties and methods of this object, see RepeatedMeasuresModel.

Variables for which to compute the marginal means, specified as a character vector or string scalar representing the name of a between or within-subjects factor in rm, or a string array or 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 | string | cell

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

Example: 'alpha',0.01

Data Types: double | single

Output Arguments

collapse all

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 nameDescription
MeanEstimated marginal means
StdErrStandard errors of the estimates
LowerLower limit of a 95% confidence interval for the true population mean
UpperUpper limit of a 95% confidence interval for the true population mean

Version History

Introduced in R2014a