forked from LIMO-EEG-Toolbox/limo_tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
limo_display_results.m
2449 lines (2237 loc) · 121 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 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 = indicates to allow surfing the figure (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'}
%
% 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 v3 06-05-2009
% Carl Gaspar 03-09-2009 - fixed some axis issues for 3D plots (see subfunction time_vect_)
% Cyril P. v4 09-09-2009 allows random effect results to be displayed (+ some clean up)
% Cyril P. v5. 10-03-2010 split the whole file into 2 parts based on LIMO.level (1 or 2)
% Guillaume Rousselet v4 06-07-2010 added the max(T)/max(F) and cluster stats for random effect
% Cyril Pernet v4 16-05-2010 fixed the random effect to automatically load bootstrap and get the neighbouring matrix for clusters
% Nicolas Chauveau 08-12-2011 fixed the ERP plot of gp*repeated measures (for levels>2)
% Cyril Pernet v5 10-10-2012 added tfce and redesigned CI with filling
% Andrew Stewart 10-11-2013 added options for spectral power and time-freq
% Cyril Pernet 21-03-2014 made time-freq to work with the new display +
% changed limo_stat values to take timne-freq
% Cyril Pernet & Ramon Martinez-Cancino 23-10-2014 updates for components (ICA)
%
% see also limo_stat_values topoplot
% ----------------------------------
% Copyright (C) LIMO Team 2010
try
options = varargin;
if ~isempty( varargin ),
for i = 1:2:numel(options)
g.(options{i}) = options{i+1};
end
else g = []; end;
catch
disp('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
cd(PathName)
load (FileName);
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
if LIMO.design.bootstrap == 0
if MCC == 2
errordlg2('Clustering thresholding necessitates boostrap - invalid choice');
elseif MCC == 3
errordlg2('TFCE thresholding necessitates boostrap - invalid choice');
elseif MCC == 4
errordlg2('Maximum stat thresholding necessitates bootstrap - invalid choice');
end
MCC = 1;
end
if LIMO.design.bootstrap == 1 && LIMO.design.tfce == 0 && MCC == 3
errordlg2('TFCE thresholding hasn''t been computed - invalid choice');
MCC =1;
end
% -------------------------------------------------------------------------
% ------------------- LEVEL 1 ------------------------------------
% ------------------- SINGLE SUBJECT ------------------------------------
% -------------------------------------------------------------------------
if LIMO.Level == 1
switch Type
case{1}
%--------------------------
% imagesc of the results
%--------------------------
if strcmp(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 strcmp(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
warndlg(' no values under threshold ','no significant effect','modal');
toplot = []; 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
data_cached = 0;
end
end
% ------------------
% compute the plot
% ------------------
if data_cached == 0
if strcmp(LIMO.Analysis,'Time-Frequency')
[M, mask, mytitle] = limo_stat_values_tf(Type,FileName,p,MCC,LIMO,choice);
else
[M, mask, mytitle] = limo_stat_values(Type,FileName,p,MCC,LIMO,choice);
end
if isempty(mask)
return
elseif sum(mask(:)) == 0
warndlg(' 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;
save LIMO LIMO
toplot = []; return
else
assignin('base','p_values',M)
assignin('base','mask',mask)
end
if strcmp(FileName,'R2.mat')
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(R2(:,:,:,1)); % plot R2 values instead of F
else
toplot = squeeze(R2(:,:,1));
end
assignin('base','R2_values',squeeze(R2(:,:,2)))
clear R2
elseif strncmp(FileName,'Condition_effect',16)
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(Condition_effect(:,:,:,1)); % plot F values
else
toplot = squeeze(Condition_effect(:,:,1));
end
assignin('base','F_values',toplot)
clear Condition_effect
elseif strncmp(FileName,'Covariate_effect',16)
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(Covariate_effect(:,:,:,1)); % plot F values
else
toplot = squeeze(Covariate_effect(:,:,1));
end
assignin('base','F_values',toplot)
clear Covariate_effect
elseif strncmp(FileName,'Interaction_effect',18)
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(Interaction_effect(:,:,:,1)); % plot F values
else
toplot = squeeze(Interaction_effect(:,:,1));
end
assignin('base','F_values',toplot)
clear Interaction_effect
elseif strncmp(FileName,'semi_partial_coef',17)
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(semi_partial_coef(:,:,:,1)); % plot the coef rather than F
else
toplot = squeeze(semi_partial_coef(:,:,1)); % plot the coef rather than F
end
assignin('base','semi_partial_coef',toplot)
clear semi_partial_coef
elseif strcmp(FileName(1:4),'con_')
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(con(:,:,:,4)); % plot T values
else
toplot = squeeze(con(:,:,4));
end
assignin('base','T_values',toplot)
clear con
elseif strcmp(FileName(1:4),'ess_')
if strcmp(LIMO.Analysis,'Time-Frequency')
toplot = squeeze(ess(:,:,:,end-1)); % plot F values
else
toplot = squeeze(ess(:,:,end-1));
end
assignin('base','F_values',toplot)
clear ess
else
errordlg2('file not supported');
return
end
update_cache = 1;
end
% -------------------------------------------------------------------------
% Actual plot takes place here
% -------------------------------------------------------------------------
if ~isempty(toplot)
% cache the results for next time
if data_cached == 0
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;
save LIMO LIMO
end
if strcmp(LIMO.Analysis,'Time') || strcmp(LIMO.Analysis,'Frequency')
limo_display_image(LIMO,toplot,mask,mytitle)
else % strcmp(LIMO.Analysis,'Time-Frequency') - 3D maps
limo_display_results_tf(LIMO,toplot,mask,mytitle);
end
end
else
% mutivariate results from 1st level analysis
% ------------------------------------------
if strncmp(FileName,'R2',2)
cd(LIMO.dir); load R2_EV.mat; EV = R2_EV(1:5,:); % no point plotting 0, just pick 5 1st Eigen values
test = sum(sum(R2_EV(1:5,:)>1,2)>1); % check if we have more than 1 EV>1
if test ==1; choice = 'Roy'; else choice = 'Pillai'; end
clear R2_EV;
load R2.mat;
F_values(:,1) = squeeze(R2(:,2));
F_values(:,2) = squeeze(R2(:,4));
[M, mask, mytitle] = limo_statm_values(Type,FileName,p,MCC,LIMO,choice);
if isempty(mask)
return
elseif sum(mask(:)) == 0
warndlg(' no values under threshold ','no significant effect','modal');
toplot = []; return
else
toplot = squeeze(R2(:,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
elseif strncmp(FileName,'Condition_effect',16)
cd(LIMO.dir);
if strcmp(FileName(end-6:end),'_EV.mat'); FileName = [FileName(1:end-7) '.mat']; end
name = sprintf('Condition_effect_%g_EV',eval(FileName(18:end-4))); load(name);
EV = Condition_effect_EV(1:5,:); % no point plotting 0, just pick 5 1st Eigen values
test = sum(sum(EV>1,2)>1); % check if we have more than 1 EV>1
if test <=1; choice = 'Roy'; else choice = 'Pillai'; end
clear Condition_effect_EV;
load(FileName);
F_values(:,1) = squeeze(Condition_effect(:,1));
F_values(:,2) = squeeze(Condition_effect(:,3));
[M, mask, mytitle] = limo_statm_values(Type,FileName,p,MCC,LIMO,choice);
if isempty(mask)
return
elseif sum(mask(:)) == 0
warndlg(' no values under threshold ','no significant effect','modal');
toplot = []; return
else
if strcmp(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
elseif strncmp(FileName,'Covariate_effect',16)
cd(LIMO.dir);
if strcmp(FileName(end-6:end),'_EV.mat'); FileName = [FileName(1:end-7) '.mat']; end
name = sprintf('Covariate_effect_%g_EV',eval( FileName(18:end-4))); load(name);
EV = Covariate_effect_EV(1:5,:); % no point plotting 0, just pick 5 1st Eigen values
test = sum(sum(Covariate_effect_EV(1:5,:)>1,2)>1); % check if we have more than 1 EV>1
if test ==1; choice = 'Roy'; else choice = 'Pillai'; end
clear Covariate_effect_EV;
load(FileName);
F_values(:,1) = squeeze(Covariate_effect(:,1));
F_values(:,2) = squeeze(Covariate_effect(:,3));
[M, mask, mytitle] = limo_statm_values(Type,FileName,p,MCC,LIMO,choice);
if isempty(mask)
return
elseif sum(mask(:)) == 0
warndlg(' no values under threshold ','no significant effect','modal');
toplot = []; return
else
if strcmp(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
h = subplot(3,3,[4 5 7 8]);
timevect = linspace(LIMO.data.start,LIMO.data.end,size(EV,2));
ratio = (LIMO.data.end*1000 - LIMO.data.start*1000) / size(EV,2);
if LIMO.data.start < 0
frame_zeros = round(abs(LIMO.data.start*1000) / ratio);
end
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('5 first Eigen values','Fontsize',14)
% imagesc effect values
subplot(3,3,[1 2]);
scale = toplot'.*mask; scale(scale==0)=NaN;
imagesc(timevect,1,scale);
v = max(toplot(:)); [~,f]=find(toplot==v);
try
caxis([min(min(scale)), max(max(scale))]);
end
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
case{2}
%--------------------------
% topoplot
%--------------------------
% univariate results from 1st level analysis
% ------------------------------------------
if strcmp(LIMO.Analysis,'Time-Frequency')
warndlg('topoplot not supported for 3D data')
else
EEG.trials = 1;
EEG.chanlocs = LIMO.data.chanlocs;
if strcmp(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;
else strcmp(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
try
EEG.freq = eval(cell2mat(freqlist));
catch NO_NUM
EEG.freq = str2num(cell2mat(freqlist));
end
if min(EEG.freq)<EEG.xmin || max(EEG.freq)>EEG.xmax
errordlg('slected frequency out of bound'); return
end
end
end
if strcmp(FileName,'R2.mat')
EEG.data = squeeze(R2(:,:,2));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = 'R2 - F values';
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:2),EEG.data);
elseif strncmp(FileName,'Condition_effect',16)
EEG.data = squeeze(Condition_effect(:,:,1));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = sprintf('Condition %s - F values',FileName(18:end-4));
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:9),EEG.data);
elseif strncmp(FileName,'Covariate_effect',16)
EEG.data = squeeze(Covariate_effect(:,:,1));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = sprintf('Covariate %s - F values',FileName(18:end-4));
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:9),EEG.data);
elseif strncmp(FileName,'Interaction_effect',18)
EEG.data = squeeze(Interaction_effect(:,:,1));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = sprintf('Interaction %s - F values',FileName(20:end-4));
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:11),EEG.data);
elseif strcmp(FileName,'semi partial_coef.mat')
regressor = str2num(cell2mat(inputdlg('which regressor(s) to plot (e.g. 1:3)','Plotting option')));
if max(regressor) > size(Partial_coef,3); errordlg('error in regressor number'); return; end
for b = regressor
EEG.data = squeeze(Partial_coef(:,:,b,1));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = sprintf('semi partial coef R2 values variable %g',b);
EEG.pnts = size(EEG.data,2);
EEG.times = LIMO.data.start/1000:(LIMO.data.sampling_rate/1000):LIMO.data.end/1000;
EEG.trials = 1;
EEG.chanlocs = LIMO.data.chanlocs;
EEG.nbchan = size(EEG.data,1);
if strcmp(LIMO.Analysis,'Time')
EEG.xmin = LIMO.data.start/1000;
EEG.xmax = LIMO.data.end/1000;
pop_topoplot(EEG);
else
EEG.xmin = LIMO.data.freqlist(1);
EEG.xmax = LIMO.data.freqlist(end);
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
tmp_name = sprintf('semi_partial_coef_%g',b);
assignin('base',tmp_name,EEG.data);
end
elseif strcmp(FileName(1:4),'con_')
EEG.data = squeeze(con(:,:,4));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = ['Contrast ',[FileName(5:end-4)],' -- T values'];
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:8),EEG.data);
elseif strcmp(FileName(1:4),'ess_')
EEG.data = squeeze(ess(:,:,end-1));
EEG.pnts = size(EEG.data,2);
EEG.nbchan = size(EEG.data,1);
EEG.setname = ['Contrast ',[FileName(5:end-4)],' -- F values'];
if strcmp(LIMO.Analysis,'Time')
pop_topoplot(EEG);
else
N = size(EEG.freq,2); figure;
for f=1:N
if N<=6
subplot(1,N,f)
else
subplot(ceil(N/6),6,f);
end
[~,ind] = min(abs(LIMO.data.freqlist-EEG.freq(f)));
topoplot(EEG.data(:,ind),EEG.chanlocs);
title([num2str(LIMO.data.freqlist(ind)) ' Hz'],'FontSize',12)
end
end
assignin('base',EEG.setname(1:8),EEG.data);
else
disp('file not supported');
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
try regressor = sort(eval(cell2mat(regressor)));
if max(regressor) > size(LIMO.design.X,2); errordlg('invalid regressor number'); end
catch ME
return
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
errordlg('you can''t plot categorical and continuous regressors together'); return
end
% which ERP to make
% ------------------
if isempty(g.plot3type) && ~any(strcmp(g.plot3type,{'Original','Modelled','Adjusted'}))
extra = questdlg('Plotting ERP','ERP Options','Original','Modelled','Adjusted','Adjusted');
else
extra = g.plot3type;
end
if isempty(extra)
return;
elseif strcmp(extra,'Original')
if regressor == size(LIMO.design.X,2)
errordlg('you can''t plot adjusted mean for original data'); return
end
end
% timing /frequency info
% -----------------------
if strcmp(LIMO.Analysis,'Time')
timevect = LIMO.data.start:(1000/LIMO.data.sampling_rate):LIMO.data.end;
elseif strcmp(LIMO.Analysis,'Frequency')
freqvect=LIMO.data.freqlist';
elseif strcmp(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 electrode/frequency to plot
% --------------------------------
if isempty(g.channels)
electrode = inputdlg('which electrode to plot','Plotting option');
else
electrode = g.channels;
end
if strcmp(LIMO.Analysis,'Time-Frequency')
disp('loading the 4D data ...')
frequency = inputdlg('which Frequency to plot','Plotting option');
else
frequency = [];
end
if strcmp(electrode,'') || strcmp(frequency,'')
disp('looking for max'); load R2;
if strcmp(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 strcmp(electrode,''); electrode = e;
else electrode = eval(cell2mat(electrode)); end
if size(electrode) > 1
errordlg('invalid electrode choice'); return
elseif electrode > size(LIMO.data.chanlocs,2) || electrode < 1
errordlg('invalid electrode number'); return
end
if strcmp(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
[electrode,~] = ind2sub(size(tmp),find(tmp==max(tmp(:))));
end
clear tmp
else
electrode = eval(cell2mat(electrode));
if size(electrode) > 1
errordlg('invalid electrode choice'); return
elseif electrode > size(LIMO.data.chanlocs,2) || electrode < 1
errordlg('invalid electrode 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 strcmp(LIMO.Analysis,'Time-Frequency') && isfield(LIMO.cache,'ERPplot')
if mean([LIMO.cache.ERPplot.electrode == electrode ...
LIMO.cache.ERPplot.regressor == regressor ...
LIMO.cache.ERPplot.frequency == frequency]) == 1 ...
&& strcmp('LIMO.cache.ERPplot.extra',extra)
if sum(regressor <= categorical) == length(regressor)
average = LIMO.cache.ERPplot.average;
ci = LIMO.cache.ERPplot.ci;
mytitle = LIMO.cache.ERPplot.title;
disp('using cached data');
data_cached = 1;
else
continuous = LIMO.cache.ERPplot.continuous;
mytitle = LIMO.cache.ERPplot.title;
disp('using cached data');
data_cached = 1;
end
end
elseif strcmp(LIMO.Analysis,'Time') && isfield(LIMO.cache,'ERPplot') || ...
strcmp(LIMO.Analysis,'Frequency') && isfield(LIMO.cache,'ERPplot')
if mean([LIMO.cache.ERPplot.electrode == electrode ...
LIMO.cache.ERPplot.regressor == regressor]) == 1 ...
&& strcmp('LIMO.cache.ERPplot.extra',extra)
if sum(regressor <= categorical) == length(regressor)
average = LIMO.cache.ERPplot.average;
ci = LIMO.cache.ERPplot.ci;
mytitle = LIMO.cache.ERPplot.title;
disp('using cached data');
data_cached = 1;
else
continuous = LIMO.cache.ERPplot.continuous;
mytitle = LIMO.cache.ERPplot.title;
disp('using cached data');
data_cached = 1;
end
end
end
end
% no cache = compute
if data_cached == 0
probs = [p/2; 1-p/2];
z = norminv(probs);
if strcmp(extra,'Original')
load Yr;
if sum(regressor <= categorical) == length(regressor) % for categorical variables
for i=1:length(regressor)
index{i} = find(LIMO.design.X(:,regressor(i)));
if strcmp(LIMO.Analysis,'Time-Frequency')
data = squeeze(Yr(electrode,freq_index,:,index{i}));
mytitle = sprintf('Original ERSP at \n electrode %s (%g) at %g Hz', LIMO.data.chanlocs(electrode).labels, electrode, frequency);
else
data = squeeze(Yr(electrode,:,index{i}));
end
average(i,:) = mean(data,2);
se = (std(data') ./ sqrt(numel(index{i})));
ci(i,:,:) = repmat(average(i,:),2,1) + repmat(se,2,1).*repmat(z,1,size(Yr,2));
end
if strcmp(LIMO.Analysis,'Time')
mytitle = sprintf('Original ERP at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
elseif strcmp(LIMO.Analysis,'Frequency')
mytitle = sprintf('Original Power Spectrum at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
end
else % continuous variable
for i=1:length(regressor)
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 strcmp(LIMO.Analysis,'Time-Frequency')
continuous(i,:,:) = Yr(electrode,freq_index,:,sorting_values);
mytitle{i} = sprintf('Original single trials \n sorted by regressor %g electrode %s (%g)', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode);
else
continuous(i,:,:) = Yr(electrode,:,sorting_values);
mytitle{i} = sprintf('Original single trials \n sorted by regressor %g \n electrode %s (%g) at %s Hz', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode, frequency);
end
end
end
clear Yr
elseif strcmp(extra,'Modelled')
load Betas;
if strcmp(LIMO.Analysis,'Time-Frequency')
Betas = squeeze(Betas(electrode,freq_index,:,:));
else
Betas = squeeze(Betas(electrode,:,:));
end
Yh = (LIMO.design.X*Betas')'; % modelled data
if sum(regressor <= categorical) == length(regressor) % for categorical variables
load Yr;
if strcmp(LIMO.Analysis,'Time-Frequency')
Yr = squeeze(Yr(:,freq_index,:,:));
end
R = eye(size(Yr,3)) - (LIMO.design.X*pinv(LIMO.design.X));
for i=1:length(regressor)
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(electrode,:,index{i}))')'*(R(index{i},index{i})*squeeze(Yr(electrode,:,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 strcmp(LIMO.Analysis,'Time')
mytitle = sprintf('Modelled ERP at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
elseif strcmp(LIMO.Analysis,'Frequency')
mytitle = sprintf('Modelled Power Spectrum at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
else
mytitle = sprintf('Modelled ERSP \n electrode %s (%g) at %g Hz', LIMO.data.chanlocs(electrode).labels, electrode, frequency);
end
else % continuous variable
for i=1:length(regressor)
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 strcmp(LIMO.Analysis,'Time-Frequency')
mytitle{i} = sprintf('Modelled single trials \n sorted by regressor %g \n electrode %s (%g) at %g Hz', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode, frequency);
else
mytitle{i} = sprintf('Modelled single trials \n sorted by regressor %g electrode %s (%g)', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode);
end
end
end
else % Adjusted
all = [1:size(LIMO.design.X,2)-1]; all(regressor)=[];
if strcmp(LIMO.Analysis,'Time-Frequency')
load Yr; Yr = squeeze(Yr(electrode,freq_index,:,:));
load Betas; Betas = squeeze(Betas(electrode,freq_index,:,:));
else
load Yr; Yr = squeeze(Yr(electrode,:,:));
load Betas; Betas = squeeze(Betas(electrode,:,:));
end
confounds = (LIMO.design.X(:,all)*Betas(:,all)')';
Ya = Yr - confounds; clear Yr Betas confounds;
if sum(regressor <= categorical) == length(regressor) % for categorical variables
for i=1:length(regressor)
index{i} = find(LIMO.design.X(:,regressor(i)));
data = squeeze(Ya(:,index{i}));
average(i,:) = mean(data,2);
se = std(data') ./ sqrt(numel(index{i}));
ci(i,:,:) = repmat(average(i,:),2,1) + repmat(se,2,1).*repmat(z,1,size(Ya,1));
end
if strcmp(LIMO.Analysis,'Time')
mytitle = sprintf('Adjusted ERP at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
elseif strcmp(LIMO.Analysis,'Frequency')
mytitle = sprintf('Adjusted Power Spectrum at electrode %s (%g)', LIMO.data.chanlocs(electrode).labels, electrode);
else
mytitle = sprintf('Adjusted ERSP electrode %s (%g) at %g Hz', LIMO.data.chanlocs(electrode).labels, electrode, frequency);
end
else % continuous variable
for i=1:length(regressor)
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 strcmp(LIMO.Analysis,'Time-Frequency')
mytitle{i} = sprintf('Adjusted single trials \n sorted by regressor \n %g electrode %s (%g) at %g Hz', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode, frequency);
else
mytitle{i} = sprintf('Adjusted single trials \n sorted by regressor %g electrode %s (%g)', regressor(i), LIMO.data.chanlocs(electrode).labels, electrode);
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 strcmp(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 strcmp(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 strcmp(LIMO.cache.fig.name,name) && ...
LIMO.cache.fig.MCC == MCC && ...
LIMO.cache.fig.threshold == p
if strcmp(LIMO.Analysis,'Time-Frequency')
sig = single(LIMO.cache.fig.mask(electrode,freq_index,:)); sig(find(sig==0)) = NaN;
else
sig = single(LIMO.cache.fig.mask(electrode,:)); sig(find(sig==0)) = NaN;
end
end
else
if strcmp(LIMO.Analysis,'Time-Frequency')
[M, mask, mytitle2] = limo_stat_values_tf(1,name,p,MCC,LIMO,choice);
sig = single(squeeze(mask(electrode,freq_index,:))); sig(find(sig==0)) = NaN;
else
[M, mask, mytitle2] = limo_stat_values(1,name,p,MCC,LIMO,choice);
sig = single(mask(electrode,:)); sig(find(sig==0)) = NaN;
end
end
h = axis;
if strcmp(LIMO.Analysis,'Frequency')
plot(freqvect,sig.*h(3),'r*','LineWidth',2)
else
plot(timevect,sig.*h(3),'r*','LineWidth',2)
end
break
end
else
index = index+LIMO.design.nb_conditions(i);
if i<length(LIMO.design.nb_conditions)
index2 = LIMO.design.nb_conditions(i)+LIMO.design.nb_conditions(i+1);
end
end
end
if LIMO.design.nb_interactions ~= 0
index = sum(LIMO.design.nb_conditions)+1; index2 = sum(LIMO.design.nb_conditions)+LIMO.design.nb_interactions(1);
for i=1:length(LIMO.design.nb_interactions)
effect = index:index2;
if length(regressor) == length(effect)
if mean(regressor == effect) == 1
name = sprintf('Interaction_effect_%g.mat',i); load(name);
if isfield(LIMO,'cache') && isfield(LIMO,'fig')
if strcmp(LIMO.cache.fig.name,name) && ...
LIMO.cache.fig.MCC == MCC && ...
LIMO.cache.fig.threshold == p
if strcmp(LIMO.Analysis,'Time-Frequency')
sig = single(squeeze(LIMO.cache.fig.mask(electrode,freq_index,:))); sig(find(sig==0)) = NaN;
else
sig = single(LIMO.cache.fig.mask(electrode,:)); sig(find(sig==0)) = NaN;
end
end
else
if strcmp(LIMO.Analysis,'Time-Frequency')
[M, mask, mytitle2] = limo_stat_values_tf(1,name,p,MCC,LIMO,choice);
sig = single(squeeze(mask(electrode,freq_index,:))); sig(find(sig==0)) = NaN;
else
[M, mask, mytitle2] = limo_stat_values(1,name,p,MCC,LIMO,choice);
sig = single(mask(electrode,:)); sig(find(sig==0)) = NaN;
end
end
h = axis;
if strcmp(LIMO.Analysis,'Frequency')
plot(freqvect,sig.*h(3),'r*','LineWidth',2)
else
plot(timevect,sig.*h(3),'r*','LineWidth',2)