Two way Repeated Measures ANOVA two different ways

91 views (last 30 days)
Mark Robinson on 22 Nov 2018
Answered: Scott MacKenzie on 25 Feb 2022
I'm working on a dataset for a stats course and I am curious to know about ways of conducting a two way repeated measures ANOVA
A researcher wants to compare the body temperatures of participants when performing exercise under conditions of euhydration and dehydration. The researcher records their body temperatures at the start (0 minutes), midpoint (30 minutes) and end of exercise (60 minutes). The dataset is below.
% This code produces the appropraite ANOVA output
% first enter the temperature data
temp = [37.1 37.2 37.3 37.5 37 37.4 38.2 38.4 38.3 38.1 38 37.9...
39.2 39 38.7 38.9 38.6 38.7 37.3 37.1 37.2 37.5 37.2 37.7...
38.5 38.7 38.4 38.3 38.3 38.2 39.6 39.5 39.3 39.4 38.5 39.2]';
% time condition 1=time0, 2=time30, 3 = time60
time = cat(1, ones(6,1), ones(6,1)*2, ones(6,1)*3, ones(6,1), ones(6,1)*2, ones(6,1)*3);
% hydration condition 1=euhydration, 2=dehydration
hydrat = cat(1, ones(18,1), ones(18,1)*2); % hydration
% subjects
subj = [1 2 3 4 5 6]';
subj = cat(1,subj,subj,subj,subj,subj,subj);
% ANOVA using anovan
[p,tbl,stats,terms] = anovan(temp,{time,hydrat,subj},'model',2,'random',3,'varnames',{'Time','Hydration','Subj'});
I was also interested to know if I could use the "fitrm" and "ranova" functions but this does not produce the same output, but I'm struggling to understand why
% first enter the temperature data
euh_0 = [37.1 37.2 37.3 37.5 37 37.4]';
euh_30 = [38.2 38.4 38.3 38.1 38 37.9]';
euh_60 = [39.2 39 38.7 38.9 38.6 38.7]';
deh_0 = [37.3 37.1 37.2 37.5 37.2 37.7]';
deh_30 = [38.5 38.7 38.4 38.3 38.3 38.2]';
deh_60 = [39.6 39.5 39.3 39.4 38.5 39.2]';
temp = table(euh_0, euh_30, euh_60, deh_0, deh_30, deh_60) % create table
within = table([1 1 1 2 2 2]',[1 2 3 1 2 3]','VariableNames',{'Hyd' 'Time'}) % within model
% fit rm model
temp_rm = fitrm(temp,'euh_0-deh_60~1','WithinDesign',within,'WithinModel','Hyd*Time')
[ranovatbl,A,C,D] = ranova(temp_rm,'WithinModel','Hyd*Time')

Scott MacKenzie on 25 Feb 2022
@Mark Robinson The reason anovan and ranova give different results is that the within table in your solution using ranova is not setup properly. In your code, the data in the columns are of type double. They need to be of type categorical:
within = table([1 1 1 2 2 2]',[1 2 3 1 2 3]','VariableNames',{'Hyd' 'Time'}) % within model
within.Hyd = categorical(within.Hyd);
within.Time = categorical(within.Time);
With the above change, the results are the same using anovan or ranova.

François-Xavier Michon on 25 Oct 2019
Hello ,
first I m not a stastistic expert so I could be wrong
In the first function, you use anovan is a simple multiple way anova (you consider all your data independant, not taking in account it come from same subjects) . It's normal to get a different output than with ranova because ranova is the matlab function to be use on repeated mesure design.
For me your data set is a repeated mesure design because you repeat a mesure on the same subject at different time point. using ranova I found the same result than in a stat software using a repeated measure 2way anova.
but before using anova you need to check the normality and homogeneity of the data set . If it fails you need to use an non parametric test like krustal wallis
late response but still a response :).
Kanupriya Gupta on 25 Feb 2022
Actually, they did take the repeated measures into account when using anovan. They included a 'subj' variable in their script and assigned it as a 'random' variable.

Categories

Find more on Repeated Measures and MANOVA in Help Center and File Exchange

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!