'!invalid contrast' when running contrasts using SPM
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey all,
I am trying to run a contrast using SPM (SPM12) in order to determine whether brain activation differs between two conditions, using the code snippet below:
%% Contrasts
matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'nav-follow';
disp(length(names));
disp(size(confounds_matrix,2));
initial_convec = [0 0 -1 0 0 1 0 0 0 0 0 0 0];
num_confounds = size(confounds_matrix, 2);
additional_convec = zeros(1, num_confounds+1);
convec = [initial_convec, additional_convec];
matlabbatch{3}.spm.stats.con.consess{1}.tcon.convec = convec;
matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'replsc'; % 'none';
matlabbatch{3}.spm.stats.con.delete = 0;
spm_jobman('run', matlabbatch);
However, I keep getting the error message '!invalid contrast'.
Contrasts folder : ./GroupHunt/spm_output/sub-01
0 0 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <- !invalid contrast
01-Jun-2024 14:03:55 - Failed 'Contrast Manager'
Error using spm_run_con (line 254)
Error in contrast specification
In file "/mnt/data/fMRI/GroupHunt/spm12/config/spm_run_con.m" (v7738), function "spm_run_con" at line 254.
The following modules did not run:
Failed: Contrast Manager
However, I can't understand why this contrast is invalid. There are 26 values in the 'convec' vector which specifies the contrast and 26 regressors in my design matrix.
The variable 'convec' looks as follows:
convec =
Columns 1 through 10
0 0 -1 0 0 1 0 0 0 0
Columns 11 through 20
0 0 0 0 0 0 0 0 0 0
Columns 21 through 26
0 0 0 0 0 0
My design matrix has 26 regressors as follows:
load(fullfile(subdir, 'SPM.mat'));
numRegressors = size(SPM.xX.X, 2);
disp(['Number of regressors: ', num2str(numRegressors)]);
Number of regressors: 26
I would be so so grateful for a helping hand! :D
0 comentarios
Respuestas (1)
Aditya
el 27 de Jun. de 2024
The error message !invalid contrast in SPM typically indicates that the contrast vector (convec) does not match the design matrix in some way.
Given the information you provided, here are a few steps to debug and correct the issue:
Step 1: Verify the Design Matrix
Ensure that the design matrix (SPM.xX.X) is correctly specified and contains 26 regressors. You have already done this, but double-check that the regressors are in the expected order.
load(fullfile(subdir, 'SPM.mat'));
numRegressors = size(SPM.xX.X, 2);
disp(['Number of regressors: ', num2str(numRegressors)]);
Step 2: Check the Contrast Vector
Ensure that the contrast vector is correctly specified and matches the design matrix. Here is an example of how to create the contrast vector:
% Initial contrast vector for the conditions of interest
initial_convec = [0 0 -1 0 0 1 0 0 0 0 0 0 0];
% Number of confounds
num_confounds = size(confounds_matrix, 2);
% Additional zeros for the confounds
additional_convec = zeros(1, num_confounds + 1);
% Complete contrast vector
convec = [initial_convec, additional_convec];
% Ensure the length of convec matches the number of regressors
assert(length(convec) == numRegressors, 'Contrast vector length does not match number of regressors');
Step 3: Specify the Contrast in the Batch
Ensure that the contrast is correctly specified in the batch. Here is an example:
matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'nav-follow';
matlabbatch{3}.spm.stats.con.consess{1}.tcon.convec = convec;
matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'none'; % or 'replsc' if appropriate
matlabbatch{3}.spm.stats.con.delete = 0;
Step 4: Run the Batch
Run the batch and check for errors:
spm_jobman('run', matlabbatch);
0 comentarios
Ver también
Categorías
Más información sobre MRI en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!