Load the sample data.

load repeatedmeas

The table `between` includes the between-subject
variables age, IQ, group, gender, and eight repeated measures *y*1
through *y*8 as responses. The table `within` includes
the within-subject variables *w*1 and *w*2.
This is simulated data.

Fit a repeated measures model, where the repeated measures *y*1
through *y*8 are the responses, and age, IQ, group,
gender, and the group-gender interaction are the predictor variables.
Also specify the within-subject design matrix.

R = fitrm(between,'y1-y8 ~ Group*Gender + Age + IQ','WithinDesign',within);

Perform a multiple comparison of the estimated marginal
means based on the variable `Group`.

T = multcompare(R,'Group')

T =
Group_1 Group_2 Difference StdErr pValue Lower Upper
_______ _______ __________ ______ _________ _______ _______
A B 4.9875 5.6271 0.65436 -9.1482 19.123
A C 23.094 5.9261 0.0021493 8.2074 37.981
B A -4.9875 5.6271 0.65436 -19.123 9.1482
B C 18.107 5.8223 0.013588 3.4805 32.732
C A -23.094 5.9261 0.0021493 -37.981 -8.2074
C B -18.107 5.8223 0.013588 -32.732 -3.4805

The small *p*-value of 0.0021493 indicates
that there is significant difference between the marginal means of
groups A and C. The *p*-values of 0.65436 indicates
that the difference between the marginal means for groups A and B
is not significantly different from 0.

`multcompare` uses the Tukey-Kramer test
statistic by default. Change the comparison type to the Scheffe procedure.

T = multcompare(R,'Group','ComparisonType','Scheffe')

T =
Group_1 Group_2 Difference StdErr pValue Lower Upper
_______ _______ __________ ______ _________ _______ _______
A B 4.9875 5.6271 0.67981 -9.7795 19.755
A C 23.094 5.9261 0.0031072 7.5426 38.646
B A -4.9875 5.6271 0.67981 -19.755 9.7795
B C 18.107 5.8223 0.018169 2.8273 33.386
C A -23.094 5.9261 0.0031072 -38.646 -7.5426
C B -18.107 5.8223 0.018169 -33.386 -2.8273

The Scheffe test produces larger *p*-values,
but similar conclusions.

Perform multiple comparisons of estimated marginal means
based on the variable `Group` for each gender separately.

T = multcompare(R,'Group','By','Gender')

T =
Gender Group_1 Group_2 Difference StdErr pValue Lower Upper
______ _______ _______ __________ ______ ________ _________ __________
Female A B 4.1883 8.0177 0.86128 -15.953 24.329
Female A C 24.565 8.2083 0.017697 3.9449 45.184
Female B A -4.1883 8.0177 0.86128 -24.329 15.953
Female B C 20.376 8.1101 0.049957 0.0033459 40.749
Female C A -24.565 8.2083 0.017697 -45.184 -3.9449
Female C B -20.376 8.1101 0.049957 -40.749 -0.0033459
Male A B 5.7868 7.9498 0.74977 -14.183 25.757
Male A C 21.624 8.1829 0.038022 1.0676 42.179
Male B A -5.7868 7.9498 0.74977 -25.757 14.183
Male B C 15.837 8.0511 0.14414 -4.3881 36.062
Male C A -21.624 8.1829 0.038022 -42.179 -1.0676
Male C B -15.837 8.0511 0.14414 -36.062 4.3881

The results indicate that the difference between marginal means
for groups A and B is not significant from 0 for either gender (corresponding *p*-values
are 0.86128 for females and 0.74977 for males). The difference between
marginal means for groups A and C is significant for both genders
(corresponding *p*-values are 0.017697 for females
and 0.038022 for males). While the difference between marginal means
for groups B and C is significantly different from 0 for females (*p*-value
is 0.049957), it is not significantly different from 0 for males (*p*-value
is 0.14414).