Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

ck_StatsAndPlots.m 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692
  1. % ck_StatsAndPlots
  2. % Takes the pre-processed fitting result tables
  3. % Calculates stats and creates figures
  4. SaveFigs=false; % autosave generated figs
  5. CloseFigs=false; % autoclose generated figs
  6. %% ========================================================================
  7. % INITIATE ---------------------------------------------------------------
  8. % ========================================================================
  9. %% Paths ==================================================================
  10. fprintf('Setting up paths\n')
  11. BaseFld = pwd;
  12. cd ../../../
  13. SHARED_ROOT_FLD = pwd;
  14. cd(BaseFld)
  15. ResFld = fullfile(SHARED_ROOT_FLD,'FitResults','MULTIMODAL','cv1');
  16. % add toolboxes (colorbrewer,matplotlib,boundedline)
  17. addpath(genpath(fullfile(SHARED_ROOT_FLD,'Toolboxes')));
  18. def_cmap = 'Spectral';
  19. ResType = 'mean';
  20. TT = ['Tables_' ResType];
  21. % figure saving folder
  22. pngfld = fullfile(pwd,'fig_png'); [~,~] = mkdir(pngfld);
  23. svgfld = fullfile(pwd,'fig_svg'); [~,~] = mkdir(svgfld);
  24. %% Load ===================================================================
  25. fprintf(['Loading results table. '...
  26. 'Please be patient, this will take a while..\n']);
  27. tic; load(fullfile(ResFld,TT)); t_load=toc;
  28. fprintf(['Loading took ' num2str(t_load) ' s\n']);
  29. %% Correct for result type ================================================
  30. fprintf('Generalizing variable names...\n');
  31. fprintf('MRI...');
  32. eval(['tMRI = tMRI_' ResType '; clear tMRI_' ResType ';']);
  33. fprintf('MUA...');
  34. eval(['tMUA = tMUA_' ResType '; clear tMUA_' ResType ';']);
  35. fprintf('LFP...');
  36. eval(['tLFP = tLFP_' ResType '; clear tLFP_' ResType ';']);
  37. fprintf('>> DONE\n');
  38. %% Split MRI table by model ===============================================
  39. fprintf('Splitting MRI table by model\n')
  40. m = unique(tMRI.Model);
  41. for mi = 1:length(m)
  42. M = tMRI(strcmp(tMRI.Model,m{mi}),:);
  43. T(mi).mod = M;
  44. T(mi).name = m{mi};
  45. modidx.(m{mi}) = mi;
  46. end
  47. %% Initiate some information ==============================================
  48. fprintf('Generating ROI, model, and subject labels\n')
  49. % proces ROI info
  50. rois = {...
  51. 'V1', [34];... % occipital / visual
  52. 'V2', [131];... % occipital / visual
  53. 'V3', [60,93];... % occipital / visual
  54. 'V3A' [123];... % occipital / visual
  55. 'V4', [20,39,75];... % mid-visual
  56. 'V6', [73];... % mid-visual
  57. 'V6A', [141,56];...
  58. 'MT', [95];... % mid-visual
  59. 'MST', [99];... % mid-visual
  60. 'TEO', [125];... % temporal
  61. 'TAa', [152];... % temporal
  62. 'Tpt', [97];... % temporal (temporal/parietal)
  63. 'TPO', [159];... % temporal
  64. 'FST', [53];... % temporal
  65. 'A1', [80];... % temporal
  66. 'ML' [25];... % temporal
  67. 'AL', [46];... % temporal
  68. 'PULV', [197,198];... % subcortical
  69. 'LGN', [200,201];... % subcortical
  70. 'STR', [175];... % subcortical
  71. 'MIP', [89];...
  72. 'PIP', [90];...
  73. 'LIP', [31,130];... % parietal
  74. 'VIP', [30];... % parietal
  75. '5', [134];... % parietal
  76. '7', [91,121];... % parietal
  77. 'SI', [50,137];... % Prim Somatosensory
  78. 'SII', [63];... % Sec Somatosensory
  79. 'F2', [153];... % premotor
  80. 'F4', [146];... % premotor
  81. 'F5', [129];... % premotor
  82. 'F7', [126];... % premotor
  83. '8', [32,51,57,148];... % frontal FEF 8A: 51, 148; 8B: 32, 57 % combine these
  84. 'CINp', [6,17,27];... % posterior cingulate
  85. 'CINa', [45,98];... % anterior cingulate
  86. 'OFC', [55,107];... % frontal
  87. 'INS', [18,87,128];... % frontal
  88. 'DLPFC',[47,76,127];... % frontal
  89. 'VMPFC',[5];... % frontal
  90. };
  91. roi=rois(:,2);
  92. roilabels=rois(:,1);
  93. MRI_MODELS={...
  94. 'linhrf_cv1_mhrf','linhrf_cv1_dhrf';...
  95. 'linhrf_cv1_mhrf_neggain','linhrf_cv1_dhrf_neggain';...
  96. 'csshrf_cv1_mhrf','csshrf_cv1_dhrf';...
  97. 'doghrf_cv1_mhrf','doghrf_cv1_dhrf';...
  98. };
  99. ephys_MOD={'linear_ephys_cv1','linear_ephys_cv1_neggain',...
  100. 'css_ephys_cv1','dog_ephys_cv1'};
  101. MMS={...
  102. 'LIN_m','LIN_d';...
  103. 'LIN-N_m','LIN-N_d';...
  104. 'CSS_m','CSS_d';...
  105. 'DOG_m','DOG_d';...
  106. };
  107. cSUBS = unique(tMRI.Monkey);
  108. SUBS = cellstr(cSUBS);
  109. %% ========================================================================
  110. % FMRI PRF ANALYSIS ------------------------------------------------------
  111. % ========================================================================
  112. %% Fig 2C: # significant voxels per ROI (split by monkey and model) =======
  113. RTHRES = 5; % R2 inclusion threshold
  114. ff = figure;
  115. set(ff,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  116. set(ff,'Position',[10 10 1600 1000]);
  117. paneln=1;
  118. for s = 1:length(SUBS)
  119. fprintf(['SUB: ' SUBS{s} '\n'])
  120. for rowmod=1:4
  121. subplot(4,2,paneln); hold on;
  122. nvox=[];
  123. for r=1:length(roi)
  124. nvox = [nvox; sum(...
  125. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2 > RTHRES & ...
  126. strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey, cSUBS(s)) & ...
  127. ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  128. ck_GetROIidx(roilabels(r),rois) ) ) ...
  129. sum(strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey, cSUBS(s)) & ...
  130. ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  131. ck_GetROIidx(roilabels(r),rois) ) ) ];
  132. end
  133. for xval=1:size(nvox,1)
  134. bar(xval,nvox(xval,1));
  135. end
  136. title(['SUB ' SUBS{s} ', ' MMS{rowmod,1} ' nVox with R2 > ' ...
  137. num2str(RTHRES)],'interpreter','none');
  138. xlabel('ROI'); ylabel('nVox','interpreter','none');
  139. set(gca, 'Box','off','yscale','log');
  140. set(gca,'xtick',1:length(nvox),'xticklabels',roilabels,'TickDir','out');
  141. xtickangle(45)
  142. paneln=paneln+1;
  143. end
  144. end
  145. if SaveFigs
  146. saveas(ff,fullfile(pngfld, 'MRI_nVoxSign_ROI.png'));
  147. saveas(ff,fullfile(svgfld, 'MRI_nVoxSign_ROI.svg'));
  148. end
  149. if CloseFigs; close(ff); end
  150. %% SFig 1: prop significant voxels per ROI (split by monkey and model) ====
  151. ff2 = figure;
  152. set(ff2,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  153. set(ff2,'Position',[10 10 1600 1000]);
  154. paneln=1;
  155. for s = 1: length(SUBS)
  156. fprintf(['SUB: ' SUBS{s} '\n'])
  157. for rowmod=1:4
  158. subplot(4,2,paneln); hold on;
  159. nvox=[];
  160. for r=1:length(roi)
  161. nvox = [nvox; sum(...
  162. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2 > RTHRES & ...
  163. strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey, cSUBS(s)) & ...
  164. ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  165. ck_GetROIidx(roilabels(r),rois) ) ) ...
  166. sum(strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey, cSUBS(s)) & ...
  167. ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  168. ck_GetROIidx(roilabels(r),rois) ) ) ];
  169. end
  170. for xval=1:size(nvox,1)
  171. bar(xval,nvox(xval,1)./nvox(xval,2));
  172. end
  173. title(['SUB ' SUBS{s} ', ' MMS{rowmod,1} ' proportion Vox with R2 > ' ...
  174. num2str(RTHRES)],'interpreter','none');
  175. xlabel('ROI'); ylabel('Proportion Vox','interpreter','none');
  176. set(gca, 'Box','off','ylim',[0 .6]);
  177. set(gca,'xtick',1:length(nvox),'xticklabels',roilabels,'TickDir','out');
  178. xtickangle(45)
  179. paneln=paneln+1;
  180. end
  181. end
  182. if SaveFigs
  183. saveas(ff2,fullfile(pngfld, 'MRI_propVoxSign_ROI.png'));
  184. saveas(ff2,fullfile(svgfld, 'MRI_propVoxSign_ROI.svg'));
  185. end
  186. if CloseFigs; close(ff2); end
  187. %% MRI scatter plots & differences R2 per ROI =============================
  188. RTHRES = 0; % include all voxels
  189. for sidx = 0:2 % both monkeys and individuals
  190. % scatter plots ---
  191. % Different ROIS in different colors
  192. f=figure;
  193. set(f,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  194. set(f,'Position',[10 10 1300 600]);
  195. % Tell us what's happening
  196. if sidx
  197. fprintf(['Monkey ' SUBS{sidx} '\n']);
  198. marker = [' ' SUBS{sidx}];
  199. else
  200. fprintf(['Both monkeys\n']);
  201. marker = ' both';
  202. end
  203. % plot scatter per area
  204. figure(f); paneln=1;
  205. for rowmod=1:4
  206. for colmod=rowmod+1:4
  207. subplot(2,3,paneln); hold on;
  208. PerROI(sidx+1,paneln).Models = {MRI_MODELS{rowmod,1},MRI_MODELS{colmod,1}};
  209. PerROI(sidx+1,paneln).mR2 = []; PerROI(sidx+1,paneln).seR2 = [];
  210. for r=1:length(roi)
  211. s_R2 = T(modidx.(MRI_MODELS{rowmod,1})).mod.R2 >= RTHRES | ...
  212. T(modidx.(MRI_MODELS{colmod,1})).mod.R2 >= RTHRES;
  213. if sidx
  214. s_Monkey = strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey,cSUBS(sidx));
  215. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  216. ck_GetROIidx(roilabels(r),rois)) & s_Monkey;
  217. else
  218. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  219. ck_GetROIidx(roilabels(r),rois));
  220. end
  221. scatter(...
  222. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS),...
  223. T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS),...
  224. 100,'Marker','.');
  225. PerROI(sidx+1,paneln).roi(r).sub = marker(2:end);
  226. PerROI(sidx+1,paneln).roi(r).name = roilabels(r);
  227. PerROI(sidx+1,paneln).roi(r).R2 = [...
  228. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS),...
  229. T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)];
  230. PerROI(sidx+1,paneln).mR2 = [PerROI(sidx+1,paneln).mR2; ...
  231. nanmean(T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS)),...
  232. nanmean(T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS))];
  233. PerROI(sidx+1,paneln).seR2 = [PerROI(sidx+1,paneln).seR2; ...
  234. nanstd(T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS))./...
  235. sqrt(length(T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS))),...
  236. nanstd(T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS))./...
  237. sqrt(length(T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)))];
  238. % stats per ROI
  239. [PerROI(sidx+1,paneln).roi(r).p,...
  240. PerROI(sidx+1,paneln).roi(r).h,...
  241. PerROI(sidx+1,paneln).roi(r).stats] = signrank(...
  242. PerROI(sidx+1,paneln).roi(r).R2(:,1),...
  243. PerROI(sidx+1,paneln).roi(r).R2(:,2));
  244. PerROI(sidx+1,paneln).roi(r).dir = ...
  245. diff(PerROI(sidx+1,paneln).mR2(r,:))./...
  246. abs(diff(PerROI(sidx+1,paneln).mR2(r,:)));
  247. end
  248. plot([-2 100],[-2 100],'k','Linewidth',1);
  249. title([MMS{rowmod,1} ' vs ' MMS{colmod,1}],'interpreter','none');
  250. xlabel(MMS{rowmod,1},'interpreter','none');
  251. ylabel(MMS{colmod,1},'interpreter','none');
  252. set(gca, 'Box','off', 'xlim', [-2 100], 'ylim',[-2 100]);
  253. paneln=paneln+1;
  254. end
  255. end
  256. sgtitle(['SUBJECT' marker])
  257. if SaveFigs; saveas(f,fullfile(pngfld, ...
  258. ['MRI_ModelComparison_ROI_R2' marker '.png'])); end
  259. if SaveFigs; saveas(f,fullfile(svgfld, ...
  260. ['MRI_ModelComparison_ROI_R2' marker '.svg'])); end
  261. if CloseFigs; close(f); end
  262. end
  263. % Report stats per ROI ----
  264. fprintf('Compare CSS against P-LIN per ROI -----\n');
  265. nBetter = sum([PerROI(1,2).roi(:).p] < 0.05 & [PerROI(1,2).roi(:).dir] > 0);
  266. nWorse = sum([PerROI(1,2).roi(:).p] < 0.05 & [PerROI(1,2).roi(:).dir] < 0);
  267. nSimilar = sum([PerROI(1,2).roi(:).p] > 0.05);
  268. nROI = length(PerROI(1,2).roi);
  269. fprintf('- Both together -\n');
  270. fprintf([num2str(nBetter) '/' num2str(nROI) ' CSS better\n']);
  271. fprintf([num2str(nWorse) '/' num2str(nROI) ' CSS worse\n']);
  272. fprintf([num2str(nSimilar) '/' num2str(nROI) ' no difference\n']);
  273. nBetter = sum([PerROI(2,2).roi(:).p] < 0.05 & [PerROI(2,2).roi(:).dir] > 0);
  274. nWorse = sum([PerROI(2,2).roi(:).p] < 0.05 & [PerROI(2,2).roi(:).dir] < 0);
  275. nSimilar = sum([PerROI(2,2).roi(:).p] > 0.05);
  276. nROI = length(PerROI(2,2).roi);
  277. fprintf(['- ' SUBS{1} ' -\n']);
  278. fprintf([num2str(nBetter) '/' num2str(nROI) ' CSS better\n']);
  279. fprintf([num2str(nWorse) '/' num2str(nROI) ' CSS worse\n']);
  280. fprintf([num2str(nSimilar) '/' num2str(nROI) ' no difference\n']);
  281. nBetter = sum([PerROI(3,2).roi(:).p] < 0.05 & [PerROI(3,2).roi(:).dir] > 0);
  282. nWorse = sum([PerROI(3,2).roi(:).p] < 0.05 & [PerROI(3,2).roi(:).dir] < 0);
  283. nSimilar = sum([PerROI(3,2).roi(:).p] > 0.05);
  284. nROI = length(PerROI(3,2).roi);
  285. fprintf(['- ' SUBS{2} ' -\n']);
  286. fprintf([num2str(nBetter) '/' num2str(nROI) ' CSS better\n']);
  287. fprintf([num2str(nWorse) '/' num2str(nROI) ' CSS worse\n']);
  288. fprintf([num2str(nSimilar) '/' num2str(nROI) ' no difference\n']);
  289. %% Fig 4A / SFig 3C: MRI scatter plots & differences R2 all voxels ========
  290. RTHRES = 0; % include all voxels
  291. for sidx = 0:2 % both monkeys and individuals
  292. % All ROIS together in black
  293. fsc=figure;
  294. set(fsc,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  295. set(fsc,'Position',[10 10 1300 600]);
  296. % Tell us what's happening
  297. if sidx
  298. fprintf(['Monkey ' SUBS{sidx} '\n']);
  299. marker = [' ' SUBS{sidx}];
  300. else
  301. fprintf(['Both monkeys\n']);
  302. marker = ' both';
  303. end
  304. % plot scatter over all voxels
  305. figure(fsc); paneln=1;
  306. for rowmod=1:4
  307. for colmod=rowmod+1:4
  308. subplot(2,3,paneln); hold on;
  309. XY=[];
  310. for r=1:length(roi)
  311. s_R2 = T(modidx.(MRI_MODELS{rowmod,1})).mod.R2 >= RTHRES | ...
  312. T(modidx.(MRI_MODELS{colmod,1})).mod.R2 >= RTHRES;
  313. if sidx
  314. s_Monkey = strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey,cSUBS(sidx));
  315. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  316. ck_GetROIidx(roilabels(r),rois)) & s_Monkey;
  317. else
  318. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  319. ck_GetROIidx(roilabels(r),rois));
  320. end
  321. XY=[XY; [T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS) ...
  322. T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)] ];
  323. end
  324. binscatter(XY(:,1),XY(:,2),100); colorbar;
  325. set(gca,'ColorScale','log');
  326. colormap(inferno)
  327. plot([-2 100],[-2 100],'k','Linewidth',1);
  328. title([MMS{rowmod,1} ' vs ' MMS{colmod,1}],'interpreter','none');
  329. xlabel(MMS{rowmod,1},'interpreter','none');
  330. ylabel(MMS{colmod,1},'interpreter','none');
  331. set(gca, 'Box','off', 'xlim', [-2 100], 'ylim',[-2 100]);
  332. caxis([1 1e4])
  333. paneln=paneln+1;
  334. end
  335. end
  336. sgtitle(['SUBJECT' marker])
  337. if SaveFigs
  338. saveas(fsc,fullfile(pngfld,['MRI_ModelComparison_R2' marker '.png']));
  339. saveas(fsc,fullfile(svgfld,['MRI_ModelComparison_R2' marker '.svg']));
  340. end
  341. if CloseFigs; close(fsc); end
  342. end
  343. % stats over both subs
  344. MR2 = [T(2).mod.R2 T(4).mod.R2 T(7).mod.R2 T(8).mod.R2];
  345. sel=logical(sum(MR2>0,2));
  346. [p,tbl,stats] = kruskalwallis(MR2(sel,:),{'css','dog','p-lin','u-lin'});
  347. fprintf(['Kruskal Wallis ----- p = ' num2str(p) '\n']);
  348. [c,m,h,gnames] = multcompare(stats);
  349. fprintf('Tukey HSD -----\n')
  350. for i=1:size(c,1)
  351. fprintf([gnames{c(i,1)} ' vs ' gnames{c(i,2)} ...
  352. ', p = ' num2str(c(i,6)) '\n'])
  353. end
  354. %% SFig 3A-B Difference in R2 across models per ROI =======================
  355. for sidx = 0:2 % both monkeys and individuals
  356. % Tell us what's happening
  357. if sidx
  358. fprintf(['Monkey ' SUBS{sidx} '\n']);
  359. marker = [' ' SUBS{sidx}];
  360. else
  361. fprintf(['Both monkeys\n']);
  362. marker = ' both';
  363. end
  364. idx=1;
  365. for rowmod=1:4
  366. for colmod=rowmod+1:4
  367. diffmat{sidx+1,idx}=[];
  368. for r=1:length(roi)
  369. if sidx
  370. s_Monkey = strcmp(T(modidx.(MRI_MODELS{rowmod,1})).mod.Monkey,cSUBS(sidx));
  371. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  372. ck_GetROIidx(roilabels(r),rois)) & s_Monkey;
  373. else
  374. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  375. ck_GetROIidx(roilabels(r),rois));
  376. end
  377. [n,x] = hist(...
  378. T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)-...
  379. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS), 100);
  380. f = n./sum(SSS);
  381. m = mean(T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)-...
  382. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS));
  383. sd = std(T(modidx.(MRI_MODELS{colmod,1})).mod.R2(SSS)-...
  384. T(modidx.(MRI_MODELS{rowmod,1})).mod.R2(SSS));
  385. se = sd ./ sqrt(sum(SSS));
  386. diffmat{sidx+1,idx} = [diffmat{sidx+1,idx}; m sd se];
  387. end
  388. idx=idx+1;
  389. end
  390. end
  391. end
  392. f2=figure;
  393. set(f2,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  394. set(f2,'Position',[100 100 1800 1000]);
  395. cc=1;
  396. for rowmod=1:4
  397. for colmod=rowmod+1:4
  398. subplot(3,2,cc); hold on;
  399. for xval=1:length(diffmat{1,cc})
  400. bar(xval,diffmat{1,cc}(xval,1));
  401. end
  402. for xval=1:length(diffmat{1,cc})
  403. errorbar(xval,diffmat{1,cc}(xval,1),diffmat{cc}(xval,3),...
  404. 'k-','Linestyle','none');
  405. end
  406. set(gca,'xtick',1:length(diffmat{cc}),...
  407. 'xticklabels',roilabels,'ylim',[-2 3],'TickDir','out');
  408. xlabel('ROI'); ylabel('Diff R2');
  409. title([MMS{colmod,1} ' - ' MMS{rowmod,1}],...
  410. 'interpreter','none');
  411. xtickangle(45)
  412. cc=cc+1;
  413. end
  414. end
  415. if SaveFigs
  416. saveas(f2,fullfile(pngfld, 'MRI_ModelComparison_ROI_R2.png'));
  417. saveas(f2,fullfile(svgfld, 'MRI_ModelComparison_ROI_R2.svg'));
  418. end
  419. if CloseFigs; close(f2); end
  420. %% only CSS and DoG vs P-LIN per monkey ===================================
  421. f3=figure;
  422. set(f3,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  423. set(f3,'Position',[100 100 1200 1000]);
  424. subplot(2,2,1); hold on;
  425. for xval=1:length(diffmat{2,2})
  426. bar(xval,diffmat{2,2}(xval,1));
  427. end
  428. for xval=1:length(diffmat{2,2})
  429. errorbar(xval,diffmat{2,2}(xval,1),diffmat{2,2}(xval,3),...
  430. 'k-','Linestyle','none');
  431. end
  432. set(gca,'xtick',1:length(diffmat{2,2}),...
  433. 'xticklabels',roilabels,'ylim',[-0.1 2.5],'TickDir','out');
  434. xlabel('ROI'); ylabel('Diff R2');
  435. title('M1: CSS - P-LIN','interpreter','none');
  436. xtickangle(45)
  437. subplot(2,2,2); hold on;
  438. for xval=1:length(diffmat{2,3})
  439. bar(xval,diffmat{2,3}(xval,1));
  440. end
  441. for xval=1:length(diffmat{2,3})
  442. errorbar(xval,diffmat{2,3}(xval,1),diffmat{2,3}(xval,3),...
  443. 'k-','Linestyle','none');
  444. end
  445. set(gca,'xtick',1:length(diffmat{2,3}),...
  446. 'xticklabels',roilabels,'ylim',[-0.1 2.5],'TickDir','out');
  447. xlabel('ROI'); ylabel('Diff R2');
  448. title('M1: DoG - P-LIN','interpreter','none');
  449. xtickangle(45)
  450. subplot(2,2,3); hold on;
  451. for xval=1:length(diffmat{3,2})
  452. bar(xval,diffmat{3,2}(xval,1));
  453. end
  454. for xval=1:length(diffmat{3,2})
  455. errorbar(xval,diffmat{3,2}(xval,1),diffmat{3,2}(xval,3),...
  456. 'k-','Linestyle','none');
  457. end
  458. set(gca,'xtick',1:length(diffmat{3,2}),...
  459. 'xticklabels',roilabels,'ylim',[-0.1 2.5],'TickDir','out');
  460. xlabel('ROI'); ylabel('Diff R2');
  461. title('M2: CSS - P-LIN','interpreter','none');
  462. xtickangle(45)
  463. subplot(2,2,4); hold on;
  464. for xval=1:length(diffmat{3,3})
  465. bar(xval,diffmat{3,3}(xval,1));
  466. end
  467. for xval=1:length(diffmat{3,3})
  468. errorbar(xval,diffmat{3,3}(xval,1),diffmat{3,3}(xval,3),...
  469. 'k-','Linestyle','none');
  470. end
  471. set(gca,'xtick',1:length(diffmat{3,3}),...
  472. 'xticklabels',roilabels,'ylim',[-0.1 2.5],'TickDir','out');
  473. xlabel('ROI'); ylabel('Diff R2');
  474. title('M2: DoG - P-LIN','interpreter','none');
  475. xtickangle(45)
  476. if SaveFigs
  477. saveas(f3,fullfile(pngfld, 'MRI_SelModelComparison_ROI_R2.png'));
  478. saveas(f3,fullfile(svgfld, 'MRI_SelModelComparison_ROI_R2.svg'));
  479. end
  480. if CloseFigs; close(f3); end
  481. %% Fig 4B NegGain Fits: Characterize ======================================
  482. R2th = 5; % minimum R2
  483. R2enh = 5; % R2 improvement
  484. DoG = tMRI(...
  485. strcmp(tMRI.Model,'doghrf_cv1_mhrf'),:);
  486. lin_n = tMRI(...
  487. strcmp(tMRI.Model,'linhrf_cv1_mhrf_neggain'),:);
  488. lin = tMRI(...
  489. strcmp(tMRI.Model,'linhrf_cv1_mhrf'),:);
  490. f_neg2 = figure;
  491. set(f_neg2,'Position',[10 10 1200 1000]);
  492. vox_sel = lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh & ...
  493. (lin_n.ecc<25 & lin.ecc<25 & DoG.ecc<25) & ....
  494. (lin_n.rfs<20 & lin.rfs<20 & DoG.rfs<20);
  495. fprintf('-------------\n');
  496. subplot(2,3,1); hold on;
  497. histogram(lin_n.gain(vox_sel),-100:0.1:100,...
  498. 'Normalization','probability','FaceColor','k','FaceAlpha',0.75);
  499. xlabel('gain LIN-POSNEG');ylabel('nvoxels');
  500. set(gca,'xlim',[-2.6 2.6]);
  501. MM=median(lin_n.gain(vox_sel));
  502. yy=get(gca,'ylim');
  503. plot([MM MM], [0 1],'k','Linewidth',2)
  504. set(gca,'ylim',[0 0.3],'TickDir','out');
  505. title('Gain SELECTED voxels')
  506. fprintf(['MEDIAN GAIN SEL: ' num2str(MM) '\n'])
  507. % Wilcoxon 1-tailed < 1
  508. [p,h,stats] = signrank(lin_n.gain(vox_sel),0,'tail','left');
  509. fprintf(['Gain SEL < 0: Wilcoxon z = ' ...
  510. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  511. % all vox
  512. subplot(2,3,4); hold on;
  513. histogram(lin_n.gain,-100:0.1:100,...
  514. 'Normalization','probability','FaceColor','k','FaceAlpha',0.75);
  515. xlabel('gain LIN-POSNEG');ylabel('nvoxels');
  516. set(gca,'xlim',[-2.6 2.6]);
  517. MM=median(lin_n.gain);
  518. yy=get(gca,'ylim');
  519. plot([MM MM], [0 1],'k','Linewidth',2)
  520. set(gca,'ylim',[0 0.3],'TickDir','out');
  521. title('Gain ALL voxels')
  522. fprintf(['MEDIAN GAIN ALL: ' num2str(MM) '\n'])
  523. % Wilcoxon 1-tailed < 1
  524. [p,h,stats] = signrank(lin_n.gain,0,'tail','right');
  525. fprintf(['Gain ALL < 0: Wilcoxon z = ' ...
  526. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  527. fprintf('-------------\n');
  528. subplot(2,3,2); hold on;
  529. bb = [lin_n.ecc(vox_sel) lin.ecc(vox_sel)];
  530. plot([1 2],mean(bb),'o','Linewidth',2)
  531. errorbar([1 2],mean(bb),std(bb),'k','Linewidth',2)
  532. plot([1 2],mean(bb),'o','MarkerSize',10,'MarkerFaceColor','k','MarkerEdgeColor','k')
  533. set(gca,'xtick',1:2,'xticklabels',{'LIN-N','LIN'},...
  534. 'ylim',[0 15],'xlim',[0.8 2.2],'TickDir','out')
  535. ylabel('Eccentricity');
  536. title('Ecc')
  537. subplot(2,3,3); hold on;
  538. histogram(lin.ecc(vox_sel)-lin_n.ecc(vox_sel),-10:0.5:10,...
  539. 'FaceColor','k','FaceAlpha',0.5);
  540. xlabel('Ecc. Diff (POS-POSNEG)');ylabel('nvoxels');
  541. MM=median(bb(:,2)-bb(:,1));
  542. yy=get(gca,'ylim');
  543. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  544. set(gca,'ylim',[0 yy(2)+100],'TickDir','out');
  545. title('Ecc Diff')
  546. fprintf(['MEDIAN ECC DIFF: ' num2str(MM) '\n'])
  547. bbecc=bb;
  548. subplot(2,3,5); hold on;
  549. bb = [lin_n.rfs(vox_sel) lin.rfs(vox_sel)];
  550. plot([1 2],mean(bb),'o','Linewidth',2)
  551. errorbar([1 2],mean(bb),std(bb),'k','Linewidth',2)
  552. plot([1 2],mean(bb),'o','MarkerSize',10,'MarkerFaceColor','k','MarkerEdgeColor','k')
  553. set(gca,'xtick',1:2,'xticklabels',{'LIN-N','LIN'},...
  554. 'ylim',[0 5.1],'xlim',[0.8 2.2],'TickDir','out')
  555. ylabel('Size');
  556. title('Size')
  557. subplot(2,3,6); hold on;
  558. histogram(lin.rfs(vox_sel)-lin_n.rfs(vox_sel),-10:0.25:10,...
  559. 'FaceColor','k','FaceAlpha',0.5);
  560. xlabel('Size Diff (POS-POSNEG)');ylabel('nvoxels');
  561. MM=median(bb(:,2)-bb(:,1));
  562. yy=get(gca,'ylim');
  563. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  564. set(gca,'ylim',[0 yy(2)+110]);
  565. set(gca,'xlim',[-5.1 5.1],'TickDir','out');
  566. title('Size Diff')
  567. fprintf(['MEDIAN SZ DIFF: ' num2str(MM) '\n'])
  568. bbsz=bb;
  569. sgtitle('pRFs POS LINEAR vs POSNEG LINEAR model')
  570. if SaveFigs
  571. saveas(f_neg2,fullfile(pngfld, 'MRI_NEG-PRF2.png'));
  572. saveas(f_neg2,fullfile(svgfld, 'MRI_NEG-PRF2.svg'));
  573. end
  574. if CloseFigs; close(f_neg2); end
  575. % Wilcoxon 1-tailed < 0
  576. [p,h,stats] = signrank(bbecc(:,1),bbecc(:,2));
  577. fprintf(['Wilcoxon z = ' ...
  578. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  579. %% DoG Fits: Characterize =================================================
  580. f_neg3 = figure;
  581. set(f_neg3,'Position',[10 10 1300 1100]);
  582. vox_sel = DoG.R2>R2th & DoG.R2>lin.R2+R2enh;
  583. subplot(1,3,1); hold on;
  584. histogram(DoG.normamp(vox_sel),-10:0.1:10,'FaceColor','k','FaceAlpha',0.5);
  585. xlabel('INH nAMP');ylabel('nvoxels');
  586. set(gca,'xlim',[-0.2 3.1]);
  587. MM=median(DoG.normamp(vox_sel));
  588. yy=get(gca,'ylim');
  589. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  590. set(gca,'ylim',[0 yy(2)+30],'TickDir','out');
  591. title('NORMAMP')
  592. fprintf(['MEDIAN NAMP: ' num2str(MM) '\n'])
  593. % Wilcoxon 1-tailed > 1
  594. [p,h,stats] = signrank(DoG.normamp(vox_sel),1,'tail','right');
  595. fprintf(['nAmp > 1: Wilcoxon z = ' ...
  596. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  597. fprintf(['Median nAMP: ' num2str(median(DoG.normamp(vox_sel))) ', IQR: '...
  598. num2str(iqr(DoG.normamp(vox_sel))) '\n'])
  599. subplot(1,3,2); hold on;
  600. bb = [DoG.ecc(vox_sel) lin.ecc(vox_sel)];
  601. bbecc=bb;
  602. plot([1 2],mean(bb),'o','Linewidth',2)
  603. errorbar([1 2],mean(bb),std(bb),'k','Linewidth',2)
  604. plot([1 2],mean(bb),'o','MarkerSize',10,'MarkerFaceColor','k','MarkerEdgeColor','k')
  605. set(gca,'xtick',1:2,'xticklabels',{'DoG','LIN'},...
  606. 'ylim',[0 20],'xlim',[0.8 2.2],'TickDir','out')
  607. ylabel('Eccentricity');
  608. title('Ecc Diff')
  609. subplot(1,3,3); hold on;
  610. histogram(lin.ecc(vox_sel)-DoG.ecc(vox_sel),-10:0.5:10,...
  611. 'FaceColor','k','FaceAlpha',0.5);
  612. xlabel('Ecc. Diff (POS-DoG)');ylabel('nvoxels');
  613. MM=median(bb(:,2)-bb(:,1));
  614. yy=get(gca,'ylim');
  615. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  616. set(gca,'ylim',[0 yy(2)+110],'TickDir','out');
  617. title('Ecc Diff')
  618. fprintf(['MEDIAN ECC DIFF: ' num2str(MM) '\n'])
  619. sgtitle('pRFs POS LINEAR vs DoG model')
  620. if SaveFigs
  621. saveas(f_neg3,fullfile(pngfld, 'MRI_NEG-PRF3.png'));
  622. saveas(f_neg3,fullfile(svgfld, 'MRI_NEG-PRF3.svg'));
  623. end
  624. if CloseFigs; close(f_neg3); end
  625. % Wilcoxon 1-tailed < 1
  626. [p,h,stats] = signrank(bbecc(:,1),bbecc(:,2));
  627. fprintf(['Wilcoxon z = ' ...
  628. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  629. %% Value of exponential parameter for CSS across ROIs =====================
  630. RTHRES = 5;
  631. fexp = figure;
  632. set(fexp,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  633. set(fexp,'Position',[10 10 1600 300]);
  634. hold on;
  635. for s = 1:length(SUBS)
  636. fprintf(['SUB: ' SUBS{s} '\n'])
  637. exptv(s).roi={};
  638. for r=1:length(roi)
  639. exptvals = T(modidx.csshrf_cv1_mhrf).mod.expt(...
  640. T(modidx.csshrf_cv1_mhrf).mod.R2 > RTHRES & ...
  641. strcmp(T(modidx.csshrf_cv1_mhrf).mod.Monkey,cSUBS(s)) & ...
  642. ismember(T(modidx.csshrf_cv1_mhrf).mod.ROI,...
  643. ck_GetROIidx(roilabels(r),rois) ) );
  644. exptv(s).roi{r}=exptvals;
  645. end
  646. end
  647. all_expt=[];
  648. for xval=1:length(roi)
  649. if size([exptv(1).roi{xval};exptv(2).roi{xval}],1) > 4
  650. bar(xval,mean([exptv(1).roi{xval};exptv(2).roi{xval}]));
  651. all_expt = [all_expt; exptv(1).roi{xval}; exptv(2).roi{xval}];
  652. else
  653. bar(xval,0);
  654. all_expt = [all_expt; exptv(1).roi{xval}; exptv(2).roi{xval}];
  655. end
  656. end
  657. for xval=1:length(roi)
  658. if size([exptv(1).roi{xval};exptv(2).roi{xval}],1) > 4
  659. errorbar(xval,...
  660. mean([exptv(1).roi{xval};exptv(2).roi{xval}]),...
  661. std([exptv(1).roi{xval};exptv(2).roi{xval}]),...
  662. 'k','Linestyle','none');
  663. % errorbar(xval,...
  664. % mean([exptv(1).roi{xval};exptv(2).roi{xval}]),...
  665. % std([exptv(1).roi{xval};exptv(2).roi{xval}])./...
  666. % sqrt(length([exptv(1).roi{xval};exptv(2).roi{xval}])),...
  667. % 'k','Linestyle','none');
  668. end
  669. end
  670. title(['Avg EXPT parameter, R2 > ' ...
  671. num2str(RTHRES)],'interpreter','none');
  672. ylabel('EXPT PM','interpreter','none');
  673. set(gca,'xtick',1:length(roi),'xticklabels',roilabels,'TickDir','out');
  674. xtickangle(45)
  675. if SaveFigs
  676. saveas(fexp,fullfile(pngfld, 'MRI_CSS_EXPT-PM_ROI.png'));
  677. saveas(fexp,fullfile(svgfld, 'MRI_CSS_EXPT-PM_ROI.svg'));
  678. end
  679. if CloseFigs; close(fexp); end
  680. % Wilcoxon 1-tailed < 1
  681. [p,h,stats] = signrank(all_expt,1,'tail','left');
  682. fprintf(['ALL VOXELS - Wilcoxon EXPT < 1 : z = ' ...
  683. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  684. fprintf('\n------\nSTATS\n------\n')
  685. for xval=1:length(roi)
  686. if size([exptv(1).roi{xval};exptv(2).roi{xval}],1) > 4
  687. [p,h,stats] = signrank([exptv(1).roi{xval};exptv(2).roi{xval}],1,'tail','left');
  688. if isfield(stats,'zval')
  689. fprintf([roilabels{xval} ' VOXELS - Wilcoxon EXPT < 1 : z = ' ...
  690. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  691. end
  692. else
  693. fprintf([roilabels{xval} ': Not enough values for statistics\n'])
  694. end
  695. end
  696. %% SFig 13: MRI scatter plot HRF & differences ============================
  697. RTHRES = 0;
  698. f3a=figure;
  699. set(f3a,'Position',[100 100 1500 400]);
  700. set(f3a,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  701. s_R2 = T(modidx.linhrf_cv1_mhrf).mod.R2>RTHRES;
  702. f3b=figure;
  703. set(f3b,'Position',[100 100 1300 1200]);
  704. set(f3b,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  705. s_R2 = T(modidx.linhrf_cv1_mhrf).mod.R2>RTHRES;
  706. for mm = 1:size(MRI_MODELS,1)
  707. figure(f3a)
  708. subplot(1,4,mm); hold on;
  709. XY=[];
  710. for r=1:length(roi)
  711. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  712. ck_GetROIidx(roilabels(r),rois) );
  713. % scatter(T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS),...
  714. % T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS),100,'Marker','.');
  715. XY=[XY; T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS) ...
  716. T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS)];
  717. end
  718. binscatter(XY(:,1),XY(:,2),100); colorbar;
  719. set(gca,'ColorScale','log');
  720. colormap(inferno)
  721. caxis([1 1e4])
  722. plot([-2 100],[-2 100],'k','Linewidth',1);
  723. title(['mHRF vs cHRF (' MRI_MODELS{mm,1} ')'],'interpreter','none');
  724. xlabel('Monkey HRF R2'); ylabel('Canonical HRF R2');
  725. set(gca, 'Box','off', 'xlim', [-2 100], 'ylim',[-2 100]);
  726. diffmat2{1}=[]; dH=[];
  727. for r=1:length(roi)
  728. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  729. ck_GetROIidx(roilabels(r),rois) );
  730. [n,x] = hist(...
  731. T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS)-...
  732. T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS),100);
  733. f = n./sum(SSS);
  734. m = mean(T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS)-...
  735. T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS));
  736. sd = std(T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS)-...
  737. T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS));
  738. nvox = sum(SSS);
  739. se = sd ./ sqrt(nvox);
  740. diffmat2{1} = [diffmat2{1}; m sd se nvox];
  741. dH=[dH;...
  742. T(modidx.(MRI_MODELS{mm,1})).mod.R2(SSS) - ...
  743. T(modidx.(MRI_MODELS{mm,2})).mod.R2(SSS) ];
  744. end
  745. figure(f3b)
  746. subplot(4,1,mm); hold on
  747. for xval=1:length(diffmat2{1})
  748. bar(xval,diffmat2{1}(xval,1));
  749. end
  750. for xval=1:length(diffmat2{1})
  751. errorbar(xval,diffmat2{1}(xval,1),diffmat2{1}(xval,3),...
  752. 'k-','Linestyle','none')
  753. end
  754. % mean (weighted mean taking nvox into account)
  755. mAll = sum((diffmat2{1}(:,1).*diffmat2{1}(:,4)))./...
  756. sum(diffmat2{1}(:,4));
  757. mAll = mean(dH);
  758. stdAll = std(dH);
  759. % Wilcoxon 1-tailed < 1
  760. [p,h,stats] = signrank(dH,0);
  761. fprintf(['ALL VOXELS - Wilcoxon dHRF (' MRI_MODELS{mm,1} ') < 1 : z = ' ...
  762. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  763. text(0.5, -1.2,[num2str(mAll) ' +/- ' num2str(stdAll)])
  764. set(gca,'xticklabels',[],'ylim',[-1.6 1.6],'TickDir','out');
  765. %xlabel('ROI');
  766. ylabel('Diff R2');
  767. title(['mHRF - cHRF (' MRI_MODELS{mm,1} ')'],'interpreter','none');
  768. %legend(roilabels,'interpreter','none','Location','NorthEast');
  769. set(gca,'xtick',1:length(diffmat2{1}),'xticklabels',roilabels);
  770. xtickangle(45)
  771. end
  772. if SaveFigs
  773. saveas(f3a,fullfile(pngfld, 'HRF_Comparison.png'));
  774. saveas(f3a,fullfile(svgfld, 'HRF_Comparison.svg'));
  775. saveas(f3b,fullfile(pngfld, 'HRF_Comparison_binned.png'));
  776. saveas(f3b,fullfile(svgfld, 'HRF_Comparison_binned.svg'));
  777. end
  778. if CloseFigs; close(f3a); close(f3b); close all; end
  779. %% MRI rf size depending on HRF ===========================================
  780. R2th=5;
  781. s_R2 = T(modidx.csshrf_cv1_mhrf).mod.R2 > R2th;
  782. for mm = 1:size(MRI_MODELS,1)
  783. xy_sz{mm}=[]; xy_ecc{mm}=[];
  784. for r=1:length(roi)
  785. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  786. ck_GetROIidx(roilabels(r),rois) );
  787. xy_sz{mm} = [xy_sz{mm};...
  788. T(modidx.(MRI_MODELS{mm,1})).mod.rfs(SSS) ...
  789. T(modidx.(MRI_MODELS{mm,2})).mod.rfs(SSS)];
  790. xy_ecc{mm} = [xy_ecc{mm};...
  791. T(modidx.(MRI_MODELS{mm,1})).mod.ecc(SSS) ...
  792. T(modidx.(MRI_MODELS{mm,2})).mod.ecc(SSS)];
  793. end
  794. xy_sz{mm}( isinf(xy_sz{mm}) ) = nan;
  795. xy_ecc{mm}( isinf(xy_ecc{mm}) ) = nan;
  796. % Wilcoxon
  797. fprintf(['--' MMS{mm,1} '--\n'])
  798. [p,h,stats] = signrank(xy_sz{mm}(:,1),xy_sz{mm}(:,2),'method','approximate');
  799. fprintf(['ALL VOXELS R2>TH - Wilcoxon HRF sz: z = ' ...
  800. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  801. fprintf(['Mean:' num2str(nanmean(diff(xy_sz{mm},1,2))) ', std ' ...
  802. num2str(nanstd(diff(xy_sz{mm},1,2))) '\n'])
  803. [p,h,stats] = signrank(xy_ecc{mm}(:,1),xy_ecc{mm}(:,2),'method','approximate');
  804. fprintf(['ALL VOXELS R2>TH - Wilcoxon HRF ecc: z = ' ...
  805. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  806. fprintf(['Mean:' num2str(nanmean(diff(xy_ecc{mm},1,2))) ', std ' ...
  807. num2str(nanstd(diff(xy_ecc{mm},1,2))) '\n'])
  808. diffmat2{1}=[];
  809. for r=1:length(roi)
  810. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{rowmod,1})).mod.ROI,...
  811. ck_GetROIidx(roilabels(r),rois) );
  812. [n,x] = hist(...
  813. T(modidx.(MRI_MODELS{mm,1})).mod.rfs(SSS) - ...
  814. T(modidx.(MRI_MODELS{mm,2})).mod.rfs(SSS), 100);
  815. f = n./sum(SSS);
  816. dsz = T(modidx.(MRI_MODELS{mm,1})).mod.rfs - ...
  817. T(modidx.(MRI_MODELS{mm,2})).mod.rfs;
  818. dsz = dsz(SSS);
  819. dsz = dsz(isfinite(dsz));
  820. m = mean(dsz);
  821. sd = std(dsz);
  822. se = sd ./ sqrt(length(dsz));
  823. diffmat2{1} = [diffmat2{1}; m sd se size(dsz,1)];
  824. end
  825. end
  826. %% MRI ECC vs PRF Size ====================================================
  827. Rth=5;
  828. f5=figure;
  829. set(f5,'Position',[100 100 800 1200]);
  830. set(f5,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  831. for m=1:length(MRI_MODELS)-1
  832. s_R2 = T(modidx.(MRI_MODELS{m,1})).mod.R2 > Rth;
  833. EccBin = 0.5:1:16.5;
  834. subplot(3,2,(m-1)*2 +1);hold on;
  835. for r=1:length(roi)
  836. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  837. ck_GetROIidx(roilabels(r),rois) );
  838. ES{r}=[];
  839. scatter(T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS),...
  840. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS),100,'Marker','.');
  841. for b=1:length(EccBin)
  842. bb=[EccBin(b)-0.5 EccBin(b)+0.5];
  843. PSZ=T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS);
  844. ECC=T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS);
  845. ES{r}=[ES{r}; EccBin(b) median(PSZ(ECC>=bb(1) & ECC<=bb(2)))];
  846. end
  847. end
  848. title(['Ecc vs pRF size [' MMS{m} ', R>' num2str(Rth) ']'],...
  849. 'interpreter','none');
  850. xlabel('Eccentricity');ylabel('pRF size');
  851. set(gca, 'Box','off', 'xlim', [0 10], 'ylim',[0 10]);
  852. subplot(3,2,(m-1)*2 +2);hold on;
  853. for r=1:length(roi)
  854. h=plot(ES{r}(:,1),ES{r}(:,2),'o');
  855. set(h,'MarkerSize',6,'markerfacecolor', get(h, 'color'));
  856. end
  857. title(['Ecc vs pRF size [' MMS{m} ', R>' num2str(Rth) ']'],...
  858. 'interpreter','none'); xlabel('Eccentricity');ylabel('pRF size');
  859. set(gca, 'Box','off', 'xlim', [0 10], 'ylim',[0 10]);
  860. end
  861. if SaveFigs
  862. saveas(f5,fullfile(pngfld, 'MRI_Ecc_vs_Size.png'));
  863. saveas(f5,fullfile(svgfld, 'MRI_Ecc_vs_Size.svg'));
  864. end
  865. if CloseFigs; close(f5); end
  866. %% Fig 5 & SFig 5: Ecc-Sz for CSS per area including CI ===================
  867. SaveFigs=false;
  868. for Rth=[5 3]
  869. clear tbl lm;
  870. max_ecc = 100;
  871. bins=[0:18; 2:20]';
  872. f5css=figure;
  873. set(f5css,'Position',[100 100 2000 1500]);
  874. set(f5css,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  875. sgtitle(['Voxels & fit, R>' num2str(Rth)])
  876. m=3; % css
  877. s_R2 = T(modidx.(MRI_MODELS{m,1})).mod.R2 > Rth & ...
  878. T(modidx.(MRI_MODELS{m,1})).mod.ecc < max_ecc;
  879. nsp=length(roi);
  880. nrc=ceil(sqrt(nsp));
  881. nvox_roi = []; binned_data=[];
  882. for r=1:length(roi)
  883. ES{r} = []; ES_m{r} = [];
  884. ESb{r} = []; ESf{r} = [];
  885. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  886. ck_GetROIidx(roilabels(r),rois) );
  887. s_Monkey = strcmp(T(modidx.(MRI_MODELS{m,1})).mod.Monkey,'M01');
  888. SSS_m1 = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  889. ck_GetROIidx(roilabels(r),rois)) & s_Monkey;
  890. s_Monkey = strcmp(T(modidx.(MRI_MODELS{m,1})).mod.Monkey,'M02');
  891. SSS_m2 = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  892. ck_GetROIidx(roilabels(r),rois)) & s_Monkey;
  893. nvox_roi = [nvox_roi; sum(SSS_m1) sum(SSS_m2)];
  894. roi_n{r,1} = rois{r};
  895. roi_n{r,2} = sum(SSS_m1);
  896. roi_n{r,3} = sum(SSS_m2);
  897. ES{r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS) ...
  898. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS) ];
  899. ES{r}( ES{r}(:,2) > 50,: ) = []; % remove insanely large pRF's
  900. ES_m{1,r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS_m1) ...
  901. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS_m1) ];
  902. ES_m{2,r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS_m2) ...
  903. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS_m2) ];
  904. %subplot(nrc,nrc,r); hold on;
  905. subplot(5,8,r); hold on;
  906. scatter(ES_m{1,r}(:,1),ES_m{1,r}(:,2),10,'Marker','o',...
  907. 'MarkerFaceColor','b','MarkerFaceAlpha',.2,...
  908. 'MarkerEdgeColor','none');
  909. scatter(ES_m{2,r}(:,1),ES_m{2,r}(:,2),10,'Marker','o',...
  910. 'MarkerFaceColor','k','MarkerFaceAlpha',.2,...
  911. 'MarkerEdgeColor','none');
  912. % make table
  913. tbl = table(ES{r}(:,1),ES{r}(:,2),'VariableNames',{'ecc','sz'});
  914. if ~isempty(tbl)
  915. % remove inf's
  916. tbl(isinf(tbl.sz),:)=[];
  917. % fit
  918. lm{r} = fitlm(tbl,'sz ~ 1 + ecc');
  919. % CI
  920. lmCI{r}=coefCI(lm{r},0.05);
  921. if ~isnan(lm{r}.Coefficients.pValue(1))
  922. % Prediction
  923. x=[0;20];
  924. [ypred,yci] = predict(lm{r},x);
  925. yci2=yci(:,2)-ypred;
  926. if lm{r}.Coefficients.pValue(2) < 0.05
  927. boundedline(x,ypred',yci2,'r','alpha')
  928. else
  929. boundedline(x,ypred',yci2,'k','alpha')
  930. end
  931. %fprintf([roilabels{r} ' n = ' num2str(size(tbl,1)) '\n'])
  932. %fprintf([roilabels{r} ' p = ' num2str(lm{r}.Coefficients.pValue(2)) '\n'])
  933. fprintf([roilabels{r} ' slope = ' num2str(lm{r}.Coefficients.Estimate(2)) '\n'])
  934. end
  935. % binned
  936. for b=1:size(bins,1)
  937. seldata = (tbl.ecc>bins(b,1) & tbl.ecc<=bins(b,2)) ;
  938. if sum(seldata)>1
  939. binned_data=[binned_data;...
  940. r b mean(tbl.sz(seldata)) std(tbl.sz(seldata))./sqrt(sum(seldata))];
  941. end
  942. end
  943. end
  944. title(['Ecc vs pRF size [' roilabels{r} ', R>' num2str(Rth) ']'],...
  945. 'interpreter','none');
  946. title(roilabels{r});
  947. xlabel('Eccentricity');ylabel('pRF size');
  948. set(gca, 'Box','off', 'xlim', [0 20], 'ylim',[0 25]);
  949. end
  950. % binned
  951. f5css_binned=figure;
  952. set(f5css_binned,'Position',[100 100 2000 1500]);
  953. set(f5css_binned,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  954. sgtitle(['Binned & voxel-based fit, R>' num2str(Rth)])
  955. for r=1:length(roi)
  956. subplot(5,8,r); hold on;
  957. errorbar(...
  958. binned_data(binned_data(:,1)==r,2),...
  959. binned_data(binned_data(:,1)==r,3),...
  960. binned_data(binned_data(:,1)==r,4),...
  961. 'LineStyle','none','Marker','o','MarkerSize',6,...
  962. 'Color','k','MarkerFaceColor',[.3 .3 .3]);
  963. plot([8 8],[0 25],'k--')
  964. if ~isempty(lm{r}) && ~isnan(lm{r}.Coefficients.pValue(1))
  965. x=[0;20];
  966. [ypred,yci] = predict(lm{r},x);
  967. yci2=yci(:,2)-ypred;
  968. if lm{r}.Coefficients.pValue(2) < 0.05
  969. boundedline(x,ypred',yci2,'r','alpha')
  970. else
  971. boundedline(x,ypred',yci2,'k','alpha')
  972. end
  973. end
  974. title([roilabels{r} ', R>' num2str(Rth) ', nVox [' ...
  975. num2str(roi_n{r,2}) ' ' num2str(roi_n{r,3}) ']'],...
  976. 'interpreter','none');
  977. %title(roilabels{r});
  978. xlabel('Ecc (dva)');ylabel('Sz (dva)');
  979. set(gca, 'Box','off', 'xlim', [0 20], 'ylim',[0 25]);
  980. end
  981. if SaveFigs
  982. saveas(f5css,fullfile(pngfld, ['MRI_Ecc_vs_Size_R' num2str(Rth) '.png']));
  983. saveas(f5css,fullfile(svgfld, ['MRI_Ecc_vs_Size_R' num2str(Rth) '.svg']));
  984. saveas(f5css_binned,fullfile(pngfld, ['MRI_Ecc_vs_Size_binned_R' num2str(Rth) '.png']));
  985. saveas(f5css_binned,fullfile(svgfld, ['MRI_Ecc_vs_Size_binned_R' num2str(Rth) '.svg']));
  986. end
  987. if CloseFigs; close(f5css_R5); close(f5css_binned_R5); end
  988. % Select areas with data in both monkeys =================================
  989. if false
  990. minVox_both=25;
  991. % which ROIs have a minimum number of voxels in both animals?
  992. s_roi = mean(nvox_roi>=minVox_both,2)==1;
  993. fprintf(['ROIs with more than ' num2str(minVox_both) ' sign. voxels in BOTH:\n'])
  994. rois(s_roi,1)
  995. minVox_s1=minVox_both;
  996. s1_roi = nvox_roi(:,1)>minVox_s1;
  997. fprintf(['ROIs with more than ' num2str(minVox_s1) ' sign. voxels in S1:\n'])
  998. rois(s1_roi,1)
  999. minVox_s2=minVox_both;
  1000. s2_roi = nvox_roi(:,2)>minVox_s2;
  1001. fprintf(['ROIs with more than ' num2str(minVox_s2) ' sign. voxels in S2:\n'])
  1002. rois(s2_roi,1)
  1003. figure; hold on;
  1004. lidx=1; clear L
  1005. for idx=find(s_roi==1)'
  1006. x=[0;20];
  1007. [ypred,yci] = predict(lm{idx},x);
  1008. yci2=yci(:,2)-ypred;
  1009. plot(x,ypred','LineWidth',3)
  1010. L{lidx}=roilabels{idx};
  1011. lidx=lidx+1;
  1012. end
  1013. legend(L)
  1014. end
  1015. % NEW Fig 5: Ecc-Sz for CSS, selected ROIs ===============================
  1016. A_idx = [1:5 8:9];
  1017. B_idx = [10:13 23 25:26];
  1018. C_idx = [19 18 20];
  1019. D_idx = [29:31 33 37:38];
  1020. % precreate color matrices for plotting
  1021. A_cols = brewermap(length(A_idx),def_cmap);
  1022. B_cols = brewermap(length(B_idx),def_cmap);
  1023. C_cols = brewermap(length(C_idx),def_cmap);
  1024. D_cols = brewermap(length(D_idx),def_cmap);
  1025. f_eccsz = figure;
  1026. set(f_eccsz,'Position',[100 100 2400 2000]);
  1027. sgtitle(['Ecc vs Sz, R>' num2str(Rth)])
  1028. subplot(2,2,1); hold on;
  1029. lidx=1; clear L
  1030. for r=A_idx
  1031. errorbar(...
  1032. binned_data(binned_data(:,1)==r,2),...
  1033. binned_data(binned_data(:,1)==r,3),...
  1034. binned_data(binned_data(:,1)==r,4),...
  1035. 'LineStyle','none','Marker','o','MarkerSize',6,...
  1036. 'Color',A_cols(lidx,:),'MarkerFaceColor',A_cols(lidx,:));
  1037. lidx=lidx+1;
  1038. end
  1039. lidx=1;
  1040. for r=A_idx
  1041. x=[0;20];
  1042. [ypred,yci] = predict(lm{r},x);
  1043. yci2=yci(:,2)-ypred;
  1044. %boundedline(x,ypred',yci2,'cmap',A_cols(lidx,:),'alpha')
  1045. plot(x,ypred','-','LineWidth',2,'Color',A_cols(lidx,:))
  1046. L{lidx}=roilabels{r};
  1047. lidx=lidx+1;
  1048. end
  1049. legend(L,'Location','NorthWest')
  1050. plot([8 8],[0 25],'k--')
  1051. set(gca,'ylim',[0 15], 'TickDir','out');
  1052. subplot(2,2,2); hold on;
  1053. lidx=1; clear L
  1054. for r=B_idx
  1055. errorbar(...
  1056. binned_data(binned_data(:,1)==r,2),...
  1057. binned_data(binned_data(:,1)==r,3),...
  1058. binned_data(binned_data(:,1)==r,4),...
  1059. 'LineStyle','none','Marker','o','MarkerSize',6,...
  1060. 'Color',B_cols(lidx,:),'MarkerFaceColor',B_cols(lidx,:));
  1061. lidx=lidx+1;
  1062. end
  1063. lidx=1;
  1064. for r=B_idx
  1065. x=[0;20];
  1066. [ypred,yci] = predict(lm{r},x);
  1067. yci2=yci(:,2)-ypred;
  1068. %boundedline(x,ypred',yci2,'cmap',B_cols(lidx,:),'alpha')
  1069. plot(x,ypred','-','LineWidth',2,'Color',B_cols(lidx,:))
  1070. L{lidx}=roilabels{r};
  1071. lidx=lidx+1;
  1072. end
  1073. legend(L,'Location','NorthWest')
  1074. plot([8 8],[0 25],'k--')
  1075. set(gca,'ylim',[0 20], 'TickDir','out');
  1076. C_idx = [19 18 20];
  1077. D_idx = [29:31 33 37 38];
  1078. subplot(2,2,3); hold on;
  1079. lidx=1; clear L
  1080. for r=C_idx
  1081. errorbar(...
  1082. binned_data(binned_data(:,1)==r,2),...
  1083. binned_data(binned_data(:,1)==r,3),...
  1084. binned_data(binned_data(:,1)==r,4),...
  1085. 'LineStyle','none','Marker','o','MarkerSize',6,...
  1086. 'Color',C_cols(lidx,:),'MarkerFaceColor',C_cols(lidx,:));
  1087. lidx=lidx+1;
  1088. end
  1089. lidx=1;
  1090. for r=C_idx
  1091. x=[0;20];
  1092. [ypred,yci] = predict(lm{r},x);
  1093. yci2=yci(:,2)-ypred;
  1094. %boundedline(x,ypred',yci2,'cmap',C_cols(lidx,:),'alpha')
  1095. plot(x,ypred','-','LineWidth',2,'Color',C_cols(lidx,:))
  1096. L{lidx}=roilabels{r};
  1097. lidx=lidx+1;
  1098. end
  1099. legend(L,'Location','NorthWest')
  1100. plot([8 8],[0 25],'k--')
  1101. set(gca,'ylim',[0 20], 'TickDir','out');
  1102. subplot(2,2,4); hold on;
  1103. lidx=1; clear L
  1104. for r=D_idx
  1105. errorbar(...
  1106. binned_data(binned_data(:,1)==r,2),...
  1107. binned_data(binned_data(:,1)==r,3),...
  1108. binned_data(binned_data(:,1)==r,4),...
  1109. 'LineStyle','none','Marker','o','MarkerSize',6,...
  1110. 'Color',D_cols(lidx,:),'MarkerFaceColor',D_cols(lidx,:));
  1111. lidx=lidx+1;
  1112. end
  1113. lidx=1;
  1114. for r=D_idx
  1115. x=[0;20];
  1116. [ypred,yci] = predict(lm{r},x);
  1117. yci2=yci(:,2)-ypred;
  1118. %boundedline(x,ypred',yci2,'cmap',D_cols(lidx,:),'alpha')
  1119. plot(x,ypred','-','LineWidth',2,'Color',D_cols(lidx,:))
  1120. L{lidx}=roilabels{r};
  1121. lidx=lidx+1;
  1122. end
  1123. legend(L,'Location','NorthWest')
  1124. plot([8 8],[0 25],'k--')
  1125. set(gca,'ylim',[0 20], 'TickDir','out');
  1126. if SaveFigs
  1127. saveas(f_eccsz,fullfile(pngfld, ['MRI_Ecc_vs_Size_ROIs_R' num2str(Rth) '.png']));
  1128. saveas(f_eccsz,fullfile(svgfld, ['MRI_Ecc_vs_Size_ROIs_R' num2str(Rth) '.svg']));
  1129. end
  1130. if CloseFigs; close(f_eccsz); end
  1131. end
  1132. %% SFig 5A/B: Ecc-Sz per area including CI and binned data with SEM =======
  1133. reroi = [19 18 20 1:5 7:14 21:38];
  1134. for Rth=[5 3]
  1135. clear tbl lm;
  1136. bins=[0:18; 2:20]';
  1137. sf5css=figure;
  1138. set(sf5css,'Position',[100 100 1600 1200]);
  1139. set(sf5css,'DefaultAxesColorOrder',brewermap(length(roi),def_cmap));
  1140. sgtitle(['R>' num2str(Rth)])
  1141. m=3; % css
  1142. s_R2 = T(modidx.(MRI_MODELS{m,1})).mod.R2 > Rth;
  1143. nsp=length(reroi);
  1144. nvox_roi = []; binned_data=[];
  1145. for r=1:length(reroi)
  1146. rr=reroi(r);
  1147. ES2{r} = []; ES2_m{r} = [];
  1148. ES2b{r} = []; ES2f{r} = [];
  1149. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  1150. ck_GetROIidx(roilabels(rr),rois) );
  1151. s_Monkey = strcmp(T(modidx.(MRI_MODELS{m,1})).mod.Monkey,'M01');
  1152. SSS_m1 = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  1153. ck_GetROIidx(roilabels(rr),rois)) & s_Monkey;
  1154. s_Monkey = strcmp(T(modidx.(MRI_MODELS{m,1})).mod.Monkey,'M02');
  1155. SSS_m2 = s_R2 & ismember( T(modidx.(MRI_MODELS{m,1})).mod.ROI,...
  1156. ck_GetROIidx(roilabels(rr),rois)) & s_Monkey;
  1157. nvox_roi = [nvox_roi; sum(SSS_m1) sum(SSS_m2)];
  1158. roi_n{r,1} = rois{rr};
  1159. roi_n{r,2} = sum(SSS_m1);
  1160. roi_n{r,3} = sum(SSS_m2);
  1161. ES2{r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS) ...
  1162. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS) ];
  1163. ES2{r}( ES2{r}(:,2) > 50,: ) = []; % remove insanely large pRF's
  1164. ES2_m{1,r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS_m1) ...
  1165. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS_m1) ];
  1166. ES2_m{2,r}=[T(modidx.(MRI_MODELS{m,1})).mod.ecc(SSS_m2) ...
  1167. T(modidx.(MRI_MODELS{m,1})).mod.rfs(SSS_m2) ];
  1168. subplot(5,7,r); hold on;
  1169. scatter(ES2_m{1,r}(:,1),ES2_m{1,r}(:,2),20,'Marker','o',...
  1170. 'MarkerFaceColor','b','MarkerFaceAlpha',.2,...
  1171. 'MarkerEdgeColor','none');
  1172. scatter(ES2_m{2,r}(:,1),ES2_m{2,r}(:,2),20,'Marker','o',...
  1173. 'MarkerFaceColor','k','MarkerFaceAlpha',.2,...
  1174. 'MarkerEdgeColor','none');
  1175. % make table
  1176. tbl2 = table(ES2{r}(:,1),ES2{r}(:,2),'VariableNames',{'ecc','sz'});
  1177. if ~isempty(tbl2)
  1178. % remove inf's
  1179. tbl2(isinf(tbl2.sz),:)=[];
  1180. % fit
  1181. lm2{r} = fitlm(tbl2,'sz ~ 1 + ecc');
  1182. % CI
  1183. lmCI2{r}=coefCI(lm2{r},0.05);
  1184. if ~isnan(lm2{r}.Coefficients.pValue(1))
  1185. % Prediction
  1186. x=[0;20];
  1187. [ypred,yci] = predict(lm2{r},x);
  1188. yci2=yci(:,2)-ypred;
  1189. if lm2{r}.Coefficients.pValue(2) < 0.05
  1190. boundedline(x,ypred',yci2,'r','alpha')
  1191. else
  1192. boundedline(x,ypred',yci2,'k','alpha')
  1193. end
  1194. fprintf([roilabels{rr} ' n = ' num2str(size(tbl2,1)) '\n'])
  1195. fprintf([roilabels{rr} ' p = ' num2str(lm2{r}.Coefficients.pValue(2)) '\n'])
  1196. fprintf([roilabels{rr} ' slope = ' num2str(lm2{r}.Coefficients.Estimate(2)) '\n'])
  1197. end
  1198. % binned
  1199. for b=1:size(bins,1)
  1200. seldata = (tbl2.ecc>bins(b,1) & tbl2.ecc<=bins(b,2)) ;
  1201. if sum(seldata)>1
  1202. binned_data=[binned_data;...
  1203. rr b mean(tbl2.sz(seldata)) std(tbl2.sz(seldata))./sqrt(sum(seldata))];
  1204. end
  1205. end
  1206. end
  1207. errorbar(...
  1208. binned_data(binned_data(:,1)==rr,2),...
  1209. binned_data(binned_data(:,1)==rr,3),...
  1210. binned_data(binned_data(:,1)==rr,4),...
  1211. 'LineStyle','none','Marker','o','MarkerSize',6,...
  1212. 'Color','k','MarkerFaceColor',[.8 .8 .8]);
  1213. plot([8 8],[0 25],'k--')
  1214. %xlabel('Eccentricity');ylabel('pRF size');
  1215. set(gca, 'Box','off', 'xlim', [0 20], 'ylim',[0 25],...
  1216. 'FontName','Myriad Pro','FontSize',11,'TitleHorizontalAlignment','left');
  1217. title(['Ecc vs pRF size [' roilabels{rr} ', R>' num2str(Rth) ']'],...
  1218. 'interpreter','none');
  1219. title(roilabels{rr});
  1220. text(2,20,sprintf(['n = [' num2str(roi_n{r,2}) ' ' num2str(roi_n{r,3}) ']\n'...
  1221. 'p = ' num2str(lm2{r}.Coefficients.pValue(2)) '\n'...
  1222. 'slope = ' num2str(lm2{r}.Coefficients.Estimate(2))]));
  1223. end
  1224. if SaveFigs
  1225. saveas(sf5css,fullfile(pngfld, ['SF5_MRI_Ecc_vs_Size_R' num2str(Rth) '.png']));
  1226. saveas(sf5css,fullfile(svgfld, ['SF5_MRI_Ecc_vs_Size_R' num2str(Rth) '.svg']));
  1227. end
  1228. if CloseFigs; close(sf5css); end
  1229. end
  1230. %% ========================================================================
  1231. % EPHYS PRF ANALYSIS -----------------------------------------------------
  1232. % ========================================================================
  1233. %% Fig 9: EPHYS ECC vs PRF Size ===========================================
  1234. Rth=25;
  1235. SNRth=3;
  1236. m=unique(tMUA.Model);
  1237. R2=[];
  1238. for i=2%1:length(m)
  1239. R2 = [R2 tMUA.R2(strcmp(tMUA.Model,m{i}))];
  1240. end
  1241. subs = tMUA.Monkey;
  1242. for i=1:length(subs)
  1243. if strcmp(subs{i},'M03')
  1244. subs{i} = 1;
  1245. elseif strcmp(subs{i},'M04')
  1246. subs{i} = 2;
  1247. end
  1248. end
  1249. subs=cell2mat(subs); names={'M03','M04'};
  1250. mm=unique(tMUA.Model);
  1251. for m=2%1:length(mm)
  1252. % collect
  1253. if ~strcmp(mm{m},'classicRF')
  1254. eccsz = [tMUA.R2(strcmp(tMUA.Model,mm{m})) ...
  1255. tMUA.ecc(strcmp(tMUA.Model,mm{m})) ...
  1256. tMUA.rfs(strcmp(tMUA.Model,mm{m})) ...
  1257. tMUA.Area(strcmp(tMUA.Model,mm{m})) ...
  1258. tMUA.Array(strcmp(tMUA.Model,mm{m})) ...
  1259. subs(strcmp(tMUA.Model,mm{m})) ...
  1260. tMUA.gain(strcmp(tMUA.Model,mm{m})) ...
  1261. ];
  1262. else
  1263. eccsz = [tMUA.SNR(strcmp(tMUA.Model,mm{m})) ...
  1264. tMUA.ecc(strcmp(tMUA.Model,mm{m})) ...
  1265. tMUA.rfs(strcmp(tMUA.Model,mm{m})) ...
  1266. tMUA.Area(strcmp(tMUA.Model,mm{m})) ...
  1267. tMUA.Array(strcmp(tMUA.Model,mm{m})) ...
  1268. subs(strcmp(tMUA.Model,mm{m})) ...
  1269. ];
  1270. end
  1271. f_eccsz_arr = figure;
  1272. set(f_eccsz_arr,'Position',[100 100 1800 600]);
  1273. for ss=1:2
  1274. a=[1 4];
  1275. for aa=1:length(a)
  1276. leg={};
  1277. if strcmp(mm{m},'classicRF')
  1278. sel = eccsz(:,1)>SNRth & eccsz(:,4)==a(aa) & eccsz(:,6)==ss;
  1279. else
  1280. sel = eccsz(:,1)>Rth & eccsz(:,4)==a(aa) & eccsz(:,6)==ss;
  1281. end
  1282. es1=eccsz(sel,:);
  1283. subplot(2,2,(ss-1)*2 + aa);
  1284. hold on;
  1285. arr=unique(es1(:,5));
  1286. for aaa = 1:length(arr)
  1287. if arr(aaa)~=99
  1288. sel2=es1(:,5)==arr(aaa);
  1289. scatter(es1(sel2,2),es1(sel2,3));
  1290. leg=[leg {num2str(arr(aaa))}];
  1291. end
  1292. end
  1293. if a(aa)==1
  1294. set(gca,'xlim',[0 8],'ylim',[0 3]);
  1295. else
  1296. set(gca,'xlim',[0 8],'ylim',[0 5]);
  1297. end
  1298. legend(leg,'Location','NorthEastOutside');
  1299. title([names{ss} ' V' num2str(a(aa))]);
  1300. xlabel('Ecc (dva)'); ylabel('RF-size (sd, dva)')
  1301. end
  1302. end
  1303. sgtitle(['MODEL: ' mm{m} ', R2th: ' num2str(Rth)],...
  1304. 'interpreter','none');
  1305. if SaveFigs
  1306. saveas(f_eccsz_arr,fullfile(svgfld, ...
  1307. ['EPHYS_MUA_Ecc_vs_Size_' mm{m} '.svg']));
  1308. saveas(f_eccsz_arr,fullfile(pngfld, ...
  1309. ['EPHYS_MUA_Ecc_vs_Size_' mm{m} '.png']));
  1310. end
  1311. if CloseFigs; close(f_eccsz_arr); end
  1312. f_eccsz_v1 = figure;
  1313. set(f_eccsz_v1,'Position',[100 100 1600 400]);
  1314. for ss=1:2
  1315. leg={};
  1316. if strcmp(mm{m},'classicRF')
  1317. sel = eccsz(:,1)>SNRth & eccsz(:,4)==1 & eccsz(:,6)==ss;
  1318. else
  1319. sel = eccsz(:,1)>Rth & eccsz(:,4)==1 & eccsz(:,6)==ss;
  1320. end
  1321. es1=eccsz(sel,:);
  1322. subplot(1,2,ss); hold on;
  1323. arr=unique(es1(:,5));
  1324. for aaa = 1:length(arr)
  1325. sel2=es1(:,5)==arr(aaa);
  1326. scat=scatter(es1(sel2,2),es1(sel2,3));
  1327. %if (ss==1 && (arr(aaa)==11 || arr(aaa)==13)) || ...
  1328. % (ss==2 && (arr(aaa)==10 || arr(aaa)==12))
  1329. if (ss==1 && arr(aaa)==11) || ...
  1330. (ss==2 && arr(aaa)==10)
  1331. set(scat,'MarkerFaceColor','r','MarkerEdgeColor','r');
  1332. elseif (ss==1 && arr(aaa)==13) || ...
  1333. (ss==2 && arr(aaa)==12)
  1334. set(scat,'MarkerFaceColor','b','MarkerEdgeColor','b');
  1335. else
  1336. set(scat,'MarkerFaceColor','k','MarkerEdgeColor','k');
  1337. end
  1338. leg=[leg {num2str(arr(aaa))}];
  1339. end
  1340. title([names{ss} ' V1']);
  1341. xlabel('Ecc (dva)'); ylabel('RF-size (sd, dva)')
  1342. set(gca,'xlim',[0 8],'ylim',[0 3]);
  1343. %legend(leg,'Location','NorthEastOutside');
  1344. end
  1345. sgtitle(['MODEL: ' mm{m} ', R2th: ' num2str(Rth)],...
  1346. 'interpreter','none');
  1347. if SaveFigs
  1348. saveas(f_eccsz_v1,fullfile(pngfld, ...
  1349. ['EPHYS_MUA_Ecc_vs_Size_' mm{m} '.png']));
  1350. saveas(f_eccsz_v1,fullfile(svgfld, ...
  1351. ['EPHYS_MUA_Ecc_vs_Size_' mm{m} '.svg']));
  1352. end
  1353. if CloseFigs; close(f_eccsz_v1); end
  1354. end
  1355. %close all;
  1356. %% Fig 6 / SFig 6 EPHYS VFC MUA (scatter and heatmap) =====================
  1357. % scatter MUA =============================================================
  1358. R2TH = 50;
  1359. s=tMUA.R2>R2TH;
  1360. model='css_ephys_cv1';
  1361. fm=figure; set(fm,'Position',[100 100 1400 1000]);
  1362. [cmap,~,~] = brewermap(length(unique(tMUA.Array)),'spectral');
  1363. set(fm,'DefaultAxesColorOrder',cmap);
  1364. msz = 5;
  1365. % M03 V1 ----
  1366. m=strcmp(tMUA.Monkey,'M03') & strcmp(tMUA.Model,model);
  1367. v=tMUA.Area==1;
  1368. subplot(2,2,1);hold on;
  1369. plot([-10 20],[0 0],'k'); plot([0 0],[-30 10],'k');
  1370. lt={'meridian','meridian'};
  1371. nelec=0;
  1372. for r=unique(tMUA.Array)'
  1373. a=tMUA.Array==r;
  1374. currcol = cmap(r,:);
  1375. if sum(s & m & a & v) > 0
  1376. nelec=nelec+sum(s & m & a & v);
  1377. p=plot(tMUA.X(s & m & a & v),...
  1378. tMUA.Y(s & m & a & v),'o','Color',currcol,...
  1379. 'LineStyle','none','LineWidth',1,...
  1380. 'MarkerSize',msz,'MarkerFaceColor',currcol);
  1381. lt=[lt num2str(r)];
  1382. end
  1383. end
  1384. set(gca, 'Box','off', 'xlim', [-1 8], 'ylim',[-6 1]);
  1385. title(['M03 V1 MUA (n = ' num2str(nelec) ')'])
  1386. l=legend(lt); set(l,'Location','NorthEastOutside'); clear lt;
  1387. % M03 V4 ----
  1388. v=tMUA.Area==4;
  1389. subplot(2,2,3);hold on;
  1390. plot([-10 20],[0 0],'k'); plot([0 0],[-30 10],'k');
  1391. lt={'meridian','meridian'};
  1392. nelec=0;
  1393. for r=unique(tMUA.Array)'
  1394. a=tMUA.Array==r;
  1395. currcol = cmap(r,:);
  1396. if sum(s & m & a & v) > 0
  1397. nelec=nelec+sum(s & m & a & v);
  1398. p=plot(tMUA.X(s & m & a & v),...
  1399. tMUA.Y(s & m & a & v),'o','Color',currcol,...
  1400. 'LineStyle','none','LineWidth',1,...
  1401. 'MarkerSize',msz,'MarkerFaceColor',currcol);
  1402. lt=[lt num2str(r)];
  1403. end
  1404. end
  1405. set(gca, 'Box','off', 'xlim', [-1 8], 'ylim',[-6 1]);
  1406. % set(gca, 'Box','off', 'xlim', [-2 25], 'ylim',[-25 2]);
  1407. title(['M03 V4 MUA (n = ' num2str(nelec) ')'])
  1408. l=legend(lt); set(l,'Location','NorthEastOutside'); clear lt;
  1409. % M04 V1 ----
  1410. m=strcmp(tMUA.Monkey,'M04') & strcmp(tMUA.Model,model);
  1411. v=tMUA.Area==1;
  1412. subplot(2,2,2);hold on;
  1413. plot([-10 20],[0 0],'k'); plot([0 0],[-30 10],'k');
  1414. lt={'meridian','meridian'};
  1415. nelec=0;
  1416. for r=unique(tMUA.Array)'
  1417. a=tMUA.Array==r;
  1418. currcol = cmap(r,:);
  1419. if sum(s & m & a & v) > 0
  1420. nelec=nelec+sum(s & m & a & v);
  1421. p=plot(tMUA.X(s & m & a & v),...
  1422. tMUA.Y(s & m & a & v),'o','Color',currcol,...
  1423. 'LineStyle','none','LineWidth',1,...
  1424. 'MarkerSize',msz,'MarkerFaceColor',currcol);
  1425. lt=[lt num2str(r)];
  1426. end
  1427. end
  1428. set(gca, 'Box','off', 'xlim', [-1 8], 'ylim',[-6 1]);
  1429. title(['M04 V1 MUA (n = ' num2str(nelec) ')'])
  1430. l=legend(lt); set(l,'Location','NorthEastOutside'); clear lt;
  1431. % M04 V4 ----
  1432. v=tMUA.Area==4;
  1433. subplot(2,2,4);hold on;
  1434. plot([-10 30],[0 0],'k'); plot([0 0],[-30 10],'k');
  1435. lt={'meridian','meridian'};
  1436. nelec=0;
  1437. for r=unique(tMUA.Array)'
  1438. a=tMUA.Array==r;
  1439. currcol = cmap(r,:);
  1440. if sum(s & m & a & v) > 0
  1441. nelec=nelec+sum(s & m & a & v);
  1442. p=plot(tMUA.X(s & m & a & v),...
  1443. tMUA.Y(s & m & a & v),'o','Color',currcol,...
  1444. 'LineStyle','none','LineWidth',1,...
  1445. 'MarkerSize',msz,'MarkerFaceColor',currcol);
  1446. lt=[lt num2str(r)];
  1447. end
  1448. end
  1449. set(gca, 'Box','off', 'xlim', [-2 25], 'ylim',[-25 2]);
  1450. title(['M04 V4 MUA (n = ' num2str(nelec) ')'])
  1451. l=legend(lt); set(l,'Location','NorthEastOutside'); clear lt;
  1452. if SaveFigs
  1453. saveas(fm,fullfile(pngfld, 'MUA_VFC.png'));
  1454. saveas(fm,fullfile(svgfld, 'MUA_VFC.svg'));
  1455. end
  1456. if CloseFigs; close(fm); end
  1457. % Heatmap MUA =============================================================
  1458. fhm=figure; set(fhm,'Position',[100 100 1800 600]);
  1459. settings.PixPerDeg = 29.5032;
  1460. settings.meshsize = 2000;
  1461. colormap(inferno)
  1462. % M03 V1 ----
  1463. m=strcmp(tMUA.Monkey,'M03') & strcmp(tMUA.Model,model);
  1464. v=tMUA.Area==1;
  1465. subplot(2,4,1);hold on;
  1466. allprf=[];
  1467. for r=unique(tMUA.Array)'
  1468. a=tMUA.Array==r;
  1469. if sum(s & m & a & v) > 0
  1470. allprf = [allprf; ...
  1471. tMUA.X(s & m & a & v) ...
  1472. tMUA.Y(s & m & a & v) ...
  1473. tMUA.rfs(s & m & a & v)];
  1474. end
  1475. end
  1476. res = ck_2dPRF_ephys(allprf(:,1),allprf(:,2),allprf(:,3));
  1477. img=flipud(res.img); res.ymesh2 = fliplr(res.ymesh);
  1478. % zoom in on plot
  1479. xrange = [-3 8]; yrange = [-6 3];
  1480. xrange_idx = [...
  1481. find(res.xmesh >= xrange(1),1,'first') find(res.xmesh <= xrange(2),1,'last')];
  1482. yrange_idx = [...
  1483. find(res.ymesh2 >= yrange(1),1,'first') find(res.ymesh2 <= yrange(2),1,'last')];
  1484. xrr=res.xmesh(xrange_idx); yrr=res.ymesh2(yrange_idx);
  1485. % plot
  1486. sumimg=sum(img,3);
  1487. imagesc(sumimg);
  1488. set(gca,'xlim',xrange_idx,'ylim',...
  1489. yrange_idx,'Color','k','xtick',[],'ytick',[])
  1490. colorbar;
  1491. subplot(2,4,5); hold on;
  1492. plot(1.2*res.xr,[0 0],'w'); plot([0 0],1.2*res.yr,'w');
  1493. set(gca,'xlim',xrr,'ylim',yrr,'Color','k')
  1494. colorbar; clear('res','img','sumimg');
  1495. title('M03 V1 MUA')
  1496. % M03 V4 ----
  1497. v=tMUA.Area==4;
  1498. subplot(2,4,2);hold on;
  1499. allprf=[];
  1500. for r=unique(tMUA.Array)'
  1501. a=tMUA.Array==r;
  1502. if sum(s & m & a & v) > 0
  1503. allprf = [allprf; ...
  1504. tMUA.X(s & m & a & v) ...
  1505. tMUA.Y(s & m & a & v) ...
  1506. tMUA.rfs(s & m & a & v)];
  1507. end
  1508. end
  1509. res = ck_2dPRF_ephys(allprf(:,1),allprf(:,2),allprf(:,3));
  1510. img=flipud(res.img); res.ymesh2 = fliplr(res.ymesh);
  1511. % zoom in on plot
  1512. xrange = [-3 8]; yrange = [-6 3];
  1513. xrange_idx = [...
  1514. find(res.xmesh >= xrange(1),1,'first') find(res.xmesh <= xrange(2),1,'last')];
  1515. yrange_idx = [...
  1516. find(res.ymesh2 >= yrange(1),1,'first') find(res.ymesh2 <= yrange(2),1,'last')];
  1517. xrr=res.xmesh(xrange_idx); yrr=res.ymesh2(yrange_idx);
  1518. % plot
  1519. sumimg=sum(img,3);
  1520. imagesc(sumimg);
  1521. set(gca,'xlim',xrange_idx,'ylim',...
  1522. yrange_idx,'Color','k','xtick',[],'ytick',[])
  1523. colorbar;
  1524. subplot(2,4,6); hold on;
  1525. plot(1.2*res.xr,[0 0],'w'); plot([0 0],1.2*res.yr,'w');
  1526. set(gca,'xlim',xrr,'ylim',yrr,'Color','k')
  1527. colorbar; clear('res','img','sumimg');
  1528. title('M03 V4 MUA')
  1529. % M04 V1 ----
  1530. m=strcmp(tMUA.Monkey,'M04') & strcmp(tMUA.Model,model);
  1531. v=tMUA.Area==1;
  1532. subplot(2,4,3);hold on;
  1533. allprf=[];
  1534. for r=unique(tMUA.Array)'
  1535. a=tMUA.Array==r;
  1536. if sum(s & m & a & v) > 0
  1537. allprf = [allprf; ...
  1538. tMUA.X(s & m & a & v) ...
  1539. tMUA.Y(s & m & a & v) ...
  1540. tMUA.rfs(s & m & a & v)];
  1541. end
  1542. end
  1543. res = ck_2dPRF_ephys(allprf(:,1),allprf(:,2),allprf(:,3));
  1544. img=flipud(res.img); res.ymesh2 = fliplr(res.ymesh);
  1545. % zoom in on plot
  1546. xrange = [-3 8]; yrange = [-6 3];
  1547. xrange_idx = [...
  1548. find(res.xmesh >= xrange(1),1,'first') find(res.xmesh <= xrange(2),1,'last')];
  1549. yrange_idx = [...
  1550. find(res.ymesh2 >= yrange(1),1,'first') find(res.ymesh2 <= yrange(2),1,'last')];
  1551. xrr=res.xmesh(xrange_idx); yrr=res.ymesh2(yrange_idx);
  1552. % plot
  1553. sumimg=sum(img,3);
  1554. imagesc(sumimg);
  1555. set(gca,'xlim',xrange_idx,'ylim',...
  1556. yrange_idx,'Color','k','xtick',[],'ytick',[])
  1557. colorbar;
  1558. subplot(2,4,7); hold on;
  1559. plot(1.2*res.xr,[0 0],'w'); plot([0 0],1.2*res.yr,'w');
  1560. set(gca,'xlim',xrr,'ylim',yrr,'Color','k')
  1561. colorbar; clear('res','img','sumimg');
  1562. title('M04 V1 MUA')
  1563. % M04 V4 ----
  1564. v=tMUA.Area==4;
  1565. subplot(2,4,4);hold on;
  1566. allprf=[];
  1567. for r=unique(tMUA.Array)'
  1568. a=tMUA.Array==r;
  1569. if sum(s & m & a & v) > 0
  1570. allprf = [allprf; ...
  1571. tMUA.X(s & m & a & v) ...
  1572. tMUA.Y(s & m & a & v) ...
  1573. tMUA.rfs(s & m & a & v)];
  1574. end
  1575. end
  1576. res = ck_2dPRF_ephys(allprf(:,1),allprf(:,2),allprf(:,3));
  1577. img=flipud(res.img); res.ymesh2 = fliplr(res.ymesh);
  1578. % zoom in on plot
  1579. xrange = [-5 25]; yrange = [-25 5];
  1580. xrange_idx = [...
  1581. find(res.xmesh >= xrange(1),1,'first') find(res.xmesh <= xrange(2),1,'last')];
  1582. yrange_idx = [...
  1583. find(res.ymesh2 >= yrange(1),1,'first') find(res.ymesh2 <= yrange(2),1,'last')];
  1584. xrr=res.xmesh(xrange_idx); yrr=res.ymesh2(yrange_idx);
  1585. % plot
  1586. sumimg=sum(img,3);
  1587. imagesc(sumimg);
  1588. set(gca,'xlim',xrange_idx,'ylim',...
  1589. yrange_idx,'Color','k','xtick',[],'ytick',[])
  1590. colorbar;
  1591. subplot(2,4,8); hold on;
  1592. plot(1.2*res.xr,[0 0],'w'); plot([0 0],1.2*res.yr,'w');
  1593. set(gca,'xlim',xrr,'ylim',yrr,'Color','k')
  1594. colorbar; clear('res','img','sumimg');
  1595. title('M04 V4 MUA')
  1596. if SaveFigs
  1597. saveas(fhm,fullfile(pngfld, 'MUA_VFC_hm.png'));
  1598. saveas(fhm,fullfile(svgfld, 'MUA_VFC_hm.svg'));
  1599. end
  1600. if CloseFigs; close(fhm); end
  1601. %% Ephys location difference & size difference ============================
  1602. rth=25; snrth=3; c_rth=25;
  1603. ephys_MMS = MMS(:,1);
  1604. clear C R2m SZ
  1605. for m=1:length(ephys_MOD)
  1606. C{m}=[];R2m{m}=[];SZ{m}=[];
  1607. model=ephys_MOD{m};
  1608. s = strcmp(tMUA.Model,model);
  1609. C{m}=[C{m} tMUA.R2(s) tMUA.X(s) tMUA.Y(s) tMUA.rfs(s)];
  1610. R2m{m}=[R2m{m} tMUA.R2(s)];
  1611. SZ{m}=[SZ{m} tMUA.R2(s) tMUA.rfs(s)];
  1612. PRF_EST(m,1).sig = 'MUA';
  1613. PRF_EST(m,1).R2 = tMUA.R2(s);
  1614. PRF_EST(m,1).X = tMUA.X(s);
  1615. PRF_EST(m,1).Y = tMUA.Y(s);
  1616. PRF_EST(m,1).S = tMUA.rfs(s);
  1617. PRF_EST(m,1).A = tMUA.Area(s);
  1618. PRF_EST(m,1).G = tMUA.gain(s);
  1619. PRF_EST(m,1).M = tMUA.Monkey(s);
  1620. PRF_EST(m,1).ARR = tMUA.Array(s);
  1621. s = strcmp(tMUA.Model,'classicRF');
  1622. %C{m}=[C{m} tMUA.X(s)./668.745 tMUA.Y(s)./668.745 tMUA.rfs(s)./2];
  1623. PRF_EST(m,2).sig = 'MUACLASSIC';
  1624. PRF_EST(m,2).R2 = tMUA.R2(s);
  1625. PRF_EST(m,2).X = tMUA.X(s);
  1626. PRF_EST(m,2).Y = tMUA.Y(s);
  1627. PRF_EST(m,2).S = tMUA.rfs(s);
  1628. PRF_EST(m,2).A = tMUA.Area(s);
  1629. PRF_EST(m,2).G = tMUA.gain(s);
  1630. PRF_EST(m,2).M = tMUA.Monkey(s);
  1631. PRF_EST(m,2).SNR = tMUA.SNR(s);
  1632. PRF_EST(m,2).ARR = tMUA.Array(s);
  1633. s = strcmp(tLFP.Model,model);
  1634. sig=unique(tLFP.SigType);
  1635. lfp_order = [3 1 2 5 4];
  1636. cnt=1;
  1637. for i=lfp_order
  1638. b=strcmp(tLFP.SigType,sig{i});
  1639. C{m}=[C{m} tLFP.R2(s & b) tLFP.X(s & b) tLFP.Y(s & b) tLFP.rfs(s & b)];
  1640. R2m{m}=[R2m{m} tLFP.R2(s & b)];
  1641. SZ{m}=[SZ{m} tLFP.R2(s & b) tLFP.rfs(s & b)];
  1642. PRF_EST(m,2+cnt).sig = sig{i};
  1643. PRF_EST(m,2+cnt).R2 = tLFP.R2(s & b);
  1644. PRF_EST(m,2+cnt).X = tLFP.X(s & b);
  1645. PRF_EST(m,2+cnt).Y = tLFP.Y(s & b);
  1646. PRF_EST(m,2+cnt).S = tLFP.rfs(s & b);
  1647. PRF_EST(m,2+cnt).A = tLFP.Area(s & b);
  1648. PRF_EST(m,2+cnt).G = tLFP.gain(s & b);
  1649. PRF_EST(m,2+cnt).M = tLFP.Monkey(s & b);
  1650. cnt=cnt+1;
  1651. end
  1652. s= sum(R2m{m}>rth,2)==size(R2m{m},2);
  1653. distRF{m} = [...
  1654. sqrt(((C{m}(s,2)-C{m}(s,5)).^2) + ((C{m}(s,3)-C{m}(s,6)).^2)) ...
  1655. sqrt(((C{m}(s,2)-C{m}(s,9)).^2) + ((C{m}(s,3)-C{m}(s,10)).^2)) ...
  1656. sqrt(((C{m}(s,2)-C{m}(s,13)).^2) + ((C{m}(s,3)-C{m}(s,14)).^2)) ...
  1657. sqrt(((C{m}(s,2)-C{m}(s,17)).^2) + ((C{m}(s,3)-C{m}(s,18)).^2)) ...
  1658. sqrt(((C{m}(s,2)-C{m}(s,21)).^2) + ((C{m}(s,3)-C{m}(s,22)).^2)) ];
  1659. distSZ{m} = [...
  1660. C{m}(s,4)-C{m}(s,7) ...
  1661. C{m}(s,4)-C{m}(s,11) ...
  1662. C{m}(s,4)-C{m}(s,15) ...
  1663. C{m}(s,4)-C{m}(s,19) ...
  1664. C{m}(s,4)-C{m}(s,23) ];
  1665. % normalize by MUA-pRF
  1666. normSz{m} = [...
  1667. C{m}(s,7)./C{m}(s,4) ...
  1668. C{m}(s,11)./C{m}(s,4) ...
  1669. C{m}(s,15)./C{m}(s,4) ...
  1670. C{m}(s,19)./C{m}(s,4) ...
  1671. C{m}(s,23)./C{m}(s,4) ];
  1672. % % normalize by cRF
  1673. % normSz{m} = [...
  1674. % C{m}(s,7)./PRF_EST(m,2).S(s,:) ...
  1675. % C{m}(s,11)./PRF_EST(m,2).S(s,:) ...
  1676. % C{m}(s,15)./PRF_EST(m,2).S(s,:) ...
  1677. % C{m}(s,19)./PRF_EST(m,2).S(s,:) ...
  1678. % C{m}(s,23)./PRF_EST(m,2).S(s,:) ];
  1679. end
  1680. %% Fig 7: compare MUA with classic ========================================
  1681. for m=[1 3]
  1682. mlabel=ephys_MMS{m};
  1683. cRF_coll = [];
  1684. pRF_coll = [];
  1685. f_cRFpRF=figure;
  1686. set(f_cRFpRF,'Position',[100 100 1500 600]);
  1687. pn=0;
  1688. for area = [1 4]
  1689. pn=pn+1;
  1690. fprintf(['=== AREA V' num2str(area) ' ===\n'])
  1691. % location
  1692. sel = PRF_EST(m,1).A == area & ...
  1693. PRF_EST(m,1).R2 > rth & ...
  1694. PRF_EST(m,2).R2 >= c_rth & ...
  1695. PRF_EST(m,2).SNR >= snrth & ...
  1696. ( strcmp(PRF_EST(m,1).M,'M03') & (PRF_EST(m,1).ARR ~= 11 & PRF_EST(m,1).ARR ~= 13) | ...
  1697. strcmp(PRF_EST(m,1).M,'M04') & (PRF_EST(m,1).ARR ~= 10 & PRF_EST(m,1).ARR ~= 12));
  1698. dLOCATION = sqrt(...
  1699. (PRF_EST(m,1).X(sel)-PRF_EST(m,2).X(sel)).^2 + ...
  1700. (PRF_EST(m,1).Y(sel)-PRF_EST(m,2).Y(sel)).^2);
  1701. mselect = PRF_EST(m,1).M(sel);
  1702. m3idx = strcmp(mselect,'M03'); m4idx = strcmp(mselect,'M04');
  1703. fprintf(['MODEL ' ephys_MOD{m} ', MUA vs CLASSIC distance ----\n'])
  1704. fprintf(['Mean ' num2str(nanmean(dLOCATION)) ', STD ' num2str(nanstd(dLOCATION)) '\n'])
  1705. fprintf(['Median ' num2str(nanmedian(dLOCATION)) ', IQR ' num2str(iqr(dLOCATION)) '\n'])
  1706. % size
  1707. SIZE_MUA = [PRF_EST(m,1).S(sel) PRF_EST(m,2).S(sel)];
  1708. rmINF = isinf(SIZE_MUA(:,1));
  1709. SIZE_MUA(rmINF,:)=[];
  1710. m3idx(rmINF,:)=[];
  1711. m4idx(rmINF,:)=[];
  1712. [p,h,stats] = signrank(SIZE_MUA(:,1),SIZE_MUA(:,2));
  1713. fprintf(['MODEL ' ephys_MOD{m} ', MUA vs CLASSIC size ----\n'])
  1714. fprintf(['dSZ: Wilcoxon z = ' ...
  1715. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  1716. fprintf(['Mean (mua-classic) ' num2str(nanmean(SIZE_MUA(:,1)-SIZE_MUA(:,2))) ...
  1717. ', STD ' num2str(nanstd(SIZE_MUA(:,1)-SIZE_MUA(:,2))) '\n'])
  1718. fprintf(['Median ' num2str(nanmedian(SIZE_MUA(:,1)-SIZE_MUA(:,2))) ...
  1719. ', IQR ' num2str(iqr(SIZE_MUA(:,1)-SIZE_MUA(:,2))) '\n'])
  1720. subplot(1,2,pn);hold on;
  1721. splim=[3 8];
  1722. plot([0 10],[0 10],'-r');
  1723. % split by monkey
  1724. pRF3=SIZE_MUA(m3idx,1); cRF3=SIZE_MUA(m3idx,2);
  1725. scatter(pRF3,cRF3,50,'Marker','o',...
  1726. 'MarkerEdgeColor','none',...
  1727. 'MarkerFaceColor',[.3 .3 .3],'MarkerFaceAlpha',0.3);
  1728. idx = ~isnan(pRF3) & ~isnan(cRF3);
  1729. polyfit(pRF3(idx),cRF3(idx),1)
  1730. pRF4=SIZE_MUA(m4idx,1); cRF4=SIZE_MUA(m4idx,2);
  1731. scatter(pRF4,cRF4,50,'Marker','o',...
  1732. 'MarkerEdgeColor','none',...
  1733. 'MarkerFaceColor',[.0 .0 .5],'MarkerFaceAlpha',0.3);
  1734. idx = ~isnan(pRF4) & ~isnan(cRF4);
  1735. polyfit(pRF4(idx),cRF4(idx),1)
  1736. pRF=[pRF3;pRF4];cRF=[cRF3;cRF4];
  1737. n_electrodes = [length(pRF3) length(pRF4)]
  1738. plot([0 10],[0 10],'-r');
  1739. set(gca, 'xlim',[0 splim(pn)],'ylim',[0 splim(pn)]);
  1740. legend({'x=y','M3','M4'})
  1741. title(['Area V' num2str(area)])
  1742. xlabel('MUA pRF size'); ylabel('Classic RF size')
  1743. % Stats per area
  1744. pRF_both = [pRF3;pRF4];
  1745. cRF_both = [cRF3;cRF4];
  1746. [R,p] = corr(cRF_both,pRF_both,'rows','complete');
  1747. fprintf(['Pearson corr for V' num2str(area) ': R=' num2str(R) ', p=' num2str(p) '\n'])
  1748. cRF_coll = [cRF_coll; ...
  1749. cRF3 3*ones(size(cRF3)) area*ones(size(cRF3));...
  1750. cRF4 4*ones(size(cRF4)) area*ones(size(cRF4))];
  1751. pRF_coll = [pRF_coll; ...
  1752. pRF3 3*ones(size(cRF3)) area*ones(size(pRF3));...
  1753. pRF4 4*ones(size(cRF4)) area*ones(size(pRF4))];
  1754. end
  1755. [R,p] = corr(cRF_coll(:,1),pRF_coll(:,1),'rows','complete');
  1756. fprintf(['Pearson corr: R=' num2str(R) ', p=' num2str(p) '\n'])
  1757. %%
  1758. f_cRFpRF2 = figure;
  1759. set(f_cRFpRF2,'Position',[0 0 2000 400]);
  1760. subplot(1,3,1); hold on
  1761. plot([0 10],[0 10],'-r');
  1762. % M3 V1
  1763. s = pRF_coll(:,2) == 3 & pRF_coll(:,3) == 1;
  1764. scatter(pRF_coll(s,1),cRF_coll(s,1),55,'Marker','o',...
  1765. 'MarkerEdgeColor','none',...
  1766. 'MarkerFaceColor','k','MarkerFaceAlpha',0.3);
  1767. % M4 V1
  1768. s = pRF_coll(:,2) == 4 & pRF_coll(:,3) == 1;
  1769. scatter(pRF_coll(s,1),cRF_coll(s,1),55,'Marker','o',...
  1770. 'MarkerEdgeColor','none',...
  1771. 'MarkerFaceColor',[.0 .0 .5],'MarkerFaceAlpha',0.3);
  1772. % M3 V4
  1773. s = pRF_coll(:,2) == 3 & pRF_coll(:,3) == 4;
  1774. scatter(pRF_coll(s,1),cRF_coll(s,1),50,'Marker','o',...
  1775. 'MarkerFaceColor',[1 1 1],'LineWidth',1,...
  1776. 'MarkerEdgeColor','k','MarkerFaceAlpha',0.3);
  1777. % M4 V4
  1778. s = pRF_coll(:,2) == 4 & pRF_coll(:,3) == 4;
  1779. scatter(pRF_coll(s,1),cRF_coll(s,1),50,'Marker','o',...
  1780. 'MarkerFaceColor',[1 1 1],'LineWidth',1,...
  1781. 'MarkerEdgeColor',[.0 .0 .5],'MarkerFaceAlpha',0.3);
  1782. set(gca, 'xlim',[0 splim(pn)],'ylim',[0 splim(pn)]);
  1783. legend({'x=y','M3 V1','M4 V1','M3 V4','M4 V4'})
  1784. xlabel('MUA pRF size'); ylabel('Classic RF size')
  1785. ppp=pRF_coll(:,1);ccc=cRF_coll(:,1);
  1786. title(['pRF model: ' mlabel]);
  1787. subplot(1,3,2); hold on;
  1788. histogram(ppp-ccc,-5.05:0.1:5.05,'FaceColor',[.5 .5 .5],'LineStyle','none')
  1789. xlabel('pRF size - cRF size');
  1790. ylabel('n channels');
  1791. med_diff = nanmedian(ppp-ccc);
  1792. iqr_diff = [med_diff-(iqr(ppp-ccc)/2) med_diff+(iqr(ppp-ccc)/2)];
  1793. m_diff = nanmean(ppp-ccc);
  1794. sem_diff = nanstd(ppp-ccc)./sqrt(sum(~isnan(ppp.*ccc)));
  1795. [p,h,stats] = signrank(ppp-ccc,0);
  1796. fprintf(['Difference pRF-cRF: Wilcoxon z = ' ...
  1797. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  1798. plot([med_diff med_diff],[0 100],'r');
  1799. plot([m_diff m_diff],[0 100],'r--');
  1800. plot([0 0],[0 100],'k');
  1801. legend({'histogram', ['median ' num2str(med_diff)], ['mean ' num2str(m_diff)]})
  1802. title(['IQR ' num2str(iqr_diff(1)) ' ' num2str(iqr_diff(2)) ...
  1803. '; SEM ' num2str(sem_diff)])
  1804. subplot(1,3,3); hold on;
  1805. histogram(ppp./ccc,-0.05:0.1:10.05,'FaceColor',[.5 .5 .5],'LineStyle','none')
  1806. xlabel('pRF size / cRF size');
  1807. ylabel('n channels');
  1808. med_rat = nanmedian(ppp./ccc);
  1809. iqr_rat = [med_rat-(iqr(ppp./ccc)/2) med_rat+(iqr(ppp./ccc)/2)];
  1810. m_rat = nanmean(ppp./ccc);
  1811. sem_rat = nanstd(ppp./ccc)./sqrt(sum(~isnan(ppp.*ccc)));
  1812. [p,h,stats] = signrank(ppp./ccc,1);
  1813. fprintf(['Ratio pRF/cRF: Wilcoxon z = ' ...
  1814. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  1815. plot([med_rat med_rat],[0 100],'r');
  1816. plot([m_rat m_rat],[0 100],'r--');
  1817. plot([1 1],[0 100],'k');
  1818. legend({'histogram', ['median ' num2str(med_rat)], ['mean ' num2str(m_rat)]})
  1819. title(['IQR ' num2str(iqr_rat(1)) ' ' num2str(iqr_rat(2)) ...
  1820. '; SEM ' num2str(sem_rat)])
  1821. if SaveFigs
  1822. saveas(f_cRFpRF2,fullfile(pngfld, ['MUA_cRF-pRF_' mlabel '.png']));
  1823. saveas(f_cRFpRF2,fullfile(svgfld, ['MUA_cRF-pRF_' mlabel '.svg']));
  1824. saveas(f_cRFpRF,fullfile(pngfld, ['MUA_cRF-pRF' mlabel '.png']));
  1825. saveas(f_cRFpRF,fullfile(svgfld, ['MUA_cRF-pRF' mlabel '.svg']));
  1826. end
  1827. if CloseFigs; close(f_cRFpRF); close(f_cRFpRF2); end
  1828. end
  1829. %% Fig 8 MUA model comparison =============================================
  1830. m=unique(tMUA.Model);
  1831. R2=[];
  1832. RTH = 0;
  1833. for i=1:length(m)
  1834. R2 = [R2 tMUA.R2(strcmp(tMUA.Model,m{i}))];
  1835. end
  1836. v1=tMUA.Area(strcmp(tMUA.Model,m{1}))==1;
  1837. v4=tMUA.Area(strcmp(tMUA.Model,m{1}))==4;
  1838. sub = 'both';
  1839. if strcmp(sub,'M03') || strcmp(sub,'M04')
  1840. v1=v1 & strcmp(tMUA.Monkey(strcmp(tMUA.Model,m{1})),sub);
  1841. v4=v4 & strcmp(tMUA.Monkey(strcmp(tMUA.Model,m{1})),sub);
  1842. end
  1843. f6=figure;
  1844. msz=15;
  1845. set(f6,'Position',[100 100 1200 1200]);
  1846. for row=1:4
  1847. for column=1:4
  1848. subplot(4,4,((row-1)*4)+column); hold on;
  1849. plot([0 100],[0 100],'k');
  1850. XY = [R2(v1,row+1), R2(v1,column+1)];
  1851. XYs = XY(XY(:,1)>RTH & XY(:,2)>RTH,:);
  1852. scatter(XYs(:,1), XYs(:,2),msz,'Marker','o',...
  1853. 'MarkerEdgeColor',[.3 .3 .3],'MarkerFaceColor',[.3 .3 .3],...
  1854. 'MarkerFaceAlpha',0.5);
  1855. XY = [R2(v4,row+1), R2(v4,column+1)];
  1856. XYs = XY(XY(:,1)>RTH & XY(:,2)>RTH,:);
  1857. scatter(XYs(:,1), XYs(:,2),msz,'Marker','o',...
  1858. 'MarkerEdgeColor',[.3 .8 .3],'MarkerFaceColor',[.3 .8 .3],...
  1859. 'MarkerFaceAlpha',0.5);
  1860. set(gca, 'Box','off', 'xlim', [-2 100], 'ylim',[-2 100]);
  1861. xlabel(m{row+1},'interpreter','none');
  1862. ylabel(m{column+1},'interpreter','none');
  1863. title('MUA');
  1864. if row==1 && column==1
  1865. legend({'','V1','V4'},'location','NorthWest');
  1866. end
  1867. end
  1868. end
  1869. if SaveFigs
  1870. saveas(f6,fullfile(pngfld, 'EPHYS_MUA_ModelComparison.png'));
  1871. saveas(f6,fullfile(svgfld, 'EPHYS_MUA_ModelComparison.svg'));
  1872. end
  1873. if CloseFigs; close(f6); end
  1874. %% Stats model comparison R2 MUA ==========================================
  1875. for RTH = [0 25]
  1876. % stats V1
  1877. MR2=R2(v1,2:5);
  1878. sel=logical(sum(MR2>RTH,2));
  1879. [p,tbl,stats] = kruskalwallis(MR2(sel,:),{'css','dog','p-lin','u-lin'});
  1880. [c,m,h,gnames] = multcompare(stats);
  1881. for i=1:size(c,1)
  1882. fprintf(['V1 RTH-' num2str(RTH) ': ' gnames{c(i,1)} ' vs ' gnames{c(i,2)} ...
  1883. ', p = ' num2str(c(i,6)) '\n'])
  1884. end
  1885. % stats V4
  1886. MR2=R2(v4,2:5);
  1887. sel=logical(sum(MR2>RTH,2));
  1888. [p,tbl,stats] = kruskalwallis(MR2(sel,:),{'css','dog','p-lin','u-lin'});
  1889. [c,m,h,gnames] = multcompare(stats);
  1890. for i=1:size(c,1)
  1891. fprintf(['V4 RTH-' num2str(RTH) ': ' gnames{c(i,1)} ' vs ' gnames{c(i,2)} ...
  1892. ', p = ' num2str(c(i,6)) '\n'])
  1893. end
  1894. end
  1895. %% SFig 7 & SFig 8: LFP model comparison ==================================
  1896. f7=figure;
  1897. set(f7,'Position',[100 100 1600 1200]);
  1898. msz=15;
  1899. m=unique(tMUA.Model);
  1900. v1=tMUA.Area(strcmp(tMUA.Model,m{1}))==1;
  1901. v4=tMUA.Area(strcmp(tMUA.Model,m{1}))==4;
  1902. sub = 'both';
  1903. if strcmp(sub,'M03') || strcmp(sub,'M04')
  1904. v1=v1 & strcmp(tMUA.Monkey(strcmp(tMUA.Model,m{1})),sub);
  1905. v4=v4 & strcmp(tMUA.Monkey(strcmp(tMUA.Model,m{1})),sub);
  1906. end
  1907. % scatter dots
  1908. sig=unique(tLFP.SigType);
  1909. lfp_order = [3 1 2 5 4];
  1910. spn=1; fbn=1;
  1911. for fb=lfp_order
  1912. lfpmods{fbn,1}=[];
  1913. lfpmods{fbn,2}=[];
  1914. m=unique(tLFP.Model);
  1915. % reorder ---------
  1916. m=m([3 4 1 2]);
  1917. modname={'P-LIN','U-LIN','CSS','DoG'};
  1918. % -----------------
  1919. R2=[];
  1920. for i=1:length(m)
  1921. R2 = [R2 tLFP.R2(...
  1922. strcmp(tLFP.Model,m{i}) & ...
  1923. strcmp(tLFP.SigType,sig{fb}))];
  1924. end
  1925. for m1=1:4
  1926. lfpmods{fbn,1}=[lfpmods{fbn,1} R2(v1,m1)];
  1927. lfpmods{fbn,2}=[lfpmods{fbn,2} R2(v4,m1)];
  1928. for m2=m1+1:4
  1929. subplot(length(sig),6,spn); hold on;
  1930. plot([-5 100],[-5 100],'k');
  1931. % M1R2=R2(v1,m1);
  1932. % M2R2=R2(v1,m2);
  1933. % M1R2=M1R2(M1R2>0 & M2R2>0);
  1934. % M2R2=M2R2(M1R2>0 & M2R2>0);
  1935. scatter(R2(v1,m1), R2(v1,m2),msz,'Marker','o',...
  1936. 'MarkerEdgeColor',[.3 .3 .3],'MarkerEdgeAlpha',0,...
  1937. 'MarkerFaceColor',[.3 .3 .3],'MarkerFaceAlpha',0.25);
  1938. scatter(R2(v4,m1), R2(v4,m2),msz,'Marker','o',...
  1939. 'MarkerEdgeColor',[.3 .8 .3],'MarkerEdgeAlpha',0,...
  1940. 'MarkerFaceColor',[.3 .8 .3],'MarkerFaceAlpha',0.25);
  1941. % M1R2=R2(v4,m1); M1R2=M1R2(M1R2>0 & M2R2>0);
  1942. % M2R2=R2(v4,m1); M1R2=M1R2(M1R2>0 & M2R2>0);
  1943. % scatter(R2(v4,m1), R2(v4,m2),msz,'Marker','o',...
  1944. % 'MarkerEdgeColor',[.3 .3 .3],'MarkerEdgeAlpha',0,...
  1945. % 'MarkerFaceColor',[.3 .3 .3],'MarkerFaceAlpha',0.25);
  1946. set(gca, 'Box','off', 'xlim', [-5 100], 'ylim',[-5 100],...
  1947. 'xticklabels',{},'yticklabels',{},'TickDir','out');
  1948. xlabel(modname{m1},'interpreter','none');ylabel(modname{m2},'interpreter','none')
  1949. title(sig{fb})
  1950. if spn==1
  1951. %legend({'','V1','V4'},'location','SouthEast');
  1952. end
  1953. spn=spn+1;
  1954. end
  1955. end
  1956. fbn=fbn+1;
  1957. end
  1958. if SaveFigs
  1959. saveas(f7,fullfile(pngfld, 'EPHYS_LFP_ModelComparison.png'));
  1960. saveas(f7,fullfile(svgfld, 'EPHYS_LFP_ModelComparison.svg'));
  1961. end
  1962. if CloseFigs; close(f7); end
  1963. %% stats ==================================================================
  1964. FreqNames = {'Theta','Alpha','Beta','Gamma-low','Gamma-high'};
  1965. for fb=1:5
  1966. % stats V1
  1967. fprintf(['\n= V1 LFP-' FreqNames{fb} ' ================\n'])
  1968. [p,tbl,stats] = kruskalwallis(lfpmods{fb,1},modname);
  1969. fprintf(['H =' num2str(tbl{2,5}(1)) ', df = ' num2str(tbl{2,3}(1)) ', p = ' num2str(tbl{2,6}(1)) '\n'])
  1970. [c,m,h,gnames] = multcompare(stats);
  1971. for i=1:size(c,1)
  1972. fprintf([gnames{c(i,1)} ' vs ' gnames{c(i,2)} ...
  1973. ', p = ' num2str(c(i,6)) '\n'])
  1974. end
  1975. % stats V4
  1976. fprintf(['\n= V4 LFP-' FreqNames{fb} ' ================\n'])
  1977. [p,tbl,stats] = kruskalwallis(lfpmods{fb,2},modname);
  1978. fprintf(['H =' num2str(tbl{2,5}(1)) ', df = ' num2str(tbl{2,3}(1)) ', p = ' num2str(tbl{2,6}(1)) '\n'])
  1979. [c,m,h,gnames] = multcompare(stats);
  1980. for i=1:size(c,1)
  1981. fprintf([gnames{c(i,1)} ' vs ' gnames{c(i,2)} ...
  1982. ', p = ' num2str(c(i,6)) '\n'])
  1983. end
  1984. end
  1985. %% SFig 9: R2 for different ephys signals =================================
  1986. r2th=0;
  1987. ephys_MOD={'linear_ephys_cv1','linear_ephys_cv1_neggain',...
  1988. 'css_ephys_cv1','dog_ephys_cv1'};
  1989. ephys_MMS = MMS(:,1);
  1990. for m=1:length(ephys_MOD)
  1991. RR=[];
  1992. fprintf(['\n============ ' ephys_MOD{m} ' ===========\n'])
  1993. model=ephys_MOD{m};
  1994. s = strcmp(tMUA.Model,model);
  1995. RR=[RR tMUA.R2(s)];
  1996. s = strcmp(tLFP.Model,model);
  1997. sig=unique(tLFP.SigType);
  1998. lfp_order = [3 1 2 5 4];
  1999. for i=lfp_order
  2000. b=strcmp(tLFP.SigType,sig{i});
  2001. RR=[RR tLFP.R2(s & b)];
  2002. end
  2003. LAB=['MUA';sig(lfp_order)];
  2004. f8=figure;
  2005. set(f8,'Position',[100 100 1900 1350]);
  2006. sgtitle(['R2 per Model: ' model],'interpreter','none');
  2007. c=0;d=0;
  2008. for ref=1:6
  2009. c=c+1;
  2010. for fb=1:6
  2011. d=d+1;
  2012. s=(RR(:,ref)>r2th & RR(:,fb)>r2th);
  2013. subplot(6,6,d); hold on;
  2014. %scatter(RR(s,ref),RR(s,fb),120,[0.3 0.3 0.3],'Marker','.');
  2015. binscatter(RR(s,ref),RR(s,fb),25,...
  2016. 'XLimits', [0 100],...
  2017. 'YLimits', [0 100],...
  2018. 'ShowEmptyBins', 'off')
  2019. colorbar;
  2020. set(gca,'ColorScale','log');
  2021. colormap(inferno)
  2022. caxis([1 256])
  2023. plot([0 100],[0 100],'Color',[.7 .7 .7],'LineWidth',2);
  2024. xlabel(LAB{ref});ylabel(LAB{fb});
  2025. %title(['R2 ' model],'interpreter','none');
  2026. set(gca,'xlim',[0 100],'ylim',[0 100]);
  2027. set(gca,'TickDir','out','xtick',[0 50 100],'ytick',[0 50 100]);
  2028. end
  2029. end
  2030. if SaveFigs
  2031. saveas(f8,fullfile(pngfld, ['EPHYS_MUA_R2_' ephys_MOD{m} '.png']));
  2032. saveas(f8,fullfile(svgfld, ['EPHYS_MUA_R2_' ephys_MOD{m} '.svg']));
  2033. end
  2034. if CloseFigs; close(f8); end
  2035. % Stats
  2036. [p,tbl,stats] = kruskalwallis(RR,LAB');
  2037. fprintf(['H =' num2str(tbl{2,5}(1)) ', df = ' num2str(tbl{2,3}(1)) ', p = ' num2str(tbl{2,6}(1)) '\n'])
  2038. [c,m,h,gnames] = multcompare(stats);
  2039. for i=1:size(c,1)
  2040. fprintf([gnames{c(i,1)} ' (' num2str(m(c(i,1),1)) ' +/- ' num2str(m(c(i,1),2)) ') vs ' ...
  2041. gnames{c(i,2)} ' (' num2str(m(c(i,2),1)) ' +/- ' num2str(m(c(i,2),2)) '), p = ' num2str(c(i,6)) '\n'])
  2042. end
  2043. close all
  2044. end
  2045. %% Fig 11A,B: location and size across ephys channels =====================
  2046. RTH=25; SNRTH = 3;
  2047. % CSS -----
  2048. midx = 3; % 2 = U-LIN, 3 = CSS
  2049. fprintf(['MODEL ' ephys_MOD{midx} '\n']);
  2050. % 1 = MUA, 2 = ClasRF, 3 = Theta, 4 = Alpha, 5 = Beta, 6 = Gamma-low, 7 =
  2051. % Gamma-high
  2052. SigCompNames = {};
  2053. SigComp_nElec =[];
  2054. SigCompDist = [];
  2055. SigCompDist_columns = {'mean','std','median','iqr'};
  2056. SigCompSz = [];
  2057. SigCompSz_columns = {'mean_nS1','std_nS1','median_nS1','iqr_nS1',...
  2058. 'mean_nS2','std_nS2','median_nS2','iqr_nS2',...
  2059. 'mean_nS2/nS1','std_nS2/nS1','median_nS2/nS1','iqr_nS2/nS1'};
  2060. sub = 'both';
  2061. rown=1;
  2062. for sigidx1 = 1:7
  2063. for sigidx2 = 1:7
  2064. SigCompNames{rown,1} = PRF_EST(midx,sigidx1).sig;
  2065. SigCompNames{rown,2} = PRF_EST(midx,sigidx2).sig;
  2066. % threshold
  2067. if strcmp(sub,'M03') || strcmp(sub,'M04')
  2068. elec = PRF_EST(midx,sigidx1).R2 > RTH & ...
  2069. PRF_EST(midx,sigidx2).R2 > RTH & ...
  2070. strcmp(PRF_EST(midx,sigidx2).M,sub);
  2071. else
  2072. elec = PRF_EST(midx,sigidx1).R2 > RTH & PRF_EST(midx,sigidx2).R2 > RTH;
  2073. end
  2074. % calculate distance
  2075. DIST = sqrt((PRF_EST(midx,sigidx1).X(elec) - PRF_EST(midx,sigidx2).X(elec)).^2 + ...
  2076. (PRF_EST(midx,sigidx1).Y(elec) - PRF_EST(midx,sigidx2).Y(elec)).^2);
  2077. SigCompDist = [SigCompDist; nanmean(DIST) nanstd(DIST) nanmedian(DIST) iqr(DIST)];
  2078. % calculate normalized size
  2079. % normalize by MUA pRF
  2080. % nS1 = PRF_EST(midx,sigidx1).S(elec)./PRF_EST(midx,1).S(elec);
  2081. % nS2 = PRF_EST(midx,sigidx2).S(elec)./PRF_EST(midx,1).S(elec);
  2082. % normalize by cRF
  2083. nS1 = PRF_EST(midx,sigidx1).S(elec)./PRF_EST(midx,2).S(elec);
  2084. nS2 = PRF_EST(midx,sigidx2).S(elec)./PRF_EST(midx,2).S(elec);
  2085. SigCompSz = [SigCompSz;...
  2086. nanmean(nS1(~isinf(nS1))) nanstd(nS1(~isinf(nS1))) ...
  2087. nanmedian(nS1(~isinf(nS1))) iqr(nS1(~isinf(nS1))) ...
  2088. nanmean(nS2(~isinf(nS2))) nanstd(nS2(~isinf(nS2))) ...
  2089. nanmedian(nS2(~isinf(nS2))) iqr(nS2(~isinf(nS2))) ...
  2090. nanmean(nS2(~isinf(nS1) & ~isinf(nS2))./nS1(~isinf(nS1) & ~isinf(nS2))) ...
  2091. nanstd(nS2(~isinf(nS1) & ~isinf(nS2))./nS1(~isinf(nS1) & ~isinf(nS2))) ...
  2092. nanmedian(nS2(~isinf(nS1) & ~isinf(nS2))./nS1(~isinf(nS1) & ~isinf(nS2))) ...
  2093. iqr(nS2(~isinf(nS1) & ~isinf(nS2))./nS1(~isinf(nS1) & ~isinf(nS2)))];
  2094. SigComp_nElec = [SigComp_nElec;sum(elec)];
  2095. rown = rown+1;
  2096. end
  2097. end
  2098. [sorted_names,sidx] = sortrows(SigCompNames);
  2099. sorted_n = SigComp_nElec(sidx,:);
  2100. sorted_dist = SigCompDist(sidx,:);
  2101. sorted_sz = SigCompSz(sidx,:);
  2102. uSig = unique(SigCompNames);
  2103. nSig = size(unique(SigCompNames),1);
  2104. DistMat_median = zeros(nSig);
  2105. DistMat_iqr = zeros(nSig);
  2106. DistMat_n = zeros(nSig);
  2107. SzMat_median = zeros(nSig);
  2108. SzMat_iqr = zeros(nSig);
  2109. for i=1:nSig
  2110. ii=((i-1)*nSig)+1;
  2111. DistMat_median(:,i) = sorted_dist(ii:ii+nSig-1,3);
  2112. DistMat_iqr(:,i) = sorted_dist(ii:ii+nSig-1,4)./2;
  2113. DistMat_n(:,i) = sorted_n(ii:ii+nSig-1);
  2114. SzMat_median(:,i) = sorted_sz(ii:ii+nSig-1,11);
  2115. SzMat_iqr(:,i) = sorted_sz(ii:ii+nSig-1,12)./2;
  2116. end
  2117. % re-order for plot
  2118. order=[4 3 5 1 2 7 6];
  2119. DistMat_median = DistMat_median(order,:);
  2120. DistMat_median = DistMat_median(:,order);
  2121. DistMat_iqr = DistMat_iqr(order,:);
  2122. DistMat_iqr = DistMat_iqr(:,order);
  2123. SzMat_median = SzMat_median(order,:);
  2124. SzMat_median = SzMat_median(:,order);
  2125. SzMat_iqr = SzMat_iqr(order,:);
  2126. SzMat_iqr = SzMat_iqr(:,order);
  2127. DistMat_n = DistMat_n(order,:);
  2128. DistMat_n = DistMat_n(:,order);
  2129. uSig = uSig(order);
  2130. %
  2131. fcss=figure;
  2132. set(fcss,'Position',[10 10 2200 1200],'Renderer','painters');
  2133. colormap(viridis)
  2134. %colormap(brewermap([],'RdBu'));
  2135. subplot(2,3,1);
  2136. imagesc(DistMat_median)
  2137. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2138. 'XTickLabelRotation',45)
  2139. caxis([0 1.5]);colorbar;
  2140. title('pRF distance median');
  2141. subplot(2,3,2);
  2142. imagesc(DistMat_iqr)
  2143. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2144. 'XTickLabelRotation',45)
  2145. caxis([0 0.8]);colorbar;
  2146. title('pRF distance iqr');
  2147. subplot(2,3,3);
  2148. imagesc(DistMat_n)
  2149. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2150. 'XTickLabelRotation',45,'ColorScale','log');
  2151. colorbar;
  2152. caxis([1 1700])
  2153. title('n');
  2154. subplot(2,3,4);
  2155. imagesc(SzMat_median)
  2156. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2157. 'XTickLabelRotation',45)
  2158. caxis([0 2]);colorbar;
  2159. title('pRF relative sz median');
  2160. subplot(2,3,5);
  2161. imagesc(SzMat_iqr)
  2162. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2163. 'XTickLabelRotation',45)
  2164. caxis([0 2]);colorbar;
  2165. title('pRF relative sz iqr');
  2166. subplot(2,3,6);
  2167. nMask = DistMat_n >= 10;
  2168. imagesc(nMask)
  2169. set(gca,'TickDir','out','xtick',1:11,'xticklabels',uSig, 'yticklabels',uSig,...
  2170. 'XTickLabelRotation',45);
  2171. colorbar;
  2172. caxis([0 1])
  2173. title('mask n > 10');
  2174. sgtitle(['MODEL ' ephys_MOD{midx}], 'interpreter','none')
  2175. if SaveFigs
  2176. saveas(fcss,fullfile(pngfld, 'EPHYS_xsig_dist.png'));
  2177. saveas(fcss,fullfile(svgfld, 'EPHYS_xsig_dist.svg'));
  2178. end
  2179. if CloseFigs; close(fcss); end
  2180. fcss_sz=figure;hold on;
  2181. %errorbar(1:7,SzMat_median(:,2),SzMat_iqr(:,2),'ko','LineStyle','none'); % norm by MUA pRF
  2182. errorbar(1:7,SzMat_median(:,1),SzMat_iqr(:,1),'ko','LineStyle','none'); % norm by MUA cRF
  2183. ylabel('Normalized pRF size')
  2184. set(gca,'xlim',[0.5 7.5], 'xtick',1:7, 'xticklabels',...
  2185. {'cRF-MUA','pRF-MUA','Theta','Alpha', 'Beta', 'Gam-low', 'Gam-high'},...
  2186. 'XTickLabelRotation',45);
  2187. if SaveFigs
  2188. saveas(fcss_sz,fullfile(pngfld, 'EPHYS_xsig_sz.png'));
  2189. saveas(fcss_sz,fullfile(svgfld, 'EPHYS_xsig_sz.svg'));
  2190. end
  2191. if CloseFigs; close(fcss_sz); end
  2192. %% Fig 10: Split Alpha and Beta LFP by positive negative gain =============
  2193. R2th = 20; % minimum R2
  2194. R2enh = 5; % R2 improvement
  2195. fb = {'Alpha','Beta'};
  2196. %% ALPHA Fig 10, SFig 11 ==================================================
  2197. fidx = 1;
  2198. DoG = tLFP(...
  2199. strcmp(tLFP.Model,'dog_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2200. lin_n = tLFP(...
  2201. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,fb{fidx}),:);
  2202. lin = tLFP(...
  2203. strcmp(tLFP.Model,'linear_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2204. css = tLFP(...
  2205. strcmp(tLFP.Model,'css_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2206. lin_nGAM1 = tLFP(...
  2207. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,'lGamma'),:);
  2208. lin_nGAM2 = tLFP(...
  2209. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,'hGamma'),:);
  2210. % U-LIN ----
  2211. f_neg2 = figure;
  2212. roi=1; % only do this for V1 channels
  2213. set(f_neg2,'Position',[10 10 900 800]);
  2214. chan_sel = lin_n.Area==roi & lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh;
  2215. chan_sel2 = lin_n.Area==roi & lin_n.R2>R2th;
  2216. chan_pgain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain>0;
  2217. chan_ngain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain<0;
  2218. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2219. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2220. subplot(2,2,1); hold on;
  2221. % gain alpha U-LIN
  2222. histogram(lin_n.gain(chan_sel2),-2000:50:2000,'FaceColor','k','FaceAlpha',0.5);
  2223. histogram(lin_n.gain(chan_ngain),-2000:50:2000,'FaceColor','r','FaceAlpha',0.5);
  2224. histogram(lin_n.gain(chan_pgain),-2000:50:2000,'FaceColor','b','FaceAlpha',0.5);
  2225. xlabel('gain U-LIN - ALL ELEC');ylabel('nChannels');
  2226. set(gca,'xlim',[-800 1800],'TickDir','out');
  2227. MM=median(lin_n.gain(chan_sel2));
  2228. yy=get(gca,'ylim');
  2229. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  2230. set(gca,'ylim',[0 yy(2)+10]);
  2231. title('Gain')
  2232. fprintf(['UNSELECTED - ALPHA MEDIAN GAIN: ' num2str(MM) ', IQR ' num2str(iqr(lin_n.gain(chan_sel))) '\n'])
  2233. subplot(2,2,2); hold on;
  2234. % gain alpha U-LIN
  2235. histogram(lin_n.gain(chan_sel),-1000:50:1000,'FaceColor','k','FaceAlpha',0.5);
  2236. xlabel('gain LIN-POSNEG');ylabel('nChannels');
  2237. set(gca,'xlim',[-800 1700],'TickDir','out');
  2238. MM=median(lin_n.gain(chan_sel));
  2239. yy=get(gca,'ylim');
  2240. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  2241. set(gca,'ylim',[0 yy(2)+10]);
  2242. title('Gain selected channels (based on R2 ULIN>PLIN')
  2243. fprintf(['ALPHA MEDIAN GAIN: ' num2str(MM) ', IQR ' num2str(iqr(lin_n.gain(chan_sel))) '\n'])
  2244. % Wilcoxon 1-tailed < 1
  2245. [p,h,stats] = signrank(lin_n.gain(chan_sel),0,'tail','left');
  2246. fprintf(['Gain < 0: Wilcoxon z = ' ...
  2247. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2248. subplot(2,2,3); hold on;
  2249. bb = [lin_n.ecc(chan_sel) lin.ecc(chan_sel)];
  2250. mEcc = [mean(lin_n.ecc(chan_ngain)) mean(lin_n.ecc(chan_pgain))];
  2251. sdEcc = [std(lin_n.ecc(chan_ngain)) std(lin_n.ecc(chan_pgain))];
  2252. mdEcc = [median(lin_n.ecc(chan_ngain)) median(lin_n.ecc(chan_pgain)) ];
  2253. iqrEcc = [iqr(lin_n.ecc(chan_ngain)) iqr(lin_n.ecc(chan_pgain)) ]./2;
  2254. errorbar(1:2,mdEcc,iqrEcc,...
  2255. 'ko','MarkerSize',4,'MarkerFaceColor','k','Linewidth',2)
  2256. set(gca,'xtick',1:2,'xticklabels',{'ULIN-N','ULIN-P'},...
  2257. 'xlim',[0.8 2.2],'TickDir','out')
  2258. ylabel('Eccentricity');
  2259. title('Ecc')
  2260. % Ecc difference
  2261. fprintf('-- STATS Ecc --\n');
  2262. fprintf(['mEcc nGain U-LIN: ' num2str(mEcc(1)) ', STD ' num2str(sdEcc(1)) '\n'])
  2263. fprintf(['mEcc pGain U-LIN: ' num2str(mEcc(2)) ', STD ' num2str(sdEcc(2)) '\n'])
  2264. fprintf(['mdEcc nGain U-LIN: ' num2str(mdEcc(1)) ', IQR ' num2str(iqrEcc(1)) '\n'])
  2265. fprintf(['mdEcc pGain U-LIN: ' num2str(mdEcc(2)) ', IQR ' num2str(iqrEcc(2)) '\n'])
  2266. [p,h,stats] = ranksum(lin_n.ecc(chan_ngain),lin_n.ecc(chan_pgain));
  2267. fprintf(['Ecc difference pos gain U-LIN vs neg gain U-LIN: Wilcoxon z = ' ...
  2268. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2269. subplot(2,2,4); hold on;
  2270. bb = [lin_n.rfs(chan_sel) lin.rfs(chan_sel)];
  2271. mSz = [mean(lin_n.rfs(chan_ngain)) mean(lin_n.rfs(chan_pgain)) ];
  2272. sdSz = [std(lin_n.rfs(chan_ngain)) std(lin_n.rfs(chan_pgain)) ];
  2273. mdSz = [median(lin_n.rfs(chan_ngain)) median(lin_n.rfs(chan_pgain))];
  2274. iqrSz = [iqr(lin_n.rfs(chan_ngain)) iqr(lin_n.rfs(chan_pgain)) ]./2;
  2275. errorbar(1:2,mdSz,iqrSz,'ko','MarkerSize',4,'MarkerFaceColor','k','Linewidth',2)
  2276. set(gca,'xtick',1:2,'xticklabels',{'ULIN-N','ULIN-P'},...
  2277. 'xlim',[0.8 2.2],'TickDir','out')
  2278. ylabel('Size');
  2279. title('Size')
  2280. % Sz difference
  2281. fprintf('-- STATS Sz --\n');
  2282. fprintf(['mSz nGain U-LIN: ' num2str(mSz(1)) ', STD ' num2str(sdSz(1)) '\n'])
  2283. fprintf(['mSz pGain U-LIN: ' num2str(mSz(2)) ', STD ' num2str(sdSz(2)) '\n'])
  2284. fprintf(['mdSz nGain U-LIN: ' num2str(mdSz(1)) ', IQR ' num2str(iqrSz(1)) '\n'])
  2285. fprintf(['mdSz pGain U-LIN: ' num2str(mdSz(2)) ', IQR ' num2str(iqrSz(2)) '\n'])
  2286. [p,h,stats] = ranksum(lin_n.rfs(chan_ngain),lin_n.rfs(chan_pgain));
  2287. fprintf(['Sz difference pos gain U-LIN vs neg gain U-LIN: Wilcoxon z = ' ...
  2288. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2289. if SaveFigs
  2290. saveas(f_neg2,fullfile(pngfld, 'ALPHA_posneg_ecc_sz.png'));
  2291. saveas(f_neg2,fullfile(svgfld, 'ALPHA_posneg_ecc_sz.svg'));
  2292. end
  2293. if CloseFigs; close(f_neg2); end
  2294. %% Compare eccentricities between alpha and gamma prfs ====================
  2295. fextra=figure;
  2296. set(fextra,'Position',[100 100 600 1500]);
  2297. dE=[];
  2298. subplot(4,2,1);hold on;
  2299. plot([0 15],[0 15]);
  2300. scatter(lin_n.ecc(chan_ngain),lin_nGAM1.ecc(chan_ngain));
  2301. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2302. xlabel('A- CHAN: Ecc LOW GAM');ylabel('A- CHAN: Ecc ALPHA');
  2303. fprintf('Are Negative ALPHA pRF shifted relative to fixation from Low GAMMA?\n');
  2304. [p,h,stats] = signrank(lin_n.ecc(chan_ngain),lin_nGAM1.ecc(chan_ngain));
  2305. fprintf(['Median dEcc is ' ...
  2306. num2str(median(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))) ...
  2307. ' IQR ' ...
  2308. num2str(iqr(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2) ...
  2309. ' (POS --> towards fixation) \n']);
  2310. fprintf(['p = ' num2str(p) '\n']);
  2311. dE=[dE; ...
  2312. median(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain)) ...
  2313. iqr(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2];
  2314. subplot(4,2,2);hold on;
  2315. plot([0 15],[0 15]);
  2316. scatter(lin_n.ecc(chan_pgain),lin_nGAM1.ecc(chan_pgain));
  2317. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2318. xlabel('A+ CHAN: Ecc LOW GAM');ylabel('A+ CHAN: Ecc ALPHA');
  2319. fprintf('Are Positive ALPHA pRF shifted relative to fixation from Low GAMMA?\n');
  2320. [p,h,stats] = signrank(lin_n.ecc(chan_pgain),lin_nGAM1.ecc(chan_pgain));
  2321. fprintf(['Median dEcc is ' ...
  2322. num2str(median(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))) ...
  2323. ' IQR ' ...
  2324. num2str(iqr(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2) ...
  2325. ' (POS --> towards fixation) \n']);
  2326. fprintf(['p = ' num2str(p) '\n']);
  2327. dE=[dE; ...
  2328. median(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain)) ...
  2329. iqr(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2];
  2330. subplot(4,2,3);hold on;
  2331. plot([0 15],[0 15]);
  2332. scatter(lin_n.ecc(chan_ngain),lin_nGAM2.ecc(chan_ngain));
  2333. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2334. xlabel('A- CHAN: Ecc HIGH GAM');ylabel('A- CHAN: Ecc ALPHA');
  2335. fprintf('Are Negative ALPHA pRF shifted relative to fixation from High GAMMA?\n');
  2336. [p,h,stats] = signrank(lin_n.ecc(chan_ngain),lin_nGAM2.ecc(chan_ngain));
  2337. fprintf(['Median dEcc is ' ...
  2338. num2str(median(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))) ...
  2339. ' IQR ' ...
  2340. num2str(iqr(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2) ...
  2341. ' (POS --> towards fixation) \n']);
  2342. fprintf(['p = ' num2str(p) '\n']);
  2343. dE=[dE; ...
  2344. median(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain)) ...
  2345. iqr(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2];
  2346. subplot(4,2,4);hold on;
  2347. plot([0 15],[0 15]);
  2348. scatter(lin_n.ecc(chan_pgain),lin_nGAM2.ecc(chan_pgain));
  2349. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2350. xlabel('A+ CHAN: Ecc HIGH GAM');ylabel('A+ CHAN: Ecc ALPHA');
  2351. fprintf('Are Positive ALPHA pRF shifted relative to fixation from High GAMMA?\n');
  2352. [p,h,stats] = signrank(lin_n.ecc(chan_pgain),lin_nGAM2.ecc(chan_pgain));
  2353. fprintf(['Median dEcc is ' ...
  2354. num2str(median(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))) ...
  2355. ' IQR ' ...
  2356. num2str(iqr(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2) ...
  2357. ' (POS --> towards fixation) \n']);
  2358. fprintf(['p = ' num2str(p) '\n']);
  2359. dE=[dE; ...
  2360. median(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain)) ...
  2361. iqr(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2];
  2362. subplot(4,2,5:8);hold on;
  2363. hold on;
  2364. bar(1:4, dE(:,1));
  2365. errorbar(1:4, dE(:,1), dE(:,2), 'k','Linestyle', 'none');
  2366. ylabel('dEcc Alpha vs Gam')
  2367. set(gca,'xtick',1:4,'xticklabels',{'A- v lG','A+ v lG','A- v hG','A+ v hG'})
  2368. %% plot the diff in within channel pRF location for low/high LFP freq =====
  2369. fshiftprf = figure;
  2370. set(fshiftprf,'Position',[100 100 1600 1600]);
  2371. Xa1 = lin_n.X(chan_ngain); Ya1 = lin_n.Y(chan_ngain);
  2372. Xlg1 = lin_nGAM1.X(chan_ngain); Ylg1 = lin_nGAM1.Y(chan_ngain);
  2373. Xa2 = lin_n.X(chan_pgain); Ya2 = lin_n.Y(chan_pgain);
  2374. Xlg2 = lin_nGAM1.X(chan_pgain); Ylg2 = lin_nGAM1.Y(chan_pgain);
  2375. % only prfs within 8 deg for display
  2376. csel1 = Xa1<8 & Ya1<2 & Xlg1<8 & Ylg1<2 & ...
  2377. Xa1>-2 & Ya1>-8 & Xlg1>-2 & Ylg1>-8;
  2378. csel2 = Xa2<8 & Ya2<2 & Xlg2<8 & Ylg2<2 & ...
  2379. Xa2>-2 & Ya2>-8 & Xlg2>-2 & Ylg2>-8;
  2380. subplot(2,2,1);hold on;
  2381. plot([0 0],[-10 10],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2382. plot([-10 10],[0 0],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2383. quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2384. 'Color',[0.8 0.8 0.8],...
  2385. 'AutoScale',0,'ShowArrowHead',0); % lines from gam to alpha pRF
  2386. scatter(Xa1(csel1),Ya1(csel1),20,'ko','MarkerFaceColor','r'); % alpha pRF center
  2387. scatter(Xlg1(csel1),Ylg1(csel1),20,'ko','MarkerFaceColor','b'); % lgam prf center
  2388. % quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2389. % 'k','LineWidth',1,'AutoScale',1,'ShowArrowHead',1); % arrows from gam to alpha pRF
  2390. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g'); % fovea
  2391. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2392. 'FontName','Myriad Pro','TickDir','out');
  2393. xlabel('Horizontal dva');ylabel('Vertical dva');
  2394. shiftsz = sqrt((Xa1(csel1)-Xlg1(csel1)).^2 + (Ya1(csel1)-Ylg1(csel1)).^2);
  2395. m_ss = mean(shiftsz); se_ss = std(shiftsz)./sqrt(length(shiftsz));
  2396. fprintf(['Average negALPHA shift size: ' num2str(m_ss) ' +/- ' num2str(se_ss) ' SEM\n']);
  2397. subplot(2,2,2);hold on;
  2398. quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2399. 'k','AutoScale',1,'ShowArrowHead',1)
  2400. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g')
  2401. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2402. 'FontName','Myriad Pro','TickDir','out');
  2403. xlabel('Horizontal dva');ylabel('Vertical dva');
  2404. subplot(2,2,3);hold on;
  2405. plot([0 0],[-10 10],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2406. plot([-10 10],[0 0],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2407. quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2408. 'Color',[0.8 0.8 0.8],...
  2409. 'AutoScale',0,'ShowArrowHead',0); % lines from gam to alpha pRF
  2410. scatter(Xa2(csel2),Ya2(csel2),20,'ko','MarkerFaceColor','r'); % alpha pRF center
  2411. scatter(Xlg2(csel2),Ylg2(csel2),20,'ko','MarkerFaceColor','b'); % lgam prf center
  2412. % quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2413. % 'k','LineWidth',1,'AutoScale',1,'ShowArrowHead',1); % arrows from gam to alpha pRF
  2414. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g'); % fovea
  2415. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2416. 'FontName','Myriad Pro','TickDir','out');
  2417. xlabel('Horizontal dva');ylabel('Vertical dva');
  2418. shiftsz = sqrt((Xa2(csel2)-Xlg2(csel2)).^2 + (Ya2(csel2)-Ylg2(csel2)).^2);
  2419. m_ss = mean(shiftsz); se_ss = std(shiftsz)./sqrt(length(shiftsz));
  2420. fprintf(['Average posALPHA shift size: ' num2str(m_ss) ' +/- ' num2str(se_ss) ' SEM\n']);
  2421. subplot(2,2,4);hold on;
  2422. quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2423. 'k','AutoScale',1,'ShowArrowHead',1)
  2424. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g')
  2425. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2426. 'FontName','Myriad Pro','TickDir','out');
  2427. xlabel('Horizontal dva');ylabel('Vertical dva');
  2428. if SaveFigs
  2429. saveas(fextra,fullfile(pngfld, 'ALPHAvGAM_posneg_ecc_sz.png'));
  2430. saveas(fextra,fullfile(svgfld, 'ALPHAvGAM_posneg_ecc_sz.svg'));
  2431. end
  2432. if CloseFigs; close(fextra); end
  2433. %% ALPHA vs GAMMA pRF separation index ====================================
  2434. lin_n = tLFP(...
  2435. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,'Alpha'),:);
  2436. DoG = tMUA(...
  2437. strcmp(tMUA.Model,'dog_ephys_cv1'),:);
  2438. roi=1; % only do this for V1 channels
  2439. chan_sel = lin_n.Area==roi & lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh;
  2440. chan_sel2 = lin_n.Area==roi & lin_n.R2>R2th;
  2441. chan_pgain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain>0;
  2442. chan_ngain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain<0;
  2443. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2444. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2445. [mean(sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2446. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2)) ...
  2447. std(sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2448. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2))./sqrt(sum(chan_ngain))]
  2449. [mean(sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2450. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2)) ...
  2451. std(sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2452. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2))./sqrt(sum(chan_pgain))]
  2453. [mean(sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2454. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2)) ...
  2455. std(sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2456. (lin_n.Y(chan_ngain)-lin_nGAM2.Y(chan_ngain)).^2))./sqrt(sum(chan_ngain))]
  2457. [mean(sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2458. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2)) ...
  2459. std(sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2460. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2))./sqrt(sum(chan_pgain))]
  2461. fprintf('=== ALPHA ===\n')
  2462. % size
  2463. fprintf('Size diff (a-lG)\n')
  2464. fprintf('NGAIN\n')
  2465. [mean(lin_n.rfs(chan_ngain)-lin_nGAM1.rfs(chan_ngain)) ...
  2466. std(lin_n.rfs(chan_ngain)-lin_nGAM1.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2467. fprintf('PGAIN\n')
  2468. [mean(lin_n.rfs(chan_pgain)-lin_nGAM1.rfs(chan_pgain)) ...
  2469. std(lin_n.rfs(chan_pgain)-lin_nGAM1.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2470. % normalized size
  2471. fprintf('Norm Size diff (a/lG)\n')
  2472. fprintf('NGAIN\n')
  2473. [mean(lin_n.rfs(chan_ngain)./lin_nGAM1.rfs(chan_ngain)) ...
  2474. std(lin_n.rfs(chan_ngain)./lin_nGAM1.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2475. fprintf('PGAIN\n')
  2476. [mean(lin_n.rfs(chan_pgain)./lin_nGAM1.rfs(chan_pgain)) ...
  2477. std(lin_n.rfs(chan_pgain)./lin_nGAM1.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2478. fprintf('Norm Size diff (a/hG)\n')
  2479. fprintf('NGAIN\n')
  2480. [mean(lin_n.rfs(chan_ngain)./lin_nGAM2.rfs(chan_ngain)) ...
  2481. std(lin_n.rfs(chan_ngain)./lin_nGAM2.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2482. fprintf('PGAIN\n')
  2483. [mean(lin_n.rfs(chan_pgain)./lin_nGAM2.rfs(chan_pgain)) ...
  2484. std(lin_n.rfs(chan_pgain)./lin_nGAM2.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2485. % distance in relation to size
  2486. distn = sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2487. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2);
  2488. distp = sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2489. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2);
  2490. sz2n=lin_n.rfs(chan_ngain)+lin_nGAM1.rfs(chan_ngain);
  2491. sz2p=lin_n.rfs(chan_pgain)+lin_nGAM1.rfs(chan_pgain);
  2492. ff=figure;
  2493. set(ff,'Position',[10 10 600 1500]);
  2494. fprintf('DIST REL/Sz (dist/(s1+s2))\n')
  2495. subplot(4,2,1);hold on;
  2496. scatter(distn,sz2n);
  2497. scatter(distp,sz2p);
  2498. plot([0 20],[0 20]);
  2499. xlabel('distance A-G pRF');ylabel('sumsize A-G pRF')
  2500. set(gca,'xlim',[0 20],'ylim',[0 20]);
  2501. legend({'negative', 'positive'});
  2502. subplot(4,2,2);hold on;
  2503. fprintf('lG NEG\n')
  2504. fprintf('mean std median iqr\n')
  2505. [mean(distn./sz2n) std(distn./sz2n)./sqrt(sum(chan_ngain))...
  2506. median(distn./sz2n) iqr(distn./sz2n)./2]
  2507. histogram(distn./sz2n,100,'Normalization','probability')
  2508. fprintf('lG POS\n')
  2509. [mean(distp./sz2p) std(distp./sz2p)./sqrt(sum(chan_pgain))...
  2510. median(distp./sz2p) iqr(distp./sz2p)./2]
  2511. histogram(distp./sz2p,100,'Normalization','probability')
  2512. title('Low Gamma'); xlabel('Separation Index');
  2513. BC=[median(distn./sz2n) median(distp./sz2p)];
  2514. BCE=[iqr(distn./sz2n)/2 iqr(distp./sz2p)/2];
  2515. [p,h,stats] = ranksum(distn./sz2n, distp./sz2p);
  2516. fprintf('SEPARATION INDEX [Alpha-lGam] - Neg vs Pos channels\n');
  2517. fprintf(['p = ' num2str(p) '\n']);
  2518. distn = sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2519. (lin_n.Y(chan_ngain)-lin_nGAM2.Y(chan_ngain)).^2);
  2520. distp = sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2521. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2);
  2522. sz2n=lin_n.rfs(chan_ngain)+lin_nGAM2.rfs(chan_ngain);
  2523. sz2p=lin_n.rfs(chan_pgain)+lin_nGAM2.rfs(chan_pgain);
  2524. subplot(4,2,3);hold on;
  2525. scatter(distn,sz2n);
  2526. scatter(distp,sz2p);
  2527. plot([0 20],[0 20]);
  2528. xlabel('distance A-G pRF');ylabel('sumsize A-G pRF')
  2529. set(gca,'xlim',[0 20],'ylim',[0 20]);
  2530. legend({'negative', 'positive'});
  2531. subplot(4,2,4);hold on;
  2532. fprintf('hG NEG\n')
  2533. fprintf('mean std median iqr\n')
  2534. [mean(distn./sz2n) std(distn./sz2n)./sqrt(sum(chan_ngain))...
  2535. median(distn./sz2n) iqr(distn./sz2n)./2]
  2536. histogram(distn./sz2n,100,'Normalization','probability')
  2537. fprintf('hG POS\n')
  2538. [mean(distp./sz2p) std(distp./sz2p)./sqrt(sum(chan_pgain))...
  2539. median(distp./sz2p) iqr(distp./sz2p)./2]
  2540. histogram(distp./sz2p,100,'Normalization','probability')
  2541. title('High Gamma'); xlabel('Separation Index');
  2542. BC=[BC median(distn./sz2n) median(distp./sz2p)];
  2543. BCE=[BCE iqr(distn./sz2n)/2 iqr(distp./sz2p)/2];
  2544. [p,h,stats] = ranksum(distn./sz2n, distp./sz2p);
  2545. fprintf('SEPARATION INDEX [Alpha-hGam] - Neg vs Pos channels\n');
  2546. fprintf(['p = ' num2str(p) '\n']);
  2547. subplot(4,2,5:8); hold on;
  2548. bar(1:4, BC);
  2549. errorbar(1:4, BC, BCE, 'k', 'Linestyle','none')
  2550. ylabel('Separation Index')
  2551. set(gca, 'xtick',1:4,'xticklabels',{'lG-','lG+','hG-','hG+'})
  2552. if SaveFigs
  2553. saveas(ff,fullfile(pngfld, 'ALPHAvGAM_sepidx.png'));
  2554. saveas(ff,fullfile(svgfld, 'ALPHAvGAM_sepidx.svg'));
  2555. end
  2556. if CloseFigs; close(ff); end
  2557. %% ALPHA DoG ==============================================================
  2558. chan_sel = DoG.R2>R2th & DoG.R2>lin.R2+R2enh & ...
  2559. DoG.normamp~=0 & DoG.ecc<16;
  2560. MM=median(DoG.normamp(chan_sel));
  2561. fprintf(['ALPHA MEDIAN NAMP: ' num2str(MM) ', IQR ' num2str(iqr(DoG.normamp(chan_sel))) '\n'])
  2562. % Wilcoxon 1-tailed < 1
  2563. [p,h,stats] = signrank(lin_n.gain(chan_sel),0,'tail','left');
  2564. fprintf(['Gain < 0: Wilcoxon z = ' ...
  2565. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2566. bb = [DoG.ecc(chan_sel) lin.ecc(chan_sel)];
  2567. % Wilcoxon
  2568. [p,h,stats] = signrank(bb(:,1),bb(:,2));
  2569. fprintf(['ECC diff Wilcoxon z = ' ...
  2570. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2571. MM=median(bb(:,2)-bb(:,1));
  2572. fprintf(['ALPHA MEDIAN ECC DIFF: ' num2str(median(lin.ecc(chan_sel)-DoG.ecc(chan_sel))) ...
  2573. ', IQR ' num2str(iqr(lin.ecc(chan_sel)-DoG.ecc(chan_sel))) '\n'])
  2574. %% BETA SFig 10, 11 =======================================================
  2575. fidx = 2;
  2576. DoG = tLFP(...
  2577. strcmp(tLFP.Model,'dog_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2578. lin_n = tLFP(...
  2579. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,fb{fidx}),:);
  2580. lin = tLFP(...
  2581. strcmp(tLFP.Model,'linear_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2582. css = tLFP(...
  2583. strcmp(tLFP.Model,'css_ephys_cv1') & strcmp(tLFP.SigType,fb{fidx}),:);
  2584. % U-LIN ----
  2585. f_neg2 = figure;
  2586. roi=1; % only do this for V1 channels
  2587. set(f_neg2,'Position',[10 10 900 1200]);
  2588. chan_sel = lin_n.Area==roi & lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh;
  2589. chan_sel2 = lin_n.Area==roi & lin_n.R2>R2th;
  2590. chan_pgain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain>0;
  2591. chan_ngain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain<0;
  2592. subplot(2,2,1); hold on;
  2593. % gain alpha U-LIN
  2594. histogram(lin_n.gain(chan_sel2),-2000:50:2000,'FaceColor','k','FaceAlpha',0.5);
  2595. histogram(lin_n.gain(chan_ngain),-2000:50:2000,'FaceColor','r','FaceAlpha',0.5);
  2596. histogram(lin_n.gain(chan_pgain),-2000:50:2000,'FaceColor','b','FaceAlpha',0.5);
  2597. xlabel('gain U-LIN - ALL ELEC');ylabel('nChannels');
  2598. set(gca,'xlim',[-800 1800],'TickDir','out');
  2599. MM=median(lin_n.gain(chan_sel2));
  2600. yy=get(gca,'ylim');
  2601. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  2602. set(gca,'ylim',[0 yy(2)+10]);
  2603. title('Gain')
  2604. fprintf(['UNSELECTED - BETA MEDIAN GAIN: ' num2str(MM) ', IQR ' num2str(iqr(lin_n.gain(chan_sel))) '\n'])
  2605. subplot(2,2,2); hold on;
  2606. % gain alpha U-LIN
  2607. histogram(lin_n.gain(chan_sel),-1000:50:1000,'FaceColor','k','FaceAlpha',0.5);
  2608. xlabel('gain LIN-POSNEG');ylabel('nChannels');
  2609. set(gca,'xlim',[-800 1700],'TickDir','out');
  2610. MM=median(lin_n.gain(chan_sel));
  2611. yy=get(gca,'ylim');
  2612. plot([MM MM], [0 yy(2)+40],'k','Linewidth',5)
  2613. set(gca,'ylim',[0 yy(2)+10]);
  2614. title('Gain selected channels (based on R2 ULIN>PLIN')
  2615. fprintf(['BETA MEDIAN GAIN: ' num2str(MM) ', IQR ' num2str(iqr(lin_n.gain(chan_sel))) '\n'])
  2616. % Wilcoxon 1-tailed < 1
  2617. [p,h,stats] = signrank(lin_n.gain(chan_sel),0,'tail','left');
  2618. fprintf(['Gain < 0: Wilcoxon z = ' ...
  2619. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2620. subplot(2,2,3); hold on;
  2621. bb = [lin_n.ecc(chan_sel) lin.ecc(chan_sel)];
  2622. mEcc = [mean(lin_n.ecc(chan_ngain)) mean(lin_n.ecc(chan_pgain))];
  2623. sdEcc = [std(lin_n.ecc(chan_ngain)) std(lin_n.ecc(chan_pgain))];
  2624. mdEcc = [median(lin_n.ecc(chan_ngain)) median(lin_n.ecc(chan_pgain))];
  2625. iqrEcc = [iqr(lin_n.ecc(chan_ngain)) iqr(lin_n.ecc(chan_pgain))]./2;
  2626. errorbar(1:2,mdEcc,iqrEcc,...
  2627. 'ko','MarkerSize',4,'MarkerFaceColor','k','Linewidth',2)
  2628. set(gca,'xtick',1:2,'xticklabels',{'ULIN-N','ULIN-P'},...
  2629. 'xlim',[0.8 2.2],'TickDir','out')
  2630. ylabel('Eccentricity');
  2631. title('Ecc')
  2632. % Ecc difference
  2633. fprintf('-- STATS Ecc --\n');
  2634. fprintf(['mEcc nGain U-LIN: ' num2str(mEcc(1)) ', STD ' num2str(sdEcc(1)) '\n'])
  2635. fprintf(['mEcc pGain U-LIN: ' num2str(mEcc(2)) ', STD ' num2str(sdEcc(2)) '\n'])
  2636. fprintf(['mdEcc nGain U-LIN: ' num2str(mdEcc(1)) ', IQR ' num2str(iqrEcc(1)) '\n'])
  2637. fprintf(['mdEcc pGain U-LIN: ' num2str(mdEcc(2)) ', IQR ' num2str(iqrEcc(2)) '\n'])
  2638. [p,h,stats] = ranksum(lin_n.ecc(chan_ngain),lin_n.ecc(chan_pgain));
  2639. fprintf(['Ecc difference pos gain U-LIN vs neg gain U-LIN: Wilcoxon z = ' ...
  2640. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2641. subplot(2,2,4); hold on;
  2642. bb = [lin_n.rfs(chan_sel) lin.rfs(chan_sel)];
  2643. mSz = [mean(lin_n.rfs(chan_ngain)) mean(lin_n.rfs(chan_pgain))];
  2644. sdSz = [std(lin_n.rfs(chan_ngain)) std(lin_n.rfs(chan_pgain))];
  2645. mdSz = [median(lin_n.rfs(chan_ngain)) median(lin_n.rfs(chan_pgain))];
  2646. iqrSz = [iqr(lin_n.rfs(chan_ngain)) iqr(lin_n.rfs(chan_pgain))]./2;
  2647. errorbar(1:2,mdSz,iqrSz,'ko','MarkerSize',4,'MarkerFaceColor','k','Linewidth',2)
  2648. set(gca,'xtick',1:4,'xticklabels',{'ULIN-N','ULIN-P'},...
  2649. 'xlim',[0.8 2.2],'TickDir','out')
  2650. ylabel('Size');
  2651. title('Size')
  2652. % Sz difference
  2653. fprintf('-- STATS Sz --\n');
  2654. fprintf(['mSz nGain U-LIN: ' num2str(mSz(1)) ', STD ' num2str(sdSz(1)) '\n'])
  2655. fprintf(['mSz pGain U-LIN: ' num2str(mSz(2)) ', STD ' num2str(sdSz(2)) '\n'])
  2656. fprintf(['mdSz nGain U-LIN: ' num2str(mdSz(1)) ', IQR ' num2str(iqrSz(1)) '\n'])
  2657. fprintf(['mdSz pGain U-LIN: ' num2str(mdSz(2)) ', IQR ' num2str(iqrSz(2)) '\n'])
  2658. [p,h,stats] = ranksum(lin_n.rfs(chan_ngain),lin_n.rfs(chan_pgain));
  2659. fprintf(['Sz difference pos gain U-LIN vs neg gain U-LIN: Wilcoxon z = ' ...
  2660. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2661. if SaveFigs
  2662. saveas(f_neg2,fullfile(pngfld, 'BETA_posneg_ecc_sz.png'));
  2663. saveas(f_neg2,fullfile(svgfld, 'BETA_posneg_ecc_sz.svg'));
  2664. end
  2665. if CloseFigs; close(f_neg2); end
  2666. %% Compare eccentricities between beta and gamma prfs =====================
  2667. lin_n = tLFP(...
  2668. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,'Beta'),:);
  2669. roi=1; % only do this for V1 channels
  2670. chan_sel = lin_n.Area==roi & lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh;
  2671. chan_sel2 = lin_n.Area==roi & lin_n.R2>R2th;
  2672. chan_pgain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain>0;
  2673. chan_ngain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain<0;
  2674. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2675. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2676. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2677. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2678. fextra=figure;
  2679. set(fextra,'Position',[10 10 600 1500]);
  2680. dE=[];
  2681. subplot(4,2,1);hold on;
  2682. plot([0 15],[0 15]);
  2683. scatter(lin_n.ecc(chan_ngain),lin_nGAM1.ecc(chan_ngain));
  2684. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2685. xlabel('B- CHAN: Ecc LOW GAM');ylabel('B- CHAN: Ecc BETA');
  2686. fprintf('Are Negative BETA pRF shifted relative to fixation from Low GAMMA?\n');
  2687. [p,h,stats] = signrank(lin_n.ecc(chan_ngain),lin_nGAM1.ecc(chan_ngain));
  2688. fprintf(['Median dEcc is ' ...
  2689. num2str(median(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))) ...
  2690. ' IQR ' ...
  2691. num2str(iqr(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2) ...
  2692. ' (POS --> towards fixation) \n']);
  2693. fprintf(['p = ' num2str(p) '\n']);
  2694. dE=[dE; ...
  2695. median(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain)) ...
  2696. iqr(lin_nGAM1.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2];
  2697. subplot(4,2,2);hold on;
  2698. plot([0 15],[0 15]);
  2699. scatter(lin_n.ecc(chan_pgain),lin_nGAM1.ecc(chan_pgain));
  2700. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2701. xlabel('B+ CHAN: Ecc LOW GAM');ylabel('B+ CHAN: Ecc BETA');
  2702. fprintf('Are Positive BETA pRF shifted relative to fixation from Low GAMMA?\n');
  2703. [p,h,stats] = signrank(lin_n.ecc(chan_pgain),lin_nGAM1.ecc(chan_pgain));
  2704. fprintf(['Median dEcc is ' ...
  2705. num2str(median(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))) ...
  2706. ' IQR ' ...
  2707. num2str(iqr(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2) ...
  2708. ' (POS --> towards fixation) \n']);
  2709. fprintf(['p = ' num2str(p) '\n']);
  2710. dE=[dE; ...
  2711. median(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain)) ...
  2712. iqr(lin_nGAM1.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2];
  2713. subplot(4,2,3);hold on;
  2714. plot([0 15],[0 15]);
  2715. scatter(lin_n.ecc(chan_ngain),lin_nGAM2.ecc(chan_ngain));
  2716. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2717. xlabel('B- CHAN: Ecc HIGH GAM');ylabel('B- CHAN: Ecc BETA');
  2718. fprintf('Are Negative BETA pRF shifted relative to fixation from High GAMMA?\n');
  2719. [p,h,stats] = signrank(lin_n.ecc(chan_ngain),lin_nGAM2.ecc(chan_ngain));
  2720. fprintf(['Median dEcc is ' ...
  2721. num2str(median(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))) ...
  2722. ' IQR ' ...
  2723. num2str(iqr(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2) ...
  2724. ' (POS --> towards fixation) \n']);
  2725. fprintf(['p = ' num2str(p) '\n']);
  2726. dE=[dE; ...
  2727. median(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain)) ...
  2728. iqr(lin_nGAM2.ecc(chan_ngain)-lin_n.ecc(chan_ngain))./2];
  2729. subplot(4,2,4);hold on;
  2730. plot([0 15],[0 15]);
  2731. scatter(lin_n.ecc(chan_pgain),lin_nGAM2.ecc(chan_pgain));
  2732. set(gca,'xlim',[0 15],'ylim',[0 15]);
  2733. xlabel('B+ CHAN: Ecc HIGH GAM');ylabel('B+ CHAN: Ecc BETA');
  2734. fprintf('Are Positive BETA pRF shifted relative to fixation from High GAMMA?\n');
  2735. [p,h,stats] = signrank(lin_n.ecc(chan_pgain),lin_nGAM2.ecc(chan_pgain));
  2736. fprintf(['Median dEcc is ' ...
  2737. num2str(median(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))) ...
  2738. ' IQR ' ...
  2739. num2str(iqr(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2) ...
  2740. ' (POS --> towards fixation) \n']);
  2741. fprintf(['p = ' num2str(p) '\n']);
  2742. dE=[dE; ...
  2743. median(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain)) ...
  2744. iqr(lin_nGAM2.ecc(chan_pgain)-lin_n.ecc(chan_pgain))./2];
  2745. subplot(4,2,5:8);hold on;
  2746. hold on;
  2747. bar(1:4, dE(:,1));
  2748. errorbar(1:4, dE(:,1), dE(:,2), 'k','Linestyle', 'none');
  2749. ylabel('dEcc Beta vs Gam')
  2750. set(gca,'xtick',1:4,'xticklabels',{'B- v lG','B+ v lG','B- v hG','B+ v hG'})
  2751. %% plot the diff in within channel pRF location for low/high LFP freq =====
  2752. fshiftprf = figure;
  2753. set(fshiftprf,'Position',[100 100 1600 1600]);
  2754. Xa1 = lin_n.X(chan_ngain); Ya1 = lin_n.Y(chan_ngain);
  2755. Xlg1 = lin_nGAM1.X(chan_ngain); Ylg1 = lin_nGAM1.Y(chan_ngain);
  2756. Xa2 = lin_n.X(chan_pgain); Ya2 = lin_n.Y(chan_pgain);
  2757. Xlg2 = lin_nGAM1.X(chan_pgain); Ylg2 = lin_nGAM1.Y(chan_pgain);
  2758. % only prfs within 8 deg for display
  2759. csel1 = Xa1<8 & Ya1<2 & Xlg1<8 & Ylg1<2 & ...
  2760. Xa1>-2 & Ya1>-8 & Xlg1>-2 & Ylg1>-8;
  2761. csel2 = Xa2<8 & Ya2<2 & Xlg2<8 & Ylg2<2 & ...
  2762. Xa2>-2 & Ya2>-8 & Xlg2>-2 & Ylg2>-8;
  2763. subplot(2,2,1);hold on;
  2764. plot([0 0],[-10 10],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2765. plot([-10 10],[0 0],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2766. quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2767. 'Color',[0.8 0.8 0.8],...
  2768. 'AutoScale',0,'ShowArrowHead',0); % lines from gam to alpha pRF
  2769. scatter(Xa1(csel1),Ya1(csel1),20,'ko','MarkerFaceColor','r'); % alpha pRF center
  2770. scatter(Xlg1(csel1),Ylg1(csel1),20,'ko','MarkerFaceColor','b'); % lgam prf center
  2771. % quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2772. % 'k','LineWidth',1,'AutoScale',1,'ShowArrowHead',1); % arrows from gam to alpha pRF
  2773. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g'); % fovea
  2774. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2775. 'FontName','Myriad Pro','TickDir','out');
  2776. xlabel('Horizontal dva');ylabel('Vertical dva');
  2777. shiftsz = sqrt((Xa1(csel1)-Xlg1(csel1)).^2 + (Ya1(csel1)-Ylg1(csel1)).^2);
  2778. m_ss = mean(shiftsz); se_ss = std(shiftsz)./sqrt(length(shiftsz));
  2779. fprintf(['Average negALPHA shift size: ' num2str(m_ss) ' +/- ' num2str(se_ss) ' SEM\n']);
  2780. subplot(2,2,2);hold on;
  2781. quiver(Xlg1(csel1),Ylg1(csel1),Xa1(csel1)-Xlg1(csel1),Ya1(csel1)-Ylg1(csel1),...
  2782. 'k','AutoScale',1,'ShowArrowHead',1)
  2783. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g')
  2784. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2785. 'FontName','Myriad Pro','TickDir','out');
  2786. xlabel('Horizontal dva');ylabel('Vertical dva');
  2787. subplot(2,2,3);hold on;
  2788. plot([0 0],[-10 10],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2789. plot([-10 10],[0 0],'--','LineWidth',2,'Color',[0.5 0.5 0.5]);
  2790. quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2791. 'Color',[0.8 0.8 0.8],...
  2792. 'AutoScale',0,'ShowArrowHead',0); % lines from gam to alpha pRF
  2793. scatter(Xa2(csel2),Ya2(csel2),20,'ko','MarkerFaceColor','r'); % alpha pRF center
  2794. scatter(Xlg2(csel2),Ylg2(csel2),20,'ko','MarkerFaceColor','b'); % lgam prf center
  2795. % quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2796. % 'k','LineWidth',1,'AutoScale',1,'ShowArrowHead',1); % arrows from gam to alpha pRF
  2797. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g'); % fovea
  2798. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2799. 'FontName','Myriad Pro','TickDir','out');
  2800. xlabel('Horizontal dva');ylabel('Vertical dva');
  2801. shiftsz = sqrt((Xa2(csel2)-Xlg2(csel2)).^2 + (Ya2(csel2)-Ylg2(csel2)).^2);
  2802. m_ss = mean(shiftsz); se_ss = std(shiftsz)./sqrt(length(shiftsz));
  2803. fprintf(['Average posALPHA shift size: ' num2str(m_ss) ' +/- ' num2str(se_ss) ' SEM\n']);
  2804. subplot(2,2,4);hold on;
  2805. quiver(Xlg2(csel2),Ylg2(csel2),Xa2(csel2)-Xlg2(csel2),Ya2(csel2)-Ylg2(csel2),...
  2806. 'k','AutoScale',1,'ShowArrowHead',1)
  2807. plot(0,0,'go','MarkerSize',8,'MarkerFaceColor','g')
  2808. set(gca,'xlim',[-1.5 8.2],'ylim',[-6.5 2.2],'FontSize',14,...
  2809. 'FontName','Myriad Pro','TickDir','out');
  2810. xlabel('Horizontal dva');ylabel('Vertical dva');
  2811. if SaveFigs
  2812. saveas(fextra,fullfile(pngfld, 'BETAvGAM_posneg_ecc_sz.png'));
  2813. saveas(fextra,fullfile(svgfld, 'BETAvGAM_posneg_ecc_sz.svg'));
  2814. end
  2815. if CloseFigs; close(fextra); end
  2816. %% Beta vs Gamma pRF separation index =====================================
  2817. lin_n = tLFP(...
  2818. strcmp(tLFP.Model,'linear_ephys_cv1_neggain') & strcmp(tLFP.SigType,'Beta'),:);
  2819. roi=1; % only do this for V1 channels
  2820. chan_sel = lin_n.Area==roi & lin_n.R2>R2th & lin_n.R2>lin.R2+R2enh;
  2821. chan_sel2 = lin_n.Area==roi & lin_n.R2>R2th;
  2822. chan_pgain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain>0;
  2823. chan_ngain = lin_n.Area==roi & lin_n.R2>R2th & lin_n.gain<0;
  2824. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2825. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2826. chan_gam1 = lin_n.Area==roi & lin_nGAM1.R2>R2th;
  2827. chan_gam2 = lin_n.Area==roi & lin_nGAM2.R2>R2th;
  2828. [mean(sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2829. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2)) ...
  2830. std(sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2831. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2))./sqrt(sum(chan_ngain))]
  2832. [mean(sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2833. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2)) ...
  2834. std(sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2835. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2))./sqrt(sum(chan_pgain))]
  2836. [mean(sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2837. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2)) ...
  2838. std(sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2839. (lin_n.Y(chan_ngain)-lin_nGAM2.Y(chan_ngain)).^2))./sqrt(sum(chan_ngain))]
  2840. [mean(sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2841. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2)) ...
  2842. std(sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2843. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2))./sqrt(sum(chan_pgain))]
  2844. fprintf('=== BETA ===\n')
  2845. % size
  2846. fprintf('Size diff (a-lG)\n')
  2847. fprintf('NGAIN\n')
  2848. [mean(lin_n.rfs(chan_ngain)-lin_nGAM1.rfs(chan_ngain)) ...
  2849. std(lin_n.rfs(chan_ngain)-lin_nGAM1.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2850. fprintf('PGAIN\n')
  2851. [mean(lin_n.rfs(chan_pgain)-lin_nGAM1.rfs(chan_pgain)) ...
  2852. std(lin_n.rfs(chan_pgain)-lin_nGAM1.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2853. % normalized size
  2854. fprintf('Norm Size diff (a/lG)\n')
  2855. fprintf('NGAIN\n')
  2856. [mean(lin_n.rfs(chan_ngain)./lin_nGAM1.rfs(chan_ngain)) ...
  2857. std(lin_n.rfs(chan_ngain)./lin_nGAM1.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2858. fprintf('PGAIN\n')
  2859. [mean(lin_n.rfs(chan_pgain)./lin_nGAM1.rfs(chan_pgain)) ...
  2860. std(lin_n.rfs(chan_pgain)./lin_nGAM1.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2861. fprintf('Norm Size diff (a/hG)\n')
  2862. fprintf('NGAIN\n')
  2863. [mean(lin_n.rfs(chan_ngain)./lin_nGAM2.rfs(chan_ngain)) ...
  2864. std(lin_n.rfs(chan_ngain)./lin_nGAM2.rfs(chan_ngain))./sqrt(sum(chan_ngain))]
  2865. fprintf('PGAIN\n')
  2866. [mean(lin_n.rfs(chan_pgain)./lin_nGAM2.rfs(chan_pgain)) ...
  2867. std(lin_n.rfs(chan_pgain)./lin_nGAM2.rfs(chan_pgain))./sqrt(sum(chan_pgain))]
  2868. % distance in relation to size
  2869. distn = sqrt((lin_n.X(chan_ngain)-lin_nGAM1.X(chan_ngain)).^2 + ...
  2870. (lin_n.Y(chan_ngain)-lin_nGAM1.Y(chan_ngain)).^2);
  2871. distp = sqrt((lin_n.X(chan_pgain)-lin_nGAM1.X(chan_pgain)).^2 + ...
  2872. (lin_n.Y(chan_pgain)-lin_nGAM1.Y(chan_pgain)).^2);
  2873. sz2n=lin_n.rfs(chan_ngain)+lin_nGAM1.rfs(chan_ngain);
  2874. sz2p=lin_n.rfs(chan_pgain)+lin_nGAM1.rfs(chan_pgain);
  2875. fextra=figure;
  2876. set(fextra,'Position',[10 10 600 1500]);
  2877. subplot(4,2,1);hold on;
  2878. scatter(distn,sz2n);
  2879. scatter(distp,sz2p);
  2880. plot([0 20],[0 20]);
  2881. set(gca,'xlim',[0 20],'ylim',[0 20]);
  2882. xlabel('distance B-G pRF');ylabel('sumsize B-G pRF')
  2883. legend({'negative', 'positive'});
  2884. fprintf('DIST REL/Sz (dist/(s1+s2))\n')
  2885. subplot(4,2,2);hold on;
  2886. fprintf('lG NEG\n')
  2887. fprintf('mean std median iqr\n')
  2888. [mean(distn./sz2n) std(distn./sz2n)./sqrt(sum(chan_ngain))...
  2889. median(distn./sz2n) iqr(distn./sz2n)./2]
  2890. histogram(distn./sz2n,100,'Normalization','probability')
  2891. fprintf('lG POS\n')
  2892. [mean(distp./sz2p) std(distp./sz2p)./sqrt(sum(chan_pgain))...
  2893. median(distp./sz2p) iqr(distp./sz2p)./2]
  2894. histogram(distp./sz2p,100,'Normalization','probability')
  2895. title('Low Gamma'); xlabel('Separation Index');
  2896. BC=[median(distn./sz2n) median(distp./sz2p)];
  2897. BCE=[iqr(distn./sz2n)/2 iqr(distp./sz2p)/2];
  2898. distn = sqrt((lin_n.X(chan_ngain)-lin_nGAM2.X(chan_ngain)).^2 + ...
  2899. (lin_n.Y(chan_ngain)-lin_nGAM2.Y(chan_ngain)).^2);
  2900. distp = sqrt((lin_n.X(chan_pgain)-lin_nGAM2.X(chan_pgain)).^2 + ...
  2901. (lin_n.Y(chan_pgain)-lin_nGAM2.Y(chan_pgain)).^2);
  2902. sz2n=lin_n.rfs(chan_ngain)+lin_nGAM2.rfs(chan_ngain);
  2903. sz2p=lin_n.rfs(chan_pgain)+lin_nGAM2.rfs(chan_pgain);
  2904. subplot(4,2,3);hold on;
  2905. scatter(distn,sz2n);
  2906. scatter(distp,sz2p);
  2907. plot([0 20],[0 20]);
  2908. xlabel('distance B-G pRF');ylabel('sumsize B-G pRF')
  2909. set(gca,'xlim',[0 20],'ylim',[0 20]);
  2910. legend({'negative', 'positive'});
  2911. subplot(4,2,4);hold on;
  2912. fprintf('hG NEG\n')
  2913. fprintf('mean std median iqr\n')
  2914. [mean(distn./sz2n) std(distn./sz2n)./sqrt(sum(chan_ngain))...
  2915. median(distn./sz2n) iqr(distn./sz2n)./2]
  2916. histogram(distn./sz2n,100,'Normalization','probability')
  2917. fprintf('hG POS\n')
  2918. [mean(distp./sz2p) std(distp./sz2p)./sqrt(sum(chan_pgain))...
  2919. median(distp./sz2p) iqr(distp./sz2p)./2]
  2920. histogram(distp./sz2p,100,'Normalization','probability')
  2921. title('High Gamma'); xlabel('Separation Index');
  2922. BC=[BC median(distn./sz2n) median(distp./sz2p)];
  2923. BCE=[BCE iqr(distn./sz2n)/2 iqr(distp./sz2p)/2];
  2924. subplot(4,2,5:8); hold on;
  2925. bar(1:4, BC);
  2926. ylabel('Separation Index')
  2927. errorbar(1:4, BC, BCE, 'k', 'Linestyle','none')
  2928. set(gca, 'xtick',1:4,'xticklabels',{'lG-','lG+','hG-','hG+'})
  2929. if SaveFigs
  2930. saveas(fextra,fullfile(pngfld, 'BETAvGAM_sepidx.png'));
  2931. saveas(fextra,fullfile(svgfld, 'BETAvGAM_sepidx.svg'));
  2932. end
  2933. if CloseFigs; close(fextra); end
  2934. %% Beta DoG ===============================================================
  2935. chan_sel = DoG.R2>R2th & DoG.R2>lin.R2+R2enh & ...
  2936. DoG.normamp~=0 & DoG.ecc<16;
  2937. MM=median(DoG.normamp(chan_sel));
  2938. fprintf(['BETA MEDIAN NAMP: ' num2str(MM) ', IQR ' num2str(iqr(DoG.normamp(chan_sel))) '\n'])
  2939. % Wilcoxon 1-tailed < 1
  2940. [p,h,stats] = signrank(lin_n.gain(chan_sel),0,'tail','left');
  2941. fprintf(['Gain < 0: Wilcoxon z = ' ...
  2942. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2943. bb = [DoG.ecc(chan_sel) lin.ecc(chan_sel)];
  2944. % Wilcoxon
  2945. [p,h,stats] = signrank(bb(:,1),bb(:,2));
  2946. fprintf(['ECC diff Wilcoxon z = ' ...
  2947. num2str(stats.zval) ', p = ' num2str(p) '\n']);
  2948. MM=median(bb(:,2)-bb(:,1));
  2949. fprintf(['BETA MEDIAN ECC DIFF: ' num2str(median(lin.ecc(chan_sel)-DoG.ecc(chan_sel))) ...
  2950. ', IQR ' num2str(iqr(lin.ecc(chan_sel)-DoG.ecc(chan_sel))) '\n'])
  2951. %% ========================================================================
  2952. % FMRI-EPHYS PRF ANALYSIS ------------------------------------------------
  2953. % ========================================================================
  2954. %% Fig 12 & SFig 12: Correlate MRI-ephys REGRESSION BASED =================
  2955. % based on the ecc vs size correlation
  2956. % PER SIGNAL SOURCE
  2957. % - calculate linear regression on random (filtered) subset of data
  2958. % - repeat
  2959. % - filter results
  2960. % ACROSS SIGNAL SOURCES
  2961. % - correlate the bootstrapped fit-result parameters
  2962. % - optional >> do this in a bootstrapped way
  2963. rng(1); % seed the random number generator
  2964. % adjust these to check robustness ----------------------------------------
  2965. Rth_mri = 5; % R2 threshold MRI
  2966. Rth_ephys = 50; % R2 threshold ephys
  2967. selVFC = 1; % if true, only use lower right visual quadrant
  2968. selANAT = 0; % if true, only use approximate area of electrodes
  2969. ephysSUB = 'Both';
  2970. % -------------------------------------------------------------------------
  2971. MaxECC = [10 30]; % max ecc to use for fitting [V1 V4]
  2972. MODS = {...
  2973. 'linhrf_cv1_mhrf','linear_ephys_cv1';...
  2974. 'linhrf_cv1_mhrf_neggain','linear_ephys_cv1_neggain';...
  2975. 'csshrf_cv1_mhrf','css_ephys_cv1';...
  2976. 'doghrf_cv1_mhrf','dog_ephys_cv1';...
  2977. };
  2978. MRI_MODEL = MODS(:,1); EPHYS_MODEL = MODS(:,2);
  2979. MMS={'linear','linear_ng','css','dog'};
  2980. warning off;
  2981. cmROI = {'V1','V4'};
  2982. fprintf('=======================\n');
  2983. for m = 3 % select which model
  2984. fprintf(['\nCrossmodal Correlation for Model: ' MODS{m} '\n']);
  2985. s_R2 = T(modidx.(MRI_MODEL{m})).mod.R2 > Rth_mri & ...
  2986. T(modidx.(MRI_MODEL{m})).mod.rfs < 1000;
  2987. % collect mri prfs
  2988. for r = 1:size(cmROI,2)
  2989. if ~selANAT
  2990. SSS = s_R2 & ismember( T(modidx.(MRI_MODELS{m})).mod.ROI,...
  2991. ck_GetROIidx(cmROI(r),rois) );
  2992. else
  2993. if strcmp(cmROI{r},'V1')
  2994. SSS = s_R2 & T(modidx.(MRI_MODEL{m})).mod.ELEC_V1 > 0 & ...
  2995. ismember( T(modidx.(MRI_MODELS{m})).mod.ROI,...
  2996. ck_GetROIidx(cmROI(r),rois) );
  2997. elseif strcmp(cmROI{r},'V4')
  2998. SSS = s_R2 & T(modidx.(MRI_MODEL{m})).mod.ELEC_V4 > 0 & ...
  2999. ismember( T(modidx.(MRI_MODELS{m})).mod.ROI,...
  3000. ck_GetROIidx(cmROI(r),rois) );
  3001. end
  3002. end
  3003. if selVFC
  3004. VFSEL = T(modidx.(MRI_MODEL{m})).mod.X >= 0 & ...
  3005. T(modidx.(MRI_MODEL{m})).mod.Y <=0;
  3006. SSS = SSS & VFSEL;
  3007. end
  3008. % if selANAT && strcmp(cmROI{r},'V1')
  3009. % ANATSEL = T(modidx.(MRI_MODEL{m})).mod.ELEC_V1 > 0;
  3010. % SSS = SSS & ANATSEL;
  3011. % elseif selANAT && strcmp(cmROI{r},'V4')
  3012. % ANATSEL = T(modidx.(MRI_MODEL{m})).mod.ELEC_V4 > 0;
  3013. % SSS = SSS & ANATSEL;
  3014. % end
  3015. if strcmp(cmROI{r},'V1') % V1
  3016. mri1(m).ECC = T(modidx.(MRI_MODEL{m})).mod.ecc(SSS);
  3017. mri1(m).S = T(modidx.(MRI_MODEL{m})).mod.rfs(SSS);
  3018. mri1(m).G = T(modidx.(MRI_MODEL{m})).mod.gain(SSS);
  3019. elseif strcmp(cmROI{r},'V4') % V4
  3020. mri4(m).ECC = T(modidx.(MRI_MODEL{m})).mod.ecc(SSS);
  3021. mri4(m).S = T(modidx.(MRI_MODEL{m})).mod.rfs(SSS);
  3022. mri4(m).G = T(modidx.(MRI_MODEL{m})).mod.gain(SSS);
  3023. end
  3024. end
  3025. % collect ephys prfs
  3026. % MUA V1
  3027. if strcmp(ephysSUB,'M03') || strcmp(ephysSUB,'M04')
  3028. s = strcmp(tMUA.Model,EPHYS_MODEL{m}) & ...
  3029. strcmp(tMUA.Monkey,ephysSUB) & ...
  3030. tMUA.Area == 1 & tMUA.R2 > Rth_ephys & tMUA.rfs < 1000;
  3031. else
  3032. s = strcmp(tMUA.Model,EPHYS_MODEL{m}) & ...
  3033. tMUA.Area == 1 & tMUA.R2 > Rth_ephys & tMUA.rfs < 1000;
  3034. end
  3035. % Exclude 2 outlier V1 arrays in both monkeys
  3036. s2 = ( strcmp(tMUA.Monkey,'M03') & (tMUA.Array == 11 | tMUA.Array == 13)) | ...
  3037. ( strcmp(tMUA.Monkey,'M04') & (tMUA.Array == 10 | tMUA.Array == 12));
  3038. s(s2) = false;
  3039. mua1(m).ECC = tMUA.ecc(s);
  3040. mua1(m).S = tMUA.rfs(s);
  3041. mua1(m).G = tMUA.gain(s);
  3042. % MUA V4
  3043. s = strcmp(tMUA.Model,EPHYS_MODEL{m}) & ...
  3044. tMUA.Area == 4 & tMUA.R2 > Rth_ephys & tMUA.rfs < 1000;
  3045. mua4(m).ECC = tMUA.ecc(s);
  3046. mua4(m).S = tMUA.rfs(s);
  3047. mua4(m).G = tMUA.gain(s);
  3048. % LFP
  3049. freqband=unique(tLFP.SigType);
  3050. for fb = 1: length(freqband)
  3051. % V1
  3052. if strcmp(ephysSUB,'M03') || strcmp(ephysSUB,'M04')
  3053. s = strcmp(tLFP.Model,EPHYS_MODEL{m}) & ...
  3054. strcmp(tLFP.Monkey,ephysSUB) & ...
  3055. tLFP.Area == 1 & tLFP.R2 > Rth_ephys & tLFP.rfs < 1000 & ...
  3056. strcmp(tLFP.SigType, freqband{fb});
  3057. else
  3058. s = strcmp(tLFP.Model,EPHYS_MODEL{m}) & ...
  3059. tLFP.Area == 1 & tLFP.R2 > Rth_ephys & tLFP.rfs < 1000 & ...
  3060. strcmp(tLFP.SigType, freqband{fb});
  3061. end
  3062. s2 = ( strcmp(tMUA.Monkey,'M03') & (tMUA.Array == 11 | tMUA.Array == 13)) | ...
  3063. ( strcmp(tMUA.Monkey,'M04') & (tMUA.Array == 10 | tMUA.Array == 12));
  3064. s(s2) = false;
  3065. lfp1(fb,m).freqband = freqband{fb};
  3066. lfp1(fb,m).ECC = tLFP.ecc(s);
  3067. lfp1(fb,m).S = tLFP.rfs(s);
  3068. lfp1(fb,m).G = tLFP.gain(s);
  3069. % V4
  3070. s = strcmp(tLFP.Model,EPHYS_MODEL{m}) & ...
  3071. tLFP.Area == 4 & tLFP.R2 > Rth_ephys & tLFP.rfs < 1000 & ...
  3072. strcmp(tLFP.SigType, freqband{fb});
  3073. lfp4(fb,m).freqband = freqband{fb};
  3074. lfp4(fb,m).ECC = tLFP.ecc(s);
  3075. lfp4(fb,m).S = tLFP.rfs(s);
  3076. lfp4(fb,m).G = tLFP.gain(s);
  3077. end
  3078. % Calculate & bootstrap linear regressions
  3079. % =============================================
  3080. fprintf('Performing regressions on ALL data\n')
  3081. MRI_stats1 = regstats(mri1(m).S,mri1(m).ECC);
  3082. MRI_stats4 = regstats(mri4(m).S,mri4(m).ECC);
  3083. MUA_stats1 = regstats(mua1(m).S,mua1(m).ECC);
  3084. MUA_stats4 = regstats(mua4(m).S,mua4(m).ECC);
  3085. for fb=1:length(freqband)
  3086. try
  3087. LFP_stats1{fb} = regstats(lfp1(fb,m).S,lfp1(fb,m).ECC);
  3088. catch
  3089. LFP_stats1{fb} = [];
  3090. end
  3091. try
  3092. LFP_stats4{fb} = regstats(lfp4(fb,m).S,lfp4(fb,m).ECC);
  3093. catch
  3094. LFP_stats4{fb} = [];
  3095. end
  3096. end
  3097. % Do statistics on model comparisons with fitlm
  3098. ck_xmod_stats;
  3099. XMOD(m).model = MMS{m}; XMOD(m).stats = stats;
  3100. if m==2
  3101. ck_xmod_stats_lowfreqlfp;
  3102. end
  3103. end
  3104. warning on;
  3105. %% Fig 11C: Cross-signal comparison exponential parameter =================
  3106. RTHRES = 25;
  3107. clear exptvals_MUA exptvals_LFP exptvals_MRI kw
  3108. rois2 = [1 4];
  3109. f=figure;set(f,'Position',[10 10 1200 500]);
  3110. ephysSub='M04';
  3111. for r=1:length(rois2)
  3112. kw{r}=[];
  3113. exptvals_MRI{r} = [exptv(1).roi{rois2(r)};exptv(2).roi{rois2(r)}];
  3114. kw{r}=[kw{r}; exptvals_MRI{r} ones(size(exptvals_MRI{r}))];
  3115. if strcmp(ephysSub,'M03') || strcmp(ephysSub,'M04')
  3116. exptvals_MUA{r} = tMUA.expt(strcmp(tMUA.Model,'css_ephys_cv1') & ...
  3117. strcmp(tMUA.Monkey,ephysSub) & strcmp(tMUA.SigType,'MUA') & ...
  3118. tMUA.Area==rois2(r) & tMUA.R2 > RTHRES );
  3119. fprintf(['Only ' ephysSub '\n'])
  3120. else
  3121. exptvals_MUA{r} = tMUA.expt(strcmp(tMUA.Model,'css_ephys_cv1') & ...
  3122. strcmp(tMUA.SigType,'MUA') & tMUA.Area==rois2(r) & tMUA.R2 > RTHRES );
  3123. end
  3124. kw{r}=[kw{r}; exptvals_MUA{r} 2*ones(size(exptvals_MUA{r}))];
  3125. sig=unique(tLFP.SigType);
  3126. lfp_order = [3 1 2 5 4]; spn=1;
  3127. cl=2;
  3128. for fb=lfp_order
  3129. cl=cl+1;
  3130. if strcmp(ephysSub,'M03') || strcmp(ephysSub,'M04')
  3131. exptvals_LFP{r,spn} = tLFP.expt(strcmp(tLFP.Model,'css_ephys_cv1') & ...
  3132. strcmp(tLFP.Monkey,ephysSub) & strcmp(tLFP.SigType,sig{fb}) & ...
  3133. tLFP.Area==rois2(r) & tLFP.R2 > RTHRES );
  3134. fprintf(['Only ' ephysSub '\n'])
  3135. else
  3136. exptvals_LFP{r,spn} = tLFP.expt(strcmp(tLFP.Model,'css_ephys_cv1') & ...
  3137. strcmp(tLFP.SigType,sig{fb}) & tLFP.Area==rois2(r) & tLFP.R2 > RTHRES );
  3138. end
  3139. if size(exptvals_LFP{r,spn},1)>3
  3140. kw{r}=[kw{r}; exptvals_LFP{r,spn} cl*ones(size(exptvals_LFP{r,spn}))];
  3141. end
  3142. spn=spn+1;
  3143. end
  3144. figure(f);
  3145. subplot(1,2,r); hold on;
  3146. bar(1:7,[mean(exptvals_MRI{r}) ...
  3147. mean(exptvals_MUA{r}) ...
  3148. mean(exptvals_LFP{r,1}) ...
  3149. mean(exptvals_LFP{r,2}) ...
  3150. mean(exptvals_LFP{r,3}) ...
  3151. mean(exptvals_LFP{r,4}) ...
  3152. mean(exptvals_LFP{r,5})]);
  3153. errorbar(1:7,[mean(exptvals_MRI{r}) ...
  3154. mean(exptvals_MUA{r}) ...
  3155. mean(exptvals_LFP{r,1}) ...
  3156. mean(exptvals_LFP{r,2}) ...
  3157. mean(exptvals_LFP{r,3}) ...
  3158. mean(exptvals_LFP{r,4}) ...
  3159. mean(exptvals_LFP{r,5})],...
  3160. [std(exptvals_MRI{r}) ...
  3161. std(exptvals_MUA{r}) ...
  3162. std(exptvals_LFP{r,1}) ...
  3163. std(exptvals_LFP{r,2}) ...
  3164. std(exptvals_LFP{r,3}) ...
  3165. std(exptvals_LFP{r,4}) ...
  3166. std(exptvals_LFP{r,5})],'ko','Linestyle','none')
  3167. set(gca,'xlim',[.5 7.5],'ylim',[0 1.1],'xtick',1:7,'xticklabels',...
  3168. {'MRI','MUA', 'THETA','ALPHA','BETA','lGAM','hGAM'})
  3169. title(['V' num2str(rois2(r))])
  3170. ylabel('pRF exponent')
  3171. fprintf('-- Compare < 1 --\n');
  3172. fprintf(['AREA V' num2str(rois2(r)) '\n']);
  3173. [p,h,stats] = signrank(exptvals_MRI{r},1,'tail','left');
  3174. fprintf(['MRI, Wilcoxon EXPT < 1 : z = ' num2str(stats.zval) ', p = ' num2str(p) '\n']);
  3175. [p,h,stats] = signrank(exptvals_MUA{r},1,'tail','left');
  3176. fprintf(['MUA, Wilcoxon EXPT < 1 : z = ' num2str(stats.zval) ', p = ' num2str(p) '\n']);
  3177. for i=1:5
  3178. if size(exptvals_LFP{r,i},1) > 5
  3179. [p,h,stats] = signrank(exptvals_LFP{r,i},1,'tail','left');
  3180. if isfield(stats,'zval')
  3181. fprintf(['LFP-' num2str(i) ', Wilcoxon EXPT < 1 : z = ' num2str(stats.zval) ', p = ' num2str(p) '\n']);
  3182. end
  3183. end
  3184. end
  3185. fprintf('-- Compare across signals --\n');
  3186. fprintf(['AREA V' num2str(rois2(r)) '\n']);
  3187. [expcss(r).p,expcss(r).tbl,expcss(r).stats] = kruskalwallis(kw{r}(:,1), kw{r}(:,2));
  3188. [expcss(r).c,expcss(r).m,expcss(r).h,expcss(r).gnames] = multcompare(expcss(r).stats);
  3189. end
  3190. if SaveFigs
  3191. saveas(f,fullfile(pngfld, 'xsig_prfexp.png'));
  3192. saveas(f,fullfile(svgfld, 'xsig_prfexp.svg'));
  3193. end
  3194. if CloseFigs; close(f); end
  3195. %% ========================================================================
  3196. % CLEAN UP ---------------------------------------------------------------
  3197. % ========================================================================
  3198. %% clear and close
  3199. close all; clc;