repeated anova for two groups with time course data

3 views (last 30 days)
I would like to compare two groups that we subjected to repeated measure across different days.
From what I understand I cannot use ANOVA as the measures are not independent since time is a key factor.
Now I tried to prepare the data for a repeated anova anyalysis to essentially compare the timecourse of the two groups.
However,I'm not sure how to prepare the data for ranova.
Here some example data structure
matrix1 group1: colums = timepoints (1to10) , rows= subjects (N=7)
matrix2 group2 colums = timepoints (1to10), rows= subjects (N=5)
For some subjects a measurement on a given day is missing, is it fine to incle NaNs in the data?
Could anybody give an example of how to prepare the data for such a simple 2 condition comparison?
Unfortunately I could not find an example.

Answers (1)

Aditya
Aditya on 4 Feb 2025
Hi Spikes,
To compare two groups subjected to repeated measures across different days using repeated measures ANOVA in MATLAB, you can use the fitrm and ranova functions. These functions allow you to handle within-subject factors (e.g., time) and between-subject factors (e.g., group).
% Example data for group 1 (7 subjects, 10 time points)
group1 = rand(7, 10); % Replace with your actual data
group1(2, 3) = NaN; % Example of a missing measurement
% Example data for group 2 (5 subjects, 10 time points)
group2 = rand(5, 10); % Replace with your actual data
group2(4, 5) = NaN; % Example of a missing measurement
% Create a table in long format
subject = [repmat((1:7)', 10, 1); repmat((8:12)', 10, 1)];
group = [repmat({'Group1'}, 70, 1); repmat({'Group2'}, 50, 1)];
time = repmat((1:10)', 12, 1);
data = [group1(:); group2(:)];
% Create the table
tbl = table(subject, group, time, data, ...
'VariableNames', {'Subject', 'Group', 'Time', 'Measurement'});
% Fit the repeated measures model
rm = fitrm(tbl, 'Measurement~Group*Time', 'WithinDesign', table((1:10)', 'VariableNames', {'Time'}));
% Perform repeated measures ANOVA
ranovatbl = ranova(rm, 'WithinModel', 'Time');
% Display the results
disp(ranovatbl);

Community Treasure Hunt

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

Start Hunting!