| Author |
Topic  |
|
|
eesley
BIAC Alum
USA
7 Posts |
Posted - Mar 18 2003 : 2:04:01 PM
|
I am running into some difficulties including regressors in an SPM analysis script. Does anyone have any experience with this?
Chuck E. |
|
|
weissman
New Member

17 Posts |
Posted - Apr 10 2003 : 1:30:22 PM
|
I have done this many times, in the context of modeling motion parameters. What seems to be the difficulty?
: ) Daniel |
 |
|
|
eesley
BIAC Alum
USA
7 Posts |
Posted - Apr 10 2003 : 1:37:05 PM
|
Perhaps it would be easier to meet in person to go over it? (we can email to set up a time eesley@biac.duke.edu) I entered the regressors in a similar format as the conditions in the script, but when I go to run it I get strange, undecipherable errors. Without the regressors sections, it runs fine. So I'm not sure where the error is.
Thanks for you help, Chuck |
 |
|
|
weissman
New Member

17 Posts |
Posted - Apr 10 2003 : 2:06:18 PM
|
Hi Chuck,
Rather than meeting immediately, why don't we see if we can solve your problem via some interaction in the BIAC forums? What I propose is to send you an example of a script in which we incorporate user-specified regressors into the model.
Later today, I'll send you a copy of an SPM makesinglemodel batch script, which is what I use to model the data from each individual fMRI subject.
In this script, you'll see how we model the motion parameters with user-specified regressors. For each fMRI run, there are 6 motion regressors arranged in a matrix that has 6 columns and a number of rows that is equal to the number of TRs in the run.
You'll see that we load these motion regressors from the realignment files that SPM spits out when it performs motion correction (e.g., the names of the files are realignment_params_*) for each fMRI run.
What if you take a look at this script when I send it, and see if you can figure out a solution? If not, just let me know.
: ) Daniel
|
 |
|
|
weissman
New Member

