Home > marsbar > @mardo_99 > private > pr_spm_ui.m

pr_spm_ui

PURPOSE ^

MarsBaR: setting up the general linear model for independent data

SYNOPSIS ^

function varargout=pr_spm_ui(varargin)

DESCRIPTION ^

 MarsBaR: setting up the general linear model for independent data

 MarsBaR version copied with minor edits from:
 99/11/15 Andrew Holmes @(#)spm_spm_ui.m    2.33
 See that file for comments and help

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout=pr_spm_ui(varargin)
0002 % MarsBaR: setting up the general linear model for independent data
0003 %
0004 % MarsBaR version copied with minor edits from:
0005 % 99/11/15 Andrew Holmes @(#)spm_spm_ui.m    2.33
0006 % See that file for comments and help
0007 %
0008 % $Id$
0009 
0010 %-Condition arguments
0011 %-----------------------------------------------------------------------
0012 if (nargin==0), Action = 'CFG'; else, Action = varargin{1}; end
0013 
0014 % For selecting images, later
0015 img_flt = mars_veropts('get_img_ext');
0016 
0017 switch lower(Action), case 'cfg'
0018 %=======================================================================
0019 % - C O N F I G U R E   D E S I G N
0020 %=======================================================================
0021 % pr_spm_ui('CFG',D)
0022 if nargin<2, D = []; else, D = varargin{2}; end
0023 
0024 %-GUI setup
0025 %-----------------------------------------------------------------------
0026 SPMid    = spm('SFnBanner',mfilename,marsbar('ver'));
0027 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Stats: Setup analysis',0);
0028 spm_help('!ContextHelp',mfilename)
0029 
0030 %-Option definitions
0031 %-----------------------------------------------------------------------
0032 %-Generic factor names
0033 sF = {'sF1','sF2','sF3','sF4'};
0034 
0035 %-Covariate by factor interaction options
0036 sCFI = {'<none>';...                            %-1
0037     'with sF1';'with sF2';'with sF3';'with sF4';...            %-2:5
0038     'with sF2 (within sF4)';'with sF3 (within sF4)'};        %-6,7
0039 
0040 %-DesMtx argument components for covariate by factor interaction options
0041 % (Used for CFI's Covariate Centering (CC), GMscale & Global normalisation)
0042 CFIforms = {    '[]',        'C',    '{}';...            %-1
0043         'I(:,1)',    'FxC',    '{D.sF{1}}';...            %-2
0044         'I(:,2)',    'FxC',    '{D.sF{2}}';...            %-3
0045         'I(:,3)',    'FxC',    '{D.sF{3}}';...            %-4
0046         'I(:,4)',    'FxC',    '{D.sF{4}}';...            %-5
0047         'I(:,[4,2])',    'FxC',    '{D.sF{4},D.sF{2}}';...        %-6
0048         'I(:,[4,3])',    'FxC',    '{D.sF{4},D.sF{3}}'    };    %-7
0049 
0050 %-Centre (mean correction) options for covariates & globals            (CC)
0051 % (options 9-12 are for centering of global when using AnCova GloNorm) (GC)
0052 sCC = {        'around overall mean';...                %-1
0053         'around sF1 means';...                    %-2
0054         'around sF2 means';...                    %-3
0055         'around sF3 means';...                    %-4
0056         'around sF4 means';...                    %-5
0057         'around sF2 (within sF4) means';...            %-6
0058         'around sF3 (within sF4) means';...            %-7
0059         '<no centering>';...                    %-8
0060         'around user specified value';...            %-9
0061         '(as implied by AnCova)';...                %-10
0062         'GM';...                        %-11
0063         '(redundant: not doing AnCova)'}';            %-12
0064 %-DesMtx I forms for covariate centering options
0065 CCforms = {'ones(nScan,1)',CFIforms{2:end,1},''}';
0066 
0067 
0068 %-Global normalization options (options 1-7 match CFIforms)       (GloNorm)
0069 sGloNorm = {    'AnCova';...                        %-1
0070         'AnCova by sF1';...                    %-2
0071         'AnCova by sF2';...                    %-3
0072         'AnCova by sF3';...                    %-4
0073         'AnCova by sF4';...                    %-5
0074         'AnCova by sF2 (within sF4)';...            %-6
0075         'AnCova by sF3 (within sF4)';...            %-7
0076         'proportional scaling';...                %-8
0077         '<no global normalisation>'};                %-9
0078 
0079 %-Grand mean scaling options                                        (GMsca)
0080 sGMsca = {    'scaling of overall grand mean';...            %-1
0081         'scaling of sF1 grand means';...            %-2
0082         'scaling of sF2 grand means';...            %-3
0083         'scaling of sF3 grand means';...            %-4
0084         'scaling of sF4 grand means';...            %-5
0085         'scaling of sF2 (within sF4) grand means';...        %-6
0086         'scaling of sF3 (within sF4) grand means';...        %-7
0087         '(implicit in PropSca global normalisation)';...    %-8
0088         '<no grand Mean scaling>'    };            %-9
0089 %-NB: Grand mean scaling by subject is redundent for proportional scaling
0090 
0091 
0092 %-Global calculation options                                       (GXcalc)
0093 sGXcalc  = {    'omit';...                        %-1
0094         'user specified';...                    %-2
0095         'mean voxel value (within per image fullmean/8 mask)'};    %-3
0096 
0097 
0098 
0099 %=======================================================================
0100 %-D E S I G N   P A R A M E T E R S
0101 %=======================================================================
0102 %-Get design type
0103 %-----------------------------------------------------------------------
0104 nVar = 1;
0105 if isempty(D)
0106 
0107     %-Multivariate repsonse variable?
0108     %---------------------------------------------------------------
0109     if spm_input('Multivariate analysis?','+1','y/n',[1,0],2)
0110         nVar = spm_input('number of variates?','+1','n1');
0111     end
0112 
0113     D    = pr_spm_ui( ...
0114         char(spm_input('Select design class...','+1','m',...
0115         {'Basic stats','Standard PET designs','SPM96 PET designs'},...
0116         {'DesDefs_Stats','DesDefs_PET','DesDefs_PET96'},2)));
0117 end
0118 
0119 D = D(spm_input('Select design type...','+1','m',{D.DesName}'));
0120 
0121 
0122 %-Set factor names for this design
0123 %-----------------------------------------------------------------------
0124 sCC       = sf_estrrep(sCC,[sF',D.sF']);
0125 sCFI      = sf_estrrep(sCFI,[sF',D.sF']);
0126 sGloNorm  = sf_estrrep(sGloNorm,[sF',D.sF']);
0127 sGMsca    = sf_estrrep(sGMsca,[sF',D.sF']);
0128 
0129 %-Get filenames & factor indicies
0130 %-----------------------------------------------------------------------
0131 [P,I] = pr_spm_ui('Files&Indices',D.sF,D.n,D.b.aTime,nVar);
0132 nScan = size(I,1);                        %-#obs
0133 
0134 %-Additional design parameters
0135 %-----------------------------------------------------------------------
0136 bL  = any(diff(I,1),1);     %-Multiple factor levels?
0137     % NB: bL(2) might be thrown by user specified f1 levels
0138     %     (D.b.aTime & D.n(2)>1) - assumme user is consistent?
0139 bFI = [bL(1),bL(2:3)&~bL(4),bL(4),bL([2,3])&bL(4)];
0140     %-Allowable interactions for covariates
0141     %-Only offer interactions with multi-level factors, and
0142     % don't offer by F2|F3 if bL(4)!
0143 
0144 %-Build Condition (H) and Block (B) partitions
0145 %=======================================================================
0146 eval(['[H,Hnames] = spm_DesMtx(',D.Hform,');'])
0147 if rank(H)==nScan, error('unestimable condition effects'), end
0148 eval(['[B,Bnames] = spm_DesMtx(',D.Bform,');'])
0149 if rank(B)==nScan, error('unestimable block effects'), end
0150 
0151 %-Drop a constant H partition if B partition can model constant
0152 if size(H,2)>0 & all(H(:)==1) & (rank([H B])==rank(B))
0153     H = []; Hnames = {};
0154     warning('Dropping redundant constant H partition')
0155 end
0156 
0157 
0158 %-Covariate partition(s): interest (C) & nuisance (G) excluding global
0159 %=======================================================================
0160 nC = D.nC;            %-Default #covariates
0161 C  = {[],[]}; Cnames = {{},{}};    %-Covariate DesMtx partitions & names
0162 xC = [];            %-Struct array to hold raw covariates
0163 
0164 
0165 dcname = {'CovInt','NusCov'};    %-Default root names for covariates
0166 dstr   = {'covariate','nuisance variable'};
0167 
0168 GUIpos = spm_input('!NextPos');
0169 nc     = [0,0];
0170 for i=1:2            % 1:covariates of interest, 2:nuisance variables
0171     if isinf(nC(i)), nC(i)=spm_input(['# ',dstr{i},'s'],GUIpos,'w1'); end
0172 
0173     while nc(i) < nC(i)
0174 
0175     %-Create prompt, get covariate, get covariate name
0176         %---------------------------------------------------------------
0177     if nC(i)==1, str=dstr{i}; else, str=sprintf('%s %d',dstr{i},nc(i)+1); end
0178         c = spm_input(str,GUIpos,'r',[],[nScan,Inf]);
0179         if any(isnan(c(:))), break, end        %-NaN is dummy value to exit
0180     nc(i)  = nc(i)+1;            %-#Covariates (so far)
0181     if nC(i)>1,    tstr = sprintf('%s^{%d}',dcname{i},nc(i));
0182     else,        tstr = dcname{i}; end
0183            cname  = spm_input([str,' name?'],'+1','s',tstr);
0184            rc     = c;                %-Save covariate value
0185     rcname = cname;                %-Save covariate name
0186 
0187         %-Interaction option? (if single covariate vector entered)?
0188         %---------------------------------------------------------------
0189         if size(c,2) == 1
0190                if length(D.iCFI{i})>1
0191                %-User choice of interaction options, default is negative
0192                %-Only offer interactions for appropriate factor combinations
0193         iCFI = intersect(abs(D.iCFI{i}),find([1,bFI]));
0194         dCFI = max([1,intersect(iCFI,-D.iCFI{i}(D.iCFI{i}<0))]);
0195             iCFI = spm_input([str,': interaction?'],'+1','m',...
0196             sCFI(iCFI),iCFI,find(iCFI==dCFI));
0197         else
0198         iCFI = abs(D.iCFI{i});        %-AutoSelect default option
0199         end
0200     else
0201         iCFI = 1;
0202     end
0203 
0204         %-Centre covariate(s)? (Default centring to correspond to CFI)
0205         % Always offer "no centering" as default for design matrix blocks
0206         %---------------------------------------------------------------
0207     DiCC = D.iCC{i};
0208     if size(c,2)>1, DiCC = union(DiCC,-8); end
0209         if length(DiCC)>1
0210             %-User has a choice of centering options
0211         %-Only offer factor specific for appropriate factor combinations
0212         iCC = intersect(abs(DiCC),find([1,bFI,1]) );
0213             %-Default is max -ve option in D, overridden by iCFI if CFI
0214         if iCFI==1, dCC=-DiCC(DiCC<0); else, dCC=iCFI; end
0215         dCC = max([1,intersect(iCC,dCC)]);
0216         iCC = spm_input([str,': centre?'],'+1','m',...
0217             sCC(iCC),iCC,find(iCC==dCC));
0218         else
0219             iCC = abs(DiCC);    %-AutoSelect default option
0220         end
0221     %-Centre within factor levels as appropriate
0222         if any(iCC==[1:7]), c = c - spm_meanby(c,eval(CCforms{iCC})); end
0223 
0224         %-Do any interaction (only for single covariate vectors)
0225         %---------------------------------------------------------------
0226         if iCFI>1                %-(NB:iCFI=1 if size(c,2)>1)
0227                tI        = [eval(CFIforms{iCFI,1}),c];
0228         tConst    = CFIforms{iCFI,2};
0229         tFnames   = [eval(CFIforms{iCFI,3}),{cname}];
0230         [c,cname] = spm_DesMtx(tI,tConst,tFnames);
0231     elseif size(c,2)>1            %-Design matrix block
0232         [null,cname] = spm_DesMtx(c,'X',cname);
0233     else
0234         cname = {cname};
0235     end
0236 
0237     %-Store raw covariate details in xC struct for reference
0238     %-Pack c into appropriate DesMtx partition
0239         %---------------------------------------------------------------
0240     %-Construct description string for covariate
0241     str = {sprintf('%s: %s',str,rcname)};
0242     if size(rc,2)>1, str = {sprintf('%s (block of %d covariates)',...
0243         str{:},size(rc,2))}; 
0244     end
0245     if iCC<8, str=[str;{['used centered ',sCC{iCC}]}]; end
0246     if iCFI>1, str=[str;{['fitted as interaction ',sCFI{iCFI}]}]; end
0247 
0248     tmp       = struct(    'rc',rc,    'rcname',rcname,...
0249                 'c',c,        'cname',{cname},...
0250                 'iCC',iCC,    'iCFI',iCFI,...
0251                 'type',i,...
0252                 'cols',[1:size(c,2)] + ...
0253                         size([H,C{1}],2) +  ...
0254                         size([B,C{2}],2)*(i-1),...
0255                 'descrip',{str}                );
0256     if isempty(xC), xC=tmp; else, xC=[xC,tmp]; end
0257     C{i}      = [C{i},c];
0258     Cnames{i} = [Cnames{i}; cname];
0259 
0260     end    % (while)
0261 
0262 end % (for)
0263 clear c tI tConst tFnames
0264 spm_input('!SetNextPos',GUIpos);
0265 
0266 %-Unpack into C & G design matrix sub-partitions
0267 G = C{2}; Gnames = Cnames{2};
0268 C = C{1}; Cnames = Cnames{1};
0269 
0270 
0271 %-Options...
0272 %=======================================================================
0273 %-Global normalization options                                 (GloNorm)
0274 %-----------------------------------------------------------------------
0275 if length(D.iGloNorm)>1
0276     %-User choice of global normalisation options, default is negative
0277     %-Only offer factor specific for appropriate factor combinations
0278     iGloNorm = intersect(abs(D.iGloNorm),find([1,bFI,1,1]));
0279     dGloNorm = max([0,intersect(iGloNorm,-D.iGloNorm(D.iGloNorm<0))]);
0280     iGloNorm = spm_input('GloNorm: Select global normalisation','+1','m',...
0281             sGloNorm(iGloNorm),iGloNorm,find(iGloNorm==dGloNorm));
0282 else
0283     iGloNorm = abs(D.iGloNorm);
0284 end
0285 
0286 
0287 %-Grand mean scaling options                                     (GMsca)
0288 %-----------------------------------------------------------------------
0289 if iGloNorm==8
0290     iGMsca=8;    %-grand mean scaling implicit in PropSca GloNorm
0291 elseif length(D.iGMsca)==1
0292     iGMsca = abs(D.iGMsca);
0293 else
0294     %-User choice of grand mean scaling options
0295     %-Only offer factor specific for appropriate factor combinations
0296     iGMsca = intersect(abs(D.iGMsca),find([1,bFI,0,1]));
0297         %-Default is max -ve option in D, overridden by iGloNorm if AnCova
0298         if iGloNorm==9, dGMsca=-D.iGMsca(D.iGMsca<0); else, dGMsca=iGloNorm; end
0299     dGMsca = max([0,intersect(iGMsca,dGMsca)]);
0300     iGMsca = spm_input('GMsca: grand mean scaling','+1','m',...
0301             sGMsca(iGMsca),iGMsca,find(iGMsca==dGMsca));
0302 end
0303 
0304 
0305 %-Value for PropSca / GMsca                                         (GM)
0306 %-----------------------------------------------------------------------
0307 if iGMsca == 9                          %-Not scaling (GMsca or PropSca)
0308     GM = 0;                         %-Set GM to zero when not scaling
0309 else                                    %-Ask user value of GM
0310     if iGloNorm==8
0311         str = 'PropSca global mean to';
0312     else
0313         str = [strrep(sGMsca{iGMsca},'scaling of','scale'),' to'];
0314     end
0315     GM = spm_input(str,'+1','r',D.GM,1);
0316     %-If GM is zero then don't GMsca! or PropSca GloNorm
0317     if GM==0, iGMsca=9; if iGloNorm==8, iGloNorm=9; end, end
0318 end
0319 
0320 %-Sort out description strings for GloNorm and GMsca
0321 %-----------------------------------------------------------------------
0322 sGloNorm = sGloNorm{iGloNorm};
0323 sGMsca   = sGMsca{iGMsca};
0324 if iGloNorm==8
0325     sGloNorm = sprintf('%s to %-4g',sGloNorm,GM);
0326 elseif iGMsca<8
0327     sGMsca   = sprintf('%s to %-4g',sGMsca,GM);
0328 end
0329 
0330 
0331 %-Global centering (for AnCova GloNorm)                             (GC)
0332 %-----------------------------------------------------------------------
0333 %-Specify the centering option for the global covariate for AnCova
0334 %-Basically, if 'GMsca'ling then should centre to GM (iGC=11). Otherwise,
0335 % should centre in similar fashion to AnCova (i.e. by the same factor(s)),
0336 % such that models are seperable (iGC=10). This is particularly important
0337 % for subject specific condition effects if then passed on to a second-level
0338 % model. (See also spm_adjmean_ui.m) SPM96 (& earlier) used to just centre
0339 % GX around its (overall) mean (iGC=1).
0340 
0341 %-This code allows more general options to be specified (but is a bit complex)
0342 %-Setting D.iGC=[-10,-11] gives the standard choices above
0343 
0344 %-If not doing AnCova then GC is irrelevant
0345 if ~any(iGloNorm==[1:7])
0346     iGC = 12;
0347     gc  = [];
0348 else
0349     %-Annotate options 10 & 11 with specific details
0350     %---------------------------------------------------------------
0351     %-Tag '(as implied by AnCova)' with actual AnCova situation
0352     sCC{10} = [sCC{iGloNorm},' (<= ',sGloNorm,')'];
0353     %-Tag 'GM' case with actual GM & GMsca case
0354     sCC{11} = sprintf('around GM=%g (i.e. %s after grand mean scaling)',...
0355         GM,strrep(sCC{iGMsca},'around ',''));
0356 
0357     %-Constuct vector of allowable iGC
0358     %---------------------------------------------------------------
0359     %-Weed out redundent factor combinations from pre-set allowable options
0360     iGC = intersect(abs(D.iGC),find([1,bFI,1,1,1,1]));
0361     %-Omit 'GM' option if didn't GMsca (iGMsca~=8 'cos doing AnCova)
0362     if any(iGMsca==[8,9]), iGC = setdiff(iGC,11); end
0363     %-Omit 'GM' option if same as '(as implied by AnCova)'
0364     if iGloNorm==iGMsca, iGC = setdiff(iGC,11); end
0365 
0366     %-If there's a choice, set defaults (if any), & get answer
0367     %---------------------------------------------------------------
0368     if length(iGC)>1
0369         dGC = max([0,intersect(iGC,-D.iGC(D.iGC<0))]);
0370         str = 'Centre global covariate';
0371         if iGMsca<8, str = [str,' (after grand mean scaling)']; end
0372         iGC = spm_input(str,'+1','m',sCC(iGC),iGC,find(iGC==dGC));
0373     elseif isempty(iGC)
0374         error('Configuration error: empty iGC')
0375     end
0376 
0377     %-If 'user specified' then get value
0378     %---------------------------------------------------------------
0379     if iGC==9
0380         gc     = spm_input('Centre globals around','+0','r',D.GM,1);
0381         sCC{9} = sprintf('%s of %g',sCC{iGC},gc);
0382     else
0383         gc  = 0;
0384     end
0385 end
0386 
0387 
0388 %-Thresholds & masks defining voxels to analyse                   (MASK)
0389 %=======================================================================
0390 GUIpos = spm_input('!NextPos');
0391 
0392 %-Analysis threshold mask
0393 %-----------------------------------------------------------------------
0394 %-Work out available options:
0395 % -Inf=>None, complex=>proportional, real=>absolute (i.e. times global)
0396 M_T = D.M_.T; if isempty(M_T), M_T = [-Inf, 100, 0.8*sqrt(-1)]; end
0397 M_T = {    'none',        M_T(min(find(isinf(M_T))));...
0398     'absolute',    M_T(min(find(isfinite(M_T)&(M_T==real(M_T)))));...
0399     'prop''nal',    M_T(min(find(isfinite(M_T)&(M_T~=real(M_T)))))    };
0400 
0401 %-Work out available options
0402 %-If there's a choice between proportional and absolute then ask
0403 %-----------------------------------------------------------------------
0404 q = ~[isempty(M_T{1,2}), isempty(M_T{2,2}), isempty(M_T{3,2})];
0405 
0406 if all(q(2:3))
0407     tmp = spm_input('Threshold masking',GUIpos,'b',M_T(q,1),find(q));
0408     q(setdiff([1:3],tmp))=0;
0409 end
0410 
0411 %-Get mask value - note that at most one of q(2:3) is true
0412 %-----------------------------------------------------------------------
0413 if ~any(q)                %-Oops - nothing specified!
0414     M_T = -Inf;
0415 elseif all(q==[1,0,0])            %-no threshold masking
0416     M_T = -Inf;
0417 else                    %-get mask value
0418     if q(1),    args = {'br1','None',-Inf,abs(M_T{1+find(q(2:3)),2})};
0419     else,        args = {'r',abs(M_T{1+find(q(2:3)),2})}; end
0420     if q(2)
0421         M_T = spm_input('analysis threshold',GUIpos,args{:});
0422     elseif q(3)
0423         M_T = spm_input('analysis thresh  (prop''n of global)',GUIpos,...
0424                                 args{:});
0425         if isfinite(M_T) & isreal(M_T), M_T=M_T*sqrt(-1); end
0426     else
0427         error('Shouldn''t get here!')
0428     end
0429 end
0430 
0431 %-Make a description string
0432 %-----------------------------------------------------------------------
0433 if isinf(M_T)
0434     xsM.Analysis_threshold = 'None (-Inf)';
0435 elseif isreal(M_T)
0436     xsM.Analysis_threshold = sprintf('images thresholded at %6g',M_T);
0437 else
0438     xsM.Analysis_threshold = sprintf(['images thresholded at %6g ',...
0439         'times global'],imag(M_T));
0440 end
0441 
0442 
0443 %-Implicit masking: Ignore zero voxels in low data-types?
0444 %-----------------------------------------------------------------------
0445 % (Implicit mask is NaN in higher data-types.)
0446 type = mars_vol_utils('type', spm_vol(P{1,1}));
0447 if ~spm_type(type,'nanrep')
0448     switch D.M_.I
0449     case Inf,    M_I = spm_input('Implicit mask (ignore zero''s)?',...
0450             '+1','y/n',[1,0],1);        %-Ask
0451     case {0,1}, M_I = D.M_.I;            %-Pre-specified
0452     otherwise,  error('unrecognised D.M_.I type')
0453     end
0454 
0455     if M_I, xsM.Implicit_masking = 'Yes: zero''s treated as missing';
0456     else,   xsm.Implicit_masking = 'No'; end
0457 else
0458     M_I = 1;
0459     xsM.Implicit_masking = 'Yes: NaN''s treated as missing';
0460 end
0461 
0462 
0463 %-Explicit mask images (map them later...)
0464 %-----------------------------------------------------------------------
0465 switch(D.M_.X)
0466 case Inf,   M_X = spm_input('explicitly mask images?','+1','y/n',[1,0],2);
0467 case {0,1}, M_X = D.M_.X;
0468 otherwise,  error('unrecognised D.M_.X type')
0469 end
0470 if M_X, M_P = spm_get(Inf,img_flt,{'select mask images'}); else, M_P = {}; end
0471 
0472 
0473 %-Global calculation                                            (GXcalc)
0474 %=======================================================================
0475 iGXcalc = abs(D.iGXcalc);
0476 %-Only offer "omit" option if not doing any GloNorm, GMsca or PropTHRESH
0477 if ~(iGloNorm==9 & iGMsca==9 & (isinf(M_T)|isreal(M_T)))
0478     iGXcalc = intersect(iGXcalc,[2:size(sGXcalc,1)]);
0479 end
0480 if isempty(iGXcalc)
0481     error('no GXcalc options')
0482 elseif length(iGXcalc)>1
0483     %-User choice of global calculation options, default is negative
0484     dGXcalc = max([1,intersect(iGXcalc,-D.iGXcalc(D.iGXcalc<0))]);
0485     iGXcalc = spm_input('Global calculation','+1','m',...
0486             sGXcalc(iGXcalc),iGXcalc,find(iGXcalc==dGXcalc));
0487 else
0488     iGXcalc = abs(D.iGXcalc);
0489 end
0490 
0491 if iGXcalc==2                %-Get user specified globals
0492     g = spm_input('globals','+0','r',[],[nScan,nVar]);
0493 end
0494 sGXcalc = sGXcalc{iGXcalc};
0495 
0496 
0497 %=======================================================================
0498 % - C O N F I G U R E   D E S I G N
0499 %=======================================================================
0500 spm('FigName','Stats: configuring',Finter,CmdLine);
0501 spm('Pointer','Watch');
0502 
0503 
0504 %-Images & image info: Map Y image files and check consistency of
0505 % dimensions and orientation / voxel size
0506 %=======================================================================
0507 fprintf('%-40s: ','Mapping files')                                   %-#
0508 for  i = 1:nVar
0509     VY(:,i) = spm_vol(char(P{:,i}));
0510 end
0511 
0512 %-Check compatability of images
0513 %-----------------------------------------------------------------------
0514 [samef msg] = mars_vol_check(VY);
0515 if ~samef, disp(char(msg)),error('Cannot use images'),end;
0516 
0517 fprintf('%30s\n','...done')                                          %-#
0518 
0519 
0520 %-Global values, scaling and global normalisation
0521 %=======================================================================
0522 %-Compute global values
0523 %-----------------------------------------------------------------------
0524 switch iGXcalc, case 1
0525     %-Don't compute => no GMsca (iGMsca==9) or GloNorm (iGloNorm==9)
0526     g = [];
0527 case 2
0528     %-User specified globals
0529 case 3
0530     %-Compute as mean voxel value (within per image fullmean/8 mask)
0531     g = zeros(nScan,nVar);
0532     fprintf('%-40s: %30s','Calculating globals',' ')             %-#
0533     for i = 1:nScan
0534         for j = 1:nVar
0535             if nVar>1
0536                 str = sprintf('%3d(%02d)/%d(%d)',i,j,nScan,nVar);
0537             else
0538                 str = sprintf('%3d/%-3d',i,nScan);
0539             end
0540             fprintf('%s%30s',repmat(sprintf('\b'),1,30),str)%-#
0541             g(i,j) = spm_global(VY(i,j));
0542         end
0543     end
0544     fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done')       %-#
0545 otherwise
0546     error('illegal iGXcalc')
0547 end
0548 rg = g;
0549 
0550 
0551 fprintf('%-40s: ','Design configuration')                            %-#
0552 
0553 
0554 %-Scaling: compute global scaling factors gSF required to implement proportional
0555 % scaling global normalisation (PropSca) or grand mean scaling (GMsca),
0556 % as specified by iGMsca (& iGloNorm)
0557 %-----------------------------------------------------------------------
0558 switch iGMsca, case 8
0559     %-Proportional scaling global normalisation
0560     if iGloNorm~=8, error('iGloNorm-iGMsca(8) mismatch for PropSca'), end
0561     gSF    = GM./g;
0562     g      = GM*ones(nScan,nVar);
0563 case {1,2,3,4,5,6,7}
0564     %-Grand mean scaling according to iGMsca
0565     gSF    = GM./spm_meanby(g,eval(CCforms{iGMsca}));
0566     g      = g.*gSF;
0567 case 9
0568     %-No grand mean scaling
0569     gSF    = ones(nScan,nVar);
0570 otherwise
0571     error('illegal iGMsca')
0572 end
0573 
0574 
0575 %-Apply gSF to memory-mapped scalefactors to implement scaling
0576 %-----------------------------------------------------------------------
0577 for i=1:nScan
0578     for j = 1:nVar
0579         VY(i,j).pinfo(1:2,:) = VY(i,j).pinfo(1:2,:)*gSF(i,j);
0580     end
0581 end
0582 
0583 
0584 %-AnCova: Construct global nuisance covariates partition (if AnCova)
0585 %-----------------------------------------------------------------------
0586 if any(iGloNorm==[1:7])
0587 
0588     %-Centre global covariate as requested
0589     %---------------------------------------------------------------
0590     switch iGC, case {1,2,3,4,5,6,7}    %-Standard sCC options
0591         gc = spm_meanby(g,eval(CCforms{iGC}));
0592     case 8                    %-No centering
0593         gc = 0;
0594     case 9                    %-User specified centre
0595         %-gc set above
0596     case 10                    %-As implied by AnCova option
0597         gc = spm_meanby(g,eval(CCforms{iGloNorm}));
0598     case 11                    %-Around GM
0599         gc = GM;
0600     otherwise                %-unknown iGC
0601         error('unexpected iGC value')
0602     end
0603     
0604     for i = 1:nVar
0605     
0606         %-AnCova - add scaled centred global to DesMtx `G' partition
0607         %-------------------------------------------------------
0608         rcname='global'; if nVar>1, rcname=sprintf('global-%d',i); end
0609         tI         = [eval(CFIforms{iGloNorm,1}),g(:,i)-gc(:,i)];
0610         tConst     = CFIforms{iGloNorm,2};
0611         tFnames    = [eval(CFIforms{iGloNorm,3}),{rcname}];
0612         [f,gname]  = spm_DesMtx(tI,tConst,tFnames);
0613         clear tI tConst tFnames
0614     
0615         %-Save GX info in xC struct for reference
0616         str = {sprintf('%s: %s',dstr{2},rcname)};
0617         if any(iGMsca==[1:7]), str=[str;{['(after ',sGMsca,')']}]; end
0618         if iGC~=8, str=[str;{['used centered ',sCC{iGC}]}]; end
0619         if iGloNorm > 1
0620             str=[str;{['fitted as interaction ',sCFI{iGloNorm}]}]; 
0621         end
0622         tmp  = struct(    'rc',rg(:,i).*gSF(:,i),    'rcname',rcname,...
0623                 'c',f,            'cname'    ,{gname},...
0624                 'iCC',iGC,        'iCFI'    ,iGloNorm,...
0625                 'type',            3,...
0626                 'cols',[1:size(f,2)]+size([H C B G],2),...
0627                 'descrip',        {str}        );
0628     
0629         G = [G,f]; Gnames = [Gnames; gname];
0630         if isempty(xC), xC = tmp; else, xC = [xC,tmp]; end
0631         
0632     end
0633 
0634 elseif iGloNorm==8 | iGXcalc>1
0635 
0636     %-Globals calculated, but not AnCova: Make a note of globals
0637     %---------------------------------------------------------------
0638     if iGloNorm==8
0639         str = { 'global values: (used for proportional scaling)';...
0640             '("raw" unscaled globals shown)'};
0641     elseif isfinite(M_T) & ~isreal(M_T)
0642         str = { 'global values: (used to compute analysis threshold)'};
0643     else
0644         str = { 'global values: (computed but not used)'};
0645     end
0646 
0647     for i = 1:nVar
0648         rcname='global'; if nVar>1, rcname=sprintf('global-%d',i); end
0649         tmp  = struct(    'rc',rg(:,i),    'rcname',rcname,...
0650                 'c',{[]},    'cname'    ,{{}},...
0651                 'iCC',0,    'iCFI'    ,0,...
0652                 'type',        3,...
0653                 'cols',        {[]},...
0654                 'descrip',    {str}            );
0655         if isempty(xC), xC = tmp; else, xC = [xC,tmp]; end
0656     end
0657 end
0658 
0659 
0660 %-Save info on global calculation in xGX structure
0661 %-----------------------------------------------------------------------
0662 xGX = struct(...
0663     'iGXcalc',iGXcalc,    'sGXcalc',sGXcalc,    'rg',rg,...
0664     'iGMsca',iGMsca,    'sGMsca',sGMsca,    'GM',GM,'gSF',gSF,...
0665     'iGC',    iGC,        'sGC',    sCC{iGC},    'gc',    gc,...
0666     'iGloNorm',iGloNorm,    'sGloNorm',sGloNorm);
0667 
0668 
0669 
0670 %-Construct masking information structure and compute actual analysis
0671 % threshold using scaled globals (rg.*gSF)
0672 %-----------------------------------------------------------------------
0673 if isreal(M_T),    M_TH =      M_T  * ones(nScan,nVar);    %-NB: -Inf is real
0674 else,        M_TH = imag(M_T) * (rg.*gSF); end
0675 
0676 if ~isempty(M_P)
0677     VM = spm_vol(char(M_P));
0678     xsM.Explicit_masking = [{'Yes: mask images :'};{VM.fname}'];
0679 else
0680     VM=[];
0681     xsM.Explicit_masking = 'No';
0682 end
0683 xM = struct('T',M_T, 'TH',M_TH, 'I',M_I, 'VM',{VM}, 'xs',xsM);
0684 
0685 
0686 
0687 %-Construct full design matrix (X), parameter names (Xnames),
0688 % and design information structure (xX)
0689 %=======================================================================
0690 X      = [H C B G];
0691 Xnames = [Hnames; Cnames; Bnames; Gnames];
0692 tmp    = cumsum([size(H,2), size(C,2), size(B,2), size(G,2)]);
0693 xX     = struct(    'I',        I,...
0694             'sF',        {D.sF},...
0695             'X',        X,...
0696             'sigma',    0,...
0697             'iH',        [1:size(H,2)],...
0698             'iC',        [1:size(C,2)] + tmp(1),...
0699             'iB',        [1:size(B,2)] + tmp(2),...
0700             'iG',        [1:size(G,2)] + tmp(3),...
0701             'Xnames',    {Xnames});
0702 
0703 
0704 
0705 %-Pre-specified contrast for F-test on effects of interest
0706 %=======================================================================
0707 if ~isempty([H,C])
0708     %-Some effects designated "of interest"
0709     F_iX0 = (size(H,2)+size(C,2)) + [1:size(B,2)+size(G,2)];
0710 else
0711     %-No effects designated "of interest" - F-test for B=0
0712     F_iX0 = [];
0713 end
0714 
0715 
0716 %-Design description (an nx2 cellstr) - for saving and display
0717 %=======================================================================
0718 tmp = {    sprintf('%d condition, +%d covariate, +%d block, +%d nuisance',...
0719         size(H,2),size(C,2),size(B,2),size(G,2));...
0720     sprintf('%d total, having %d degrees of freedom',...
0721         size(X,2),rank(X));...
0722     sprintf('leaving %d degrees of freedom from %d images',...
0723         size(X,1)-rank(X),size(X,1))                };
0724 xsDes = struct(    'Design',            {D.DesName},...
0725         'Global_calculation',        {sGXcalc},...
0726         'Grand_mean_scaling',        {sGMsca},...
0727         'Global_normalisation',        {sGloNorm},...
0728         'Parameters',            {tmp}            );
0729 
0730 
0731 fprintf('%30s\n','...done')                                          %-#
0732 
0733 SPM = struct('xX',    xX,...
0734          'VY',    VY,...
0735          'xM',    xM,...
0736          'F_iX0', F_iX0,...
0737          'xC',    xC,...
0738          'xsDes', xsDes,...
0739          'SPMid', SPMid,...
0740          'cfg',   'SPMcfg');
0741 varargout = {SPM};
0742 
0743 %-End
0744 %=======================================================================
0745 spm('Pointer','Arrow')
0746 fprintf('%-40s: %30s\n','Completed',spm('time'))                     %-#
0747 fprintf('\n\n')
0748 
0749 case 'files&indices'
0750 %=======================================================================
0751 % - Get files and factor indices
0752 %=======================================================================
0753 % [P,I] = pr_spm_ui('Files&Indices',DsF,Dn,DbaTime,nV)
0754 % DbaTime=D.b.aTime; Dn=D.n; DsF=D.sF;
0755 if nargin<5, nV = 1; else, nV = varargin{5}; end
0756 if nargin<4, DbaTime = 1; else, DbaTime = varargin{4}; end
0757 if nargin<3, Dn  = [Inf,Inf,Inf,Inf]; else, Dn=varargin{3}; end
0758 if nargin<2, DsF = {'Fac1','Fac2','Fac3','Fac4'}; else, DsF=varargin{2}; end
0759 
0760 %-Initialise variables
0761 %-----------------------------------------------------------------------
0762 i4 = [];        % factor 4 index (usually group)
0763 i3 = [];        % factor 3 index (usually subject), per f4
0764 i2 = [];        % factor 2 index (usually condition), per f3/f4
0765 i1 = [];        % factor 1 index (usually replication), per f2/f3/f4
0766 P  = {};        % cell array of string filenames
0767 
0768 %-Accrue filenames and factor level indicator vectors
0769 %-----------------------------------------------------------------------
0770 bMV = nV>1;
0771 if isinf(Dn(4)), n4 = spm_input(['#',DsF{4},'''s'],'+1','n1');
0772     else, n4 = Dn(4); end
0773 bL4 = n4>1;
0774 
0775 ti2 = '';
0776 GUIpos = spm_input('!NextPos');
0777 for j4  = 1:n4
0778     spm_input('!SetNextPos',GUIpos);
0779     sF4P=''; if bL4, sF4P=[DsF{4},' ',int2str(j4),': ']; end
0780     if isinf(Dn(3)), n3=spm_input([sF4P,'#',DsF{3},'''s'],'+1','n1');
0781         else, n3 = Dn(3); end
0782     bL3 = n3>1;
0783     
0784     if DbaTime & Dn(2)>1
0785     %disp('NB:selecting in time order - manually specify conditions')
0786     %-NB: This means f2 levels might not be 1:n2
0787     GUIpos2 = spm_input('!NextPos');
0788     for j3 = 1:n3
0789         sF3P=''; if bL3, sF3P=[DsF{3},' ',int2str(j3),': ']; end
0790         str = [sF4P,sF3P];
0791         tP  = {};
0792         n21 = Dn(2)*Dn(1);
0793         for v=1:nV
0794             vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
0795             ttP = spm_get(n21,img_flt,{[str,'select images',vstr]});
0796             n21 = length(ttP);
0797             tP  = [tP,ttP];
0798         end
0799         ti2 = spm_input([str,' ',DsF{2},'?'],GUIpos2,'c',ti2',n21,Dn(2));
0800         %-Work out i1 & check
0801         [tl2,null,j] = unique(ti2);
0802         tn1 = zeros(size(tl2)); ti1 = zeros(size(ti2));
0803         for i=1:length(tl2)
0804             tn1(i)=sum(j==i); ti1(ti2==tl2(i))=1:tn1(i); end
0805         if isfinite(Dn(1)) & any(tn1~=Dn(1))
0806         %-#i1 levels mismatches specification in Dn(1)
0807         error(sprintf('#%s not %d as pre-specified',DsF{1},Dn(1)))
0808         end
0809         P  = [P;tP];
0810         i4 = [i4; j4*ones(n21,1)];
0811         i3 = [i3; j3*ones(n21,1)];
0812         i2 = [i2; ti2];
0813         i1 = [i1; ti1];
0814     end
0815 
0816     else
0817 
0818     if isinf(Dn(2))
0819         n2 = spm_input([sF4P,'#',DsF{2},'''s'],'+1','n1');
0820     else
0821         n2 = Dn(2);
0822     end
0823     bL2 = n2>1;
0824 
0825     if n2==1 & Dn(1)==1 %-single scan per f3 (subj)
0826         %disp('NB:single scan per f3')
0827         str = [sF4P,'select images, ',DsF{3},' 1-',int2str(n3)];
0828         tP = {};
0829         for v=1:nV
0830             vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
0831             ttP = spm_get(n3,img_flt,{[str,vstr]});
0832             tP = [tP,ttP];
0833         end
0834         P   = [P;tP];
0835         i4  = [i4; j4*ones(n3,1)];
0836         i3  = [i3; [1:n3]'];
0837         i2  = [i2; ones(n3,1)];
0838         i1  = [i1; ones(n3,1)];
0839     else
0840         %-multi scan per f3 (subj) case
0841         %disp('NB:multi scan per f3')
0842         for j3 = 1:n3
0843         sF3P=''; if bL3, sF3P=[DsF{3},' ',int2str(j3),': ']; end
0844         if Dn(1)==1
0845             %-No f1 (repl) within f2 (cond)
0846             %disp('NB:no f1 within f2')
0847             str = [sF4P,sF3P,'select images: ',DsF{2},...
0848                  ' 1-',int2str(n2)];
0849             tP = {};
0850             for v=1:nV
0851                 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
0852                 ttP = spm_get(n2,img_flt,{[str,vstr]});
0853                 tP = [tP,ttP];
0854             end
0855             P   = [P;tP];
0856             i4  = [i4; j4*ones(n2,1)];
0857             i3  = [i3; j3*ones(n2,1)];
0858             i2  = [i2; [1:n2]'];
0859             i1  = [i1; ones(n2,1)];
0860         else
0861             %-multi f1 (repl) within f2 (cond)
0862             %disp('NB:f1 within f2')
0863             for j2  = 1:n2
0864             sF2P='';
0865             if bL2, sF2P=[DsF{2},' ',int2str(j2),': ']; end
0866             str = [sF4P,sF3P,sF2P,' select images...'];
0867             tP  = {};
0868             n1  = Dn(1);
0869             for v=1:nV
0870                 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
0871                 ttP = spm_get(n1,img_flt,{[str,vstr]});
0872                 n1  = length(ttP);
0873                 tP  = [tP,ttP];
0874             end
0875             P   = [P;tP];
0876             i4  = [i4; j4*ones(n1,1)];
0877             i3  = [i3; j3*ones(n1,1)];
0878             i2  = [i2; j2*ones(n1,1)];
0879             i1  = [i1; [1:n1]'];
0880             end                         % (for j2)
0881         end                             % (if Dn(1)==1)
0882         end                                 % (for j3)
0883     end                                     % (if  n2==1 &...)
0884     end                                         % (if DbaTime & Dn(2)>1)
0885 end                                             % (for j4)
0886 varargout = {P,[i1,i2,i3,i4]};
0887 
0888 
0889 case 'desdefs_stats'
0890 %=======================================================================
0891 % - Basic Stats Design definitions...
0892 %=======================================================================
0893 % D = pr_spm_ui('DesDefs_Stats');
0894 % These are the basic Stats design definitions...
0895 
0896 %-Note: struct expands cell array values to give multiple records:
0897 %       => must embed cell arrays within another cell array!
0898 %-Negative indices indicate defaults (first used)
0899 
0900 D = struct(...
0901     'DesName','One sample t-test',...
0902     'n',    [Inf 1 1 1],    'sF',{{'obs','','',''}},...
0903     'Hform',        'I(:,2),''-'',''mean''',...
0904     'Bform',        '[]',...
0905     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0906     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0907     'iGloNorm',9,'iGC',12,...
0908     'M_',struct('T',-Inf,'I',Inf,'X',Inf),...
0909     'b',struct('aTime',0));
0910 
0911 D = [D, struct(...
0912     'DesName','Two sample t-test',...
0913     'n',    [Inf 2 1 1],    'sF',{{'obs','group','',''}},...
0914     'Hform',        'I(:,2),''-'',''group''',...
0915     'Bform',        'I(:,3),''-'',''\mu''',...
0916     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0917     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0918     'iGloNorm',9,'iGC',12,...
0919     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0920     'b',struct('aTime',1))];
0921 
0922 D = [D, struct(...
0923     'DesName','Paired t-test',...
0924     'n',    [1 2 Inf 1],    'sF',{{'','cond','pair',''}},...
0925     'Hform',        'I(:,2),''-'',''condition''',...
0926     'Bform',        'I(:,3),''-'',''\gamma''',...
0927     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0928     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0929     'iGloNorm',9,'iGC',12,...
0930     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0931     'b',struct('aTime',0))];
0932 
0933 D = [D, struct(...
0934     'DesName','One way Anova',...
0935     'n',    [Inf Inf 1 1],    'sF',{{'repl','group','',''}},...
0936     'Hform',        'I(:,2),''-'',''group''',...
0937     'Bform',        'I(:,3),''-'',''\mu''',...
0938     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0939     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0940     'iGloNorm',9,'iGC',12,...
0941     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0942     'b',struct('aTime',0))];
0943 
0944 D = [D, struct(...
0945     'DesName','Simple regression (correlation)',...
0946     'n',    [Inf 1 1 1],    'sF',{{'repl','','',''}},...
0947     'Hform',        '[]',...
0948     'Bform',        'I(:,2),''-'',''\mu''',...
0949     'nC',[1,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0950     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0951     'iGloNorm',9,'iGC',12,...
0952     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0953     'b',struct('aTime',0))];
0954 
0955 D = [D, struct(...
0956     'DesName','Multiple regression',...
0957     'n',    [Inf 1 1 1],    'sF',{{'repl','','',''}},...
0958     'Hform',        '[]',...
0959     'Bform',        'I(:,2),''-'',''\mu''',...
0960     'nC',[Inf,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
0961     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0962     'iGloNorm',9,'iGC',12,...
0963     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0964     'b',struct('aTime',0))];
0965 
0966 D = [D, struct(...
0967     'DesName','AnCova',...
0968     'n',    [Inf Inf 1 1],    'sF',{{'repl','group','',''}},...
0969     'Hform',        'I(:,2),''-'',''group''',...
0970     'Bform',        'I(:,3),''-'',''\mu''',...
0971     'nC',[0,1],'iCC',{{8,1}},'iCFI',{{1,1}},...
0972     'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
0973     'iGloNorm',9,'iGC',12,...
0974     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
0975     'b',struct('aTime',0))];
0976 
0977 varargout = {D};
0978 
0979 
0980 case 'desdefs_pet'
0981 %=======================================================================
0982 % - Standard (SPM99) PET/SPECT Design definitions...
0983 %=======================================================================
0984 % D = pr_spm_ui('DesDefs_PET');
0985 % These are the standard PET design definitions...
0986 
0987 %-Single subject
0988 %-----------------------------------------------------------------------
0989 D = struct(...
0990     'DesName','Single-subject: conditions & covariates',...
0991     'n',    [Inf Inf 1 1],    'sF',{{'repl','condition','',''}},...
0992     'Hform',        'I(:,2),''-'',''cond''',...
0993     'Bform',        'I(:,3),''-'',''\mu''',...
0994     'nC',[Inf,Inf],'iCC',{{[-1,3,8],[-1,8]}},'iCFI',{{[1,3],1}},...
0995     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
0996     'iGloNorm',[1,8,9],'iGC',10,...
0997     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
0998     'b',struct('aTime',1));
0999 
1000 D = [D, struct(...
1001     'DesName','Single-subject: covariates only',...
1002     'n',    [Inf 1 1 1],    'sF',{{'repl','','',''}},...
1003     'Hform',        '[]',...
1004     'Bform',        'I(:,3),''-'',''\mu''',...
1005     'nC',[Inf,Inf],'iCC',{{[-1,8],[-1,8]}},'iCFI',{{1,1}},...
1006     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
1007     'iGloNorm',[1,8,9],'iGC',10,...
1008     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1009     'b',struct('aTime',1))];
1010 
1011 %-Multi-subject
1012 %-----------------------------------------------------------------------
1013 D = [D, struct(...
1014     'DesName','Multi-subj: conditions & covariates',...
1015     'n',[Inf Inf Inf 1],    'sF',{{'repl','condition','subject',''}},...
1016     'Hform',        'I(:,2),''-'',''cond''',...
1017     'Bform',        'I(:,3),''-'',''subj''',...
1018     'nC',[Inf,Inf],'iCC',{{[1,3,4,8],[1,4,8]}},'iCFI',{{[1,3,-4],[1,-4]}},...
1019     'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
1020     'iGloNorm',[4,8,9],'iGC',10,...
1021     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1022     'b',struct('aTime',1))];
1023 
1024 D = [D, struct(...
1025     'DesName','Multi-subj: cond x subj  interaction & covariates',...
1026     'n',[Inf Inf Inf 1],    'sF',{{'repl','condition','subject',''}},...
1027     'Hform',        'I(:,[3,2]),''-'',{''subj'',''cond''}',...
1028     'Bform',        'I(:,3),''-'',''subj''',...
1029     'nC',[Inf,Inf],'iCC',{{[1,3,4,8],[1,4,8]}},'iCFI',{{[1,3,-4],[1,-4]}},...
1030     'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
1031     'iGloNorm',[4,8,9],'iGC',10,...
1032     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1033     'b',struct('aTime',1))];
1034 
1035 D = [D, struct(...
1036     'DesName','Multi-subj: covariates only',...
1037     'n',[Inf 1 Inf 1],    'sF',{{'repl','','subject',''}},...
1038     'Hform',        '[]',...
1039     'Bform',        'I(:,3),''-'',''subj''',...
1040     'nC',[Inf,Inf],'iCC',{{[1,4,8],[1,4,8]}},'iCFI',{{[1,-4],[1,-4]}},...
1041     'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
1042     'iGloNorm',[4,8:9],'iGC',10,...
1043     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1044     'b',struct('aTime',0))];
1045 
1046 %-Multi-group
1047 %-----------------------------------------------------------------------
1048 D = [D, struct(...
1049     'DesName','Multi-group: conditions & covariates',...
1050     'n',[Inf Inf Inf Inf],    'sF',{{'repl','condition','subject','group'}},...
1051     'Hform',        'I(:,[4,2]),''-'',{''stud'',''cond''}',...
1052     'Bform',        'I(:,[4,3]),''-'',{''stud'',''subj''}',...
1053     'nC',[Inf,Inf],'iCC',{{[5:8],[5,7,8]}},'iCFI',{{[1,5,6,-7],[1,5,-7]}},...
1054     'iGXcalc',[1,2,-3],'iGMsca',[-7,9],'GM',50,...
1055     'iGloNorm',[7,8,9],'iGC',10,...
1056     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1057     'b',struct('aTime',1))];
1058 
1059 D = [D, struct(...
1060     'DesName','Multi-group: covariates only',...
1061     'n',[Inf 1 Inf Inf],    'sF',{{'repl','','subject','group'}},...
1062     'Hform',        '[]',...
1063     'Bform',        'I(:,[4,3]),''-'',{''stud'',''subj''}',...
1064     'nC',[Inf,Inf],'iCC',{{[5,7,8],[5,7,8]}},'iCFI',{{[1,5,-7],[1,5,-7]}},...
1065     'iGXcalc',[1,2,-3],'iGMsca',[-7,9],'GM',50,...
1066     'iGloNorm',[7,8,9],'iGC',10,...
1067     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1068     'b',struct('aTime',0))];
1069 
1070 %-Population comparisons
1071 %-----------------------------------------------------------------------
1072 D = [D, struct(...
1073     'DesName',...
1074     'Population main effect: 2 cond''s, 1 scan/cond (paired t-test)',...
1075     'n',[1 2 Inf 1],    'sF',{{'','condition','subject',''}},...
1076     'Hform',        'I(:,2),''-'',''cond''',...
1077     'Bform',        'I(:,3),''-'',''\mu''',...
1078     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1079     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
1080     'iGloNorm',[8,9],'iGC',10,...
1081     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1082     'b',struct('aTime',0))];
1083 
1084 D = [D, struct(...
1085     'DesName',...
1086     'Dodgy population main effect: >2 cond''s, 1 scan/cond',...
1087     'n',[1 Inf Inf 1],    'sF',{{'','condition','subject',''}},...
1088     'Hform',        'I(:,2),''-'',''cond''',...
1089     'Bform',        'I(:,3),''-'',''\mu''',...
1090     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1091     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
1092     'iGloNorm',[8,9],'iGC',10,...
1093     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1094     'b',struct('aTime',0))];
1095 
1096 D = [D, struct(...
1097     'DesName','Compare-populations: 1 scan/subject (two sample t-test)',...
1098     'n',[Inf 2 1 1],    'sF',{{'subject','group','',''}},...
1099     'Hform',        'I(:,2),''-'',''group''',...
1100     'Bform',        'I(:,3),''-'',''\mu''',...
1101     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1102     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
1103     'iGloNorm',[8,9],'iGC',10,...
1104     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1105     'b',struct('aTime',0))];
1106 
1107 D = [D, struct(...
1108     'DesName','Compare-populations: 1 scan/subject (AnCova)',...
1109     'n',[Inf 2 1 1],    'sF',{{'subject','group','',''}},...
1110     'Hform',        'I(:,2),''-'',''group''',...
1111     'Bform',        'I(:,3),''-'',''\mu''',...
1112     'nC',[0,Inf],'iCC',{{8,1}},'iCFI',{{1,1}},...
1113     'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
1114     'iGloNorm',[1,8,9],'iGC',10,...
1115     'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
1116     'b',struct('aTime',0))];
1117 
1118 %-The Full Monty!
1119 %-----------------------------------------------------------------------
1120 D = [D, struct(...
1121     'DesName','The Full Monty...',...
1122     'n',[Inf Inf Inf Inf],    'sF',{{'repl','cond','subj','group'}},...
1123     'Hform',        'I(:,[4,2]),''-'',{''stud'',''cond''}',...
1124     'Bform',        'I(:,[4,3]),''-'',{''stud'',''subj''}',...
1125     'nC',[Inf,Inf],'iCC',{{[1:8],[1:8]}},'iCFI',{{[1:7],[1:7]}},...
1126     'iGXcalc',[1,2,3],'iGMsca',[1:7],'GM',50,...
1127     'iGloNorm',[1:9],'iGC',[1:11],...
1128     'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
1129     'b',struct('aTime',1))];
1130 
1131 
1132 varargout = {D};
1133 
1134 case 'desdefs_pet96'
1135 %=======================================================================
1136 % - SPM96 PET/SPECT Design definitions...
1137 %=======================================================================
1138 % D = pr_spm_ui('DesDefs_PET96');
1139 
1140 %-Single subject
1141 %-----------------------------------------------------------------------
1142 D = struct(...
1143     'DesName','SPM96:Single-subject: replicated conditions',...
1144     'n',    [Inf Inf 1 1],    'sF',{{'repl','condition','',''}},...
1145     'Hform',        'I(:,2),''-'',''cond''',...
1146     'Bform',        'I(:,3),''-'',''\mu''',...
1147     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1148     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1149     'iGloNorm',[1,8,9],'iGC',10,...
1150     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1151     'b',struct('aTime',0));
1152 
1153 D = [D, struct(...
1154     'DesName','SPM96:Single-subject: replicated conditions & covariates',...
1155     'n',    [Inf Inf 1 1],    'sF',{{'repl','condition','',''}},...
1156     'Hform',        'I(:,2),''-'',''cond''',...
1157     'Bform',        'I(:,3),''-'',''\mu''',...
1158     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{1,1}},...
1159     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1160     'iGloNorm',[1,8,9],'iGC',10,...
1161     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1162     'b',struct('aTime',0))];
1163 
1164 D = [D, struct(...
1165     'DesName','SPM96:Single-subject: covariates only',...
1166     'n',    [Inf 1 1 1],    'sF',{{'repl','','',''}},...
1167     'Hform',        '[]',...
1168     'Bform',        'I(:,3),''-'',''\mu''',...
1169     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{1,1}},...
1170     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1171     'iGloNorm',[1,8,9],'iGC',10,...
1172     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1173     'b',struct('aTime',0))];
1174 
1175 %-Multi-subject
1176 %-----------------------------------------------------------------------
1177 D = [D, struct(...
1178     'DesName','SPM96:Multi-subject: different conditions',...
1179     'n',    [1 Inf Inf 1],    'sF',{{'','condition','subject',''}},...
1180     'Hform',        'I(:,2),''-'',''scancond''',...
1181     'Bform',        'I(:,3),''-'',''subj''',...
1182     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1183     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1184     'iGloNorm',[1,4,8,9],'iGC',10,...
1185     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1186     'b',struct('aTime',0))];
1187 
1188 D = [D, struct(...
1189     'DesName','SPM96:Multi-subject: replicated conditions',...
1190     'n',[Inf Inf Inf 1],    'sF',{{'repl','condition','subject',''}},...
1191     'Hform',        'I(:,2),''-'',''cond''',...
1192     'Bform',        'I(:,3),''-'',''subj''',...
1193     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1194     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1195     'iGloNorm',[1,4,8,9],'iGC',10,...
1196     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1197     'b',struct('aTime',0))];
1198 
1199 D = [D, struct(...
1200     'DesName','SPM96:Multi-subject: different conditions & covariates',...
1201     'n',    [1 Inf Inf 1],    'sF',{{'','condition','subject',''}},...
1202     'Hform',        'I(:,2),''-'',''cond''',...
1203     'Bform',        'I(:,3),''-'',''subj''',...
1204     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,4],[1,4]}},...
1205     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1206     'iGloNorm',[1,4,8,9],'iGC',10,...
1207     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1208     'b',struct('aTime',0))];
1209 
1210 D = [D, struct(...
1211     'DesName','SPM96:Multi-subject: replicated conditions & covariates',...
1212     'n',[Inf Inf Inf 1],    'sF',{{'repl','condition','subject',''}},...
1213     'Hform',        'I(:,2),''-'',''condition''',...
1214     'Bform',        'I(:,3),''-'',''subj''',...
1215     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,3,4],[1,4]}},...
1216     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1217     'iGloNorm',[1,4,8,9],'iGC',10,...
1218     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1219     'b',struct('aTime',0))];
1220 
1221 D = [D, struct(...
1222     'DesName','SPM96:Multi-subject: covariates only',...
1223     'n',[Inf 1 Inf 1],    'sF',{{'repl','','subject',''}},...
1224     'Hform',        '[]',...
1225     'Bform',        'I(:,3),''-'',''subj''',...
1226     'nC',[Inf,Inf],'iCC',{{[1,4,8],[1,4,8]}},'iCFI',{{[1,4],[1,4]}},...
1227     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1228     'iGloNorm',[1,4,8,9],'iGC',10,...
1229     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1230     'b',struct('aTime',0))];
1231 
1232 %-Multi-study
1233 %-----------------------------------------------------------------------
1234 D = [D, struct(...
1235     'DesName','SPM96:Multi-study: different conditions',...
1236     'n',[1 Inf Inf Inf],    'sF',{{'','cond','subj','study'}},...
1237     'Hform',        'I(:,[4,2]),''-'',{''study'',''cond''}',...
1238     'Bform',        'I(:,[4,3]),''-'',{''study'',''subj''}',...
1239     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1240     'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
1241     'iGloNorm',[1,5,7,8,9],'iGC',10,...
1242     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1243     'b',struct('aTime',0))];
1244 
1245 D = [D, struct(...
1246     'DesName','SPM96:Multi-study: replicated conditions',...
1247     'n',[Inf Inf Inf Inf],    'sF',{{'repl','cond','subj','study'}},...
1248     'Hform',        'I(:,[4,2]),''-'',{''study'',''condition''}',...
1249     'Bform',        'I(:,[4,3]),''-'',{''study'',''subj''}',...
1250     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1251     'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
1252     'iGloNorm',[1,5,7,8,9],'iGC',10,...
1253     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1254     'b',struct('aTime',0))];
1255 
1256 D = [D, struct(...
1257     'DesName','SPM96:Multi-study: different conditions & covariates',...
1258     'n',[1 Inf Inf Inf],    'sF',{{'','cond','subj','study'}},...
1259     'Hform',        'I(:,[4,2]),''-'',{''study'',''cond''}',...
1260     'Bform',        'I(:,[4,3]),''-'',{''study'',''subj''}',...
1261     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,6,7],[1,5,7]}},...
1262     'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
1263     'iGloNorm',[1,5,7,8,9],'iGC',10,...
1264     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1265     'b',struct('aTime',0))];
1266 
1267 D = [D, struct(...
1268     'DesName','SPM96:Multi-study: replicated conditions & covariates',...
1269     'n',[Inf Inf Inf Inf],    'sF',{{'','cond','subj','study'}},...
1270     'Hform',        'I(:,[4,2]),''-'',{''study'',''condition''}',...
1271     'Bform',        'I(:,[4,3]),''-'',{''study'',''subj''}',...
1272     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,6,7],[1,5,7]}},...
1273     'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
1274     'iGloNorm',[1,5,7,8,9],'iGC',10,...
1275     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1276     'b',struct('aTime',0))];
1277 
1278 D = [D, struct(...
1279     'DesName','SPM96:Multi-study: covariates only',...
1280     'n',[Inf 1 Inf Inf],    'sF',{{'repl','','subj','study'}},...
1281     'Hform',        '[]',...
1282     'Bform',        'I(:,[4,3]),''-'',{''study'',''subj''}',...
1283     'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,7],[1,5,7]}},...
1284     'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
1285     'iGloNorm',[1,5,7,8,9],'iGC',10,...
1286     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1287     'b',struct('aTime',0))];
1288 
1289 %-Group comparisons
1290 %-----------------------------------------------------------------------
1291 D = [D, struct(...
1292     'DesName','SPM96:Compare-groups: 1 scan per subject',...
1293     'n',[Inf Inf 1 1],    'sF',{{'subject','group','',''}},...
1294     'Hform',        'I(:,2),''-'',''group''',...
1295     'Bform',        '[]',...
1296     'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1297     'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
1298     'iGloNorm',[1,8,9],'iGC',10,...
1299     'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
1300     'b',struct('aTime',0))];
1301 
1302 varargout = {D};
1303 
1304 
1305 otherwise
1306 %=======================================================================
1307 % - U N K N O W N   A C T I O N
1308 %=======================================================================
1309 warning(['Illegal Action string: ',Action])
1310 
1311 
1312 %=======================================================================
1313 % - E N D
1314 %=======================================================================
1315 end
1316 
1317 
1318 
1319 
1320 %=======================================================================
1321 %- S U B - F U N C T I O N S
1322 %=======================================================================
1323 
1324 function str = sf_estrrep(str,srstr)
1325 %=======================================================================
1326 for i = 1:size(srstr,1)
1327     str = strrep(str,srstr{i,1},srstr{i,2});
1328 end
1329 return

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019