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

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