I agree this looks like a bug where if you specify a variable as random but it doesn't actually appear in any terms, the code gets confused. The work-around in your case is not to specify the 'random' argument when no terms use it. I'll report this as a bug to be fixed.
But I don't understand the statement about how including subject in the model would eat up all the between-subject variability. The example doesn't show any between-subject factors. The following code introduces a between-subject factor and specifies that subject is nested in it. Perhaps you want something like this.
Y = randn(100,1);
subject = repmat([1:10]', 10,1);
traits = randn(100,2);
between = repmat([1 1 1 1 1 2 2 2 2 2]',10,1);
[p,T,stats] = anovan(Y, [subject, traits, between], ...
'varnames', {'Subject','Trait1', 'Trait2' 'Between'} , ...
'random', 1, ...
'continuous', [2 3], ...
'nested', [0 0 0 1;0 0 0 0;0 0 0 0;0 0 0 0], ...
'model', [0 0 0 1;1 0 0 0; 0 1 0 0; 0 0 1 0; 0 1 1 0] ...
);
Best Answer