how to fix error from 3dMVM and 3dLMEr

AFNI version info (afni -ver): AFNI_20.2.03
I have a very simple experiment that was conducted for two groups: patients vs. control, PRE and POST a particular treatment. I already ran analysis on individual subjects to get individual activation maps; now I am simply trying to capture the Group by Time interaction effect. My patient group has N=39, my control group has n=25. I tried 3dMVM and 3dLMEr, but for both AFNI kept giving me the following error message:

"Error in if (len%%wd != 0) errex.AFNI(paste("The content under -dataTable is not rectangular!","

Below are my code and data table, how can I fix it?
FYI the datatable was in a csv file, with only 4 columns, not sure how can it possibly be "not rectangular"

3dMVM -prefix stat_MVM -jobs 4 -bsVars "GROUP" -wsVars "TIME" -mask TT_mask+tlrc -SS_type 2 -num_glt 14 -gltLabel 1 preVSpost -gltCode 1 'TIME : 1*TIME : 1*POST -1*PRE' -gltLabel 2 MDvsCL -gltCode 2 'condition : 1*GROUP : 1*patients -1*control' -gltLabel 3 Interaction -gltCode 3 'GROUP: 1*patients -1*control TIME : 1*POST -1*PRE' -dataTable datatable.csv

3dLMEr -prefix stat_LME -mask TT_mask+tlrc -model 'groupXtime' -SS_type 3 -gltCode eff_time 'TIME: 1*POST-1*PRE'  -gltCode eff_group 'GROUP: 1*patients -1*control'   -gltCode eff_Interaction 'GROUP : 1*patients -1*control TIME : 1*POST-1*PRE' -dataTable datatable.csv


