Home > marsbar > @mardo_5 > 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:
 $Id: spm_spm_ui.m 372 2005-12-08 17:12:13Z karl $
 See that (SPM5) file for comments and help

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

Generated on Thu 17-Mar-2016 01:14:46 by m2html © 2005