2-way repeated measures MANOVA

Hi, I have some motion tracking data that is in the format below:
data=(samples,q,v,d,p)
where samples = sample number (1:60000)
q = value of position in each sample (X,Y,Z)
v = 1:2, video condition, 2 levels
d = 1:2, difficulty condition, 2 levels
p = participant number (1:12)
I would like to run a 2-way repeated measures across the 2 crossed conditions and for each participant in each value of position data.
I have done this before in SPSS, but this was only with a small sample and with a mean of the 60000 data points for each position (not ideal!)
The mathworks literature is a little sketchy on MANOVA, so I was wondering if anyone has any idea of how to do this? Worst case scenario I'll have to extract and run in SPSS but that is a last resort option only!

Answers (1)

Hi Arran ,
Running a two-way repeated measures ANOVA on motion tracking data with multiple conditions and participants can be complex, especially with a large dataset. In MATLAB, you can use the fitrm and ranova functions to perform repeated measures ANOVA. Here’s a step-by-step sample code on how to set up and run this analysis:
% Sample data setup (assuming you have the data in separate vectors)
samples = (1:60000)';
q = rand(60000, 3); % Replace with your actual position data (X, Y, Z)
v = randi([1, 2], 60000, 1); % Video condition
d = randi([1, 2], 60000, 1); % Difficulty condition
p = randi([1, 12], 60000, 1); % Participant number
% Create a table
dataTable = table(samples, q(:,1), q(:,2), q(:,3), v, d, p, ...
'VariableNames', {'Sample', 'X', 'Y', 'Z', 'Video', 'Difficulty', 'Participant'});
% Reshape data for repeated measures
% Assuming you want to perform ANOVA on each position component separately
for posComponent = {'X', 'Y', 'Z'}
posComponent = posComponent{1};
% Define the within-subjects design
WithinDesign = table([1 1 2 2]', [1 2 1 2]', ...
'VariableNames', {'Video', 'Difficulty'});
% Fit the repeated measures model
rm = fitrm(dataTable, sprintf('%s ~ Video*Difficulty*Participant', posComponent), ...
'WithinDesign', WithinDesign);
% Perform repeated measures ANOVA
tbl = ranova(rm);
% Display the results
fprintf('Results for position component %s:\n', posComponent);
disp(tbl);
end
This approach should help you perform the analysis in MATLAB without resorting to SPSS. Adjust the data handling and model specifications as needed based on your specific dataset and research questions.

Asked:

on 27 Nov 2014

Answered:

on 31 Jan 2025

Community Treasure Hunt

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

Start Hunting!