below is my datatable:
(ignore the SV###, those are original subject numbers that are not exactly in the right order, the final subject number is under "Subj")

Subj	GROUP	TIME	file
s1	         patient	POST	post/SV005/activation+tlrc 
s2	         patient	POST	post/SV011/activation+tlrc
s3	         patient	POST	post/SV013/activation+tlrc
s4	         patient	POST	post/SV021/activation+tlrc
s5	         patient	POST	post/SV022/activation+tlrc
s6	         patient	POST	post/SV029/activation+tlrc
s7	         patient	POST	post/SV031/activation+tlrc
s8	         patient	POST	post/SV032/activation+tlrc
s9	         patient	POST	post/SV038/activation+tlrc
s10	         patient	POST	post/SV039/activation+tlrc
s11	         patient	POST	post/SV041/activation+tlrc
s12	         patient	POST	post/SV042/activation+tlrc
s13	         patient	POST	post/SV045/activation+tlrc
s14	         patient	POST	post/SV046/activation+tlrc
s15	         patient	POST	post/SV047/activation+tlrc
s16	         patient	POST	post/SV049/activation+tlrc
s17	         patient	POST	post/SV054/activation+tlrc
s18	         patient	POST	post/SV065/activation+tlrc
s19	         patient	POST	post/SV069/activation+tlrc
s20	         patient	POST	post/SV071/activation+tlrc
s21	         patient	POST	post/SV074/activation+tlrc
s22	         patient	POST	post/SV076/activation+tlrc
s23	         patient	POST	post/SV081/activation+tlrc
s24	         patient	POST	post/SV083/activation+tlrc
s25	         patient	POST	post/SV085/activation+tlrc
s26	         patient	POST	post/SV087/activation+tlrc
s27	         patient	POST	post/SV096/activation+tlrc
s28	         patient	POST	post/SV098/activation+tlrc
s29	         patient	POST	post/SV099/activation+tlrc
s30	         patient	POST	post/SV107/activation+tlrc
s31	         patient	POST	post/SV112/activation+tlrc
s32	         patient	POST	post/SV113/activation+tlrc
s33	         patient	POST	post/SV114/activation+tlrc
s34	         patient	POST	post/SV115/activation+tlrc
s35	         patient	POST	post/SV119/activation+tlrc
s36	         patient	POST	post/SV121/activation+tlrc
s37	         patient	POST	post/SV136/activation+tlrc
s38	         patient	POST	post/SV137/activation+tlrc
s39	         patient	POST	post/SV140/activation+tlrc
s1	         patient	PRE	pre/SV005/activation+tlrc 
s2	         patient	PRE	pre/SV011/activation+tlrc
s3	         patient	PRE	pre/SV013/activation+tlrc
s4	         patient	PRE	pre/SV021/activation+tlrc
s5	         patient	PRE	pre/SV022/activation+tlrc
s6	         patient	PRE	pre/SV029/activation+tlrc
s7	         patient	PRE	pre/SV031/activation+tlrc
s8	         patient	PRE	pre/SV032/activation+tlrc
s9	         patient	PRE	pre/SV038/activation+tlrc
s10	         patient	PRE	pre/SV039/activation+tlrc
s11	         patient	PRE	pre/SV041/activation+tlrc
s12	         patient	PRE	pre/SV042/activation+tlrc
s13	         patient	PRE	pre/SV045/activation+tlrc
s14	         patient	PRE	pre/SV046/activation+tlrc
s15	         patient	PRE	pre/SV047/activation+tlrc
s16	         patient	PRE	pre/SV049/activation+tlrc
s17	         patient	PRE	pre/SV054/activation+tlrc
s18	         patient	PRE	pre/SV065/activation+tlrc
s19	         patient	PRE	pre/SV069/activation+tlrc
s20	         patient	PRE	pre/SV071/activation+tlrc
s21	         patient	PRE	pre/SV074/activation+tlrc
s22	         patient	PRE	pre/SV076/activation+tlrc
s23	         patient	PRE	pre/SV081/activation+tlrc
s24	         patient	PRE	pre/SV083/activation+tlrc
s25	         patient	PRE	pre/SV085/activation+tlrc
s26	         patient	PRE	pre/SV087/activation+tlrc
s27	         patient	PRE	pre/SV096/activation+tlrc
s28	         patient	PRE	pre/SV098/activation+tlrc
s29	         patient	PRE	pre/SV099/activation+tlrc
s30	         patient	PRE	pre/SV107/activation+tlrc
s31	         patient	PRE	pre/SV112/activation+tlrc
s32	         patient	PRE	pre/SV113/activation+tlrc
s33	         patient	PRE	pre/SV114/activation+tlrc
s34	         patient	PRE	pre/SV115/activation+tlrc
s35	         patient	PRE	pre/SV119/activation+tlrc
s36	         patient	PRE	pre/SV121/activation+tlrc
s37	         patient	PRE	pre/SV136/activation+tlrc
s38	         patient	PRE	pre/SV137/activation+tlrc
s39	         patient	PRE	pre/SV140/activation+tlrc
s40	         control	POST	post/SV002/activation+tlrc
s41	         control	POST	post/SV008/activation+tlrc
s42	         control	POST	post/SV009/activation+tlrc
s43	         control	POST	post/SV014/activation+tlrc
s44	         control	POST	post/SV024/activation+tlrc
s45	         control	POST	post/SV025/activation+tlrc
s46	         control	POST	post/SV027/activation+tlrc
s47	         control	POST	post/SV030/activation+tlrc
s48	         control	POST	post/SV037/activation+tlrc
s49	         control	POST	post/SV043/activation+tlrc
s50	         control	POST	post/SV053/activation+tlrc
s51	         control	POST	post/SV056/activation+tlrc
s52	         control	POST	post/SV057/activation+tlrc
s53	         control	POST	post/SV061/activation+tlrc
s54	         control	POST	post/SV063/activation+tlrc
s55	         control	POST	post/SV068/activation+tlrc
s56	         control	POST	post/SV086/activation+tlrc
s57	         control	POST	post/SV090/activation+tlrc
s58	         control	POST	post/SV094/activation+tlrc
s59	         control	POST	post/SV097/activation+tlrc
s60	         control	POST	post/SV103/activation+tlrc
s61	         control	POST	post/SV111/activation+tlrc
s62	         control	POST	post/SV120/activation+tlrc
s63	         control	POST	post/SV124/activation+tlrc
s64	         control	POST	post/SV127/activation+tlrc
s40	         control	PRE	pre/SV002/activation+tlrc
s41	         control	PRE	pre/SV008/activation+tlrc
s42	         control	PRE	pre/SV009/activation+tlrc
s43	         control	PRE	pre/SV014/activation+tlrc
s44	         control	PRE	pre/SV024/activation+tlrc
s45	         control	PRE	pre/SV025/activation+tlrc
s46	         control	PRE	pre/SV027/activation+tlrc
s47	         control	PRE	pre/SV030/activation+tlrc
s48	         control	PRE	pre/SV037/activation+tlrc
s49	         control	PRE	pre/SV043/activation+tlrc
s50	         control	PRE	pre/SV053/activation+tlrc
s51	         control	PRE	pre/SV056/activation+tlrc
s52	         control	PRE	pre/SV057/activation+tlrc
s53	         control	PRE	pre/SV061/activation+tlrc
s54	         control	PRE	pre/SV063/activation+tlrc
s55	         control	PRE	pre/SV068/activation+tlrc
s56	         control	PRE	pre/SV086/activation+tlrc
s57	         control	PRE	pre/SV090/activation+tlrc
s58	         control	PRE	pre/SV094/activation+tlrc
s59	         control	PRE	pre/SV097/activation+tlrc
s60	         control	PRE	pre/SV103/activation+tlrc
s61	         control	PRE	pre/SV111/activation+tlrc
s62	         control	PRE	pre/SV120/activation+tlrc
s63	         control	PRE	pre/SV124/activation+tlrc
s64	         control	PRE	pre/SV127/activation+tlrc

Howdy-

I will defer to @Gang and @discoraj for suggestions about the dataTable fixing, but I will note that there is new functionality (courtesy of the famous @discoraj) for providing more specific troublepointing about the dataTable. For example, the specific line of badness would be pointed out.

Indeed, your AFNI version is now 5 years old (!). It would probably be helpful to update for a lot of new functionality, fixes, improvements and options.

--pt

Also, since indeed the dataTable does look like it has 4 columns throughout, I wonder if the issue is the name of the 4th column, which from the 3dMVM help description under -dataTable TABLE .. says:

2) The first column is fixed and reserved with label 'Subj', and the
last is reserved for 'InputFile'.
...

