Using nlmefit vs anovan for ANOVA with repeated measures

1 view (last 30 days)
I've been looking into differences between the models fit by nlmefit and anovan for an ANOVA with repeated measures. I'm using the following code to generate some fake data from four "subjects" (random factor) and two conditions (fixed factor), and modeling these data using either nlmefit (assuming a linear model) or anovan:
n = 5; % Number of observations per subject per level.
X = [ones(n*8,1) [ones(n*4,1); -1*ones(n*4,1)]];
subject = repmat([ones(n,1); 2*ones(n,1); 3*ones(n,1); 4*ones(n,1)],[2 1]);
data = subject+2*X(:,2)+randn(n*8,1);
% NLMEFIT Model
fun = @(B,X) (X*B');
[betas,psi,stats1,B] = nlmefit(X,data,subject,...
[],fun,zeros(1,size(X,2)),'REParamsSelect',1);
% ANOVAN Model
A = [1 0; 0 1]; % Two-way ANOVA, no interaction
[~,~,stats2] = anovan(data,{X(:,2)+1,subject},'model',A,'random',2);
Looking at stats1 and stats2 fields, it is clear that these functions fit different models -- for instance, the NLMEFIT model as DOF=36, from fitting the two regressors in X as well as variance parameters, while the ANOVAN model has DOF=35, from fitting categorical regressors for both the fixed and random effects.
For the question I'm asking, all I care about is the effect of condition (fixed effect) and not the effect of subject, but want to account for the fact that the data are structured and different subjects may have different mean responses. I'm wondering: for this purpose, are either of these models conceptually valid? Is one preferable to the other for any reason?
  1 Comment
Sanjay
Sanjay on 1 Jul 2014
Hi Ben, have you found an answer to this? I have the same problem! Don't know why the anovan and nlmefit models give different results.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!