3dLMEr model for longitudinal data

Hi,

I'm running 3dLMEr on dataset of 115 patients with 4 scan timepoints (not all patients have all scans - some have 1, 2, 3, or 4) and wanted to make sure my script looks good. There are no errors and 3dLMEr runs smoothly. Here's my code below

3dLMEr -prefix /path/results_3dLMEr_ECN.nii -jobs 8 \
-mask /path/ECN_mask.nii \
-model 'session+age+sex+FD+(session|Subj)' \
-resid /path/residuals_3dLMEr_ECN.nii \
-qVars 'session,age,sex,FD' \
-dataTable \
Subj session age sex FD InputFile \
sub-patient01	1	1	25	0.1907	/path/connmap_sub-patient01_ses-01_ECN.nii \
sub-patient01	2	1	25	0.25926	/path/connmap_sub-patient01_ses-02_ECN.nii \
sub-patient01	3	1	25	0.23718	/path/connmap_sub-patient01_ses-03_ECN.nii \
sub-patient02	2	0	30	0.19278	/path/connmap_sub-patient02_ses-02_ECN.nii \
sub-patient03	1	0	28	0.13903	/path/connmap_sub-patient03_ses-01_ECN.nii \

I'm trying to account for varying slope effects and random intercept, hence (session|Subj). I'm also accounting for age, sex, and frame wise displacement (FD), and not interested in any interactions or main effects, just if there are longitudinal changes. For that case in the bucket file, I would only look at the session effect, correct?

Are my qvars correct even though session and sex are theoretically categorical? In this case, I dummy coded them because I had session as ses-01 through ses-04 and it crashed because there was some issue with the model according to the output.

Thanks

1 Like

Since both sex and session are categorical variables, it would be more appropriate not to treat them as quantitative variables and instead allow the program to handle them internally as factors. In addition, a reasonable model specification would be:

-model 'session+age+sex+FD+(FD|Subj)' \

Gang Chen

1 Like

So, removing session and sex from qvars:

-qVars 'age,FD'

or renaming the variables as such:

Subj session age sex FD InputFile \
sub-patient01	ses-01	male	25	0.1907	/path/connmap_sub-patient01_ses-01_ECN.nii \
sub-patient01	ses-02	male	25	0.25926	/path/connmap_sub-patient01_ses-02_ECN.nii \
sub-patient01	ses-03	male	25	0.23718	/path/connmap_sub-patient01_ses-03_ECN.nii \
sub-patient02	ses-02	female	30	0.19278	/path/connmap_sub-patient02_ses-02_ECN.nii \
sub-patient03	ses-01	female	28	0.13903	/path/connmap_sub-patient03_ses-01_ECN.nii \

or both.

Thanks

1 Like

Changing the specification of the -qVars option is technically sufficient for 3dLMEr to run. Nevertheless, coding factors using their meaningful (or interpretable) levels, rather than dummy coding, is more informative and easier to recognize.

Note that in the data table header, sex and age should be listed as:

Subj session sex age FD InputFile \

Gang Chen

1 Like

I saw that. Thanks for catching that. I have another question.

I saved the residuals and used those for 3dFWHMx (then use the output for 3dClustSim), but then read in other parts that I should use the clean resting state data (aka the residuals from the GLM for when accounting for motion, WM, CSF, etc.). I'm using the CONN toolbox for preprocessing and noticed there is an option to output confound effects beta-maps (which represents the variance accounted by noise), so maybe I should use this?

The residuals from 3dLMEr may be already too blurred after several interpolations, but that's my thinking.

Thanks

1 Like

Conventional massive univariate analysis implicitly assumes that neighboring voxels are statistically independent. This unrealistic assumption incurs a substantial cost: statistical evidence must then be heavily penalized to account for multiple testing. As a result, most multiple-comparison adjustment procedures are excessive from the outset. Moreover, additional complications, such as estimating spatial relatedness, as you have noted, further entangle and destabilize the penalization process.

For these reasons, it is less productive to fixate on the precision or exactness of the estimated surviving cluster sizes. Instead, greater emphasis should be placed on the continuity of statistical evidence and on result-reporting practices that “highlight, but don’t hide” the data. This perspective is discussed in detail in this paper and further elaborated in this blog post.

When evidence continuity is foregrounded, the exact surviving cluster size becomes less critical. In practice, this means that you may reasonably adopt whichever approach to estimating spatial relatedness you consider most appropriate for your cluster determination, without overemphasizing the nominal precision of that step.

Gang Chen

1 Like

Thank you for the insight.

1 Like
[picchionid@cn0013 ~]$ R --version
R version 4.5.0 (2025-04-11) -- "How About a Twenty-Six"
[picchionid@cn0013 ~]$ afni --version
Precompiled binary linux_rocky_8: Jan 30 2026 (Version AFNI_26.0.08 'Pupienus Maximus')

Gang,

Hi. How are you?

Why did you change the other random effect in the model from session to framewise displacement?

"Nevertheless, coding factors using their meaningful (or interpretable) levels, rather than dummy coding, is more informative and easier to recognize." Are you saying sex does not need to be dummy coded because it is a dichotomous variable, and are you saying session does not need to be dummy coded because it is an ordinal variable?

Sincerely,

Dante

Dante,

Why did you change the other random effect in the model from session to framewise displacement?

You can find a detailed discussion on proper model specification here.

In general, it is more error-proof to let the program handle dummy-coding for categorical variables internally rather than coding them manually.

Gang Chen