attachment:batch_spm5_1stlevel(1).m of MatlabLecturesSchedule - Methods
location: attachment:batch_spm5_1stlevel(1).m of MatlabLecturesSchedule

Attachment 'batch_spm5_1stlevel(1).m'

Download

   1 % 1st-level SPM5 batch stats script SPM5	Rik Henson, Jan 06
   2 % No contrasts, but see SPM2 script on SPM webpage for examples (has not changed)
   3 % (or example SPM5 batch for 2nd-level ANOVAs)
   4 
   5 spm('defaults','FMRI')
   6 global defaults
   7 global UFp; UFp = 0.001;
   8 
   9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10 
  11 nses = 2;		  % Number of sessions
  12 ncon = [4 4];		  % Number of conditions per session
  13 sesdir = {'Ses1';'Ses2'}; % Session directory names
  14 
  15 nscan = [740 740];	  % Vector of scans per session
  16 
  17 owd = '/myhome';
  18 
  19 subnum = [1:18];
  20 subnam = [050045 060001 060002 060003 060004 060005 060013 060014 060015 060016 060017 060018 060019 060023 060024 060025 060035 060036];
  21 dosubs = [1:2];
  22 
  23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24 
  25 for s = 1:length(dosubs)
  26 
  27     clear SPM
  28 
  29     sub = dosubs(s)
  30     f = find(subnum==sub);
  31     cbusub = subnam(f);
  32 	
  33     cd(owd)
  34 
  35 % Replace the next line with a function call to return cell array of onsets,
  36 % durations (could be all 0 for events), and possibly any parametric modulators
  37 % (or to load these from a mat file)
  38     [sots,durs,pars] = get_sots(sub);
  39 
  40     for ses=1:nses
  41       for c=1:ncon(ses)
  42 	   onsets{ses,c} = sots{ses,c};
  43 	   if(isempty(onsets{ses,c}))	% Hack to handle any missing events
  44 		onsets{ses,c}=nscan(ses)-3;
  45   	   end
  46       end
  47     end
  48 
  49     swd = sprintf('%s/sub%06d',owd,cbusub);
  50     cwd = sprintf('%s/%s/Stats',swd,sesdir{1});
  51     eval(sprintf('!mkdir %s',cwd));
  52     cd(cwd)
  53 
  54 % Specify design 
  55 %==========================================================
  56 
  57     SPM.nscan          = nscan;
  58     SPM.xBF.name       = 'hrf';
  59     SPM.xBF.order      = 1;                 
  60     SPM.xBF.length     = 32; 
  61     SPM.xBF.T          = 16;     
  62     SPM.xBF.T0         = 8;     
  63     SPM.xBF.UNITS      = 'scans';
  64     SPM.xBF.Volterra   = 1;      
  65 
  66 % Trial specification: Onsets, duration (UNITS) and parameters for modulation
  67 %-------------------------------------------------------------
  68  
  69     npar = zeros(1,nses);
  70     for ses=1:nses
  71 	  for c=1:ncon(ses)
  72 
  73 	    SPM.Sess(ses).U(c).name      = {sprintf('Con%d',c)};
  74 	    SPM.Sess(ses).U(c).ons       = onsets{c};
  75 	    SPM.Sess(ses).U(c).dur       = durs{c};
  76 
  77 	    if isempty(pars{c})
  78 		   SPM.Sess(ses).U(c).P(1).name = 'none';
  79 	    else
  80                 for p=1:size(pars{c},2)
  81 		          SPM.Sess(ses).U(c).P(p).name = sprintf('par %d',p);
  82  	              SPM.Sess(ses).U(c).P(p).P    = pars{c}(:,p);
  83 	              SPM.Sess(ses).U(c).P(p).h    = 1;	% order (1=linear)
  84 	              SPM.Sess(ses).U(c).P(p).i    = [1 p+1];
  85                   npar(ses) = npar(ses)+1;
  86                 end
  87         end
  88 	  end
  89     end
  90 
  91 
  92 % design (user specified covariates, eg movement parameters)
  93 %-------------------------------------------------------------
  94 
  95 
  96    for ses = 1:nses
  97 
  98 	 nusr(ses) = 0;
  99 
 100 % Eg if want to model out bad scans (eg spikes...)
 101 %  	spks = load(sprintf('%s/spikes_sub%d_ses%d',swd,sub,wses(ses)));
 102 %	if(~isempty(spks.adout))
 103 %    	 spks = unique(spks.adout(:,1));
 104 % 	 nusr(ses) = length(spks);
 105 %    	 usr = zeros(nscan,nusr(ses));
 106 %    	 for spk=1:nusr(ses)
 107 %		usr(spks(spk),spk)=1;
 108 %    	 end
 109 %	 SPM.Sess(ses).C.C = usr;
 110 %	 tmp=[];
 111 %	 for r=1:nusr(ses)
 112 %	 	tmp{r} = sprintf('spike %d',r);
 113 %	 end
 114 %	 SPM.Sess(ses).C.name = tmp;
 115 %	else
 116 %	 SPM.Sess(ses).C.C = [];
 117 %	 tmp=[];
 118 %	end
 119 
 120 	  mname = spm_select('List', fullfile(swd,sesdir{ses}), '^rp_.*\.txt$');
 121       mpars = load(fullfile(swd,sesdir{ses},mname));
 122 
 123 	  SPM.Sess(ses).C.C    = [SPM.Sess(ses).C.C mpars];
 124 	  SPM.Sess(ses).C.name = [tmp {'x' 'y' 'z' 'p' 'r' 'y'}];
 125 
 126 	  nusr(ses) = nusr(ses)+6;
 127      end
 128 
 129 % global normalization: OPTIONS:'Scaling'|'None'
 130 %-------------------------------------------------------------
 131      SPM.xGX.iGXcalc    = 'None';
 132 
 133 % low frequency confound: high-pass cutoff (secs) [Inf = no filtering]
 134 %-------------------------------------------------------------
 135      for ses=1:nses
 136 	   SPM.xX.K(ses).HParam = 128;
 137      end
 138 
 139 % intrinsic autocorrelations: OPTIONS: 'none'|'AR(1) + w'
 140 %-------------------------------------------------------------
 141      SPM.xVi.form       = 'AR(1)';
 142 
 143 
 144 % specify data: matrix of filenames and TR
 145 %=============================================================
 146 
 147     P=[]; files=cell(1,nses);
 148     for ses=1:nses
 149 	  files{ses} = spm_select('List', fullfile(swd,sesdir{ses}), '^sw.*\.nii$');
 150     	for f=1:length(files{ses})    
 151 		P = [P; fullfile(swd,sesdir{ses},files{ses}(f,:))];
 152 	  end
 153     end
 154     SPM.xY.P = P;
 155 
 156     SPM.xY.RT          = 1.48;
 157 
 158 % Configure design matrix
 159 %=============================================================
 160 
 161     SPM = spm_fmri_spm_ui(SPM);
 162 
 163 % Update real/nuisance in design matrix (for nonsphericity correction)
 164 %=============================================================
 165 
 166     if sum(nusr)>0
 167  	  for ses=1:nses
 168    		SPM.xX.iG = [SPM.xX.iG  [1:nusr(ses)] + (sum(ncon(1:ses))+sum(npar(1:ses)))*SPM.xBF.order + sum(nusr(1:(ses-1)))];
 169       end
 170  	  SPM.xX.iC = setdiff(SPM.xX.iC,SPM.xX.iG);
 171     end
 172 
 173 % Estimate parameters
 174 %==============================================================
 175     SPM = spm_spm(SPM);
 176 
 177 end

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-10-14 11:15:44, 737.5 KB) [[attachment:1_CBUComputing.pdf]]
  • [get | view] (2017-06-20 13:12:05, 1993.2 KB) [[attachment:1_CBUComputing2016.pdf]]
  • [get | view] (2017-10-11 18:16:13, 1942.0 KB) [[attachment:1_CBU_Computing.pdf]]
  • [get | view] (2017-10-11 18:11:29, 3455.5 KB) [[attachment:1_CBU_Computing.ppt]]
  • [get | view] (2015-10-09 15:29:53, 319.2 KB) [[attachment:2_Linux.pdf]]
  • [get | view] (2015-10-09 15:30:29, 5009.7 KB) [[attachment:2_Linux.zip]]
  • [get | view] (2014-12-04 10:03:39, 3958.5 KB) [[attachment:3_MATLAB.zip]]
  • [get | view] (2014-12-04 10:04:18, 212.0 KB) [[attachment:3_Parallel.pdf]]
  • [get | view] (2022-10-20 09:06:47, 1581.3 KB) [[attachment:Computing2022.pdf]]
  • [get | view] (2023-11-06 13:40:01, 1841.0 KB) [[attachment:Computing2023.pdf]]
  • [get | view] (2021-10-12 09:44:32, 1427.1 KB) [[attachment:Computing_11Oct21.pdf]]
  • [get | view] (2012-11-19 16:35:37, 2434.4 KB) [[attachment:Demo.zip]]
  • [get | view] (2015-12-02 13:45:02, 26.8 KB) [[attachment:ExampleScripts.zip]]
  • [get | view] (2013-12-17 18:24:09, 11.1 KB) [[attachment:Examples and exercises]]
  • [get | view] (2012-12-04 09:06:39, 9.8 KB) [[attachment:Examples.zip]]
  • [get | view] (2012-11-27 17:48:52, 11344.7 KB) [[attachment:ExamplesOlaf.zip]]
  • [get | view] (2013-12-17 18:28:39, 11.1 KB) [[attachment:Examples_and_exercises.zip]]
  • [get | view] (2015-11-24 17:37:13, 11.9 KB) [[attachment:Examples_and_exercises_2015.zip]]
  • [get | view] (2016-11-29 15:02:26, 11.8 KB) [[attachment:Examples_and_exercises_2016.zip]]
  • [get | view] (2016-11-30 11:57:48, 12.2 KB) [[attachment:Examples_and_exercises_2016_djm.zip]]
  • [get | view] (2017-11-14 12:21:56, 3158.3 KB) [[attachment:Examples_and_exercises_2017_djm.zip]]
  • [get | view] (2019-11-05 14:51:00, 12.7 KB) [[attachment:Examples_and_exercises_2019_djm.zip]]
  • [get | view] (2019-11-05 15:23:31, 12.9 KB) [[attachment:Examples_and_exercises_2019_djm2.zip]]
  • [get | view] (2019-11-05 15:28:25, 13.0 KB) [[attachment:Examples_and_exercises_2019_djm3.zip]]
  • [get | view] (2019-11-08 09:38:24, 11.2 KB) [[attachment:Examples_and_exercises_2019_djm4.zip]]
  • [get | view] (2017-11-14 12:24:35, 12.1 KB) [[attachment:Examples_and_exercises_Nov2017_djm.zip]]
  • [get | view] (2019-11-11 10:01:12, 903.9 KB) [[attachment:Getting Started Nov2019.pdf]]
  • [get | view] (2012-11-13 13:34:09, 386.8 KB) [[attachment:Handouts.pdf]]
  • [get | view] (2014-11-04 16:08:20, 1455.9 KB) [[attachment:IntroMatrixAlgebra.zip]]
  • [get | view] (2015-11-18 17:14:47, 932.3 KB) [[attachment:IntroMatrixAlgebra_Matlab_18Nov15.pdf]]
  • [get | view] (2015-11-18 17:18:06, 1513.6 KB) [[attachment:IntroMatrixAlgebra_Matlab_18Nov15.zip]]
  • [get | view] (2013-10-30 18:24:19, 571.7 KB) [[attachment:Intro_to_CBU_computing_2013.pdf]]
  • [get | view] (2013-12-11 12:54:22, 1994.6 KB) [[attachment:JTaylorMatlabLectureDemo.zip]]
  • [get | view] (2012-11-19 16:37:32, 1024.9 KB) [[attachment:Lecture.pdf]]
  • [get | view] (2012-11-19 16:36:10, 1024.9 KB) [[attachment:Lecture.zip]]
  • [get | view] (2012-11-13 17:46:26, 380.9 KB) [[attachment:LectureHandouts.pdf]]
  • [get | view] (2012-11-27 17:47:55, 1224.2 KB) [[attachment:LectureOlaf.pdf]]
  • [get | view] (2012-11-13 17:46:46, 830.7 KB) [[attachment:LectureSlides.pdf]]
  • [get | view] (2022-10-17 14:41:11, 286.5 KB) [[attachment:Linux2022.pdf]]
  • [get | view] (2023-11-07 13:36:57, 286.5 KB) [[attachment:Linux2023.pdf]]
  • [get | view] (2017-10-27 09:25:00, 201.3 KB) [[attachment:LinuxClass_JeffBerry_19Oct17.pdf]]
  • [get | view] (2018-10-22 12:48:26, 721.5 KB) [[attachment:LinuxClass_JeffBerry_22Oct18.pdf]]
  • [get | view] (2016-10-27 08:33:27, 207.2 KB) [[attachment:LinuxClass_JeffBerry_26Oct16.pdf]]
  • [get | view] (2016-10-27 09:01:40, 4178.5 KB) [[attachment:LinuxClass_JeffBerry_26Oct16_material.tar.gz]]
  • [get | view] (2021-10-12 09:44:37, 829.5 KB) [[attachment:LinuxPart1_11Oct21.pdf]]
  • [get | view] (2021-10-12 09:44:42, 684.8 KB) [[attachment:LinuxPart2_11Oct21.pdf]]
  • [get | view] (2016-11-21 10:18:53, 488.3 KB) [[attachment:MATLAB Basics 16Nov16.pdf]]
  • [get | view] (2019-11-06 17:33:48, 16.8 KB) [[attachment:MATLAB_basic_commands_2_exercises.docx]]
  • [get | view] (2019-11-06 17:36:48, 480.3 KB) [[attachment:MATLAB_basic_commands_2_exercises.pdf]]
  • [get | view] (2014-07-31 12:11:41, 357.8 KB) [[attachment:Matlab - SPM-AA.pdf]]
  • [get | view] (2017-11-01 11:22:33, 466.9 KB) [[attachment:Matlab Basic Commands - handouts]]
  • [get | view] (2017-11-01 11:22:45, 576.0 KB) [[attachment:Matlab Basic Commands - slides]]
  • [get | view] (2018-10-23 16:10:59, 2.4 KB) [[attachment:MatlabBasicsCommands_ Delia_23Oct18.zip]]
  • [get | view] (2018-10-23 16:12:21, 1192.1 KB) [[attachment:MatlabBasicsCommands_Delia_23Oct18.pdf]]
  • [get | view] (2014-11-14 11:28:06, 269.4 KB) [[attachment:MatlabVisualisation-Handouts.pdf]]
  • [get | view] (2014-11-14 11:28:21, 314.9 KB) [[attachment:MatlabVisualisation-Slides.pdf]]
  • [get | view] (2014-11-14 11:28:41, 541.0 KB) [[attachment:MatlabVisualisation_examples.zip]]
  • [get | view] (2018-10-23 16:09:45, 695.6 KB) [[attachment:Matlab_Basic_introduction_AndreaGreve_23Oct18.pdf]]
  • [get | view] (2012-11-26 19:00:14, 11342.9 KB) [[attachment:OlafExamples.zip]]
  • [get | view] (2012-11-26 18:59:49, 1224.0 KB) [[attachment:OlafLecture.pdf]]
  • [get | view] (2013-12-12 12:02:04, 878.5 KB) [[attachment:OlafMatrixAlgebraPresentation.pdf]]
  • [get | view] (2013-12-12 12:01:39, 3.6 KB) [[attachment:OlafMatrixAlgebraScript.m]]
  • [get | view] (2012-11-13 13:35:16, 2.5 KB) [[attachment:Scripts.zip]]
  • [get | view] (2015-12-02 12:17:56, 26.8 KB) [[attachment:ScriptsVisualization]]
  • [get | view] (2012-11-13 13:35:07, 647.1 KB) [[attachment:Slides.pdf]]
  • [get | view] (2017-11-01 11:28:12, 466.9 KB) [[attachment:YaaraMatlabBasicCommandsHandouts.pdf]]
  • [get | view] (2017-11-01 11:24:21, 4.7 KB) [[attachment:YaaraMatlabBasicCommandsScripts.zip]]
  • [get | view] (2017-11-01 11:28:25, 576.0 KB) [[attachment:YaaraMatlabBasicCommandsSlides.pdf]]
  • [get | view] (2015-10-27 15:04:53, 2.6 KB) [[attachment:YaaraMatlabBasics.zip]]
  • [get | view] (2015-10-27 15:05:37, 448.8 KB) [[attachment:YaaraMatlabBasicsHandouts.pdf]]
  • [get | view] (2015-10-27 15:06:10, 564.9 KB) [[attachment:YaaraMatlabBasicsSlides.pdf]]
  • [get | view] (2019-11-06 17:35:08, 718.0 KB) [[attachment:basic_commands_2_2019.pdf]]
  • [get | view] (2019-11-06 17:33:38, 2583.2 KB) [[attachment:basic_commands_2_2019.pptx]]
  • [get | view] (2013-03-18 18:22:07, 5.0 KB) [[attachment:batch_spm5_1stlevel(1).m]]
  • [get | view] (2017-11-30 12:46:52, 6.0 KB) [[attachment:cbu_scheduler_example.m]]
  • [get | view] (2014-12-10 13:21:59, 292.6 KB) [[attachment:computing_pres2014_cluster.pdf]]
  • [get | view] (2013-12-17 18:33:34, 11.1 KB) [[attachment:examples_and_exercises]]
  • [get | view] (2013-12-17 18:34:35, 11.1 KB) [[attachment:examples_and_exercises.zip]]
  • [get | view] (2015-11-24 17:32:11, 11.9 KB) [[attachment:examples_and_exercises_2015.zip]]
  • [get | view] (2012-12-04 16:11:47, 1338.4 KB) [[attachment:lecture]]
  • [get | view] (2016-12-07 17:33:36, 1032.1 KB) [[attachment:matlabWorkshop_viz_Kate.pdf]]
  • [get | view] (2017-11-22 11:10:30, 1310.9 KB) [[attachment:matlabWorkshop_viz_Kate2017.pdf]]
  • [get | view] (2019-11-07 17:32:52, 2156.8 KB) [[attachment:matlab_lecture_Nov_2019_post.pdf]]
  • [get | view] (2019-11-08 09:40:29, 3155.9 KB) [[attachment:matlab_lecture_Nov_2019_post.pptx]]
  • [get | view] (2013-02-04 14:58:14, 3.2 KB) [[attachment:mrclogo.gif]]
  • [get | view] (2019-11-08 19:18:11, 7.5 KB) [[attachment:plottingExampleCode_ljb_20191108.m]]
  • [get | view] (2019-11-08 19:16:48, 1604.9 KB) [[attachment:visualisationInMatlab_ljb_slides_20191109.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.