-
Notifications
You must be signed in to change notification settings - Fork 0
/
getpRFTSeries.m
1563 lines (1118 loc) · 65.7 KB
/
getpRFTSeries.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
%% getpRFTSeries.m %%
%
% By: Josh Wilson
% Created: March 2022
%
% Takes a scan and analysis in mrTools, grabs info (time series, parameters, etc) from voxels, and graphs some stuff.
% cleanRois is a data frame that indexes into different rois. You define what rois you want and the order in the script. Defaults to v1,v2,v3.
%
% Part 1: Saves voxel data in structures 'rois' (all voxels) and 'cleanRois' (filtered version of 'rois' that meets
% certain cutoffs you can define like r2, RF width, etc). Need to do unless you have structures saved already.
%
% Part 2: Takes the cleanROIs data and graphs things like RF overlap, distance, noise correlations between voxels. If you
% don't want to do this (ex. you just want to save the data), you can set "doAnalyses = 0". But might as well graph if extracting for first time.
%
% Arguments you probably want to pass in:
%
% *loadData*: pass in 1 if you to load a saved structure, else 0 to extract new from mrTools analysis.
%
% If 1, also pass in:
% *data*: name of file with rois + cleanRois (ex. 's0401pRF.mat'). Need to have rois + cleanRois saved in that file.
%
% If 0, also pass in:
% *scanNum*: Scan number. Defaults to the concat group. I always concat everything (even single scans) to filter them.
% *analysis*: Name of the anaylsis you want (ex: 'pRFDoG', 'pRF').
% You should also save the 'rois' and 'cleanRois' structures in a .mat file for easier loading/analysis later.
%
%
% Example usage:
% Pre-extracted data: getpRFTSeries('loadData=1','data=s0401pRF.mat')
% Unextracted (mrTools open): [rois cleanRois] = getpRFTSeries('scanNum=2','analysis=pRFDoG'
%
%
%function [rois cleanRois] = getpRFtSeries(varargin)
function [v1Exponent, v1ExponentConfInt, ...
v2Exponent, v2ExponentConfInt,...
v3Exponent, v3ExponentConfInt, ...
v1v2Exponent, v1v2ExponentConfInt, ...
v1v3Exponent, v1v3ExponentConfInt] = getpRFTSeries(varargin)
%%%%%%%%%%%%%%%%%%%
%% Get Arguments %%
%%%%%%%%%%%%%%%%%%%
loadData = 1; % default to extracting data from mrTools.
getArgs(varargin); doAnalyses = 1;
if ~exist('graphStuff');graphStuff=0;end
if ~loadData % this is part 1 described above where you extract voxel data from mrTools if you don't have it saved already.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Load scan info and set some parameters %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
v = newView
v = viewSet(v,'curGroup','Concatenation'); %I only run this on concats. This pre-filters them.
nScans = viewGet(v,'nScans');
v = viewSet(v,'curScan',scanNum); %remember to set the scan number and analysis you want. I will automate this later
v = loadAnalysis(v,strcat('pRFAnal/',analysis));
tSeries = loadTSeries(v);
% manually define the ROIS you want to look at %
v1 = loadROITSeries(v,'v1')
v2 = loadROITSeries(v,'v2')
v3 = loadROITSeries(v,'v3')
rois = [v1 v2 v3]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Get the pRF-predicted time series of all voxels in the ROI %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for roi = 1:length(rois)
for voxel = 1:rois(roi).n
% grab computed analyses %
x = rois(roi).scanCoords(1,voxel); y = rois(roi).scanCoords(2,voxel); z = rois(roi).scanCoords(3,voxel);
a = viewGet(v,'Analysis');
d = viewGet(v,'d',scanNum);
r2 = viewGet(v,'overlayData',scanNum,viewGet(v,'overlayNum','r2'));
thisR2 = r2(x,y,z);
polarAngle = viewGet(v,'overlayData',scanNum,viewGet(v,'overlayNum','polarAngle'));
thisPolarAngle = polarAngle(x,y,z);
eccentricity = viewGet(v,'overlayData',scanNum,viewGet(v,'overlayNum','eccentricity'));
thisEccentricity = eccentricity(x,y,z);
rfHalfWidth = viewGet(v,'overlayData',scanNum,viewGet(v,'overlayNum','rfHalfWidth'));
thisRfHalfWidth = rfHalfWidth(x,y,z);
% get params %
scanDims = viewGet(v,'scanDims',scanNum);
whichVoxel = find(d.linearCoords == sub2ind(scanDims,x,y,z));
r = d.r(whichVoxel,:);
params = d.params(:,whichVoxel);
if isfield(d,'paramsInfo')
paramsInfo = d.paramsInfo;
else
paramsInfo = [];
end
% get the model time series for the voxel and parameters %
m = pRFFit(v,scanNum,x,y,z,'stim',d.stim,'getModelResponse=1','params',params,'concatInfo',d.concatInfo,'fitTypeParams',a.params.pRFFit,'paramsInfo',paramsInfo);
rois(roi).vox.linearCoords(voxel) = whichVoxel;
rois(roi).vox.params(:,voxel) = params;
rois(roi).vox.r2(voxel) = thisR2;
rois(roi).vox.polarAngle(voxel) = thisPolarAngle;
rois(roi).vox.eccentricity(voxel) = thisEccentricity;
rois(roi).vox.rfHalfWidth(voxel) = thisRfHalfWidth;
rois(roi).vox.tSeries(:,voxel) = m.tSeries;
rois(roi).vox.pRFtSeries(:,voxel) = m.modelResponse;
rois(roi).vox.baselineNoise = rois(roi).vox.tSeries-rois(roi).vox.pRFtSeries;
rois(roi).vox.measurementVar(voxel) = var(m.tSeries-m.modelResponse);
%rois(roi).vox.rfStimOverlapTSeries(:,voxel) = m.rfStimCor(:);
if mod(voxel,100) == 0
disp(sprintf('(getpRFTSeries) Roi %i of %i; Voxel %i of %i',roi,length(rois),voxel,rois(roi).n));
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%
%% Select Good Voxels %%
%%%%%%%%%%%%%%%%%%%%%%%%
% set the cutoffs for voxels you want to look at %
r2min = .6
eccMin = 0; eccMax = 25;
rfWmin = 1; rfWmax = 20;
cleanRois = rois
% filter for voxels that meet cutoffs %
for roi = 1:length(rois)
cleanRois(roi).vox.linearCoords = rois(roi).vox.linearCoords((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.rfHalfWidth = rois(roi).vox.rfHalfWidth((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.r2 = rois(roi).vox.r2((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.polarAngle = rois(roi).vox.polarAngle((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.eccentricity = rois(roi).vox.eccentricity((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.tSeries = rois(roi).vox.tSeries(:,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.measurementVar = rois(roi).vox.measurementVar((eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.baselineNoise = rois(roi).vox.baselineNoise(:,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.x = rois(roi).vox.params(1,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth));
cleanRois(roi).vox.y = rois(roi).vox.params(2,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth));
cleanRois(roi).vox.rfstd = rois(roi).vox.params(3,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth));
%cleanRois(roi).vox.rfStimOverlapTSeries = rois(roi).vox.rfStimOverlapTSeries(:,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.pRFtSeries = rois(roi).vox.pRFtSeries(:,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
cleanRois(roi).vox.scanCoords = rois(roi).scanCoords(:,(eccMax>rois(roi).vox.eccentricity>eccMin)&(rois(roi).vox.r2>r2min)&(rois(roi).vox.rfHalfWidth>rfWmin)&(rfWmax>rois(roi).vox.rfHalfWidth))
end
end %done extracting data
%%%%%%%%%%%%%%%
%% Load data %%
%%%%%%%%%%%%%%%
% if you already have roi + CleanRoi data, load it here.
if loadData
load(data,'rois','cleanRois');
end
% Start of part 2 (calculating correlations, distances, then graphing).
%%%%%%%%%%%%%%%%
%% RF Overlap %%
%%%%%%%%%%%%%%%%s
% receptive field overlaps %
sprintf('Correlating RFs and calculating distances (takes about a minute)...')
%v1
roi = 1; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
mu1 = 0; s1 = cleanRois(roi).vox.rfstd(column); s2 = cleanRois(roi).vox.rfstd(row);
mu2 = sqrt((cleanRois(roi).vox.x(column)-cleanRois(roi).vox.x(row))^2 + (cleanRois(roi).vox.y(column)-cleanRois(roi).vox.y(row))^2);
if mu1 == mu2 & s1 == s2; v1rfOverlap(row,column) = 1;else;
c = (mu2*(s1^2) - s2*(mu1*s2 + s1 * sqrt((mu1 - mu2)^2 + 2*(s1^2 - s2^2)*log(s1/s2))))/(s1^2-s2^2);
v1rfOverlap(row,column) = 1 - normcdf(c,mu1,s1) + normcdf(c,mu2,s2); end;
end
end
v1rfOverlap = v1rfOverlap.*100;
% v2 %
roi = 2; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
mu1 = 0; s1 = cleanRois(roi).vox.rfstd(column); s2 = cleanRois(roi).vox.rfstd(row);
mu2 = sqrt((cleanRois(roi).vox.x(column)-cleanRois(roi).vox.x(row))^2 + (cleanRois(roi).vox.y(column)-cleanRois(roi).vox.y(row))^2);
if mu1 == mu2 & s1 == s2; v2rfOverlap(row,column) = 1;else;
c = (mu2*(s1^2) - s2*(mu1*s2 + s1 * sqrt((mu1 - mu2)^2 + 2*(s1^2 - s2^2)*log(s1/s2))))/(s1^2-s2^2);
v2rfOverlap(row,column) = 1 - normcdf(c,mu1,s1) + normcdf(c,mu2,s2); end;
end
end
v2rfOverlap = v2rfOverlap.*100;
%v3
roi = 3; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
mu1 = 0; s1 = cleanRois(roi).vox.rfstd(column); s2 = cleanRois(roi).vox.rfstd(row);
mu2 = sqrt((cleanRois(roi).vox.x(column)-cleanRois(roi).vox.x(row))^2 + (cleanRois(roi).vox.y(column)-cleanRois(roi).vox.y(row))^2);
if mu1 == mu2 & s1 == s2; v3rfOverlap(row,column) = 1;else;
c = (mu2*(s1^2) - s2*(mu1*s2 + s1 * sqrt((mu1 - mu2)^2 + 2*(s1^2 - s2^2)*log(s1/s2))))/(s1^2-s2^2);
v3rfOverlap(row,column) = 1 - normcdf(c,mu1,s1) + normcdf(c,mu2,s2); end;
end
end
v3rfOverlap = v3rfOverlap.*100;
% v1/v2
for roi1vox = 1:length(cleanRois(1).vox.linearCoords)
for roi2vox = 1:length(cleanRois(2).vox.linearCoords)
mu1 = 0; s1 = cleanRois(1).vox.rfstd(roi1vox); s2 = cleanRois(2).vox.rfstd(roi2vox);
mu2 = sqrt((cleanRois(1).vox.x(roi1vox)-cleanRois(2).vox.x(roi2vox))^2 + (cleanRois(1).vox.y(roi1vox)-cleanRois(2).vox.y(roi2vox))^2);
if mu1 == mu2 & s1 == s2; v1v2rfOverlap(roi1vox,roi2vox) = 1;else;
c = (mu2*(s1^2) - s2*(mu1*s2 + s1 * sqrt((mu1 - mu2)^2 + 2*(s1^2 - s2^2)*log(s1/s2))))/(s1^2-s2^2);
v1v2rfOverlap(roi1vox,roi2vox) = 1 - normcdf(c,mu1,s1) + normcdf(c,mu2,s2); end;
end
end
v1v2rfOverlap = transpose(v1v2rfOverlap).*100;
% v1/v3
for roi1vox = 1:length(cleanRois(1).vox.linearCoords)
for roi2vox = 1:length(cleanRois(3).vox.linearCoords)
mu1 = 0; s1 = cleanRois(1).vox.rfstd(roi1vox); s2 = cleanRois(3).vox.rfstd(roi2vox);
mu2 = sqrt((cleanRois(1).vox.x(roi1vox)-cleanRois(3).vox.x(roi2vox))^2 + (cleanRois(1).vox.y(roi1vox)-cleanRois(3).vox.y(roi2vox))^2);
if mu1 == mu2 & s1 == s2; v1v3rfOverlap(roi1vox,roi2vox) = 1;else;
c = (mu2*(s1^2) - s2*(mu1*s2 + s1 * sqrt((mu1 - mu2)^2 + 2*(s1^2 - s2^2)*log(s1/s2))))/(s1^2-s2^2);
v1v3rfOverlap(roi1vox,roi2vox) = 1 - normcdf(c,mu1,s1) + normcdf(c,mu2,s2); end;
end
end
v1v3rfOverlap = transpose(v1v3rfOverlap).*100;
%%%%%%%%%%%%%%%%%%%%%%
%% voxel distances %%
%%%%%%%%%%%%%%%%%%%%%
% v1 %
roi = 1; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
dist = sqrt((cleanRois(roi).vox.scanCoords(1,column)-cleanRois(roi).vox.scanCoords(1,row))^2 + (cleanRois(roi).vox.scanCoords(2,column)-cleanRois(roi).vox.scanCoords(2,row))^2 + (cleanRois(roi).vox.scanCoords(3,column)-cleanRois(roi).vox.scanCoords(3,row))^2);
v1dist(row,column) = dist;
end
end
% v2 %
roi = 2; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
dist = sqrt((cleanRois(roi).vox.scanCoords(1,column)-cleanRois(roi).vox.scanCoords(1,row))^2 + (cleanRois(roi).vox.scanCoords(2,column)-cleanRois(roi).vox.scanCoords(2,row))^2 + (cleanRois(roi).vox.scanCoords(3,column)-cleanRois(roi).vox.scanCoords(3,row))^2);
v2dist(row,column) = dist;
end
end
% v3 %
roi = 3; for row = 1:length(cleanRois(roi).vox.linearCoords)
for column = 1:length(cleanRois(roi).vox.linearCoords)
dist = sqrt((cleanRois(roi).vox.scanCoords(1,column)-cleanRois(roi).vox.scanCoords(1,row))^2 + (cleanRois(roi).vox.scanCoords(2,column)-cleanRois(roi).vox.scanCoords(2,row))^2 + (cleanRois(roi).vox.scanCoords(3,column)-cleanRois(roi).vox.scanCoords(3,row))^2);
v3dist(row,column) = dist;
end
end
% v1/v2
for roi1vox = 1:length(cleanRois(1).vox.linearCoords)
for roi2vox = 1:length(cleanRois(2).vox.linearCoords)
dist = sqrt((cleanRois(1).vox.scanCoords(1,roi1vox)-cleanRois(2).vox.scanCoords(1,roi2vox))^2 + (cleanRois(1).vox.scanCoords(2,roi1vox)-cleanRois(2).vox.scanCoords(2,roi2vox))^2 + (cleanRois(1).vox.scanCoords(3,roi1vox)-cleanRois(2).vox.scanCoords(3,roi2vox))^2);
v1v2dist(roi2vox,roi1vox) = dist;
end
end
% v1/v3
for roi1vox = 1:length(cleanRois(1).vox.linearCoords)
for roi2vox = 1:length(cleanRois(3).vox.linearCoords)
dist = sqrt((cleanRois(1).vox.scanCoords(1,roi1vox)-cleanRois(3).vox.scanCoords(1,roi2vox))^2 + (cleanRois(1).vox.scanCoords(2,roi1vox)-cleanRois(3).vox.scanCoords(2,roi2vox))^2 + (cleanRois(1).vox.scanCoords(3,roi1vox)-cleanRois(3).vox.scanCoords(3,roi2vox))^2);
v1v3dist(roi2vox,roi1vox) = dist;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% get noise correlations %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
v1NoiseCor = corrcoef(cleanRois(1).vox.baselineNoise);
v2NoiseCor = corrcoef(cleanRois(2).vox.baselineNoise);
v3NoiseCor = corrcoef(cleanRois(3).vox.baselineNoise);
v1v2NoiseCor = transpose(corr(cleanRois(1).vox.baselineNoise,cleanRois(2).vox.baselineNoise));
v1v3NoiseCor = transpose(corr(cleanRois(1).vox.baselineNoise,cleanRois(3).vox.baselineNoise));
v1tSeriesCor = corrcoef(cleanRois(1).vox.pRFtSeries);
v2tSeriesCor = corrcoef(cleanRois(2).vox.pRFtSeries);
v3tSeriesCor = corrcoef(cleanRois(3).vox.pRFtSeries);
v1v3tSeriesCor = transpose(corr(cleanRois(1).vox.pRFtSeries,cleanRois(3).vox.pRFtSeries));
%%%%%%%%%%%%%%%%%%%%%%%%%%% graph %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if doAnalyses
sprintf('Graphing things (also takes about a minute)...')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% noise and receptive field correlation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% first, do v1 %
v1rfOverlapArr = reshape(v1rfOverlap,[1 length(v1rfOverlap)^2]); v1NoiseCorArr = reshape(v1NoiseCor,[1 length(v1NoiseCor)^2]);
[v1rfOverlapArr,sortOrder] = sort(v1rfOverlapArr); v1NoiseCorArr = v1NoiseCorArr(sortOrder);
v1NoiseCorArr(v1rfOverlapArr==100) = []; v1rfOverlapArr(v1rfOverlapArr==100) = [];
v1rfOverlapArr = log10(v1rfOverlapArr + 1);
figure(11); hold on; scatter(v1rfOverlapArr,v1NoiseCorArr,1,'filled','k');
%bootstrap
[meanExponent stdExponent] = getFitConfidenceInterval(v1NoiseCorArr',v1rfOverlapArr',graphStuff);
% plot the fit
expFit = fit(v1rfOverlapArr',v1NoiseCorArr','a + b*exp(x)');
legendColor = plot(expFit); legendColor.Color = [.3, .5, .3]; legendColor.LineWidth = 2;
v1expFit = plot(expFit); v1expFit.Color = [0, 0.4470, 0.7410]; v1expFit.LineWidth = 2;
%confidence internal
confInt = confint(expFit);
lowerFitBound = @(x) confInt(1,1)+confInt(1,2)*exp(x); upperFitBound = @(x) confInt(2,1)+confInt(2,2)*exp(x);
fplot(lowerFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]); fplot(upperFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]);
legend('Exponential Fit');
title('V1 residual correlations'); xlabel('Receptive field overlap between voxels (percent)'); ylabel('Residual correlation between voxels (Pearson r)'); ylim([-.4 1]);
v1Exponent = expFit.b;
v1ExponentConfInt = confint(expFit);
v1ExponentConfInt = v1ExponentConfInt(:,2);
if graphStuff
drawPublishAxis('labelFontSize=14');set(gcf,'renderer','Painters')
leg = legend([v1expFit legendColor],'Exponential Fit', 'Permuted Fits'); leg.Position = [0.17 .77 0.2685 0.1003];
end
% second, do v2 %
v2rfOverlapArr = reshape(v2rfOverlap,[1 length(v2rfOverlap)^2]); v2NoiseCorArr = reshape(v2NoiseCor,[1 length(v2NoiseCor)^2]);
[v2rfOverlapArr,sortOrder] = sort(v2rfOverlapArr); v2NoiseCorArr = v2NoiseCorArr(sortOrder);
v2NoiseCorArr(v2rfOverlapArr==100) = []; v2rfOverlapArr(v2rfOverlapArr==100) = [];
v2rfOverlapArr = log10(v2rfOverlapArr + 1);
figure(12); hold on; scatter(v2rfOverlapArr,v2NoiseCorArr,1,'filled','k');
%bootstrap
getFitConfidenceInterval(v2NoiseCorArr',v2rfOverlapArr',graphStuff);
expFit = fit(v2rfOverlapArr',v2NoiseCorArr','a + b*exp(x)');
legendColor = plot(expFit); legendColor.Color = [.3, .5, .3]; legendColor.LineWidth = 2;
v2expFit = plot(expFit); v2expFit.Color = [0, 0.4470, 0.7410]; v2expFit.LineWidth = 2;
%confidence internal
confInt = confint(expFit);
lowerFitBound = @(x) confInt(1,1)+confInt(1,2)*exp(x); upperFitBound = @(x) confInt(2,1)+confInt(2,2)*exp(x);
fplot(lowerFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]); fplot(upperFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]);
legend('Exponential Fit');
title('V2 residual correlations'); xlabel('Receptive field overlap between voxels (percent)'); ylabel('Residual correlation between voxels (Pearson r)');ylim([-.4 1]);
v2Exponent = expFit.b;
v2ExponentConfInt = confint(expFit);
v2ExponentConfInt = v2ExponentConfInt(:,2);
if graphStuff
drawPublishAxis('labelFontSize=14');set(gcf,'renderer','Painters')
leg = legend([v2expFit legendColor],'Exponential Fit', 'Permuted Fits'); leg.Position = [0.17 .77 0.2685 0.1003];
end
% third, do v3 %
v3rfOverlapArr = reshape(v3rfOverlap,[1 length(v3rfOverlap)^2]); v3NoiseCorArr = reshape(v3NoiseCor,[1 length(v3NoiseCor)^2]);
[v3rfOverlapArr,sortOrder] = sort(v3rfOverlapArr); v3NoiseCorArr = v3NoiseCorArr(sortOrder);
v3NoiseCorArr(v3rfOverlapArr==100) = []; v3rfOverlapArr(v3rfOverlapArr==100) = [];
v3rfOverlapArr = log10(v3rfOverlapArr + 1);
figure(13); hold on; scatter(v3rfOverlapArr,v3NoiseCorArr,1,'filled','k');
%bootstrap
getFitConfidenceInterval(v3NoiseCorArr',v3rfOverlapArr',graphStuff);
expFit = fit(v3rfOverlapArr',v3NoiseCorArr','a + b*exp(x)');
legendColor = plot(expFit); legendColor.Color = [.3, .5, .3]; legendColor.LineWidth = 2;
v3expFit = plot(expFit); v3expFit.Color = [0, 0.4470, 0.7410]; v3expFit.LineWidth = 2;
%confidence internal
confInt = confint(expFit);
lowerFitBound = @(x) confInt(1,1)+confInt(1,2)*exp(x); upperFitBound = @(x) confInt(2,1)+confInt(2,2)*exp(x);
fplot(lowerFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]); fplot(upperFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]);
legend('Exponential Fit');
title('V3 residual correlations'); xlabel('Receptive field overlap between voxels (percent)'); ylabel('Residual correlation between voxels (Pearson r)');ylim([-.4 1]);
v3Exponent = expFit.b;
v3ExponentConfInt = confint(expFit);
v3ExponentConfInt = v3ExponentConfInt(:,2);
if graphStuff
drawPublishAxis('labelFontSize=14');set(gcf,'renderer','Painters')
leg = legend([v3expFit legendColor],'Exponential Fit', 'Permuted Fits'); leg.Position = [0.17 .77 0.2685 0.1003];
end
%between v1 and v2
v1v2rfOverlapArr = reshape(v1v2rfOverlap,[1 min(size(v1v2rfOverlap))*max(size(v1v2rfOverlap))]);
v1v2NoiseCorArr = reshape(v1v2NoiseCor,[1 min(size(v1v2NoiseCor))*max(size(v1v2NoiseCor))]);
[v1v2rfOverlapArr,sortOrder] = sort(v1v2rfOverlapArr); v1v2NoiseCorArr = v1v2NoiseCorArr(sortOrder);
v1v2NoiseCorArr(v1v2rfOverlapArr==100) = []; v1v2rfOverlapArr(v1v2rfOverlapArr==100) = [];
v1v2rfOverlapArr = log10(v1v2rfOverlapArr + 1);
figure(14); hold on; scatter(v1v2rfOverlapArr,v1v2NoiseCorArr,1,'filled','k');
%bootstrap
getFitConfidenceInterval(v1v2NoiseCorArr',v1v2rfOverlapArr',graphStuff);
expFit = fit(v1v2rfOverlapArr',v1v2NoiseCorArr','a + b*exp(x)');
legendColor = plot(expFit); legendColor.Color = [.3, .5, .3]; legendColor.LineWidth = 2;
v1v2expFit = plot(expFit); v1v2expFit.Color = [0, 0.4470, 0.7410]; v1v2expFit.LineWidth = 2;
%confidence internal
confInt = confint(expFit);
lowerFitBound = @(x) confInt(1,1)+confInt(1,2)*exp(x); upperFitBound = @(x) confInt(2,1)+confInt(2,2)*exp(x);
fplot(lowerFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]); fplot(upperFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]);
legend('Exponential Fit');
title('V1/V2 residual correlations'); xlabel('Receptive field overlap between voxels (percent)'); ylabel('Residual correlation between voxels (Pearson r)');ylim([-.4 1]);
v1v2Exponent = expFit.b;
v1v2ExponentConfInt = confint(expFit);
v1v2ExponentConfInt = v1v2ExponentConfInt(:,2);
if graphStuff
drawPublishAxis('labelFontSize=14');set(gcf,'renderer','Painters')
leg = legend([v1v2expFit legendColor],'Exponential Fit', 'Permuted Fits'); leg.Position = [0.17 .77 0.2685 0.1003];
end
%between v1 and v3
v1v3rfOverlapArr = reshape(v1v3rfOverlap,[1 min(size(v1v3rfOverlap))*max(size(v1v3rfOverlap))]);
v1v3NoiseCorArr = reshape(v1v3NoiseCor,[1 min(size(v1v3NoiseCor))*max(size(v1v3NoiseCor))]);
[v1v3rfOverlapArr,sortOrder] = sort(v1v3rfOverlapArr); v1v3NoiseCorArr = v1v3NoiseCorArr(sortOrder);
v1v3NoiseCorArr(v1v3rfOverlapArr==100) = []; v1v3rfOverlapArr(v1v3rfOverlapArr==100) = [];
v1v3NoiseCorArr(isnan(v1v3rfOverlapArr))=[];
v1v3rfOverlapArr(isnan(v1v3rfOverlapArr))=[];
v1v3rfOverlapArr = log10(v1v3rfOverlapArr + 1);
figure(15); hold on; scatter(v1v3rfOverlapArr,v1v3NoiseCorArr,1,'filled','k');
%bootstrap
[meanExponent stdExponent] = getFitConfidenceInterval(v1v3NoiseCorArr',v1v3rfOverlapArr',graphStuff);
expFit = fit(v1v3rfOverlapArr',v1v3NoiseCorArr','a + b*exp(x)');
legendColor = plot(expFit); legendColor.Color = [.3, .5, .3]; legendColor.LineWidth = 2;
v1v3expFit = plot(expFit); v1v3expFit.Color = [0, 0.4470, 0.7410]; v1v3expFit.LineWidth = 2;
%confidence internal
confInt = confint(expFit);
lowerFitBound = @(x) confInt(1,1)+confInt(1,2)*exp(x); upperFitBound = @(x) confInt(2,1)+confInt(2,2)*exp(x);
fplot(lowerFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]); fplot(upperFitBound,[0,2],'--','color',[0, 0.4470, 0.7410]);
%expFit = fit(v1v3rfOverlapArr',v1v3NoiseCorArr','a*exp(b*x)+c');
v1v3Exponent = expFit.b;
v1v3ExponentConfInt = confint(expFit);
v1v3ExponentConfInt = v1v3ExponentConfInt(:,2);
legend('Exponential Fit');
title('V1/V3 residual correlations'); xlabel('Receptive field overlap between voxels (percent)'); ylabel('Residual correlation between voxels (Pearson r)');ylim([-.4 1]);
if graphStuff
drawPublishAxis('labelFontSize=14');set(gcf,'renderer','Painters')
leg = legend([v1v3expFit legendColor],'Exponential Fit', 'Permuted Fits'); leg.Position = [0.17 .77 0.2685 0.1003];
end
end %%end doAnalyses
dontdo = 0;if dontdo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% distance and noise correlation %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% first, do v1 %
v1distArr = reshape(v1dist,[1 length(v1dist)^2]); v1NoiseCorArr = reshape(v1NoiseCor,[1 length(v1NoiseCor)^2]);
[v1distArr,sortOrder] = sort(v1distArr); v1NoiseCorArr = v1NoiseCorArr(sortOrder);
v1NoiseCorArr(v1distArr==0) = []; v1distArr(v1distArr==0) = [];
figure(16); hold on; scatter(v1distArr,v1NoiseCorArr,1,'filled','k');
expFit = fit(v1distArr',v1NoiseCorArr','a + b*exp(x)');
v1expFit = plot(expFit,'predobs'); for i = 1:3, v1expFit(i).Color = [0, 0.4470, 0.7410]; v1expFit(i).LineWidth = 2; end
for i = 2:3, v1expFit(i).LineStyle = '--'; v1expFit(i).LineWidth = .75; end
legend('','Linear Fit', 'Exponential Fit');
title('V1 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
drawPublishAxis('labelFontSize=14');
leg = legend('','Exponential Fit', '95% Prediction bounds'); leg.Position = [0.17 .77 0.2685 0.1003];
% second, do v2 %
v2distArr = reshape(v2dist,[1 length(v2dist)^2]); v2NoiseCorArr = reshape(v2NoiseCor,[1 length(v2NoiseCor)^2]);
[v2distArr,sortOrder] = sort(v2distArr); v2NoiseCorArr = v2NoiseCorArr(sortOrder);
v2NoiseCorArr(v2distArr==0) = []; v2distArr(v2distArr==0) = [];
figure(17); hold on; scatter(v2distArr,v2NoiseCorArr,1,'filled','k');
expFit = fit(v2distArr',v2NoiseCorArr','a + b*exp(x)');
v2expFit = plot(expFit,'predobs'); for i = 1:3, v2expFit(i).Color = [0, 0.4470, 0.7410]; v2expFit(i).LineWidth = 2; end
for i = 2:3, v2expFit(i).LineStyle = '--'; v2expFit(i).LineWidth = .75; end
legend('','Linear Fit', 'Exponential Fit');
title('V2 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
drawPublishAxis('labelFontSize=14');
leg = legend('','Exponential Fit', '95% Prediction bounds'); leg.Position = [0.17 .77 0.2685 0.1003];
% third, do v3 %
v3distArr = reshape(v3dist,[1 length(v3dist)^2]); v3NoiseCorArr = reshape(v3NoiseCor,[1 length(v3NoiseCor)^2]);
[v3distArr,sortOrder] = sort(v3distArr); v3NoiseCorArr = v3NoiseCorArr(sortOrder);
v3NoiseCorArr(v3distArr==0) = []; v3distArr(v3distArr==0) = [];
figure(18); hold on; scatter(v3distArr,v3NoiseCorArr,1,'filled','k');
expFit = fit(v3distArr',v3NoiseCorArr','a + b*exp(x)');
v3expFit = plot(expFit,'predobs'); for i = 1:3, v3expFit(i).Color = [0, 0.4470, 0.7410]; v3expFit(i).LineWidth = 2; end
for i = 2:3, v3expFit(i).LineStyle = '--'; v3expFit(i).LineWidth = .75; end
legend('','Linear Fit', 'Exponential Fit');
title('V3 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
drawPublishAxis('labelFontSize=14');
leg = legend('','Exponential Fit', '95% Prediction bounds'); leg.Position = [0.17 .77 0.2685 0.1003];
%between v1 and v2
v1v2distArr = reshape(v1v2dist,[1 min(size(v1v2dist))*max(size(v1v2dist))]); v1v2NoiseCorArr = reshape(v1v2NoiseCor,[1 min(size(v1v2NoiseCor))*max(size(v1v2NoiseCor))]);
[v1v2distArr,sortOrder] = sort(v1v2distArr); v1v2NoiseCorArr = v1v2NoiseCorArr(sortOrder);
v1v2NoiseCorArr(v1v2distArr==0) = []; v1v2distArr(v1v2distArr==0) = [];
figure(19); hold on; scatter(v1v2distArr,v1v2NoiseCorArr,1,'filled','k');
expFit = fit(v1v2distArr',v1v2NoiseCorArr','a + b*exp(x)');
v1v2expFit = plot(expFit,'predobs'); for i = 1:3, v1v2expFit(i).Color = [0, 0.4470, 0.7410]; v1v2expFit(i).LineWidth = 2; end
for i = 2:3, v1v2expFit(i).LineStyle = '--'; v1v2expFit(i).LineWidth = .75; end
legend('','Linear Fit', 'Exponential Fit');
title('V1 V2 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
drawPublishAxis('labelFontSize=14');
leg = legend('','Exponential Fit', '95% Prediction bounds'); leg.Position = [0.17 .77 0.2685 0.1003];
%between v1 and v3
v1v3distArr = reshape(v1v3dist,[1 min(size(v1v3dist))*max(size(v1v3dist))]); v1v3NoiseCorArr = reshape(v1v3NoiseCor,[1 min(size(v1v3NoiseCor))*max(size(v1v3NoiseCor))]);
[v1v3distArr,sortOrder] = sort(v1v3distArr); v1v3NoiseCorArr = v1v3NoiseCorArr(sortOrder);
v1v3NoiseCorArr(v1v3distArr==0) = []; v1v3distArr(v1v3distArr==0) = [];
figure(20); hold on; scatter(v1v3distArr,v1v3NoiseCorArr,1,'filled','k');
expFit = fit(v1v3distArr',v1v3NoiseCorArr','a + b*exp(x)');
v1v3expFit = plot(expFit,'predobs'); for i = 1:3, v1v3expFit(i).Color = [0, 0.4470, 0.7410]; v1v3expFit(i).LineWidth = 2; end
for i = 2:3, v1v3expFit(i).LineStyle = '--'; v1v3expFit(i).LineWidth = .75; end
legend('','Linear Fit', 'Exponential Fit');
title('V1 V3 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
drawPublishAxis('labelFontSize=14');
leg = legend('','Exponential Fit', '95% Prediction bounds'); leg.Position = [0.17 .77 0.2685 0.1003];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% old stuff i don't think is useful %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%% distance vs rf cor %%
%%%%%%%%%%%%%%%%%%%%%%%%
distrf = 0
if distrf
% first, do v1 %
figure(25);hold on;subplot(2,3,1);hold on;
for i = 1:length(v1rfOverlap); scatter(v1dist(i,:),v1rfOverlap(i,:)); end;
v1distArr = reshape(v1dist,[1 length(v1dist)^2]); v1rfOverlapArr = reshape(v1rfOverlap,[1 length(v1rfOverlap)^2]);
[v1distArr,sortOrder] = sort(v1distArr); v1rfOverlapArr = v1rfOverlapArr(sortOrder);
bins = [];rfOverlapAvgs = []; step = .5
for bin = 0:step:40
if sum( (bin < v1distArr) & (v1distArr < bin+step) ) > 15
rfOverlapAvg = median(v1rfOverlapArr((bin < v1distArr) & (v1distArr < bin+step)));
bins = [bins bin]; rfOverlapAvgs = [rfOverlapAvgs rfOverlapAvg];
end
end
plot(bins,rfOverlapAvgs,'black','LineWidth',5);ylim([0,1]);
title('V1 Distance and RF Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('KL divergence between voxel RFs i,j');
% do v2 %
figure(25);hold on;subplot(2,3,2);hold on;
for i = 1:length(v2rfOverlap); scatter(v2dist(i,:),v2rfOverlap(i,:)); end;
v2distArr = reshape(v2dist,[1 length(v2dist)^2]); v2rfOverlapArr = reshape(v2rfOverlap,[1 length(v2rfOverlap)^2]);
[v2distArr,sortOrder] = sort(v2distArr); v2rfOverlapArr = v2rfOverlapArr(sortOrder);
bins = [];rfOverlapAvgs = [];
for bin = 0:step:40
if sum( (bin < v2distArr) & (v2distArr < bin+step) ) > 15
rfOverlapAvg = median(v2rfOverlapArr((bin < v2distArr) & (v2distArr < bin+step)));
bins = [bins bin]; rfOverlapAvgs = [rfOverlapAvgs rfOverlapAvg];
end
end
plot(bins,rfOverlapAvgs,'black','LineWidth',5);ylim([0,1]);
title('V2 Distance and RF Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('KL divergence between voxel RFs i,j');
% do v3 %
figure(25);hold on;subplot(2,3,3);hold on;
for i = 1:length(v3rfOverlap); scatter(v3dist(i,:),v3rfOverlap(i,:)); end;
v3distArr = reshape(v3dist,[1 length(v3dist)^2]); v3rfOverlapArr = reshape(v3rfOverlap,[1 length(v3rfOverlap)^2]);
[v3distArr,sortOrder] = sort(v3distArr); v3rfOverlapArr = v3rfOverlapArr(sortOrder);
bins = [];rfOverlapAvgs = [];
for bin = 0:step:40
if sum( (bin < v3distArr) & (v3distArr < bin+step) ) > 15
rfOverlapAvg = median(v3rfOverlapArr((bin < v3distArr) & (v3distArr < bin+step)));
bins = [bins bin]; rfOverlapAvgs = [rfOverlapAvgs rfOverlapAvg];
end
end
plot(bins,rfOverlapAvgs,'black','LineWidth',5);ylim([0,1]);
title('V3 Distance and RF Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('KL divergence between voxel RFs i,j');
%between v1 and v2
figure(25);hold on;subplot(2,3,4);hold on;
for i = 1:min(size(v1v2rfOverlap)); scatter(v1v2dist(i,:),v1v2rfOverlap(i,:)); end;
v1v2distArr = reshape(v1v2dist,[1 min(size(v1v2dist))*max(size(v1v2dist))]);
v1v2rfOverlapArr = reshape(v1v2rfOverlap,[1 min(size(v1v2rfOverlap))*max(size(v1v2rfOverlap))]);
[v1v2distArr,sortOrder] = sort(v1v2distArr); v1v2rfOverlapArr = v1v2rfOverlapArr(sortOrder);
bins = [];rfOverlapAvgs = [];
for bin = 0:step:45
if sum( (bin < v1v2distArr) & (v1v2distArr < bin+step) ) > 15
rfOverlapAvg = median(v1v2rfOverlapArr((bin < v1v2distArr) & (v1v2distArr < bin+step)));
bins = [bins bin]; rfOverlapAvgs = [rfOverlapAvgs rfOverlapAvg];
end
end
plot(bins,rfOverlapAvgs,'black','LineWidth',5);ylim([0,1]);
title('Distance and RF Correlations between v1 and v2'); xlabel('Distance between voxels V1i, V2j (mm)'); ylabel('KL divergence between voxel RFs V1i, V2j (distance)');
%between v1 and v3
figure(25);hold on;subplot(2,3,5);hold on;
for i = 1:min(size(v1v3rfOverlap)); scatter(v1v3dist(i,:),v1v3rfOverlap(i,:)); end;
v1v3distArr = reshape(v1v3dist,[1 min(size(v1v3dist))*max(size(v1v3dist))]);
v1v3rfOverlapArr = reshape(v1v3rfOverlap,[1 min(size(v1v3rfOverlap))*max(size(v1v3rfOverlap))]);
[v1v3distArr,sortOrder] = sort(v1v3distArr); v1v3rfOverlapArr = v1v3rfOverlapArr(sortOrder);
bins = [];rfOverlapAvgs = [];
for bin = 0:step:45
if sum( (bin < v1v3distArr) & (v1v3distArr < bin+step) ) > 15
rfOverlapAvg = median(v1v3rfOverlapArr((bin < v1v3distArr) & (v1v3distArr < bin+step)));
bins = [bins bin]; rfOverlapAvgs = [rfOverlapAvgs rfOverlapAvg];
end
end
plot(bins,rfOverlapAvgs,'black','LineWidth',5);ylim([0,1]);
title('Distance and RF Correlations between v1 and v3'); xlabel('Distance between voxels V1i, V3j'); ylabel('KL divergence between voxel RFs RFs V1i, V2j (distance)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% time series and noise correlation %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% V1
figure(26);hold on;subplot(1,3,1);hold on;
for i = 1:length(v1NoiseCor); scatter(v1tSeriesCor(i,:),v1NoiseCor(i,:)); end;
v1tSeriesCorArr = reshape(v1tSeriesCor,[1 length(v1tSeriesCor)^2]); v1NoiseCorArr = reshape(v1NoiseCor,[1 length(v1NoiseCor)^2]);
[v1tSeriesCorArr,sortOrder] = sort(v1tSeriesCorArr); v1NoiseCorArr = v1NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = []; step = .05;
for bin = -.5:step:1
if sum( (bin < v1tSeriesCorArr) & (v1tSeriesCorArr < bin+step) ) > 15
noiseCorAvg = median(v1NoiseCorArr((bin < v1tSeriesCorArr) & (v1tSeriesCorArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);xlim([-.5,1]);ylim([-.5,1]);
title('V1 Time Series and Noise Correlation'); xlabel('Time Series Correlation between voxels i,j'); ylabel('Noise correlation between voxels i,j');
%% V2
figure(26);hold on;subplot(1,3,2);hold on;
for i = 1:length(v2NoiseCor); scatter(v2tSeriesCor(i,:),v2NoiseCor(i,:)); end;
v2tSeriesCorArr = reshape(v2tSeriesCor,[1 length(v2tSeriesCor)^2]); v2NoiseCorArr = reshape(v2NoiseCor,[1 length(v2NoiseCor)^2]);
[v2tSeriesCorArr,sortOrder] = sort(v2tSeriesCorArr); v2NoiseCorArr = v2NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = -.5:step:1
if sum( (bin < v2tSeriesCorArr) & (v2tSeriesCorArr < bin+step) ) > 15
noiseCorAvg = median(v2NoiseCorArr((bin < v2tSeriesCorArr) & (v2tSeriesCorArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);xlim([-.5,1]);ylim([-.5,1]);
title('V2 Time Series and Noise Correlation'); xlabel('Time Series Correlation between voxels i,j'); ylabel('Noise correlation between voxels i,j');
%% V3
figure(26);hold on;subplot(1,3,3);hold on;
for i = 1:length(v3NoiseCor); scatter(v3tSeriesCor(i,:),v3NoiseCor(i,:)); end;
v3tSeriesCorArr = reshape(v3tSeriesCor,[1 length(v3tSeriesCor)^2]); v3NoiseCorArr = reshape(v3NoiseCor,[1 length(v3NoiseCor)^2]);
[v3tSeriesCorArr,sortOrder] = sort(v3tSeriesCorArr); v3NoiseCorArr = v3NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = -.5:step:1
if sum( (bin < v3tSeriesCorArr) & (v3tSeriesCorArr < bin+step) ) > 15
noiseCorAvg = median(v3NoiseCorArr((bin < v3tSeriesCorArr) & (v3tSeriesCorArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);xlim([-.5,1]);ylim([-.5,1]);
title('V3 Time Series and Noise Correlation'); xlabel('Time Series Correlation between voxels i,j'); ylabel('Noise correlation between voxels i,j');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% noise std in signal absent and present time frames %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(9);
for roi = 1:length(cleanRois)
x = []; y = []; avg = []; errhigh = []; errlow = []; errmeanhigh = []; errmeanlow = []; yAll = []; avgAll = [];
seg = .1; for bin = 0:seg:(1-seg)
z = []; avgs = [];
for voxel = 1:length(cleanRois(roi).vox.linearCoords)
if mean(cleanRois(roi).vox.pRFtSeries(:,voxel)) > .5 %this fixes an issue where some model responses are centered around 0
lowbound = min(cleanRois(roi).vox.pRFtSeries(:,voxel))+bin*(max(cleanRois(roi).vox.pRFtSeries(:,voxel))-min(cleanRois(roi).vox.pRFtSeries(:,voxel)));
highbound = min(cleanRois(roi).vox.pRFtSeries(:,voxel))+(bin+seg)*(max(cleanRois(roi).vox.pRFtSeries(:,voxel))-min(cleanRois(roi).vox.pRFtSeries(:,voxel)));
z = [z std(cleanRois(roi).vox.baselineNoise(cleanRois(roi).vox.pRFtSeries(:,voxel)>=lowbound & cleanRois(roi).vox.pRFtSeries(:,voxel)<=highbound ,voxel))];
avgs = [avgs mean(cleanRois(roi).vox.baselineNoise(cleanRois(roi).vox.pRFtSeries(:,voxel)>=lowbound & cleanRois(roi).vox.pRFtSeries(:,voxel)<=highbound ,voxel))];
end
end
avgs = avgs(~isnan(avgs)); z = z(~isnan(z));
x = [x bin];
y = [y mean(z)];
yAll{length(x)} = z;
avg = [avg mean(avgs)];
avgAll{length(x)} = avgs;
% errorbars %
for i = 1:1000; err(i) = mean(datasample(z,length(cleanRois(roi).vox.linearCoords)));end; err = sort(err);
errhigh = [errhigh quantile(err,.95)-mean(z)];
errlow = [errlow mean(z)-quantile(err,.05)];
for i = 1:1000; err(i) = mean(datasample(avgs,length(cleanRois(roi).vox.linearCoords)));end; err = sort(err);
errmeanhigh = [errmeanhigh quantile(err,.95)-mean(avgs)];
errmeanlow = [errmeanlow mean(avgs)-quantile(err,.05)];
end
% plot %
subplot(2,length(cleanRois),roi); hold on;
scatter(x,y*100,60,'black','filled');
eb = errorbar(x,y*100,errlow*100,errhigh*100,'o'); eb.Color = 'black';
title(sprintf('%s Residual Std by Activity Quantile',cleanRois(roi).name))
xlabel('Quantile of Voxel Activity');
ylabel('Noise (% signal change)');
subplot(2,length(cleanRois),roi+3); hold on;
scatter(x,avg*100,60,'black','filled');plot([0,1],[0,0],'black--');
eb = errorbar(x,avg*100,errmeanlow*100,errmeanhigh*100,'o'); eb.Color = 'black';
title(sprintf('%s Average Residual by Activity Quantile',cleanRois(roi).name))
xlabel('Quantile of Voxel Activity');
ylabel('Average Residual (% signal change)');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% distance and noise correlation %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
showdist = 0;
if showdist
% first, do v1 %
figure(11);hold on;subplot(1,2,2);hold on;
v1NoiseCor = corrcoef(cleanRois(1).vox.baselineNoise);
for i = 1:length(v1NoiseCor); scatter(v1dist(i,:),v1NoiseCor(i,:)); end;
v1distArr = reshape(v1dist,[1 length(v1dist)^2]); v1NoiseCorArr = reshape(v1NoiseCor,[1 length(v1NoiseCor)^2]);
[v1distArr,sortOrder] = sort(v1distArr); v1NoiseCorArr = v1NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = []; step = .5
for bin = 0:step:40
if sum( (bin < v1distArr) & (v1distArr < bin+step) ) > 15
noiseCorAvg = median(v1NoiseCorArr((bin < v1distArr) & (v1distArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);set(gca,'XDir','reverse');
title('V1 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
% second, do v2 %
figure(12);hold on;subplot(1,2,2);hold on;
v2NoiseCor = corrcoef(cleanRois(2).vox.baselineNoise);
for i = 1:length(v2NoiseCor); scatter(v2dist(i,:),v2NoiseCor(i,:)); end;
v2distArr = reshape(v2dist,[1 length(v2dist)^2]); v2NoiseCorArr = reshape(v2NoiseCor,[1 length(v2NoiseCor)^2]);
[v2distArr,sortOrder] = sort(v2distArr); v2NoiseCorArr = v2NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = 0:step:40
if sum( (bin < v2distArr) & (v2distArr < bin+step) ) > 15
noiseCorAvg = median(v2NoiseCorArr((bin < v2distArr) & (v2distArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);set(gca,'XDir','reverse');
title('V2 Distance and Noise Correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
% third, do v3 %
figure(13);hold on;subplot(1,2,2);hold on;
v3NoiseCor = corrcoef(cleanRois(3).vox.baselineNoise);
for i = 1:length(v3NoiseCor); scatter(v3dist(i,:),v3NoiseCor(i,:)); end;
v3distArr = reshape(v3dist,[1 length(v3dist)^2]); v3NoiseCorArr = reshape(v3NoiseCor,[1 length(v3NoiseCor)^2]);
[v3distArr,sortOrder] = sort(v3distArr); v3NoiseCorArr = v3NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = 0:step:40
if sum( (bin < v3distArr) & (v3distArr < bin+step) ) > 15
noiseCorAvg = median(v3NoiseCorArr((bin < v3distArr) & (v3distArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5); set(gca,'XDir','reverse');
title('v3 Distance and Noise correlations'); xlabel('Distance between voxels i,j (mm)'); ylabel('Noise correlation between voxels i,j');
%between v1 and v2
figure(14);hold on;subplot(1,2,2);hold on;
v1v2NoiseCor = transpose(corr(cleanRois(1).vox.baselineNoise,cleanRois(2).vox.baselineNoise));
for i = 1:min(size(v1v2NoiseCor)); scatter(v1v2dist(i,:),v1v2NoiseCor(i,:)); end;
v1v2distArr = reshape(v1v2dist,[1 min(size(v1v2dist))*max(size(v1v2dist))]);
v1v2NoiseCorArr = reshape(v1v2NoiseCor,[1 min(size(v1v2NoiseCor))*max(size(v1v2NoiseCor))]);
[v1v2distArr,sortOrder] = sort(v1v2distArr); v1v2NoiseCorArr = v1v2NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = 0:step:45
if sum( (bin < v1v2distArr) & (v1v2distArr < bin+step) ) > 15
noiseCorAvg = median(v1v2NoiseCorArr((bin < v1v2distArr) & (v1v2distArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5); set(gca,'XDir','reverse');
title('Distance and Noise Correlations between v1 and v2'); xlabel('Distance between voxels V1i, V2j (mm)'); ylabel('Noise correlation between voxels V1i, V2j');
%between v1 and v3
figure(15);hold on;subplot(1,2,2);hold on;
v1v3NoiseCor = transpose(corr(cleanRois(1).vox.baselineNoise,cleanRois(3).vox.baselineNoise));
for i = 1:min(size(v1v3NoiseCor)); scatter(v1v3dist(i,:),v1v3NoiseCor(i,:)); end;
v1v3distArr = reshape(v1v3dist,[1 min(size(v1v3dist))*max(size(v1v3dist))]);
v1v3NoiseCorArr = reshape(v1v3NoiseCor,[1 min(size(v1v3NoiseCor))*max(size(v1v3NoiseCor))]);
[v1v3distArr,sortOrder] = sort(v1v3distArr); v1v3NoiseCorArr = v1v3NoiseCorArr(sortOrder);
bins = [];noiseCorAvgs = [];
for bin = 0:step:45
if sum( (bin < v1v3distArr) & (v1v3distArr < bin+step) ) > 15
noiseCorAvg = median(v1v3NoiseCorArr((bin < v1v3distArr) & (v1v3distArr < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5); set(gca,'XDir','reverse');
title('Distance and Noise Correlations between v1 and v3'); xlabel('Distance between voxels V1i, V3j'); ylabel('Noise correlation between voxels V1i, V2j');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% noise and receptive field overlaps cutoff by distance %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
distanceHigh = 10; distanceLow = 3;
% v1 %
figure(30); v1NoiseArrClose = v1NoiseCor(v1dist<distanceLow & v1dist>0); v1NoiseArrFar = v1NoiseCor(v1dist>distanceHigh);
v1kldArrClose = v1rfOverlap(v1dist<distanceLow & v1dist>0); v1kldArrFar = v1rfOverlap(v1dist>distanceHigh);
subplot(1,2,1);scatter(v1kldArrClose,v1NoiseArrClose);hold on;
bins = [];noiseCorAvgs = []; step = .01;
for bin = 0:step:40
if sum( (bin < v1kldArrClose) & (v1kldArrClose < bin+step) ) > 30
noiseCorAvg = median(v1NoiseArrClose((bin < v1kldArrClose) & (v1kldArrClose < bin+step)));
bins = [bins bin]; noiseCorAvgs = [noiseCorAvgs noiseCorAvg];
end
end
plot(bins,noiseCorAvgs,'black','LineWidth',5);
title('V1 Receptive field overlap and Noise Correlations (close voxels)'); xlabel('Receptive field overlap (percent)'); ylabel('Noise correlation between voxels i,j'); xlim([0,1]); ylim([-.4,1]);
subplot(1,2,2);scatter(v1kldArrFar,v1NoiseArrFar);hold on;
bins = [];noiseCorAvgs = [];
for bin = 0:step:40