JoramSoch / MACS

MACS – a new SPM toolbox for model assessment, comparison and selection
GNU General Public License v3.0
23 stars 6 forks source link

Error using vertcat and error using reshape #16

Open FioritoAnna opened 5 months ago

FioritoAnna commented 5 months ago

Hi,

Thank you for developing such a great toolbox! I have two questions:

1) I'm currently analyzing fMRI data from a task consisting of four runs. I'm interested in comparing models that combine two options for movement correction (24 motion parameters / ICA-AROMA) and two options for physiological noise correction (first 5 CompCor for CSF and first 5 CompCor for WM / CompCor explaining 50% of variance in CSF and WM). This leads to four models:

1- ICA-AROMA_CompCor50% 2- ICA-AROMA_CompCor5 3- 24reg_CompCor50% 4- 24reg_CompCor5

However, models using CompCor50% have a different number of regressors across the four runs since a different number of CompCor can explain 50% of the variance in each run. This discrepancy seems to be causing the following error message:

Error using vertcat
Dimensions of arrays being concatenated are not consistent.
In file "/crnldata/psyr2/Anna/SchizEmo_Project/fMRI_analysis/Schizemo_BIDSpm/code/lib/spm12/toolbox/MACS/MA_cvLME_multi.m" (???), function "MA_cvLME_multi" at line 239.
In file "/crnldata/psyr2/Anna/SchizEmo_Project/fMRI_analysis/Schizemo_BIDSpm/code/lib/spm12/toolbox/MACS/batch_MA_cvLME_auto.m" (???), function "run_module" at line 75.

Do you have any suggestions for dealing with this problem?

2) I attempted to compare model 2 and 4 to avoid using a model with a different number of regressors across the four runs. I tested this approach with two subjects, and it seems to work better. I can obtain MA_cvLME.nii and MA_cvLME_S1-4.nii in each subject directory. I followed instructions from Manual ("11- How to perform cross-validated Bayesian model selection"). However, I encounter another error message during MS: perform BMC (automatic):

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
In file "/crnldata/psyr2/Anna/SchizEmo_Project/fMRI_analysis/Schizemo_BIDSpm/code/lib/spm12/toolbox/MACS/MS_BMS_group.m" (???), function "MS_BMS_group" at line 153.
In file "/crnldata/psyr2/Anna/SchizEmo_Project/fMRI_analysis/Schizemo_BIDSpm/code/lib/spm12/toolbox/MACS/batch_MS_BMS_group_auto.m" (???), function "run_module" at line 105.
The following modules did not run:
Failed: MS: perform BMS (automatic)`

I would greatly appreciate any feedback or suggestions you may have!

Best regards, Anna

JoramSoch commented 5 months ago

Dear @FioritoAnna,

first of all: Yes, the model needs to have the same number of regressors across all runs for the voxel-wise cvLME to be computable (see this page from the manual for more information and these lousy hand-written notes for technical details).

A possible solution (as also explained in the excerpt from the manual) is to add zero regressors, i.e. include regressors fully consisting of zeros in those sessions where you would otherwise have "missing" regressors. Please note that the regressors need to be in the same order in all sessions, such that they are not mismatched when the session-wise design matrices are vertically concatenated.

Another solution would be that you do not include those components that explain 50% of the variance in each session, but those components that explain 50% of the variance across all sessions (not sure whether that's technically feasible) or always include the same number of components, e.g. the first 3 or the first 10 (that seems to be the point of your models 2 and 4).

(Side note: I'm not entirely sure how much sense it makes to apply the cross-validated log model evidence to such confound/noise regression techniques. Let's say you always take the first 5 principal components of that CompCor approach. Those components can be quite different between sessions and their influence on the measured signal (i.e. their beta weights) not necessarily similar across sessions. However, the assumption behind cross-validated estimation of GLM is that regressors from different sessions have similar effects on the measured signal across sessions, such that posterior distributions from the training data (say, S-1 sessions) can be used as prior information for the test data (the remaining session). Whether this works for CompCor regressors or PC-style confound regressors in general, I have no idea and is probably an open empirical question.)

Regarding your Problem 2: It seems as if your subjects have image resolutions. Did you normalize all subjects into the same group-level space? If subjects have different image resolutions, their cvLME images cannot be stacked together. The number of voxels is taken from the first model of the first subject

H = spm_vol(job.models{1}{1}{1});           % LME image header
V = prod(H.dim);                            % number of voxels

and then applied for loading all models from all subjects:

LME = zeros(N,M,V);             % N x M x V array of LMEs
for i = 1:N                     % subjects
    for j = 1:M                 % models
        lme_hdr = spm_vol(job.models{i}{j}{S});
        lme_img = spm_read_vols(lme_hdr);
        lme_img = reshape(lme_img,[1 1 V]);
        LME(i,j,:) = lme_img;
    end;
end;

Could this be the source of the second error?

Cheers Joram

FioritoAnna commented 4 months ago

Dear Joram,

Thank you very much for your detailed and clear reply; it was really insightful! Regarding problem 2, I have normalized all subjects using the same template and forced a resolution of 2. I have performed second-level analyses and am quite confident that the space is consistent across all subjects.

I will consider more carefully the implications of using this cross-validated log model to compare CompCor strategies.

All the best, Anna

JoramSoch commented 4 months ago

Dear Anna,

great!

Regarding problem 2, I have normalized all subjects using the same template and forced a resolution of 2. I have performed second-level analyses and am quite confident that the space is consistent across all subjects.

Do I understand this correctly that the second-level BMS is now running (or does it mean that you had already normalized into the same space before the error occured)?

Cheers Joram

FioritoAnna commented 4 months ago

Dear Joram,

I apologize for any confusion. I've already normalized into the same space before the error occurred, so I don't believe the error in my case arises from differences in subject space. If my subject dimensions had varied, I would have received an error message during the second-level analyses (which I did not).

Best regards, Anna

JoramSoch commented 4 months ago

OK, good. Then I would suggest to proceed as follows: In the MATLAB editor, select Run >> Pause on Errors. This will stop your script and jump into the lower-most function where the error occured. The error occurs here, so when the execution stops, jump into the function MS_BMS_group and output job.models{i}{j}{1}. This is the LME image that is making problems here. You can then have a look at this image file to see whether something is wrong. Please also compare it with job.models{1}{1}{1} to see if there is any mismatch in dimensions. If you can't find anything wrong, try running the analysis without subject i to see whether this resolves the problem.