Attachment 'cbu_csv5_ui.m'
Download 1 function varargout = cbu_csv5_ui(varargin)
2 %
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 % cbuhacked version - Ian Nimmo-Smith, 3-11 June 1999
5 %
6 % v0.2 handling blank lines - thanks to Joe Devlin
7 % v0.3 now runs under its own name so no conflict with
8 % spm_spm_ui.m in standard distribution
9 SCCSid = '0.3';
10 %
11 % adapted for SPM5 August 2006
12 %
13 % [1] design and filename entry from a .csv file [done]
14 % [2] saving design and filename details in design.csv [done]
15 % [3] inputting covariate values from the .csv file [done]
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 % Setting up the general linear model for independent data
19 % FORMATs (given in Programmers Help)
20 %_______________________________________________________________________
21 %
22 % spm_spm_ui.m configures the design matrix (describing the general
23 % linear model), data specification, and other parameters necessary for
24 % the statistical analysis. These parameters are saved in a
25 % configuration file (SPM.mat) in the current directory, and are
26 % passed on to spm_spm.m which estimates the design. Inference on these
27 % estimated parameters is then handled by the SPM results section.
28 %
29 % A separate program (spm_spm_fmri_ui.m) handles design configuration
30 % for fMRI time series, though this program can be used for fMRI data
31 % when observations can be regarded as independent.
32 %
33 % ----------------------------------------------------------------------
34 %
35 % Various data and parameters need to be supplied to specify the design:
36 % * the image files
37 % * indicators of the corresponding condition/subject/group
38 % * any covariates, nuisance variables, or design matrix partitions
39 % * the type of global normalisation (if any)
40 % * grand mean scaling options
41 % * thresholds and masks defining the image volume to analyse
42 %
43 % The interface supports a comprehensive range of options for all these
44 % parameters, which are described below in the order in which the
45 % information is requested. Rather than ask for all these parameters,
46 % spm_spm_ui.m uses a "Design Definition", a structure describing the
47 % options and defaults appropriate for a particular analysis. Thus,
48 % once the user has chosen a design, a subset of the following prompts
49 % will be presented.
50 %
51 % If the pre-specified design definitions don't quite have the combination
52 % of options you want, you can pass a custom design structure D to be used
53 % as parameter: spm_spm_ui('cfg',D). The format of the design structure
54 % and option definitions are given in the programmers help, at the top of
55 % the main body of the code.
56 %
57 % ----------------
58 %
59 % Design class & Design type
60 % ==========================
61 %
62 % Unless a design definition is passed to spm_spm_ui.m as a parameter,
63 % the user is prompted first to select a design class, and then to
64 % select a design type from that class.
65 %
66 % The designs are split into three classes:
67 % i) Basic stats: basic models for simple statistics
68 % These specify designs suitable for simple voxel-by-voxel analyses.
69 % - one-sample t-test
70 % - two-sample t-test
71 % - paired t-test
72 % - one way Anova
73 % - one way Anova (with constant)
74 % - one way Anova (within subject)
75 % - simple regression (equivalent to correlation)
76 % - multiple regression
77 % - multiple regression (with constant)
78 % - basic AnCova (ANalysis of COVAriance)
79 % (essentially a two-sample t-test with a nuisance covariate)
80 %
81 % ii) PET models: models suitable for analysis of PET/SPECT experiments
82 % - Single-subject: conditions & covariates
83 % - Single-subject: covariates only
84 %
85 % - Multi-subj: conditions & covariates
86 % - Multi-subj: cond x subj interaction & covariates
87 % - Multi-subj: covariates only
88 % - Multi-group: conditions & covariates
89 % - Multi-group: covariates only
90 %
91 % - Population main effect: 2 cond's, 1 scan/cond (paired t-test)
92 % - Dodgy population main effect: >2 cond's, 1 scan/cond
93 % - Compare-populations: 1 scan/subject (two sample t-test)
94 % - Compare-populations: 1 scan/subject (AnCova)
95 %
96 % - The Full Monty... (asks you everything!)
97 %
98 % iii) SPM96 PET models: models used in SPM96 for PET/SPECT
99 % These models are provided for backward compatibility, but as they
100 % don't include some of the advanced modelling features, we recommend
101 % you switch to the new (SPM99) models at the earliest opportunity.
102 % - SPM96:Single-subject: replicated conditions
103 % - SPM96:Single-subject: replicated conditions & covariates
104 % - SPM96:Single-subject: covariates only
105 % - SPM96:Multi-subject: different conditions
106 % - SPM96:Multi-subject: replicated conditions
107 % - SPM96:Multi-subject: different conditions & covariates
108 % - SPM96:Multi-subject: replicated conditions & covariates
109 % - SPM96:Multi-subject: covariates only
110 % - SPM96:Multi-group: different conditions
111 % - SPM96:Multi-group: replicated conditions
112 % - SPM96:Multi-group: different conditions & covariates
113 % - SPM96:Multi-group: replicated conditions & covariates
114 % - SPM96:Multi-group: covariates only
115 % - SPM96:Compare-groups: 1 scan per subject
116 %
117 %
118 % Random effects, generalisability, population inference...
119 % =========================================================
120 %
121 % Note that SPM only considers a single component of variance, the
122 % residual error variance. When there are repeated measures, all
123 % analyses with SPM are fixed effects analyses, and inference only
124 % extends to the particular subjects under consideration (at the times
125 % they were imaged).
126 %
127 % In particular, the multi-subject and multi-group designs ignore the
128 % variability in response from subject to subject. Since the
129 % scan-to-scan (within-condition, within-subject variability is much
130 % smaller than the between subject variance which is ignored), this can
131 % lead to detection of group effects that are not representative of the
132 % population(s) from which the subjects are drawn. This is particularly
133 % serious for multi-group designs comparing two groups. If inference
134 % regarding the population is required, a random effects analysis is
135 % required.
136 %
137 % However, random effects analyses can be effected by appropriately
138 % summarising the data, thereby collapsing the model such that the
139 % residual variance for the new model contains precisely the variance
140 % components needed for a random effects analysis. In many cases, the
141 % fixed effects models here can be used as the first stage in such a
142 % two-stage procedure to produce appropriate summary data, which can
143 % then be used as raw data for a second-level analysis. For instance,
144 % the "Multi-subj: cond x subj interaction & covariates" design can be
145 % used to write out an image of the activation for each subject. A
146 % simple t-test on these activation images then turns out to be
147 % equivalent to a mixed-effects analysis with random subject and
148 % subject by condition interaction effects, inferring for the
149 % population based on this sample of subjects (strictly speaking the
150 % design would have to be balanced, with equal numbers of scans per
151 % condition per subject, and also only two conditions per subject). For
152 % additional details, see spm_RandFX.man.
153 %
154 % ----------------
155 %
156 % Selecting image files & indicating conditions
157 % =============================================
158 %
159 % You may now be prompted to specify how many studies, subjects and
160 % conditions you have, and then will be promted to select the scans.
161 %
162 % The data should all have the same orientation and image and voxel size.
163 %
164 % File selection is handled by spm_select.m - the help for which describes
165 % efficient use of the interface.
166 %
167 % You may be asked to indicate the conditions for a set of scans, with
168 % a prompt like "[12] Enter conditions? (2)". For this particular
169 % example you need to indicate for 12 scans the corresponding
170 % condition, in this case from 2 conditions. Enter a vector of
171 % indicators, like '0 1 0 1...', or a string of indicators, like
172 % '010101010101' or '121212121212', or 'rararararara'. (This
173 % "conditions" input is handled by spm_input.m, where comprehensive
174 % help can be found.)
175 %
176 % ----------------
177 %
178 % Covariate & nuisance variable entry
179 % ===================================
180 %
181 % * If applicable, you'll be asked to specify covariates and nuisance
182 % variables. Unlike SPM94/5/6, where the design was partitioned into
183 % effects of interest and nuisance effects for the computation of
184 % adjusted data and the F-statistic (which was used to thresh out
185 % voxels where there appeared to be no effects of interest), SPM99 does
186 % not partition the design in this way. The only remaining distinction
187 % between effects of interest (including covariates) and nuisance
188 % effects is their location in the design matrix, which we have
189 % retained for continuity. Pre-specified design matrix partitions can
190 % be entered. (The number of covariates / nuisance variables specified,
191 % is actually the number of times you are prompted for entry, not the
192 % number of resulting design matrix columns.) You will be given the
193 % opportunity to name the covariate.
194 %
195 % * Factor by covariate interactions: For covariate vectors, you may be
196 % offered a choice of interaction options. (This was called "covariate
197 % specific fits" in SPM95/6.) The full list of possible options is:
198 % - <none>
199 % - with replication
200 % - with condition (across group)
201 % - with subject (across group)
202 % - with group
203 % - with condition (within group)
204 % - with subject (within group)
205 %
206 % * Covariate centering: At this stage may also be offered "covariate
207 % centering" options. The default is usually that appropriate for the
208 % interaction chosen, and ensures that main effects of the interacting
209 % factor aren't affected by the covariate. You are advised to choose
210 % the default, unless you have other modelling considerations. The full
211 % list of possible options is:
212 % - around overall mean
213 % - around replication means
214 % - around condition means (across group)
215 % - around subject means (across group)
216 % - around group means
217 % - around condition means (within group)
218 % - around subject means (within group)
219 % - <no centering>
220 %
221 % ----------------
222 %
223 % Global options
224 % ==============
225 %
226 % Depending on the design configuration, you may be offered a selection
227 % of global normalisation and scaling options:
228 %
229 % * Method of global flow calculation
230 % - SPM96:Compare-groups: 1 scan per subject
231 % - None (assumming no other options requiring the global value chosen)
232 % - User defined (enter your own vector of global values)
233 % - SPM standard: mean voxel value (within per image fullmean/8 mask)
234 %
235 % * Grand mean scaling : Scaling of the overall grand mean simply
236 % scales all the data by a common factor such that the mean of all the
237 % global values is the value specified. For qualitative data, this puts
238 % the data into an intuitively accessible scale without altering the
239 % statistics. When proportional scaling global normalisation is used
240 % (see below), each image is seperately scaled such that it's global
241 % value is that specified (in which case the grand mean is also
242 % implicitly scaled to that value). When using AnCova or no global
243 % normalisation, with data from different subjects or sessions, an
244 % intermediate situation may be appropriate, and you may be given the
245 % option to scale group, session or subject grand means seperately. The
246 % full list of possible options is:
247 % - scaling of overall grand mean
248 % - caling of replication grand means
249 % - caling of condition grand means (across group)
250 % - caling of subject grand means (across group)
251 % - caling of group grand means
252 % - caling of condition (within group) grand means
253 % - caling of subject (within group) grand means
254 % - implicit in PropSca global normalisation)
255 % - no grand Mean scaling>'
256 %
257 % * Global normalisation option : Global nuisance effects are usually
258 % accounted for either by scaling the images so that they all have the
259 % same global value (proportional scaling), or by including the global
260 % covariate as a nuisance effect in the general linear model (AnCova).
261 % Much has been written on which to use, and when. Basically, since
262 % proportional scaling also scales the variance term, it is appropriate
263 % for situations where the global measurement predominantly reflects
264 % gain or sensitivity. Where variance is constant across the range of
265 % global values, linear modelling in an AnCova approach has more
266 % flexibility, since the model is not restricted to a simple
267 % proportional regression.
268 %
269 % Considering AnCova global normalisation, since subjects are unlikely
270 % to have the same relationship between global and local measurements,
271 % a subject-specific AnCova ("AnCova by subject"), fitting a different
272 % slope and intercept for each subject, would be preferred to the
273 % single common slope of a straight AnCova. (Assumming there's enough
274 % scans per subject to estimate such an effect.) This is basically an
275 % interaction of the global covariate with the subject factor. You may
276 % be offered various AnCova options, corresponding to interactions with
277 % various factors according to the design definition: The full list of
278 % possible options is:
279 % - AnCova
280 % - AnCova by replication
281 % - AnCova by condition (across group)
282 % - AnCova by subject (across group)
283 % - AnCova by group
284 % - AnCova by condition (within group)
285 % - AnCova by subject (within group)
286 % - Proportional scaling
287 % - <no global normalisation>
288 %
289 % Since differences between subjects may be due to gain and sensitivity
290 % effects, AnCova by subject could be combined with "grand mean scaling
291 % by subject" to obtain a combination of between subject proportional
292 % scaling and within subject AnCova.
293 %
294 % * Global centering: Lastly, for some designs using AnCova, you will
295 % be offered a choice of centering options for the global covariate. As
296 % with covariate centering, this is only relevant if you have a
297 % particular interest in the parameter estimates. Usually, the default
298 % of a centering corresponding to the AnCova used is chosen. The full
299 % list of possible options is:
300 % - around overall mean
301 % - around replication means
302 % - around condition means (across group)
303 % - around subject means (across group)
304 % - around group means
305 % - around condition means (within group)
306 % - around subject means (within group)
307 % - <no centering>
308 % - around user specified value
309 % - (as implied by AnCova)
310 % - GM (The grand mean scaled value)
311 % - (redundant: not doing AnCova)
312 %
313 %
314 %
315 % Note that this is a logical ordering for the global options, which is
316 % not the order used by the interface due to algorithm constraints. The
317 % interface asks for the options in this order:
318 % - Global normalisation
319 % - Grand mean scaling options
320 % (if not using proportional scaling global normalisation)
321 % - Value for grand mean scaling proportional scaling GloNorm
322 % (if appropriate)
323 % - Global centering options
324 % - Value for global centering (if "user-defined" chosen)
325 % - Method of calculation
326 %
327 % ----------------
328 %
329 % Masking options
330 % ===============
331 %
332 % The mask specifies the voxels within the image volume which are to be
333 % assessed. SPM supports three methods of masking. The volume analysed
334 % is the intersection of all masks:
335 %
336 % i) Threshold masking : "Analysis threshold"
337 % - images are thresholded at a given value and only voxels at
338 % which all images exceed the threshold are included in the
339 % analysis.
340 % - The threshold can be absolute, or a proportion of the global
341 % value (after scaling), or "-Inf" for no threshold masking.
342 % - (This was called "Grey matter threshold" in SPM94/5/6)
343 %
344 % ii) Implicit masking
345 % - An "implicit mask" is a mask implied by a particular voxel
346 % value. Voxels with this mask value are excluded from the
347 % analysis.
348 % - For image data-types with a representation of NaN
349 % (see spm_type.m), NaN's is the implicit mask value, (and
350 % NaN's are always masked out).
351 % - For image data-types without a representation of NaN, zero is
352 % the mask value, and the user can choose whether zero voxels
353 % should be masked out or not.
354 %
355 % iii) Explicit masking
356 % - Explicit masks are other images containing (implicit) masks
357 % that are to be applied to the current analysis.
358 % - All voxels with value NaN (for image data-types with a
359 % representation of NaN), or zero (for other data types) are
360 % excluded from the analysis.
361 % - Explicit mask images can have any orientation and voxel/image
362 % size. Nearest neighbour interpolation of a mask image is used if
363 % the voxel centers of the input images do not coincide with that
364 % of the mask image.
365 %
366 %
367 % ----------------
368 %
369 % Non-sphericity correction
370 % =========================
371 %
372 % In some instances the i.i.d. assumptions about the errors do not hold:
373 %
374 % Identity assumption:
375 % The identity assumption, of equal error variance (homoscedasticity), can
376 % be violated if the levels of a factor do not have the same error variance.
377 % For example, in a 2nd-level analysis of variance, one contrast may be scaled
378 % differently from another. Another example would be the comparison of
379 % qualitatively different dependant variables (e.g. normals vs. patients). If
380 % You say no to identity assumptions, you will be asked whether the error
381 % variance is the same over levels of each factor. Different variances
382 % (heteroscedasticy) induce different error covariance components that
383 % are estimated using restricted maximum likelihood (see below).
384 %
385 % Independence assumption.
386 % In some situations, certain factors may contain random effects. These induce
387 % dependencies or covariance components in the error terms. If you say no
388 % to independence assumptions, you will be asked whether random effects
389 % should be modelled for each factor. A simple example of this would be
390 % modelling the random effects of subject. These cause correlations among the
391 % error terms of observation from the same subject. For simplicity, it is
392 % assumed that the random effects of each factor are i.i.d. One can always
393 % re-specify the covariance components by hand in SPM.xVi.Vi for more
394 % complicated models
395 %
396 % ReML
397 % The ensuing covariance components will be estimated using ReML in spm_spm
398 % (assuming the same for all responsive voxels) and used to adjust the
399 % statistics and degrees of freedom during inference. By default spm_spm
400 % will use weighted least squares to produce Gauss-Markov or Maximum
401 % likelihood estimators using the non-sphericity structure specified at this
402 % stage. The components will be found in xX.xVi and enter the estimation
403 % procedure exactly as the serial correlations in fMRI models.
404 %
405 % see also: spm_reml.m and spm_non_sphericity.m
406 %
407 % ----------------
408 %
409 % Multivariate analyses
410 % =====================
411 %
412 % Mulitvariate analyses with n-variate response variables are supported
413 % and automatically invoke a ManCova and CVA in spm_spm. Multivariate
414 % designs are, at the moment limited to Basic and PET designs.
415 %
416 % ----------------------------------------------------------------------
417 %
418 % Variables saved in the SPM stucture
419 %
420 % xY.VY - nScan x 1 struct array of memory mapped images
421 % (see spm_vol for definition of the map structure)
422 % xX - structure describing design matrix
423 % xX.D - design definition structure
424 % (See definition in main body of spm_spm_ui.m)
425 % xX.I - nScan x 4 matrix of factor level indicators
426 % I(n,i) is the level of factor i corresponding to image n
427 % xX.sF - 1x4 cellstr containing the names of the four factors
428 % xX.sF{i} is the name of factor i
429 % xX.X - design matrix
430 % xX.xVi - correlation constraints for non-spericity correction
431 % xX.iH - vector of H partition (condition effects) indices,
432 % identifying columns of X correspoding to H
433 % xX.iC - vector of C partition (covariates of interest) indices
434 % xX.iB - vector of B partition (block effects) indices
435 % xX.iG - vector of G partition (nuisance variables) indices
436 % xX.name - p x 1 cellstr of effect names corresponding to columns
437 % of the design matrix
438 %
439 % xC - structure array of covariate details
440 % xC(i).rc - raw (as entered) i-th covariate
441 % xC(i).rcname - name of this covariate (string)
442 % xC(i).c - covariate as appears in design matrix (after any scaling,
443 % centering of interactions)
444 % xC(i).cname - cellstr containing names for effects corresponding to
445 % columns of xC(i).c
446 % xC(i).iCC - covariate centering option
447 % xC(i).iCFI - covariate by factor interaction option
448 % xC(i).type - covariate type: 1=interest, 2=nuisance, 3=global
449 % xC(i).cols - columns of design matrix corresponding to xC(i).c
450 % xC(i).descrip - cellstr containing a description of the covariate
451 %
452 % xGX - structure describing global options and values
453 % xGX.iGXcalc - global calculation option used
454 % xGX.sGXcalc - string describing global calculation used
455 % xGX.rg - raw globals (before scaling and such like)
456 % xGX.iGMsca - grand mean scaling option
457 % xGX.sGMsca - string describing grand mean scaling
458 % xGX.GM - value for grand mean (/proportional) scaling
459 % xGX.gSF - global scaling factor (applied to xGX.rg)
460 % xGX.iGC - global covariate centering option
461 % xGX.sGC - string describing global covariate centering option
462 % xGX.gc - center for global covariate
463 % xGX.iGloNorm - Global normalisation option
464 % xGX.sGloNorm - string describing global normalisation option
465 %
466 % xM - structure describing masking options
467 % xM.T - Threshold masking value (-Inf=>None,
468 % real=>absolute, complex=>proportional (i.e. times global) )
469 % xM.TH - nScan x 1 vector of analysis thresholds, one per image
470 % xM.I - Implicit masking (0=>none, 1=>implicit zero/NaN mask)
471 % xM.VM - struct array of explicit mask images
472 % (empty if no explicit masks)
473 % xM.xs - structure describing masking options
474 % (format is same as for xsDes described below)
475 %
476 % xsDes - structure of strings describing the design:
477 % Fieldnames are essentially topic strings (use "_"'s for
478 % spaces), and the field values should be strings or cellstr's
479 % of information regarding that topic. spm_DesRep.m
480 % uses this structure to produce a printed description
481 % of the design, displaying the fieldnames (with "_"'s
482 % converted to spaces) in bold as topics, with
483 % the corresponding text to the right
484 %
485 % SPMid - String identifying SPM and program versions
486 %
487 % ----------------
488 %
489 % NB: The SPM.mat file is not very portable: It contains
490 % memory-mapped handles for the images, which hardcodes the full file
491 % pathname and datatype. Therefore, subsequent to creating the
492 % SPM.mat, you cannot move the image files, and cannot move the
493 % entire analysis to a system with a different byte-order (even if the
494 % full file pathnames are retained. Further, the image scalefactors
495 % will have been pre-scaled to effect any grand mean or global
496 % scaling.
497 %_______________________________________________________________________
498 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
499
500 % Andrew Holmes
501 % $Id: spm_spm_ui.m 539 2006-05-19 17:59:30Z Darren $
502
503 %SCCSid = '$Rev: 539 $';
504
505 %=======================================================================
506 % - FORMAT specifications for programers
507 %=======================================================================
508 %( This is a multi function function, the first argument is an action )
509 %( string, specifying the particular action function to take. )
510 %
511 % FORMAT spm_spm_ui('CFG',D)
512 % Configure design
513 % D - design definition structure - see format definition below
514 % (If D is a struct array, then the user is asked to choose from the
515 % design definitions in the array. If D is not specified as an
516 % argument, then user is asked to choose from the standard internal
517 % definitions)
518 %
519 % FORMAT [P,I] = spm_spm_ui('Files&Indices',DsF,Dn,DbaTime)
520 % PET/SPECT file & factor level input
521 % DsF - 1x4 cellstr of factor names (ie D.sF)
522 % Dn - 1x4 vector indicating the number of levels (ie D.n)
523 % DbaTime - ask for F3 images in time order, with F2 levels input by user?
524 % P - nScan x 1 cellsrt of image filenames
525 % I - nScan x 4 matrix of factor level indices
526 %
527 % FORMAT D = spm_spm_ui('DesDefs_Stats')
528 % Design definitions for simple statistics
529 % D - struct array of design definitions (see definition below)
530 %
531 % FORMAT D = spm_spm_ui('DesDefs_PET')
532 % Design definitions for PET/SPECT models
533 % D - struct array of design definitions (see definition below)
534 %
535 % FORMAT D = spm_spm_ui('DesDefs_PET96')
536 % Design definitions for SPM96 PET/SPECT models
537 % D - struct array of design definitions (see definition below)
538
539 %=======================================================================
540 % Design definitions specification for programers & power users
541 %=======================================================================
542 % Within spm_spm_ui.m, a definition structure, D, determines the
543 % various options, defaults and specifications appropriate for a
544 % particular design. Usually one uses one of the pre-specified
545 % definitions chosen from the menu, which are specified in the function
546 % actions at the end of the program (spm_spm_ui('DesDefs_Stats'),
547 % spm_spm_ui('DesDefs_PET'), spm_spm_ui('DesDefs_PET96')). For
548 % customised use of spm_spm_ui.m, the design definition structure is
549 % shown by the following example:
550 %
551 % D = struct(...
552 % 'DesName','The Full Monty...',...
553 % 'n',[Inf Inf Inf Inf], 'sF',{{'repl','cond','subj','group'}},...
554 % 'Hform', 'I(:,[4,2]),''-'',{''stud'',''cond''}',...
555 % 'Bform', 'I(:,[4,3]),''-'',{''stud'',''subj''}',...
556 % 'nC',[Inf,Inf],'iCC',{{[1:8],[1:8]}},'iCFI',{{[1:7],[1:7]}},...
557 % 'iGXcalc',[1,2,3],'iGMsca',[1:7],'GM',50,...
558 % 'iGloNorm',[1:9],'iGC',[1:11],...
559 % 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
560 % 'b',struct('aTime',1));
561 %
562 % ( Note that the struct command expands cell arrays to give multiple )
563 % ( records, so if you want a cell array as a field value, you have to )
564 % ( embed it within another cell, hence the double "{{"'s. )
565 %
566 % ----------------
567 %
568 % Design structure fields and option definitions
569 % ==============================================
570 %
571 % D.Desname - a string naming the design
572 %
573 % In general, spm_spm_ui.m accomodates four factors. Usually these are
574 % 'group', 'subject', 'condition' & 'replication', but to allow for a
575 % flexible interface these are dynamically named for different designs,
576 % and are referred to as Factor4, Factor3, Factor2, and Factor1
577 % respectively. The first part of the D definition dictates the names
578 % and number of factor levels (i.e. number of subjects etc.) relevant
579 % for this design, and also how the H (condition) and B (block)
580 % partitions of the design matrix should be constructed.
581 %
582 % D.n - a 1x4 vector, indicating the number of levels. D.n(i)
583 % for i in [1:4] is the number of levels for factor i.
584 % Specify D.n(i) as 1 to ignore this factor level,
585 % otherwise the number of levels can be pre-specified as a
586 % given number, or given as Inf to allow the user to
587 % choose the number of levels.
588 %
589 % D.sF - a 1x4 cellstr containing the names of the four
590 % factors. D.sF{i} is the name of factor i.
591 %
592 % D.b.aTime - a binary indicator specifying whether images within F3
593 % level (subject) are selected in time order. For time
594 % order (D.b.aTime=1), F2 levels are indicated by a user
595 % input "condition" string (input handled by spm_input's
596 % 'c' type). When (D.b.aTime=0), images for each F3 are
597 % selected by F2 (condition). The latter was the mode of
598 % SPM95 and SPM96. (SPM94 and SPMclassic didn't do
599 % replications of conditions.)
600 %
601 % Once the user has entered the images and indicated the factor levels,
602 % a nScan x 4 matrix, I, of indicator variables is constructed
603 % specifying for each scan the relevant level of each of the four
604 % factors. I(n,i) is the level of factor i corresponding to image n.
605 % This I matrix of factor indicators is then used to construct the H
606 % and B forms of the design matrix according to the prescripton in the
607 % design definition D:
608 %
609 % D.Hform - a string specifying the form of the H partition of the
610 % design matrix. The string is evaluated as an argument
611 % string for spm_DesMtx, which builds design matrix
612 % partitions from indicator vectors.
613 % (eval(['[H,Hnames] = spm_DesMtx(',D.Hform,');']))
614 %
615 % D.BForm - a string specifying the form of the G partition.
616 %
617 % ( Note that a constant H partition is dropped if the B partition can )
618 % ( model the constant effect. )
619 %
620 % The next part of the design definition defines covariate options.
621 % Covariates are split into covariates (of interest) and nuisance
622 % variables. The covariates of interest and nuisance variables are put
623 % into the C & G partitions of the design matrox (the final design
624 % matrix is [H,C,B,G], where global nuisance covariates are appended to
625 % G). In SPM94/5/6 the design matrix was partitioned into effects of
626 % interest [H,C] and effects of no interest [B,G], with an F-test for
627 % no effects of interest and adjusted data (for effects of no interest)
628 % following from these partitions. SPM99 is more freestyle, with
629 % adjustments and F-tests specified by contrasts. However, the concept
630 % of effects of interest and of no interest has been maintained for
631 % continuity, and spm_spm_ui.m computes an F-contrast to test for "no
632 % effects of interest".
633 %
634 % D.nC - a 1x2 vector: D.nC(1) is the number of covariates,
635 % D.nC(2) the number of nuisance variables. Specify zero
636 % to skip covariate entry, the actual number of
637 % covariates, or Inf to let the user specify the number of
638 % covariates. As with earlier versions, blocks of design
639 % matrix can be entered. However, these are now treated as
640 % a single covariate entity, so the number of
641 % covariates.nuisance variables is now the number of items
642 % you are prompted for, regardless of their dimension. (In
643 % SPM95-6 this number was the number of covariate vectors
644 % that could be entered.)
645 %
646 % D.iCC - a 1x2 cell array containing two vectors indicating the
647 % allowable covariate centering options for this design.
648 % These options are defined in the body of spm_spm_ui.m,
649 % in variables sCC & CFIforms. Use negative indices to
650 % indicate the default, if any - the largest negative
651 % wins.
652 %
653 % D.iCFI - a 1x2 cell array containing two vectors indicating the
654 % allowable covariate by factor interactions for this
655 % design. Interactions are only offered with a factor if
656 % it has multiple levels. The options are defined in the
657 % body of spm_spm_ui.m, in variables sCFI & CFIforms. Use
658 % negative indicies to indicate a default.
659 %
660 % The next part defines global options:
661 %
662 % D.iGXcalc - a vector of possible global calculation options for
663 % this design, as listed in the body of spm_spm_ui.m in
664 % variable sGXcalc. (If other global options are chosen,
665 % then the "omit" option is not offered.) Again, negative
666 % values indicate a default.
667 %
668 % D.iGloNorm - a vector of possible global normalisation options for
669 % this design, as described in the body of spm_spm_ui.m in
670 % variable sGloNorm.
671 %
672 % D.iGMsca - a vector of possible grand mean scaling options, as
673 % described in the body of spm_spm_ui.m in variable
674 % sGMsca. (Note that grand mean scaling is redundent when
675 % using proportional scaling global flow normalisation.)
676 %
677 % D.iGC - a vector of possible global covariate centering
678 % options, corresponding to the descriptions in variable
679 % iCC given in the body of spm_spm_ui.m. This is only
680 % relevant for AnCova type global normalisation, and even
681 % then only if you're actually interested in constraining
682 % the values of the parameters in some useful way.
683 % Usually, one chooses option 10, "as implied by AnCova".
684 %
685 % The next component specifies masking options:
686 %
687 % D.M_.T - a vector defining the analysis threshold: Specify
688 % "-Inf" as an element to offer "None" as an option. If a
689 % real element is found, then absolute thresholding is
690 % offered, with the first real value proffered as default
691 % threshold. If an imaginary element is found, then
692 % proportional thresholding if offered (i.e. the threshold
693 % is a proportion of the image global), with the (abs of)
694 % the first imaginary element proffered as default.
695 %
696 % D.M_.I - Implicit masking? 0-no, 1-yes, Inf-ask. (This is
697 % irrelevant for image types with a representation of NaN,
698 % since NaN is then the mask value, and NaN's are always
699 % masked.)
700 %
701 % D.M.X - Explicit masking? 0-no, 1-yes, Inf-ask.
702 %
703 % ----------------
704 %
705 % To use a customised design structure D, type spm_spm_ui('cfg',D) in the
706 % Matlab command window.
707 %
708 % The easiest way to generate a customised design definition structure
709 % is to tweak one of the pre-defined definitions. The following code
710 % will prompt you to select one of the pre-defined designs, and return
711 % the design definition structure for you to work on:
712 %
713 % D = spm_spm_ui(char(spm_input('Select design class...','+1','m',...
714 % {'Basic stats','Standard PET designs','SPM96 PET designs'},...
715 % {'DesDefs_Stats','DesDefs_PET','DesDefs_PET96'},2)));
716 % D = D(spm_input('Select design type...','+1','m',{D.DesName}'))
717 %
718 %_______________________________________________________________________
719 % @(#)spm_spm_ui.m 2.54 Andrew Holmes 04/12/09
720
721
722 %-Condition arguments
723 %-----------------------------------------------------------------------
724 global defaults
725 defaults.analyze.flip=1; %to keep spm_flip_analyze_images.m (spm_vol.m) happy
726
727 if (nargin==0), Action = 'CFG'; else, Action = varargin{1}; end
728
729 switch lower(Action)
730 case 'cfg'
731 %===================================================================
732 % - C O N F I G U R E D E S I G N
733 %===================================================================
734 % spm_spm_ui('CFG',D)
735 if nargin<2, D = []; else, D = varargin{2}; end
736
737 %-GUI setup
738 %-------------------------------------------------------------------
739 SPMid = ['SPM5: ',mfilename,' v',SCCSid];
740 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Stats: Setup analysis',0);
741 spm_help('!ContextHelp',mfilename)
742
743
744 %-Ask about overwriting files from previous analyses...
745 %-------------------------------------------------------------------
746 if exist(fullfile('.','SPM.mat'))
747 str = { 'Current directory contains existing SPM file:',...
748 'Continuing will overwrite existing file!'};
749 if spm_input(str,1,'bd','stop|continue',[1,0],1,mfilename);
750 fprintf('%-40s: %30s\n\n',...
751 'Abort... (existing SPM file)',spm('time'))
752 spm_clf(Finter)
753 return
754 end
755 end
756
757
758
759 %-Option definitions
760 %-------------------------------------------------------------------
761 %-Generic factor names
762 sF = {'sF1','sF2','sF3','sF4'};
763
764 %-Covariate by factor interaction options
765 sCFI = {'<none>';... %-1
766 'with sF1';'with sF2';'with sF3';'with sF4';... %-2:5
767 'with sF2 (within sF4)';'with sF3 (within sF4)'}; %-6,7
768
769 %-DesMtx argument components for covariate by factor interaction options
770 % (Used for CFI's Covariate Centering (CC), GMscale & Global normalisation)
771 CFIforms = { '[]', 'C', '{}';... %-1
772 'I(:,1)', 'FxC', '{D.sF{1}}';... %-2
773 'I(:,2)', 'FxC', '{D.sF{2}}';... %-3
774 'I(:,3)', 'FxC', '{D.sF{3}}';... %-4
775 'I(:,4)', 'FxC', '{D.sF{4}}';... %-5
776 'I(:,[4,2])', 'FxC', '{D.sF{4},D.sF{2}}';... %-6
777 'I(:,[4,3])', 'FxC', '{D.sF{4},D.sF{3}}' }; %-7
778
779 %-Centre (mean correction) options for covariates & globals (CC)
780 % (options 9-12 are for centering of global when using AnCova GloNorm) (GC)
781 sCC = { 'around overall mean';... %-1
782 'around sF1 means';... %-2
783 'around sF2 means';... %-3
784 'around sF3 means';... %-4
785 'around sF4 means';... %-5
786 'around sF2 (within sF4) means';... %-6
787 'around sF3 (within sF4) means';... %-7
788 '<no centering>';... %-8
789 'around user specified value';... %-9
790 '(as implied by AnCova)';... %-10
791 'GM';... %-11
792 '(redundant: not doing AnCova)'}'; %-12
793 %-DesMtx I forms for covariate centering options
794 CCforms = {'ones(nScan,1)',CFIforms{2:end,1},''}';
795
796
797 %-Global normalization options (options 1-7 match CFIforms) (GloNorm)
798 sGloNorm = { 'AnCova';... %-1
799 'AnCova by sF1';... %-2
800 'AnCova by sF2';... %-3
801 'AnCova by sF3';... %-4
802 'AnCova by sF4';... %-5
803 'AnCova by sF2 (within sF4)';... %-6
804 'AnCova by sF3 (within sF4)';... %-7
805 'proportional scaling';... %-8
806 '<no global normalisation>'}; %-9
807
808 %-Grand mean scaling options (GMsca)
809 sGMsca = { 'scaling of overall grand mean';... %-1
810 'scaling of sF1 grand means';... %-2
811 'scaling of sF2 grand means';... %-3
812 'scaling of sF3 grand means';... %-4
813 'scaling of sF4 grand means';... %-5
814 'scaling of sF2 (within sF4) grand means';... %-6
815 'scaling of sF3 (within sF4) grand means';... %-7
816 '(implicit in PropSca global normalisation)';... %-8
817 '<no grand Mean scaling>' }; %-9
818 %-NB: Grand mean scaling by subject is redundent for proportional scaling
819
820
821 %-Global calculation options (GXcalc)
822 sGXcalc = { 'omit';... %-1
823 'user specified';... %-2
824 'mean voxel value (within per image fullmean/8 mask)'}; %-3
825
826
827
828 %===================================================================
829 %-D E S I G N P A R A M E T E R S
830 %===================================================================
831 %-Get design type
832 %-------------------------------------------------------------------
833
834 D = [D, struct(...
835 'DesName','Bespoke design via CBU CSV interface',...
836 'n',[Inf Inf Inf Inf], 'sF',{{'repl','condition','subject','group'}},...
837 'Hform', 'I(:,[4,2]),''-'',{''stud'',''cond''}',...
838 'Bform', 'I(:,[4,3]),''-'',{''stud'',''subj''}',...
839 'nC',[Inf,Inf],'iCC',{{[5:8],[5,7,8]}},'iCFI',{{[1,5,6,7],[1,5,7]}},...
840 'iGXcalc',[1,2,-3],'iGMsca',[-7,9],'GM',50,...
841 'iGloNorm',[7,8,9],'iGC',10,...
842 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
843 'b',struct('aTime',1))];
844
845 if isempty(D)
846
847 D = spm_spm_ui( ...
848 char(spm_input('Select design class...','+1','m',...
849 {'Basic stats','Standard PET designs','SPM96 PET designs'},...
850 {'DesDefs_Stats','DesDefs_PET','DesDefs_PET96'},2)));
851 end
852
853 % D = D(spm_input('Select design type...','+1','m',{D.DesName}'));
854
855
856 %-Set factor names for this design
857 %-------------------------------------------------------------------
858 sCC = sf_estrrep(sCC,[sF',D.sF']);
859 sCFI = sf_estrrep(sCFI,[sF',D.sF']);
860 sGloNorm = sf_estrrep(sGloNorm,[sF',D.sF']);
861 sGMsca = sf_estrrep(sGMsca,[sF',D.sF']);
862
863 %-Get filenames & factor indicies
864 %-------------------------------------------------------------------
865 %%%%%%%%%%%%%%
866 %start cbuhack
867 %%%%%%%%%%%%%%
868
869 cbu_title='untitled';
870 cbu_factors='GSCR';
871 cbu_factor_format='%d,%d,%d,%d,';
872 cbu_cov_columns=0;
873 cbu_cov_partition={};
874 cbu_cov_block_labels={};
875 cbu_cov_format='';
876 cbu_covariates=[];
877
878 str = { 'Do you want to read filename/condition stuff',...
879 'from an ascii file?'};
880 cbuhack = spm_input(str,1,'bd','yes|no',[1,0],0,'CBU file input ');
881 if cbuhack
882 [P,I, ...
883 cbu_title, ...
884 cbu_factors, ...
885 cbu_factor_format, ...
886 cbu_cov_columns, ...
887 cbu_cov_partition, ...
888 cbu_cov_block_labels, ...
889 cbu_cov_format, ...
890 cbu_covariates] ...
891 = cbu_csv5_ui('cbuhack',D.sF,D.n,D.b.aTime);
892 else
893 [P,I] = spm_spm_ui('Files&Indices',D.sF,D.n,D.b.aTime); %-Files & indices
894 end
895
896 save I I;
897
898 %%%%%%%%%%%%
899 %end cbuhack
900 %%%%%%%%%%%%
901 %%[P,I] = spm_spm_ui('Files&Indices',D.sF,D.n,D.b.aTime);
902
903 nScan = size(I,1); %-#obs
904
905 %-Additional design parameters
906 %-------------------------------------------------------------------
907 bL = any(diff(I,1),1); %-Multiple factor levels?
908 % NB: bL(2) might be thrown by user specified f1 levels
909 % (D.b.aTime & D.n(2)>1) - assumme user is consistent?
910 bFI = [bL(1),bL(2:3)&~bL(4),bL(4),bL([2,3])&bL(4)];
911 %-Allowable interactions for covariates
912 %-Only offer interactions with multi-level factors, and
913 % don't offer by F2|F3 if bL(4)!
914
915 %-Build Condition (H) and Block (B) partitions
916 %===================================================================
917 H=[];Hnames=[];
918 B=[];Bnames=[];
919 eval(['[H,Hnames] = spm_DesMtx(',D.Hform,');'])
920 if rank(H)==nScan, error('unestimable condition effects'), end
921 eval(['[B,Bnames] = spm_DesMtx(',D.Bform,');'])
922 if rank(B)==nScan, error('unestimable block effects'), end
923
924 %-Drop a constant H partition if B partition can model constant
925 if size(H,2)>0 & all(H(:)==1) & (rank([H B])==rank(B))
926 H = []; Hnames = {};
927 warning('Dropping redundant constant H partition')
928 end
929
930
931 %-Covariate partition(s): interest (C) & nuisance (G) excluding global
932 %===================================================================
933 nC = D.nC; %-Default #covariates
934 C = {[],[]}; Cnames = {{},{}}; %-Covariate DesMtx partitions & names
935 xC = []; %-Struct array to hold raw covariates
936
937
938 dcname = {'CovInt','NusCov'}; %-Default root names for covariates
939 dstr = {'covariate','nuisance variable'};
940
941 GUIpos = spm_input('!NextPos');
942 nc = [0,0];
943 for i = 1:2 % 1:covariates of interest, 2:nuisance variables
944
945 if ~cbuhack
946 if isinf(nC(i)), nC(i)=spm_input(['# ',dstr{i},'s'],GUIpos,'w1');, end
947 else
948 if size(cbu_cov_partition,2)<i
949 nC(i)=0;
950 else
951 nC(i)=size(cbu_cov_partition{i},2);
952 end
953 end
954
955 while nc(i) < nC(i)
956
957 %-Create prompt, get covariate, get covariate name
958 %-----------------------------------------------------------
959 if nC(i)==1
960 str=dstr{i};
961 else
962 str=sprintf('%s %d',dstr{i},nc(i)+1);
963 end
964
965 if ~cbuhack
966 c = spm_input(str,GUIpos,'r',[],[nScan,Inf]);
967 cbu_cov_partition{i}{nc(i)+1} = ...
968 (cbu_cov_columns+1):(cbu_cov_columns+size(c,2));
969 cbu_cov_columns = cbu_cov_columns+size(c,2);
970 cbu_covariates = [cbu_covariates, c];
971 else
972 c = cbu_covariates(:,cbu_cov_partition{i}{nc(i)+1});
973 end
974
975 if any(isnan(c(:))), break, end %-NaN is dummy value to exit
976 nc(i) = nc(i)+1; %-#Covariates (so far)
977 if nC(i)>1, tstr = sprintf('%s^{%d}',dcname{i},nc(i));
978 else, tstr = dcname{i}; end
979
980 if ~cbuhack
981 cname = spm_input([str,' name?'],'+1','s',tstr);
982 cbu_cov_block_labels{i}{nc(i)} = cname;
983 else
984 cname = cbu_cov_block_labels{i}{nc(i)};
985 end
986
987 rc = c; %-Save covariate value
988 rcname = cname; %-Save covariate name
989
990 %-Interaction option? (if single covariate vector entered)?
991 %-----------------------------------------------------------
992 if size(c,2) == 1
993 %-User choice of interaction options, default is negative
994 %-Only offer interactions for appropriate factor combinations
995 if length(D.iCFI{i})>1
996 iCFI = intersect(abs(D.iCFI{i}),find([1,bFI]));
997 dCFI = max([1,intersect(iCFI,-D.iCFI{i}(D.iCFI{i}<0))]);
998 iCFI = spm_input([str,': interaction?'],'+1','m',...
999 sCFI(iCFI),iCFI,find(iCFI==dCFI));
1000 else
1001 iCFI = abs(D.iCFI{i}); %-AutoSelect default option
1002 end
1003 else
1004 iCFI = 1;
1005 end
1006
1007 %-Centre covariate(s)? (Default centring to correspond to CFI)
1008 % Always offer "no centering" as default for design matrix blocks
1009 %-----------------------------------------------------------
1010 DiCC = D.iCC{i};
1011 if size(c,2)>1, DiCC = union(DiCC,-8); end
1012 if length(DiCC)>1
1013 %-User has a choice of centering options
1014 %-Only offer factor specific for appropriate factor combinations
1015 iCC = intersect(abs(DiCC),find([1,bFI,1]) );
1016 %-Default is max -ve option in D, overridden by iCFI if CFI
1017 if iCFI == 1, dCC = -DiCC(DiCC<0); else, dCC = iCFI; end
1018 dCC = max([1,intersect(iCC,dCC)]);
1019 iCC = spm_input([str,': centre?'],'+1','m',...
1020 sCC(iCC),iCC,find(iCC==dCC));
1021 else
1022 iCC = abs(DiCC); %-AutoSelect default option
1023 end
1024 %-Centre within factor levels as appropriate
1025 if any(iCC == [1:7]), c = c - spm_meanby(c,eval(CCforms{iCC})); end
1026
1027 %-Do any interaction (only for single covariate vectors)
1028 %-----------------------------------------------------------
1029 if iCFI > 1 %-(NB:iCFI=1 if size(c,2)>1)
1030 tI = [eval(CFIforms{iCFI,1}),c];
1031 tConst = CFIforms{iCFI,2};
1032 tFnames = [eval(CFIforms{iCFI,3}),{cname}];
1033 [c,cname] = spm_DesMtx(tI,tConst,tFnames);
1034 elseif size(c,2)>1 %-Design matrix block
1035 [null,cname] = spm_DesMtx(c,'X',cname);
1036 else
1037 cname = {cname};
1038 end
1039
1040 %-Store raw covariate details in xC struct for reference
1041 %-Pack c into appropriate DesMtx partition
1042 %-----------------------------------------------------------
1043 %-Construct description string for covariate
1044 str = {sprintf('%s: %s',str,rcname)};
1045 if size(rc,2)>1, str = {sprintf('%s (block of %d covariates)',...
1046 str{:},size(rc,2))}; end
1047 if iCC < 8, str=[str;{['used centered ',sCC{iCC}]}]; end
1048 if iCFI> 1, str=[str;{['fitted as interaction ',sCFI{iCFI}]}]; end
1049
1050 tmp = struct( 'rc',rc, 'rcname',rcname,...
1051 'c',c, 'cname',{cname},...
1052 'iCC',iCC, 'iCFI',iCFI,...
1053 'type',i,...
1054 'cols',[1:size(c,2)] + ...
1055 size([H,C{1}],2) + ...
1056 size([B,C{2}],2)*(i-1),...
1057 'descrip',{str} );
1058 if isempty(xC), xC = tmp; else, xC = [xC,tmp]; end
1059 C{i} = [C{i},c];
1060 Cnames{i} = [Cnames{i}; cname];
1061
1062 end % (while)
1063
1064 end % (for)
1065 clear c tI tConst tFnames
1066 spm_input('!SetNextPos',GUIpos);
1067
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%
1069 %start cbuhack save design
1070 %%%%%%%%%%%%%%%%%%%%%%%%%%
1071
1072 csv=fopen('design.csv','w'); % save design/file data in design.csv
1073
1074 cbu_full='GSCR';
1075 cbu_f='';
1076 cbu_o='';
1077 cbu_w='';
1078 for i = 1:4
1079 if length(unique(I(:,5-i)))>1
1080 cbu_f=[cbu_f,cbu_full(i)];
1081 cbu_o=[cbu_o,'%d, '];
1082 cbu_w=[cbu_w,'I(i,',int2str(5-i),'), '];
1083 end
1084 end
1085
1086 fprintf(csv,'=cbu_title=''%s'';\n=cbu_factors=''%s'';\n=cbu_cov_columns=[%s];\n', ...
1087 cbu_title,cbu_f,int2str(cbu_cov_columns));
1088
1089 part='';
1090 labs='';
1091 if size(cbu_cov_partition,2)>0
1092 part = [part, '=cbu_cov_partition={'];
1093 labs = [labs, '=cbu_cov_block_labels={'];
1094 for i=1:size(cbu_cov_partition,2)
1095 if size(cbu_cov_partition{i},2)>0
1096 part = [part, '{'];
1097 labs = [labs, '{'];
1098 for j=1:size(cbu_cov_partition{i},2)
1099 part = [part, sprintf('[%s],',int2str(cbu_cov_partition{i}{j}))];
1100 labs = [labs, sprintf('''%s'',',cbu_cov_block_labels{i}{j})];
1101 end
1102 part = [part, '}, '];
1103 labs = [labs, '}, '];
1104 end
1105 end
1106 part = [part, '};\n'];
1107 labs = [labs, '};\n'];
1108 end
1109
1110 fprintf(csv,strrep(strrep(part,',}','}'),', }','}'));
1111 fprintf(csv,strrep(strrep(labs,',}','}'),', }','}'));
1112
1113 fprintf(csv,'+\n');
1114
1115 for i=1:size(I,1)
1116 eval(strrep(['fprintf(csv,''',cbu_o,''',',cbu_w,');'],', )',')'));
1117 for j=1:size(cbu_covariates,2)
1118 fprintf(csv,'%g, ',cbu_covariates(i,j));
1119 end %j
1120 fprintf(csv,'%s\n',P{i});
1121 end %i
1122 fclose(csv);
1123
1124 %%%%%%%%%%%%%%%%%%%%%%%%
1125 %end cbuhack save design
1126 %%%%%%%%%%%%%%%%%%%%%%%%
1127
1128
1129 %-Unpack into C & G design matrix sub-partitions
1130 G = C{2}; Gnames = Cnames{2};
1131 C = C{1}; Cnames = Cnames{1};
1132
1133
1134 %-Options...
1135 %===================================================================
1136 %-Global normalization options (GloNorm)
1137 %-------------------------------------------------------------------
1138 if length(D.iGloNorm)>1
1139 %-User choice of global normalisation options, default is negative
1140 %-Only offer factor specific for appropriate factor combinations
1141 iGloNorm = intersect(abs(D.iGloNorm),find([1,bFI,1,1]));
1142 dGloNorm = max([0,intersect(iGloNorm,-D.iGloNorm(D.iGloNorm<0))]);
1143 iGloNorm = spm_input('GloNorm: Select global normalisation','+1','m',...
1144 sGloNorm(iGloNorm),iGloNorm,find(iGloNorm==dGloNorm));
1145 else
1146 iGloNorm = abs(D.iGloNorm);
1147 end
1148
1149
1150 %-Grand mean scaling options (GMsca)
1151 %-------------------------------------------------------------------
1152 if iGloNorm==8
1153 iGMsca=8; %-grand mean scaling implicit in PropSca GloNorm
1154 elseif length(D.iGMsca)==1
1155 iGMsca = abs(D.iGMsca);
1156 else
1157 %-User choice of grand mean scaling options
1158 %-Only offer factor specific for appropriate factor combinations
1159 iGMsca = intersect(abs(D.iGMsca),find([1,bFI,0,1]));
1160 %-Default is max -ve option in D, overridden by iGloNorm if AnCova
1161 if iGloNorm==9, dGMsca=-D.iGMsca(D.iGMsca<0); else, dGMsca=iGloNorm; end
1162 dGMsca = max([0,intersect(iGMsca,dGMsca)]);
1163 iGMsca = spm_input('GMsca: grand mean scaling','+1','m',...
1164 sGMsca(iGMsca),iGMsca,find(iGMsca==dGMsca));
1165 end
1166
1167
1168 %-Value for PropSca / GMsca (GM)
1169 %-------------------------------------------------------------------
1170 if iGMsca == 9 %-Not scaling (GMsca or PropSca)
1171 GM = 0; %-Set GM to zero when not scaling
1172 else %-Ask user value of GM
1173 if iGloNorm==8
1174 str = 'PropSca global mean to';
1175 else
1176 str = [strrep(sGMsca{iGMsca},'scaling of','scale'),' to'];
1177 end
1178 GM = spm_input(str,'+1','r',D.GM,1);
1179 %-If GM is zero then don't GMsca! or PropSca GloNorm
1180 if GM==0, iGMsca=9; if iGloNorm==8, iGloNorm=9; end, end
1181 end
1182
1183 %-Sort out description strings for GloNorm and GMsca
1184 %-------------------------------------------------------------------
1185 sGloNorm = sGloNorm{iGloNorm};
1186 sGMsca = sGMsca{iGMsca};
1187 if iGloNorm==8
1188 sGloNorm = sprintf('%s to %-4g',sGloNorm,GM);
1189 elseif iGMsca<8
1190 sGMsca = sprintf('%s to %-4g',sGMsca,GM);
1191 end
1192
1193
1194 %-Global centering (for AnCova GloNorm) (GC)
1195 %-------------------------------------------------------------------
1196 %-Specify the centering option for the global covariate for AnCova
1197 %-Basically, if 'GMsca'ling then should centre to GM (iGC=11). Otherwise,
1198 % should centre in similar fashion to AnCova (i.e. by the same factor(s)),
1199 % such that models are seperable (iGC=10). This is particularly important
1200 % for subject specific condition effects if then passed on to a second-level
1201 % model. (See also spm_adjmean_ui.m) SPM96 (& earlier) used to just centre
1202 % GX around its (overall) mean (iGC=1).
1203
1204 %-This code allows more general options to be specified (but is complex)
1205 %-Setting D.iGC=[-10,-11] gives the standard choices above
1206
1207 %-If not doing AnCova then GC is irrelevant
1208 if ~any(iGloNorm == [1:7])
1209 iGC = 12;
1210 gc = [];
1211 else
1212 %-Annotate options 10 & 11 with specific details
1213 %---------------------------------------------------------------
1214 %-Tag '(as implied by AnCova)' with actual AnCova situation
1215 sCC{10} = [sCC{iGloNorm},' (<= ',sGloNorm,')'];
1216 %-Tag 'GM' case with actual GM & GMsca case
1217 sCC{11} = sprintf('around GM=%g (i.e. %s after grand mean scaling)',...
1218 GM,strrep(sCC{iGMsca},'around ',''));
1219
1220 %-Constuct vector of allowable iGC
1221 %---------------------------------------------------------------
1222 %-Weed out redundent factor combinations from pre-set allowable options
1223 iGC = intersect(abs(D.iGC),find([1,bFI,1,1,1,1]));
1224 %-Omit 'GM' option if didn't GMsca (iGMsca~=8 'cos doing AnCova)
1225 if any(iGMsca==[8,9]), iGC = setdiff(iGC,11); end
1226 %-Omit 'GM' option if same as '(as implied by AnCova)'
1227 if iGloNorm==iGMsca, iGC = setdiff(iGC,11); end
1228
1229 %-If there's a choice, set defaults (if any), & get answer
1230 %---------------------------------------------------------------
1231 if length(iGC)>1
1232 dGC = max([0,intersect(iGC,-D.iGC(D.iGC<0))]);
1233 str = 'Centre global covariate';
1234 if iGMsca<8, str = [str,' (after grand mean scaling)']; end
1235 iGC = spm_input(str,'+1','m',sCC(iGC),iGC,find(iGC==dGC));
1236 elseif isempty(iGC)
1237 error('Configuration error: empty iGC')
1238 end
1239
1240 %-If 'user specified' then get value
1241 %---------------------------------------------------------------
1242 if iGC==9
1243 gc = spm_input('Centre globals around','+0','r',D.GM,1);
1244 sCC{9} = sprintf('%s of %g',sCC{iGC},gc);
1245 else
1246 gc = 0;
1247 end
1248 end
1249
1250
1251 %-Thresholds & masks defining voxels to analyse (MASK)
1252 %===================================================================
1253 GUIpos = spm_input('!NextPos');
1254
1255 %-Analysis threshold mask
1256 %-------------------------------------------------------------------
1257 %-Work out available options:
1258 % -Inf=>None, real=>absolute, complex=>proportional, (i.e. times global)
1259 M_T = D.M_.T; if isempty(M_T), M_T = [-Inf, 100, 0.8*sqrt(-1)]; end
1260 M_T = { 'none', M_T(min(find(isinf(M_T))));...
1261 'absolute', M_T(min(find(isfinite(M_T)&(M_T==real(M_T)))));...
1262 'relative', M_T(min(find(isfinite(M_T)&(M_T~=real(M_T))))) };
1263
1264 %-Work out available options
1265 %-If there's a choice between proportional and absolute then ask
1266 %-------------------------------------------------------------------
1267 q = ~[isempty(M_T{1,2}), isempty(M_T{2,2}), isempty(M_T{3,2})];
1268
1269 if all(q(2:3))
1270 tmp = spm_input('Threshold masking',GUIpos,'b',M_T(q,1),find(q));
1271 q(setdiff([1:3],tmp))=0;
1272 end
1273
1274 %-Get mask value - note that at most one of q(2:3) is true
1275 %-------------------------------------------------------------------
1276 if ~any(q) %-Oops - nothing specified!
1277 M_T = -Inf;
1278 elseif all(q==[1,0,0]) %-no threshold masking
1279 M_T = -Inf;
1280 else %-get mask value
1281 if q(1), args = {'br1','None',-Inf,abs(M_T{1+find(q(2:3)),2})};
1282 else, args = {'r',abs(M_T{1+find(q(2:3)),2})}; end
1283 if q(2)
1284 M_T = spm_input('threshold',GUIpos,args{:});
1285 elseif q(3)
1286 M_T = spm_input('threshold (relative to global)',GUIpos,...
1287 args{:});
1288 if isfinite(M_T) & isreal(M_T), M_T=M_T*sqrt(-1); end
1289 else
1290 error('Shouldn''t get here!')
1291 end
1292 end
1293
1294 %-Make a description string
1295 %-------------------------------------------------------------------
1296 if isinf(M_T)
1297 xsM.Analysis_threshold = 'None (-Inf)';
1298 elseif isreal(M_T)
1299 xsM.Analysis_threshold = sprintf('images thresholded at %6g',M_T);
1300 else
1301 xsM.Analysis_threshold = sprintf(['images thresholded at %6g ',...
1302 'times global'],imag(M_T));
1303 end
1304
1305
1306 %-Implicit masking: Ignore zero voxels in low data-types?
1307 %-------------------------------------------------------------------
1308 % (Implicit mask is NaN in higher data-types.)
1309 type = getfield(spm_vol(P{1,1}),'dt')*[1,0]';
1310 if ~spm_type(type,'nanrep')
1311 switch D.M_.I
1312 case Inf, M_I = spm_input('Implicit mask (ignore zero''s)?',...
1313 '+1','y/n',[1,0],1); %-Ask
1314 case {0,1}, M_I = D.M_.I; %-Pre-specified
1315 otherwise, error('unrecognised D.M_.I type')
1316 end
1317
1318 if M_I, xsM.Implicit_masking = 'Yes: zero''s treated as missing';
1319 else, xsm.Implicit_masking = 'No'; end
1320 else
1321 M_I = 1;
1322 xsM.Implicit_masking = 'Yes: NaN''s treated as missing';
1323 end
1324
1325
1326 %-Explicit mask images (map them later...)
1327 %-------------------------------------------------------------------
1328 switch(D.M_.X)
1329 case Inf, M_X = spm_input('explicitly mask images?','+1','y/n',[1,0],2);
1330 case {0,1}, M_X = D.M_.X;
1331 otherwise, error('unrecognised D.M_.X type')
1332 end
1333 if M_X, M_P = spm_select(Inf,'image','select mask images'); else, M_P = {}; end
1334
1335
1336 %-Global calculation (GXcalc)
1337 %===================================================================
1338 iGXcalc = abs(D.iGXcalc);
1339 %-Only offer "omit" option if not doing any GloNorm, GMsca or PropTHRESH
1340 if ~(iGloNorm==9 & iGMsca==9 & (isinf(M_T)|isreal(M_T)))
1341 iGXcalc = intersect(iGXcalc,[2:size(sGXcalc,1)]);
1342 end
1343 if isempty(iGXcalc)
1344 error('no GXcalc options')
1345 elseif length(iGXcalc)>1
1346 %-User choice of global calculation options, default is negative
1347 dGXcalc = max([1,intersect(iGXcalc,-D.iGXcalc(D.iGXcalc<0))]);
1348 iGXcalc = spm_input('Global calculation','+1','m',...
1349 sGXcalc(iGXcalc),iGXcalc,find(iGXcalc==dGXcalc));
1350 else
1351 iGXcalc = abs(D.iGXcalc);
1352 end
1353
1354 if iGXcalc==2 %-Get user specified globals
1355 g = spm_input('globals','+0','r',[],[nScan,1]);
1356 end
1357 sGXcalc = sGXcalc{iGXcalc};
1358
1359
1360 % Non-sphericity correction (set xVi.var and .dep)
1361 %===================================================================
1362 xVi.I = I;
1363 nL = max(I); % number of levels
1364 mL = find(nL > 1); % multilevel factors
1365 xVi.var = sparse(1,4); % unequal variances
1366 xVi.dep = sparse(1,4); % dependencies
1367
1368 if length(mL) > 1
1369
1370 % repeated measures design
1371 %---------------------------------------------------------------
1372 if spm_input('non-sphericity correction?','+1','y/n',[1,0],0)
1373
1374 % make menu strings
1375 %-----------------------------------------------------------
1376 for i = 1:4
1377 mstr{i} = sprintf('%s (%i levels)',D.sF{i},nL(i));
1378 end
1379 mstr = mstr(mL);
1380
1381 % are errors identical
1382 %-----------------------------------------------------------
1383 if spm_input('are errors identical','+1','y/n',[0,1],0)
1384 str = 'unequal variances are between';
1385 [i j] = min(nL(mL));
1386 i = spm_input(str,'+0','m',mstr,[],j);
1387
1388 % set in xVi and eliminate from dependency option
1389 %-------------------------------------------------------
1390 xVi.var(mL(i)) = 1;
1391 mL(i) = [];
1392 mstr(i) = [];
1393 end
1394
1395 % are errors independent
1396 %-----------------------------------------------------------
1397 if spm_input('are errors independent','+1','y/n',[0,1],0)
1398 str = ' dependencies are within';
1399 [i j] = max(nL(mL));
1400 i = spm_input(str,'+0','m',mstr,[],j);
1401
1402 % set in xVi
1403 %-------------------------------------------------------
1404 xVi.dep(mL(i)) = 1;
1405 end
1406
1407 end
1408 end
1409
1410 %-Place covariance components Q{:} in xVi.Vi
1411 %-------------------------------------------------------------------
1412 xVi = spm_non_sphericity(xVi);
1413
1414 %===================================================================
1415 % - C O N F I G U R E D E S I G N
1416 %===================================================================
1417 spm('FigName','Stats: configuring',Finter,CmdLine);
1418 spm('Pointer','Watch');
1419
1420
1421 %-Images & image info: Map Y image files and check consistency of
1422 % dimensions and orientation / voxel size
1423 %===================================================================
1424 fprintf('%-40s: ','Mapping files') %-#
1425 VY = spm_vol(char(P));
1426
1427
1428 %-Check compatability of images (Bombs for single image)
1429 %-------------------------------------------------------------------
1430 spm_check_orientations(VY);
1431
1432 fprintf('%30s\n','...done') %-#
1433
1434
1435 %-Global values, scaling and global normalisation
1436 %===================================================================
1437 %-Compute global values
1438 %-------------------------------------------------------------------
1439 switch iGXcalc, case 1
1440 %-Don't compute => no GMsca (iGMsca==9) or GloNorm (iGloNorm==9)
1441 g = [];
1442 case 2
1443 %-User specified globals
1444 case 3
1445 %-Compute as mean voxel value (within per image fullmean/8 mask)
1446 g = zeros(nScan,1 );
1447 fprintf('%-40s: %30s','Calculating globals',' ') %-#
1448 for i = 1:nScan
1449 str = sprintf('%3d/%-3d',i,nScan);
1450 fprintf('%s%30s',repmat(sprintf('\b'),1,30),str)%-#
1451 g(i) = spm_global(VY(i));
1452 end
1453 fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done') %-#
1454 otherwise
1455 error('illegal iGXcalc')
1456 end
1457 rg = g;
1458
1459
1460 fprintf('%-40s: ','Design configuration') %-#
1461
1462
1463 %-Scaling: compute global scaling factors gSF required to implement
1464 % proportional scaling global normalisation (PropSca) or grand mean
1465 % scaling (GMsca), as specified by iGMsca (& iGloNorm)
1466 %-------------------------------------------------------------------
1467 switch iGMsca, case 8
1468 %-Proportional scaling global normalisation
1469 if iGloNorm~=8, error('iGloNorm-iGMsca(8) mismatch for PropSca'), end
1470 gSF = GM./g;
1471 g = GM*ones(nScan,1);
1472 case {1,2,3,4,5,6,7}
1473 %-Grand mean scaling according to iGMsca
1474 gSF = GM./spm_meanby(g,eval(CCforms{iGMsca}));
1475 g = g.*gSF;
1476 case 9
1477 %-No grand mean scaling
1478 gSF = ones(nScan,1);
1479 otherwise
1480 error('illegal iGMsca')
1481 end
1482
1483
1484 %-Apply gSF to memory-mapped scalefactors to implement scaling
1485 %-------------------------------------------------------------------
1486 for i = 1:nScan
1487 VY(i).pinfo(1:2,:) = VY(i).pinfo(1:2,:)*gSF(i);
1488 end
1489
1490
1491 %-AnCova: Construct global nuisance covariates partition (if AnCova)
1492 %-------------------------------------------------------------------
1493 if any(iGloNorm == [1:7])
1494
1495 %-Centre global covariate as requested
1496 %---------------------------------------------------------------
1497 switch iGC, case {1,2,3,4,5,6,7} %-Standard sCC options
1498 gc = spm_meanby(g,eval(CCforms{iGC}));
1499 case 8 %-No centering
1500 gc = 0;
1501 case 9 %-User specified centre
1502 %-gc set above
1503 case 10 %-As implied by AnCova option
1504 gc = spm_meanby(g,eval(CCforms{iGloNorm}));
1505 case 11 %-Around GM
1506 gc = GM;
1507 otherwise %-unknown iGC
1508 error('unexpected iGC value')
1509 end
1510
1511
1512 %-AnCova - add scaled centred global to DesMtx `G' partition
1513 %---------------------------------------------------------------
1514 rcname = 'global';
1515 tI = [eval(CFIforms{iGloNorm,1}),g - gc];
1516 tConst = CFIforms{iGloNorm,2};
1517 tFnames = [eval(CFIforms{iGloNorm,3}),{rcname}];
1518 [f,gnames] = spm_DesMtx(tI,tConst,tFnames);
1519 clear tI tConst tFnames
1520
1521 %-Save GX info in xC struct for reference
1522 %---------------------------------------------------------------
1523 str = {sprintf('%s: %s',dstr{2},rcname)};
1524 if any(iGMsca==[1:7]), str=[str;{['(after ',sGMsca,')']}]; end
1525 if iGC ~= 8, str=[str;{['used centered ',sCC{iGC}]}]; end
1526 if iGloNorm > 1
1527 str=[str;{['fitted as interaction ',sCFI{iGloNorm}]}];
1528 end
1529 tmp = struct( 'rc',rg.*gSF, 'rcname',rcname,...
1530 'c',f, 'cname' ,{gnames},...
1531 'iCC',iGC, 'iCFI' ,iGloNorm,...
1532 'type', 3,...
1533 'cols',[1:size(f,2)] + size([H C B G],2),...
1534 'descrip', {str} );
1535
1536 G = [G,f]; Gnames = [Gnames; gnames];
1537 if isempty(xC), xC = tmp; else, xC = [xC,tmp]; end
1538
1539
1540 elseif iGloNorm==8 | iGXcalc>1
1541
1542 %-Globals calculated, but not AnCova: Make a note of globals
1543 %---------------------------------------------------------------
1544 if iGloNorm==8
1545 str = { 'global values: (used for proportional scaling)';...
1546 '("raw" unscaled globals shown)'};
1547 elseif isfinite(M_T) & ~isreal(M_T)
1548 str = { 'global values: (used to compute analysis threshold)'};
1549 else
1550 str = { 'global values: (computed but not used)'};
1551 end
1552
1553 rcname ='global';
1554 tmp = struct( 'rc',rg, 'rcname',rcname,...
1555 'c',{[]}, 'cname' ,{{}},...
1556 'iCC',0, 'iCFI' ,0,...
1557 'type', 3,...
1558 'cols', {[]},...
1559 'descrip', {str} );
1560
1561 if isempty(xC), xC = tmp; else, xC = [xC,tmp]; end
1562 end
1563
1564
1565 %-Save info on global calculation in xGX structure
1566 %-------------------------------------------------------------------
1567 xGX = struct(...
1568 'iGXcalc',iGXcalc, 'sGXcalc',sGXcalc, 'rg',rg,...
1569 'iGMsca',iGMsca, 'sGMsca',sGMsca, 'GM',GM,'gSF',gSF,...
1570 'iGC', iGC, 'sGC', sCC{iGC}, 'gc', gc,...
1571 'iGloNorm',iGloNorm, 'sGloNorm',sGloNorm);
1572
1573
1574
1575 %-Construct masking information structure and compute actual analysis
1576 % threshold using scaled globals (rg.*gSF)
1577 %-------------------------------------------------------------------
1578 if isreal(M_T), M_TH = M_T * ones(nScan,1); %-NB: -Inf is real
1579 else, M_TH = imag(M_T) * (rg.*gSF); end
1580
1581 if ~isempty(M_P)
1582 VM = spm_vol(char(M_P));
1583 xsM.Explicit_masking = [{'Yes: mask images :'};{VM.fname}'];
1584 else
1585 VM = [];
1586 xsM.Explicit_masking = 'No';
1587 end
1588 xM = struct('T',M_T, 'TH',M_TH, 'I',M_I, 'VM',{VM}, 'xs',xsM);
1589
1590
1591 %-Construct full design matrix (X), parameter names and structure (xX)
1592 %===================================================================
1593 X = [H C B G];
1594 tmp = cumsum([size(H,2), size(C,2), size(B,2), size(G,2)]);
1595 xX = struct( 'X', X,...
1596 'iH', [1:size(H,2)],...
1597 'iC', [1:size(C,2)] + tmp(1),...
1598 'iB', [1:size(B,2)] + tmp(2),...
1599 'iG', [1:size(G,2)] + tmp(3),...
1600 'name', {[Hnames; Cnames; Bnames; Gnames]},...
1601 'I', I,...
1602 'sF', {D.sF});
1603
1604
1605 %-Design description (an nx2 cellstr) - for saving and display
1606 %===================================================================
1607 tmp = { sprintf('%d condition, +%d covariate, +%d block, +%d nuisance',...
1608 size(H,2),size(C,2),size(B,2),size(G,2));...
1609 sprintf('%d total, having %d degrees of freedom',...
1610 size(X,2),rank(X));...
1611 sprintf('leaving %d degrees of freedom from %d images',...
1612 size(X,1)-rank(X),size(X,1)) };
1613 xsDes = struct( 'Design', {D.DesName},...
1614 'Global_calculation', {sGXcalc},...
1615 'Grand_mean_scaling', {sGMsca},...
1616 'Global_normalisation', {sGloNorm},...
1617 'Parameters', {tmp} );
1618
1619
1620 fprintf('%30s\n','...done') %-#
1621
1622
1623
1624 %-Assemble SPM structure
1625 %===================================================================
1626 SPM.xY.P = P; % filenames
1627 SPM.xY.VY = VY; % mapped data
1628 SPM.nscan = size(xX.X,1); % scan number
1629 SPM.xX = xX; % design structure
1630 SPM.xC = xC; % covariate structure
1631 SPM.xGX = xGX; % global structure
1632 SPM.xVi = xVi; % non-sphericity structure
1633 SPM.xM = xM; % mask structure
1634 SPM.xsDes = xsDes; % description
1635 SPM.SPMid = SPMid; % version
1636
1637 %-Save SPM.mat and set output argument
1638 %-------------------------------------------------------------------
1639 fprintf('%-40s: ','Saving SPM configuration') %-#
1640
1641 if spm_matlab_version_chk('7') >=0
1642 save('SPM', 'SPM', '-V6');
1643 else
1644 save('SPM', 'SPM');
1645 end;
1646 fprintf('%30s\n','...SPM.mat saved') %-#
1647 varargout = {SPM};
1648
1649 %-Display Design report
1650 %===================================================================
1651 fprintf('%-40s: ','Design reporting') %-#
1652 fname = cat(1,{SPM.xY.VY.fname}');
1653 spm_DesRep('DesMtx',SPM.xX,fname,SPM.xsDes)
1654 fprintf('%30s\n','...done')
1655
1656
1657 %-End: Cleanup GUI
1658 %===================================================================
1659 spm_clf(Finter)
1660 spm('Pointer','Arrow')
1661 fprintf('%-40s: %30s\n','Completed',spm('time')) %-#
1662 spm('FigName','Stats: configured',Finter,CmdLine);
1663 spm('Pointer','Arrow')
1664 fprintf('\n\n')
1665
1666
1667
1668 case 'files&indices'
1669 %===================================================================
1670 % - Get files and factor indices
1671 %===================================================================
1672 % [P,I] = spm_spm_ui('Files&Indices',DsF,Dn,DbaTime,nV)
1673 % DbaTime=D.b.aTime; Dn=D.n; DsF=D.sF;
1674 if nargin<5, nV = 1; else, nV = varargin{5}; end
1675 if nargin<4, DbaTime = 1; else, DbaTime = varargin{4}; end
1676 if nargin<3, Dn = [Inf,Inf,Inf,Inf]; else, Dn=varargin{3}; end
1677 if nargin<2, DsF = {'Fac1','Fac2','Fac3','Fac4'}; else, DsF=varargin{2}; end
1678
1679 %-Initialise variables
1680 %-------------------------------------------------------------------
1681 i4 = []; % factor 4 index (usually group)
1682 i3 = []; % factor 3 index (usually subject), per f4
1683 i2 = []; % factor 2 index (usually condition), per f3/f4
1684 i1 = []; % factor 1 index (usually replication), per f2/f3/f4
1685 P = {}; % cell array of string filenames
1686
1687 %-Accrue filenames and factor level indicator vectors
1688 %-------------------------------------------------------------------
1689 bMV = nV>1;
1690 if isinf(Dn(4)), n4 = spm_input(['#',DsF{4},'''s'],'+1','n1');
1691 else, n4 = Dn(4); end
1692 bL4 = n4>1;
1693
1694 ti2 = '';
1695 GUIpos = spm_input('!NextPos');
1696 for j4 = 1:n4
1697 spm_input('!SetNextPos',GUIpos);
1698 sF4P=''; if bL4, sF4P=[DsF{4},' ',int2str(j4),': ']; end
1699 if isinf(Dn(3)), n3=spm_input([sF4P,'#',DsF{3},'''s'],'+1','n1');
1700 else, n3 = Dn(3); end
1701 bL3 = n3>1;
1702
1703 if DbaTime & Dn(2)>1
1704 %disp('NB:selecting in time order - manually specify conditions')
1705 %-NB: This means f2 levels might not be 1:n2
1706 GUIpos2 = spm_input('!NextPos');
1707 for j3 = 1:n3
1708 sF3P=''; if bL3, sF3P=[DsF{3},' ',int2str(j3),': ']; end
1709 str = [sF4P,sF3P];
1710 tP = {};
1711 n21 = Dn(2)*Dn(1);
1712 for v=1:nV
1713 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
1714 ttP = cellstr(spm_select(n21,'image',[str,'select images',vstr]));
1715 n21 = length(ttP);
1716 tP = [tP,ttP];
1717 end
1718 ti2 = spm_input([str,' ',DsF{2},'?'],GUIpos2,'c',ti2',n21,Dn(2));
1719 %-Work out i1 & check
1720 [tl2,null,j] = unique(ti2);
1721 tn1 = zeros(size(tl2)); ti1 = zeros(size(ti2));
1722 for i=1:length(tl2)
1723 tn1(i)=sum(j==i); ti1(ti2==tl2(i))=1:tn1(i); end
1724 if isfinite(Dn(1)) & any(tn1~=Dn(1))
1725 %-#i1 levels mismatches specification in Dn(1)
1726 error(sprintf('#%s not %d as pre-specified',DsF{1},Dn(1)))
1727 end
1728 P = [P;tP];
1729 i4 = [i4; j4*ones(n21,1)];
1730 i3 = [i3; j3*ones(n21,1)];
1731 i2 = [i2; ti2];
1732 i1 = [i1; ti1];
1733 end
1734
1735 else
1736
1737 if isinf(Dn(2))
1738 n2 = spm_input([sF4P,'#',DsF{2},'''s'],'+1','n1');
1739 else
1740 n2 = Dn(2);
1741 end
1742 bL2 = n2>1;
1743
1744 if n2==1 & Dn(1)==1 %-single scan per f3 (subj)
1745 %disp('NB:single scan per f3')
1746 str = [sF4P,'select images, ',DsF{3},' 1-',int2str(n3)];
1747 tP = {};
1748 for v=1:nV
1749 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
1750 ttP = cellstr(spm_select(n3,'image',[str,vstr]));
1751 tP = [tP,ttP];
1752 end
1753 P = [P;tP];
1754 i4 = [i4; j4*ones(n3,1)];
1755 i3 = [i3; [1:n3]'];
1756 i2 = [i2; ones(n3,1)];
1757 i1 = [i1; ones(n3,1)];
1758 else
1759 %-multi scan per f3 (subj) case
1760 %disp('NB:multi scan per f3')
1761 for j3 = 1:n3
1762 sF3P=''; if bL3, sF3P=[DsF{3},' ',int2str(j3),': ']; end
1763 if Dn(1)==1
1764 %-No f1 (repl) within f2 (cond)
1765 %disp('NB:no f1 within f2')
1766 str = [sF4P,sF3P,'select images: ',DsF{2},...
1767 ' 1-',int2str(n2)];
1768 tP = {};
1769 for v=1:nV
1770 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
1771 ttP = cellstr(spm_select(n2,'image',[str,vstr]));
1772 tP = [tP,ttP];
1773 end
1774 P = [P;tP];
1775 i4 = [i4; j4*ones(n2,1)];
1776 i3 = [i3; j3*ones(n2,1)];
1777 i2 = [i2; [1:n2]'];
1778 i1 = [i1; ones(n2,1)];
1779 else
1780 %-multi f1 (repl) within f2 (cond)
1781 %disp('NB:f1 within f2')
1782 for j2 = 1:n2
1783 sF2P='';
1784 if bL2, sF2P=[DsF{2},' ',int2str(j2),': ']; end
1785 str = [sF4P,sF3P,sF2P,' select images...'];
1786 tP = {};
1787 n1 = Dn(1);
1788 for v=1:nV
1789 vstr=''; if bMV, vstr=sprintf(' (var-%d)',v); end
1790 ttP = cellstr(spm_select(n1,'image',[str,vstr]));
1791 n1 = length(ttP);
1792 tP = [tP,ttP];
1793 end
1794 P = [P;tP];
1795 i4 = [i4; j4*ones(n1,1)];
1796 i3 = [i3; j3*ones(n1,1)];
1797 i2 = [i2; j2*ones(n1,1)];
1798 i1 = [i1; [1:n1]'];
1799 end % (for j2)
1800 end % (if Dn(1)==1)
1801 end % (for j3)
1802 end % (if n2==1 &...)
1803 end % (if DbaTime & Dn(2)>1)
1804 end % (for j4)
1805 varargout = {P,[i1,i2,i3,i4]};
1806
1807 %%%%%%%%%%%%%%
1808 %start cbuhack
1809 %
1810
1811 case 'cbuhack'
1812 %=======================================================================
1813 % - Get files and factor indices from a file
1814 %=======================================================================
1815 % [P,I] = spm_spm_ui('cbuhack',DsF,Dn,DbaTime)
1816 % DbaTime=D.b.aTime; Dn=D.n; DsF=D.sF;
1817 if nargin<4, DbaTime = 1; else, DbaTime = varargin{4}; end
1818 if nargin<3, Dn = [Inf,Inf,Inf,Inf]; else, Dn=varargin{3}; end
1819 if nargin<2, DsF = {'Fac1','Fac2','Fac3','Fac4'}; else, DsF=varargin{2}; end
1820
1821 %-Initialise variables
1822 %-----------------------------------------------------------------------
1823 i4 = []; % factor 4 index (usually group)
1824 i3 = []; % factor 3 index (usually subject), per f4
1825 i2 = []; % factor 2 index (usually condition), per f3/f4
1826 i1 = []; % factor 1 index (usually replication), per f2/f3/f4
1827 P = {}; % cell array of string filenames
1828 cbu_covariates = [];
1829
1830 cbufilestuff=spm_select(1,'.csv');
1831 hash='';
1832 at='';
1833 start=0;
1834 cbu_factors='';
1835 cbu_factor_format='';
1836 cbu_indices='';
1837 cbu_cov_columns=0;
1838 cbu_cov_partition={};
1839 cbu_cov_block_labels={};
1840 cbu_cov_format='';
1841 cbu_count=[];
1842 cbuf=fopen(cbufilestuff,'r');
1843 cellstring='tmpstring=[''a'',int2str(t4),''b'',int2str(t3),''c'',int2str(t2)];';
1844 fullstring='GSCR';
1845
1846 while (feof(cbuf) == 0)
1847
1848 line = fgetl(cbuf);
1849
1850 if size(line, 2) == 0
1851 line='%'; % ignore blank lines
1852 end
1853
1854 if strcmp(line(1),'=') % '=' initialises stuff
1855 eval(line(2:size(line,2)));
1856
1857 elseif strcmp(line(1),'+') % '+' marks end of preamble
1858 start=1;
1859 if isempty(cbu_factors)
1860 cbu_factor_format='%d,%d,%d,%d,';
1861 cbu_factor_columns=4;
1862 else
1863 cbu_factor_columns=size(cbu_factors,2);
1864 end %cbu_factors
1865
1866 for j = 1:3
1867 i=findstr(fullstring(j),cbu_factors);
1868 if i
1869 cbu_factor_format = [cbu_factor_format,'%d,'];
1870 cbu_indices=[cbu_indices,'t',int2str(5-j),'=cbu_line(',int2str(i),');'];
1871 else
1872 cbu_indices=[cbu_indices,'t',int2str(5-j),'=1;'];
1873 end %if
1874 end %j
1875
1876 i=findstr('R',cbu_factors);
1877 if i
1878 cbu_factor_format = [cbu_factor_format,'%d,'];
1879 cbu_indices=[cbu_indices,'t1=cbu_line(',int2str(i),');'];
1880 else
1881 cbu_indices=[cbu_indices,cellstring,'if isfield(cbu_count,tmpstring),',...
1882 'tmpcnt=getfield(cbu_count,tmpstring)+1;',...
1883 't1=tmpcnt;cbu_count=setfield(cbu_count,tmpstring,tmpcnt);,',...
1884 'else t1=1;cbu_count=setfield(cbu_count,tmpstring,1);,end'];
1885 end %if
1886
1887 if cbu_cov_columns==0
1888 cbu_cov_format='';
1889 cbu_cov_blocknos=0;
1890 else
1891 for i = 1:cbu_cov_columns
1892 cbu_cov_format=[cbu_cov_format,'%g,'];
1893 end
1894 if isempty(cbu_cov_partition)
1895 cbu_cov_format='';
1896 cbu_cov_blocknos=0;
1897 else
1898 cbu_cov_blocknos=size(cbu_cov_partition,2);
1899 end
1900 end %cbu_cov_columns
1901
1902 cbu_columns=cbu_factor_columns+cbu_cov_columns;
1903
1904 elseif strcmp(line(1),'#') % '#' indicates a change of super-directory
1905 hash=strrep(line(2:size(line,2)),' ','');
1906
1907 elseif strcmp(line(1),'@') % '@' indicates a change subdirectory
1908 at=strrep(line(2:size(line,2)),' ','');
1909
1910 elseif ~strcmp(line(1),'%') % '%' is an ignorable comment line
1911 cbu_line = sscanf(line,[cbu_factor_format,cbu_cov_format,'%s\n']);
1912 cbu_file=char(cbu_line(cbu_columns+1:size(cbu_line,1))');
1913 cbu_covs = cbu_line(cbu_factor_columns+1:cbu_columns)';
1914 eval(cbu_indices);
1915 if findstr('#',cbu_file) | findstr('@',cbu_file)
1916 cbu_file = strrep(strrep(cbu_file,'#',hash),'@',at);
1917 elseif strncmp(cbu_file,'/',1)
1918 cbu_file = cbu_file;
1919 else
1920 cbu_file = [hash,at,cbu_file];
1921 end
1922 i4 = [i4; t4];
1923 i3 = [i3; t3];
1924 i2 = [i2; t2];
1925 i1 = [i1; t1];
1926 P = [ P; cellstr(strrep(cbu_file,' ',''))];
1927 cbu_covariates=[cbu_covariates;cbu_covs];
1928 end %if
1929 end %while
1930 fclose(cbuf);
1931 varargout = {P,[i1,i2,i3,i4], ...
1932 cbu_title, ...
1933 cbu_factors, ...
1934 cbu_factor_format, ...
1935 cbu_cov_columns, ...
1936 cbu_cov_partition, ...
1937 cbu_cov_block_labels, ...
1938 cbu_cov_format, ...
1939 cbu_covariates};
1940 %
1941 %end cbuhack
1942 %%%%%%%%%%%%
1943
1944 case 'desdefs_stats'
1945
1946 %===================================================================
1947 % - Basic Stats Design definitions...
1948 %===================================================================
1949 % D = spm_spm_ui('DesDefs_Stats');
1950 % These are the basic Stats design definitions...
1951
1952 %-Note: struct expands cell array values to give multiple records:
1953 % => must embed cell arrays within another cell array!
1954 %-Negative indices indicate defaults (first used)
1955
1956 D = struct(...
1957 'DesName','One sample t-test',...
1958 'n', [Inf 1 1 1], 'sF',{{'obs','','',''}},...
1959 'Hform', 'I(:,2),''-'',''mean''',...
1960 'Bform', '[]',...
1961 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1962 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
1963 'iGloNorm',9,'iGC',12,...
1964 'M_',struct('T',-Inf,'I',Inf,'X',Inf),...
1965 'b',struct('aTime',0));
1966
1967 D = [D, struct(...
1968 'DesName','Two sample t-test',...
1969 'n', [Inf 2 1 1], 'sF',{{'obs','group','',''}},...
1970 'Hform', 'I(:,2),''-'',''group''',...
1971 'Bform', 'I(:,3),''-'',''\mu''',...
1972 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1973 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
1974 'iGloNorm',9,'iGC',12,...
1975 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
1976 'b',struct('aTime',1))];
1977
1978 D = [D, struct(...
1979 'DesName','Paired t-test',...
1980 'n', [1 2 Inf 1], 'sF',{{'','cond','pair',''}},...
1981 'Hform', 'I(:,2),''-'',''condition''',...
1982 'Bform', 'I(:,3),''-'',''\gamma''',...
1983 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1984 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
1985 'iGloNorm',9,'iGC',12,...
1986 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
1987 'b',struct('aTime',0))];
1988
1989 D = [D, struct(...
1990 'DesName','One way Anova',...
1991 'n', [Inf Inf 1 1], 'sF',{{'repl','group','',''}},...
1992 'Hform', 'I(:,2),''-'',''group''',...
1993 'Bform', '[]',...
1994 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
1995 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
1996 'iGloNorm',9,'iGC',12,...
1997 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
1998 'b',struct('aTime',0))];
1999
2000 D = [D, struct(...
2001 'DesName','One way Anova (with constant)',...
2002 'n', [Inf Inf 1 1], 'sF',{{'repl','group','',''}},...
2003 'Hform', 'I(:,2),''-'',''group''',...
2004 'Bform', 'I(:,3),''-'',''\mu''',...
2005 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2006 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2007 'iGloNorm',9,'iGC',12,...
2008 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2009 'b',struct('aTime',0))];
2010
2011 D = [D, struct(...
2012 'DesName','One way Anova (Within-subjects)',...
2013 'n', [1 Inf Inf 1],'sF',{{'repl','condition','subject',''}},...
2014 'Hform', 'I(:,2),''-'',''cond''',...
2015 'Bform', 'I(:,3),''-'',''subj''',...
2016 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2017 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2018 'iGloNorm',9,'iGC',12,...
2019 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2020 'b',struct('aTime',0))];
2021
2022 D = [D, struct(...
2023 'DesName','Simple regression (correlation)',...
2024 'n', [Inf 1 1 1], 'sF',{{'repl','','',''}},...
2025 'Hform', '[]',...
2026 'Bform', 'I(:,2),''-'',''\mu''',...
2027 'nC',[1,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2028 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2029 'iGloNorm',9,'iGC',12,...
2030 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2031 'b',struct('aTime',0))];
2032
2033
2034 D = [D, struct(...
2035 'DesName','Multiple regression',...
2036 'n', [Inf 1 1 1], 'sF',{{'repl','','',''}},...
2037 'Hform', '[]',...
2038 'Bform', '[]',...
2039 'nC',[Inf,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2040 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2041 'iGloNorm',9,'iGC',12,...
2042 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2043 'b',struct('aTime',0))];
2044
2045 D = [D, struct(...
2046 'DesName','Multiple regression (with constant)',...
2047 'n', [Inf 1 1 1], 'sF',{{'repl','','',''}},...
2048 'Hform', '[]',...
2049 'Bform', 'I(:,2),''-'',''\mu''',...
2050 'nC',[Inf,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2051 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2052 'iGloNorm',9,'iGC',12,...
2053 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2054 'b',struct('aTime',0))];
2055
2056 D = [D, struct(...
2057 'DesName','AnCova',...
2058 'n', [Inf Inf 1 1], 'sF',{{'repl','group','',''}},...
2059 'Hform', 'I(:,2),''-'',''group''',...
2060 'Bform', 'I(:,3),''-'',''\mu''',...
2061 'nC',[0,1],'iCC',{{8,1}},'iCFI',{{1,1}},...
2062 'iGXcalc',[-1,2,3],'iGMsca',[1,-9],'GM',[],...
2063 'iGloNorm',9,'iGC',12,...
2064 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2065 'b',struct('aTime',0))];
2066
2067 varargout = {D};
2068
2069
2070 case 'desdefs_pet'
2071 %===================================================================
2072 % - Standard (SPM99) PET/SPECT Design definitions...
2073 %===================================================================
2074 % D = spm_spm_ui('DesDefs_PET');
2075 % These are the standard PET design definitions...
2076
2077 %-Single subject
2078 %-------------------------------------------------------------------
2079 D = struct(...
2080 'DesName','Single-subject: conditions & covariates',...
2081 'n', [Inf Inf 1 1], 'sF',{{'repl','condition','',''}},...
2082 'Hform', 'I(:,2),''-'',''cond''',...
2083 'Bform', 'I(:,3),''-'',''\mu''',...
2084 'nC',[Inf,Inf],'iCC',{{[-1,3,8],[-1,8]}},'iCFI',{{[1,3],1}},...
2085 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2086 'iGloNorm',[1,8,9],'iGC',10,...
2087 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2088 'b',struct('aTime',1));
2089
2090 D = [D, struct(...
2091 'DesName','Single-subject: covariates only',...
2092 'n', [Inf 1 1 1], 'sF',{{'repl','','',''}},...
2093 'Hform', '[]',...
2094 'Bform', 'I(:,3),''-'',''\mu''',...
2095 'nC',[Inf,Inf],'iCC',{{[-1,8],[-1,8]}},'iCFI',{{1,1}},...
2096 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2097 'iGloNorm',[1,8,9],'iGC',10,...
2098 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2099 'b',struct('aTime',1))];
2100
2101 %-Multi-subject
2102 %-------------------------------------------------------------------
2103 D = [D, struct(...
2104 'DesName','Multi-subj: conditions & covariates',...
2105 'n',[Inf Inf Inf 1], 'sF',{{'repl','condition','subject',''}},...
2106 'Hform', 'I(:,2),''-'',''cond''',...
2107 'Bform', 'I(:,3),''-'',''subj''',...
2108 'nC',[Inf,Inf],'iCC',{{[1,3,4,8],[1,4,8]}},'iCFI',{{[1,3,-4],[1,-4]}},...
2109 'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
2110 'iGloNorm',[4,8,9],'iGC',10,...
2111 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2112 'b',struct('aTime',1))];
2113
2114 D = [D, struct(...
2115 'DesName','Multi-subj: cond x subj interaction & covariates',...
2116 'n',[Inf Inf Inf 1], 'sF',{{'repl','condition','subject',''}},...
2117 'Hform', 'I(:,[3,2]),''-'',{''subj'',''cond''}',...
2118 'Bform', 'I(:,3),''-'',''subj''',...
2119 'nC',[Inf,Inf],'iCC',{{[1,3,4,8],[1,4,8]}},'iCFI',{{[1,3,-4],[1,-4]}},...
2120 'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
2121 'iGloNorm',[4,8,9],'iGC',10,...
2122 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2123 'b',struct('aTime',1))];
2124
2125 D = [D, struct(...
2126 'DesName','Multi-subj: covariates only',...
2127 'n',[Inf 1 Inf 1], 'sF',{{'repl','','subject',''}},...
2128 'Hform', '[]',...
2129 'Bform', 'I(:,3),''-'',''subj''',...
2130 'nC',[Inf,Inf],'iCC',{{[1,4,8],[1,4,8]}},'iCFI',{{[1,-4],[1,-4]}},...
2131 'iGXcalc',[1,2,-3],'iGMsca',[-4,9],'GM',50,...
2132 'iGloNorm',[4,8:9],'iGC',10,...
2133 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2134 'b',struct('aTime',0))];
2135
2136 %-Multi-group
2137 %-------------------------------------------------------------------
2138 D = [D, struct(...
2139 'DesName','Multi-group: conditions & covariates',...
2140 'n',[Inf Inf Inf Inf], 'sF',{{'repl','condition','subject','group'}},...
2141 'Hform', 'I(:,[4,2]),''-'',{''stud'',''cond''}',...
2142 'Bform', 'I(:,[4,3]),''-'',{''stud'',''subj''}',...
2143 'nC',[Inf,Inf],'iCC',{{[5:8],[5,7,8]}},'iCFI',{{[1,5,6,-7],[1,5,-7]}},...
2144 'iGXcalc',[1,2,-3],'iGMsca',[-7,9],'GM',50,...
2145 'iGloNorm',[7,8,9],'iGC',10,...
2146 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2147 'b',struct('aTime',1))];
2148
2149 D = [D, struct(...
2150 'DesName','Multi-group: covariates only',...
2151 'n',[Inf 1 Inf Inf], 'sF',{{'repl','','subject','group'}},...
2152 'Hform', '[]',...
2153 'Bform', 'I(:,[4,3]),''-'',{''stud'',''subj''}',...
2154 'nC',[Inf,Inf],'iCC',{{[5,7,8],[5,7,8]}},'iCFI',{{[1,5,-7],[1,5,-7]}},...
2155 'iGXcalc',[1,2,-3],'iGMsca',[-7,9],'GM',50,...
2156 'iGloNorm',[7,8,9],'iGC',10,...
2157 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2158 'b',struct('aTime',0))];
2159
2160 %-Population comparisons
2161 %-------------------------------------------------------------------
2162 D = [D, struct(...
2163 'DesName',...
2164 'Population main effect: 2 cond''s, 1 scan/cond (paired t-test)',...
2165 'n',[1 2 Inf 1], 'sF',{{'','condition','subject',''}},...
2166 'Hform', 'I(:,2),''-'',''cond''',...
2167 'Bform', 'I(:,3),''-'',''\mu''',...
2168 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2169 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2170 'iGloNorm',[8,9],'iGC',10,...
2171 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2172 'b',struct('aTime',0))];
2173
2174 D = [D, struct(...
2175 'DesName',...
2176 'Dodgy population main effect: >2 cond''s, 1 scan/cond',...
2177 'n',[1 Inf Inf 1], 'sF',{{'','condition','subject',''}},...
2178 'Hform', 'I(:,2),''-'',''cond''',...
2179 'Bform', 'I(:,3),''-'',''\mu''',...
2180 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2181 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2182 'iGloNorm',[8,9],'iGC',10,...
2183 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2184 'b',struct('aTime',0))];
2185
2186 D = [D, struct(...
2187 'DesName','Compare-populations: 1 scan/subject (two sample t-test)',...
2188 'n',[Inf 2 1 1], 'sF',{{'subject','group','',''}},...
2189 'Hform', 'I(:,2),''-'',''group''',...
2190 'Bform', 'I(:,3),''-'',''\mu''',...
2191 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2192 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2193 'iGloNorm',[8,9],'iGC',10,...
2194 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2195 'b',struct('aTime',0))];
2196
2197 D = [D, struct(...
2198 'DesName','Compare-populations: 1 scan/subject (AnCova)',...
2199 'n',[Inf 2 1 1], 'sF',{{'subject','group','',''}},...
2200 'Hform', 'I(:,2),''-'',''group''',...
2201 'Bform', 'I(:,3),''-'',''\mu''',...
2202 'nC',[0,Inf],'iCC',{{8,1}},'iCFI',{{1,1}},...
2203 'iGXcalc',[1,2,-3],'iGMsca',[-1,9],'GM',50,...
2204 'iGloNorm',[1,8,9],'iGC',10,...
2205 'M_',struct('T',[0,0.8*sqrt(-1)],'I',0,'X',0),...
2206 'b',struct('aTime',0))];
2207
2208 %-The Full Monty!
2209 %-------------------------------------------------------------------
2210 D = [D, struct(...
2211 'DesName','The Full Monty...',...
2212 'n',[Inf Inf Inf Inf], 'sF',{{'repl','cond','subj','group'}},...
2213 'Hform', 'I(:,[4,2]),''-'',{''stud'',''cond''}',...
2214 'Bform', 'I(:,[4,3]),''-'',{''stud'',''subj''}',...
2215 'nC',[Inf,Inf],'iCC',{{[1:8],[1:8]}},'iCFI',{{[1:7],[1:7]}},...
2216 'iGXcalc',[1,2,3],'iGMsca',[1:7],'GM',50,...
2217 'iGloNorm',[1:9],'iGC',[1:11],...
2218 'M_',struct('T',[-Inf,0,0.8*sqrt(-1)],'I',Inf,'X',Inf),...
2219 'b',struct('aTime',1))];
2220
2221
2222 varargout = {D};
2223
2224 case 'desdefs_pet96'
2225 %===================================================================
2226 % - SPM96 PET/SPECT Design definitions...
2227 %===================================================================
2228 % D = spm_spm_ui('DesDefs_PET96');
2229
2230 %-Single subject
2231 %-------------------------------------------------------------------
2232 D = struct(...
2233 'DesName','SPM96:Single-subject: replicated conditions',...
2234 'n', [Inf Inf 1 1], 'sF',{{'repl','condition','',''}},...
2235 'Hform', 'I(:,2),''-'',''cond''',...
2236 'Bform', 'I(:,3),''-'',''\mu''',...
2237 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2238 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2239 'iGloNorm',[1,8,9],'iGC',10,...
2240 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2241 'b',struct('aTime',0));
2242
2243 D = [D, struct(...
2244 'DesName','SPM96:Single-subject: replicated conditions & covariates',...
2245 'n', [Inf Inf 1 1], 'sF',{{'repl','condition','',''}},...
2246 'Hform', 'I(:,2),''-'',''cond''',...
2247 'Bform', 'I(:,3),''-'',''\mu''',...
2248 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{1,1}},...
2249 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2250 'iGloNorm',[1,8,9],'iGC',10,...
2251 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2252 'b',struct('aTime',0))];
2253
2254 D = [D, struct(...
2255 'DesName','SPM96:Single-subject: covariates only',...
2256 'n', [Inf 1 1 1], 'sF',{{'repl','','',''}},...
2257 'Hform', '[]',...
2258 'Bform', 'I(:,3),''-'',''\mu''',...
2259 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{1,1}},...
2260 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2261 'iGloNorm',[1,8,9],'iGC',10,...
2262 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2263 'b',struct('aTime',0))];
2264
2265 %-Multi-subject
2266 %-------------------------------------------------------------------
2267 D = [D, struct(...
2268 'DesName','SPM96:Multi-subject: different conditions',...
2269 'n', [1 Inf Inf 1], 'sF',{{'','condition','subject',''}},...
2270 'Hform', 'I(:,2),''-'',''scancond''',...
2271 'Bform', 'I(:,3),''-'',''subj''',...
2272 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2273 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2274 'iGloNorm',[1,4,8,9],'iGC',10,...
2275 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2276 'b',struct('aTime',0))];
2277
2278 D = [D, struct(...
2279 'DesName','SPM96:Multi-subject: replicated conditions',...
2280 'n',[Inf Inf Inf 1], 'sF',{{'repl','condition','subject',''}},...
2281 'Hform', 'I(:,2),''-'',''cond''',...
2282 'Bform', 'I(:,3),''-'',''subj''',...
2283 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2284 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2285 'iGloNorm',[1,4,8,9],'iGC',10,...
2286 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2287 'b',struct('aTime',0))];
2288
2289 D = [D, struct(...
2290 'DesName','SPM96:Multi-subject: different conditions & covariates',...
2291 'n', [1 Inf Inf 1], 'sF',{{'','condition','subject',''}},...
2292 'Hform', 'I(:,2),''-'',''cond''',...
2293 'Bform', 'I(:,3),''-'',''subj''',...
2294 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,4],[1,4]}},...
2295 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2296 'iGloNorm',[1,4,8,9],'iGC',10,...
2297 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2298 'b',struct('aTime',0))];
2299
2300 D = [D, struct(...
2301 'DesName','SPM96:Multi-subject: replicated conditions & covariates',...
2302 'n',[Inf Inf Inf 1], 'sF',{{'repl','condition','subject',''}},...
2303 'Hform', 'I(:,2),''-'',''condition''',...
2304 'Bform', 'I(:,3),''-'',''subj''',...
2305 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,3,4],[1,4]}},...
2306 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2307 'iGloNorm',[1,4,8,9],'iGC',10,...
2308 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2309 'b',struct('aTime',0))];
2310
2311 D = [D, struct(...
2312 'DesName','SPM96:Multi-subject: covariates only',...
2313 'n',[Inf 1 Inf 1], 'sF',{{'repl','','subject',''}},...
2314 'Hform', '[]',...
2315 'Bform', 'I(:,3),''-'',''subj''',...
2316 'nC',[Inf,Inf],'iCC',{{[1,4,8],[1,4,8]}},'iCFI',{{[1,4],[1,4]}},...
2317 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2318 'iGloNorm',[1,4,8,9],'iGC',10,...
2319 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2320 'b',struct('aTime',0))];
2321
2322 %-Multi-study
2323 %-------------------------------------------------------------------
2324 D = [D, struct(...
2325 'DesName','SPM96:Multi-study: different conditions',...
2326 'n',[1 Inf Inf Inf], 'sF',{{'','cond','subj','study'}},...
2327 'Hform', 'I(:,[4,2]),''-'',{''study'',''cond''}',...
2328 'Bform', 'I(:,[4,3]),''-'',{''study'',''subj''}',...
2329 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2330 'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
2331 'iGloNorm',[1,5,7,8,9],'iGC',10,...
2332 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2333 'b',struct('aTime',0))];
2334
2335 D = [D, struct(...
2336 'DesName','SPM96:Multi-study: replicated conditions',...
2337 'n',[Inf Inf Inf Inf], 'sF',{{'repl','cond','subj','study'}},...
2338 'Hform', 'I(:,[4,2]),''-'',{''study'',''condition''}',...
2339 'Bform', 'I(:,[4,3]),''-'',{''study'',''subj''}',...
2340 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2341 'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
2342 'iGloNorm',[1,5,7,8,9],'iGC',10,...
2343 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2344 'b',struct('aTime',0))];
2345
2346 D = [D, struct(...
2347 'DesName','SPM96:Multi-study: different conditions & covariates',...
2348 'n',[1 Inf Inf Inf], 'sF',{{'','cond','subj','study'}},...
2349 'Hform', 'I(:,[4,2]),''-'',{''study'',''cond''}',...
2350 'Bform', 'I(:,[4,3]),''-'',{''study'',''subj''}',...
2351 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,6,7],[1,5,7]}},...
2352 'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
2353 'iGloNorm',[1,5,7,8,9],'iGC',10,...
2354 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2355 'b',struct('aTime',0))];
2356
2357 D = [D, struct(...
2358 'DesName','SPM96:Multi-study: replicated conditions & covariates',...
2359 'n',[Inf Inf Inf Inf], 'sF',{{'','cond','subj','study'}},...
2360 'Hform', 'I(:,[4,2]),''-'',{''study'',''condition''}',...
2361 'Bform', 'I(:,[4,3]),''-'',{''study'',''subj''}',...
2362 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,6,7],[1,5,7]}},...
2363 'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
2364 'iGloNorm',[1,5,7,8,9],'iGC',10,...
2365 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2366 'b',struct('aTime',0))];
2367
2368 D = [D, struct(...
2369 'DesName','SPM96:Multi-study: covariates only',...
2370 'n',[Inf 1 Inf Inf], 'sF',{{'repl','','subj','study'}},...
2371 'Hform', '[]',...
2372 'Bform', 'I(:,[4,3]),''-'',{''study'',''subj''}',...
2373 'nC',[Inf,Inf],'iCC',{{1,1}},'iCFI',{{[1,5,7],[1,5,7]}},...
2374 'iGXcalc',3,'iGMsca',[1,5,9],'GM',50,...
2375 'iGloNorm',[1,5,7,8,9],'iGC',10,...
2376 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2377 'b',struct('aTime',0))];
2378
2379 %-Group comparisons
2380 %-------------------------------------------------------------------
2381 D = [D, struct(...
2382 'DesName','SPM96:Compare-groups: 1 scan per subject',...
2383 'n',[Inf Inf 1 1], 'sF',{{'subject','group','',''}},...
2384 'Hform', 'I(:,2),''-'',''group''',...
2385 'Bform', '[]',...
2386 'nC',[0,0],'iCC',{{8,8}},'iCFI',{{1,1}},...
2387 'iGXcalc',3,'iGMsca',[1,9],'GM',50,...
2388 'iGloNorm',[1,8,9],'iGC',10,...
2389 'M_',struct('T',[0.8*sqrt(-1)],'I',0,'X',0),...
2390 'b',struct('aTime',0))];
2391
2392 varargout = {D};
2393
2394
2395 otherwise
2396 %===================================================================
2397 % - U N K N O W N A C T I O N
2398 %===================================================================
2399 warning(['Illegal Action string: ',Action])
2400
2401 %===================================================================
2402 % - E N D
2403 %===================================================================
2404 end
2405
2406 %=======================================================================
2407 %- S U B - F U N C T I O N S
2408 %=======================================================================
2409
2410 function str = sf_estrrep(str,srstr)
2411 %=======================================================================
2412 for i = 1:size(srstr,1)
2413 str = strrep(str,srstr{i,1},srstr{i,2});
2414 end
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.