-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_takeargs.m
2818 lines (2518 loc) · 98.6 KB
/
palm_takeargs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [opts,plm] = palm_takeargs(varargin)
% Handle the inputs for PALM.
%
% _____________________________________
% Anderson M. Winkler
% FMRIB / University of Oxford
% Oct/2014
% http://brainder.org
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% PALM -- Permutation Analysis of Linear Models
% Copyright (C) 2015 Anderson M. Winkler
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Load the defaults
opts = palm_defaults;
% As varargin is actually from another function, fix it.
if nargin == 1
if exist(varargin{1},'file')
vararginx = palm_configrw(varargin{1});
else
error('Unknown option or file not found: %s',varargin{1});
end
else
vararginx = varargin;
idxa = find(strcmpi(vararginx,'-o'));
if isempty(idxa)
otmp = opts.o;
else
otmp = vararginx{idxa+1};
end
if ~ strcmp(otmp(end),'_')
otmp = horzcat(otmp,'_');
end
cfgname = horzcat(otmp,'palmconfig.txt');
[opth,~,~] = fileparts(cfgname);
if ~isempty(opth) && ~exist(opth,'dir')
mkdir(opth);
end
palm_configrw(vararginx,cfgname);
end
% Number of input images/masks/surfaces
% These are NOT meant to be edited.
Ni = sum(strcmp(vararginx,'-i')); % number of data inputs
Nm = sum(strcmp(vararginx,'-m')); % number of masks
Ns = sum(strcmp(vararginx,'-s')); % number of surfaces
Nd = sum(strcmp(vararginx,'-d')); % number of design files
Nimiss = sum(strcmp(vararginx,'-imiss')); % number of missing indicators for inputs
Ndmiss = sum(strcmp(vararginx,'-dmiss')); % number of missing indicators for designs
Nt = sum(strcmp(vararginx,'-t')); % number of t-contrast files
Nf = sum(strcmp(vararginx,'-f')); % number of F-test files
Ncon = sum(strcmp(vararginx,'-con')); % number of contrast files (t or F, mset format)
Nevd = sum(strcmp(vararginx,'-evperdat')); % number of EV per datum inputs
opts.i = cell(Ni,1); % Input files (to constitute Y later)
opts.m = cell(Nm,1); % Mask file(s)
opts.s = cell(Ns,1); % Surface file(s)
opts.sa = cell(Ns,1); % Area file(s) or weight(s)
opts.d = cell(Nd,1); % Design file(s)
opts.imiss = cell(Nd,1); % Design file(s)
opts.dmiss = cell(Nd,1); % Design file(s)
opts.t = cell(Nt,1); % t contrast file(s)
opts.f = opts.t; % F contrast file(s)
opts.Ccon = cell(Ncon,1); % Contrast file(s) (t or F, mset format)
opts.Dcon = cell(Ncon,1); % Contrast file(s) (multivariate, mset format)
opts.eb = []; % File with definition of exchangeability blocks
opts.vg = []; % File with definition of variance groups
opts.EE = false; % To be filled below (don't edit this!)
opts.ISE = false; % To be filled below (don't edit this!)
opts.within = false; % To be filled below (don't edit this!)
opts.whole = false; % To be filled below (don't edit this!)
opts.conskipcount = 0; % When saving the contrasts, skip how many from 1?
opts.singlevg = true; % Make sure that sigle VG will be used if nothing is supplied (this is NOT a "default" setting, and it's not a setting at all, but hard coded. Don't edit it!)
opts.subjidx = []; % Filename of the indices of subjects to keep
plm.subjidx = []; % Indices of subjects to keep
% These are to be incremented below
i = 1; m = 1; d = 1;
t = 1; s = 1;
con = 1; ev = 1;
imiss = 1; dmiss = 1;
% Remove trailing empty arguments. This is useful for some Octave versions.
while numel(vararginx) > 0 && isempty(vararginx{1})
vararginx(1) = [];
end
narginx = numel(vararginx);
% Take the input arguments
a = 1;
while a <= narginx
switch vararginx{a}
case {'-help','-?','-basic','-advanced'}
% Do nothing, as these options are parsed separately,
% and should anyway be given without any other argument.
a = a + 1;
case '-i' % basic
% Get the filenames for the data.
opts.i{i} = vararginx{a+1};
i = i + 1;
a = a + 2;
case '-m' % basic
% Get the filenames for the masks, if any.
opts.m{m} = vararginx{a+1};
m = m + 1;
a = a + 2;
case {'-s','-surf'} % basic
% Get the filenames for the surfaces, if any.
opts.s{s} = vararginx{a+1};
if nargin == a+1 || (narginx>a+1 && strcmp(vararginx{a+2}(1),'-'))
opts.sa{s} = [];
a = a + 2;
else
opts.sa{s} = vararginx{a+2};
a = a + 3;
end
s = s + 1;
case '-d' % basic
% Get the design matrix file.
opts.d{d} = vararginx{a+1};
d = d + 1;
a = a + 2;
case '-evperdat' % advanced
% Use one EV per datum?
opts.evperdat = true;
opts.evdatfile{ev} = vararginx{a+1};
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
opts.evpos{ev}(1) = 1; % EV position
opts.evpos{ev}(2) = 1; % Design number
a = a + 2;
elseif nargin == a + 2 || ...
ischar(vararginx{a+3}) && ...
strcmpi(vararginx{a+3}(1),'-')
if ischar(vararginx{a+2}) % EV position
opts.evpos{ev}(1) = eval(vararginx{a+2});
else
opts.evpos{ev}(1) = vararginx{a+2};
end
opts.evpos{ev}(2) = 1; % Design number
a = a + 3;
else
if ischar(vararginx{a+2}) % EV position
opts.evpos{ev}(1) = eval(vararginx{a+2});
else
opts.evpos{ev}(1) = vararginx{a+2};
end
if ischar(vararginx{a+3}) % Design number
opts.evpos{ev}(2) = eval(vararginx{a+3});
else
opts.evpos{ev}(2) = vararginx{a+3};
end
a = a + 4;
end
ev = ev + 1;
case '-imiss' % basic
% Get the filenames for the missing data indicators (inputs).
opts.imiss{imiss} = vararginx{a+1};
imiss = imiss + 1;
a = a + 2;
case '-dmiss' % basic
% Get the filenames for the missing data indicators (designs).
opts.dmiss{dmiss} = vararginx{a+1};
dmiss = dmiss + 1;
a = a + 2;
case '-mcar'
% For the missing data, treat as missing completely at random.
opts.mcar = true;
a = a + 1;
case '-t' % basic
% Get the t contrast files.
opts.t{t} = vararginx{a+1};
t = t + 1;
a = a + 2;
case '-f' % basic
% Get the F contrast files.
if t == 1
error('The option "-f" cannot be specified before its respective "-t".');
end
opts.f{t-1} = vararginx{a+1};
a = a + 2;
case '-con' % advanced
% Get the contrast files from an .mset file or
% pair of files. If a pair, the 1st is for Cset
% and the second for Dset.
opts.Ccon{con} = vararginx{a+1};
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
opts.Dcon{con} = [];
a = a + 2;
else
opts.Dcon{con} = vararginx{a+2};
a = a + 3;
end
con = con + 1;
case '-conskipcount' % advanced
% Numbers to skip when saving the contrasts
opts.conskipcount = vararginx{a+1};
if ischar(opts.conskipcount)
opts.conskipcount = str2double(opts.conskipcount);
end
a = a + 2;
case '-tonly' % advanced
% Run only the t-contrasts
opts.tonly = true;
a = a + 1;
case '-fonly' % basic
% Run only the F-contrasts
opts.fonly = true;
a = a + 1;
case '-eb' % basic
% Get the exchangeability blocks file.
opts.eb = vararginx{a+1};
a = a + 2;
case '-vg' % basic
% Get the variance groups file.
opts.vg = vararginx{a+1};
if ischar(opts.vg) && ...
any(strcmpi(opts.vg,{'single'}))
opts.vg = 'single';
opts.singlevg = true;
elseif ischar(opts.vg) && ...
any(strcmpi(opts.vg,{'auto','automatic'}))
opts.vg = 'auto';
opts.singlevg = false;
else
opts.singlevg = false;
end
a = a + 2;
case '-swe' % advanced
% Compute one (of various possible) sandwich estimators
opts.SwE = true;
a = a + 1;
case '-o' % basic
% Output prefix for the files to be saved.
opts.o = vararginx{a+1};
a = a + 2;
case '-n' % basic
% Number of permutations
opts.nP0 = vararginx{a+1};
if ischar(opts.nP0)
opts.nP0 = str2double(opts.nP0);
end
a = a + 2;
case '-C' % basic
% Threshold for cluster extent, univariate, NPC and MV
opts.cluster.uni.do = true;
opts.cluster.uni.thr = vararginx{a+1};
if ischar(opts.cluster.uni.thr)
opts.cluster.uni.thr = str2double(opts.cluster.uni.thr);
end
opts.cluster.npc.do = true;
opts.cluster.npc.thr = vararginx{a+1};
if ischar(opts.cluster.npc.thr)
opts.cluster.npc.thr = str2double(opts.cluster.npc.thr);
end
opts.cluster.mv.do = true;
opts.cluster.mv.thr = vararginx{a+1};
if ischar(opts.cluster.mv.thr)
opts.cluster.mv.thr = str2double(opts.cluster.mv.thr);
end
a = a + 2;
case '-Cuni' % advanced
% Threshold for cluster statistic, univariate
opts.cluster.uni.do = true;
opts.cluster.uni.thr = vararginx{a+1};
if ischar(opts.cluster.uni.thr)
opts.cluster.uni.thr = str2double(opts.cluster.uni.thr);
end
a = a + 2;
case '-Cnpc' % advanced
% Threshold for cluster statistic, NPC
opts.NPC = true;
opts.cluster.npc.do = true;
opts.cluster.npc.thr = vararginx{a+1};
if ischar(opts.cluster.npc.thr)
opts.cluster.npc.thr = str2double(opts.cluster.npc.thr);
end
a = a + 2;
case '-Cmv' % advanced
% Threshold for cluster statistic, MV
opts.MV = true;
opts.cluster.mv.do = true;
opts.cluster.mv.thr = vararginx{a+1};
if ischar(opts.cluster.mv.thr)
opts.cluster.mv.thr = str2double(opts.cluster.mv.thr);
end
a = a + 2;
case '-Cstat' % advanced
% Type of cluster statistic
opts.cluster.stat = vararginx{a+1};
if ~ any(strcmp(opts.cluster.stat,{'extent','mass','density','tippett','pivotal'}))
error('Cluster statistic "%s" unknown.',opts.cluster.stat);
end
a = a + 2;
case '-T' % basic
% Do TFCE for univariate, NPC and MV?
opts.tfce.uni.do = true;
opts.tfce.npc.do = true;
opts.tfce.mv.do = true;
opts.tfce.stat = 'tfce';
a = a + 1;
case '-Tstat' % not in the help
% Type of cluster statistic
opts.tfce.stat = vararginx{a+1};
if ~ any(strcmp(opts.tfce.stat,{'tfce','density','tippett'}))
error('TFCE statistic "%s" unknown.',opts.tfce.stat);
end
a = a + 2;
case '-Tuni' % advanced
% Do TFCE for uni?
opts.tfce.uni.do = true;
a = a + 1;
case '-Tnpc' % advanced
% Do TFCE for NPC?
opts.NPC = true;
opts.tfce.npc.do = true;
a = a + 1;
case '-Tmv' % advanced
% Do TFCE for MV?
opts.MV = true;
opts.tfce.mv.do = true;
a = a + 1;
case {'-tfce1D','-tfce1d'} % basic
% Shortcut for -tfce_H 2 -tfce_E 2 -tfce_C 6,
% i.e., parameters for TFCE in 2D mode
opts.tfce.H = 2;
opts.tfce.E = 2;
opts.tfce.conn = 6;
a = a + 1;
case {'-tfce2D','-tfce2d'} % basic
% Shortcut for -tfce_H 2 -tfce_E 1 -tfce_C 26,
% i.e., parameters for TFCE in 2D mode
opts.tfce.H = 2;
opts.tfce.E = 1;
opts.tfce.conn = 26;
a = a + 1;
case {'-tfce_H','-tfce_h'} % advanced
% TFCE H parameter
opts.tfce.H = vararginx{a+1};
if ischar(opts.tfce.H)
opts.tfce.H = str2double(opts.tfce.H);
end
a = a + 2;
case {'-tfce_E','-tfce_e'} % advanced
% TFCE E parameter
opts.tfce.E = vararginx{a+1};
if ischar(opts.tfce.E)
opts.tfce.E = str2double(opts.tfce.E);
end
a = a + 2;
case {'-tfce_C','-tfce_c'} % advanced
% TFCE connectivity
opts.tfce.conn = vararginx{a+1};
if ischar(opts.tfce.conn)
opts.tfce.conn = str2double(opts.tfce.conn);
end
a = a + 2;
case '-tfce_dh' % advanced
% TFCE delta-h parameter
opts.tfce.deltah = vararginx{a+1};
if ischar(opts.tfce.deltah)
if strcmpi(opts.tfce.deltah,'auto')
opts.tfce.deltah = 0;
else
opts.tfce.deltah = str2double(opts.tfce.deltah);
end
end
a = a + 2;
case '-tableasvolume' % basic
% Treat tables (e.g., CSV inputs) as volume, such that TFCE can
% be calculated. This is useful for TFCE over timeseries.
opts.tableasvolume = true;
a = a + 1;
case '-within' % basic
% Define whether should permute blocks as a whole or not
opts.within = true;
a = a + 1;
case '-whole' % basic
% Define whether should permute blocks as a whole or not
opts.whole = true;
a = a + 1;
case '-ee' % basic
% Exchangeable errors (EE)?
% If yes, this means permutations.
opts.EE = true;
a = a + 1;
case '-ise' % basic
% Independent and symmetric errors (ISE)?
% If yes, this means sign-flippings.
opts.ISE = true;
a = a + 1;
case '-cmcp' % advanced
% Define whether Conditional Monte Carlo should be used or not,
% that is, ignoring repeated elements in the permutation set.
opts.cmcp = true;
a = a + 1;
case '-cmcx' % advanced
% Define whether repeated rows in X should be ignored or not
% when defining the permutations, which constitutes another
% form of CMC
opts.cmcx = true;
a = a + 1;
case '-twotail' % basic
% Do a two-tailed test for all t-contrasts?
opts.twotail = true;
a = a + 1;
case '-concordant' % basic
% For the NPC, favour alternatives with the same sign?
opts.concordant = true;
a = a + 1;
case '-reversemasks' % basic
% Reverse masks.
opts.reversemasks = true;
a = a + 1;
case '-corrmod' % basic
% Correct over modalities.
opts.corrmod = true;
a = a + 1;
case '-corrcon' % basic
% Correct over contrasts.
opts.corrcon = true;
a = a + 1;
case '-saveparametric' % advanced
% If the user wants to have also the parametric p-values.
opts.savepara = true;
a = a + 1;
case '-saveglm' % advanced
% If the user wants, save COPE and VARCOPEs in the 1st
% permutation.
opts.saveglm = true;
a = a + 1;
case {'-savecdf','-save1-p'} % basic
% Save 1-p values (CDF) instead of the P-values
opts.savecdf = true;
a = a + 1;
case '-logp' % basic
% Convert the P-values or (1-P)-values to -log10 before saving.
opts.savelogp = true;
a = a + 1;
case '-savemask' % advanced
% If the user wants to have also the masks used for each.
% modality
opts.savemask = true;
a = a + 1;
case '-rmethod' % advanced
% Which method to use for the regression/permutation?
if narginx > a
methlist = { ...
'Draper-Stoneman', ...
'Still-White', ...
'Freedman-Lane', ...
'terBraak', ...
'Kennedy', ... % Kennedy won't be in the help
'Manly', ...
'Huh-Jhun', ...
'Dekker'};
methidx = strcmpi(vararginx{a+1},methlist);
if ~any(methidx)
error('Regression/Permutation method "%s" unknown.',vararginx{a+1});
else
a = a + 2;
end
opts.rmethod = methlist{methidx};
else
error([...
'The option -rmethod requires a method to be specified.\n'...
'Consult the documentation.%s'],'');
end
case '-npc' % basic
% This is a shortcut to enable NPC with the default settings.
opts.NPC = true;
opts.npcmod = true;
a = a + 1;
case '-npcmethod' % basic
% Do the non-parametric combination?
if nargin == a || (nargin > a && strcmp(vararginx{a+1}(1),'-'))
error('The option "-npcmethod" requires a combining method to be indicated.');
elseif nargin > a
% Which combining function to use for the combination?
methlist = { ...
'Tippett', ...
'Fisher', ...
'Pearson-David', ...
'Stouffer', ...
'Wilkinson', ...
'Winer', ...
'Edgington', ...
'Mudholkar-George', ...
'Friston', ...
'Darlington-Hayes', ...
'Zaykin', ...
'Dudbridge-Koeleman', ...
'Dudbridge-Koeleman2', ...
'Taylor-Tibshirani', ...
'Jiang'};
methidx = strcmpi(vararginx{a+1},methlist);
% Check if method exists, and load extra parameters if needed
if ~any(methidx)
error('Combining method "%s" unknown.',vararginx{a+1});
elseif any(strcmpi(vararginx{a+1},{...
'Wilkinson', ...
'Zaykin', ...
'Jiang'}))
if ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
plm.npcparm = 0.05;
a = a + 2;
elseif ischar(vararginx{a+2})
a = a + 3;
plm.npcparm = eval(vararginx{a+2});
else
plm.npcparm = vararginx{a+2};
a = a + 3;
end
elseif any(strcmpi(vararginx{a+1},{...
'Darlington-Hayes', ...
'Dudbridge-Koeleman', ...
'Jiang'}))
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
plm.npcparm = 1;
a = a + 2;
elseif ischar(vararginx{a+2})
plm.npcparm = eval(vararginx{a+2});
a = a + 3;
else
plm.npcparm = vararginx{a+2};
a = a + 3;
end
elseif strcmpi(vararginx{a+1},'Friston')
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
plm.npcparm = 1;
a = a + 2;
elseif ischar(vararginx{a+2})
plm.npcparm = eval(vararginx{a+2});
a = a + 3;
else
plm.npcparm = vararginx{a+2};
a = a + 3;
end
elseif strcmpi(vararginx{a+1},'Dudbridge-Koeleman2')
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
plm.npcparm = 1;
plm.npcparm2 = 0.05;
a = a + 2;
else
if ischar(vararginx{a+2})
plm.npcparm = eval(vararginx{a+2});
else
plm.npcparm = vararginx{a+2};
end
if nargin == a + 2 || ...
ischar(vararginx{a+3}) && ...
strcmpi(vararginx{a+3}(1),'-')
plm.npcparm2 = 0.05;
elseif ischar(vararginx{a+3})
plm.npcparm2 = eval(vararginx{a+3});
else
plm.npcparm2 = vararginx{a+3};
end
a = a + 4;
end
else
a = a + 2;
end
opts.npcmethod = methlist{methidx};
end
case '-npcmod' % basic
% NPC over modalities.
opts.NPC = true;
opts.npcmod = true;
a = a + 1;
case '-npccon' % basic
% NPC over contrasts -- that is, all contrasts, even contrasts
% in different designs (if more than one -d is supplied).
opts.NPC = true;
opts.npccon = true;
opts.syncperms = true;
a = a + 1;
case '-mv' % basic
% Compute classic multivariate statistics
if nargin == a
opts.MV = true;
a = a + 1;
elseif nargin > a && strcmp(vararginx{a+1}(1),'-')
opts.MV = true;
a = a + 1;
elseif nargin > a
% Which multivariate statistic to use?
methlist = { ...
'auto', ...
'HotellingTsq', ...
'Wilks', ...
'Lawley', ...
'Lawley-Hotelling', ...
'Pillai', ...
'Roy', ...
'Roy-ii', ...
'Roy-iii', ...
'CCA', ...
'PLS'};
methidx = strcmpi(vararginx{a+1},methlist);
% Check if method exists, and load extra parameters if needed
if ~any(methidx)
error('Multivariate statistic "%s" unknown.',vararginx{a+1});
elseif strcmpi(vararginx{a+1},'CCA')
opts.MV = false;
opts.CCA = true;
opts.PLS = false;
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
opts.ccaorplsparm = 1;
a = a + 2;
elseif ischar(vararginx{a+2})
opts.ccaorplsparm = eval(vararginx{a+2});
a = a + 3;
else
opts.ccaorplsparm = vararginx{a+2};
a = a + 3;
end
elseif strcmpi(vararginx{a+1},'PLS')
opts.MV = false;
opts.CCA = false;
opts.PLS = true;
if nargin == a + 1 || ...
ischar(vararginx{a+2}) && ...
strcmpi(vararginx{a+2}(1),'-')
opts.ccaorplsparm = 1;
a = a + 2;
elseif ischar(vararginx{a+2})
opts.ccaorplsparm = eval(vararginx{a+2});
a = a + 3;
else
opts.ccaorplsparm = vararginx{a+2};
a = a + 3;
end
else
opts.MV = true;
opts.CCA = false;
opts.PLS = false;
a = a + 2;
end
opts.mvstat = methlist{methidx};
end
case '-fdr' % basic
% Compute FDR-adjusted p-values
opts.FDR = true;
a = a + 1;
case {'-accel','-approx'} % advanced
% Choose a method to do the approximation of p-values
if narginx > a && ~strcmpi(vararginx{a+1}(1),'-')
methlist = { ...
'negbin', ...
'tail', ...
'noperm', ...
'gamma', ...
'lowrank'};
methidx = strcmpi(vararginx{a+1},methlist);
if ~ any(methidx)
error('Approximation method "%s" unknown.',vararginx{a+1});
end
for mm = 1:numel(methlist)
opts.accel.(methlist{mm}) = methidx(mm);
end
% Extra parameters
if opts.accel.negbin
% Number of exceedances:
if narginx > a+1 && ~strcmpi(vararginx{a+2}(1),'-')
if ischar(vararginx{a+2})
opts.accel.negbin = str2double(vararginx{a+2});
else
opts.accel.negbin = vararginx{a+2};
end
a = a + 3;
else
opts.accel.negbin = opts.accel.negbin_nexced;
a = a + 2;
end
elseif opts.accel.tail
% Define whether include or not the unpermuted stat:
if narginx > a+1 && ~strcmpi(vararginx{a+2}(1),'-')
if ischar(vararginx{a+2})
if any(strcmpi(vararginx{a+2},{'out','G1out','T1out','true', '1'}))
opts.accel.G1out = true;
opts.saveuncorrected = false; % defensive, as the uncorrected will be invalid here.
elseif any(strcmpi(vararginx{a+2},{'in', 'G1in', 'T1in', 'false','0'}))
opts.accel.G1out = false;
end
else
if vararginx{a+2}
opts.accel.G1out = true;
opts.saveuncorrected = false; % defensive, as the uncorrected will be invalid here.
else
opts.accel.G1out = false;
end
end
a = a + 3;
else
a = a + 2;
end
elseif opts.accel.gamma
% Define whether include or not the unpermuted stat:
if narginx > a+1 && ~strcmpi(vararginx{a+2}(1),'-')
if ischar(vararginx{a+2})
if any(strcmpi(vararginx{a+2},{'out','G1out','T1out','true', '1'}))
opts.accel.G1out = true;
opts.saveuncorrected = false;
elseif any(strcmpi(vararginx{a+2},{'in', 'G1in', 'T1in', 'false','0'}))
opts.accel.G1out = false; % defensive, as the uncorrected will be invalid here.
end
else
if vararginx{a+2}
opts.accel.G1out = true;
opts.saveuncorrected = false; % defensive, as the uncorrected will be invalid here.
else
opts.accel.G1out = false;
end
end
a = a + 3;
else
a = a + 2;
end
elseif opts.accel.lowrank
% Fraction of voxels to be sampled (if < 1) or actual
% number of voxels to be sampled.
if narginx > a+1 && ~strcmpi(vararginx{a+2}(1),'-')
if ischar(vararginx{a+2})
opts.accel.lowrank_val = str2double(vararginx{a+2});
else
opts.accel.lowrank_val = vararginx{a+2};
end
a = a + 3;
else
a = a + 2;
end
else
a = a + 2;
end
else
error([...
'The options "-accel" and "-approx" require a method to.\n' ...
'be specified. Consult the documentation.%s'],'');
end
case {'-noniiclass','-nonifticlass'} % advanced
% Disable using the NIFTI class
opts.useniiclass = false;
a = a + 1;
case '-precision' % advanced
% Precision to use?
if narginx > a && ~strcmpi(vararginx{a+1}(1),'-')
methlist = {'single','double'};
methidx = strcmpi(vararginx{a+1},methlist);
if ~any(methidx)
error('Precision "%s" unknown. Use "single" or "double".',vararginx{a+1});
else
a = a + 2;
end
opts.precision = methlist{methidx};
else
error([...
'The option "-precision" requires a method to be specified.\n'...
'Use "-precision double" or "-precision single".']);
end
case '-saveperms' % advanced
% Save the permutations
opts.saveperms = true;
a = a + 1;
case '-savemax' % advanced
% Save the permutations
opts.savemax = true;
a = a + 1;
case '-savemetrics' % advanced
% Save a file with the number of permutations, average
% Hamming distance, etc.
opts.savemetrics = true;
a = a + 1;
case '-inormal' % advanced
% Inverse-normal transformation?
opts.inormal = true;
% Take the parameters given to -inormal
parms = {};
if narginx - a >= 1
if ~strcmp(vararginx{a+1}(1),'-')
parms{1} = vararginx{a+1};
end
end
if narginx - a >= 2
if ~strcmp(vararginx{a+2}(1),'-')
parms{2} = vararginx{a+2};
end
end
a = a + 1 + numel(parms);
% Then modify the variables accordingly
methlist = { ...
'Blom', ...
'Tukey', ...
'Bliss', ...
'Waerden', ...
'SOLAR'};
for p = 1:numel(parms)
methidx = strcmpi(parms{p},methlist);
if any(methidx)
opts.inormal_meth = parms{p};
elseif any(parms{p},{'quali','qualitative','discrete'})
opts.inormal_quanti = false;
elseif any(parms{p},{'quanti','quantitative','continuous'})
opts.inormal_quanti = true;
else
error('Parameter "%s" unknown for the "-inormal" option.',parms{p});
end
end
case '-probit' % advanced
% Probit transformation?
opts.probit = true;
a = a + 1;
case '-seed' % advanced
% Seed for the random number generator
opts.seed = vararginx{a+1};
if ischar(opts.seed) && ...
~any(strcmpi(opts.seed,{'shuffle','twist','reset'}))
opts.seed = str2double(opts.seed);
end