-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bike2_ComputeERP_2.m
822 lines (703 loc) · 26.5 KB
/
Bike2_ComputeERP_2.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
clear all
close all
ccc
exp = 'Bike2';
subs = {'100' '101' '102' '104' '106' '108' '110'...
'114' '115' '116' '117' '118' '120' '121'...
'122' '126' '127' '129' '130' '131' '132' '133'...
'135' '136'}; %new sample
nsubs = length(subs);
conds = {'sask'; '110st'; '83ave'};
conds_lab = {'Sask Drive'; '110 Street'; '83 Avenue'};
nconds = length(conds);
Pathname = 'M:\Data\Bike_lanes\';
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
%%
for i_sub = 1:nsubs
for i_cond = 1:nconds
Filename = [subs{i_sub} '_' exp '_' conds{i_cond}];
EEG = pop_loadset('filename',[Filename '_Targets.set'],'filepath','M:\Data\Bike_lanes\segments_JK\');
% EEG = pop_loadset('filename',[Filename '_Targets.set'],'filepath','M:\Data\Bike_lanes\segments_JK_2\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
EEG = pop_loadset('filename',[Filename '_Standards.set'],'filepath','M:\Data\Bike_lanes\segments_JK');
% EEG = pop_loadset('filename',[Filename '_Standards.set'],'filepath','M:\Data\Bike_lanes\segments_JK_2');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
end
end
eeglab redraw
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%subject erps
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
erp_out = [];
for i_sub = 1:nsubs
fprintf(['Subject ' num2str(i_sub)])
for i_cond = 1:nconds
%average over trials (3rd dimension)
erp_out(:,1,:,i_cond,i_sub) = mean(ALLEEG(1+ 2*((i_sub-1)*nconds+(i_cond-1))).data,3)'; %Targets
erp_out(:,2,:,i_cond,i_sub) = mean(ALLEEG(2+ 2*((i_sub-1)*nconds+(i_cond-1))).data,3)'; %standards
end
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%grand average plots + difference waves
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
figure('Color',[1 1 1]);
for i_cond = 1:nconds
switch i_cond
case 1
colour = 'b';
case 2
colour = 'g';
case 3
colour = 'r';
% case 4
% colour = 'm';
end
subplot(2,nconds,i_cond);
boundedline(EEG.times,squeeze(mean(erp_out(:,1,electrode,i_cond,:),5)),squeeze(std(erp_out(:,1,electrode,i_cond,:),[],5))./sqrt(nsubs),colour,...
EEG.times,squeeze(mean(erp_out(:,2,electrode,i_cond,:),5)),squeeze(std(erp_out(:,2,electrode,i_cond,:),[],5))./sqrt(nsubs),'k');
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
if i_cond == 2
legend('Targets','Standards','Location','NorthEast','Autoupdate', 'off');
end
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title(conds{i_cond});
xlabel('Time (ms)');
ylabel('Voltage (uV)');
subplot(2,nconds,nconds+i_cond);
boundedline(EEG.times,squeeze(mean(erp_diff_out(:,electrode,i_cond,:),4)),squeeze(std(erp_diff_out(:,electrode,i_cond,:),[],4))./sqrt(nsubs),colour);
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
if i_cond == 2
legend('Targets-Standards','Location','NorthEast','Autoupdate', 'off');
end
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title(conds{i_cond});
xlabel('Time (ms)');
ylabel('Voltage (uV)');
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% difference waves on same axis
%
% MANUSCRIPT: DIFFERENCE-WAVES P3
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
figure
boundedline(EEG.times,squeeze(mean(erp_diff_out(:,electrode,1,:),4)),squeeze(std(erp_diff_out(:,electrode,1,:),[],4))./sqrt(nsubs),'b',...%erp_diff_out(:,electrode,1,:),[],4
EEG.times,squeeze(mean(erp_diff_out(:,electrode,2,:),4)),squeeze(std(erp_diff_out(:,electrode,2,:),[],4))./sqrt(nsubs),'g',...
EEG.times,squeeze(mean(erp_diff_out(:,electrode,3,:),4)),squeeze(std(erp_diff_out(:,electrode,3,:),[],4))./sqrt(nsubs),'r');
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Difference-Wave');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
L(1) = plot(nan, nan, 'b');
L(2) = plot(nan, nan, 'g');
L(3) = plot(nan, nan, 'r');
legend(L, {'Sask Drive', '110 Street', '83 Avenue'},'Location','northwest', 'Autoupdate', 'off')
% fill([300;300;450;450],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
fill([355;355;505;505],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
clear electrode;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% P3 DIFFERENCE WAVE STATS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TARGET VARIABLES FOR JASP
electrode = 15;
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
time_window = find(EEG.times>355,1)-1:find(EEG.times>505,1)-2;
P3_diffs = [squeeze(mean(erp_diff_out(time_window,electrode,1,:),1)),...
squeeze(mean(erp_diff_out(time_window,electrode,2,:),1)),...
squeeze(mean(erp_diff_out(time_window,electrode,3,:),1))];
writematrix(P3_diffs, 'Pz_P300_dif-wave.csv')
clear time_window;
%%
%t-test for dif waves
time_window = find(EEG.times>325,1)-1:find(EEG.times>450,1)-2;
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
%%%timepoints X events X electrodes X conditions X participants%%%%
% COMPARING DIFFERENCE WAVES for non-preferred conditions
%[h p ci stat] = ttest(squeeze(mean(erp_diff_out(time_window,electrode,1,:),1)),squeeze(mean(erp_diff_out(time_window,electrode,2,:),1)),.05,'both',1)
%non-parametric
%[p, h,stats] = ranksum(squeeze(mean(erp_diff_out(time_window,electrode,2,:),1)),squeeze(mean(erp_diff_out(time_window,electrode,1,:),1)),'alpha', 0.05, 'tail','both')
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TARGET ERP FIGURES + STATS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Targets on same axis
electrode = 13;
figure;
boundedline(EEG.times,squeeze(mean(erp_out(:,1,electrode,1,:),5)), squeeze(std(erp_out(:,1,electrode,1,:),[],5))./sqrt(nsubs),'b',...
EEG.times,squeeze(mean(erp_out(:,1,electrode,2,:),5)), squeeze(std(erp_out(:,1,electrode,2,:),[],5))./sqrt(nsubs),'g',...
EEG.times,squeeze(mean(erp_out(:,1,electrode,3,:),5)), squeeze(std(erp_out(:,1,electrode,3,:),[],5))./sqrt(nsubs),'r')
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Target Tones');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
L(1) = plot(nan, nan, 'b');
L(2) = plot(nan, nan, 'g');
L(3) = plot(nan, nan, 'r');
legend(L, {'Sask Drive', '110 Street', '83 Avenue'},'Location','northeast', 'Autoupdate', 'off')
% fill([125;125;200;200],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
% fill([200;200;300;300],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
fill([118;118;218;218],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
fill([218;218;318;318],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TARGET N1 ERP VARIABLES FOR JASP
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ttest for targets
electrode = 15; %adjust the electrode number accordingly btn Fz and Pz
time_window = find(EEG.times>118,1)-1:find(EEG.times>218,1)-2;
%[h p ci stat] = ttest(squeeze(mean(erp_out(time_window,1,electrode,1,:),1)),squeeze(mean(erp_out(time_window,1,electrode,3,:),1)),.05,'both',1)
% TARGET VARIABLES FOR JASP
N1_targ_sask = squeeze(mean(erp_out(time_window,1,electrode,1,:),1));
N1_targ_110 = squeeze(mean(erp_out(time_window,1,electrode,2,:),1));
N1_targ_83 = squeeze(mean(erp_out(time_window,1,electrode,3,:),1));
N1_targ_conds = [N1_targ_sask, N1_targ_110, N1_targ_83];
% writematrix(N1_targ_conds, 'Fz_N1_targets.csv')
writematrix(N1_targ_conds, 'Pz_N1_targets.csv')
clear time_window;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TARGET P2 ERP VARIABLES FOR JASP
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15; %adjust the electrode number accordingly btn Fz and Pz
time_window = find(EEG.times>218,1)-1:find(EEG.times>318,1)-2;
P2_targ_sask = squeeze(mean(erp_out(time_window,1,electrode,1,:),1));
P2_targ_110 = squeeze(mean(erp_out(time_window,1,electrode,2,:),1));
P2_targ_83 = squeeze(mean(erp_out(time_window,1,electrode,3,:),1));
P2_targ_conds = [P2_targ_sask, P2_targ_110, P2_targ_83];
% writematrix(P2_targ_conds,'Fz_P2_targets.csv')
writematrix(P2_targ_conds,'Pz_P2_targets.csv')
clear time_window;
%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% STANDARDS ERP FIGURES + STATS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Standards on same axis
electrode = 15;
figure;
boundedline(EEG.times,squeeze(mean(erp_out(:,2,electrode,1,:),5)), squeeze(std(erp_out(:,2,electrode,1,:),[],5))./sqrt(nsubs),'b',...
EEG.times,squeeze(mean(erp_out(:,2,electrode,2,:),5)), squeeze(std(erp_out(:,2,electrode,2,:),[],5))./sqrt(nsubs),'g', ...
EEG.times,squeeze(mean(erp_out(:,2,electrode,3,:),5)), squeeze(std(erp_out(:,2,electrode,3,:),[],5))./sqrt(nsubs),'r');
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Standard Tones');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
L(1) = plot(nan, nan, 'b');
L(2) = plot(nan, nan, 'g');
L(3) = plot(nan, nan, 'r');
legend(L, {'Sask Drive', '110 Street', '83 Avenue'},'Location','northeast', 'Autoupdate', 'off')
% fill([125;125;200;200],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
% fill([200;200;300;300],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
fill([118;118;218;218],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
fill([218;218;318;318],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% STANDARD N1 ERP VARIABLES FOR JASP
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
time_window = find(EEG.times>118,1)-1:find(EEG.times>218,1)-2;
N1_stan_sask = squeeze(mean(erp_out(time_window,2,electrode,1,:),1));
N1_stan_110 = squeeze(mean(erp_out(time_window,2,electrode,2,:),1));
N1_stan_83 = squeeze(mean(erp_out(time_window,2,electrode,3,:),1));
N1_stan_conds = [N1_stan_sask, N1_stan_110, N1_stan_83];
%writematrix(N1_stan_conds, 'Fz_N1_standards.csv')
writematrix(N1_stan_conds, 'Pz_N1_standards.csv')
clear time_window;
clear electrode;
%%
% time_window = find(EEG.times>225,1)-1:find(EEG.times>325,1)-2;
%[h p ci stat] = ttest(squeeze(mean(erp_out(time_window,2,electrode,3,:),1)),squeeze(mean(erp_out(time_window,2,electrode,1,:),1)),.05,'both',1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% STANDARD P2 ERP VARIABLES FOR JASP
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
time_window = find(EEG.times>218,1)-1:find(EEG.times>318,1)-2;
P2_stan_sask = squeeze(mean(erp_out(time_window,2,electrode,1,:),1));
P2_stan_110 = squeeze(mean(erp_out(time_window,2,electrode,2,:),1));
P2_stan_83 = squeeze(mean(erp_out(time_window,2,electrode,3,:),1));
P2_stan_conds = [P2_stan_sask, P2_stan_110, P2_stan_83];
% writematrix(P2_stan_conds, 'Fz_P2_standards.csv')
writematrix(P2_stan_conds, 'Pz_P2_standards.csv')
clear time_window;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% MANUSCRIPT TOPOGRAPHIES
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%difference topographies for P3 figure
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
time_window = find(EEG.times>355,1)-1:find(EEG.times>505,1)-2;
figure('Color',[1 1 1]);
for i_cond = 1:nconds
subplot(1,nconds,i_cond);
set(gca,'Color',[1 1 1]);
temp = mean(mean(erp_diff_out(time_window,:,i_cond,:),4),1);
temp(16:18) = NaN;
topoplot(temp,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title(conds_lab{i_cond});
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Voltage Difference (uV)');
end
%%
%Target & Standards topographies
time_window = find(EEG.times>218,1)-1:find(EEG.times>318,1)-2;
figure('Color',[1 1 1]);
subplot(1,3,1);
set(gca,'Color',[1 1 1]);
temp1 = mean(mean(erp_out(time_window,1,:,1,:),5),1);
temp1(16:18) = NaN;
topoplot(temp1,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('Sask Drive');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Targets');
subplot(1,3,2);
set(gca,'Color',[1 1 1]);
temp2 = mean(mean(erp_out(time_window,1,:,2,:),5),1);
temp2(16:18) = NaN;
topoplot(temp2,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('110 Street');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Targets');
subplot(1,3,3);
set(gca,'Color',[1 1 1]);
temp3 = mean(mean(erp_out(time_window,1,:,3,:),5),1);
temp3(16:18) = NaN;
topoplot(temp3,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('83 Avenue');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Targets');
%standards
figure('Color',[1 1 1]);
subplot(1,3,1);
set(gca,'Color',[1 1 1]);
temp4 = mean(mean(erp_out(time_window,2,:,1,:),5),1);
temp4(16:18) = NaN;
topoplot(temp4,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('Sask Drive');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Standards');
subplot(1,3,2);
set(gca,'Color',[1 1 1]);
temp5 = mean(mean(erp_out(time_window,2,:,2,:),5),1);
temp5(16:18) = NaN;
topoplot(temp5,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('110 Street');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Standards');
subplot(1,3,3);
set(gca,'Color',[1 1 1]);
temp6 = mean(mean(erp_out(time_window,2,:,3,:),5),1);
temp6(16:18) = NaN;
topoplot(temp6,'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced', 'whitebk','on','plotrad',.6,'maplimits',[-4 4])
title('83 Avenue');
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'Standards');
clear time_window
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%% TIME WINDOW + PEAK AVERAGES TO DETERMINE STATS WINDOW.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% P3 PEAK (DIFFERENCE-WAVES)
%trying out on difference
erp_diff_out = squeeze(erp_out(:,1,:,:,:)-erp_out(:,2,:,:,:));
electrode = 15;
figure;
boundedline(EEG.times,squeeze(mean(mean(erp_diff_out(:,electrode,:,:),4),3)), squeeze(std(0))./sqrt(nsubs),'m'),...
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Difference-Wave Grand ERPs');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
fill([355;355;505;505],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
clear electrode;
% MMN/N2b % NOT INCLUDING IN MANUSCRIPT UNLESS SIGNIFICANT
% electrode = 13;
% figure;
% boundedline(EEG.times,squeeze(mean(mean(erp_diff_out(:,electrode,:,:),4),3)), squeeze(std(0))./sqrt(nsubs),'m'),...
% set(gca,'Color',[1 1 1]);
% set(gca,'YDir','reverse');
% axis tight; ylim([-12 16]);
% line([-200 1000],[0 0],'color','k');
% line([0 0],[-2.5 8],'color','k');
% title('Difference-Wave Grand ERPs');
% xlabel('Time (ms)');
% ylabel('Voltage (uV)');
% clear electrode;
% N1 + P2 PEAK/TIME WINDOW - TARGETS
electrode = 13;
figure;
boundedline(EEG.times,squeeze(mean(mean(erp_out(:,1,electrode,:,:),4),5)), squeeze(std(0))./sqrt(nsubs),'m'),...
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Target Grand ERPs');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
fill([118;118;218;218],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
fill([218;218;318;318],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
clear electrode;
% N1 + P2 PEAK/TIME WINDOW - STANDARDS
electrode = 13;
figure;
boundedline(EEG.times,squeeze(mean(mean(erp_out(:,2,electrode,:,:),4),5)), squeeze(std(0))./sqrt(nsubs),'m'),...
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-8 12]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title('Standard Grand ERPs');
xlabel('Time (ms)');
ylabel('Voltage (uV)');
fill([118;118;218;218],[-8;12;12;-8],'w','FaceAlpha',0.1, 'EdgeAlpha', '1', 'Linestyle', ':');
fill([218;218;318;318],[-8;12;12;-8],'w','FaceAlpha',0.1,'EdgeAlpha', '1', 'Linestyle', ':');
clear electrode;
%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% BARGRAPHS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% N1 FZ standards and targets
%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 13;
time_window = find(EEG.times>118,1)-1:find(EEG.times>218,1)-2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%STANDARDS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,2,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,2,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,2,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,2,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,2,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,2,electrode,3,:),[],5))./sqrt(nsubs));
n1_mean_fz = [hmean; imean; lmean]';
n1_sd_fz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
figure;
subplot (2,4,1)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(n1_mean_fz,n1_sd_fz);
ylim([-6 0])
%ylabel('Standards Fz')
% xlabel('Condition')
title('Standards Fz')
legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% TARGET N1 TIME WINDOW FZ
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,1,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,1,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,1,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,1,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,1,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,1,electrode,3,:),[],5))./sqrt(nsubs));
tn1_mean_fz = [hmean; imean; lmean]';
tn1_sd_fz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,2)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(tn1_mean_fz,tn1_sd_fz);
ylim([-6 0])
%ylabel('Targets Fz')
% xlabel('Condition')
title('Targets Fz')
%legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz electrode time_window
%%%%%%%%%%%%%%%%%%%%%
%
%
% N1 PZ
%
%
%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
time_window = find(EEG.times>118,1)-1:find(EEG.times>218,1)-2;
%STANDARDS
hmean = mean(squeeze(mean(erp_out(time_window,2,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,2,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,2,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,2,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,2,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,2,electrode,3,:),[],5))./sqrt(nsubs));
n1_mean_pz = [hmean; imean; lmean]';
n1_sd_pz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,3)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(n1_mean_pz,n1_sd_pz);
ylim([-6 0])
%ylabel('Standards Pz')
% xlabel('Condition')
title('Standards Pz')
%legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz
%TARGET N1 TIME WINDOW FZ
%Targets
hmean = mean(squeeze(mean(erp_out(time_window,1,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,1,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,1,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,1,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,1,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,1,electrode,3,:),[],5))./sqrt(nsubs));
tn1_mean_pz = [hmean; imean; lmean]';
tn1_sd_pz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,4)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(tn1_mean_pz,tn1_sd_pz);
ylim([-6 0])
%ylabel('Targets Pz')
% xlabel('Condition')
title('Targets Pz')
%legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz electrode time_window
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% P2 FZ
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
time_window = find(EEG.times>218,1)-1:find(EEG.times>318,1)-2;
electrode = 13;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%STANDARDS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,2,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,2,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,2,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,2,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,2,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,2,electrode,3,:),[],5))./sqrt(nsubs));
P2_mean_fz = [hmean; imean; lmean]';
P2_sd_fz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,5)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(P2_mean_fz,P2_sd_fz);
ylim([-2 0])
%ylabel('Standards Pz')
% xlabel('Condition')
title('Standards Pz')
legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% TARGET
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,1,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,1,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,1,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,1,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,1,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,1,electrode,3,:),[],5))./sqrt(nsubs));
tp2_mean_fz = [hmean; imean; lmean]';
tp2_sd_fz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,6)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(tp2_mean_fz,tp2_sd_fz);
ylim([-5 0])
%ylabel('Targets Fz')
% xlabel('Condition')
title('Targets Fz')
%legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz electrode
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% P2 PZ
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 15;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%STANDARDS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,2,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,2,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,2,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,2,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,2,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,2,electrode,3,:),[],5))./sqrt(nsubs));
p2_mean_pz = [hmean; imean; lmean]';
p2_sd_pz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,7)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(p2_mean_pz,p2_sd_pz);
ylim([0 2])
%ylabel('Standards Pz')
% xlabel('Condition')
title('Standards Pz')
%legend(conds_plot)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% TARGET
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hmean = mean(squeeze(mean(erp_out(time_window,1,electrode,1,:),5)));
imean = mean(squeeze(mean(erp_out(time_window,1,electrode,2,:),5)));
lmean = mean(squeeze(mean(erp_out(time_window,1,electrode,3,:),5)));
hsd = mean(squeeze(std(erp_out(time_window,1,electrode,1,:),[],5))./sqrt(nsubs));
isd = mean (squeeze(std(erp_out(time_window,1,electrode,2,:),[],5))./sqrt(nsubs));
lsd = mean(squeeze(std(erp_out(time_window,1,electrode,3,:),[],5))./sqrt(nsubs));
tp2_mean_pz = [hmean; imean; lmean]';
tp2_sd_pz = [hsd; isd; lsd]';
conds_plot = {'Heavy'; 'Intermediate';'Low'};
subplot (2,4,8)
set(gcf,'color','w');
set(gcf, 'Position', [100, 500, 1000, 400])
barweb(tp2_mean_pz,tp2_sd_pz);
ylim([-1.4 .9])
%ylabel('Targets Pz')
% xlabel('Condition')
title('Targets Pz')
%legend(conds_plot)
clear hmean imean lmean hsd isd lsd n1_mean_fz n1_sd_fz electrode
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% EXPLORATORY ANALYSES
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%individual subs
for i_sub = 1:nsubs
figure
boundedline(EEG.times,squeeze(erp_out(:,1,electrode,:,i_sub)),squeeze(std(0))./sqrt(nsubs),'r',...
EEG.times,squeeze(erp_out(:,2,electrode,:,i_sub)),squeeze(std(0))./sqrt(nsubs),'k');
set(gca,'Color',[1 1 1]);
set(gca,'YDir','reverse');
axis tight; ylim([-25 25]);
line([-200 1000],[0 0],'color','k');
line([0 0],[-2.5 8],'color','k');
title(subs{i_sub});
xlabel('Time (ms)');
ylabel('Voltage (uV)');
end
%%
%%
% %SINGLE ERPS FOR INDIVIDUAL COPYING
%
% for i_cond = 1:nconds
% switch i_cond
% case 1
% colour = 'b';
% case 2
% colour = 'g';
% case 3
% colour = 'r';
% end
%
% figure;
% boundedline(EEG.times,squeeze(mean(erp_out(:,1,electrode,i_cond,:),5)),squeeze(std(erp_out(:,1,electrode,i_cond,:),[],5))./sqrt(nsubs),colour,...
% EEG.times,squeeze(mean(erp_out(:,2,electrode,i_cond,:),5)),squeeze(std(erp_out(:,2,electrode,i_cond,:),[],5))./sqrt(nsubs),'k');
% set(gca,'Color',[1 1 1]);
% set(gca,'YDir','reverse');
% if i_cond == 2 || 3
% legend('Targets','Standards','Location','NorthEast');
% elseif i_cond == 1
% legend('Targets','Standards','Location','NorthEast');
% end
% axis tight; ylim([-8 12]);
% line([-200 1000],[0 0],'color','k');
% line([0 0],[-2.5 8],'color','k');
% title(conds{i_cond});
% xlabel('Time (ms)');
% ylabel('Voltage (uV)');
% end
%%
%%
% for i_set = 1:48; trial_count(i_set) = ALLEEG(i_set).trials; end
% trial_count = reshape(trial_count,[2,3,8]);
% min(trial_count,[],3)
% mean(trial_count,3)
% max(trial_count,[],3)
%
% %mean and sd
% mean(mean(erp_diff_out(time_window,7,1:3,:),1),4)
% std(mean(erp_diff_out(time_window,7,1:3,:),1),[],4)
%
%
%
% ttest of each condition
% [h p ci stat] = ttest(squeeze(mean(erp_diff_out(time_window,7,1,:),1)),0,.05,'right',1)
% [h p ci stat] = ttest(squeeze(mean(erp_diff_out(time_window,7,2,:),1)),0,.05,'right',1)
% [h p ci stat] = ttest(squeeze(mean(erp_diff_out(time_window,7,3,:),1)),0,.05,'right',1)
% [h p ci stat] = ttest(squeeze(mean(erp_diff_out(time_window,7,4,:),1)),0,.05,'right',1)
%
%
%
% eeglab redraw