0todd0000 / spm1d

One-Dimensional Statistical Parametric Mapping in Python
GNU General Public License v3.0
61 stars 21 forks source link

Unbalanced designs? #189

Closed ElineNijmeijer1 closed 3 years ago

ElineNijmeijer1 commented 3 years ago

Hi Todd,

I'm trying to run a repeated measures ANOVA in python. Therefore I checked the design and it should be balanced (9 participants, 3 conditions each).

However, I still go the error that something went wrong. The first row are the conditions (9x 3 different conditions) The second row consists of the 9 subjects (measured 3 times for each condition once)

And then the shape of the data (Y) is shown, which is (27,60) (60 timepoints).

Do you have any idea what's going wrong?

Regards, Eline


[0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2] [ 2 3 6 7 10 11 12 18 19 2 3 6 7 10 11 12 18 19 2 3 6 7 10 11 12 18 19] 27 27 (27, 60) Traceback (most recent call last):

File "....\SPM test balanced designs.py", line 165, in Frm = spm1d.stats.anova1rm(YLARGE, ALARGE, SUBJ, equal_var)

File "....spm1d\stats\anova\ui.py", line 116, in anova1rm design = designs.ANOVA1rm(A, SUBJ)

File "....spm1d\stats\anova\designs.py", line 154, in init self._check_balanced()

File "....spm1d\stats\anova\designs.py", line 178, in _check_balanced raise( ValueError('Design must be balanced.') )

ValueError: Design must be balanced.

0todd0000 commented 3 years ago

Hi Eline,

The numbers in A and SUBJ are OK, but the order is not. The order should look something like this:

A    = [0, 0, 0, ...   1, 1, 1, .... 2, 2, 2, ...]
SUBJ = [2, 3, 6, ...   2, 3, 6, .... 2, 3, 6, ...]

or something like this:

A    = [0, 1, 2,  0, 1, 2,  0, 1, 2, ...]
SUBJ = [2, 2, 2,  3, 3, 3,  6, 6, 6, ....]

In both cases above, each subject has all three cases.

But in the printed data you pasted above, this is not the case:

A    = [0, 1, 2, 0,  1,  2,  0,  1,  2, 0, 1, 2,...]
SUBJ = [2, 3, 6, 7, 10, 11, 12, 18, 19, 2, 3, 6, ...]

Notice that subject 2, for example, has three values of A=0, and no values of A=1 or A=2. For a balanced design, each subject must have ALL of A=0, A=1 and A=2.

ElineNijmeijer1 commented 3 years ago

Hi Todd,

Thanks a lot! Could have known that ;-) Now it works :-)