Load the sample data.
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. Hypothetically, the response can be results of a memory test. The within-subject variable w1
can be the type of exercise the subject does before the test and w2
can be the different points in the day the subject takes the memory test. So, one subject does two different type of exercises A and B before taking the test and takes the test at four different times on different days. For each subject, the measurements are taken under these conditions:
Exercise to perform before the test: A B A B A B A B
Test time: 1 1 2 2 3 3 4 4
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.
Perform repeated measures analysis of variance.
ranovatbl=7×8 table
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB
______ ___ ______ _______ _________ ________ _________ ________
(Intercept):Time 6645.2 7 949.31 2.2689 0.031674 0.071235 0.056257 0.14621
Age:Time 5824.3 7 832.05 1.9887 0.059978 0.10651 0.090128 0.17246
IQ:Time 5188.3 7 741.18 1.7715 0.096749 0.14492 0.12892 0.19683
Group:Time 15800 14 1128.6 2.6975 0.0014425 0.011884 0.0064346 0.089594
Gender:Time 4455.8 7 636.55 1.5214 0.16381 0.20533 0.19258 0.23042
Group:Gender:Time 4247.3 14 303.38 0.72511 0.74677 0.663 0.69184 0.49549
Error(Time) 64433 154 418.39
Specify the model for the within-subject factors. Also display the matrices used in the hypothesis test.
ranovatbl=21×8 table
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB
______ __ ______ ________ _________ _________ _________ _________
(Intercept) 3141.7 1 3141.7 2.5034 0.12787 0.12787 0.12787 0.12787
Age 537.48 1 537.48 0.42828 0.51962 0.51962 0.51962 0.51962
IQ 2975.9 1 2975.9 2.3712 0.13785 0.13785 0.13785 0.13785
Group 20836 2 10418 8.3012 0.0020601 0.0020601 0.0020601 0.0020601
Gender 3036.3 1 3036.3 2.4194 0.13411 0.13411 0.13411 0.13411
Group:Gender 211.8 2 105.9 0.084385 0.91937 0.91937 0.91937 0.91937
Error 27609 22 1255 1 0.5 0.5 0.5 0.5
(Intercept):w1 146.75 1 146.75 0.23326 0.63389 0.63389 0.63389 0.63389
Age:w1 942.02 1 942.02 1.4974 0.23402 0.23402 0.23402 0.23402
IQ:w1 11.563 1 11.563 0.01838 0.89339 0.89339 0.89339 0.89339
Group:w1 4481.9 2 2240.9 3.562 0.045697 0.045697 0.045697 0.045697
Gender:w1 270.65 1 270.65 0.4302 0.51869 0.51869 0.51869 0.51869
Group:Gender:w1 240.37 2 120.19 0.19104 0.82746 0.82746 0.82746 0.82746
Error(w1) 13841 22 629.12 1 0.5 0.5 0.5 0.5
(Intercept):w2 3663.8 3 1221.3 3.8381 0.013513 0.020339 0.01575 0.062894
Age:w2 1199.9 3 399.95 1.2569 0.2964 0.29645 0.29662 0.27432
⋮
A=6×1 cell array
{1x8 double}
{1x8 double}
{1x8 double}
{2x8 double}
{1x8 double}
{2x8 double}
C=1×3 cell array
{8x1 double} {8x1 double} {8x3 double}
Display the contents of A
.
ans = 8×8
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
Display the contents of C
.
ans = 8×5
1 1 1 0 0
1 1 0 1 0
1 1 0 0 1
1 1 -1 -1 -1
1 -1 1 0 0
1 -1 0 1 0
1 -1 0 0 1
1 -1 -1 -1 -1