-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathERP_analysis.m
2527 lines (2199 loc) · 107 KB
/
ERP_analysis.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
% Nuttida last updated on 3 March 2018
% Note:
% - This script analyzes ERPs for all minus the first 20 trials of each
% block
%--------------------------------------------------------------------------
addpath(genpath('/local/home/serenceslab/serenceslab_toolboxes/genTools/'))
clear all; close all;
sub = [1 2 4:9 11:14 16 18 19 20 21]; %17 subjects
%% stacking all subjects' data
for s = 1:size(sub,2)
cd (['data/sbj' num2str(sub(s))]);
clear erp erpf erptg erptgf erp_resp erp_respf
%load (['erp_sbj' num2str(sub(s))]); %this one has both trial-onset locked and tg locked
load(['erp_tglocked_cutfirst20_sbj' num2str(sub(s))]); %tg locked
load(['erp_resplocked_cutfirst20_subj' num2str(sub(s))]); %resp locked
cd ../..
%trial onset locked
% gerp(s, :, :, :, :, :, :) = erp;
% gerpf(s, :, :, :, :, :, :) = erpf; %filtered
%tg locked
gerp_tg(s, :, :, :, :, :, :) = erptg;
gerp_tgf(s, :, :, :, :, :, :) = erptgf; %filtered
%resp locked
gerp_resp(s, :, :, :, :, :, :) = erpresp;
gerp_respf(s, :, :, :, :, :, :) = erprespf; %filtered
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for figures plotting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fig_gerp_tg_flicker = gerp_tgf - repmat(nanmean((gerp_tgf), 4), [1, 1, 1, 2, 1, 1, 1]) + ...
repmat(nanmean(nanmean((gerp_tgf), 4)), [s, 1, 1, 2, 1, 1, 1]);
fig_gerp_resp_flicker = gerp_respf - repmat(nanmean((gerp_respf), 4), [1, 1, 1, 2, 1, 1, 1]) + ...
repmat(nanmean(nanmean((gerp_respf), 4)), [s, 1, 1, 2, 1, 1, 1]);
fig_gerp_tg_exp = gerp_tgf - repmat(nanmean((gerp_tgf), 3), [1, 1, 3, 1, 1, 1, 1]) + ...
repmat(nanmean(nanmean((gerp_tgf), 3)), [s, 1, 3, 1, 1, 1, 1]);
fig_gerp_resp_exp = gerp_respf - repmat(nanmean((gerp_respf), 3), [1, 1, 3, 1, 1, 1, 1]) + ...
repmat(nanmean(nanmean((gerp_respf), 3)), [s, 1, 3, 1, 1, 1, 1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plotting stuff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b = beh_analysis(sub); %load behavioral data
fq = 1000/512; %512 = EEG sampling rate
clear erp erpf
timex.tg = -1500:fq:1499; %time vector in ms --> 1536 time points for tg locked
timex.resp = -1500:fq:100; %time vector in ms --> 820 time points for resp locked
condi = {'Color Expectation', 'Orientation Expectation', 'Motor Expectation'}; %condition labels
%blabel = {'RT_Color', 'rt_ori', 'rt_resp'}; %labels for behavioral
chan_label = {'FPz', 'AFz', 'Fz', 'FCz' 'Cz', 'CPz', 'Pz', 'POz', '0z'}; %labels for all electrodes
close all;
eoi = [33; ...
37; ...
38 ;...
47 ; ...
48 ; ...
32 ;...
31 ; ...
30 ; ...
29 ;];
close all
rtline = -4:.01:8;
% electrodes used to extract CPP and VN
ch_cpz = 6;
ch_oz = 9;
%% Repeated-Measures 3-way ANOVA
%subject, cond (color/ori/resp), prior, flickerSpeed, hit(2), chan , time point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% tg-locked %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
binsize = 50;
%chosentime.tg = -100:binsize:1500; %time duration of interest (timepoint 718-1536)
chosentime.tg = -250:binsize:1500;
for b = 1:numel(chosentime.tg)
diff.tg = abs(timex.tg - chosentime.tg(b));
timebin.tg(b) = find(diff.tg == min(diff.tg)); %time points that correspond to the starting time (in ms) of each bin
end
for bb = 1:numel(timebin.tg)-1
gerp_tgbinned( :, :, :, :, :, :, bb) = mean(gerp_tg( :, :, :, :, :, :, timebin.tg(bb):timebin.tg(bb+1)-1 ), 7);
end
cntch = 0;
for ch = [ch_cpz ch_oz] %CPz and Oz
cntch = cntch+1;
cntt = 0;
for ttt = 1:numel(timebin.tg)-1 %a total of 32 time bins of interest
cntt = cntt +1;
condcolor_fast_exp = squeeze(gerp_tgbinned(:, 1, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
condcolor_fast_unexp = squeeze(gerp_tgbinned(:, 1, 3, 1, 2, eoi(ch, :), ttt));
condcolor_fast_neu = squeeze(gerp_tgbinned(:, 1, 2, 1, 2, eoi(ch, :), ttt));
condcolor_slow_exp = squeeze(gerp_tgbinned(:, 1, 1, 2, 2, eoi(ch, :), ttt)); %33Hz
condcolor_slow_unexp = squeeze(gerp_tgbinned(:, 1, 3, 2, 2, eoi(ch, :), ttt));
condcolor_slow_neu = squeeze(gerp_tgbinned(:, 1, 2, 2, 2, eoi(ch, :), ttt));
condori_fast_exp = squeeze(gerp_tgbinned(:, 2, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
condori_fast_unexp = squeeze(gerp_tgbinned(:, 2, 3, 1, 2, eoi(ch, :), ttt));
condori_fast_neu = squeeze(gerp_tgbinned(:, 2, 2, 1, 2, eoi(ch, :), ttt));
condori_slow_exp = squeeze(gerp_tgbinned(:, 2, 1, 2, 2, eoi(ch, :), ttt)); %33Hz
condori_slow_unexp = squeeze(gerp_tgbinned(:, 2, 3, 2, 2, eoi(ch, :), ttt));
condori_slow_neu = squeeze(gerp_tgbinned(:, 2, 2, 2, 2, eoi(ch, :), ttt));
condresp_fast_exp = squeeze(gerp_tgbinned(:, 3, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
condresp_fast_unexp = squeeze(gerp_tgbinned(:, 3, 3, 1, 2, eoi(ch, :), ttt));
condresp_fast_neu = squeeze(gerp_tgbinned(:, 3, 2, 1, 2, eoi(ch, :), ttt));
condresp_slow_exp = squeeze(gerp_tgbinned(:, 3, 1, 2, 2, eoi(ch, :), ttt)); %33Hz
condresp_slow_unexp = squeeze(gerp_tgbinned(:, 3, 3, 2, 2, eoi(ch, :), ttt));
condresp_slow_neu = squeeze(gerp_tgbinned(:, 3, 2, 2, 2, eoi(ch, :), ttt));
DV = [condcolor_fast_exp; condcolor_fast_unexp; condcolor_fast_neu; ...
condcolor_slow_exp; condcolor_slow_unexp; condcolor_slow_neu; ...
condori_fast_exp; condori_fast_unexp; condori_fast_neu; ...
condori_slow_exp; condori_slow_unexp; condori_slow_neu; ...
condresp_fast_exp; condresp_fast_unexp; condresp_fast_neu; ...
condresp_slow_exp; condresp_slow_unexp; condresp_slow_neu];
sublist = repmat(1:numel(sub), [1,18])'; % subject list
IVexp = repmat([ones(1,numel(sub)) ones(1,numel(sub)).*2 ones(1,numel(sub)).*3], [1, 6])'; % independent variable: exp/neutral/unexp
IVtask = repmat([ones(1,numel(sub)*6) ones(1,numel(sub)*6).*2 ones(1,numel(sub)*6).*3], [1 1])'; %task condition: color/ori/resp
IVflick= repmat([ones(1,numel(sub)*3) ones(1,numel(sub)*3).*2], [1, 3])'; % independent variable: 50Hz/33Hz
[p, tb1, stats] = anovan(DV, {IVexp, IVtask, IVflick, sublist}, ...
'model', 'full', 'varnames', {'exp/neu/unexp', 'color/ori/resp', '50Hz/33Hz', 'subj'}, 'random', [4]);
%'random', [4] means that we are
%doing repeated measure ANOVA
%within subjects
%and we want the 4th matrix (subj
%in this case) to be random
%*if we don't specify this, it wont
%be repeated measure
panova_tg(cntch, cntt, :) = p; %associated p-values for all factor comparisons
%size 2x32x15 (chansxtime binsxnumber of all comparisons)
%in this case we have 4 things:
%subj, exp, flicker rates, bias
%conds; so it's
%nchoosek(4,4)+(4,3)+(4,2)+(4,1)=15
fvalexp_tg(cntch, cntt, :) = tb1(2, 6); %f-values of expectaion factor
%pvalexp_tg(cntch, cntt, :) = tb1(2, 7);
fvalflick_tg(cntch, cntt, :) = tb1(4, 6); %f-values of flicker rate factor
%pvalflick_tg(cntch, cntt, :) = tb1(4, 7);
fvalcond_tg(cntch, cntt, :) = tb1(3, 6); %f-values of bias cond factor
%pvalcond_tg(cntch, cntt, :) = tb1(3, 7);
%interaction effect of exp x flicker rate
fvalexpflick_tg(cntch, cntt, :) = tb1(7, 6);
end
end
%p-values by effects
%main effects
panova_cpz_exp_tg = panova_tg(1, :, 1); %expectation
panova_oz_exp_tg = panova_tg(2, :, 1);
panova_cpz_cond_tg = panova_tg(1, :, 2); %task conditions
panova_oz_cond_tg = panova_tg(2, :, 2);
panova_cpz_flick_tg = panova_tg(1, :, 3); %flicker rates
panova_oz_flick_tg = panova_tg(2, :, 3);
%interaction effects
panova_cpz_exp_cond_tg = panova_tg(1, :, 5); %exp x cond
panova_oz_exp_cond_tg = panova_tg(2, :, 5);
panova_cpz_exp_flick_tg = panova_tg(1, :, 6); %exp x flicker rates
panova_oz_exp_flick_tg = panova_tg(2, :, 6);
panova_cpz_cond_flick_tg = panova_tg(1, :, 8); %cond x flicker rates
panova_oz_cond_flick_tg = panova_tg(2, :, 8);
panova_cpz_exp_cond_flick_tg = panova_tg(1, :, 11); %exp x cond cond x flicker rates
panova_oz_exp_cond_flick_tg = panova_tg(2, :, 11);
fvalexp_cpz_tg = fvalexp_tg(1, :);
fvalexp_oz_tg = fvalexp_tg(2, :);
fvalflick_cpz_tg = fvalflick_tg(1, :);
fvalflick_oz_tg = fvalflick_tg(2, :);
fvalcond_cpz_tg = fvalcond_tg(1, :);
fvalcond_oz_tg = fvalcond_tg(2, :);
%interaction effect of exp x flicker rate
fvalexpflick_cpz_tg = fvalexpflick_tg(1, :);
fvalexpflick_oz_tg = fvalexpflick_tg(2, :);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%% resp-locked %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear b bb tt ttt diff
binsize = 50;
chosentime.resp = -300:binsize:100; %time duration of interest
for b = 1:numel(chosentime.resp)
diff.resp = abs(timex.resp - chosentime.resp(b));
timebin.resp(b) = find(diff.resp == min(diff.resp));
end
for bb = 1:numel(timebin.resp)-1
gerp_respbinned( :, :, :, :, :, :, bb) = mean(gerp_resp( :, :, :, :, :, :, timebin.resp(bb):timebin.resp(bb+1)-1 ), 7);
end
cntch = 0;
for ch = [ch_cpz ch_oz]
cntch = cntch+1;
cntt = 0;
for ttt = 1:numel(timebin.resp)-1
cntt = cntt +1;
Rcondcolor_fast_exp = squeeze(gerp_respbinned(:, 1, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
Rcondcolor_fast_unexp = squeeze(gerp_respbinned(:, 1, 3, 1, 2, eoi(ch, :), ttt));
Rcondcolor_fast_neu = squeeze(gerp_respbinned(:, 1, 2, 1, 2, eoi(ch, :), ttt));
Rcondcolor_slow_exp = squeeze(gerp_respbinned(:, 1, 1, 2, 2, eoi(ch, :), ttt)); %50Hz
Rcondcolor_slow_unexp = squeeze(gerp_respbinned(:, 1, 3, 2, 2, eoi(ch, :), ttt));
Rcondcolor_slow_neu = squeeze(gerp_respbinned(:, 1, 2, 2, 2, eoi(ch, :), ttt));
Rcondori_fast_exp = squeeze(gerp_respbinned(:, 2, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
Rcondori_fast_unexp = squeeze(gerp_respbinned(:, 2, 3, 1, 2, eoi(ch, :), ttt));
Rcondori_fast_neu = squeeze(gerp_respbinned(:, 2, 2, 1, 2, eoi(ch, :), ttt));
Rcondori_slow_exp = squeeze(gerp_respbinned(:, 2, 1, 2, 2, eoi(ch, :), ttt)); %50Hz
Rcondori_slow_unexp = squeeze(gerp_respbinned(:, 2, 3, 2, 2, eoi(ch, :), ttt));
Rcondori_slow_neu = squeeze(gerp_respbinned(:, 2, 2, 2, 2, eoi(ch, :), ttt));
Rcondresp_fast_exp = squeeze(gerp_respbinned(:, 3, 1, 1, 2, eoi(ch, :), ttt)); %50Hz
Rcondresp_fast_unexp = squeeze(gerp_respbinned(:, 3, 3, 1, 2, eoi(ch, :), ttt));
Rcondresp_fast_neu = squeeze(gerp_respbinned(:, 3, 2, 1, 2, eoi(ch, :), ttt));
Rcondresp_slow_exp = squeeze(gerp_respbinned(:, 3, 1, 2, 2, eoi(ch, :), ttt)); %50Hz
Rcondresp_slow_unexp = squeeze(gerp_respbinned(:, 3, 3, 2, 2, eoi(ch, :), ttt));
Rcondresp_slow_neu = squeeze(gerp_respbinned(:, 3, 2, 2, 2, eoi(ch, :), ttt));
RDV = [Rcondcolor_fast_exp; Rcondcolor_fast_unexp; Rcondcolor_fast_neu; ...
Rcondcolor_slow_exp; Rcondcolor_slow_unexp; Rcondcolor_slow_neu; ...
Rcondori_fast_exp; Rcondori_fast_unexp; Rcondori_fast_neu; ...
Rcondori_slow_exp; Rcondori_slow_unexp; Rcondori_slow_neu; ...
Rcondresp_fast_exp; Rcondresp_fast_unexp; Rcondresp_fast_neu; ...
Rcondresp_slow_exp; Rcondresp_slow_unexp; Rcondresp_slow_neu];
Rsublist = repmat(1:numel(sub), [1,18])'; % subject list
RIVexp = repmat([ones(1,numel(sub)) ones(1,numel(sub)).*2 ones(1,numel(sub)).*3], [1, 6])'; % independent variable: exp/neutral/unexp
RIVtask = repmat([ones(1,numel(sub)*6) ones(1,numel(sub)*6).*2 ones(1,numel(sub)*6).*3], [1 1])'; %task condition: color/ori/resp
RIVflick= repmat([ones(1,numel(sub)*3) ones(1,numel(sub)*3).*2], [1, 3])'; % independent variable: 50Hz/33Hz
[Rp, Rtb1, Rstats] = anovan(RDV, {RIVexp, RIVtask, RIVflick, Rsublist}, ...
'model', 'full', 'varnames', {'exp/neu/unexp', 'color/ori/resp', '50Hz/33Hz', 'subj'}, 'random', [4]);
panova_resp (cntch, cntt, :) = Rp;
fvalexp_resp (cntch, cntt, :) = Rtb1(2, 6);
fvalflick_resp (cntch, cntt, :) = Rtb1(4, 6);
fvalcond_resp (cntch, cntt, :) = Rtb1(3, 6);
%interaction effect of exp x flicker rate
fvalexpflick_resp (cntch, cntt, :) = Rtb1(7, 6);
end
end
%p-values by effects
%main effects
panova_cpz_exp_resp = panova_resp(1, :, 1); %expectation
panova_oz_exp_resp = panova_resp(2, :, 1);
panova_cpz_cond_resp = panova_resp(1, :, 2); %cond conditions
panova_oz_cond_resp = panova_resp(2, :, 2);
panova_cpz_flick_resp = panova_resp(1, :, 3); %flicker rates
panova_oz_flick_resp = panova_resp(2, :, 3);
%interaction effects
panova_cpz_exp_cond_resp = panova_resp(1, :, 5); %exp x cond
panova_oz_exp_cond_resp = panova_resp(2, :, 5);
panova_cpz_exp_flick_resp = panova_resp(1, :, 6); %exp x flicker rates
panova_oz_exp_flick_resp = panova_resp(2, :, 6);
panova_cpz_cond_flick_resp = panova_resp(1, :, 8); %cond x flicker rates
panova_oz_cond_flick_resp = panova_resp(2, :, 8);
panova_cpz_exp_cond_flick_resp = panova_resp(1, :, 11); %exp x cond x flicker rates
panova_oz_exp_cond_flick_resp = panova_resp(2, :, 11);
%f-values
fvalexp_cpz_resp = fvalexp_resp(1, :);
fvalexp_oz_resp = fvalexp_resp(2, :);
fvalflick_cpz_resp = fvalflick_resp(1, :);
fvalflick_oz_resp = fvalflick_resp(2, :);
fvalcond_cpz_resp = fvalcond_resp(1, :);
fvalcond_oz_resp = fvalcond_resp(2, :);
%interaction effect of exp x flicker rate
fvalexpflick_cpz_resp = fvalexpflick_resp(1, :);
fvalexpflick_oz_resp = fvalexpflick_resp(2, :);
%stacking p and f values for visual aesthetics
%cpz
cpz_flick_tg = [panova_cpz_flick_tg; cell2mat(fvalflick_cpz_tg)];
%size = 2x32; first row is p-values & 2nd row is f-values
cpz_exp_tg = [panova_cpz_exp_tg; cell2mat(fvalexp_cpz_tg)];
cpz_cond_tg = [panova_cpz_cond_tg; cell2mat(fvalcond_cpz_tg)];
cpz_flick_resp = [panova_cpz_flick_resp; cell2mat(fvalflick_cpz_resp)];
%size = 2x32; first row is p-values & 2nd row is f-values
cpz_exp_resp = [panova_cpz_exp_resp; cell2mat(fvalexp_cpz_resp)];
cpz_cond_resp = [panova_cpz_cond_resp; cell2mat(fvalcond_cpz_resp)];
%interaction effect
cpz_exp_flick_tg = [panova_cpz_exp_flick_tg; cell2mat(fvalexpflick_cpz_tg)];
cpz_exp_flick_resp = [panova_cpz_exp_flick_resp; cell2mat(fvalexpflick_cpz_resp)];
%oz
oz_flick_tg = [panova_oz_flick_tg; cell2mat(fvalflick_oz_tg)];
%size = 2x32; first row is p-values & 2nd row is f-values
oz_exp_tg = [panova_oz_exp_tg; cell2mat(fvalexp_oz_tg)];
oz_cond_tg = [panova_oz_cond_tg; cell2mat(fvalcond_oz_tg)];
oz_flick_resp = [panova_oz_flick_resp; cell2mat(fvalflick_oz_resp)];
%size = 2x32; first row is p-values & 2nd row is f-values
oz_exp_resp = [panova_oz_exp_resp; cell2mat(fvalexp_oz_resp)];
oz_cond_resp = [panova_oz_cond_resp; cell2mat(fvalcond_oz_resp)];
%interaction effect
oz_exp_flick_tg = [panova_oz_exp_flick_tg; cell2mat(fvalexpflick_oz_tg)];
oz_exp_flick_resp = [panova_oz_exp_flick_resp; cell2mat(fvalexpflick_oz_resp)];
%% FDR Correction
%combine CPz, Oz of both tg- and resp-locked
%main effects
chosentime.tgresp = [chosentime.tg(1:end-1), chosentime.resp(1:end-1)];
%made time time vector from combining chosen time in
%bins of tg locked and resp locked data; size = 1x40;
%can be used with p_fdr to quickly search sig time bins
[p_fdr_flick, p_masked_flick] = fdr([panova_cpz_flick_tg panova_oz_flick_tg ...
panova_cpz_flick_resp panova_oz_flick_resp], 0.05, 'parametric');
[p_fdr_exp, p_masked_exp] = fdr([panova_cpz_exp_tg panova_oz_exp_tg ...
panova_cpz_exp_resp panova_oz_exp_resp], 0.05, 'parametric'); %
[p_fdr_cond, p_masked_cond] = fdr([panova_cpz_cond_tg panova_oz_cond_tg ...
panova_cpz_cond_resp panova_oz_cond_resp], 0.05, 'parametric');
%071317
[p_fdr_flickexp, p_masked_flickexp] = fdr([panova_cpz_flick_tg panova_cpz_flick_resp ...
panova_cpz_exp_tg panova_cpz_exp_resp panova_oz_flick_tg panova_oz_flick_resp ...
panova_oz_exp_tg panova_oz_exp_resp], 0.05, 'parametric');
[p_fdr_cond, p_masked_cond] = fdr([panova_cpz_cond_tg panova_cpz_cond_resp ...
panova_oz_cond_tg panova_oz_cond_resp], 0.05, 'parametric');
% main_effect_cpz = [[1:32, 1:8]', chosentime.tgresp', [p_masked_flick(1:32),...
% p_masked_flick(65:72)]', [p_masked_exp(1:32), p_masked_exp(65:72)]', ...
% [p_masked_cond(1:32), p_masked_cond(65:72)]']; %a summary of main effects of cpz channel
%
% main_effect_oz = [[1:32, 1:8]', chosentime.tgresp', [p_masked_flick(33:64),...
% p_masked_flick(73:80)]', [p_masked_exp(33:64), p_masked_exp(73:80)]', ...
% [p_masked_cond(33:64), p_masked_cond(73:80)]']; %a summary of main effects of cpz channel
% %size = 40x5 b/c we have 32+8 time points from tg locked and
% %resp locked.
% %1st row = ith time bin
% %2nd row = time in ms of the begining of each bin
% %3th, 4th, 5th row = p_masked_flicker, p_masked_exp, p_masked_cond
%same as below--just hard code to double check
% main_effect_cpz = [[1:numel(timebin.tg)-1, 1:numel(timebin.resp)-1]', ...
% chosentime.tgresp', [p_masked_flickexp(1:43)]'...
% , [p_masked_flickexp(44:86)]'...
% , [p_masked_cond(1:43)]'];
% main_effect_oz = [[1:numel(timebin.tg)-1, 1:numel(timebin.resp)-1]', ...
% chosentime.tgresp', [p_masked_flickexp(87:129)]'...
% , [p_masked_flickexp(130:172)]'...
% , [p_masked_cond(44:86)]'];
main_effect_cpz = [[1:numel(timebin.tg)-1, 1:numel(timebin.resp)-1]', ...
chosentime.tgresp', [p_masked_flickexp(1:size(chosentime.tgresp, 2))]'...
, [p_masked_flickexp(size(chosentime.tgresp, 2)+1:(size(chosentime.tgresp, 2)*2))]'...
, [p_masked_cond(1:size(chosentime.tgresp, 2))]'];
main_effect_oz = [[1:numel(timebin.tg)-1, 1:numel(timebin.resp)-1]', ...
chosentime.tgresp', [p_masked_flickexp((size(chosentime.tgresp, 2)*2)+1:...
size(chosentime.tgresp, 2)*3)]'...
, [p_masked_flickexp((size(chosentime.tgresp, 2)*3)+1:size(chosentime.tgresp, 2)*4)]'...
, [p_masked_cond(size(chosentime.tgresp, 2)+1:size(chosentime.tgresp, 2)*2)]'];
% all_p_fdr = [p_fdr_flick, p_fdr_exp, p_fdr_cond];
all_p_fdr = [p_fdr_flickexp, p_fdr_cond];
%crit p to check interaction effects
[p_fdr_exp_cond, p_masked_exp_cond] = fdr([panova_cpz_exp_cond_tg ...
panova_oz_exp_cond_tg panova_cpz_exp_cond_resp panova_oz_exp_cond_resp], 0.05, 'parametric');
[p_fdr_exp_flick, p_masked_exp_flick] = fdr([panova_cpz_exp_flick_tg ...
panova_oz_exp_flick_tg panova_cpz_exp_flick_resp panova_oz_exp_flick_resp], 0.05, 'parametric');
[p_fdr_cond_flick, p_masked_cond_flick] = fdr([panova_cpz_cond_flick_tg ...
panova_oz_cond_flick_tg panova_cpz_cond_flick_resp panova_oz_cond_flick_resp], 0.05, 'parametric');
[p_fdr_exp_cond_flick, p_masked_exp_cond_flick] = fdr([panova_cpz_exp_cond_flick_tg ...
panova_oz_exp_cond_flick_tg panova_cpz_exp_cond_flick_resp panova_oz_exp_cond_flick_resp], 0.05, 'parametric');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%sig bins
%flicker rate effect
%cpz tg-locked
sigbin_tg_flick_cpz = find(main_effect_cpz(1:size(chosentime.tg, 2)-1, 3)==1);
sigbin_tg_flick_cpz1 = [sigbin_tg_flick_cpz(1:end-1)];
sigbin_tg_flick_cpz2 = sigbin_tg_flick_cpz(end);
sigtime_tg_flick_cpz1 = [chosentime.tg(sigbin_tg_flick_cpz1(1)) ...
chosentime.tg(sigbin_tg_flick_cpz1(end)+1)];
sigtime_tg_flick_cpz2 = [chosentime.tg(sigbin_tg_flick_cpz2(1)) ...
chosentime.tg(sigbin_tg_flick_cpz2(end)+1)];
%cpz resp-locked
sigbin_resp_flick_cpz = find(main_effect_cpz((size(chosentime.tg, 2):end), 3)==1);
sigbin_resp_flick_cpz1 = sigbin_resp_flick_cpz;
sigtime_resp_flick_cpz1 = [chosentime.resp(sigbin_resp_flick_cpz1(1)) ...
chosentime.resp(sigbin_resp_flick_cpz1(end)+1)];
%oz tg-locked
sigbin_tg_flick_oz = find(main_effect_oz(1:size(chosentime.tg, 2)-1, 3)==1);
sigtime_tg_flick_oz = [chosentime.tg(sigbin_tg_flick_oz(1)) ...
chosentime.tg(sigbin_tg_flick_oz(end)+1)];
%expectation effect
%cpz tg-locked
sigbin_tg_exp_cpz = find(main_effect_cpz(1:size(chosentime.tg, 2)-1, 4)==1);
sigbin_tg_exp_cpz1 = [sigbin_tg_exp_cpz(1:end-1)];
sigbin_tg_exp_cpz2 = [sigbin_tg_exp_cpz(end)];
sigtime_tg_exp_cpz1 = [chosentime.tg(sigbin_tg_exp_cpz1(1)) ...
chosentime.tg(sigbin_tg_exp_cpz1(end)+1)];
sigtime_tg_exp_cpz2 = [chosentime.tg(sigbin_tg_exp_cpz2(1)) ...
chosentime.tg(sigbin_tg_exp_cpz2(end)+1)];
%% CPP & Expectation: Post-Hoc T-Tests
%do this only for time windows with significant expectation main effect to
%see if what pair of exp conditions significantly differ
%a) time chunk 1: 950-1100 ms
cpz_tg_exp1 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 1, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4), 2));
cpz_tg_neu1 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 2, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4), 2));
cpz_tg_unexp1 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 3, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4), 2));
%1) CPP: exp vs. unexp
clear h p ci t
[h p ci t] = ttest(cpz_tg_exp1, cpz_tg_unexp1, 'Tail', 'left'); %we're using one-tailed tests as follow-ups
cpz_tg_expunexp1.p = p;
cpz_tg_expunexp1.h = h;
cpz_tg_expunexp1.t = t.tstat;
cpz_tg_expunexp1.df = t.df;
%2) CPP: exp vs. neu
clear h p ci t
[h p ci t] = ttest(cpz_tg_exp1, cpz_tg_neu1, 'Tail', 'left');
cpz_tg_expneu1.p = p;
cpz_tg_expneu1.h = h;
cpz_tg_expneu1.t = t.tstat;
cpz_tg_expneu1.df = t.df;
%3) CPP: neu vs. unexp
clear h p ci t
[h p ci t] = ttest(cpz_tg_neu1, cpz_tg_unexp1, 'Tail', 'left');
cpz_tg_neuunexp1.p = p;
cpz_tg_neuunexp1.h = h;
cpz_tg_neuunexp1.t = t.tstat;
cpz_tg_neuunexp1.df = t.df;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%b) time chunk 1: 1150-1200 ms
cpz_tg_exp2 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 1, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4), 2));
cpz_tg_neu2 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 2, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4), 2));
cpz_tg_unexp2 = squeeze(mean(mean(mean(gerp_tgbinned(:, :, 3, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4), 2));
%1) CPP: exp vs. unexp
clear h p ci t
[h p ci t] = ttest(cpz_tg_exp2, cpz_tg_unexp2, 'Tail', 'left'); %we're using one-tailed tests as follow-ups
cpz_tg_expunexp2.p = p;
cpz_tg_expunexp2.h = h;
cpz_tg_expunexp2.t = t.tstat;
cpz_tg_expunexp2.df = t.df;
%2) CPP: exp vs. neu
clear h p ci t
[h p ci t] = ttest(cpz_tg_exp2, cpz_tg_neu2, 'Tail', 'left');
cpz_tg_expneu2.p = p;
cpz_tg_expneu2.h = h;
cpz_tg_expneu2.t = t.tstat;
cpz_tg_expneu2.df = t.df;
%3) CPP: neu vs. unexp
clear h p ci t
[h p ci t] = ttest(cpz_tg_neu2, cpz_tg_unexp2, 'Tail', 'left');
cpz_tg_neuunexp2.p = p;
cpz_tg_neuunexp2.h = h;
cpz_tg_neuunexp2.t = t.tstat;
cpz_tg_neuunexp2.df = t.df;
%% CPP & Expectation: Follow-up one-way ANOVA on individual task condition (sig chunks only)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%do this on data collapsed across sig time chunk separately for each
%individual task condition to see if the main expectation effect
%(tested via ANOVA on data collapsed across 3 task conditions)
%tg-locked
%a) time chunk one: 920-1100 ms
for cond = 1:3
cond_exp1 = squeeze(mean(mean(gerp_tgbinned(:, cond, 1, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4));
cond_neu1 = squeeze(mean(mean(gerp_tgbinned(:, cond, 2, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4));
cond_unexp1 = squeeze(mean(mean(gerp_tgbinned(:, cond, 3, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz1), 7), 4));
DV1 = [cond_exp1; cond_neu1; cond_unexp1];
sublist = repmat(1:numel(sub), [1, 3])'; %subject list
IVexp = repmat([ones(1, numel(sub)) ones(1, numel(sub)).*2 ...
ones(1, numel(sub)).*3], [1, 1])';
[p, tbl, stats] = anovan(DV1, {IVexp, sublist}, 'model', 'full', 'varnames',...
{'exp/neu/unexp', 'subj'}, 'random', [2]);
p_indivcond_exp_tg1(cond, :) = p;
fvalue_indivcond_exp_tg1(cond, :) = tbl(2, 6);
end
%b) time chunk one: 1150-1200 ms
for cond = 1:3
cond_exp2 = squeeze(mean(mean(gerp_tgbinned(:, cond, 1, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4));
cond_neu2 = squeeze(mean(mean(gerp_tgbinned(:, cond, 2, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4));
cond_unexp2 = squeeze(mean(mean(gerp_tgbinned(:, cond, 3, :, 2, eoi(ch_cpz, :),...
sigbin_tg_exp_cpz2), 7), 4));
DV2 = [cond_exp2; cond_neu2; cond_unexp2];
sublist = repmat(1:numel(sub), [1, 3])'; %subject list
IVexp = repmat([ones(1, numel(sub)) ones(1, numel(sub)).*2 ...
ones(1, numel(sub)).*3], [1, 1])';
[p, tbl, stats] = anovan(DV2, {IVexp, sublist}, 'model', 'full', 'varnames',...
{'exp/neu/unexp', 'subj'}, 'random', [2]);
p_indivcond_exp_tg2(cond, :) = p;
fvalue_indivcond_exp_tg2(cond, :) = tbl(2, 6);
end
%% CPP & Flicker rate: Follow-up t-test on individual task condition (sig chunks only)
%1) tg-locked
for cond = 1:3
cpz_tg_fast1 = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 1, 2, ...
eoi(ch_cpz, :), sigbin_tg_flick_cpz1), 7), 3)); %time window 1
cpz_tg_slow1 = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 2, 2, ...
eoi(ch_cpz, :), sigbin_tg_flick_cpz1), 7), 3));
cpz_tg_fast2 = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 1, 2, ...
eoi(ch_cpz, :), sigbin_tg_flick_cpz2), 7), 3)); %time window 2
cpz_tg_slow2 = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 2, 2, ...
eoi(ch_cpz, :), sigbin_tg_flick_cpz2), 7), 3));
clear h p ci t
[h p ci t] = ttest(cpz_tg_fast1, cpz_tg_slow1, 'Tail', 'right');
cpz_tg_flick1.p(cond) = p;
cpz_tg_flick1.h(cond) = h;
cpz_tg_flick1.t(cond) = t.tstat;
cpz_tg_flick1.df(cond) = t.df;
clear h p ci t
[h p ci t] = ttest(cpz_tg_fast2, cpz_tg_slow2, 'Tail', 'left');
cpz_tg_flick2.p(cond) = p;
cpz_tg_flick2.h(cond) = h;
cpz_tg_flick2.t(cond) = t.tstat;
cpz_tg_flick2.df(cond) = t.df;
end
%2) resp-locked
for cond = 1:3
cpz_resp_fast1 = squeeze(mean(mean(gerp_respbinned(:, cond, [1 2 3], 1, 2, ...
eoi(ch_cpz, :), sigbin_resp_flick_cpz1), 7), 3));
cpz_resp_slow1 = squeeze(mean(mean(gerp_respbinned(:, cond, [1 2 3], 2, 2, ...
eoi(ch_cpz, :), sigbin_resp_flick_cpz1), 7), 3));
clear h p ci t
[h p ci t] = ttest(cpz_resp_fast1, cpz_resp_slow1, 'Tail', 'right');
cpz_resp_flick1.p(cond) = p;
cpz_resp_flick1.h(cond) = h;
cpz_resp_flick1.t(cond) = t.tstat;
cpz_resp_flick1.df(cond) = t.df;
end
%% VN & Flicker rate: Follow-up t-test on individual task condition (sig chunks only)
%1) tg-locked
for cond = 1:3
oz_tg_fast = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 1, 2, ...
eoi(ch_oz, :), sigbin_tg_flick_oz), 7), 3));
oz_tg_slow = squeeze(mean(mean(gerp_tgbinned(:, cond, [1 2 3], 2, 2, ...
eoi(ch_oz, :), sigbin_tg_flick_oz), 7), 3));
clear h p ci t
[h p ci t] = ttest(oz_tg_fast, oz_tg_slow, 'Tail', 'left');
oz_tg_flick.p(cond) = p;
oz_tg_flick.h(cond) = h;
oz_tg_flick.t(cond) = t.tstat;
oz_tg_flick.df(cond) = t.df;
end
%% stacking all p- and F-values
% p-value and F-value ranges for the flicker rate ane expectation chunks
% on collapsed data
%flicker rate effect
%cpz tg-locked chunk#1
sig_tg_flick_cpz1 = cpz_flick_tg(:, sigbin_tg_flick_cpz1);
minmax_tg_flick_cpz1 = [sig_tg_flick_cpz1(:, find(sig_tg_flick_cpz1(1,:) == ...
min(sig_tg_flick_cpz1(1, :)))), sig_tg_flick_cpz1(:, find(sig_tg_flick_cpz1(1,:)...
== max(sig_tg_flick_cpz1(1, :))))];
%cpz tg-locked chunk#2
sig_tg_flick_cpz2 = cpz_flick_tg(:, sigbin_tg_flick_cpz2);
minmax_tg_flick_cpz2 = [sig_tg_flick_cpz2(:, find(sig_tg_flick_cpz2(1,:) == ...
min(sig_tg_flick_cpz2(1, :)))), sig_tg_flick_cpz2(:, find(sig_tg_flick_cpz2(1,:)...
== max(sig_tg_flick_cpz2(1, :))))];
%cpz resp-locked chunk#1
sig_resp_flick_cpz1 = cpz_flick_resp(:, sigbin_resp_flick_cpz1);
minmax_resp_flick_cpz1 = [sig_resp_flick_cpz1(:, find(sig_resp_flick_cpz1(1,:) == ...
min(sig_resp_flick_cpz1(1, :)))), sig_resp_flick_cpz1(:, find(sig_resp_flick_cpz1(1,:)...
== max(sig_resp_flick_cpz1(1, :))))];
%oz tg-locked
sig_tg_flick_oz = cpz_flick_tg(:, sigbin_tg_flick_oz);
minmax_tg_flick_oz = [sig_tg_flick_oz(:, find(sig_tg_flick_oz(1,:) == ...
min(sig_tg_flick_oz(1, :)))), sig_tg_flick_oz(:, find(sig_tg_flick_oz(1,:)...
== max(sig_tg_flick_oz(1, :))))];
%expectation effect
%cpz tg-locked
sig_tg_exp_cpz1 = cpz_exp_tg(:, sigbin_tg_exp_cpz1);
minmax_tg_exp_cpz1 = [sig_tg_exp_cpz1(:, find(sig_tg_exp_cpz1(1,:) == ...
min(sig_tg_exp_cpz1(1, :)))), sig_tg_exp_cpz1(:, find(sig_tg_exp_cpz1(1,:)...
== max(sig_tg_exp_cpz1(1, :))))];
sig_tg_exp_cpz2 = cpz_exp_tg(:, sigbin_tg_exp_cpz2);
minmax_tg_exp_cpz2 = [sig_tg_exp_cpz2(:, find(sig_tg_exp_cpz2(1,:) == ...
min(sig_tg_exp_cpz2(1, :)))), sig_tg_exp_cpz2(:, find(sig_tg_exp_cpz2(1,:)...
== max(sig_tg_exp_cpz2(1, :))))];
%NULL EFFECTS
%expectation--oz tg-locked
minmax_tg_exp_oz = [oz_exp_tg(:, find(oz_exp_tg(1,:) == ...
min(oz_exp_tg(1, :)))), oz_exp_tg(:, find(oz_exp_tg(1,:)...
== max(oz_exp_tg(1, :))))];
%expectation--oz resp-locked
% minmax_resp_exp_oz = [oz_exp_resp(:, find(oz_exp_resp(1,:) == ...
% min(oz_exp_resp(1, :)))), oz_exp_resp(:, find(oz_exp_resp(1,:)...
% == max(oz_exp_resp(1, :))))];
%interaction effect: flicker rate x exp
%cpz tg-locked
minmax_tg_expflick_cpz = [cpz_exp_flick_tg(:, find(cpz_exp_flick_tg(1,:) == ...
min(cpz_exp_flick_tg(1, :)))), cpz_exp_flick_tg(:, find(cpz_exp_flick_tg(1,:)...
== max(cpz_exp_flick_tg(1, :))))];
%cpz resp-locked
minmax_resp_expflick_cpz = [cpz_exp_flick_resp(:, find(cpz_exp_flick_resp(1,:) == ...
min(cpz_exp_flick_resp(1, :)))), cpz_exp_flick_resp(:, find(cpz_exp_flick_resp(1,:)...
== max(cpz_exp_flick_resp(1, :))))];
%oz tg-locked
minmax_tg_expflick_oz = [oz_exp_flick_tg(:, find(oz_exp_flick_tg(1,:) == ...
min(oz_exp_flick_tg(1, :)))), oz_exp_flick_tg(:, find(oz_exp_flick_tg(1,:)...
== max(oz_exp_flick_tg(1, :))))];
%oz resp-locked
% minmax_resp_expflick_oz = [oz_exp_flick_resp(:, find(oz_exp_flick_resp(1,:) == ...
% min(oz_exp_flick_resp(1, :)))), oz_exp_flick_resp(:, find(oz_exp_flick_resp(1,:)...
% == max(oz_exp_flick_resp(1, :))))];
%% Figures stuff
close all force;
%set gca stuff
%xlim_tg = [-75 1475];
%xtick_tg = [0:500:1475];
xlim_tg = [-250 1475];
xtick_tg = [-250 0 500 1000 1475];
xlim_resp = [-275 1275];
xtick_resp = [-200 0 75];
ylim_cpz = [-1 10];
ytick_cpz = [0 4 8];
starloc_cpz = 9;
ylim_oz = [-5 5];
ytick_oz = [-4 0 4];
starloc_oz = 3;
flim = [0 50];
ftick = [0:50:50];
plim = [0 0.05];
ptick = [0:0.05:0.05];
%color values for plotting
c_fast = [0 0.4 0]; %green
c_slow = [0.4 0 0.6]; %purple
c_exp = [0 0.4 0.8];
c_neu = [0.5 0.5 0.5]; %grey
c_unexp = [0.8 0 0]; %orange
trans = 0.8; %transparency value for banded error
lwidth = 2.5;
lwidth_sub =1.5;
%% CPP_Fig A left: Flicker rates (collapsed)
close all;
for fig = 1
figure(1); clf;
suptitle('FigA left: CPP & flicker rate (collapsed)')
subplot(3, 2, 1)
%fast flicker rate
a1 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_fast, 'LineWidth', lwidth); hold on;
h1 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
a1, trans);
%slow flicker rate (33Hz)
a2 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_slow, 'LineWidth', lwidth); hold on;
h2 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
a2, trans);
xlim (xlim_tg);
ylim (ylim_cpz);
set(gca, 'XTick', xtick_tg)
set(gca, 'YTick', ytick_cpz)
%title(chan_label(ch), 'FontSize', 15);
%title('Tg-locked', 'FontSize', 10);
ylabel('Amplitude (uv)', 'FontSize', 14)
legend([a1 a2],'Fast Flicker Rate', 'Slow Flicker Rate');
%star plot
for tt =1:numel(timebin.tg)-1
if panova_tg(1, tt, 3) > p_fdr_flickexp
colorsign = [1 1 1];
% elseif panova(cnt, tt, 3) <= 0.05 && panova(cnt, tt, 3) > 0.01
% colorsign = [0.6 0.6 0.6];
% elseif panova(cnt, tt, 3) <= 0.01 && panova(cnt, tt, 3) > 0.001
% colorsign = [0.3 0.3 0.3];
else
colorsign = [0 0 0];
end
if panova_tg(1, tt, 3) <= p_fdr_flickexp
plot(chosentime.tg(tt)+binsize/2, starloc_cpz, '.', 'color', colorsign, 'LineWidth', 10);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3, 2, 2) %resp-locked
%fast flicker rate
a3 = plot(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_fast, 'LineWidth', lwidth); hold on;
h3 = bandedError(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
a3, trans);
%slow flicker rate (33Hz)
a4 = plot(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_slow, 'LineWidth', lwidth); hold on;
h4 = bandedError(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
a4, trans);
%title(chan_label(ch), 'FontSize', 15);
xlim (xlim_resp);
ylim (ylim_cpz);
set(gca, 'XTick', xtick_resp)
set(gca, 'YTick', ytick_cpz)
% title('Resp-locked', 'FontSize', 10);
ylabel('Amplitude (uv)', 'FontSize', 14)
legend([a3 a4],'Fast Flicker Rate', 'Slow Flicker Rate');
%star plot
for tt =1:numel(timebin.resp)-1
if panova_resp(1, tt, 3) > p_fdr_flickexp
colorsign = [1 1 1];
% elseif panova(cnt, tt, 3) <= 0.05 && panova(cnt, tt, 3) > 0.01
% colorsign = [0.6 0.6 0.6];
% elseif panova(cnt, tt, 3) <= 0.01 && panova(cnt, tt, 3) > 0.001
% colorsign = [0.3 0.3 0.3];
else
colorsign = [0 0 0];
end
if panova_resp(1, tt, 3) <= p_fdr_flick
plot(chosentime.resp(tt)+binsize/2, starloc_cpz, '.', 'color', colorsign, 'LineWidth', 10);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3, 2, 3)
plot(chosentime.tg(1:end-1)+binsize/2, cell2mat(fvalflick_cpz_tg),...
'color', 'k', 'Linewidth', lwidth_sub);
ylabel('F', 'FontSize', 14)
xlim (xlim_tg);
ylim(flim)
set(gca, 'XTick', xtick_tg)
set(gca, 'YTick', ftick)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3, 2, 4)
plot(chosentime.resp(1:end-1)+binsize/2, cell2mat(fvalflick_cpz_resp),...
'color', 'k', 'Linewidth', lwidth_sub);
ylabel('F', 'FontSize', 14)
xlim (xlim_resp);
ylim(flim)
set(gca, 'XTick', xtick_resp)
set(gca, 'YTick', ftick)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3, 2, 5)
plot(chosentime.tg(1:end-1)+binsize/2, panova_tg(1, :, 3),...
'color', 'k', 'Linewidth', lwidth_sub); hold on;
plot(timex.tg, repmat(p_fdr_flickexp, [1, size(timex.tg, 2)]),...
'color', 'k', 'LineStyle', '--'); hold on;
ylabel('p', 'FontSize', 14)
xlim (xlim_tg);
ylim(plim);
set(gca, 'XTick', xtick_tg)
set(gca, 'YTick', ptick)
xlabel('Time (ms)', 'FontSize', 14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3, 2, 6)
plot(chosentime.resp(1:end-1)+binsize/2, panova_resp(1, :, 3),...
'color', 'k', 'Linewidth', lwidth_sub); hold on;
plot(timex.resp, repmat(p_fdr_flickexp, [1, size(timex.resp, 2)]),...
'color', 'k', 'LineStyle', '--'); hold on;
ylabel('p', 'FontSize', 14)
xlim (xlim_resp);
ylim(plim);
set(gca, 'XTick', xtick_resp)
set(gca, 'YTick', ptick)
xlabel('Time (ms)', 'FontSize', 14)
end
%topo plot inset
for fig = 2
figure(2); clf;
subplot(2, 2, 1)
%tg-locked
%1)
flick_topolength_tg_cpz1 = [sigbin_tg_flick_cpz1', sigbin_tg_flick_cpz1(end)+1]; %duration of sig flick effect
%purposes
flick_topotime_tg_cpz1 = timebin.tg(flick_topolength_tg_cpz1);
topoplot(squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, :, 1, 2, :, flick_topotime_tg_cpz1),7),3),2)))...
-squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, :, 2, 2, :, flick_topotime_tg_cpz1),7),3),2))), 'mychan.loc'); %fast-slow
colorbar
caxis([-1 1])
title('1) Tg-locked CPP: Fast - Slow Flicker Rate');
subplot(2, 2, 2)
%2)
flick_topolength_tg_cpz2 = [sigbin_tg_flick_cpz2', sigbin_tg_flick_cpz2(end)+1]; %duration of sig flick effect
%purposes
flick_topotime_tg_cpz2 = timebin.tg(flick_topolength_tg_cpz2);
topoplot(squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, :, 1, 2, :, flick_topotime_tg_cpz2),7),3),2)))...
-squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, :, :, 2, 2, :, flick_topotime_tg_cpz2),7),3),2))), 'mychan.loc'); %fast-slow
colorbar
caxis([-1 1])
title('2) Tg-locked CPP: Fast - Slow Flicker Rate');
subplot(2, 2, 3)
%resp-locked
%1)
flick_topolength_resp_cpz1 = [sigbin_resp_flick_cpz1', sigbin_resp_flick_cpz1(end)+1]; %duration of sig flick effect
%purposes
flick_topotime_resp_cpz1 = timebin.resp(flick_topolength_resp_cpz1);
topoplot(squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, :, 1, 2, :, flick_topotime_resp_cpz1),7),3),2)))...
-squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, :, :, 2, 2, :, flick_topotime_resp_cpz1),7),3),2))), 'mychan.loc'); %fast-slow
colorbar
caxis([-1 1])
title('1) Resp-locked CPP: Fast - Slow Flicker Rate');
% subplot(2, 2, 4)
% %2)
% flick_topolength_resp_cpz2 = [sigbin_resp_flick_cpz2', sigbin_resp_flick_cpz2(end)+1]; %duration of sig flick effect
% %purposes
% flick_topotime_resp_cpz2 = timebin.resp(flick_topolength_resp_cpz2);
% topoplot(squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
% (:, :, :, 1, 2, :, flick_topotime_resp_cpz2),7),3),2)))...
% -squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
% (:, :, :, 2, 2, :, flick_topotime_resp_cpz2),7),3),2))), 'mychan.loc'); %fast-slow
% colorbar
% caxis([-1 1])
% title('2) Resp-locked CPP: Fast - Slow Flicker Rate');
end
%% CPP_Fig A right: Flicker rates (individual conditions)
for fig = 3
clear tt
figure(3); clf;
for bc = 1:3
subplot(3, 2, ((bc-1)*2)+1);
%target-locked
%fast flicker rate
b1 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_fast, 'LineWidth', lwidth); hold on;
k1 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
b1, trans);
%slow flicker rate
b2 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_slow, 'LineWidth', lwidth); hold on;
k2 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
b2, trans);
%title(chan_label(ch), 'FontSize', 15);
ylabel('Amplitude (uv)', 'FontSize', 14);
xlim (xlim_tg);
ylim (ylim_cpz);
set(gca, 'XTick', xtick_tg)
set(gca, 'YTick', ytick_cpz)
subplot(3, 2, 2*bc); %resp-locked
%fast flicker rate
b3 = plot(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_fast, 'LineWidth', lwidth); hold on;
k3 = bandedError(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 1, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
b3, trans);
%slow flicker rate
b4 = plot(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))...
, 'Color', c_slow, 'LineWidth', lwidth); hold on;
k4 = bandedError(timex.resp, squeeze(mean(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_resp_flicker...
(:, bc, [1 2 3], 2, 2, eoi(ch_cpz, :), :),6),3),2)))'./sqrt(numel(sub)), ...
b4, trans);
xlim (xlim_resp);
ylim (ylim_cpz);
set(gca, 'XTick', xtick_resp)
set(gca, 'YTick', ytick_cpz)
xlabel('Time (ms)', 'FontSize', 14)
end
legend([b3 b4],'Fast Flicker Rate', 'Slow Flicker Rate');
suptitle('Fig A right: CPP & Flicker Rates (non-collapsed)')
end
%% CPP_Fig B left: Expectation (collapsed)
for fig = 4
figure(4); clf;
suptitle('Fig B left: CPP & expectation (collapsed)')
subplot(3, 2, 1) %target-locked
%expected
c1 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 1, :, 2, eoi(ch_cpz, :), :),6),4),2)))...
, 'Color', c_exp, 'LineWidth', lwidth); hold on;
m1 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 1, :, 2, eoi(ch_cpz, :), :),6),4),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 1, :, 2, eoi(ch_cpz, :), :),6),4),2)))'./sqrt(numel(sub)), ...
c1, trans);
%neutral
c2 = plot(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 2, :, 2, eoi(ch_cpz, :), :),6),4),2)))...
, 'Color', c_neu, 'LineWidth', lwidth); hold on;
m2 = bandedError(timex.tg, squeeze(mean(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 2, :, 2, eoi(ch_cpz, :), :),6),4),2)))', ...
squeeze(std(mean(mean(mean(fig_gerp_tg_exp...
(:, :, 2, :, 2, eoi(ch_cpz, :), :),6),4),2)))'./sqrt(numel(sub)), ...
c2, trans);