-
Notifications
You must be signed in to change notification settings - Fork 28
/
limo_display_results.m
2410 lines (2208 loc) · 122 KB
/
limo_display_results.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 res = limo_display_results(Type,FileName,PathName,p,MCC,LIMO,flag,varargin)
% This function displays various results
% The arguments specify cases for the
% different kind of figures, thresholds etc ..
%
% FORMAT:
% limo_display_results(Type,FileName,PathName,p,MCC,LIMO,flag,options)
%
% INPUTS:
% Type = type of images/plot to do
% 1 - 2D images with a intensity plotted as function of time (x) and electrodes (y)
% 2 - topographic plot a la eeglab
% 3 - plot the ERP data (original or modeled)
% Filename = Name of the file to image
% PathName = Path of the file to image
% p = threshold p value e.g. 0.05
% MCC = Multiple Comparison technique
% 1=None, 2= Cluster, 3=TFCE, 4=T max
% LIMO = LIMO structure
% flag = interactivity (1) or not (0)
%
% OPTIONAL INPUTS (Usage: {''key'', value, ... })
% 'channels' : Provide the index of the channel to be used.
% 'regressor': Provide the index of the regressor to be used.
% 'plot3type': Type of plots to show when 'Type' is 3. Select between {'Original', 'Modeled', 'Adjusted'}
% 'sumstats' : Course plot summary statistics 'Mean' or 'Trimmed'
% 'restrict' : for time-frequency data, plot restrict plot to 'Time' or 'Frequency'
% 'dimvalue' : for time-frequency data, what value to resctrict on (e.g. restrict to 'Time' with dimvalue 5Hz)
%
% Although the function is mainly intented to be used via the GUI, some figures
% can be generated automatically, for instance limo_display_results(1,'R2.mat',pwd,0.05,5,LIMO,0);
% would load the R2.mat file from the current directory, and plot all
% electrodes/time frames F values thresholded using tfce at alpha 0.05
% topoplot and ERP like figures can't be automated since they require user
% input
%
% Cyril Pernet, Guillaume Rousselet, Carl Gaspar,
% Nicolas Chauveau, Andrew Stewart, Ramon Martinez-Cancino, Arnaud Delorme
%
% see also limo_stat_values limo_display_image limo_display_image_tf topoplot
% ----------------------------------------------------------------------
% Copyright (C) LIMO Team 2024
if ~ischar(Type)
options = { 'type', Type, 'filename', FileName, 'pathname', PathName, 'p', p, 'MCC', MCC, 'LIMO', LIMO, varargin{:} };
else
options = {Type FileName PathName p MCC LIMO flag varargin{:} };
end
try
options = varargin;
if ~isempty( varargin )
for i = 1:2:numel(options)
g.(options{i}) = options{i+1};
end
else
g = [];
end
catch
limo_errordlg('limo_display_results() error: calling convention {''key'', value, ... } error');
return
end
try g.channels; catch, g.channels = []; end % No default values
try g.regressor; catch, g.regressor = []; end % No default values
try g.plot3type; catch, g.plot3type = []; end % No default values
try g.sumstats; catch, g.sumstats = []; end % No default values
try g.restrict; catch, g.restrict = []; end % No default values
try g.dimvalue; catch, g.dimvalue = []; end % No default values
try g.fig; catch, g.fig = []; end % Existing figure
if isequal(g.regressor, 0); g.regressor = []; end
if ~isempty(g.plot3type)
extra = {'Original','Modelled','Adjusted'};
if isnumeric(g.plot3type)
extra = extra{g.plot3type};
else
extra(contains(extra,g.plot3type,'IgnoreCase',true));
end
end
res = '';
toplot = load(fullfile(PathName,FileName));
toplot = toplot.(cell2mat(fieldnames(toplot)));
if nargin <= 6
flag = 1;
end
choice = 'use theoretical p values'; % threshold based on what is computed since H0 is used for clustering
% see limo_stat_values - discontinuated empirical threshold (misleading)
% Load LIMO structure if a path was provided
% Load LIMO structure if a path was provided
if ischar(LIMO)
load(LIMO, 'LIMO');
end
[~,FileNameTmp,ext] = fileparts(FileName);
if MCC == 2 || MCC == 4 % cluster and MAX correction
LIMO.design.bootstrap = 1;
% deal with bootstrap
if ~exist([PathName filesep 'H0' filesep 'H0_' FileNameTmp ext],'file')
if LIMO.Level == 1
if strncmp(FileNameTmp,'con',3) || strncmp(FileNameTmp,'ess',3)
limo_warndlg(sprintf('This contrast cannot be bootstrapped now, \nbootstrap the model and recompute the contrast'))
else
if strcmp(limo_questdlg('Level 1: are you sure to compute all bootstraps for that subject?','bootstrap turned on','Yes','No','No'),'Yes')
LIMO.design.bootstrap = 800;
if handles.tfce == 1
LIMO.design.tfce = 1;
end
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO')
limo_eeg(4);
end
end
else % LIMO.Level == 2
res = limo_questdlg('This option requires to compute bootstraps (this may take time)','Bootstraping data','Cancel','Continue','Continue');
if ~strcmp(res,'Continue')
return;
end
if ~isfield(LIMO.design, 'bootstrap') || LIMO.design.bootstrap == 1
fprintf('Bootstrap repetition set to 1000')
LIMO.design.bootstrap = 1000;
end
if contains(FileNameTmp,'one_sample')
limo_random_robust(1,fullfile(LIMO.dir,'Yr.mat'),...
str2double(FileNameTmp(max(strfind(FileNameTmp,'_'))+1:end)),LIMO);
elseif contains(FileNameTmp,'two_samples')
limo_random_robust(2,fullfile(LIMO.dir,'Y1r.mat'),...
fullfile(LIMO.dir,'Y1r.mat'), str2double(FileNameTmp(max(strfind(FileNameTmp,'_'))+1:end)),LIMO);
elseif contains(FileNameTmp,'paired_samples')
underScoresPos = strfind(FileNameTmp,'_');
param1 = str2num(FileNameTmp(underScoresPos(end-1)+1:underScoresPos(end)-1));
param2 = str2num(FileNameTmp(underScoresPos(end)+1:end));
limo_random_robust(3,fullfile(LIMO.dir,'Y1r.mat'),...
fullfile(LIMO.dir,'Y1r.mat'), [param1 param2],LIMO);
elseif contains(FileNameTmp,'Covariate_effect') && contains(LIMO.design.name,'Regression')
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO');
limo_eeg(4,LIMO.dir);
elseif contains(FileNameTmp,'ANOVA') && ~strncmpi(FileNameTmp,'Rep_ANOVA',9)
limo_random_robust(5,fullfile(LIMO.dir,'Yr.mat'), LIMO.data.Cat,LIMO.data.Cont,LIMO,'go','yes');
elseif contains(FileNameTmp,'Rep_ANOVA')
if strncmp(FileNameTmp,'con',3)
if exist([PathName filesep 'H0' filesep 'H0_' filesep 'H0_Betas.mat'],'file')
limo_contrast([PathName filesep 'Yr.mat'], ...
[PathName filesep 'H0' filesep 'H0_' filesep 'H0_Betas.mat'], LIMO, 0,3);
else
limo_errordlg('there is no GLM bootstrap file for this contrast file')
end
elseif strncmp(FileNameTmp,'ess',3)
if exist([PathName filesep 'H0' filesep 'H0_' filesep 'H0_Betas.mat'],'file')
limo_contrast([PathName filesep 'Yr.mat'], ...
[PathName filesep 'H0' filesep 'H0_' filesep 'H0_Betas.mat'], LIMO, 1,3);
else
limo_errordlg('there is no bootstrap file for this contrast file')
end
else
disp('Bootstraping Repeated Measure ANOVA')
limo_random_robust(6,fullfile(PathName,'Yr.mat'),LIMO.data.Cat, ...
LIMO.design.repeated_measure, LIMO, 'go','yes')
end
end
end
end
elseif MCC == 3
LIMO.design.tfce = 1;
currentfile = fullfile(PathName, FileName);
if ~exist([PathName filesep 'H0' filesep 'tfce_H0_' FileNameTmp ext],'file')
limo_tfce_handling(currentfile,'checkfile','yes')
end
end
if ~isfield(LIMO,'Level')
if Type == 3 % likely a summary stat file
LIMO.Level = 2; % even if for a subject, calls limo_add_plots
end
end
% -------------------------------------------------------------------------
% ------------------- LEVEL 1 ------------------------------------
% ------------------- SINGLE SUBJECT ------------------------------------
% -------------------------------------------------------------------------
if LIMO.Level == 1
switch Type
case{1}
%--------------------------
% imagesc of the results
%--------------------------
if strcmpi(LIMO.design.type_of_analysis,'Mass-univariate')
% univariate results from 1st level analysis
% ------------------------------------------
% if previously plotted recover data from the cache
data_cached = 0;
if isfield(LIMO,'cache')
try
if strcmpi(LIMO.cache.fig.name, FileName) && ...
LIMO.cache.fig.MCC == MCC && ...
LIMO.cache.fig.threshold == p
disp('using cached data');
mask = LIMO.cache.fig.mask;
if isempty(mask)
data_cached = 0;
elseif sum(mask(:)) == 0
limo_errordlg(' no values under threshold ','no significant effect','modal');
return
else
M = LIMO.cache.fig.pval;
mytitle = LIMO.cache.fig.title;
toplot = LIMO.cache.fig.stats;
data_cached = 1;
assignin('base','p_values',M)
assignin('base','mask',mask)
end
end
catch no_cache
fprintf('could not load cached data %s',no_cache.message)
data_cached = 0;
end
end
% ------------------
% compute the plot
% ------------------
if data_cached == 0
[M, mask, mytitle] = limo_stat_values(FileName,p,MCC,LIMO);
if isempty(mask)
disp('no values computed'); return
elseif sum(mask(:)) == 0
limo_errordlg(' no values under threshold ','no significant effect','modal');
LIMO.cache.fig.name = FileName;
LIMO.cache.fig.MCC = MCC;
LIMO.cache.fig.stats = [];
LIMO.cache.fig.threshold = p;
LIMO.cache.fig.pval = M;
LIMO.cache.fig.mask = mask;
LIMO.cache.fig.title = mytitle;
% do an exception for designs with just the constant
if strcmpi(FileName,'R2.mat') && size(LIMO.design.X,2)==1
mask = ones(size(mask)); LIMO.cache.fig.mask = mask;
mytitle = 'R^2 Coef unthresholded'; LIMO.cache.fig.title = mytitle;
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO','-v7.3')
else
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO','-v7.3')
return
end
else
assignin('base','p_values',M)
assignin('base','mask',mask)
end
if contains(FileName,'R2','IgnoreCase',true)
if strcmpi(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(toplot(:,:,:,1)); % plot R2 values instead of F
else
toplot = squeeze(toplot(:,:,1));
end
assignin('base','R2_values',toplot)
elseif contains(FileName,'Condition_effect','IgnoreCase',true) || ...
contains(FileName,'Covariate_effect','IgnoreCase',true) || ...
contains(FileName,'Interaction_effect','IgnoreCase',true) || ...
contains(FileName,'semi_partial_coef','IgnoreCase',true)
if strcmpi(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(toplot(:,:,:,1)); % plot F values
else
toplot = squeeze(toplot(:,:,1));
end
if contains(FileName,'semi_partial_coef','IgnoreCase',true)
assignin('base','semi_partial_coef',toplot)
else
assignin('base','F_values',toplot)
end
elseif strcmpi(FileName(1:4),'con_')
if strcmpi(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(toplot(:,:,:,4)); % plot T values
else
toplot = squeeze(toplot(:,:,4));
end
assignin('base','T_values',toplot)
elseif strcmpi(FileName(1:4),'ess_')
if strcmpi(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(toplot(:,:,:,end-1)); % plot F values
else
toplot = squeeze(toplot(:,:,end-1));
end
assignin('base','F_values',toplot)
else
limo_errordlg('file not supported');
return
end
end
% replace plotting value with user regressor selection
if ~isempty(g.regressor) && ~isequal(g.regressor, 0)
if ~exist('freq_index', 'var'), freq_index = []; end
toplot = limo_get_model_data(LIMO, g.regressor, extra, p, freq_index);
end
% -------------------------------------------------------------------------
% Actual plot takes place here
% -------------------------------------------------------------------------
if ~isempty(toplot)
% cache the results for next time
if data_cached == 0 && ~all(mask(:)==1)
LIMO.cache.fig.name = FileName;
LIMO.cache.fig.MCC = MCC;
LIMO.cache.fig.stats = toplot;
LIMO.cache.fig.threshold = p;
LIMO.cache.fig.pval = M;
LIMO.cache.fig.mask = mask;
LIMO.cache.fig.title = mytitle;
if exist(LIMO.dir,"dir")
save(fullfile(LIMO.dir,'LIMO.mat'),'LIMO','-v7.3')
end
end
if ndims(toplot)==3
res = limo_display_image_tf(LIMO,toplot,mask,mytitle,flag);
else
res = limo_display_image(LIMO,toplot,mask,mytitle,flag);
end
end
else
% mutivariate results from 1st level analysis
% ------------------------------------------
if strncmp(FileName,'R2',2) || strncmp(FileName,'Condition_effect',16) || strncmp(FileName,'Covariate_effect',16) % MANOVA PLOTTING
if strncmp(FileName,'R2',2)
R2_EV = load(fullfile(LIMO.dir,'R2_EV.mat'));
R2_EV = R2_EV.R2_EV;
EV = R2_EV(1:size(R2_EV,1),:); % no point plotting 0, just pick 5 1st Eigen values
R2_EV_var = load(fullfile(LIMO.dir,'R2_EV_var.mat'));
R2_EV_var = R2_EV_var.R2_EV_var;
test = sum(R2_EV_var(1,:) > 95) / size(R2_EV_var,2); % If more than 50% of the time-frames have a
% first eigenvalue with a proportion higher than 90%, the results of Roy's test are displayed,
if test > .50
choice = 'Roy';
else
choice = 'Pillai';
end
clear R2_EV;
F_values(:,1) = squeeze(toplot(:,2));
F_values(:,2) = squeeze(toplot(:,4));
[M, mask, mytitle] = limo_mstat_values(Type,FileName,p,MCC,LIMO,choice);
if isempty(mask)
return
elseif sum(mask(:)) == 0
limo_errordlg(' no values under threshold ','no significant effect','modal');
return
else
toplot = squeeze(toplot(:,1)); % plot R2 values instead of F
assignin('base','F_values',F_values)
assignin('base','p_values',M)
assignin('base','mask',mask)
clear R2
end
else
if strcmpi(FileName(end-6:end),'_EV.mat')
FileName = [FileName(1:end-7) '.mat'];
toplot = load(fullfile(PathName,FileName));
toplot = toplot.(cell2mat(fieldnames(toplot)));
end
name = sprintf('%s_%g_EV',FileName(1:end-4),str2double(FileName(max(strfind(FileName,'_')):end-4)));
EV = load(fullfile(LIMO.dir,name));
EV = EV.(cell2mat(fieldnames(EV)));
EV = EV(1:size(Condition_effect_EV,1),:); % no point plotting 0, just pick 5 1st Eigen values
name = sprintf('%s_%g_EV_var',FileName(1:end-4),str2double(FileName(max(strfind(FileName,'_')):end-4)));
EV_var = load(fullfile(LIMO.dir,name));
EV_var = EV_var.(cell2mat(fieldnames(EV_var)));
EV_var = EV_var(1:size(EV_var,1),:);
test = sum(EV_var(1,:) > 95) / size(EV_var,2); % If more than 50% of the time-frames have a
%first eigenvalue with a proportion higher than 90%, the results of Roy's test are displayed,
if test > .50
choice = 'Roy';
else
choice = 'Pillai';
end
F_values(:,1) = squeeze(toplot(:,1));
F_values(:,2) = squeeze(toplot(:,3));
[M, mask, mytitle] = limo_mstat_values(Type,FileName,p,MCC,LIMO,choice);
if isempty(mask)
return
elseif sum(mask(:)) == 0
limo_errordlg(' no values under threshold ','no significant effect','modal');
return
else
if strcmpi(choice,'Roy')
toplot = F_values(:,1);
else
toplot = F_values(:,2);
end
assignin('base','F_values',F_values)
assignin('base','p_values',M)
assignin('base','mask',mask)
clear R2
end
end
figure; set(gcf,'Color','w');
% imagesc eigen values
subplot(3,3,[4 5 7 8]);
timevect = linspace(LIMO.data.start,LIMO.data.end,size(EV,2));
scale = EV; scale(scale==0)=NaN;
imagesc(timevect,1:size(EV,1),scale);
color_images_(scale,LIMO); colorbar
ylabel('Eigen Values','Fontsize',14)
set(gca,'YTickLabel',{'1','2','3','4','5'});
title('non-zero Eigen values','Fontsize',14)
% imagesc effect values
subplot(3,3,[1 2]);
scale = toplot'.*mask; scale(scale==0)=NaN;
imagesc(timevect,1,scale);
caxis([min(scale(:)), max(scale(:))]);
color_images_(scale,LIMO); xlabel(' ')
title(mytitle,'Fontsize',18); colorbar
ylabel(' '); set(gca,'YTickLabel',{''});
% ERP plot1 - Roy -
subplot(3,3,6);
plot(timevect, F_values(:,1),'LineWidth',3); grid on; axis tight
mytitle2 = sprintf('F values - Roy');
title(mytitle2,'FontSize',14)
% ERP plot2 - Pillai -
subplot(3,3,9);
plot(timevect, F_values(:,2),'LineWidth',3); grid on; axis tight
mytitle2 = sprintf('F value - Pillai');
title(mytitle2,'FontSize',14)
end % end of MANOVA PLOTTING
if strncmp(FileName,'Discriminant_coeff',18) || strncmp(FileName,'Discriminant_scores',19)
Discriminant_coeff = load(fullfile(LIMO.dir,'Discriminant_coeff'));
Discriminant_coeff = Discriminant_coeff.Discriminant_coeff;
Discriminant_scores = load(fullfile(LIMO.dir,'Discriminant_scores'));
Discriminant_scores = Discriminant_scores.Discriminant_scores;
Condition_effect_EV_var = load(fullfile(LIMO.dir,'Condition_effect_1_EV_var.mat'));
Condition_effect_EV_var = Condition_effect_EV_var.Condition_effect_EV_var;
time = linspace(LIMO.data.start,LIMO.data.end, size(Discriminant_coeff,2));
input_title = sprintf('which time-frame to plot (in ms)?: ');
timepoint = inputdlg(input_title,'Plotting option');
t = dsearchn(time', str2double(timepoint{1}));
groupcolors = 'rgbcwmryk';
groupsymbols = 'xo*+.sdv<>';
[class,~] = find(LIMO.design.X(:,1:LIMO.design.nb_conditions)');
k = LIMO.design.nb_conditions;
if k>2
figure;set(gcf,'Color','w');
subplot(2,2,[1 2]); % 2D plot of two discriminant functions
gscatter(squeeze(Discriminant_scores(1,t,:)), squeeze(Discriminant_scores(2,t,:)), class, groupcolors(1:k), groupsymbols(1:k));
grid on; axis tight;
xlabel(['Z1, var: ' num2str(round(Condition_effect_EV_var(1,t)),2) '%'],'Fontsize',14);
ylabel(['Z2, var: ' num2str(round(Condition_effect_EV_var(2,t)),2) '%'],'Fontsize',14);
title(['Results of the discriminant analysis at ' num2str(time(t)) 'ms'], 'Fontsize', 18);
z1 = subplot(2,2,3); % First discriminant coeff
cc = limo_color_images(Discriminant_coeff(:,t,1)); % get a color map commensurate to that
topoplot(Discriminant_coeff(:,t,1),LIMO.data.chanlocs, 'electrodes','off','style','map','whitebk', 'on','colormap',cc);colorbar;
title('Z1','Fontsize',14); colormap(z1, 'hot');
z2 = subplot(2,2,4); % Second discriminant coeff
cc = limo_color_images(Discriminant_coeff(:,t,2)); % get a color map commensurate to that
topoplot(Discriminant_coeff(:,t,2),LIMO.data.chanlocs, 'electrodes','off','style','map','whitebk', 'on','colormap',cc);colorbar;
title('Z2','Fontsize',14); colormap(z2, 'hot');
elseif k==2
figure;set(gcf,'Color','w');
subplot(2,2,[1 2]); % 1D plot of two discriminant functions
data = squeeze(Discriminant_scores(1,t,:));
class1 = data(class == 1);
class2 = data(class == 2);
histogram(class1, 'BinWidth', 0.1);
hold on
histogram(class2,'BinWidth',0.1);
hold off
legend show
grid on; axis tight;
xlabel(['Z1, var: ' num2str(round(Condition_effect_EV_var(1,t)),2) '%'],'Fontsize',14);
title(['Results of the discriminant analysis at ' num2str(time(t)) 'ms'], 'Fontsize', 18);
z1 = subplot(2,2,[3,4]); % First discriminant coeff
cc = limo_color_images(Discriminant_coeff(:,t,1)); % get a color map commensurate to that
topoplot(Discriminant_coeff(:,t,1),LIMO.data.chanlocs, 'electrodes','off','style','map','whitebk', 'on','colormap',cc);colorbar;
title('Z1','Fontsize',14); colormap(z1, 'hot');
end
limo_display_image(LIMO,abs(Discriminant_coeff(:,:,1)),abs(Discriminant_coeff(:,:,1)),'Discriminant coefficients Z1',flag)
% figure;set(gcf,'Color','w');
% for t=1:size(Discriminant_coeff,2)
% topoplot(Discriminant_coeff(:,t,1),LIMO.data.chanlocs, 'electrodes','numbers','style','map');
% title(['Discriminant values first discriminant at timepoint ' num2str(t) ' corresponding to ' num2str(time(t)) ' ms']);
% pause(.01)
% end;
end
if strncmp(FileName,'Linear_Classification',21)
Linear_Classification = load(fullfile(LIMO.dir,'Linear_Classification'));
Linear_Classification = Linear_Classification.Linear_Classification;
[~, mask, mytitle] = limo_mstat_values(Type,FileName,p,MCC,LIMO,choice);
timevect = linspace(LIMO.data.start,LIMO.data.end,size(Linear_Classification,1));
figure;set(gcf,'Color','w');
subplot(3,1,[1 2]); % lineplot
plot(timevect,Linear_Classification(:,2),'LineWidth',3);title(mytitle, 'Fontsize', 18);
ylabel('decoding accuracies', 'Fontsize', 14);grid on; axis tight; hold on;
plot(timevect, Linear_Classification(:,2) + 2*Linear_Classification(:,3), 'k-','LineWidth',1); hold on;
plot(timevect, Linear_Classification(:,2) - 2*Linear_Classification(:,3), 'k-','LineWidth',1)
line([0,0],[0,1], 'color', 'black')
subplot(3, 1, 3); % imagesc accuracies
toplot = Linear_Classification(:,2); scale = toplot'.*mask;scale(scale==0)=NaN;
imagesc(timevect,1,scale);xlabel('Time in ms');
color_images_(scale,LIMO);
ylabel(' '); set(gca,'YTickLabel',{''});
end
if strncmp(FileName,'Quadratic_Classification',24)
Quadratic_Classification = load(fullfile(LIMO.dir,'Quadratic_Classification'));
Quadratic_Classification = Quadratic_Classification.Quadratic_Classification;
timevect = linspace(LIMO.data.start,LIMO.data.end,size(Quadratic_Classification,1));
figure;set(gcf,'Color','w');
subplot(3,1,[1 2]); % lineplot
plot(timevect,Quadratic_Classification(:,2),'LineWidth',3);title('CV quadratic decoding accuracies +/- 2SD', 'Fontsize', 18);
ylabel('decoding accuracies', 'Fontsize', 14);grid on; axis tight; hold on
plot(timevect, Quadratic_Classification(:,2) + 2*Quadratic_Classification(:,3), 'k-','LineWidth',1); hold on;
plot(timevect, Quadratic_Classification(:,2) - 2*Quadratic_Classification(:,3), 'k-','LineWidth',1)
line([0,0],[0,1], 'color', 'black')
subplot(3,1, 3); % imagesc plot training accuracies
scale = Quadratic_Classification(:,2)'; scale(scale==0)=NaN;
imagesc(timevect,1,scale);xlabel('Time in ms');
color_images_(scale,LIMO);
ylabel(' '); set(gca,'YTickLabel',{''});
end
end
case{2}
%--------------------------
% topoplot
%--------------------------
% univariate results from 1st level analysis
% ------------------------------------------
if strcmpi(LIMO.Analysis,'Time-Frequency')
warndlg('topoplot not supported for 3D data')
else
EEG.trials = 1;
EEG.chanlocs = LIMO.data.chanlocs;
if strcmpi(LIMO.Analysis,'Time')
EEG.xmin = LIMO.data.start / 1000;% in msec
EEG.xmax = LIMO.data.end / 1000; % in msec
EEG.times = LIMO.data.start/1000:(LIMO.data.sampling_rate/1000):LIMO.data.end/1000; % in sec;
if length(EEG.times) > 2
EEG.times = [EEG.times(1) EEG.times(end)];
end
elseif strcmpi(LIMO.Analysis,'Frequency')
EEG.xmin = LIMO.data.freqlist(1);
EEG.xmax = LIMO.data.freqlist(end);
freqlist = inputdlg('specify frequency range e.g. [5:2:40]','Choose Frequencies to plot');
if isempty(freqlist)
return
else
if contains(cell2mat(freqlist),':')
EEG.freq = eval(cell2mat(freqlist));
else
EEG.freq = str2double(cell2mat(freqlist));
end
if min(EEG.freq)<EEG.xmin || max(EEG.freq)>EEG.xmax
limo_errordlg('selected frequency out of bound'); return
end
end
end
if contains(FileName,'R2','IgnoreCase',true)
if size(LIMO.design.X,2)==1
EEG.data = squeeze(toplot(:,:,1));
EEG.setname = 'R2 values for the mean';
else
EEG.data = squeeze(toplot(:,:,2));
EEG.setname = 'R2 - F values';
end
call_topolot(EEG,FileName,LIMO.Analysis)
elseif contains(FileName,'Condition_effect','IgnoreCase',true) || ...
contains(FileName,'Covariate_effect','IgnoreCase',true) || ...
contains(FileName,'Interaction_effect','IgnoreCase',true) || ...
contains(FileName,'Condition_effect','IgnoreCase',true)
EEG.data = squeeze(toplot(:,:,1));
call_topolot(EEG,FileName,LIMO.Analysis)
elseif contains(FileName,'con','IgnoreCase',true) || contains(FileName,'ess','IgnoreCase',true)
EEG.data = squeeze(toplot(:,:,end-1));
call_topolot(EEG,FileName,LIMO.Analysis)
elseif contains(FileName,'semi partial_coef.mat','IgnoreCase',true)
regressor = str2double(cell2mat(inputdlg('which regressor(s) to plot (e.g. 1:3)','Plotting option')));
if max(regressor) > size(toplot,3); errordlg('error in regressor number'); return; end
for b = regressor
EEG.data = squeeze(toplot(:,:,b,1));
call_topolot(EEG,FileName,LIMO.Analysis)
end
else
disp('file not supported');
return
end
if contains(FileName,'con','IgnoreCase',true)
assignin('base','T_values',EEG.data);
else
assignin('base','F_values',EEG.data);
end
end
case{3}
%--------------------------
% Time course / Power
%--------------------------
% which variable(s) to plot
% ----------------------
if isempty(g.regressor)
input_title = sprintf('which regressor to plot?: 1 to %g ',size(LIMO.design.X,2));
regressor = inputdlg(input_title,'Plotting option');
else
regressor = g.regressor;
end
if isempty(regressor); disp('selection aborded'); return; end
regressor = cell2mat(regressor);
if isempty(regressor); disp('selection aborded'); return; end
if ~contains(regressor,'['); regressor=['[' regressor ']']; end
if ischar(regressor); regressor=str2num(regressor); end %#ok<ST2NM>
regressor = sort(regressor);
if max(regressor) > size(LIMO.design.X,2)
limo_errordlg('invalid regressor number');
end
categorical = sum(LIMO.design.nb_conditions) + sum(LIMO.design.nb_interactions);
if max(regressor) == size(LIMO.design.X,2)
tmp = regressor(1:end-1);
else
tmp = regressor;
end
cat = sum(tmp<=categorical); cont = sum(tmp>categorical);
if cat >=1 && cont >=1
errordlg2('you can''t plot categorical and continuous regressors together'); return
end
% which data type to make
% ------------------------
if isempty(g.plot3type) && ~any(strcmpi(g.plot3type,{'Original','Modelled','Adjusted'}))
extra = questdlg('Which data type to plot?','Options','Original','Modelled','Adjusted','Adjusted');
else
extra = g.plot3type;
end
if isempty(extra)
return
elseif strcmpi(extra,'Original')
if regressor == size(LIMO.design.X,2)
limo_errordlg('you can''t plot adjusted mean for original data'); return
end
end
% timing /frequency info
% -----------------------
if strcmpi(LIMO.Analysis,'Time')
timevect = LIMO.data.start:(1000/LIMO.data.sampling_rate):LIMO.data.end;
elseif strcmpi(LIMO.Analysis,'Frequency')
freqvect=LIMO.data.freqlist';
elseif strcmpi(LIMO.Analysis,'Time-Frequency')
timevect = linspace(LIMO.data.start,LIMO.data.end,LIMO.data.size4D(3));
freqvect = linspace(LIMO.data.lowf,LIMO.data.highf,LIMO.data.size4D(2));
end
% which channel/frequency to plot
% --------------------------------
if isempty(g.channels)
channel = inputdlg('which channel to plot','Plotting option');
else
channel = g.channels;
end
if strcmpi(LIMO.Analysis,'Time-Frequency')
disp('loading the 4D data ...')
frequency = inputdlg('which Frequency to plot','Plotting option');
else
frequency = [];
end
if strcmpi(channel,'') || strcmpi(frequency,'')
disp('looking for max');
R2 = load(fullfile(LIMO.dir,'R2.mat'));
R2 = R2.R2;
if strcmpi(LIMO.Analysis,'Time-Frequency')
tmp = squeeze(R2(:,:,:,1)); clear R2
[e,f,~] = ind2sub(size(tmp),find(tmp==max(tmp(:))));
if length(e) ~= 1; e = e(1); f = f(1); end
if strcmpi(channel,'')
channel = e;
else
channel = eval(cell2mat(channel));
end
if size(channel) > 1
errordlg('invalid channel choice'); return
elseif channel > size(LIMO.data.chanlocs,2) || channel < 1
errordlg('invalid channel number'); return
end
if strcmpi(frequency,'')
freq_index = f;
frequency = freqvect(freq_index);
else
frequency = eval(cell2mat(frequency));
end
if size(frequency) > 1
errordlg('invalid frequency choice'); return
elseif frequency > LIMO.data.tf_freqs(end) || frequency < LIMO.data.tf_freqs(1)
errordlg('invalid frequency number'); return
end
else
tmp = squeeze(R2(:,:,1)); clear R2
[channel,~] = ind2sub(size(tmp),find(tmp==max(tmp(:))));
end
clear tmp
else
channel = eval(cell2mat(channel));
if size(channel) > 1
limo_errordlg('invalid channel choice'); return
elseif channel > size(LIMO.data.chanlocs,2) || channel < 1
limo_errordlg('invalid channel number'); return
end
if ~isempty(frequency)
frequency = eval(cell2mat(frequency));
if size(frequency) > 1
errordlg('invalid frequency choice');
elseif frequency > freqvect(end) || frequency < freqvect(1)
errordlg('invalid frequency number');
end
% pick the nearest frequency index
[~, freq_index] = min(abs(freqvect-frequency ));
frequency = freqvect(freq_index);
end
end
% down to business
% ----------------------
data_cached = 0;
if isfield(LIMO,'cache')
if strcmpi(LIMO.Analysis,'Time-Frequency') && isfield(LIMO.cache,'ERPplot')
if mean([LIMO.cache.Courseplot.channel == channel ...
LIMO.cache.Courseplot.regressor == regressor ...
LIMO.cache.Courseplot.frequency == frequency]) == 1 ...
&& strcmpi('LIMO.cache.Courseplot.extra',extra)
if sum(regressor <= categorical) == length(regressor)
average = LIMO.cache.Courseplot.average;
ci = LIMO.cache.Courseplot.ci;
mytitle = LIMO.cache.Courseplot.title;
disp('using cached data');
data_cached = 1;
else
continuous = LIMO.cache.Courseplot.continuous;
mytitle = LIMO.cache.Courseplot.title;
disp('using cached data');
data_cached = 1;
end
end
elseif strcmpi(LIMO.Analysis,'Time') && isfield(LIMO.cache,'Courseplot') || ...
strcmpi(LIMO.Analysis,'Frequency') && isfield(LIMO.cache,'Courseplot')
if length(LIMO.cache.Courseplot.regressor) == length(channel)
if mean([LIMO.cache.Courseplot.channel == channel ...
LIMO.cache.Courseplot.regressor == regressor]) == 1 ...
&& strcmpi('LIMO.cache.Courseplot.extra',extra)
if sum(regressor <= categorical) == length(regressor)
average = LIMO.cache.Courseplot.average;
ci = LIMO.cache.Courseplot.ci;
mytitle = LIMO.cache.Courseplot.title;
disp('using cached data');
data_cached = 1;
else
continuous = LIMO.cache.Courseplot.continuous;
mytitle = LIMO.cache.Courseplot.title;
disp('using cached data');
data_cached = 1;
end
end
end
end
end
% no cache = compute
if data_cached == 0
probs = [p/2; 1-p/2];
z = norminv(probs);
if strcmpi(extra,'Original')
Yr = load(fullfile(LIMO.dir,'Yr.mat')); Yr = Yr.Yr;
if sum(regressor <= categorical) == length(regressor) % for categorical variables
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
if strcmpi(LIMO.Analysis,'Time-Frequency')
data = squeeze(Yr(channel,freq_index,:,index{i}));
mytitle = sprintf('Original ERSP at \n channel %s (%g) at %g Hz', LIMO.data.chanlocs(channel).labels, channel, frequency);
else
data = squeeze(Yr(channel,:,index{i}));
end
average(i,:) = nanmean(data,2);
se = nanstd(data,0,2) ./ sqrt(numel(index{i}));
ci(i,:,:) = repmat(average(i,:),2,1) + repmat(se',2,1).*repmat(z,1,size(Yr,2));
end
if strcmpi(LIMO.Analysis,'Time')
mytitle = sprintf('Original ERP at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
elseif strcmpi(LIMO.Analysis,'Frequency')
mytitle = sprintf('Original Power Spectrum at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
end
else % continuous variable
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
[reg_values(i,:),sorting_values]=sort(LIMO.design.X(index{i},regressor(i))); % continuous variable 3D plot
if strcmpi(LIMO.Analysis,'Time-Frequency')
continuous(i,:,:) = Yr(channel,freq_index,:,sorting_values);
mytitle{i} = sprintf('Original single trials \n sorted by regressor %g channel %s (%g)', regressor(i), LIMO.data.chanlocs(channel).labels, channel);
else
continuous(i,:,:) = Yr(channel,:,sorting_values);
mytitle{i} = sprintf('Original single trials \n sorted by regressor %g \n channel %s (%g) at %s Hz', regressor(i), LIMO.data.chanlocs(channel).labels, channel, frequency);
end
end
end
clear Yr
elseif strcmpi(extra,'Modelled')
Betas = load(fullfile(LIMO.dir,'Betas.mat'));
Betas = Betas.Betas;
if strcmpi(LIMO.Analysis,'Time-Frequency')
Betas = squeeze(Betas(channel,freq_index,:,:));
else
Betas = squeeze(Betas(channel,:,:));
end
Yh = (LIMO.design.X*Betas')'; % modelled data
if sum(regressor <= categorical) == length(regressor) % for categorical variables
Yr = load(fullfile(LIMO.dir,'Yr.mat')); Yr = Yr.Yr;
if strcmpi(LIMO.Analysis,'Time-Frequency')
Yr = squeeze(Yr(:,freq_index,:,:));
end
R = eye(size(Yr,3)) - (LIMO.design.X*pinv(LIMO.design.X));
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
data = squeeze(Yh(:,index{i}));
average(i,:) = mean(data,2);
var = diag(((R(index{i},index{i})*squeeze(Yr(channel,:,index{i}))')'*(R(index{i},index{i})*squeeze(Yr(channel,:,index{i}))')) / LIMO.model.model_df(2));
CI = sqrt(var/size(index{i},1))*z';
ci(i,:,:) = (repmat(mean(data,2),1,2)+CI)';
end
if strcmpi(LIMO.Analysis,'Time')
mytitle = sprintf('Modelled ERP at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
elseif strcmpi(LIMO.Analysis,'Frequency')
mytitle = sprintf('Modelled Power Spectrum at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
else
mytitle = sprintf('Modelled ERSP \n channel %s (%g) at %g Hz', LIMO.data.chanlocs(channel).labels, channel, frequency);
end
else % continuous variable
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
[reg_values(i,:),sorting_values] = sort(LIMO.design.X(index{i},regressor(i))); % continuous variable 3D plot
continuous(i,:,:) = Yh(:,sorting_values);
if strcmpi(LIMO.Analysis,'Time-Frequency')
mytitle{i} = sprintf('Modelled single trials \n sorted by regressor %g \n channel %s (%g) at %g Hz', regressor(i), LIMO.data.chanlocs(channel).labels, channel, frequency);
else
mytitle{i} = sprintf('Modelled single trials \n sorted by regressor %g channel %s (%g)', regressor(i), LIMO.data.chanlocs(channel).labels, channel);
end
end
end
else % Adjusted
allvar = 1:size(LIMO.design.X,2)-1;
allvar(regressor)=[];
if strcmpi(LIMO.Analysis,'Time-Frequency')
Yr = load(fullfile(LIMO.dir,'Yr.mat'));
Yr = squeeze(Yr.Yr(channel,freq_index,:,:));
Betas = load(fullfile(LIMO.dir,'Betas.mat'));
Betas = squeeze(Betas.Betas(channel,freq_index,:,:));
else
Yr = load(fullfile(LIMO.dir,'Yr.mat'));
Yr = squeeze(Yr.Yr(channel,:,:));
Betas = load(fullfile(LIMO.dir,'Betas.mat'));
Betas = squeeze(Betas.Betas(channel,:,:));
end
confounds = (LIMO.design.X(:,allvar)*Betas(:,allvar)')';
Ya = Yr - confounds; clear Yr Betas confounds;
if sum(regressor <= categorical) == length(regressor) % for categorical variables
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
data = squeeze(Ya(:,index{i}));
average(i,:) = nanmean(data,2);
se = nanstd(data,0,2) ./ sqrt(numel(index{i}));
ci(i,:,:) = repmat(average(i,:),2,1) + repmat(se',2,1).*repmat(z,1,size(Ya,1));
end
if strcmpi(LIMO.Analysis,'Time')
mytitle = sprintf('Adjusted ERP at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
elseif strcmpi(LIMO.Analysis,'Frequency')
mytitle = sprintf('Adjusted Power Spectrum at channel %s (%g)', LIMO.data.chanlocs(channel).labels, channel);
else
mytitle = sprintf('Adjusted ERSP channel %s (%g) at %g Hz', LIMO.data.chanlocs(channel).labels, channel, frequency);
end
else % continuous variable
for i=length(regressor):-1:1
index{i} = find(LIMO.design.X(:,regressor(i)));
[reg_values(i,:),sorting_values] = sort(LIMO.design.X(index{i},regressor(i))); % continuous variable 3D plot
continuous(i,:,:) = Ya(:,sorting_values);
if strcmpi(LIMO.Analysis,'Time-Frequency')
mytitle{i} = sprintf('Adjusted single trials \n sorted by regressor \n %g channel %s (%g) at %g Hz', regressor(i), LIMO.data.chanlocs(channel).labels, channel, frequency);
else
mytitle{i} = sprintf('Adjusted single trials \n sorted by regressor %g channel %s (%g)', regressor(i), LIMO.data.chanlocs(channel).labels, channel);
end
end
end
end
end
% make the figure(s)
% ------------------
figure;set(gcf,'Color','w')
if sum(regressor <= categorical) == length(regressor)
for i=1:size(average,1)
if i==1
colorOrder = get(gca, 'ColorOrder');
colorOrder = repmat(colorOrder,ceil(size(average,1)/size(colorOrder,1)),1);
end
if strcmpi(LIMO.Analysis,'Frequency')
try
plot(freqvect,average(i,:),'LineWidth',1.5,'Color',colorOrder(i,:)); hold on
catch
freqvect = linspace(LIMO.data.start,LIMO.data.end,size(average,2));
plot(freqvect,average(i,:),'LineWidth',1.5,'Color',colorOrder(i,:)); hold on
end
else
plot(timevect,average(i,:),'LineWidth',1.5,'Color',colorOrder(i,:)); hold on
end
x = squeeze(ci(i,1,:)); y = squeeze(ci(i,2,:));
if strcmpi(LIMO.Analysis,'Frequency')
fillhandle = patch([reshape(freqvect, 1, numel(freqvect)) fliplr(reshape(freqvect, 1, numel(freqvect)))], [x' fliplr(y')], colorOrder(i,:));
else
fillhandle = patch([reshape(timevect, 1, numel(timevect)) fliplr(reshape(timevect, 1, numel(timevect)))], [x',fliplr(y')], colorOrder(i,:));
end
set(fillhandle,'EdgeColor',colorOrder(i,:),'FaceAlpha',0.2,'EdgeAlpha',0.8);
end
% if regressor spans columns of an effect, plot significant time frames
index = 1; index2 = LIMO.design.nb_conditions(1);
for i=1:length(LIMO.design.nb_conditions)
effect = index:index2;
if length(regressor) == length(effect)
if mean(regressor == effect) == 1
name = sprintf('Condition_effect_%g.mat',i);
% load(name);
if isfield(LIMO,'cache') && isfield(LIMO,'fig')
if strcmpi(LIMO.cache.fig.name,name) && ...
LIMO.cache.fig.MCC == MCC && ...
LIMO.cache.fig.threshold == p
if strcmpi(LIMO.Analysis,'Time-Frequency')
sig = single(LIMO.cache.fig.mask(channel,freq_index,:)); sig(sig==0)=NaN;
else
sig = single(LIMO.cache.fig.mask(channel,:)); sig(sig==0)=NaN;
end
end
else
if strcmpi(LIMO.Analysis,'Time-Frequency')