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.

behavioralAnalyses.m 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. clear all; close all; clc;
  2. addpath('./support_functions');
  3. figures_folder='../figures';
  4. plotopts.Fig1B=0; % includes SuppFigS3A
  5. plotopts.Fig1C=0; % handle memory usage
  6. plotopts.Fig1D=0; % includes SuppFigS2
  7. plotopts.Fig2A=0;
  8. plotopts.Fig2B=0;
  9. plotopts.Fig2C=0; % includes SuppFigS4
  10. plotopts.Fig2D=0;
  11. twinNames={'preoffer1','offer1','delay1','offer2','delay2','re-fixate','choice-go','choice-hold'};
  12. subjsData(1).sbdata=getSubjectData(1);
  13. subjsData(2).sbdata=getSubjectData(2);
  14. s1gbi=getBehavioralInfos(subjsData(1).sbdata);
  15. s2gbi=getBehavioralInfos(subjsData(2).sbdata);
  16. s1gem1=getEyeTracks(subjsData(1).sbdata,'all','preoffer1','offer1');
  17. s1gem2=getEyeTracks(subjsData(1).sbdata,'all','offer1','delay1');
  18. s1gem3=getEyeTracks(subjsData(1).sbdata,'all','delay1','offer2');
  19. s1gem4=getEyeTracks(subjsData(1).sbdata,'all','offer2','delay2');
  20. s1gem5=getEyeTracks(subjsData(1).sbdata,'all','delay2','startfix');
  21. s1gem6=getEyeTracks(subjsData(1).sbdata,'all','startfix','choicego');
  22. s1gem7=getEyeTracks(subjsData(1).sbdata,'all','choicego','choicesacc');
  23. s1gem8=getEyeTracks(subjsData(1).sbdata,'all','choicesacc','choicemade');
  24. s2gem1=getEyeTracks(subjsData(2).sbdata,'all','preoffer1','offer1');
  25. s2gem2=getEyeTracks(subjsData(2).sbdata,'all','offer1','delay1');
  26. s2gem3=getEyeTracks(subjsData(2).sbdata,'all','delay1','offer2');
  27. s2gem4=getEyeTracks(subjsData(2).sbdata,'all','offer2','delay2');
  28. s2gem5=getEyeTracks(subjsData(2).sbdata,'all','delay2','startfix');
  29. s2gem6=getEyeTracks(subjsData(2).sbdata,'all','startfix','choicego');
  30. s2gem7=getEyeTracks(subjsData(2).sbdata,'all','choicego','choicesacc');
  31. s2gem8=getEyeTracks(subjsData(2).sbdata,'all','choicesacc','choicemade');
  32. if plotopts.Fig1B
  33. %% Fig. 1B and Supp. Fig. S3A - Choice vs difference in EV
  34. nluqEV=-3:.05:3; % binning EV difference in 0.05 nominal units
  35. s1o1evsd1=s1gbi.offer1ev(s1gbi.ifLsR); s1o1evsd2=s1gbi.offer1ev(s1gbi.ifRsL);
  36. s1o2evsd1=s1gbi.offer2ev(s1gbi.ifLsR); s1o2evsd2=s1gbi.offer2ev(s1gbi.ifRsL);
  37. s2o1evsd1=s2gbi.offer1ev(s2gbi.ifLsR); s2o1evsd2=s2gbi.offer1ev(s2gbi.ifRsL);
  38. s2o2evsd1=s2gbi.offer2ev(s2gbi.ifLsR); s2o2evsd2=s2gbi.offer2ev(s2gbi.ifRsL);
  39. s1chsd1=s1gbi.choose12(s1gbi.ifLsR)==1; s1chsd2=s1gbi.choose12(s1gbi.ifRsL)==1;
  40. s2chsd1=s2gbi.choose12(s2gbi.ifLsR)==1; s2chsd2=s2gbi.choose12(s2gbi.ifRsL)==1;
  41. x1=[s1o2evsd1-s1o1evsd1; -s1o2evsd2+s1o1evsd2];
  42. y1=[1-s1chsd1; s1chsd2];
  43. g1=fitglm(x1,y1,'Distribution','binomial','link','logit');
  44. g1cci=g1.coefCI;
  45. bs1.p=g1.Coefficients.pValue;
  46. b1=g1.Coefficients.Estimate;
  47. bx1 = b1(1) + (x1*b1(2));
  48. hx1 = 1 ./ (1 + exp(-sort(bx1)));
  49. x2=[s2o2evsd1-s2o1evsd1; -s2o2evsd2+s2o1evsd2];
  50. y2=[1-s2chsd1; s2chsd2];
  51. g2=fitglm(x2,y2,'Distribution','binomial','link','logit');
  52. g2cci=g2.coefCI;
  53. bs2.p=g2.Coefficients.pValue;
  54. b2=g2.Coefficients.Estimate;
  55. bx2 = b2(1) + (x2*b2(2));
  56. hx2 = 1 ./ (1 + exp(-sort(bx2)));
  57. x3=[ x1; x2];
  58. y3=[ y1; y2];
  59. g3=fitglm(x3,y3,'Distribution','binomial','link','logit');
  60. g3cci=g3.coefCI;
  61. bs3.p=g3.Coefficients.pValue;
  62. b3=g3.Coefficients.Estimate;
  63. bx3 = b3(1) + (x3*b3(2));
  64. hx3 = 1 ./ (1 + exp(-sort(bx3)));
  65. [zq1,xq1]=nanmeanquantized(nluqEV,x1,y1);
  66. [zq2,xq2]=nanmeanquantized(nluqEV,x2,y2);
  67. [zq3,xq3]=nanmeanquantized(nluqEV,x3,y3);
  68. hfig=figure('units','normalized','outerposition',[0 0 .3 .3]);
  69. subplot(1,2,1);
  70. plot(xq3,zq3,'.','color',[0 150 0]./255); hold on;
  71. plot(sort(x3),hx3,'-','color',[0 150 0]./255); plot([0 0],[0 1],'k-');
  72. plot([-3 0],[1 1]./(1+exp(-b3(1))),'--','color',[0 150 0]./255)
  73. fill([xq3 -xq3],[glmval(g3cci(:,1),xq3,'logit')' flip(glmval(g3cci(:,2),xq3,'logit')')],[0 150 0]./255,'edgecolor','none','facealpha',.15);
  74. xlabel('EV_R-EV_L'); ylabel('chR');
  75. title('Subject 1,2: all sessions'); xlim([-3 3]); daspect([6 1 1]);
  76. text(4,.9,sprintf(['\\beta_0 %1.4f' getpstars(bs3.p(1)) ';'],b3(1)));
  77. text(4,.8,sprintf(['\\beta_1 %1.4f' getpstars(bs3.p(2)) ';'],b3(2)));
  78. text(4,.7,sprintf('n= %d;',length(x3)));
  79. saveas(hfig,[figures_folder '/Fig1B_ratio_chosen_right_vs_offer_diff_ev.fig']);
  80. saveas(hfig,[figures_folder '/Fig1B_ratio_chosen_right_vs_offer_diff_ev.png']);
  81. saveas(hfig,[figures_folder '/Fig1B_ratio_chosen_right_vs_offer_diff_ev.svg']);
  82. hfig=figure('units','normalized','outerposition',[0 0 1 .3]);
  83. subplot(1,2,1);
  84. plot(xq1,zq1,'.','color',[250 0 0]./255); hold on;
  85. plot(sort(x1),hx1,'-','color',[250 0 0]./255); plot([0 0],[0 1],'k-');
  86. plot([-3 0],[1 1]./(1+exp(-b1(1))),'--','color',[250 0 0]./255)
  87. fill([xq1 -xq1],[glmval(g1cci(:,1),xq1,'logit')' flip(glmval(g1cci(:,2),xq1,'logit')')],[250 0 0]./255,'edgecolor','none','facealpha',.15);
  88. xlabel('EV_R-EV_L'); ylabel('chR'); title('Subject 1: all sessions'); xlim([-3 3]); daspect([6 1 1]);
  89. text(4,.9,sprintf(['\\beta_0 %1.4f' getpstars(bs1.p(1)) ';'],b1(1)));
  90. text(4,.8,sprintf(['\\beta_1 %1.4f' getpstars(bs1.p(2)) ';'],b1(2)));
  91. text(4,.7,sprintf('n= %d;',length(x1)));
  92. subplot(1,2,2);
  93. plot(xq2,zq2,'.','color',[0 0 250]./255); hold on;
  94. plot(sort(x2),hx2,'-','color',[0 0 250]./255); plot([0 0],[0 1],'k-');
  95. plot([-3 0],[1 1]./(1+exp(-b2(1))),'--','color',[0 0 250]./255)
  96. fill([xq2 -xq2],[glmval(g2cci(:,1),xq2,'logit')' flip(glmval(g2cci(:,2),xq1,'logit')')],[0 0 250]./255,'edgecolor','none','facealpha',.15);
  97. xlabel('EV_R-EV_L'); ylabel('chR'); title('Subject 2: all sessions'); xlim([-3 3]); daspect([6 1 1]);
  98. text(4,.9,sprintf(['\\beta_0 %1.4f' getpstars(bs2.p(1)) ';'],b2(1)));
  99. text(4,.8,sprintf(['\\beta_1 %1.4f' getpstars(bs2.p(2)) ';'],b2(2)));
  100. text(4,.7,sprintf('n= %d;',length(x2)));
  101. saveas(hfig,[figures_folder '/SuppFigS3A_ratio_chosen_right_vs_offer_diff_ev.fig']);
  102. saveas(hfig,[figures_folder '/SuppFigS3A_ratio_chosen_right_vs_offer_diff_ev.png']);
  103. saveas(hfig,[figures_folder '/SuppFigS3A_ratio_chosen_right_vs_offer_diff_ev.svg']);
  104. end
  105. if plotopts.Fig1C
  106. %% Fig. 1C - Histogram of eye position during task execution and count of trials LookL/LookR
  107. poolstackvars=getPoolStackVars(subjsData);
  108. poolstackepos=getPoolStackEyePos(subjsData);
  109. ncells=arrayfun(@(sn) poolstackvars(sn).ncells,1:8);
  110. poolstacktweyepos=getTimewinsPoolEyePos();%poolstackvars,poolstackepos);
  111. poolstackcctweyeposx=squeeze(cat(3,poolstacktweyepos(1).posX(:,cumsum(ncells),:),poolstacktweyepos(2).posX(:,cumsum(ncells),:),...
  112. poolstacktweyepos(3).posX(:,cumsum(ncells),:),poolstacktweyepos(4).posX(:,cumsum(ncells),:),...
  113. poolstacktweyepos(5).posX(:,cumsum(ncells),:),poolstacktweyepos(6).posX(:,cumsum(ncells),:),...
  114. poolstacktweyepos(7).posX(:,cumsum(ncells),:),poolstacktweyepos(8).posX(:,cumsum(ncells),:)));
  115. %[poolstackcctweyeposx, epxcovhist]=getCellsTimewinsPoolEyePos(poolstackvars,poolstacktweyepos);
  116. epxcovhist=squeeze(sum(sum(~isnan(poolstackcctweyeposx))))./sum(arrayfun(@(sn) size(poolstackvars(sn).offer1sd,1),1:8));
  117. ntptws=arrayfun(@(sn) size(poolstacktweyepos(sn).posX,3),1:8);
  118. horiz_edges=min(poolstackcctweyeposx(:)):1e2:max(poolstackcctweyeposx(:));
  119. hcount=nan(length(horiz_edges)-1,sum(ntptws));
  120. hL=nan(1,sum(ntptws)); hR=hL;
  121. for tt=1:sum(ntptws)
  122. currepx=poolstackcctweyeposx(:,:,tt);
  123. hcount(:,tt)=histcounts(currepx(:),horiz_edges);
  124. hL(tt)=mean(currepx(~isnan(currepx))<0);
  125. hR(tt)=mean(currepx(~isnan(currepx))>0);
  126. end
  127. hfig= figure('units','normalized','position',[0 0 1 1]);
  128. subplot(2,1,1);
  129. surf(1:sum(ntptws),linspace(-1,1,length(horiz_edges)-1),hcount./max(hcount(:)),'edgecolor','none'); hold on
  130. for jj=1:length(twinNames); plot([1 1].*sum(ntptws(1:jj)),[-1 1],'k:'); text(sum(ntptws(1:jj-1)),1.05,twinNames{jj}); end
  131. view(2); colormap(1-gray(255)); caxis([0 .2]); xlim([0 sum(ntptws)]); ylim([-1 1]);
  132. xlabel('time aligned to epochs start (ms)'); ylabel('horizontal eye ');
  133. ntptws=arrayfun(@(tw) size(poolstacktweyepos(tw).posX,3), 1:8);
  134. subplot(2,1,2);
  135. coveragemask=nan(1,sum(ntptws)); coveragemask(epxcovhist>.999)=1;
  136. plot(1:sum(ntptws),hL.*coveragemask,'k','linewidth',2); hold on
  137. plot(1:sum(ntptws),hR.*coveragemask,'color',[.5 .5 .5],'linewidth',2);
  138. for jj=1:length(twinNames); plot([1 1].*sum(ntptws(1:jj)),[-1 1],'k:'); text(sum(ntptws(1:jj-1)),1.05,twinNames{jj}); end
  139. xlabel('time aligned to epochs start (ms)'); ylabel('% trials'); xlim([0 sum(ntptws)]); ylim([0 1]);
  140. legend('LookL', 'LookR');
  141. saveas(hfig,[figures_folder '/Fig1C_coverage_of_horizontal_coordinates.fig']);
  142. saveas(hfig,[figures_folder '/Fig1C_coverage_of_horizontal_coordinates.png']);
  143. saveas(hfig,[figures_folder '/Fig1C_coverage_of_horizontal_coordinates.svg']);
  144. end
  145. if plotopts.Fig1D
  146. %% Fig. 1D and Supp. Fig. S2 - Heatmaps
  147. rmabs=0; rmradius=0;
  148. dxy=1.5e2; xaxis=-(4e4+dxy/2):dxy:(4e4+dxy/2);
  149. xbins=-(4e4+dxy):dxy:(4e4+dxy); yaxis=xaxis; ybins=xbins; cxs=[0 .5];
  150. cmt=hot(255);
  151. srr={'all','bestL','bestR','chsnL','chsnR'};
  152. % all, chsnL, chsnR, firstL, firstR, bestL, bestR, subj1, subj2, bestLR, chsnLR
  153. hfig=figure('units','normalized','outerposition',[0 0 1 1]);
  154. for ssr=1:length(srr)
  155. strcond=srr{ssr};
  156. for tw=1:8
  157. subplot(length(srr),8,8*(ssr-1)+tw); hold on;
  158. if strcmpi(strcond,'all')
  159. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  160. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  161. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  162. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  163. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  164. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  165. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  166. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  167. elseif strcmpi(strcond,'subj1')
  168. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  169. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  170. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  171. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  172. s2cpx1=[];%eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  173. s2cpx2=[];%eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  174. s2cpy1=[];%eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  175. s2cpy2=[];%eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  176. elseif strcmpi(strcond,'subj2')
  177. s1cpx1=[];%eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  178. s1cpx2=[];%eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  179. s1cpy1=[];%eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  180. s1cpy2=[];%eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  181. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  182. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  183. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  184. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  185. elseif strcmpi(strcond,'bestL')
  186. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  187. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  188. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  189. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  190. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  191. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  192. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  193. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  194. elseif strcmpi(strcond,'bestR')
  195. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  196. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  197. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  198. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  199. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  200. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  201. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  202. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  203. elseif strcmpi(strcond,'bestLR')
  204. s1cpx1bL=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  205. s1cpx2bL=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  206. s1cpy1bL=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  207. s1cpy2bL=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  208. s2cpx1bL=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  209. s2cpx2bL=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  210. s2cpy1bL=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  211. s2cpy2bL=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  212. s1cpx1bR=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  213. s1cpx2bR=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  214. s1cpy1bR=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.offerRev>s1gbi.offerLev)),:))']);
  215. s1cpy2bR=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.offerLev>s1gbi.offerRev)),:))']);
  216. s2cpx1bR=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  217. s2cpx2bR=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  218. s2cpy1bR=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.offerRev>s2gbi.offerLev)),:))']);
  219. s2cpy2bR=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.offerLev>s2gbi.offerRev)),:))']);
  220. elseif strcmpi(strcond,'chsnLR')
  221. s1cpx1bL=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.choose12==1)),:))']);
  222. s1cpx2bL=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.choose12==1)),:))']);
  223. s1cpy1bL=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.choose12==1)),:))']);
  224. s1cpy2bL=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.choose12==1)),:))']);
  225. s2cpx1bL=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.choose12==1)),:))']);
  226. s2cpx2bL=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.choose12==1)),:))']);
  227. s2cpy1bL=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.choose12==1)),:))']);
  228. s2cpy2bL=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.choose12==1)),:))']);
  229. s1cpx1bR=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.choose12==2)),:))']);
  230. s1cpx2bR=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.choose12==2)),:))']);
  231. s1cpy1bR=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.choose12==2)),:))']);
  232. s1cpy2bR=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.choose12==2)),:))']);
  233. s2cpx1bR=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.choose12==2)),:))']);
  234. s2cpx2bR=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.choose12==2)),:))']);
  235. s2cpy1bR=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.choose12==2)),:))']);
  236. s2cpy2bR=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.choose12==2)),:))']);
  237. elseif strcmpi(strcond,'firstL')
  238. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  239. s1cpx2=[];%eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  240. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  241. s1cpy2=[];%eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  242. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  243. s2cpx2=[];%eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  244. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  245. s2cpy2=[];%eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  246. elseif strcmpi(strcond,'firstR')
  247. s1cpx1=[];%eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  248. s1cpx2=-eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  249. s1cpy1=[];%eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  250. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  251. s2cpx1=[];%eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  252. s2cpx2=-eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  253. s2cpy1=[];%eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  254. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  255. elseif strcmpi(strcond,'chsnL')
  256. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.choose12==1)),:))']);
  257. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.choose12==1)),:))']);
  258. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.choose12==1)),:))']);
  259. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.choose12==1)),:))']);
  260. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.choose12==1)),:))']);
  261. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.choose12==1)),:))']);
  262. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.choose12==1)),:))']);
  263. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.choose12==1)),:))']);
  264. elseif strcmpi(strcond,'chsnR')
  265. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifLsR,find(s1gbi.choose12==2)),:))']);
  266. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(intersect(s1gbi.ifRsL,find(s1gbi.choose12==2)),:))']);
  267. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifLsR,find(s1gbi.choose12==2)),:))']);
  268. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(intersect(s1gbi.ifRsL,find(s1gbi.choose12==2)),:))']);
  269. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifLsR,find(s2gbi.choose12==2)),:))']);
  270. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(intersect(s2gbi.ifRsL,find(s2gbi.choose12==2)),:))']);
  271. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifLsR,find(s2gbi.choose12==2)),:))']);
  272. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(intersect(s2gbi.ifRsL,find(s2gbi.choose12==2)),:))']);
  273. end
  274. % comment here to see subjects separately
  275. %s1cpx1=[]; s1cpx2=[]; s1cpy1=[]; s1cpy2=[];
  276. %s2cpx1=[]; s2cpx2=[]; s2cpy1=[]; s2cpy2=[];
  277. if strcmpi(strcond,'bestLR') || strcmpi(strcond,'chsnLR')
  278. nx11=size(s1cpx1bL,2); nx12=size(s1cpx2bL,2); nx21=size(s2cpx1bL,2); nx22=size(s2cpx2bL,2);
  279. nx=max([nx11 nx12 nx21 nx22]);
  280. ny11=size(s1cpy1bL,2); ny12=size(s1cpy2bL,2); ny21=size(s2cpy1bL,2); ny22=size(s2cpy2bL,2);
  281. ny=max([ny11 ny12 ny21 ny22]);
  282. cpxbL=[s1cpx1bL nan(size(s1cpx1bL,1),nx-nx11); -s1cpx2bL nan(size(s1cpx2bL,1),nx-nx12); ...
  283. s2cpx1bL nan(size(s2cpx1bL,1),nx-nx21); -s2cpx2bL nan(size(s2cpx2bL,1),nx-nx22)];
  284. cpybL=[s1cpy1bL nan(size(s1cpy1bL,1),ny-ny11); s1cpy2bL nan(size(s1cpy2bL,1),ny-ny12); ...
  285. s2cpy1bL nan(size(s2cpy1bL,1),ny-ny21); s2cpy2bL nan(size(s2cpy2bL,1),ny-ny22)];
  286. nx11=size(s1cpx1bR,2); nx12=size(s1cpx2bR,2); nx21=size(s2cpx1bR,2); nx22=size(s2cpx2bR,2);
  287. nx=max([nx11 nx12 nx21 nx22]);
  288. ny11=size(s1cpy1bR,2); ny12=size(s1cpy2bR,2); ny21=size(s2cpy1bR,2); ny22=size(s2cpy2bR,2);
  289. ny=max([ny11 ny12 ny21 ny22]);
  290. cpxbR=[s1cpx1bR nan(size(s1cpx1bR,1),nx-nx11); -s1cpx2bR nan(size(s1cpx2bR,1),nx-nx12); ...
  291. s2cpx1bR nan(size(s2cpx1bR,1),nx-nx21); -s2cpx2bR nan(size(s2cpx2bR,1),nx-nx22)];
  292. cpybR=[s1cpy1bR nan(size(s1cpy1bR,1),ny-ny11); s1cpy2bR nan(size(s1cpy2bR,1),ny-ny12); ...
  293. s2cpy1bR nan(size(s2cpy1bR,1),ny-ny21); s2cpy2bR nan(size(s2cpy2bR,1),ny-ny22)];
  294. if tw==1
  295. cpxbL=cpxbL(:,end-400+1:end); cpybL=cpybL(:,end-400+1:end);
  296. cpxbR=cpxbR(:,end-400+1:end); cpybR=cpybR(:,end-400+1:end);
  297. else
  298. cpxbL=cpxbL(:,mean(~isnan(cpxbL),1)>=.999);
  299. cpybL=cpybL(:,mean(~isnan(cpxbL),1)>=.999);
  300. cpxbR=cpxbR(:,mean(~isnan(cpxbR),1)>=.999);
  301. cpybR=cpybR(:,mean(~isnan(cpxbR),1)>=.999);
  302. end
  303. %s3=scatter(nanmean(cpxbL,2),nanmean(cpybL,2),'filled','SizeData',1); s3.MarkerFaceColor='r';
  304. %hold on; alpha(s3,.3);%p3.MarkerFaceColor=[1 1 1 ];
  305. %s3=scatter(nanmean(cpxbR,2),nanmean(cpybR,2),'filled','SizeData',1); s3.MarkerFaceColor='b';
  306. %hold off; alpha(s3,.3);%p3.MarkerFaceColor=[1 1 1 ];
  307. hxybL=imgaussfilt(histcounts2(cpxbL(:),cpybL(:),xbins,ybins,'Normalization','probability'),5);
  308. hxybR=imgaussfilt(histcounts2(cpxbR(:),cpybR(:),xbins,ybins,'Normalization','probability'),5);
  309. %hxybLth=normalize(hxybL,'range',[0 1]);%(hxybL./max(hxybL(:)));
  310. %hxybRth=normalize(hxybR,'range',[0 1]);%(hxybR./max(hxybR(:)));
  311. hxybLth=(hxybL./max(hxybL(:)));
  312. hxybRth=(hxybR./max(hxybR(:)));
  313. hxyz=normalize(hxybLth'-hxybRth','center',mode(hxybLth(:)'-hxybRth(:)'));
  314. %min(hxybLth(:))
  315. %max(hxybLth(:))
  316. sf=surf(xaxis,yaxis,hxyz,'edgecolor','none'); view(2); %daspect([1 1 1]);
  317. %colormap(getdivergentcolmap(1-[.2 .2 0; 1 1 0; 1 1 1; 0 1 1; 0 .2 .2],[256 64 64 256]));
  318. caxis([-1 1].*max(abs([min(hxyz(:)) max(hxyz(:))])));
  319. else
  320. nx11=size(s1cpx1,2); nx12=size(s1cpx2,2); nx21=size(s2cpx1,2); nx22=size(s2cpx2,2);
  321. nx=max([nx11 nx12 nx21 nx22]);
  322. ny11=size(s1cpy1,2); ny12=size(s1cpy2,2); ny21=size(s2cpy1,2); ny22=size(s2cpy2,2);
  323. ny=max([ny11 ny12 ny21 ny22]);
  324. cpx=[s1cpx1 nan(size(s1cpx1,1),nx-nx11); -s1cpx2 nan(size(s1cpx2,1),nx-nx12); ...
  325. s2cpx1 nan(size(s2cpx1,1),nx-nx21); -s2cpx2 nan(size(s2cpx2,1),nx-nx22)];
  326. cpy=[s1cpy1 nan(size(s1cpy1,1),ny-ny11); s1cpy2 nan(size(s1cpy2,1),ny-ny12); ...
  327. s2cpy1 nan(size(s2cpy1,1),ny-ny21); s2cpy2 nan(size(s2cpy2,1),ny-ny22)];
  328. %cpn=(isnan(cpx) | isnan(cpy)); cp0=(cpx==0 & cpy==0); cpx(cpn | cp0)=nan; cpy(cpn | cp0)=nan;
  329. if rmabs %cpx=rmnansandthreshold(cpx,5000,abs(cpx));
  330. cpy=rmnansandthresholdreversed(cpy,6000,abs(cpy));
  331. cpx=rmnansandthresholdreversed(cpx,12000,abs(cpx));
  332. elseif rmradius
  333. cpx=rmnansandthreshold(cpx,5000,sqrt(cpx.^2+cpy.^2));
  334. cpy=rmnansandthreshold(cpy,5000,sqrt(cpx.^2+cpy.^2));
  335. end
  336. if tw==1
  337. cpx=cpx(:,end-400+1:end); cpy=cpy(:,end-400+1:end);
  338. else
  339. cpx=cpx(:,mean(~isnan(cpx),1)>=.999);
  340. cpy=cpy(:,mean(~isnan(cpx),1)>=.999);
  341. end
  342. hxy=imgaussfilt(histcounts2(cpx(:),cpy(:),xbins,ybins,'Normalization','probability'),5);
  343. hxyth=(hxy./max(hxy(:)));
  344. surf(xaxis,yaxis,hxyth','edgecolor','none'); view(2); %daspect([1 1 1]);
  345. %caxis([0 1].*max(abs(max(hxy(:)))));
  346. colormap(cmt); caxis(cxs);
  347. end
  348. %hold on; xlim([-4e4 4e4]); ylim([-4e4 4e4]); daspect([1 1 1]);
  349. title([twinNames{tw} ', ' strcond]); hold on;
  350. %plot([-4e4 4e4],[0 0],'w:'); plot([0 0],[-4e4 4e4],'w:');
  351. xlim([-4e4 4e4]/2); ylim([-4e4 4e4]/2); daspect([1 1 1]);
  352. %plot3([-.82e4 .82e4], [0 0], [1 1], 'kx');
  353. % pl1=plot3(-.81395e4+[-1 -1 1 1 -1]*.2e4,[-1 1 1 -1 -1]*.8e4,-[1 1 1 1 1],'w:'); % stimulus frame borders
  354. % pl2=plot3(+.81395e4+[-1 -1 1 1 -1]*.2e4,[-1 1 1 -1 -1]*.8e4,-[1 1 1 1 1],'w:'); % stimulus frame borders
  355. %plot3([-.85e4-(1.7e3) .85e4+1.7e3], [0 0], [1 1], 'kx');
  356. %plot3(-.81395e4,0,1,'kx');
  357. %plot3(+.81395e4,0,1,'kx');
  358. %plot(-0.6e4,-.8e4,'rx')
  359. %plot(-1.0e4,-.8e4,'rx')
  360. %plot(+0.6e4+.2e4,-.8e4,'bx')
  361. %plot(+1.0e4-.2e4,-.8e4,'bx')
  362. % x:max(cpx(:))=10.995:.81395e4
  363. % max(cpx(:)) : 43.98 = 10.995 : .81395e4
  364. %pl1b=plot3(-.85e4+[-1 -1 1 1 -1]*4.08*8500/(27.3),[-1 1 1 -1 -1]*11.35*8500/(27.3),-[1 1 1 1 1],'w:');
  365. %pl2b=plot3(+.85e4+[-1 -1 1 1 -1]*4.08*8500/(27.3),[-1 1 1 -1 -1]*11.35*8500/(27.3),-[1 1 1 1 1],'w:');
  366. end
  367. cb=colorbar(); cb.Position(1)=.96; daspect([1 1 1]);
  368. end
  369. saveas(hfig,[figures_folder '/Fig1D-Eyetrack-heatmaps.png']);
  370. saveas(hfig,[figures_folder '/Fig1D-Eyetrack-heatmaps.fig']);
  371. saveas(hfig,[figures_folder '/Fig1D-Eyetrack-heatmaps.svg']);
  372. end
  373. if plotopts.Fig2A
  374. %% Fig. 2A - EVdiff vs chR for fR>0.5 and fR<0.5
  375. hfig=figure('units','normalized','position',[0 0 1 .2]);
  376. for tw=1:8
  377. subplot(1,8,tw); hold on;
  378. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  379. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  380. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  381. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  382. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  383. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  384. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  385. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  386. nx11=size(s1cpx1,2); nx12=size(s1cpx2,2); nx21=size(s2cpx1,2); nx22=size(s2cpx2,2);
  387. nx=max([nx11 nx12 nx21 nx22]);
  388. ny11=size(s1cpy1,2); ny12=size(s1cpy2,2); ny21=size(s2cpy1,2); ny22=size(s2cpy2,2);
  389. ny=max([ny11 ny12 ny21 ny22]);
  390. cpx=[s1cpx1 nan(size(s1cpx1,1),nx-nx11); -s1cpx2 nan(size(s1cpx2,1),nx-nx12); ...
  391. s2cpx1 nan(size(s2cpx1,1),nx-nx21); -s2cpx2 nan(size(s2cpx2,1),nx-nx22)];
  392. cpy=[s1cpy1 nan(size(s1cpy1,1),ny-ny11); s1cpy2 nan(size(s1cpy2,1),ny-ny12); ...
  393. s2cpy1 nan(size(s2cpy1,1),ny-ny21); s2cpy2 nan(size(s2cpy2,1),ny-ny22)];
  394. cpn=(isnan(cpx) | isnan(cpy)); cp0=(cpx==0 & cpy==0); cpx(cpn | cp0)=nan; cpy(cpn | cp0)=nan;
  395. if rmabs; cpx=rmnansandthreshold(cpx,5000,abs(cpx));
  396. elseif rmradius; cpx=rmnansandthreshold(cpx,5000,sqrt(cpx.^2+cpy.^2)); else; end
  397. if tw==1
  398. cpx=cpx(:,end-400+1:end); cpy=cpy(:,end-400+1:end);
  399. else
  400. cpx=cpx(:,mean(~isnan(cpx),1)>=.999);
  401. cpy=cpy(:,mean(~isnan(cpx),1)>=.999);
  402. end
  403. sum_L=sum(~isnan(rmnansandthreshold(-cpx,0)),2);
  404. sum_R=sum(~isnan(rmnansandthreshold(+cpx,0)),2);
  405. frac_L=sum_L./(sum_L+sum_R); frac_R=1-frac_L;
  406. x1=[s1gbi.offer2ev(s1gbi.ifLsR,:)-s1gbi.offer1ev(s1gbi.ifLsR,:);...
  407. s1gbi.offer2ev(s1gbi.ifRsL,:)-s1gbi.offer1ev(s1gbi.ifRsL,:);...
  408. s2gbi.offer2ev(s2gbi.ifLsR,:)-s2gbi.offer1ev(s2gbi.ifLsR,:);...
  409. s2gbi.offer2ev(s2gbi.ifRsL,:)-s2gbi.offer1ev(s2gbi.ifRsL,:)];
  410. %[s1o2evsd1-s1o1evsd1; s1os2evsd2-s1o1evsd2];
  411. y1=[s1gbi.choose12(s1gbi.ifLsR,:)==2; s1gbi.choose12(s1gbi.ifRsL,:)==2;
  412. s2gbi.choose12(s2gbi.ifLsR,:)==2; s2gbi.choose12(s2gbi.ifRsL,:)==2];
  413. x1_gR=x1(frac_R>0.5); y1_gR=y1(frac_R>0.5);
  414. x1_lR=x1(frac_R<0.5); y1_lR=y1(frac_R<0.5);
  415. %y1=double(frac_R>0.5); %nluqEV=-3:.2:3;%linspace(-max(abs(x1)),max(abs(x1)),150);
  416. %[zq1,xq1]=nanmeanquantized(nluqEV,x1,y1); plot(xq1,zq1,'.','color',[0 0 .75]);
  417. %hold on; [sq1,st1,fsigm]=sigm_fit(xq1,zq1,[0 1 NaN NaN],[],0);
  418. %yq1=st1.ypred; [~,im1]=min(abs(xq1)); plot([-3 xq1(im1)],yq1(im1).*[1 1],'k:','linewidth',1.5);
  419. %plot(linspace(-3,3,length(yq1)),st1.ypred,'b-','linewidth',1.5);
  420. %fill([linspace(-3,3,length(yq1))'; linspace(3,-3,length(yq1))'],[st1.ypredupperCI; flipud(st1.ypredlowerCI)],'b','edgecolor','none','facealpha',.3);
  421. %NuqEV=31;
  422. %nluqEV=linspace(-max(abs(x1)),max(abs(x1)),NuqEV);
  423. nluqEV=-3:.2:3;
  424. [tested,]=nanhistquantized(nluqEV,x1,ones(1,length(y1)));
  425. [frac_R_g05,uq]=nanhistquantized(nluqEV,x1,y1);
  426. stst=statset('fitglm');
  427. stst.tolX=1e-20;
  428. logitMdl= fitglm(x1,y1,'Distribution','binomial','Link','logit');
  429. logitCci = coefCI(logitMdl);
  430. logitFit = glmval(logitMdl.Coefficients.Estimate,uq,'logit'); % logitFit=1./(1+exp(-logitCoeffs(1)-logitCoeffs(2).*uq));
  431. logitFitCiu = glmval(logitCci(:,1),uq,'logit');
  432. logitFitCil = glmval(logitCci(:,2),uq,'logit');
  433. [tested_gR,]=nanhistquantized(nluqEV,x1_gR,ones(1,length(y1_gR)));
  434. [frac_R_g05_gR,uq]=nanhistquantized(nluqEV,x1_gR,y1_gR);
  435. stst=statset('fitglm');
  436. stst.tolX=1e-20;
  437. logitMdl_gR= fitglm(x1_gR,y1_gR,'Distribution','binomial','Link','logit');
  438. logitCci_gR = coefCI(logitMdl_gR);
  439. logitFit_gR = glmval(logitMdl_gR.Coefficients.Estimate,uq,'logit'); % logitFit=1./(1+exp(-logitCoeffs(1)-logitCoeffs(2).*uq));
  440. logitFitCiu_gR = glmval(logitCci_gR(:,1),uq,'logit');
  441. logitFitCil_gR = glmval(logitCci_gR(:,2),uq,'logit');
  442. [tested_lR,]=nanhistquantized(nluqEV,x1_lR,ones(1,length(y1_lR)));
  443. [frac_R_g05_lR,uq]=nanhistquantized(nluqEV,x1_lR,y1_lR);
  444. stst=statset('fitglm');
  445. stst.tolX=1e-20;
  446. logitMdl_lR= fitglm(x1_lR,y1_lR,'Distribution','binomial','Link','logit');
  447. logitCci_lR = coefCI(logitMdl_lR);
  448. logitFit_lR = glmval(logitMdl_lR.Coefficients.Estimate,uq,'logit'); % logitFit=1./(1+exp(-logitCoeffs(1)-logitCoeffs(2).*uq));
  449. logitFitCiu_lR = glmval(logitCci_lR(:,1),uq,'logit');
  450. logitFitCil_lR = glmval(logitCci_lR(:,2),uq,'logit');
  451. plot(uq,frac_R_g05_gR./tested_gR,'.','color',[0 0 50]./255); hold on;
  452. plot([-1e3 1e3],[0 0],'k-',[0 0],[-10 10],'k-');
  453. plot(uq,logitFit_gR,'-','color',[0 0 50]./255);
  454. fill([uq -uq],[logitFitCiu_gR' flip(logitFitCil_gR')],[0 0 50]./255,'edgecolor','none','facealpha',.15);
  455. text(abs(max(x1))*.6,.75,sprintf(['\\beta_1 %1.2f' getpstars(logitMdl_gR.Coefficients.pValue(2)) ';'],...
  456. logitMdl_gR.Coefficients.Estimate(2)),'color',[0 0 50]./255);
  457. plot(uq,frac_R_g05./tested,'.','color',[0 0 150]./255); hold on;
  458. plot([-1e3 1e3],[0 0],'k-',[0 0],[-10 10],'k-');
  459. plot(uq,logitFit,'-','color',[0 0 150]./255);
  460. fill([uq -uq],[logitFitCiu' flip(logitFitCil')],[0 0 150]./255,'edgecolor','none','facealpha',.15);
  461. text(abs(max(x1))*.6,.65,sprintf(['\\beta_1 %1.2f' getpstars(logitMdl.Coefficients.pValue(2)) ';'],...
  462. logitMdl.Coefficients.Estimate(2)),'color',[0 0 150]./255);
  463. plot(uq,frac_R_g05_lR./tested_lR,'.','color',[0 0 250]./255); hold on;
  464. plot([-1e3 1e3],[0 0],'k-',[0 0],[-10 10],'k-');
  465. plot(uq,logitFit_lR,'-','color',[0 0 250]./255);
  466. fill([uq -uq],[logitFitCiu_lR' flip(logitFitCil_lR')],[0 0 250]./255,'edgecolor','none','facealpha',.15);
  467. text(abs(max(x1))*.6,.55,sprintf(['\\beta_1 %1.2f' getpstars(logitMdl_lR.Coefficients.pValue(2)) ';'],...
  468. logitMdl_lR.Coefficients.Estimate(2)),'color',[0 0 250]./255);
  469. plot([0 0],[0 1],'k-'); gch=gca; gch.XTick=-3:3;
  470. xlabel('EV_R - EV_L');
  471. xlim([-3 3]); ylim([0 1]); daspect([4 1 1]);
  472. title([twinNames{tw} ' time']);
  473. if tw==1; ylabel('average chR'); end
  474. end
  475. supertitle('Subjects 1:2, all sessions');
  476. print(hfig,[figures_folder '/Fig2A-Eyetrack-chR-vs-EVdiff.png'],'-dpng','-r600');
  477. saveas(hfig,[figures_folder '/Fig2A-Eyetrack-chR-vs-EVdiff.fig']);
  478. saveas(hfig,[figures_folder '/Fig2A-Eyetrack-chR-vs-EVdiff.svg']);
  479. end
  480. if plotopts.Fig2B
  481. %% Fig 2B - fR vs chR for EVR>EVL and EVR<EVL
  482. hfig=figure('units','normalized','position',[0 0 1 .2]);
  483. for trgrp=1:3 %trgrp 1=bestL; 2=all trials; 3=bestR
  484. for tw=1:8
  485. subplot(1,8,tw); hold on;
  486. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  487. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  488. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  489. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  490. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  491. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  492. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  493. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  494. chosenR_flag=double([s1gbi.choose12(s1gbi.ifLsR)==2; s1gbi.choose12(s1gbi.ifRsL)==2;...
  495. s2gbi.choose12(s2gbi.ifLsR)==2; s2gbi.choose12(s2gbi.ifRsL)==2]);
  496. offLev=double([s1gbi.offer1ev(s1gbi.ifLsR); s1gbi.offer2ev(s1gbi.ifRsL);...
  497. s2gbi.offer1ev(s2gbi.ifLsR); s2gbi.offer2ev(s2gbi.ifRsL)]);
  498. offRev=double([s1gbi.offer2ev(s1gbi.ifLsR); s1gbi.offer1ev(s1gbi.ifRsL);...
  499. s2gbi.offer2ev(s2gbi.ifLsR); s2gbi.offer1ev(s2gbi.ifRsL)]);
  500. nx11=size(s1cpx1,2); nx12=size(s1cpx2,2); nx21=size(s2cpx1,2); nx22=size(s2cpx2,2);
  501. nx=max([nx11 nx12 nx21 nx22]);
  502. ny11=size(s1cpy1,2); ny12=size(s1cpy2,2); ny21=size(s2cpy1,2); ny22=size(s2cpy2,2);
  503. ny=max([ny11 ny12 ny21 ny22]);
  504. cpx=[s1cpx1 nan(size(s1cpx1,1),nx-nx11); -s1cpx2 nan(size(s1cpx2,1),nx-nx12); ...
  505. s2cpx1 nan(size(s2cpx1,1),nx-nx21); -s2cpx2 nan(size(s2cpx2,1),nx-nx22)];
  506. cpy=[s1cpy1 nan(size(s1cpy1,1),ny-ny11); s1cpy2 nan(size(s1cpy2,1),ny-ny12); ...
  507. s2cpy1 nan(size(s2cpy1,1),ny-ny21); s2cpy2 nan(size(s2cpy2,1),ny-ny22)];
  508. cpn=(isnan(cpx) | isnan(cpy)); cp0=(cpx==0 & cpy==0); cpx(cpn | cp0)=nan; cpy(cpn | cp0)=nan;
  509. if tw==1
  510. cpx=cpx(:,end-400+1:end);
  511. cpy=cpy(:,end-400+1:end);
  512. else
  513. cpx=cpx(:,mean(~isnan(cpx),1)>=.999);
  514. cpy=cpy(:,mean(~isnan(cpx),1)>=.999);
  515. end
  516. sum_L=sum(~isnan(rmnansandthreshold(-cpx,0)),2);
  517. sum_R=sum(~isnan(rmnansandthreshold(+cpx,0)),2);
  518. x1=((sum_R)-(sum_L))./((((sum_R)+(sum_L)))+eps);
  519. nluqEV=-1:.1:1;
  520. if trgrp==3
  521. x1(offRev>offLev)=[]; % bestR
  522. chosenR_flag(offRev>offLev)=[]; % bestR
  523. elseif trgrp==1
  524. x1(offLev>offRev)=[]; % bestL
  525. chosenR_flag(offLev>offRev)=[]; % bestL
  526. end
  527. [tested,]=nanhistquantized(nluqEV,x1,ones(1,length(chosenR_flag)));
  528. [chosen_R,uq]=nanhistquantized(nluqEV,x1,chosenR_flag);
  529. logitMdl= fitglm(x1,chosenR_flag,'Distribution','binomial','Link','logit');
  530. logitCci = coefCI(logitMdl);
  531. logitFit = glmval(logitMdl.Coefficients.Estimate,uq,'logit'); % logitFit=1./(1+exp(-logitCoeffs(1)-logitCoeffs(2).*uq));
  532. logitFitCiu = glmval(logitCci(:,1),uq,'logit');
  533. logitFitCil = glmval(logitCci(:,2),uq,'logit');
  534. plot(uq,chosen_R./tested,'.','color',(0.3.*trgrp.*[0 176 80]./255)); hold on;
  535. plot([-1e3 1e3],[0 0],'k-',[0 0],[-10 10],'k-');
  536. plot(uq,logitFit,'-','color',.3.*trgrp.*[0 176 80]./255);
  537. fill([uq -uq],[logitFitCiu' flip(logitFitCil')],.3.*trgrp.*[0 176 80]./255,'edgecolor','none','facealpha',.15);
  538. xlabel('t_R-t_L'); daspect([1.5 1 1]);
  539. xlim([-1 1].*abs(max(x1))); ylim([0 1]); %daspect([2*abs(max(x1)) 1 1]);
  540. title([twinNames{tw} ' time']); if tw>1; gch=gca; gch.XTick=[]; end
  541. text(abs(max(x1))*.6,1.45-.15.*trgrp,sprintf(['\\beta_1 %1.2f' getpstars(logitMdl.Coefficients.pValue(2)) ';'],...
  542. logitMdl.Coefficients.Estimate(2)),'color',.3.*trgrp.*[0 176 80]./255);
  543. if tw==1
  544. text(1.1,.15,sprintf('nchR = %.0d;',sum(chosenR_flag)));
  545. text(1.1,0,sprintf('chR = %.0f%%;',mean(chosenR_flag).*100));
  546. ylabel('P(choosing R)'); else; gch=gca; gch.YTick=[];
  547. end
  548. end
  549. if trgrp==1; supertitle('Subjects 1:2, all sessions, all trials'); end
  550. end
  551. print(hfig,[figures_folder '/Fig2B-Eyetrack-chR-vs-timediff.png'],'-dpng','-r600');
  552. saveas(hfig,[figures_folder '/Fig2B-Eyetrack-chR-vs-timediff.fig']);
  553. saveas(hfig,[figures_folder '/Fig2B-Eyetrack-chR-vs-timediff.svg']);
  554. end
  555. if plotopts.Fig2C
  556. %% Fig2C - Logistic GLM of choice
  557. for isweightnormalized=0%:1
  558. for focusaroundstimuli=0:1 %uncomment here for supp. fig. S4
  559. hfig=figure('units','normalized','outerposition',[0 0 1 .75]);
  560. for ss=1:3
  561. btw=nan(6,8);
  562. ptw=nan(6,8);
  563. bmax=[]; bmin=[];
  564. for tw=1:8 %7
  565. evL=[s1gbi.offerLev(s1gbi.ifLsR); s1gbi.offerLev(s1gbi.ifRsL); s2gbi.offerLev(s2gbi.ifLsR); s2gbi.offerLev(s2gbi.ifRsL)];
  566. evR=[s1gbi.offerRev(s1gbi.ifLsR); s1gbi.offerRev(s1gbi.ifRsL); s2gbi.offerRev(s2gbi.ifLsR); s2gbi.offerRev(s2gbi.ifRsL)];
  567. varL=[s1gbi.offerLvar(s1gbi.ifLsR); s1gbi.offerLvar(s1gbi.ifRsL); s2gbi.offerLvar(s2gbi.ifLsR); s2gbi.offerLvar(s2gbi.ifRsL)];
  568. varR=[s1gbi.offerRvar(s1gbi.ifLsR); s1gbi.offerRvar(s1gbi.ifRsL); s2gbi.offerRvar(s2gbi.ifLsR); s2gbi.offerRvar(s2gbi.ifRsL)];
  569. sideRL=[ones(length(s1gbi.ifLsR),1); -ones(length(s1gbi.ifRsL),1); ones(length(s2gbi.ifLsR),1); -ones(length(s2gbi.ifRsL),1)];
  570. s1sn1gbi=getBehavioralInfos(subjsData(1).sbdata,1); s1sn2gbi=getBehavioralInfos(subjsData(1).sbdata,2);
  571. s1sn3gbi=getBehavioralInfos(subjsData(1).sbdata,3); s1sn4gbi=getBehavioralInfos(subjsData(1).sbdata,4);
  572. s2sn1gbi=getBehavioralInfos(subjsData(2).sbdata,1); s2sn2gbi=getBehavioralInfos(subjsData(2).sbdata,2);
  573. s2sn3gbi=getBehavioralInfos(subjsData(2).sbdata,3); s2sn4gbi=getBehavioralInfos(subjsData(2).sbdata,4);
  574. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  575. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  576. s1cpy1=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifLsR,:))']);
  577. s1cpy2=eval(['(s1gem' num2str(tw) '.posY(s1gbi.ifRsL,:))']);
  578. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  579. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  580. s2cpy1=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifLsR,:))']);
  581. s2cpy2=eval(['(s2gem' num2str(tw) '.posY(s2gbi.ifRsL,:))']);
  582. s1cpx=[s1cpx1; s1cpx2]; s1cpy=[s1cpy1; s1cpy2];
  583. s2cpx=[s2cpx1; s2cpx2]; s2cpy=[s2cpy1; s2cpy2];
  584. if tw==1
  585. s1cpx=s1cpx(:,end-400+1:end);
  586. s1cpy=s1cpy(:,end-400+1:end);
  587. s2cpx=s2cpx(:,end-400+1:end);
  588. s2cpy=s2cpy(:,end-400+1:end);
  589. else
  590. s1cpx=s1cpx(:,mean(~isnan(s1cpx),1)>=.999);
  591. s2cpx=s2cpx(:,mean(~isnan(s2cpx),1)>=.999);
  592. s1cpy=s1cpy(:,mean(~isnan(s1cpx),1)>=.999);
  593. s2cpy=s2cpy(:,mean(~isnan(s2cpx),1)>=.999);
  594. end
  595. if focusaroundstimuli
  596. s1cpx_Rts=rmnansandwithin(s1cpx,[7.5e3,+10e3]);
  597. s1cpy_Rts=nan(size(s1cpx_Rts)); s1cpy_Rts(~isnan(s1cpx_Rts))=s1cpy(~isnan(s1cpx_Rts));
  598. s1cpy_Rts=rmnansandwithin(s1cpy_Rts,[-8e3 8e3]);
  599. s1cpx_Rts(isnan(s1cpy_Rts))=s1cpy_Rts(isnan(s1cpy_Rts));
  600. s1cpx_Lts=rmnansandwithin(s1cpx,[-10e3,-7.5e3]);
  601. s1cpy_Lts=nan(size(s1cpx_Lts)); s1cpy_Lts(~isnan(s1cpx_Lts))=s1cpy(~isnan(s1cpx_Lts));
  602. s1cpy_Lts=rmnansandwithin(s1cpy_Lts,[-8e3 8e3]);
  603. s1cpx_Lts(isnan(s1cpy_Lts))=s1cpy_Lts(isnan(s1cpy_Lts));
  604. s2cpx_Rts=rmnansandwithin(s2cpx,[7.5e3,+10e3]);
  605. s2cpy_Rts=nan(size(s2cpx_Rts)); s2cpy_Rts(~isnan(s2cpx_Rts))=s2cpy(~isnan(s2cpx_Rts));
  606. s2cpy_Rts=rmnansandwithin(s2cpy_Rts,[-8e3 8e3]);
  607. s2cpx_Rts(isnan(s2cpy_Rts))=s2cpy_Rts(isnan(s2cpy_Rts));
  608. s2cpx_Lts=rmnansandwithin(s2cpx,[-10e3,-7.5e3]);
  609. s2cpy_Lts=nan(size(s2cpx_Lts)); s2cpy_Lts(~isnan(s2cpx_Lts))=s2cpy(~isnan(s2cpx_Lts));
  610. s2cpy_Lts=rmnansandwithin(s2cpy_Lts,[-8e3 8e3]);
  611. s2cpx_Lts(isnan(s2cpy_Lts))=s2cpy_Lts(isnan(s2cpy_Lts));
  612. s1cpx=nan(size(s1cpx)); s1cpx(~isnan(s1cpx_Rts))=s1cpx_Rts(~isnan(s1cpx_Rts)); s1cpx(~isnan(s1cpx_Lts))=s1cpx_Lts(~isnan(s1cpx_Lts));
  613. s1cpy=nan(size(s1cpy)); s1cpy(~isnan(s1cpy_Rts))=s1cpy_Rts(~isnan(s1cpy_Rts)); s1cpx(~isnan(s1cpy_Lts))=s1cpy_Lts(~isnan(s1cpy_Lts));
  614. s2cpx=nan(size(s2cpx)); s2cpx(~isnan(s2cpx_Rts))=s2cpx_Rts(~isnan(s2cpx_Rts)); s2cpx(~isnan(s2cpx_Lts))=s2cpx_Lts(~isnan(s2cpx_Lts));
  615. s2cpy=nan(size(s2cpy)); s2cpy(~isnan(s2cpy_Rts))=s2cpy_Rts(~isnan(s2cpy_Rts)); s2cpx(~isnan(s2cpy_Lts))=s2cpy_Lts(~isnan(s2cpy_Lts));
  616. end
  617. s1cpn=(isnan(s1cpx) | isnan(s1cpy)); s1cp0=(s1cpx==0 & s1cpy==0); s1cpx(s1cpn | s1cp0)=nan; s1cpy(s1cpn | s1cp0)=nan;
  618. s1sum_L=sum(~isnan(rmnansandthreshold(-s1cpx,0)),2);
  619. s1sum_R=sum(~isnan(rmnansandthreshold(+s1cpx,0)),2);
  620. s1frac_R=s1sum_R./(s1sum_R+s1sum_L+eps);
  621. s2cpn=(isnan(s2cpx) | isnan(s2cpy)); s2cp0=(s2cpx==0 & s2cpy==0); s2cpx(s2cpn | s2cp0)=nan; s2cpy(s2cpn | s2cp0)=nan;
  622. s2sum_L=sum(~isnan(rmnansandthreshold(-s2cpx,0)),2);
  623. s2sum_R=sum(~isnan(rmnansandthreshold(+s2cpx,0)),2);
  624. s2frac_R=s2sum_R./(s2sum_R+s2sum_L+eps);
  625. %frac_R=[s1frac_R; s2frac_R];
  626. frac_R=[mat2gray(s1frac_R); mat2gray(s2frac_R)];
  627. chosenR_flag=double([s1gbi.choose12(s1gbi.ifLsR)==2; s1gbi.choose12(s1gbi.ifRsL)==1;...
  628. s2gbi.choose12(s2gbi.ifLsR)==2; s2gbi.choose12(s2gbi.ifRsL)==1]);
  629. if isweightnormalized
  630. %regressVars=[evL evR varL varR sideRL prevexprew frac_R];
  631. regressVars=[evL evR varL varR sideRL frac_R];
  632. %regressVars=[mat2gray(evL) mat2gray(evR) mat2gray(varL) mat2gray(varR) (sideRL) (prevexprew) mat2gray(frac_R)];
  633. %remove first trials of each session they dont have a prev reward
  634. %s12_rmtrs=[s1_rmtrs length(s1sorted)+s2_rmtrs];
  635. %regressVars(s12_rmtrs(:),:)=[];
  636. %chosenR_flag(s12_rmtrs(:))=[];
  637. else
  638. regressVars=[evL./max(evL) evR./max(evR) varL./max(varL) varR./max(varR) sideRL frac_R./max(frac_R)];
  639. %regressVars=[mat2gray(evL) mat2gray(evR) mat2gray(varL) mat2gray(varR) mat2gray(frac_R)];
  640. end
  641. if ss==1
  642. %remove second subj to check just first
  643. regressVars(size(s1cpx,1)+1:end,:)=[];
  644. chosenR_flag(size(s1cpx,1)+1:end)=[];
  645. elseif ss==2
  646. %remove first subj to check just second
  647. regressVars(1:size(s1cpx,1),:)=[];
  648. chosenR_flag(1:size(s1cpx,1))=[];
  649. end
  650. %[b,dev,stats]=glmfit(regressVars,chosenR_flag);
  651. [b,dev,stats]=glmfit(regressVars,chosenR_flag,'binomial','link','logit');
  652. btw(:,tw)=stats.beta(2:end);
  653. ptw(:,tw)=stats.p(2:end);
  654. % logit(p(choose R)) = beta*X; % might cause singularities
  655. %[b,dev,stats]=glmfit(regressVars,ratioChoiceR,'binomial','link','logit');
  656. subplot(3,8,(ss-1)*8+tw);
  657. bar(1:length(b)-1,stats.beta(2:end));
  658. bmax=max([bmax; b(2:end)]); bmin=min([bmin; b(2:end)]);
  659. if ss<3; title(['Subj' num2str(ss) ' - ' twinNames{tw}]);
  660. else; title(['Subjs1:2 - ' twinNames{tw}]); end
  661. gch=gca; gch.XTick=1:length(b)-1;
  662. gch.XTickLabel={'EV_L','EV_R','\sigma^2_L','\sigma^2_R','s_L_R','f_R'};
  663. gch.XTickLabelRotation=90;
  664. if tw==1; ylabel('glm weights'); else; gch=gca; gch.YTick=[]; end
  665. end
  666. [~,~,~,ptwfdr]=fdr_bh(ptw);
  667. for tw=1:8
  668. subplot(3,8,(ss-1)*8+tw);
  669. for jj=1:size(btw,1)
  670. text(jj-.5,btw(jj,tw)+.1*(btw(jj,tw)>0)-0.1*(btw(jj,tw)<0),getpstars(ptwfdr(jj,tw)));
  671. end
  672. ylim([bmin bmax].*1.25);
  673. end
  674. end
  675. if isweightnormalized
  676. isspstr='nonnrm';
  677. else
  678. isspstr='maxnrm';
  679. end
  680. if focusaroundstimuli
  681. focstr='isfocusedonst';
  682. else
  683. focstr='nonfocusedonst';
  684. end
  685. supertitle(['Subjects 1, 2, 1:2, all sessions, focus: ' num2str(focusaroundstimuli) ', norm weights: ' num2str(isweightnormalized)]);
  686. print(hfig,[figures_folder '/Fig2C-Behavioral-Choice-GLM-' isspstr '-' focstr '.svg'],'-dsvg','-r600');
  687. print(hfig,[figures_folder '/Fig2C-Behavioral-Choice-GLM-' isspstr '-' focstr '.png'],'-dpng','-r600');
  688. saveas(hfig,[figures_folder '/Fig2C-Behavioral-Choice-GLM-' isspstr '-' focstr '.fig']);
  689. end
  690. end
  691. end
  692. if plotopts.Fig2D
  693. %% Fig 2D - Logistic GLM of choice with epochs combined
  694. hfig=figure('units','normalized','position',[0 0 1 1]);
  695. for inclsideLR=0:1
  696. if ~(trpool<3 && inclsideLR==1)
  697. for focusaroundstimuli=0:1
  698. fracR_off1_del1_off2_del2=nan(length([s1gbi.offer1ev; s2gbi.offer1ev]),4);
  699. for tw=2:5
  700. s1cpx1=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifLsR,:))']);
  701. s1cpx2=eval(['(s1gem' num2str(tw) '.posX(s1gbi.ifRsL,:))']);
  702. s2cpx1=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifLsR,:))']);
  703. s2cpx2=eval(['(s2gem' num2str(tw) '.posX(s2gbi.ifRsL,:))']);
  704. s1cpx1=s1cpx1(:,mean(~isnan(s1cpx1),1)>=.999); s1cpx2=s1cpx2(:,mean(~isnan(s1cpx2),1)>=.999);
  705. s2cpx1=s2cpx1(:,mean(~isnan(s2cpx1),1)>=.999); s2cpx2=s2cpx2(:,mean(~isnan(s2cpx2),1)>=.999);
  706. s1cpx=[s1cpx1(:,1:min(size(s1cpx1,2),size(s1cpx2,2))); -s1cpx2(:,1:min(size(s1cpx1,2),size(s1cpx2,2)))];
  707. s2cpx=[s2cpx1(:,1:min(size(s2cpx1,2),size(s2cpx2,2))); -s2cpx2(:,1:min(size(s2cpx1,2),size(s2cpx2,2)))];
  708. s1cpx=s1cpx(:,mean(~isnan(s1cpx),1)>=.999);
  709. s2cpx=s2cpx(:,mean(~isnan(s2cpx),1)>=.999);
  710. %cpx=[s1cpx; s2cpx];
  711. %if tw==2 || tw==4
  712. % % cpx=[s1cpx(:,end-200+1:end); s2cpx(:,end-200+1:end)];
  713. % s1cpx=s1cpx(:,end-200+1:end);
  714. % s2cpx=s2cpx(:,end-200+1:end);
  715. %else
  716. % % cpx=[s1cpx(:,1:200); s2cpx(:,1:200)];
  717. % s1cpx=s1cpx(:,1:200);
  718. % s2cpx=s2cpx(:,1:200);
  719. %end
  720. if focusaroundstimuli
  721. s1cpx_Rts=rmnansandwithin(s1cpx,[7.5e3,+10e3]);
  722. %s1cpy_Rts=nan(size(s1cpx_Rts)); s1cpy_Rts(~isnan(s1cpx_Rts))=s1cpy(~isnan(s1cpx_Rts));
  723. %s1cpy_Rts=rmnansandwithin(s1cpy_Rts,[-8e3 8e3]);
  724. %s1cpx_Rts(isnan(s1cpy_Rts))=s1cpy_Rts(isnan(s1cpy_Rts));
  725. s1cpx_Lts=rmnansandwithin(s1cpx,[-10e3,-7.5e3]);
  726. %s1cpy_Lts=nan(size(s1cpx_Lts)); s1cpy_Lts(~isnan(s1cpx_Lts))=s1cpy(~isnan(s1cpx_Lts));
  727. %s1cpy_Lts=rmnansandwithin(s1cpy_Lts,[-8e3 8e3]);
  728. %s1cpx_Lts(isnan(s1cpy_Lts))=s1cpy_Lts(isnan(s1cpy_Lts));
  729. s2cpx_Rts=rmnansandwithin(s2cpx,[7.5e3,+10e3]);
  730. %s2cpy_Rts=nan(size(s2cpx_Rts)); s2cpy_Rts(~isnan(s2cpx_Rts))=s2cpy(~isnan(s2cpx_Rts));
  731. %s2cpy_Rts=rmnansandwithin(s2cpy_Rts,[-8e3 8e3]);
  732. %s2cpx_Rts(isnan(s2cpy_Rts))=s2cpy_Rts(isnan(s2cpy_Rts));
  733. s2cpx_Lts=rmnansandwithin(s2cpx,[-10e3,-7.5e3]);
  734. %s2cpy_Lts=nan(size(s2cpx_Lts)); s2cpy_Lts(~isnan(s2cpx_Lts))=s2cpy(~isnan(s2cpx_Lts));
  735. %s2cpy_Lts=rmnansandwithin(s2cpy_Lts,[-8e3 8e3]);
  736. %s2cpx_Lts(isnan(s2cpy_Lts))=s2cpy_Lts(isnan(s2cpy_Lts));
  737. s1cpx=nan(size(s1cpx)); s1cpx(~isnan(s1cpx_Rts))=s1cpx_Rts(~isnan(s1cpx_Rts)); s1cpx(~isnan(s1cpx_Lts))=s1cpx_Lts(~isnan(s1cpx_Lts));
  738. %s1cpy=nan(size(s1cpy)); s1cpy(~isnan(s1cpy_Rts))=s1cpy_Rts(~isnan(s1cpy_Rts)); s1cpx(~isnan(s1cpy_Lts))=s1cpy_Lts(~isnan(s1cpy_Lts));
  739. s2cpx=nan(size(s2cpx)); s2cpx(~isnan(s2cpx_Rts))=s2cpx_Rts(~isnan(s2cpx_Rts)); s2cpx(~isnan(s2cpx_Lts))=s2cpx_Lts(~isnan(s2cpx_Lts));
  740. %s2cpy=nan(size(s2cpy)); s2cpy(~isnan(s2cpy_Rts))=s2cpy_Rts(~isnan(s2cpy_Rts)); s2cpx(~isnan(s2cpy_Lts))=s2cpy_Lts(~isnan(s2cpy_Lts));
  741. end
  742. % subplot(2,4,tw-1);
  743. % plotperc(1:size(cpx,2),cpx,[66 33; 20 80; 49.9 50.1],'k',.15);
  744. % plot(1:size(cpx,2),nanmean(cpx),'k','linewidth',1.5);
  745. % plothline(0,'k:'); ylim([-3 3]/2*1e4);
  746. %
  747. % subplot(2,4,4+tw-1);
  748. % plotperc(1:size(cpx,2),[s1cpx1; s2cpx1],[66 33; 20 80],'b',.1);
  749. % plotperc(1:size(cpx,2),-[s1cpx2; s2cpx2],[66 33; 20 80],'r',.1);
  750. % plot(1:size(cpx,2),nanmean(-[s1cpx2; s2cpx2]),'r','linewidth',1.5);
  751. % plot(1:size(cpx,2),nanmean([s1cpx1; s2cpx1]),'b','linewidth',1.5);
  752. % plothline(0,'k:'); ylim([-3 3]/2*1e4);
  753. % if tw==2 || tw==4; plotvline(200,'k:'); elseif tw==3 || tw==5; plotvline(size(cpx,2)-200,'k:'); end
  754. %
  755. %subplot(2,4,8+tw-1);
  756. %plotperc(1:size(cpx,2),[s1cpx2; s2cpx2],[49 51; 66 33; 20 80],'k',.15);
  757. %ylim([-3 3]*1e4);
  758. %s1cpn=(isnan(s1cpx) | isnan(s1cpy)); s1cp0=(s1cpx==0 & s1cpy==0); s1cpx(s1cpn | s1cp0)=nan; s1cpy(s1cpn | s1cp0)=nan;
  759. s1cpn=(isnan(s1cpx)); s1cp0=(s1cpx==0); s1cpx(s1cpn | s1cp0)=nan;
  760. s1sum_L=sum(~isnan(rmnansandthreshold(-s1cpx,0)),2);
  761. s1sum_R=sum(~isnan(rmnansandthreshold(+s1cpx,0)),2);
  762. s1frac_R=s1sum_R./(s1sum_R+s1sum_L+eps);
  763. %s2cpn=(isnan(s2cpx) | isnan(s2cpy)); s2cp0=(s2cpx==0 & s2cpy==0); s2cpx(s2cpn | s2cp0)=nan; s2cpy(s2cpn | s2cp0)=nan;
  764. s2cpn=(isnan(s2cpx)); s2cp0=(s2cpx==0); s2cpx(s2cpn | s2cp0)=nan;
  765. s2sum_L=sum(~isnan(rmnansandthreshold(-s2cpx,0)),2);
  766. s2sum_R=sum(~isnan(rmnansandthreshold(+s2cpx,0)),2);
  767. s2frac_R=s2sum_R./(s2sum_R+s2sum_L+eps);
  768. %frac_R=[s1frac_R; s2frac_R];
  769. frac_R=[mat2gray(s1frac_R); mat2gray(s2frac_R)];
  770. %frac_L=sum_L./(sum_L+sum_R+eps); frac_R=1-frac_L;
  771. %frac_R=sum_R./(sum_L+sum_R+eps);
  772. %sum_R=mat2gray(sum_R); sum_L=mat2gray(sum_L);
  773. %frac_R=sum_R./(sum_R+sum_L); frac_L=sum_L./(sum_L+sum_R);
  774. fracR_off1_del1_off2_del2(:,tw-1)=frac_R;
  775. %fracR_off1_del1_off2_del2(:,tw-1)=nanmean(double([s1cpx; s2cpx]>0),2)./(nanmean(double([s1cpx; s2cpx]>0),2)+nanmean(double([s1cpx; s2cpx]<0),2)+eps);
  776. end
  777. evL =[s1gbi.offerLev(s1gbi.ifLsR); s1gbi.offerLev(s1gbi.ifRsL); s2gbi.offerLev(s2gbi.ifLsR); s2gbi.offerLev(s2gbi.ifRsL)];
  778. evR =[s1gbi.offerRev(s1gbi.ifLsR); s1gbi.offerRev(s1gbi.ifRsL); s2gbi.offerRev(s2gbi.ifLsR); s2gbi.offerRev(s2gbi.ifRsL)];
  779. varL =[s1gbi.offerLvar(s1gbi.ifLsR); s1gbi.offerLvar(s1gbi.ifRsL); s2gbi.offerLvar(s2gbi.ifLsR); s2gbi.offerLvar(s2gbi.ifRsL)];
  780. varR =[s1gbi.offerRvar(s1gbi.ifLsR); s1gbi.offerRvar(s1gbi.ifRsL); s2gbi.offerRvar(s2gbi.ifLsR); s2gbi.offerRvar(s2gbi.ifRsL)];
  781. sideRL=[ones(length(s1gbi.ifLsR),1); -ones(length(s1gbi.ifRsL),1); ones(length(s2gbi.ifLsR),1); -ones(length(s2gbi.ifRsL),1)];
  782. s1chsd1=gbi1.choose12(gbi1.ifLsR)==2; s1chsd2=gbi1.choose12(gbi1.ifRsL)==1;
  783. s2chsd1=gbi2.choose12(gbi2.ifLsR)==2; s2chsd2=gbi2.choose12(gbi2.ifRsL)==1;
  784. if inclsideLR
  785. x1=[evL/max(evL) evR/max(evR) varL/max(varL) varR/max(varR) sideRL fracR_off1_del1_off2_del2];
  786. else
  787. x1=[evL/max(evL) evR/max(evR) varL/max(varL) varR/max(varR) fracR_off1_del1_off2_del2];
  788. end
  789. %x1=fracR_off1_del1_off2_del2;
  790. y1=[s1chsd1; s1chsd2; s2chsd1; s2chsd2];
  791. logitMdl= fitglm(x1,y1,'Distribution','binomial','Link','logit');
  792. subplot(2,2,focusaroundstimuli+2*inclsideLR+1)
  793. bar(1:size(x1,2),logitMdl.Coefficients.Estimate(2:end));
  794. for jj=1:size(x1,2); text(jj-.15,7,getpstars(logitMdl.Coefficients.pValue(jj+1))); end
  795. ylim([-1 1].*8); ylabel('logistic model weights'); box off
  796. if inclsideLR
  797. gch=gca; gch.XTickLabel={'EV_L','EV_R','\sigma^2_L','\sigma^2_R','s_L_R','f_R offer1','f_R delay1','f_R offer2','f_R delay2'};
  798. else
  799. gch=gca; gch.XTickLabel={'EV_L','EV_R','\sigma^2_L','\sigma^2_R','f_R offer1','f_R delay1','f_R offer2','f_R delay2'};
  800. end
  801. rectangle('Position',[4.7+inclsideLR 5 .6 1.5],'facecolor','k');
  802. rectangle('Position',[5.7+inclsideLR 5 .6 1.5],'facecolor','k');
  803. rectangle('Position',[6.7+inclsideLR 5 .6 1.5],'facecolor','k');
  804. rectangle('Position',[7.7+inclsideLR 5 .6 1.5],'facecolor','k');
  805. rectangle('Position',[4.8+inclsideLR 5.2 .1 1],'facecolor',[0 .7 0]); rectangle('Position',[4.8+inclsideLR 6 .1 .2],'facecolor',[.7 0 0]);
  806. rectangle('Position',[7.1+inclsideLR 5.2 .1 1],'facecolor',[0 0 .7]); rectangle('Position',[7.1+inclsideLR 5.7 .1 .5],'facecolor',[.7 0 0]);
  807. %gch=gca; gch.XTickLabel={'f_R offer1','f_R delay1','f_R offer2','f_R delay2'};
  808. gch.XTickLabelRotation=30;
  809. if ~focusaroundstimuli && inclsideLR
  810. title('logit model of choice - include side s_L_R')
  811. elseif ~focusaroundstimuli && ~inclsideLR
  812. title('logit model of choice')
  813. elseif focusaroundstimuli && inclsideLR
  814. title('logit model of choice - include side s_L_R - focus around stimuli')
  815. elseif focusaroundstimuli && ~inclsideLR
  816. title('logit model of choice - focus around stimuli')
  817. end
  818. end
  819. end
  820. end
  821. supertitle('All trials');
  822. saveas(hfig,[figures_folder '/Fig2D-Logit_off1del1off2del2_ALL.png']);
  823. saveas(hfig,[figures_folder '/Fig2D-Logit_off1del1off2del2_ALL.fig']);
  824. saveas(hfig,[figures_folder '/Fig2D-Logit_off1del1off2del2_ALL.svg']);
  825. end