-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFPSA_FearGen.m
5675 lines (5231 loc) · 248 KB
/
FPSA_FearGen.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 [varargout]=FPSA_FearGen(varargin);
% [varargout]=FPSA_FearGen(varargin);
%
% Complete analysis and figure generation pipeline for the
% Fixation-Pattern Similarity Analysis (FPSA) manuscript. Initial versions can be
% found in Biorxiv at http://biorxiv.org/content/early/2017/04/15/125682
%
% Using this code, one can generate all results and figures presented in the manuscript.
%
% Requirements:
% ..* Matlab 2018, even though previous versions of Matlab should also work.
% ..* Relies on Fancycarp toolbox (1) for dealing with fixation data. All dependencies as
% well as raw data can be easily downloaded as a bundle from Open Science Framework
% following this link: https://osf.io/zud6h/
%
%
% Initial Setup:
% ..* First download the data from the project's OSF webpage.
% ..* After downloading the project folder from OSF, change below the PATH_PROJECT variable.
%
% Usage:
% VARARGIN sets an action related to an analysis, figure preparation or
% simple house keeping routines, such as data getters. For example,
% Some actions require input(s), these can be provided with 2nd, 3rd, and so
% forth VARARGINs. For example, 'get_fpsa_fair' action requires two
% additional input arguments i/ fixations and ii/ runs. FIXATIONS
% determines which fixations to use to compute a dissimilarity matrix and
% RUNS determine pre- or post-learning phases. By convention baseline phase
% is denoted with 2, whereas Generalization phase by 4.
%
% Examples:
% FPSA_FearGen('get_subjects') retuns the indices to participants, included
% in the analysis. These correspond to subXXX folder numbers.
% FPSA_FearGen('get_fixmat')
% Returns the fixation data (cached in the midlevel folder).
% FPSA_FearGen('get_trialcount',2)
% Returns number of trials per each subject and condition for baseline
% phase (2). Use 4 for test phase.
% FPSA_FearGen('fix_counts',fixmat) counts the fixation density on 4
% different ROIs used in the manuscript. Get FIXMAT with FPSA_FearGen('get_fixmat')
% FPSA_FearGen('get_fixmap',fixmat,{'subject' 12 'fix' 1}) returns FDMs using FIXMAT, for
% participant 12 and fixation index 1.
% FPSA_FearGen('get_fixmap',fixmat,{'subject' subjects 'fix' 1:100}) returns FDMs for
% SUBJECTS and fixations from 1 to 100 (well, basically all the
% fixations). Each FDM is a column vector.
% FPSA_FearGen('plot_ROIs') plots the ROIs.
% FPSA_FearGen('get_fpsa',1:100) would return the dissimilarity matrix
% computed with exploration patterns containing all the fixations
% (1:100). This is not a recommended method for computing dissimilarity
% matrices, rather use:
% FPSA_FearGen('get_fpsa_fair',{'fix',1:100},1:3) which would compute a fair
% dissimilarity matrix for each run separately. 3 runs in generalization
% are averaged later.
%
%
%
% Contact: sonat@uke.de; l.kampermann@uke.de
%% Set the default parameters
path_project = sprintf('%s%s',homedir,'/Documents/Experiments/project_FPSA_FearGen/');% location of the project folder (MUST END WITH A FILESEP);
condition_borders = {'' 1:8 '' 9:16}; % baseline and test condition labels.
block_extract = @(mat,y,x,z) mat((1:8)+(8*(y-1)),(1:8)+(8*(x-1)),z); % a little routing to extract blocks from RSA maps
tbootstrap = 1000; % number of bootstrap samples
method = 'correlation'; % methods for RSA computation
current_subject_pool = 0; % which subject pool to use (see get_subjects)
runs = 1:3; % which runs of the test phase to be used
criterion ='strain' ; % criterion for the MDS analysis.
force = 0; % force recaching of results.
kernel_fwhm = 37*0.8; % size of the smoothing window (.8 degrees by default);
random_noise = 1; % should fixation maps be slightly added with noise.
url = 'https://www.dropbox.com/s/0wix64zy2dlwh8g/project_FPSA_FearGen.tar.gz?dl=1';
%% overwrite default parameters with the input
invalid_varargin = logical(zeros(1,length(varargin)));
for nf = 1:length(varargin)
if strcmp(varargin{nf} , 'tbootstrap')
tbootstrap = varargin{nf+1};
elseif strcmp(varargin{nf} , 'method')
method = varargin{nf+1};
elseif strcmp(varargin{nf} , 'current_subject_pool')
current_subject_pool = varargin{nf+1};
elseif strcmp(varargin{nf} , 'runs')
runs = varargin{nf+1};
elseif strcmp(varargin{nf} , 'criterion')
criterion = varargin{nf+1};
elseif strcmp(varargin{nf} , 'force')
force = varargin{nf+1};
elseif strcmp(varargin{nf} , 'kernel_fwhm')
kernel_fwhm = varargin{nf+1};
else
invalid_varargin(nf) = true;%detect which varargins modify the default values and delete them
end
end
varargin([find(~invalid_varargin) find(~invalid_varargin)+1]) = [];%now we have clean varargin cellarray we can continue
%%
if strcmp(varargin{1},'get_subjects'); %% returns subject indices based on the CURRENT_SUBJECT_POOL variable.
%%
% For the paper we use current_pool = 0, which discards all subjects:
% who are not calibrated good enough
%
% Results are cached, use FORCE = 1 to recache. Set
% CURRENT_SUBJECT_POOL = 0 to not select participants.
filename = sprintf('%s/data/midlevel/subjectpool_%03d.mat',path_project,current_subject_pool);
if exist(filename) == 0 | force
if current_subject_pool == 0;
subjects = Project.subjects(Project.subjects_ET);
elseif current_subject_pool == 1%find tuned people;
fprintf('finding tuned subjects first...\n');
p=[];sub=[];pval=[];
for n = Project.subjects(Project.subjects_ET);
s = Subject(n);
s.fit_method = 8;%mobile vonMises function;
p = [p ; s.get_fit('rating',4).params];
pval = [pval ; s.get_fit('rating',4).pval];
sub = [sub ; n];
end
valid = (abs(p(:,3)) < 45) & pval > -log10(.05);%selection criteria
fprintf('Found %03d valid subjects...\n',sum(valid));
subjects = sub(valid);
save(filename,'subjects');
end
else
load(filename);
end
varargout{1} = subjects;
allsubs = Project.subjects(Project.subjects_ET);
varargout{2} = allsubs(~ismember(allsubs,subjects));
elseif strcmp(varargin{1},'get_trialcount') %% Sanity check for number of trials per subject.
%%
% goes through subjects and counts the number of trials in a PHASE. The
% output is [subjects conditions].
% VARARGIN{2}.
%
% Example: FPSA_FearGen('get_trialcount',4) for phase 4 (test phase).
% Example: FPSA_FearGen('get_trialcount',2) for phase 4 (test phase).
phase = varargin{2};
fixmat = FPSA_FearGen('get_fixmat');
s = 0;
for ns = unique(fixmat.subject)
s = s+1;
c = 0;
for nc = unique(fixmat.deltacsp)
c = c+1;
C(s,c) = (length(unique(fixmat.trialid(fixmat.subject == ns & fixmat.deltacsp == nc & fixmat.phase == phase))));
end
end
varargout{1} = C;
imagesc(C(:,1:8));
ylabel('participants')
xlabel('conditions')
title(sprintf('Number of trials for phase %d',phase));
colorbar;
elseif strcmp(varargin{1},'get_fixmat'); %% load the fixation data in the form of a Fixmat.
%%
% For more information on Fixmat structure refer to (1), where this
% data is also published.
% Will return fixmat for the baseline and test phases. Generalization
% phase has 3 runs, by default all are returned. Use
% fixmat = FPSA_FearGen('get_fixmat','runs',run);
% to return the required run. For example FPSA_Fair uses this method
% to compute a separate FPSA on separate runs.
%
%
% Use force = 1 to recache (defined at the top).
%
% Example: fixmat = FPSA_FearGen('get_fixmat')
filename = sprintf('%s/data/midlevel/fixmat_subjectpool_%03d_runs_%03d_%03d.mat',path_project,current_subject_pool,runs(1),runs(end));
fix = [];
if exist(filename) == 0 | force
subjects = FPSA_FearGen('current_subject_pool',current_subject_pool,'get_subjects');
fix = Fixmat(subjects,[2 4]);%all SUBJECTS, PHASES and RUNS
%further split according to runs if wanted.
valid = zeros(1,length(fix.x));
runs
for run = runs(:)'
valid = valid + ismember(fix.trialid , (1:120)+120*(run-1))&ismember(fix.phase,4);%run selection opeates only for phase 4
end
%we dont want to discard phase02 fixations
valid = valid + ismember(fix.phase,2);
fix.replaceselection(valid);
fix.ApplySelection;
save(filename,'fix');
else
load(filename)
end
fix.kernel_fwhm = kernel_fwhm;
varargout{1} = fix;
elseif strcmp(varargin{1},'fix_counts') %% Sanity check: counts fixations in 5 different ROI
%%
%during baseline and generalization, returns [subjects, roi, phase].
fixmat = varargin{2};
fixmat.unitize = 0;
subjects = unique(fixmat.subject);
c = 0;
for ns = subjects(:)'
fprintf('Counting fixations in subject: %03d.\n',ns)
c = c+1;
p = 0;
for phase = [2 4]
p = p +1;
fixmat.getmaps({'phase' phase 'subject' ns});
dummy = fixmat.maps;
count(c,:,p) = fixmat.EyeNoseMouth(dummy,0);
end
end
varargout{1} = count;
elseif strcmp(varargin{1},'get_fixmap') %% General routine to compute a FDMs i.e. probability of fixation as a function of space.
%%
% Always returns 16 maps, 8 per baseline and generalization phases.
% By default uses all the fixations available in the FIXMAT provided
% in the first VARARGIN. The second VARARGIN is a selector cell array
% as it is understood by the fixmat object.
%
% FDMs for a SUBJECT, recorded at both phases for fixations FIX (vector) based on a FIXMAT.
% maps are mean corrected for each phase separately.
fixmat = varargin{2};
selector= varargin{3};
%create the query cell to talk to Fixmat object
maps = [];
for phase = [2 4];
v = [];
c = 0;
for cond = -135:45:180
c = c+1;
v{c} = {'phase', phase, 'deltacsp' cond selector{:}};
end
fixmat.getmaps(v{:});%real work done by the fixmat object.
maps = cat(2,maps,demean(fixmat.vectorize_maps')');%within phase mean subtraction
end
varargout{1} = maps;
elseif strcmp(varargin{1},'plot_fdm'); %% plot routine for FDMs used in the paper in a similar way to Figure 3A.
%%
% Use the second VARARGIN to plot ROIs on top.
% VARARGIN{1} contains fixation maps in the form of [x,y,condition].
% The output of FPSA_FearGen('get_fixmap',...) has to be accordingly
% reshaped. size(VARARGIN{1},3) must be a multiple of 8.
maps = varargin{2};
tsubject = size(maps,3)/8;
contour_lines = 1;%FACIAL ROIs Plot or not.
fs = 18;%fontsize;
if nargin == 3
contour_lines = varargin{3};
end
% grids = [linspace(prctile(fixmat.maps(:),0),prctile(fixmat.maps(:),10),10) linspace(prctile(fixmat.maps(:),90),prctile(fixmat.maps(:),100),10)];
% [d u] = GetColorMapLimits(maps(:),2.5);
% grids = [linspace(d,u,5)];
t = repmat(circshift({'CS+' '+45' '+90' '+135' ['CS' char(8211)] '-135' '-90' '-45'},[1 3]),1,tsubject);
colors = GetFearGenColors;
colors = repmat(circshift(colors(1:8,:),0),tsubject,1);
colormap jet;
%%
for n = 1:size(maps,3)
if mod(n-1,8)+1 == 1;
figure;set(gcf,'position',[1952 361 1743 714]);
end
hhhh(n)=subplot(1,8,mod(n-1,8)+1);
imagesc(Fixmat([],[]).stimulus);
hold on
grids = linspace(min(Vectorize(maps(:))),max(Vectorize(maps(:))),21);
[a,h2] = contourf(maps(:,:,n),grids,'color','none');
caxis([grids(2) grids(end)]);
%if n == 8
%h4 = colorbar;
%set(h4,'box','off','ticklength',0,'ticks',[[grids(4) grids(end-4)]],'fontsize',fs);
%end
hold off
axis image;
axis off;
if strcmp(t{mod(n-1,8)+1}(1),'+') | strcmp(t{mod(n-1,8)+1}(1),'-')
h= title(sprintf('%s%c',t{mod(n-1,8)+1},char(176)),'fontsize',fs,'fontweight','normal');
else
h= title(sprintf('%s',t{mod(n-1,8)+1}),'fontsize',fs,'fontweight','normal');
end
try
h.Position = h.Position + [0 -50 0];
end
%
drawnow;
pause(.5);
%
try
%%
% I = find(ismember(a(1,:),h2.LevelList));
% [~,i] = max(a(2,I));
% alphas = [repmat(.5,1,length(I))];
% alphas(i) = 0;
contourf_transparency(h2,.75);
end
%%
rectangle('position',[0 0 diff(xlim) diff(ylim)],'edgecolor',colors(mod(n-1,8)+1,:),'linewidth',7);
end
pause(1);
for n = 1:size(maps,3);
subplotChangeSize(hhhh(n),.01,.01);
end
if contour_lines
hold on;
rois = Fixmat([],[]).GetFaceROIs;
for n = 1:4
contour(rois(:,:,n),'k--','linewidth',1);
end
end
elseif strcmp(varargin{1},'plot_ROIs'); %simple routine to plot ROIs on a face
%%
fix = Fixmat([],[]);
rois = fix.GetFaceROIs;
rois(:,:,1) = sum(rois(:,:,1:2),3);
rois(:,:,2:3) = rois(:,:,3:4);
rois(:,:,end) = [];
for n = 1:3
figure(n);
imagesc(fix.stimulus);
axis image;
axis off;
hold on;
% h = imagesc(ones(size(fix.stimulus,1),size(fix.stimulus,1)),[0 1]);
% h.AlphaData =rois(:,:,n)./2;
contour(rois(:,:,n),'k-','linewidth',4);
hold off;
% SaveFigure(sprintf(%s/data/midlevel/figures/ROIs.png',path_project));
end
elseif strcmp(varargin{1},'get_fpsa_timewindowed') %% Computes FPSA matrices for different time-windows
%%
%Time windows are computed based on WINDOW_SIZE and WINDOW_OVERLAP.
%WINDOWN_OVERLAP must be equal to WINDOW_SIZE to conduct the analysis
%on non-overlapping segments.
%
%Example usage:
%[sim,model] = FPSA_FearGen('get_fpsa_timewindowed',500,500);
%
%model.w contains weights for the linear model as
%[subjects,phase,model,param,time]
%
%Note:
% I hacked this routine to compute FPSA fixation by fixation.
% use it like:
% [sim,model] = FPSA_FearGen('get_fpsa_timewindowed',1,1);
% or [sim,model] = FPSA_FearGen('get_fpsa_timewindowed',0,1);
%
window_size = varargin{2};
window_overlap = varargin{3};%this is actually not an overlap, but distance between start points
hash = DataHash(varargin);
if window_size > 10
t = 0:1:(window_size-1);%running window
start_times = 1:window_overlap:1500-window_size+1;%in milliseconds
time = repmat(start_times',1,length(t)) + repmat(t,length(start_times),1)
else
t = 0:1:(window_size);%running window
if window_size == 0
start_times = 1:window_overlap:5;%in fixation indices
else
start_times = 1:window_overlap:4;%in fixation indices
end
time = repmat(start_times',1,length(t)) + repmat(t,length(start_times),1);
end
filename = sprintf('%s/data/midlevel/fpsa_timewindowed_subjectpool_%03d_kernel_fwhm_%03d_runs_%s_input_%s.mat',path_project,current_subject_pool,kernel_fwhm,mat2str(runs),hash);
if exist(filename) == 0 | force
fprintf('Has %d time windows in total...\n',size(time,1));
%
fixmat = FPSA_FearGen('current_subject_pool',current_subject_pool,'force',force,'kernel_fwhm',kernel_fwhm,'get_fixmat');
sim.correlation = nan(length(unique(fixmat.subject)),120,size(time,1));
%
tc = 0;
for t = 1:size(time,1)
fprintf('Processing window %d of %d time windows...\n',t,size(time,1));
tc = tc+1;
if window_size > 10
dummy = FPSA_FearGen('current_subject_pool',current_subject_pool,'force',force,'kernel_fwhm',kernel_fwhm,'get_fpsa_fair',{'start' time(t,:)},1:3);
else
dummy = FPSA_FearGen('current_subject_pool',current_subject_pool,'force',force,'kernel_fwhm',kernel_fwhm,'get_fpsa_fair',{'fix' time(t,:)},1:3);
end
sim.(method)(:,:,tc) = dummy.correlation;
T = FPSA_FearGen('FPSA_sim2table',dummy);
[~, C.w(:,:,:,:,tc)] = FPSA_FearGen('FPSA_model_singlesubject',T.t);
end
save(filename,'C','sim')
else
load(filename);
end
C.t = time;
varargout{1} = sim;
varargout{2} = C;
%%
figure;
model = C;
h(1)=subplot(2,2,1);
hold off;%plot(model.t,squeeze(nanmean(model.w(:,1,1,1,:))),'b',model.t,squeeze(nanmean(model.w(:,2,1,1,:))),'r');
H2= shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,1,1,1,:)))',squeeze(nanSEM(model.w(:,1,1,1,:)))','lineprops','b');hold on;
H1=shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,2,1,1,:))),squeeze(nanSEM(model.w(:,2,1,1,:))),'lineprops','r');box off;axis tight;ylim([-.05 0.2]);xlim([min(C.t(:,1)) max(C.t(:,1))]);
xtick={};for ntik = 1:size(model.t,1);xtick = [xtick sprintf('%d-%d',min(model.t(ntik,:)),max(model.t(ntik,:)))];end
set(gca,'xtick',model.t(:,1),'xticklabel',{''},'XTickLabelRotation',45,'fontsize',12,'xgrid','on','ygrid','on')
title('circular W model 1');
%
h(2)=subplot(2,2,2);hold off;
H2= shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,2,2,1,:)-model.w(:,1,2,1,:))),squeeze(nanSEM(model.w(:,2,2,1,:)-model.w(:,1,2,1,:))),'lineprops','r');hold on;
H1= shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,2,2,2,:)-model.w(:,1,2,2,:))),squeeze(nanSEM(model.w(:,2,2,2,:)-model.w(:,1,2,2,:))),'lineprops','b');box off;axis tight;ylim([-.05 0.2]);xlim([min(C.t(:,1)) max(C.t(:,1))]);
title('Generalization - Baseline');
set(gca,'xtick',model.t(:,1),'xticklabel',{''},'XTickLabelRotation',45,'fontsize',12,'xgrid','on','ygrid','on')
H2.mainLine.LineWidth = 1.5;H2.mainLine.LineWidth = 1.5;H2.mainLine.Color = [1 0 0 .5];H1.mainLine.LineWidth = 1.5;H1.mainLine.Color = [0 0 1 .5];
%
h(3)=subplot(2,2,3);hold off;%plot(model.t,squeeze(nanmean(model.w(:,2,2,1,:))),'b',model.t,squeeze(nanmean(model.w(:,2,2,2,:))),'r',model.t,squeeze(nanmean(model.w(:,1,2,1,:))),'b--',model.t,squeeze(nanmean(model.w(:,1,2,2,:))),'r--');
H2=shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,1,2,1,:)))',squeeze(nanSEM(model.w(:,1,2,1,:)))','lineprops','r-');hold on;
H1=shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,1,2,2,:))),squeeze(nanSEM(model.w(:,1,2,2,:))),'lineprops','b-');box off;axis tight;ylim([-0.02 0.2]);xlim([min(C.t(:,1)) max(C.t(:,1))]);
if size(model.t(:,1),1) < 10
set(gca,'xtick',model.t(:,1),'xticklabel',xtick,'XTickLabelRotation',0,'fontsize',12,'xgrid','on','ygrid','on','ytick',[0 .1 .2],'fontsize',12,'fontweight','normal');
else
xtick = {(model.t(1:5:end,end)+model.t(1:5:end,1)-1)/2};
set(gca,'xtick',model.t(1:5:end,1),'xticklabel',xtick(1:5:end),'XTickLabelRotation',0,'xgrid','on','ygrid','on','ytick',[0 .1 .2],'fontsize',12,'fontweight','normal');
end
H2.mainLine.LineWidth = 2;H2.mainLine.Color = [1 0 0 .5];H1.mainLine.LineWidth = 2;H1.mainLine.Color = [0 0 1 .5];
title('Baseline','fontsize',18);
hl = legend([H2.mainLine H1.mainLine],{'w_{specific}' 'w_{unspecific}'})
hl.FontSize = 12;
legend boxoff
if size(model.t(:,1),1) < 10
xlabel('fixations','fontweight','bold','fontsize',16);
else
xlabel('time window (ms)','fontweight','bold','fontsize',16);
end
ylabel('weight','fontweight','bold','fontsize',16)
grid on
%
h(4)=subplot(2,2,4);hold off;%plot(model.t,squeeze(nanmean(model.w(:,2,2,1,:))),'b',model.t,squeeze(nanmean(model.w(:,2,2,2,:))),'r',model.t,squeeze(nanmean(model.w(:,1,2,1,:))),'b--',model.t,squeeze(nanmean(model.w(:,1,2,2,:))),'r--');
H2=shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,2,2,1,:)))',squeeze(nanSEM(model.w(:,2,2,1,:)))','lineprops','r');hold on;
H1=shadedErrorBar(model.t(:,1),squeeze(nanmean(model.w(:,2,2,2,:))) ,squeeze(nanSEM(model.w(:,2,2,2,:))) ,'lineprops','b');box off;axis tight;ylim([-0.02 0.2]);xlim([min(C.t(:,1)) max(C.t(:,1))]);
H2.mainLine.LineWidth = 2;H2.mainLine.Color = [1 0 0 .5];H1.mainLine.LineWidth = 2;H1.mainLine.Color = [0 0 1 .5];
set(gca,'yticklabels',[]);
if size(model.t(:,1),1) < 10
set(gca,'xtick',model.t(:,1),'xticklabel',xtick,'XTickLabelRotation',0,'fontsize',12,'xgrid','on','ygrid','on','ytick',[0 .1 .2],'fontsize',12,'fontweight','normal');
else
set(gca,'xtick',model.t(1:5:end,1),'xticklabel',xtick(1:5:end),'XTickLabelRotation',0,'xgrid','on','ygrid','on','ytick',[0 .1 .2],'fontsize',12,'fontweight','normal');
end
if size(model.t(:,1),1) < 10
xlabel('fixations','fontweight','bold','fontsize',16);
else
ggg=xlabel('time window (ms)','fontweight','bold','fontsize',16);
end
subplotChangeSize(h,.02,.02);
title('Generalization','fontsize',18);
set(gcf,'position',[2034 402 900 900]);
%% find significant time points
whichtest = 'ttest';
alpha = 0.05;
%[subjects,phase,model,param,time]
X = squeeze( (model.w(:,2,2,1,:)-model.w(:,2,2,2,:)) - (model.w(:,1,2,1,:)-model.w(:,1,2,2,:)) ) %difference between curves
% X = squeeze( (model.w(:,2,2,1,:)-model.w(:,2,2,2,:)) )
if strcmp(whichtest,'signrank')
for i = 1:size(X,2)
[PP(i) HH(i)] = signrank(X(:,i));
end
elseif strcmp(whichtest,'ttest')
size(X)
[HH PP] = ttest(X,[]); %tests difference spec > unspec
PP
end
hold on
for n = 1:size(X,2)
if PP(n) <= .05
n
text(model.t(n,1),max(ylim)-.01,'*','HorizontalAlignment','center','fontsize',20);
end
end
sort(model.t(find(PP < alpha))-window_size)
%%
% SaveFigure('~/Dropbox/feargen_lea/manuscript/figures/figure_04.png','-transparent','-r300');
elseif strcmp(varargin{1},'get_fpsa_fair') %% Computes FPSA separately for each run and single subjects
%%
% FPSA for the 3 test-phase runs are individually computed and averaged.
% Doing it the other way (i.e. average FDMs from the 3 phases and compute
% FPSA as in get_fpsa) would have led to comparably less noisy FDMs for the test
% phase and thus differences btw B and T simply because the number of
% trials are different. See (4) for more information on how noise
% affects similarity values.
%
% Example usage:
% sim = FPSA_FearGen('get_fpsa_fair',{'fix',1:100},1:3);
selector = varargin{2};%which fixations
runs = varargin{3};%whichs runs would you like to have
hash = DataHash(selector);
fprintf('===================\n')
selector
hash
fprintf('===================\n')
%
filename = sprintf('%s/data/midlevel/fpsa_fair_kernel_fwhm_%03d_subjectpool_%03d_runs_%s_selector_%s.mat',path_project,kernel_fwhm,current_subject_pool,mat2str(runs),hash);
if exist(filename) ==0 | force;
runc = 0;
for run = runs %these are parts of phase 4 runs (1-2-3), not phases per se
runc = runc+1;
fixmat = FPSA_FearGen('current_subject_pool',current_subject_pool,'kernel_fwhm',kernel_fwhm,'runs',run,'get_fixmat');
subc = 0;
for subject = unique(fixmat.subject);
subc = subc + 1;
maps = FPSA_FearGen('get_fixmap',fixmat,{'subject' subject,selector{:}}); %this gives 16 fixmaps, [8condsBaseline 8condsTestphase]
fprintf('Subject: %03d, Run: %03d, Method: %s\n',subject,run,method);
sim.(method)(subc,:,runc)= pdist(maps',method);% %length 120, triangular form of 16*16 matrix
end
end
%average across runs
sim.(method) = mean(sim.(method),3);
save(filename,'sim');
else
load(filename);
end
varargout{1} = sim;
elseif strcmp(varargin{1},'plot_fpsa');%% A routine to plot similarity matrices
%%
figure;
sim = varargin{2};
cormatz = squareform(nanmean(sim.correlation));
cormatz = CancelDiagonals(cormatz,NaN);
[d u] = GetColorMapLimits(cormatz,2.5);
imagesc(cormatz,[d u]);
axis square;colorbar
set(gca,'fontsize',15);
axis off;
elseif strcmp(varargin{1},'get_block') %% will get the Yth, Xth block from similarity matrix SIM.
%%
% SQFM is the square_form of SIM.
%
% Example: fpsa = FPSA_FearGen('get_block',FPSA_FearGen('get_fpsa',1:100),2,2)
sim = varargin{2};
y = varargin{3};
x = varargin{4};
r = [];
sqfm = [];
for ns = 1:size(sim.correlation,1)
dummy = squareform(sim.correlation(ns,:));
B = block_extract(dummy,y,x,1);%funhandle defined at the top.
r = cat(3,r,B);
sqfm = [sqfm;squareform(B)];
end
varargout{1} = r;
varargout{2} = sqfm;
elseif strcmp(varargin{1},'get_mdscale') %% Routine to make MDS analysis using a SIMilarity matrix with NDIMENsions.
%%
%
% Example: FPSA_FearGen('get_mdscale',mean(sim.correlation),2);
sim = varargin{2};%sim is a valid similarity matrix;
ndimen = varargin{3};
viz = 1;
[dummy stress disparities] = mdscale(sim,ndimen,'Criterion',criterion,'start','cmdscale','options',statset('display','final','tolfun',10^-12,'tolx',10^-12));
dummy = dummy';
Y = dummy(:);
varargout{1} = Y;
if viz
FPSA_FearGen('plot_mdscale',Y);
end
elseif strcmp(varargin{1},'plot_mdscale') %% Routine to plot the results of the get_mdscale
%%
Y = varargin{2};
ndimen = length(Y)./16;
y = reshape(Y,length(Y)/16,16)';%to make it easy plotting put coordinates to different columns;
colors = GetFearGenColors;
colors = [colors(1:8,:);colors(1:8,:)];
if ndimen == 2
plot(y([1:8 1],1),y([1:8 1],2),'.-.','linewidth',3,'color',[.6 .6 .6]);
hold on;
plot(y([1:8 1]+8,1),y([1:8 1]+8,2),'k.-.','linewidth',3);
for nface = 1:16
plot(y(nface,1),y(nface,2),'.','color',colors(nface,:),'markersize',120,'markerface',colors(nface,:));
end
hold off;
%
for n = 1:16;text(y(n,1),y(n,2),mat2str(mod(n-1,8)+1),'fontsize',25);end
elseif ndimen == 3
plot3(y([1:8 1],1),y([1:8 1],2),y([1:8 1],3),'o-','linewidth',3);
hold on;
plot3(y([1:8 1]+8,1),y([1:8 1]+8,2),y([1:8 1]+8,3),'ro-','linewidth',3);
hold off;
for n = 1:16;text(y(n,1),y(n,2),y(n,3),mat2str(mod(n-1,8)+1),'fontsize',25);end
end
elseif strcmp(varargin{1},'FPSA_get_table') %% returns a table object ready for FPSA modelling with fitlm, fitglm, etc.
%%
%
% This action returns all dependent and independent variables
% necessary for the modelling in a neat table format.
%
% the table object contains the following variable names:
% FPSA_B : similarity matrices from baseline.
% FPSA_G : similarity matrices from test.
% circle : circular predictor consisting of a sum of specific and
% unspecific components.
% specific : specific component based on quadrature decomposition
% (the cosine factor).
% unspecific : unspecific component based on quadrature decomposition
% (the sine factor).
% Gaussian : generalization of the univariate Gaussian component to
% the similarity space.
% subject : indicator variable for subjects
% phase : indicator variable for baseline and generalizaation
% phases.
%
% Example: FPSA_FearGen('FPSA_get_table',{'fix' 1:100})
selector = varargin{2};
hash = DataHash(selector);
filename = sprintf('%s/data/midlevel/fpsa_modelling_table_subjectpool_%03d_runs_%02d_%02d_selector_%s.mat',path_project,current_subject_pool,runs(1),runs(end),hash);
if ~exist(filename) | force
%the full B and T similarity matrix which are jointly computed;
sim = FPSA_FearGen('get_fpsa_fair',selector,runs);%returns FPSA per subject
%%we only want the B and T parts
B = FPSA_FearGen('get_block',sim,1,1); %8x8x74
T = FPSA_FearGen('get_block',sim,2,2);
%once we have these, we go back to the compact form and concat the
%stuff, now each column is a non-redundant FPSA per subject
for n = 1:size(sim.correlation,1)
BB(n,:) = squareform(B(:,:,n));
TT(n,:) = squareform(T(:,:,n));
end
BB = BB';
TT = TT';
% gives us column vectors with dissimilarities of each subject for
% B and for T , size 120
% some indicator variables for phase, subject identities.
phase = repmat([repmat(1,size(BB,1)/2,1); repmat(2,size(BB,1)/2,1)],1,size(BB,2));
subject = repmat(1:size(sim.correlation,1),size(BB,1),1);
S = subject(:);
P = phase(:);
%% our models:
%MODEL1: perfectly circular similarity model;
%MODEL2: flexible circular similarity model;
%MODEL3: Model2 + a Gaussian.
% a circular FPSA matrix for B and T replicated by the number of subjects
x = [pi/4:pi/4:2*pi];
w = [cos(x);sin(x)];
model1 = repmat(repmat(squareform_force(w'*w),1,1),1,size(subject,2));%we use squareform_force as the w'*w is not perfectly positive definite matrix due to rounding errors.
%
model2_c = repmat(repmat(squareform_force(cos(x)'*cos(x)),1,1),1,size(subject,2));%
model2_s = repmat(repmat(squareform_force(sin(x)'*sin(x)),1,1),1,size(subject,2));%
%
%getcorrmat(amp_circ, amp_gau, amp_const, amp_diag, varargin)
[cmat] = getcorrmat(0,3,1,1);%see model_rsa_testgaussian_optimizer
model3_g = repmat(repmat(squareform_force(cmat),1,1),1,size(subject,2));%
%% add all this to a TABLE object.
t = table(1-BB(:),1-TT(:),model1(:),model2_c(:),model2_s(:),model3_g(:),categorical(subject(:)),categorical(phase(:)),'variablenames',{'FPSA_B' 'FPSA_G' 'circle' 'specific' 'unspecific' 'Gaussian' 'subject' 'phase'}); %this phase category is corrupt.
save(filename,'t');
else
load(filename);
end
varargout{1} = t;
elseif strcmp(varargin{1},'FPSA_sim2table'); %% subroutine to transform a FPSA matrix to a table for modelling
%%
tsubject = size(varargin{2}.correlation,1);
predictor_table = repmat(FPSA_FearGen('FPSA_predictortable'),tsubject,1);
for n_level = 1:size(varargin{2}.correlation,3)
sim.correlation = varargin{2}.correlation(:,:,n_level);
B = FPSA_FearGen('get_block',sim,1,1);
T = FPSA_FearGen('get_block',sim,2,2);
%once we have these, we go back to the compact form and concat the
%stuff, now each column is a non-redundant FPSA per subject
BB=[];TT=[];
for n = 1:size(sim.correlation,1)
BB(n,:) = squareform(B(:,:,n));
TT(n,:) = squareform(T(:,:,n));
end
BB = BB';
TT = TT';
% some indicator variables for phase, subject identities.
phase = repmat([repmat(1,size(BB,1)/2,1); repmat(2,size(BB,1)/2,1)],1,size(BB,2));
subject = repmat(1:size(sim.correlation,1),size(BB,1),1);
dummy(n_level).t = [predictor_table table(1-BB(:),1-TT(:),categorical(subject(:)),categorical(phase(:)),'variablenames',{'FPSA_B' 'FPSA_G' 'subject' 'phase'})];
end
%% will now add the predictors to the table
varargout{1} = dummy;
elseif strcmp(varargin{1},'FPSA_predictortable');
%% returns the basic predictors as a table
x = [pi/4:pi/4:2*pi];
w = [cos(x);sin(x)];
model1 = squareform_force(w'*w);%we use squareform_force as the w'*w is not perfectly positive definite matrix due to rounding errors.
%
model2_c = squareform_force(cos(x)'*cos(x));%
model2_s = squareform_force(sin(x)'*sin(x));%
%
%getcorrmat(amp_circ, amp_gau, amp_const, amp_diag, varargin)
[cmat] = getcorrmat(0,3,1,1);%see model_rsa_testgaussian_optimizer
model3_g = squareform_force(cmat);%
% add all this to a TABLE object.
varargout{1} = table(model1(:),model2_c(:),model2_s(:),model3_g(:),'variablenames',{'circle' 'specific' 'unspecific' 'Gaussian' });
elseif strcmp(varargin{1},'FPSA_model'); %% models FPSA matrices with mixed and fixed models.
%%
selector = varargin{2};
t = FPSA_FearGen('runs',runs,'FPSA_get_table',selector);
% MIXED EFFECT MODEL
% null model
out.baseline.model_00_mixed = fitlme(t,'FPSA_B ~ 1 + (1|subject)');
out.generalization.model_00_mixed = fitlme(t,'FPSA_G ~ 1 + (1|subject)');
% FPSA_model_bottom-up model
out.baseline.model_01_mixed = fitlme(t,'FPSA_B ~ 1 + circle + (1 + circle|subject)');
out.generalization.model_01_mixed = fitlme(t,'FPSA_G ~ 1 + circle + (1 + circle|subject)');
% FPSA_model_adversitycateg
out.baseline.model_02_mixed = fitlme(t,'FPSA_B ~ 1 + specific + unspecific + (1 + specific + unspecific|subject)');
out.generalization.model_02_mixed = fitlme(t,'FPSA_G ~ 1 + specific + unspecific + (1 + specific + unspecific|subject)');
% FPSA_model_adversitytuning
out.baseline.model_03_mixed = fitlme(t,'FPSA_B ~ 1 + specific + unspecific + Gaussian + (1 + specific + unspecific + Gaussian|subject)');
out.generalization.model_03_mixed = fitlme(t,'FPSA_G ~ 1 + specific + unspecific + Gaussian + (1 + specific + unspecific + Gaussian|subject)');
%% FIXED EFFECT MODEL
% FPSA null model
out.baseline.model_00_fixed = fitlm(t,'FPSA_B ~ 1');
out.generalization.model_00_fixed = fitlm(t,'FPSA_G ~ 1');
% FPSA_model_bottom-up model
out.baseline.model_01_fixed = fitlm(t,'FPSA_B ~ 1 + circle');
out.generalization.model_01_fixed = fitlm(t,'FPSA_G ~ 1 + circle');
% FPSA_model_adversitycateg
out.baseline.model_02_fixed = fitlm(t,'FPSA_B ~ 1 + specific + unspecific');
out.generalization.model_02_fixed = fitlm(t,'FPSA_G ~ 1 + specific + unspecific');
% FPSA_model_adversitytuning
out.baseline.model_03_fixed = fitlm(t,'FPSA_B ~ 1 + specific + unspecific + Gaussian');
out.generalization.model_03_fixed = fitlm(t,'FPSA_G ~ 1 + specific + unspecific + Gaussian');
varargout{1} = out;
elseif strcmp(varargin{1},'FPSA_model_singlesubject');%% Models single-subject FPSA matrices.
%% same as FPSA_model, but on gathers a model parameter for single subjects.
% Input a table if you like to model a custom FPSA matrix.
if ~istable(varargin{2})
fprintf('VARARGIN interpreted as SELECTOR cell.\n')
selector = varargin{2};
t = FPSA_FearGen('runs',runs,'FPSA_get_table',selector);
else fprintf('VARARGIN interpreted as a TABLE.\n')
t = varargin{2};
end
%% test the model for B, T
Model.model_01.w1 = nan(length(unique(t.subject)'),2);
Model.model_02.w1 = nan(length(unique(t.subject)'),2);
Model.model_02.w2 = nan(length(unique(t.subject)'),2);
Model.model_03.w1 = nan(length(unique(t.subject)'),2);
Model.model_03.w2 = nan(length(unique(t.subject)'),2);
Model.model_03.w3 = nan(length(unique(t.subject)'),2);
M = nan(length(unique(t.subject)'),2,3,3);%[subjects,phase,model,param]
for ns = unique(t.subject)'
t2 = t(ismember(t.subject,categorical(ns)),:);
if ~isnan(sum([t2.FPSA_B;t2.FPSA_G]))% valid or not: Criteria for validity: Both the B and G FPSA matrices must not contain any NaNs.
cprintf([0 1 0],'Fitting an circular and flexibile LM to subject %03d...\n',double(ns));
B = fitlm(t2,'FPSA_B ~ 1 + circle');
T = fitlm(t2,'FPSA_G ~ 1 + circle');
Model.model_01.w1(ns,:) = [B.Coefficients.Estimate(2) T.Coefficients.Estimate(2)];
M(ns,1,1,1) = B.Coefficients.Estimate(2);
M(ns,2,1,1) = T.Coefficients.Estimate(2);
MC(ns,1,1) = B.ModelCriterion;
MC(ns,2,1) = T.ModelCriterion;
LL(ns,1,1) = B.LogLikelihood;
LL(ns,2,1) = T.LogLikelihood;
%
B = fitlm(t2,'FPSA_B ~ 1 + specific + unspecific');
T = fitlm(t2,'FPSA_G ~ 1 + specific + unspecific');
Model.model_02.w1(ns,:) = [B.Coefficients.Estimate(2) T.Coefficients.Estimate(2)];
Model.model_02.w2(ns,:) = [B.Coefficients.Estimate(3) T.Coefficients.Estimate(3)];
M(ns,1,2,1) = B.Coefficients.Estimate(2);
M(ns,2,2,1) = T.Coefficients.Estimate(2);
M(ns,1,2,2) = B.Coefficients.Estimate(3);
M(ns,2,2,2) = T.Coefficients.Estimate(3);
MC(ns,1,2) = B.ModelCriterion;
MC(ns,2,2) = T.ModelCriterion;
LL(ns,1,2) = B.LogLikelihood;
LL(ns,2,2) = T.LogLikelihood;
%
B = fitlm(t2,'FPSA_B ~ 1 + specific + unspecific + Gaussian');
T = fitlm(t2,'FPSA_G ~ 1 + specific + unspecific + Gaussian');
Model.model_03.w1(ns,:) = [B.Coefficients.Estimate(2) T.Coefficients.Estimate(2)];
Model.model_03.w2(ns,:) = [B.Coefficients.Estimate(3) T.Coefficients.Estimate(3)];
Model.model_03.w3(ns,:) = [B.Coefficients.Estimate(4) T.Coefficients.Estimate(4)];
M(ns,1,3,1) = B.Coefficients.Estimate(2);
M(ns,2,3,1) = T.Coefficients.Estimate(2);
M(ns,1,3,2) = B.Coefficients.Estimate(3);
M(ns,2,3,2) = T.Coefficients.Estimate(3);
M(ns,1,3,3) = B.Coefficients.Estimate(4);
M(ns,2,3,3) = T.Coefficients.Estimate(4);
MC(ns,1,3) = B.ModelCriterion;
MC(ns,2,3) = T.ModelCriterion;
LL(ns,1,3) = B.LogLikelihood;
LL(ns,2,3) = T.LogLikelihood;
else
cprintf([1 0 0],'FPSA matrix contains NaN, will not be modelled...\n');
end
end
varargout{1} = Model;
varargout{2} = M;
varargout{3} = MC;
varargout{4} = LL;
elseif strcmp(varargin{1},'model2text'); %% spits text from a model object
%% handy function to dump model output to a text file that let you easily
%paste it to the manuscript ;-\
model = varargin{2};
a = evalc('disp(model)');
fid = fopen(sprintf('%s/data/midlevel/%s.txt',path_project,model.Formula),'w');
fwrite(fid,a);
fclose(fid);
elseif strcmp(varargin{1},'prevalence')
%% prevalence
C = FPSA_FearGen('FPSA_model_singlesubject',{'fix',1:100});
beta1_base = C.model_02.w1(:,1);
beta2_base = C.model_02.w2(:,1);
beta1_test = C.model_02.w1(:,2);
beta2_test = C.model_02.w2(:,2);
beta1_diff = C.model_02.w1(:,2)-C.model_02.w1(:,1);
beta2_diff = C.model_02.w2(:,2)-C.model_02.w2(:,1);
beta_diff_test = beta1_test - beta2_test;
beta_diffdiff = (beta1_test - beta2_test) - (beta1_base - beta2_base);%how much does w1 increase more than w2 does? (Interaction)
subs1 = FPSA_FearGen('current_subject_pool',1,'get_subjects');
subs0 = FPSA_FearGen('current_subject_pool',0,'get_subjects');
% all subs
sum(beta_diffdiff>0)
sum(beta_diffdiff>0)./length(subs0)
binopdf(sum(beta_diffdiff>0),length(subs0),.5) %.5 for chance level.
% learners only
ind = ismember(subs0,subs1);
sum(beta_diffdiff(ind)>0)
sum(beta_diffdiff(ind)>0)./length(subs1)
binopdf(sum(beta_diffdiff(ind)>0),length(subs1),.5) %.5 for chance level.
%
w_spec_test = beta1_test;
w_unspec_test = beta2_test;
w_spec_baseline = beta1_base;
w_unspec_baseline = beta2_base;
anis_TvB = (w_spec_test-w_unspec_test) - (w_spec_baseline-w_unspec_baseline);
sum(anis_TvB>0)
fprintf('N = %d subjects out of %d show bigger aniso in Test than in Baseline.\n',sum(anis_TvB>0),length(subs0))
elseif strcmp(varargin{1},'figure_03C');
%% plots the main model comparison figure;
selector = varargin{2};
C = FPSA_FearGen('FPSA_model_singlesubject',selector);
%%
% circular model
M = mean(C.model_01.w1);
SEM = std(C.model_01.w1)./sqrt(length(C.model_01.w1));
%flexible model
Mc = mean(C.model_02.w1);
SEMc = std(C.model_02.w1)./sqrt(length(C.model_01.w1));
Ms = mean(C.model_02.w2);
SEMs = std(C.model_02.w2)./sqrt(length(C.model_01.w1));
%gaussian model
Mcg = mean(C.model_03.w1);
SEMcg = std(C.model_03.w1)./sqrt(length(C.model_01.w1));
Msg = mean(C.model_03.w2);
SEMsg = std(C.model_03.w2)./sqrt(length(C.model_01.w1));
Mg = mean(C.model_03.w3);
SEMg = std(C.model_03.w3)./sqrt(length(C.model_01.w1));
%% get the p-values
[H P] = ttest(C.model_01.w1(:,1)-C.model_01.w1(:,2));%compares baseline vs test the circular model parameters
[Hc Pc] = ttest(C.model_02.w1(:,1)-C.model_02.w1(:,2));%compares spec before to after
[Hs Ps] = ttest(C.model_02.w2(:,1)-C.model_02.w2(:,2));%compares unspec before to after
[Hcs Pcs] = ttest(C.model_02.w1(:,2)-C.model_02.w2(:,2));%compares spec > unspec after
% same as before
[Hgc Pgc] = ttest(C.model_03.w1(:,1)-C.model_03.w1(:,2));%compares cosine before to after
[Hgcs Pgcs] = ttest(C.model_03.w1(:,2)-C.model_03.w2(:,2));%compares cosine after to sine after
[Hgg Pgg] = ttest(C.model_03.w3(:,1)-C.model_03.w3(:,2));%compares sine before to after
% %%anova on interaction of Time x Parameter
% y = [C.model_02.w1;C.model_02.w2];
% reps = length(C.model_02.w1);
% p = anova2(y,reps);
% %matlab can't deal with the repeated measures ANOVA, using Jasp instead
spec = C.model_02.w1(:,2)-C.model_02.w1(:,1);
unspec = C.model_02.w2(:,2)-C.model_02.w2(:,1);
[hIA,pIA,ciIA,statsIA] = ttest(spec,unspec);
%%
%%
figure;
if ispc
set(gcf,'position',[-200+500 1200 898 604]);
else
set(gcf,'position',[2150 335 898 604]);
end
%
X = [1 2 4 5 6 7 9 10 11 12 13 14]/1.5;
Y = [M Mc Ms Mcg Msg Mg];
Y2 = [SEM SEMc SEMs SEMcg SEMsg SEMg];
ylims = [floor(min(Y-Y2)*100)./100 ceil(max(Y+Y2)*100)./100+.07];
bw = .5;
hold off;
for n = 1:size(Y,2)
h = bar(X(n),Y(n));
legh(n) = h;
hold on
try %capsize is 2016b compatible.
errorbar(X(n),Y(n),Y2(n),'k.','marker','none','linewidth',1.5,'capsize',10);
catch
errorbar(X(n),Y(n),Y2(n),'k.','marker','none','linewidth',1.5);
end
if ismember(n,[1 3 5 7 9 11])
try %2016b compatibility.
set(h,'FaceAlpha',.1,'FaceColor','w','EdgeAlpha',1,'EdgeColor',[0 0 0],'LineWidth',1.5,'BarWidth',bw,'LineStyle','-');
catch
set(h,'FaceColor','w','EdgeColor',[0 0 0],'LineWidth',1.5,'BarWidth',bw,'LineStyle','-');
end
else
try
set(h,'FaceAlpha',.5,'FaceColor',[0 0 0],'EdgeAlpha',0,'EdgeColor',[.4 .4 .4],'LineWidth',1,'BarWidth',bw,'LineStyle','-');
catch
set(h,'FaceColor',[0 0 0],'EdgeColor',[.4 .4 .4],'LineWidth',1,'BarWidth',bw,'LineStyle','-');
end
end
end
%
box off;
L = legend(legh(1:2),{'Baseline' 'Generaliz.'},'box','off');
try
L.Position = L.Position + [0.1/2 0 0 0];
L.FontSize = 12;
end
set(gca,'linewidth',1.8);
% xticks
xtick = [mean(X(1:2)) mean(X(3:4)) mean(X(5:6)) mean(X(7:8)) mean(X(9:10)) mean(X(11:12)+.1) ];
label = {'\itw_{\rmcircle}' '\itw_{\rmspec.}' '\itw_{\rmunspec.}' '\itw_{\rmspec.}' '\itw_{\rmunspec.}' '\itw_{\rmGaus.}' };
for nt = 1:length(xtick)
h = text(xtick(nt),-.02,label{nt},'horizontalalignment','center','fontsize',20,'rotation',45,'fontangle','italic','fontname','times new roman');
end
try
set(gca,'xtick',[3 8]./1.5,'xcolor','none','color','none','XGrid','on','fontsize',16);
catch
set(gca,'xtick',[3 8]./1.5,'color','none','XGrid','on','fontsize',16);
end
%
text(-.5,ylims(2),'\beta','fontsize',28,'fontweight','bold');
ylim(ylims);
set(gca,'ytick', 0:.05:.2,'yticklabels', {'0' '.05' '.1' '.15' '.2'})
axis normal
% asteriks
ast_line = repmat(max(Y+Y2)+.002,1,2);
hold on
ylim(ylims);
h= line([X(1)-bw/2 X(2)+bw/2],ast_line);set(h,'color','k','linewidth',1); %B vs T model 01
h= line([X(3)-bw/2 X(4)+bw/2],ast_line);set(h,'color','k','linewidth',1); % B vs T, spec comp model 02
h= line([mean(X(3:4)) mean(X(5:6))],ast_line+.015);set(h,'color','k','linewidth',1); %delta spec vs delta unspec model_2 testphase
h= line(repmat(mean(X(3:4)),1,2),ast_line + [.01 .015]);set(h,'color','k','linewidth',1); %vertical miniline to show delta
h = line(repmat(mean(X(5:6)),1,2),ast_line + [.00 .015]);set(h,'color','k','linewidth',1); %vertical miniline to show delta
h= line([X(5)-bw/2 X(6)+bw/2],ast_line);set(h,'color','k','linewidth',1); % B vs T, unspec comp model 02 (serves the delta spec vs delta unspec thing)
h= line([X(7)-bw/2 X(8)+bw/2],ast_line);set(h,'color','k','linewidth',1); %B vs T spec model_03
% h= line([X(8)-bw/2 X(10)+bw/2],repmat(max(ylim),1,2)-.0025);set(h,'color','k','linewidth',1);
% h= line([X(11)-bw/2 X(12)+bw/2],repmat(max(ylim),1,2)-.1);set(h,'color','k','linewidth',1);
%
text(mean(X(1:2)) ,ast_line(1)+.0025, pval2asterix(P),'HorizontalAlignment','center','fontsize',16);
text(mean(X(3:4)) ,ast_line(1)+.0025, pval2asterix(Pc),'HorizontalAlignment','center','fontsize',16);
text(mean(X(4:5)) ,ast_line(1)+.015+.0025, pval2asterix(pIA),'HorizontalAlignment','center','fontsize',16); %diff B vs T spec vs unspec model_02
% text(mean(X([4 6])),ast_line(1)+.0055, pval2asterix(Pcs),'HorizontalAlignment','center','fontsize',16);
% text(mean(X([4 6])),ast_line(1)+.015 , sprintf('p = %05.3f',Pcs),'HorizontalAlignment','center','fontsize',13);
text(mean(X([7 8])),ast_line(1)+.0025, pval2asterix(Pgc),'HorizontalAlignment','center','fontsize',16);
% text(mean(X([8 10])),max(ylim) , pval2asterix(Pgcs),'HorizontalAlignment','center','fontsize',16);
% text(mean(X([11 12])),max(ylim)-.09 , pval2asterix(Pgg),'HorizontalAlignment','center','fontsize',12);
% model names
ylim(ylims)
% h = line([X(1)-bw/2 X(2)+bw/2],[-.022 -.022],'linestyle','--');
% set(h(1),'color','k','linewidth',1,'clipping','off');
text(mean(X(1:2)),ast_line(1)+.03,sprintf('Bottom-up\nSaliency\nmodel'),'Rotation',0,'HorizontalAlignment','center','FontWeight','normal','fontname','Helvetica','fontsize',14,'verticalalignment','bottom');
% h = line([X(3)-bw/2 X(6)+bw/2],[-.022 -.022],'linestyle','--');
% set(h(1),'color','k','linewidth',1,'clipping','off');
text(mean(X(3:6)),ast_line(1)+.03,sprintf('Adversity\nCategorization\nmodel'),'Rotation',0,'HorizontalAlignment','center','FontWeight','normal','fontname','Helvetica','fontsize',14,'verticalalignment','bottom');
% h = line([X(7)-bw/2 X(end)+bw/2],[-.022 -.022],'linestyle','--');
% set(h(1),'color','k','linewidth',1,'clipping','off');
text(mean(X(7:end)),ast_line(1)+.03,sprintf('Adversity\nTuning\nmodel'),'Rotation',0,'HorizontalAlignment','center','FontWeight','normal','fontname','Helvetica','fontsize',14,'verticalalignment','bottom');
%%
set(gcf,'Color',[1 1 1]);