17 Posts |
Posted - Apr 10 2003 : 5:43:59 PM
|
Hi Chuck,
Below, I've pasted the text of an example script that we use to perform model estimation using spm. Note that several of the specifications are made using variable names, as we have batched the "batch" software, so to speak.
The critical sections you should look at are the lines in which regressors are defined.
The first line below specifies which regressors to use for each run. These are numbered 1-6 because the motion parameters for run1 should always be used when modeling run 1, the params from run should always be used when modeling run 2, etc.
'regressors', [1 2 3 4 5 6], ...
The second line specifies that 6 regressors should be included in each run, one for each of the 6 motion parameters that I described in my earlier message.
'regressors_nb', [6 6 6 6 6 6], ...
If you look a bit lower in the file, you'll see several additional lines in which the motion parameters are first loaded for each run. The parameters are loaded into matrices that have 6 columns (one for each motion parameter) and Number of TRs rows (there's an estimate of motion at each TR). These lines are as follows:
mot1 = load (sprintf('%s%srun01%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot2 = load (sprintf('%s%srun02%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot3 = load (sprintf('%s%srun03%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot4 = load (sprintf('%s%srun04%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot5 = load (sprintf('%s%srun05%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot6 = load (sprintf('%s%srun06%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator));
Next, several 6 user-specified regressors are created for each run (one for each of the 6 motion paramters) as shown below:
regressors(1) = struct( ... %motion parameters for run1; here, run1=1st scan run, whatever it is 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot1); regressors(2) = struct( ... %motion parameters for run2 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot2); regressors(3) = struct( ... %motion parameters for run3 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot3); regressors(4) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot4); regressors(5) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot5); regressors(6) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot6);
I would have attached the file to this message rather than pasting it in, but I don't know how to do that in the BIAC forums, so I'll send you a copy as well.
Hope this helps!
: ) Daniel
% makeSingleModel.m % % Description: This spm bch file (batch file) sets up and % estimates a simple single subject box car design. The % first four volumes were discarded prior to running this % script, so time points 5:60 have been included in the % model estimation. The data being analyzed is from the % 1998 Irritable Bowel Syndrom fMRI study with James MacFall % and Udi Ringel
% Charles Michelich 2000/02/17 original
%--------------------------------------------------------------- % user variables defined here %--------------------------------------------------------------- global FUNCTIONAL_DIR NUM_OF_RUNS RUN_ORDER EXAM_NUM;
dataPath = FUNCTIONAL_DIR; seperator = '\'; examNumber = EXAM_NUM; nTRs=264; nSubjects = 1; nRuns = NUM_OF_RUNS;
%Onset Times %Global Task is runs1-3 %Local Task is runs 4-6 %CC=Congruent preceded by congruent %IC=Incongruent precedued by Congruent %CI=Congruent preceded by Incongruent %II=Incongruent preceded by Incongruent %Don't model the NS (no-stim) events in SPM. Global1CC=[2 4 8 22 40 46 50 68 98 112 122 124 130 158 190 228 230 234 248 250]; Global1CI=[18 32 38 62 66 78 84 96 110 120 134 148 156 172 186 208 212 216 226 240 246]; Global1IC=[12 24 34 54 64 70 80 86 100 114 132 138 150 160 174 200 210 214 222 238 244]; Global1II=[30 36 56 58 60 72 90 94 102 106 140 142 144 146 152 154 168 170 176 180 206]; Global1NSC=[6 10 20 42 44 48 52 126 128 136 188 192 194 196 198 218 220 232 236 242]; Global1NSI=[14 16 26 28 74 76 82 88 92 104 108 116 118 162 164 166 178 182 184 202 204 224]; Global2CC=[2 4 16 18 32 38 42 46 48 68 118 134 136 144 146 176 202 214 220 242 250]; Global2CI=[10 24 36 66 80 90 100 116 126 132 142 152 174 182 196 200 206 210 232 238]; Global2IC=[6 22 34 50 70 82 92 104 120 130 138 148 154 178 186 198 204 208 230 236]; Global2II=[52 54 56 58 60 76 86 88 94 108 110 114 122 124 140 150 158 160 164 168 188 194]; Global2NSC=[12 14 20 26 28 30 40 44 102 128 184 212 216 218 222 224 226 228 234 240 244 246 248]; Global2NSI=[8 62 64 72 74 78 84 96 98 106 112 156 162 166 170 172 180 190 192]; Global3CC=[10 32 36 66 84 134 150 156 166 184 196 198 200 206 230 232 238 240 242 246 248 250]; Global3CI=[8 18 30 46 62 82 110 114 124 132 142 154 160 164 170 176 190 194 216 226]; Global3IC=[12 22 38 48 68 88 112 120 126 138 152 158 162 168 174 186 192 210 218]; Global3II=[2 16 26 28 42 44 50 52 54 56 58 80 90 96 98 102 104 122 128 140 214 222]; Global3NSC=[20 34 64 86 116 118 136 144 146 148 172 178 180 182 202 204 208 228 234 236 244]; Global3NSI=[4 6 14 24 40 60 70 72 74 76 78 92 94 100 106 108 130 188 212 220 224]; Local1CC=[26 32 34 36 62 70 72 80 82 84 86 102 104 108 110 126 128 130 132]; Local1CI=[10 16 20 50 58 66 78 100 116 124 144 154 158 164 182 196 202 208 220 226 238 244 248]; Local1IC=[12 18 38 52 64 74 96 112 118 140 152 156 160 168 188 198 204 212 222 230 242 246]; Local1II=[14 40 44 46 56 98 170 172 174 178 190 194 200 214 216 218 224 232 236]; Local1NSC=[22 24 28 30 60 68 88 90 92 94 106 134 136 138 146 148 150 166 184 186 210 228 240 250]; Local1NSI=[6 8 42 48 54 76 114 120 122 142 162 176 180 192 206 234]; Local2CC=[2 30 84 88 90 114 140 170 172 178 188 192 200 208 212 228 230 232 234 246 250]; Local2CI=[14 18 24 28 62 80 100 112 138 144 152 156 164 168 176 186 196 204 226 242]; Local2IC=[4 16 20 26 36 64 98 102 120 142 146 154 160 166 174 184 194 202 214 238]; Local2II=[12 44 46 52 54 66 68 76 78 104 106 110 124 126 128 130 132 134 148 162 218 222]; Local2NSC=[32 34 82 86 92 94 96 116 118 158 180 182 190 198 206 210 236 244 248]; Local2NSI=[6 8 10 22 38 40 42 48 50 56 58 60 70 72 74 108 122 136 150 216 220 224 240]; Local3CC=[18 20 22 36 38 40 56 68 106 108 134 140 166 168 176 198 202 206 212 218 220 230]; Local3CI=[14 30 54 78 102 120 132 138 164 180 188 194 210 216 224 228 236 242 248]; Local3IC=[6 26 46 76 82 110 128 136 142 178 182 192 208 214 222 226 232 238 244 250]; Local3II=[8 12 28 52 84 86 90 94 96 98 100 114 116 130 144 148 150 152 154 158 160 186]; Local3NSC=[16 24 32 34 42 44 58 60 62 64 66 70 72 74 80 104 122 124 126 170 172 174 190 196 200 204]; Local3NSI=[10 48 50 88 92 112 118 146 156 162 184 234 240 246];
fileSpec = 'snaV*.img';
% Get the file names for each volume in each run for n=1:nRuns fullDataPath = sprintf('%s\\run%02d',dataPath,n); for t = 1:nTRs % # of images in each run folder oneRun{t} = fullfile(fullDataPath,sprintf('snaV%04d.img',t)); end filenames{n} = char(oneRun); end
%--------------------------------------------------------------- % batch variables defined here for analysis 'model' %---------------------------------------------------------------
model(1) = struct( ... 'types', 4, ... % 4 = 'specify and estimate a model' 'RT', 1.25, ... % TR in seconds 'nsess', 6, ... % Number of runs 'nscans', [264 264 264 264 264 264], ... 'replicated', 0, ... %pbm 0=not; 1=replicated 'conditions', RUN_ORDER, ... %conditions = runs; runs in actual order of occurrence 'conditions_nb', [4 4 4 4 4 4], ... %number of event types you specify within each run 'stochastics_flag', [0], ... %0=not stochastic; 1=yes 'parametrics_type', {{'none', 'none', 'none', 'none', 'none', 'none'}}, ... 'regressors', [1 2 3 4 5 6], ... 'regressors_nb', [6 6 6 6 6 6], ... 'files', {filenames}, ... 'global_effects', {'None'}, ...% need value for normalization on. 'HF_fil', 'default', ...% need value for filter on 'LF_fil', 'none', ...% need value for filter on 'int_corr', 'AR(1)', ... 'trial_fcon', 1, ... 'now_later', 0);%1 means now, 0 means later
%------------------------------------------------- %Regressors %-------------------------------------------------
mot1 = load (sprintf('%s%srun01%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot2 = load (sprintf('%s%srun02%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot3 = load (sprintf('%s%srun03%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot4 = load (sprintf('%s%srun04%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot5 = load (sprintf('%s%srun05%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator)); mot6 = load (sprintf('%s%srun06%srealignment_params_aV0001.txt',FUNCTIONAL_DIR,seperator,seperator));
regressors(1) = struct( ... %motion parameters for run1; here, run1=1st scan run, whatever it is 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot1); regressors(2) = struct( ... %motion parameters for run2 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot2); regressors(3) = struct( ... %motion parameters for run3 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot3); regressors(4) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot4); regressors(5) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot5); regressors(6) = struct( ... %motion parameters for run4 'names', {{'xtranslation', 'ytranslation', 'ztranslation', 'xrotation', 'yrotation', 'zrotation'}}, ... %pbm 'values', mot6);
%------------------------------------------- % Conditions %------------------------------------------- %Global1 conditions(1) = struct( ... 'names', {{'Global1CC','Global1CI','Global1IC','Global1II'}}, ... %pbm 'onsets', {{[Global1CC],[Global1CI],[Global1IC],[Global1II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%Global2 conditions(2) = struct( ... 'names', {{'Global2CC','Global2CI','Global2IC','Global2II'}}, ... %pbm 'onsets', {{[Global2CC],[Global2CI],[Global2IC],[Global2II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%Global3 conditions(3) = struct( ... 'names', {{'Global3CC','Global3CI','Global3IC','Global3II'}}, ... %pbm 'onsets', {{[Global3CC],[Global3CI],[Global3IC],[Global3II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%Local1 conditions(4) = struct( ... 'names', {{'Local1CC','Local1CI','Local1IC','Local1II'}}, ... %pbm 'onsets', {{[Local1CC],[Local1CI],[Local1IC],[Local1II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%Local2 conditions(5) = struct( ... 'names', {{'Local2CC','Local2CI','Local2IC','Local2II'}}, ... %pbm 'onsets', {{[Local2CC],[Local2CI],[Local2IC],[Local2II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%Local3 conditions(6) = struct( ... 'names', {{'Local3CC','Local3CI','Local3IC','Local3II'}}, ... %pbm 'onsets', {{[Local3CC],[Local3CI],[Local3IC],[Local3II]}}, ... %pbm 'types', {{'events', 'events', 'events', 'events'}}, ... %pbm 'bf_ev', [2 2 2 2], ... %basis functions for event design%pbm 'volterra', 0, ... 'variable_dur', 0);
%-------------------------------------------
% Hemodynamic Response Function bf_ev(2) = struct( ... 'ev_type', 1);
%-----BEGIN Unused epoch design basis functions----- %bf_ep(1) = struct( ... % 'ep_type', 4, ... % 'conv', 0, ... % 'deriv', 0, ... % 'length',26);
%bf_ep(2) = struct( ... % 'ep_type', 4, ... % 'conv', 0, ... % 'deriv', 0, ... % 'length',30); %-----END Unused epoch design basis functions-----
|
 |
|
|
eesley
BIAC Alum
USA
7 Posts |
Posted - Apr 11 2003 : 2:33:25 PM
|
Ok, thanks for your help. That's pretty clear and I believe I have it set up in that way, though the way I load in some of the files is different and rather than having motion data, I just have one neurocognitive test score (perhaps more later, but starting with one) for each subject. I have tried to enter the score as if it were one score on each TR (99 TRs per run). But when I run it I get this error:
??? Error using ==> horzcat All matrices on a row in the bracketed expression must have the same number of rows.
Error in ==> p:\matlab\spm99\spm_fMRI_design.m On line 315 ==> X = [X D(:,i)];
Have you seen that before?
Here are the relevant parts of the script below:
%--------------------------------------------------------------- % batch variables defined here for analysis 'model' %---------------------------------------------------------------
model(1) = struct( ... 'types', 4, ... % 1 = 'specify a model'; 4 = 'specify and estimate a model' 'global_effects', {'None'}, ...% need value for normalization on. 'burst_mode', 0, ... 'RT', 2.5, ... % TR in seconds 'nsess', length(F), ... % Number of runs 'nscans', 99*ones(1,length(F)), ... 'replicated', 0, ... %pbm 0=not; 1=replicated 'conditions', [repmat([1:10],[1,5]), 11, 12, 13, 14, 15, 16, 16, 18, 19, 20, ... repmat([11:20],[1,3]), repmat([21:30],[1]), 61, 62, 63, 64, 65, 66, 67, ... 68, 69, 70, repmat([31:40],[1]), 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, ... 31, 33, 35, 37, 39, 32, 34, 36, 38, 40, [41:50], [81:90], [51:60], [91:99], [31:40], [41:50] [1:10]],... %conditions = runs; control 1,2 olan 1,2 risp 1,2 runs in actual order of occurrence 'conditions_nb', 1*ones(1,length(F)), ... %number of event types you specify within each run 'stochastics_flag', zeros(1,length(F)), ... %0=not stochastic; 1=yes 'parametrics_type', {repmat({'none'},[1 length(F)])}, ... 'regressors', [2*ones(1,10), 3*ones(1,10), 4*ones(1,10), 5*ones(1,10), 6*ones(1,10), 8*ones(1,10),... 9*ones(1,10), 10*ones(1,10), 11*ones(1,10), 12*ones(1,10), 13*ones(1,10), 15*ones(1,10),... 16*ones(1,10), 17*ones(1,10), 18*ones(1,10), 20*ones(1,10), 21*ones(1,10), 22*ones(1,9), 23*ones(1,10),... 24*ones(1,10), 25*ones(1,10)],... % 'regressors_nb', 1*ones(1,length(F)),... % insert number of regressors 2*ones(1,length(F)) 'files', {{F{:}}}, ... 'HF_fil', 'none', ...% need value for filter on 'LF_fil', 'none', ...% need value for filter on 'int_corr', 'none', ... 'trial_fcon', 0, ... 'now_later', 1);%1 means now, 0 means later
%-------------------------------------------
% User Specified Regressors %-------------------------------------------
% 03430 no data for controls regressors(1) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03613 no data for controls regressors(2) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03609 no data for controls regressors(3) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03732 no data for controls regressors(4) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03736 no data for controls regressors(5) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03842 no data for controls regressors(6) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03650 no data for controls regressors(7) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03841 no data for controls regressors(8) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03844 no data for controls regressors(9) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03983 no data for controls regressors(10) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03987 no data for controls regressors(11) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% 03592 regressors(12) = struct( ... 'names', {{'digsym'}}, ... 'values', [36*ones(1,99)]);
% 02349 regressors(13) = struct( ... 'names', {{'digsym'}}, ... 'values', [55*ones(1,99)]);
% 03451 regressors(14) = struct( ... 'names', {{'digsym'}}, ... 'values', [53*ones(1,99)]);
% 03829 regressors(15) = struct( ... 'names', {{'digsym'}}, ... 'values', [42*ones(1,99)]);
% 02532 regressors(16) = struct( ... 'names', {{'digsym'}}, ... 'values', [55*ones(1,99)]);
% 03629 regressors(17) = struct( ... 'names', {{'digsym'}}, ... 'values', [51*ones(1,99)]);
% 03658 regressors(18) = struct( ... 'names', {{'digsym'}}, ... 'values', [47*ones(1,99)]);
% 03672 regressors(19) = struct( ... 'names', {{'digsym'}}, ... 'values', [34*ones(1,99)]);
% 02770 regressors(20) = struct( ... 'names', {{'digsym'}}, ... 'values', [32*ones(1,99)]);
% 03887 regressors(21) = struct( ... 'names', {{'digsym'}}, ... 'values', [53*ones(1,99)]);
% 03019 regressors(22) = struct( ... 'names', {{'digsym'}}, ... 'values', [32*ones(1,99)]);
% 4317 regressors(23) = struct( ... 'names', {{'digsym'}}, ... 'values', [51*ones(1,99)]);
% 4105 regressors(24) = struct( ... 'names', {{'digsym'}}, ... 'values', [37*ones(1,99)]);
% 4092 no data for controls regressors(25) = struct( ... 'names', {{'digsym'}}, ... 'values', [1*ones(1,99)]);
% regressors(n) = struct( ... % 'names', {{'baseline', 'changeincog'}}, ... % 'values', [neurocogtestvalue*ones(length(F),1), neurocogtestvalue2*ones(length(F),1)];
% Hemodynamic Response Function bf_ev(1) = struct( ... 'ev_type', 1); |
 |
|
|
mbudde
Starting Member
USA
9 Posts |
Posted - Apr 14 2003 : 12:44:47 PM
|
chuck,
I believe the regressors should be a column matrix, so instead of using "ones(1,99)" use "ones(99,1)".
matt |
 |
|
|
eesley
BIAC Alum
USA
7 Posts |
Posted - Apr 14 2003 : 2:55:36 PM
|
Thanks! That seems to have done the trick so far!
Chuck |
 |
|
| |
Topic  |
|
|
|