So, I wonder if you change the column label "file" to the keyword "InputFile" (with that capitalization), that will work?

NB: I would still very much recommend updating your local AFNI, for the aforementioned reasons.

--pt

Can you try with a tab or space separated file?
csv is problematic

1 Like

Thank you all so much for your prompt guidance! I have updated AFNI to Version AFNI_25.1.11 'Maximinus', and revised the last column to be exactly "InputFile". I even searched and replaced all spaces throughout the file. I saved it as a "tab delineated" txt file. Then I re-ran 3dLMEr, it kept giving me the following error: (but I already changed the last column to be exactly "InputFile", I even restarted my computer, and changed the file name, why is it not seeing it? I tried space delineated txt file too and got the same error message.

** ERROR: The last column must be "InputFile" [without quotes] (or "Ausgang_val" in some cases)!!!

Howdy-

Ah, you know what, there is another syntax issue I think. When you load in the datatable via file (which is the best way to do it), I think you need to put and "@" character before the filename. So, could you please try running the command as:

3dLMEr                                                                       \
    -prefix     stat_LME                                                     \
    -mask       TT_mask+tlrc                                                 \
    -model      'groupXtime'                                                 \
    -SS_type    3                                                            \
    -gltCode    eff_time 'TIME: 1*POST-1*PRE'                                \
    -gltCode    eff_group 'GROUP: 1*patients -1*control'                     \
    -gltCode    eff_Interaction                                              \
                'GROUP : 1*patients -1*control TIME : 1*POST-1*PRE'          \
    -dataTable  @datatable.csv

... and similarly for 3dMVM?

This is a check we should add in our automatic checks for programs like this...

thanks,
pt

Thanks for letting me know! putting the "@" character made a difference for 3dLMEr, now it seems to have read my datafile, but it is complaining about something else (see error message below). I double checked, there are only two factors, GROUP and TIME, with GROUP having "patients vs. control", TIME having "PRE vs. POST". I double checked all spelling, upper/lower case, and any extra space, I cannot see any problem with the syntax of gltCode, cannot figure out what the problem might be?

Also tried adding the "@" character to 3dMVM but it is still giving the error message that " -dataTable is not rectangular!"

++ Good: All InputFiles have exactly 1 volume.
++ Good: All InputFiles are on the same grid.
Error in [.data.frame(dataStr, , vars[ii]) : undefined columns selected
Calls: process.LME.opts ... gl_Constr -> glfConstr -> levels -> [ -> [.data.frame

Execution halted

I also tried not using an external file for datatable but rather just putting all file names in line with the command, 3dLMEr gave me the same error as above. At this point, it seems the problem is with the syntax of gltCode, can you please help me take a look? I cannot figure out what the probelm might be.

The syntax for specifying post hoc contrasts needs several corrections. Specifically:

  • For the 3dMVM script:
  1. First contrast
    The following line:
-gltLabel 1 preVSpost -gltCode 1 'TIME : 1*TIME : 1*POST -1*PRE' \

contains a redundancy in the term TIME : 1*TIME. It should be corrected to:

-gltLabel 1 preVSpost -gltCode 1 'TIME : 1*POST -1*PRE' \
  1. Second contrast
    This line is invalid because condition : 1*GROUP does not make contextual sense and the variable condition is not even part of your model specification:
-gltLabel 2 MDvsCL -gltCode 2 'condition : 1*GROUP : 1*patients -1*control' \

To fix this, you either need to remove or revise it based on the actual variables in your model. And you coded the patient group in the data table as patient, not patients.

  1. Third contrast
    This line:
-gltLabel 3 Interaction -gltCode 3 'GROUP: 1*patients -1*control TIME : 1*POST -1*PRE' \

is almost correct but requires a space after GROUP:

-gltLabel 3 Interaction -gltCode 3 'GROUP : 1*patient -1*control TIME : 1*POST -1*PRE' \

Again, keep consistency by specifying the patient group as patient, not patients.

  • For the 3dLMEr script

The first two lines below:

-gltCode eff_time 'TIME: 1*POST-1*PRE'  \
-gltCode eff_group 'GROUP: 1*patients -1*control'   \
-gltCode eff_Interaction 'GROUP : 1*patients -1*control TIME : 1*POST-1*PRE' \

should have additional spaces around colons and minus signs for clarity and to match proper syntax:

-gltCode eff_time 'TIME : 1*POST -1*PRE'  \
-gltCode eff_group 'GROUP : 1*patient -1*control'   \
-gltCode eff_Interaction 'GROUP : 1*patient -1*control TIME : 1*POST-1*PRE' \

Plus, consistency issue remains: specifying the patient group as patient, not patients.

Gang Chen

Thank you Gang for inspecting my code! After making the suggested corrections, the code seems to be running until it suddenly halted with the error message "Error: vector memory exhausted (limit reached?)", is this related to my hardware? or is there still anything wrong with my code? Below is the updated code:
Thank you so much for your help!!

AFNI version info (afni -ver): AFNI_25.1.11 'Maximinus',

3dLMEr -prefix stat_LME -mask TT_mask+tlrc -model 'groupXtime' -SS_type 3 -gltCode eff_time 'TIME : 1*POST -1*PRE'  -gltCode eff_group 'GROUP : 1*patient -1*control'   -gltCode eff_Interaction 'GROUP : 1*patient -1*control   TIME : 1*POST -1*PRE' -dataTable @datatableNEW.txt 

AFNI OUTPUT BELOW:
++ Good: All InputFiles have exactly 1 volume.
++ Good: All InputFiles are on the same grid.
+* Warning: Log file: ./stat_LME_log.txt exists! NOT OVERWRITING!!

++++++++++++++++++++++++++++++++++++++++++++++++++++
***** Summary information of data structure *****
128 response values
2 levels for factor TIME : POST PRE
***** End of data structure information *****
++++++++++++++++++++++++++++++++++++++++++++++++++++
Reading input files now...
Reading input files for effect estimates: Done!
Error: vector memory exhausted (limit reached?)
Execution halted


It’s likely that the computer doesn’t have enough memory to complete the analysis. What is the voxel size of the input data? If the files can be downsampled (e.g., to a resolution closer to the original acquisition), that may help reduce memory usage. Alternatively, you might need to run the analysis on a machine with larger memory capacity.

Gang Chen

Thank you Gang for the advice! After downsampling my data, I was able to move further along, however, I encountered the following error message and I am not sure what the problem might be at this point. It complained about R libraries but I have double checked and make sure all the 3 libraries have been installed. Then it pointed out other potential problems with my code, but I was using the corrected one last posted which seems to have been cleared of syntax errors. Any insight will be greatly appreciated!

++ Good: All InputFiles exist.

++ Good: All InputFiles have exactly 1 volume.

++ Good: All InputFiles are on the same grid.

++++++++++++++++++++++++++++++++++++++++++++++++++++

***** Summary information of data structure *****

128 response values

2 levels for factor TIME : POST PRE

***** End of data structure information *****

++++++++++++++++++++++++++++++++++++++++++++++++++++

Reading input files now...

Reading input files for effect estimates: Done!

Range of input data: [0.000, 21.704]

If the program hangs here for more than, for example, half an hour,

kill the process because the model specification or something else

is likely inappropriate.

Loading required package: lme4

Loading required package: Matrix

Package lme4 loaded successfully!

Loading required package: lmerTest

Attaching package: ‘lmerTest’

The following object is masked from ‘package:lme4’:

lmer

The following object is masked from ‘package:stats’:

step

Package lmerTest loaded successfully!

Loading required package: phia

Loading required package: car

Loading required package: carData

Package phia loaded successfully!


Possible reasons:

0) Missing R packages lme4, lmerTest, and phia.

1) Inappropriate model specification with options -model, or -qVars.

2) Incorrect specifications with -gltCode.

3) inconsistencies in the data table.

4) Inconsistent variable names (e.g., typos, case sensitive characters).

** Error:

Quitting due to model test failure...

----------------------------------------
Library loading message from R
library("lmerTest")
Loading required package: lme4
Loading required package: Matrix

Attaching package: ‘lmerTest’

The following object is masked from ‘package:lme4’:

    lmer

The following object is masked from ‘package:stats’:

    step
> library("lme4")
> library("phia")
Loading required package: car
Loading required package: carData

Did you specify the model as follows using 3dLMEr?

-model 'groupXtime' \

If so, it should instead be:

-model 'GROUP*TIME+(1|Subj)'

Let us know if updating the model specification resolves the issue.

Gang Chen

yes it finally worked! thank you so much for your help!!