Two-way repeated measures ANOVA

Two-way repeated measures ANOVA, for designs with two within-subjects variables.
15.1K Downloads
Updated 24 Jul 2011

View License

%
% function stats = rm_anova2(Y,S,F1,F2,FACTNAMES)
%
% Two-factor, within-subject repeated measures ANOVA.
% For designs with two within-subject factors.
%
% Parameters:
% Y dependent variable (numeric) in a column vector
% S grouping variable for SUBJECT
% F1 grouping variable for factor #1
% F2 grouping variable for factor #2
% FACTNAMES a cell array w/ two char arrays: {'factor1', 'factor2'}
%
% Y should be a 1-d column vector with all of your data (numeric).
% The grouping variables should also be 1-d numeric, each with same
% length as Y. Each entry in each of the grouping vectors indicates the
% level # (or subject #) of the corresponding entry in Y.
%
% Returns:
% stats is a cell array with the usual ANOVA table:
% Source / ss / df / ms / F / p
%
% Notes:
% Program does not do any input validation, so it is up to you to make
% sure that you have passed in the parameters in the correct form:
%
% Y, S, F1, and F2 must be numeric vectors all of the same length.
%
% There must be at least one value in Y for each possible combination
% of S, F1, and F2 (i.e. there must be at least one measurement per
% subject per condition).
%
% If there is more than one measurement per subject X condition, then
% the program will take the mean of those measurements.
%
% Aaron Schurger (2005.02.04)
% Derived from Keppel & Wickens (2004) "Design and Analysis" ch. 18
%

Cite As

Aaron Schurger (2024). Two-way repeated measures ANOVA (https://www.mathworks.com/matlabcentral/fileexchange/6874-two-way-repeated-measures-anova), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.4.0.0

Fixed one minor error in the labeling of the output, and also modified the comments.

1.3.0.0

Fixed a minor error in the code. Uploaded new version. I had fixed this problem quite a while back, and uploaded the file. It may not have uploaded properly the first time. Thanks to Johan Carlin for bringing the problem to my attention.

1.0.0.0

Reviewer Ted Zanto (zanto@ccs.fau.edu) noticed a minor error on line 133: FACTNAMES{1} should be FACTNAMES{2}. Corrected this error. This error would have been of little or no consequence to users of the program.