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.

neuralAnalysesChoiceResiduals.m 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. addpath(genpath('../../../../my-tools'));
  2. addpath(genpath('../../../../external-tools'));
  3. clearvars -except subjsData poolstack* pooltw*
  4. rng(0)
  5. curr_rng=rng; % saves random seed as the results may vary
  6. recomputelm=1;
  7. Nlag=10; Nspan=200;
  8. Nshf=0; selectdifftrials=1;
  9. if ~exist('poolstackvars','var')
  10. load '../../poolstackvars_270923.mat';
  11. end
  12. if ~exist('pooltweyepos','var')
  13. load '../latestpooltweyepos_14feb22.mat'
  14. end
  15. if ~exist('pooltwspksq','var')
  16. load '../latestpooltwspks_14feb22.mat'
  17. end
  18. twLabels={'preoffer1','offer1','delay1','offer2','delay2','refix','ch-go','ch-hold'};
  19. nccs=[ 51 59 24 29 18 32 9 26];
  20. ntrs=arrayfun(@(xx) size(poolstackvars(xx).offer1sd,1),1:8);
  21. Nccs=sum(nccs);
  22. Ntrs12=max(ntrs);
  23. Ntps12=arrayfun(@(tw) size(pooltweyepos(tw).posX,3), 1:8);
  24. Ntps12(1)=400;
  25. pooleposxmat=cat(3,pooltweyepos(1).posX,pooltweyepos(2).posX,pooltweyepos(3).posX,pooltweyepos(4).posX,...
  26. pooltweyepos(5).posX,pooltweyepos(6).posX,pooltweyepos(7).posX,pooltweyepos(8).posX);
  27. poolspksqmat=cat(3,pooltwspksq(1).spkseqs,pooltwspksq(2).spkseqs,pooltwspksq(3).spkseqs,pooltwspksq(4).spkseqs,...
  28. pooltwspksq(5).spkseqs,pooltwspksq(6).spkseqs,pooltwspksq(7).spkseqs,pooltwspksq(8).spkseqs);
  29. poolcovhist=cat(2,pooltwspksq(1).covhist,pooltwspksq(2).covhist,pooltwspksq(3).covhist,pooltwspksq(4).covhist,...
  30. pooltwspksq(5).covhist,pooltwspksq(6).covhist,pooltwspksq(7).covhist,pooltwspksq(8).covhist);
  31. clearvars pooltweyepos pooltwspksq
  32. pooloffer1sd=[]; poolofferLev=[]; poolofferRev=[]; pooloffer1ev=[]; pooloffer2ev=[]; pooloffer1var=[]; pooloffer2var=[];
  33. poolofferchR=[]; pooloffer1pr=[]; pooloffer2pr=[]; pooloffer1rw=[]; pooloffer2rw=[];
  34. for sn=1:8
  35. pooloffer1sd=cat(2, pooloffer1sd, repmat(cat(1,poolstackvars(sn).offer1sd,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  36. poolofferLev=cat(2, poolofferLev, repmat(cat(1,poolstackvars(sn).offerLev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  37. poolofferRev=cat(2, poolofferRev, repmat(cat(1,poolstackvars(sn).offerRev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  38. pooloffer1ev=cat(2, pooloffer1ev, repmat(cat(1,poolstackvars(sn).offer1ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  39. pooloffer2ev=cat(2, pooloffer2ev, repmat(cat(1,poolstackvars(sn).offer2ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  40. pooloffer1var=cat(2, pooloffer1var, repmat(cat(1,poolstackvars(sn).offer1var,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  41. pooloffer2var=cat(2, pooloffer2var, repmat(cat(1,poolstackvars(sn).offer2var,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  42. poolofferchR=cat(2, poolofferchR, repmat(cat(1,poolstackvars(sn).chooseR, nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  43. pooloffer1pr=cat(2, pooloffer1pr, repmat(cat(1,poolstackvars(sn).offer1pr,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  44. pooloffer2pr=cat(2, pooloffer2pr, repmat(cat(1,poolstackvars(sn).offer2pr,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  45. pooloffer1rw=cat(2, pooloffer1rw, repmat(cat(1,poolstackvars(sn).offer1rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  46. pooloffer2rw=cat(2, pooloffer2rw, repmat(cat(1,poolstackvars(sn).offer2rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  47. end
  48. %clearvars pooltwspksq pooltweyepos
  49. %fchg=find(poolcovhist>=.8); fchl=find(poolcovhist<.8);
  50. fchg=find(poolcovhist>=.999); fchl=find(poolcovhist<.999);
  51. ntcv=[fchg(diff([fchg sum(Ntps12)])>1)' fchl([diff(fchl) sum(Ntps12)]>1)'];
  52. ntce=[[1; 401; ntcv(1:end-1,2)] [400; ntcv(:,1)]];
  53. vtps=ones(1,sum(Ntps12)); for jj=1:7; vtps(ntcv(jj,1):ntcv(jj,2))=nan; end
  54. %% smooth by movmean filtering, downsample to 20ms, 50Hz resolution
  55. Ntps_ds=ceil(sum(Ntps12)/Nlag);
  56. %tmax_ds=nanmovmean(1:size(pooleposxmat,3),Nlag,Nlag);
  57. tmax_ds=nanmovmean(1:sum(Ntps12),Nlag,Nlag);
  58. poolspksqmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  59. pooleposxmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  60. for cc=1:Nccs
  61. poolspksqmat_ds(:,cc,:)=nanmovmean(squeeze(poolspksqmat(:,cc,:))',Nlag,[0 Nspan])';
  62. pooleposxmat_ds(:,cc,:)=nanmovmean(squeeze(pooleposxmat(:,cc,:))',Nlag,Nlag)';
  63. end
  64. clearvars poolspksqmat pooleposxmat
  65. poolcovhist_ds=nanmovmean(poolcovhist,Nlag,Nlag);
  66. %fcgh_ds=find(poolcovhist_ds>=.8); fchl_ds=find(poolcovhist_ds<.8);
  67. fcgh_ds=find(poolcovhist_ds>=.999); fchl_ds=find(poolcovhist_ds<.999);
  68. ntcv_ds=[fcgh_ds(diff([fcgh_ds Ntps_ds])>1)' fchl_ds([diff(fchl_ds) Ntps_ds]>1)'];
  69. vtps_ds=ones(1,Ntps_ds); for jj=1:7; vtps_ds(ntcv_ds(jj,1):ntcv_ds(jj,2))=nan; end
  70. ntce_ds=[[1 ceil(400/Nlag)+1 find(vtps_ds(2:end)+isnan(vtps_ds(1:end-1))==2)+1]' [ceil(400/Nlag) find(vtps_ds(1:end-1)+isnan(vtps_ds(2:end))==2)]'];
  71. vtmax_ds=rmnans(tmax_ds.*vtps_ds);%find(rmnans(vtps_ds));
  72. rtmax_ds=1:length(vtmax_ds);
  73. rtmes_ds=arrayfun(@(jj) length(ntce_ds(jj,1):ntce_ds(jj,2)), 1:8);
  74. %No baseline normalization
  75. poolspksqmat_ds_bln=poolspksqmat_ds;
  76. clearvars poolspksqmat_ds
  77. %%
  78. del2tpoi=ntce_ds(5,1):ntce_ds(5,2);
  79. Ntps_ds=length(del2tpoi);
  80. %beh_weights_mat=nan(Ntps_ds,Nccs,7);
  81. %beh_pvalues_mat=nan(Ntps_ds,Nccs,7);
  82. %zetas_ss1_mat=nan(Ntrs12,Nccs,Ntps_ds); zetas_ss2_mat=nan(Ntrs12,Nccs,Ntps_ds);
  83. %zetasLL_ss1_mat=nan(Ntrs12,Nccs,Ntps_ds); zetasLL_ss2_mat=nan(Ntrs12,Nccs,Ntps_ds);
  84. %zetasLR_ss1_mat=nan(Ntrs12,Nccs,Ntps_ds); zetasLR_ss2_mat=nan(Ntrs12,Nccs,Ntps_ds);
  85. %zetas_ch_bw1_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds); zetas_ch_bw1_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds);
  86. %zetas_ch_bw1_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds); zetas_ch_bw1_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds);
  87. %zetas_ch_bw2_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds); zetas_ch_bw2_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds);
  88. %zetas_ch_bw2_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds); zetas_ch_bw2_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds);
  89. Nsubg=1;
  90. zetas_noch_bw0_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw0_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  91. zetas_noch_bw0_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw0_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  92. zetas_noch_bw1_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw1_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  93. zetas_noch_bw1_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw1_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  94. zetas_noch_bw2_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw2_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  95. zetas_noch_bw2_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw2_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  96. zetas_noch_bw0_ss0LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); zetas_noch_bw0_ss0LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  97. betas_noch_bw0_ss0LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw0_ss0LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  98. pvals_noch_bw0_ss0LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); pvals_noch_bw0_ss0LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  99. betas_ch_bw0_ss1LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw0_ss1LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  100. betas_ch_bw0_ss2LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw0_ss2LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  101. betas_noch_bw0_ss1LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw0_ss1LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  102. betas_noch_bw0_ss2LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw0_ss2LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  103. betas_ch_bw1_ss1LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw1_ss1LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  104. betas_ch_bw1_ss2LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw1_ss2LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  105. betas_noch_bw1_ss1LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw1_ss1LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  106. betas_noch_bw1_ss2LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw1_ss2LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  107. betas_ch_bw2_ss1LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw2_ss1LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  108. betas_ch_bw2_ss2LL_mat=nan(4,Nccs,Ntps_ds,Nsubg); betas_ch_bw2_ss2LR_mat=nan(4,Nccs,Ntps_ds,Nsubg);
  109. betas_noch_bw2_ss1LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw2_ss1LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  110. betas_noch_bw2_ss2LL_mat=nan(3,Nccs,Ntps_ds,Nsubg); betas_noch_bw2_ss2LR_mat=nan(3,Nccs,Ntps_ds,Nsubg);
  111. useinterceptflag=0;
  112. bbetas_ch_bw0_ss1LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw0_ss1LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  113. bbetas_ch_bw0_ss2LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw0_ss2LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  114. bbetas_ch_bw1_ss1LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw1_ss1LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  115. bbetas_ch_bw1_ss2LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw1_ss2LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  116. bbetas_ch_bw2_ss1LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw2_ss1LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  117. bbetas_ch_bw2_ss2LL_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg); bbetas_ch_bw2_ss2LR_mat=nan(1+useinterceptflag,Nccs,Ntps_ds,Nsubg);
  118. pvals_ch_bw0_ss1LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw0_ss1LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  119. pvals_ch_bw0_ss2LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw0_ss2LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  120. pvals_noch_bw0_ss1LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw0_ss1LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  121. pvals_noch_bw0_ss2LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw0_ss2LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  122. pvals_ch_bw1_ss1LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw1_ss1LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  123. pvals_ch_bw1_ss2LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw1_ss2LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  124. pvals_noch_bw1_ss1LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw1_ss1LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  125. pvals_noch_bw1_ss2LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw1_ss2LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  126. pvals_ch_bw2_ss1LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw2_ss1LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  127. pvals_ch_bw2_ss2LL_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg)); pvals_ch_bw2_ss2LR_mat=uint8(zeros(4,Nccs,Ntps_ds,Nsubg));
  128. pvals_noch_bw2_ss1LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw2_ss1LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  129. pvals_noch_bw2_ss2LL_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg)); pvals_noch_bw2_ss2LR_mat=uint8(zeros(3,Nccs,Ntps_ds,Nsubg));
  130. ppvals_ch_bw0_ss1LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw0_ss1LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  131. ppvals_ch_bw0_ss2LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw0_ss2LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  132. ppvals_ch_bw1_ss1LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw1_ss1LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  133. ppvals_ch_bw1_ss2LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw1_ss2LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  134. ppvals_ch_bw2_ss1LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw2_ss1LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  135. ppvals_ch_bw2_ss2LL_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg)); ppvals_ch_bw2_ss2LR_mat=uint8(zeros(1+useinterceptflag,Nccs,Ntps_ds,Nsubg));
  136. offch_ss0LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss0LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  137. offch_ss1LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss1LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  138. offch_ss2LL_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss2LR_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  139. offch_ss0LL_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss0LR_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  140. offch_ss1LL_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss1LR_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  141. offch_ss2LL_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg); offch_ss2LR_noflip_mat=nan(Ntrs12,Nccs,Ntps_ds,Nsubg);
  142. % beta0s_ss1_mat=nan(Nccs,Ntps_ds); beta0s_ss2_mat=nan(Nccs,Ntps_ds);
  143. % beta1s_ss1_mat=nan(Nccs,Ntps_ds); beta1s_ss2_mat=nan(Nccs,Ntps_ds);
  144. % beta2s_ss1_mat=nan(Nccs,Ntps_ds); beta2s_ss2_mat=nan(Nccs,Ntps_ds);
  145. % beta0sLL_ss1_mat=nan(Nccs,Ntps_ds); beta0sLL_ss2_mat=nan(Nccs,Ntps_ds);
  146. % beta1sLL_ss1_mat=nan(Nccs,Ntps_ds); beta1sLL_ss2_mat=nan(Nccs,Ntps_ds);
  147. % beta2sLL_ss1_mat=nan(Nccs,Ntps_ds); beta2sLL_ss2_mat=nan(Nccs,Ntps_ds);
  148. % beta0sLR_ss1_mat=nan(Nccs,Ntps_ds); beta0sLR_ss2_mat=nan(Nccs,Ntps_ds);
  149. % beta1sLR_ss1_mat=nan(Nccs,Ntps_ds); beta1sLR_ss2_mat=nan(Nccs,Ntps_ds);
  150. % beta2sLR_ss1_mat=nan(Nccs,Ntps_ds); beta2sLR_ss2_mat=nan(Nccs,Ntps_ds);
  151. %
  152. % beta00s_ss1_mat=nan(Nccs,Ntps_ds); beta00s_ss2_mat=nan(Nccs,Ntps_ds);
  153. % beta01s_ss1_mat=nan(Nccs,Ntps_ds); beta01s_ss2_mat=nan(Nccs,Ntps_ds);
  154. % beta00sLL_ss1_mat=nan(Nccs,Ntps_ds); beta00sLL_ss2_mat=nan(Nccs,Ntps_ds);
  155. % beta01sLL_ss1_mat=nan(Nccs,Ntps_ds); beta01sLL_ss2_mat=nan(Nccs,Ntps_ds);
  156. % beta00sLR_ss1_mat=nan(Nccs,Ntps_ds); beta00sLR_ss2_mat=nan(Nccs,Ntps_ds);
  157. % beta01sLR_ss1_mat=nan(Nccs,Ntps_ds); beta01sLR_ss2_mat=nan(Nccs,Ntps_ds);
  158. if recomputelm
  159. for sg=1:Nsubg
  160. for cc=1:Nccs
  161. %ccspk=squeeze(poolspksqmat_ds(:,cc,:));
  162. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,:));
  163. ccepx=squeeze(pooleposxmat_ds(:,cc,:));
  164. ccoffEVL=squeeze(pooloffer1ev(:,cc));
  165. ccoffEVR=squeeze(pooloffer2ev(:,cc));
  166. ccoffPrL=squeeze(pooloffer1pr(:,cc));
  167. ccoffPrR=squeeze(pooloffer2pr(:,cc));
  168. ccoffRwL=squeeze(pooloffer1rw(:,cc));
  169. ccoffRwR=squeeze(pooloffer2rw(:,cc));
  170. ccoffvarL=squeeze(pooloffer1var(:,cc));
  171. ccoffvarR=squeeze(pooloffer2var(:,cc));
  172. ccoffchR=squeeze(poolofferchR(:,cc));
  173. ccoff1sd=squeeze(pooloffer1sd(:,cc));
  174. toskip=isnan(ccoffchR);
  175. if selectdifftrials
  176. toskip=isnan(ccoffchR)+double(abs(ccoffEVL-ccoffEVR)>1);
  177. end
  178. vccoff1sd=ccoff1sd(~toskip); % 1stL=1, 1stR=0
  179. vccoffchR=ccoffchR(~toskip);
  180. vccoffEVR=ccoffEVR(~toskip);
  181. vccoffEVL=ccoffEVL(~toskip);
  182. %max(abs(vccoffEVL-vccoffEVR));
  183. %vccoffPrR=ccoffPrR(~toskip);
  184. %vccoffPrL=ccoffPrL(~toskip);
  185. vccoffRwR=ccoffRwR(~toskip);
  186. vccoffRwL=ccoffRwL(~toskip);
  187. vccoffvarR=ccoffvarR(~toskip);
  188. vccoffvarL=ccoffvarL(~toskip);
  189. % FOR SVs WE USE chR as 0,1
  190. vccoffchR_flip=vccoffchR;
  191. vccoffchR_flip(vccoff1sd==0)=1-vccoffchR_flip(vccoff1sd==0);
  192. %vccoffchR_flip(vccoffchR_flip==0)=-1;
  193. % FOR THE LINEAR MODEL WE USE chR AS -1 +1
  194. vccoffchR(vccoffchR==0)=-1;
  195. nicc=length(vccoffchR);
  196. ss1=randperm(nicc,round(nicc/2));
  197. ss2=setdiff(1:nicc,ss1);
  198. behvars=[-vccoffRwL -vccoffEVL -vccoffvarL vccoffRwR vccoffEVR vccoffvarR];
  199. behchglm_bw0=fitglm(behvars,vccoffchR_flip,'Distribution','binomial','link','logit');
  200. behchglm_weights_bw0=behchglm_bw0.Coefficients.Estimate(2:end);
  201. behchglm_bw1=fitglm(behvars(ss1,:),vccoffchR_flip(ss1),'Distribution','binomial','link','logit');
  202. behchglm_weights_bw1=behchglm_bw1.Coefficients.Estimate(2:end);
  203. behchglm_bw2=fitglm(behvars(ss2,:),vccoffchR_flip(ss2),'Distribution','binomial','link','logit');
  204. behchglm_weights_bw2=behchglm_bw2.Coefficients.Estimate(2:end);
  205. vccoffSVL_bw0=behchglm_weights_bw0(1).*vccoffRwL+behchglm_weights_bw0(2).*vccoffEVL+behchglm_weights_bw0(3).*vccoffvarL;
  206. vccoffSVR_bw0=behchglm_weights_bw0(4).*vccoffRwR+behchglm_weights_bw0(5).*vccoffEVR+behchglm_weights_bw0(6).*vccoffvarR;
  207. vccoffSVL_bw1=behchglm_weights_bw1(1).*vccoffRwL+behchglm_weights_bw1(2).*vccoffEVL+behchglm_weights_bw1(3).*vccoffvarL;
  208. vccoffSVR_bw1=behchglm_weights_bw1(4).*vccoffRwR+behchglm_weights_bw1(5).*vccoffEVR+behchglm_weights_bw1(6).*vccoffvarR;
  209. vccoffSVL_bw2=behchglm_weights_bw2(1).*vccoffRwL+behchglm_weights_bw2(2).*vccoffEVL+behchglm_weights_bw2(3).*vccoffvarL;
  210. vccoffSVR_bw2=behchglm_weights_bw2(4).*vccoffRwR+behchglm_weights_bw2(5).*vccoffEVR+behchglm_weights_bw2(6).*vccoffvarR;
  211. parfor tt=1:Ntps_ds
  212. %warning('off','all')
  213. if vtps_ds(del2tpoi(tt))==1
  214. ctccspk=squeeze(ccspk(:,del2tpoi(tt)));
  215. ctccepx=squeeze(ccepx(:,del2tpoi(tt)));
  216. %toskip=isnan(ccoffchR); % from outer loop
  217. %toskip=isnan(ccoffchR) | isnan(ctccspk) | isnan(ctccepx);
  218. vctccspk=ctccspk(~toskip);
  219. vctccepx=ctccepx(~toskip);
  220. ss0LL=find(vctccepx<0); niLL=length(ss0LL);
  221. ss0LR=find(vctccepx>0); niLR=length(ss0LR);
  222. % one randomization for all bins
  223. ss1LL=intersect(ss0LL,ss1);%randperm(niLL,round(niLL/2));
  224. ss1LR=intersect(ss0LR,ss1);%randperm(niLR,round(niLR/2));
  225. ss2LL=intersect(ss0LL,ss2);%setdiff(1:niLL,ss1LL);
  226. ss2LR=intersect(ss0LR,ss2);%setdiff(1:niLR,ss1LR);
  227. % bin-by-bin randomization
  228. %ss1LL=randperm(niLL,round(niLL/2));
  229. %ss1LR=randperm(niLR,round(niLR/2));
  230. %ss2LL=setdiff(1:niLL,ss1LL);
  231. %ss2LR=setdiff(1:niLR,ss1LR);
  232. % FITTING LM FOR SV: NOCH LL/LR (SS0, BW0)
  233. ctwcclm_noch_bw0_ss0LL=fitlm([vccoffSVL_bw0(ss0LL) vccoffSVR_bw0(ss0LL)], vctccspk(ss0LL));
  234. zetas_noch_bw0_ss0LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss0LL.Residuals.Raw; nan(Ntrs12-length(ss0LL),1)];
  235. betas_noch_bw0_ss0LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw0_ss0LL.Coefficients.Estimate;
  236. pvals_noch_bw0_ss0LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss0LL.Coefficients.pValue<0.05);
  237. ctwcclm_noch_bw0_ss0LR=fitlm([vccoffSVL_bw0(ss0LR) vccoffSVR_bw0(ss0LR)], vctccspk(ss0LR));
  238. zetas_noch_bw0_ss0LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss0LR.Residuals.Raw; nan(Ntrs12-length(ss0LR),1)];
  239. betas_noch_bw0_ss0LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw0_ss0LR.Coefficients.Estimate;
  240. pvals_noch_bw0_ss0LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss0LR.Coefficients.pValue<0.05);
  241. % %% Quick check about the sign of residuals
  242. % eta=vctccspk;
  243. % svL=vccoffSVL_bw0;
  244. % svR=vccoffSVR_bw0;
  245. % lmL=fitlm(svL,eta);
  246. % lmR=fitlm(svL,eta);
  247. % zetaL=lmL.Residuals.Raw;
  248. % betaL=lmL.Coefficients.Estimate;
  249. % zetaR=lmR.Residuals.Raw;
  250. % betaR=lmR.Coefficients.Estimate;
  251. %
  252. % fullfig([0 0 .4 .4]);
  253. % subplot(2,2,1);
  254. % plot(svL,eta,'k.'); hold on
  255. % plot(sort(svL),beta(1)+sort(svL).*beta(2),'-');
  256. % xlabel('SV_L'); ylabel('\eta');
  257. % subplot(2,2,2);
  258. % plot(svR,eta,'k.'); hold on
  259. % plot(sort(svR),beta(1)+sort(svR).*beta(2),'-');
  260. % xlabel('SV_R'); ylabel('\eta');
  261. %
  262. % subplot(2,2,3);
  263. % plot(svL,zeta,'r.'); hold on
  264. % xlabel('SV_L'); ylabel('residuals');
  265. % subplot(2,2,4);
  266. % plot(svR,zeta,'r.'); hold on
  267. % xlabel('SV_R'); ylabel('residuals');
  268. %
  269. % %%
  270. % FITTING LM FOR SV: CH/NOCH LL/LR (SS1, BW0)
  271. ctwcclm_ch_bw0_ss1LL=fitlm([vccoffSVL_bw0(ss1LL) vccoffSVR_bw0(ss1LL) vccoffchR(ss1LL)], vctccspk(ss1LL));
  272. %zetas_ch_bw0_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw0_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  273. betas_ch_bw0_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss1LL.Coefficients.Estimate;
  274. pvals_ch_bw0_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss1LL.Coefficients.pValue<0.05);
  275. ctwcclm_ch_bw0_ss1LR=fitlm([vccoffSVL_bw0(ss1LR) vccoffSVR_bw0(ss1LR) vccoffchR(ss1LR)], vctccspk(ss1LR));
  276. %zetas_ch_bw0_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw0_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  277. betas_ch_bw0_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss1LR.Coefficients.Estimate;
  278. pvals_ch_bw0_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss1LR.Coefficients.pValue<0.05);
  279. ctwcclm_noch_bw0_ss1LL=fitlm([vccoffSVL_bw0(ss1LL) vccoffSVR_bw0(ss1LL)], vctccspk(ss1LL));
  280. zetas_noch_bw0_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  281. betas_noch_bw0_ss1LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw0_ss1LL.Coefficients.Estimate;
  282. pvals_noch_bw0_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss1LL.Coefficients.pValue<0.05);
  283. ctwcclm_noch_bw0_ss1LR=fitlm([vccoffSVL_bw0(ss1LR) vccoffSVR_bw0(ss1LR)], vctccspk(ss1LR));
  284. zetas_noch_bw0_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  285. betas_noch_bw0_ss1LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw0_ss1LR.Coefficients.Estimate;
  286. pvals_noch_bw0_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss1LR.Coefficients.pValue<0.05);
  287. ctwcclm_ch_bw0_ss1LL_res=fitlm(vccoffchR(ss1LL),ctwcclm_noch_bw0_ss1LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  288. bbetas_ch_bw0_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss1LL_res.Coefficients.Estimate;
  289. ppvals_ch_bw0_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss1LL_res.Coefficients.pValue<0.05);
  290. ctwcclm_ch_bw0_ss1LR_res=fitlm(vccoffchR(ss1LR),ctwcclm_noch_bw0_ss1LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  291. bbetas_ch_bw0_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss1LR_res.Coefficients.Estimate;
  292. ppvals_ch_bw0_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss1LR_res.Coefficients.pValue<0.05);
  293. % FITTING LM FOR SV: CH/NOCH LL/LR (SS2, BW0)
  294. ctwcclm_ch_bw0_ss2LL=fitlm([vccoffSVL_bw0(ss2LL) vccoffSVR_bw0(ss2LL) vccoffchR(ss2LL)], vctccspk(ss2LL));
  295. %zetas_ch_bw0_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw0_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  296. betas_ch_bw0_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss2LL.Coefficients.Estimate;
  297. pvals_ch_bw0_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss2LL.Coefficients.pValue<0.05);
  298. ctwcclm_ch_bw0_ss2LR=fitlm([vccoffSVL_bw0(ss2LR) vccoffSVR_bw0(ss2LR) vccoffchR(ss2LR)], vctccspk(ss2LR));
  299. %zetas_ch_bw0_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw0_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  300. betas_ch_bw0_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss2LR.Coefficients.Estimate;
  301. pvals_ch_bw0_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss2LR.Coefficients.pValue<0.05);
  302. ctwcclm_noch_bw0_ss2LL=fitlm([vccoffSVL_bw0(ss2LL) vccoffSVR_bw0(ss2LL)], vctccspk(ss2LL));
  303. zetas_noch_bw0_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  304. betas_noch_bw0_ss2LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw0_ss2LL.Coefficients.Estimate;
  305. pvals_noch_bw0_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss2LL.Coefficients.pValue<0.05);
  306. ctwcclm_noch_bw0_ss2LR=fitlm([vccoffSVL_bw0(ss2LR) vccoffSVR_bw0(ss2LR)], vctccspk(ss2LR));
  307. zetas_noch_bw0_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw0_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  308. pvals_noch_bw0_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw0_ss2LR.Coefficients.pValue<0.05);
  309. ctwcclm_ch_bw0_ss2LL_res=fitlm(vccoffchR(ss2LL),ctwcclm_noch_bw0_ss2LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  310. bbetas_ch_bw0_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss2LL_res.Coefficients.Estimate;
  311. ppvals_ch_bw0_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss2LL_res.Coefficients.pValue<0.05);
  312. ctwcclm_ch_bw0_ss2LR_res=fitlm(vccoffchR(ss2LR),ctwcclm_noch_bw0_ss2LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  313. bbetas_ch_bw0_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw0_ss2LR_res.Coefficients.Estimate;
  314. ppvals_ch_bw0_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw0_ss2LR_res.Coefficients.pValue<0.05);
  315. % FITTING LM FOR SV: CH/NOCH LL/LR (SS1, BW1)
  316. ctwcclm_ch_bw1_ss1LL=fitlm([vccoffSVL_bw1(ss1LL) vccoffSVR_bw1(ss1LL) vccoffchR(ss1LL)], vctccspk(ss1LL));
  317. %zetas_ch_bw1_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw1_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  318. betas_ch_bw1_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss1LL.Coefficients.Estimate;
  319. pvals_ch_bw1_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss1LL.Coefficients.pValue<0.05);
  320. ctwcclm_ch_bw1_ss1LR=fitlm([vccoffSVL_bw1(ss1LR) vccoffSVR_bw1(ss1LR) vccoffchR(ss1LR)], vctccspk(ss1LR));
  321. %zetas_ch_bw1_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw1_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  322. betas_ch_bw1_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss1LR.Coefficients.Estimate;
  323. pvals_ch_bw1_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss1LR.Coefficients.pValue<0.05);
  324. ctwcclm_noch_bw1_ss1LL=fitlm([vccoffSVL_bw1(ss1LL) vccoffSVR_bw1(ss1LL)], vctccspk(ss1LL));
  325. zetas_noch_bw1_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw1_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  326. betas_noch_bw1_ss1LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw1_ss1LL.Coefficients.Estimate;
  327. pvals_noch_bw1_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw1_ss1LL.Coefficients.pValue<0.05);
  328. ctwcclm_noch_bw1_ss1LR=fitlm([vccoffSVL_bw1(ss1LR) vccoffSVR_bw1(ss1LR)], vctccspk(ss1LR));
  329. zetas_noch_bw1_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw1_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  330. pvals_noch_bw1_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw1_ss1LR.Coefficients.pValue<0.05);
  331. ctwcclm_ch_bw1_ss1LL_res=fitlm(vccoffchR(ss1LL),ctwcclm_noch_bw1_ss1LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  332. bbetas_ch_bw1_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss1LL_res.Coefficients.Estimate;
  333. ppvals_ch_bw1_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss1LL_res.Coefficients.pValue<0.05);
  334. ctwcclm_ch_bw1_ss1LR_res=fitlm(vccoffchR(ss1LR),ctwcclm_noch_bw1_ss1LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  335. bbetas_ch_bw1_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss1LR_res.Coefficients.Estimate;
  336. ppvals_ch_bw1_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss1LR_res.Coefficients.pValue<0.05);
  337. % FITTING LM FOR SV: CH/NOCH LL/LR (SS2, BW1)
  338. ctwcclm_ch_bw1_ss2LL=fitlm([vccoffSVL_bw1(ss2LL) vccoffSVR_bw1(ss2LL) vccoffchR(ss2LL)], vctccspk(ss2LL));
  339. %zetas_ch_bw1_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw1_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  340. betas_ch_bw1_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss2LL.Coefficients.Estimate;
  341. pvals_ch_bw1_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss2LL.Coefficients.pValue<0.05);
  342. ctwcclm_ch_bw1_ss2LR=fitlm([vccoffSVL_bw1(ss2LR) vccoffSVR_bw1(ss2LR) vccoffchR(ss2LR)], vctccspk(ss2LR));
  343. %zetas_ch_bw1_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw1_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  344. betas_ch_bw1_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss2LR.Coefficients.Estimate;
  345. pvals_ch_bw1_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss2LR.Coefficients.pValue<0.05);
  346. ctwcclm_noch_bw1_ss2LL=fitlm([vccoffSVL_bw1(ss2LL) vccoffSVR_bw1(ss2LL)], vctccspk(ss2LL));
  347. zetas_noch_bw1_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw1_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  348. betas_noch_bw1_ss2LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw1_ss2LL.Coefficients.Estimate;
  349. pvals_noch_bw1_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw1_ss2LL.Coefficients.pValue<0.05);
  350. ctwcclm_noch_bw1_ss2LR=fitlm([vccoffSVL_bw1(ss2LR) vccoffSVR_bw1(ss2LR)], vctccspk(ss2LR));
  351. zetas_noch_bw1_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw1_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  352. betas_noch_bw1_ss2LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw1_ss2LR.Coefficients.Estimate;
  353. pvals_noch_bw1_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw1_ss2LR.Coefficients.pValue<0.05);
  354. ctwcclm_ch_bw1_ss2LL_res=fitlm(vccoffchR(ss2LL),ctwcclm_noch_bw1_ss2LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  355. bbetas_ch_bw1_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss2LL_res.Coefficients.Estimate;
  356. ppvals_ch_bw1_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss2LL_res.Coefficients.pValue<0.05);
  357. ctwcclm_ch_bw1_ss2LR_res=fitlm(vccoffchR(ss2LR),ctwcclm_noch_bw1_ss2LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  358. bbetas_ch_bw1_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw1_ss2LR_res.Coefficients.Estimate;
  359. ppvals_ch_bw1_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw1_ss2LR_res.Coefficients.pValue<0.05);
  360. % FITTING LM FOR SV: CH/NOCH LL/LR (SS1, BW2)
  361. ctwcclm_ch_bw2_ss1LL=fitlm([vccoffSVL_bw2(ss1LL) vccoffSVR_bw2(ss1LL) vccoffchR(ss1LL)], vctccspk(ss1LL));
  362. %zetas_ch_bw2_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw2_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  363. betas_ch_bw2_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss1LL.Coefficients.Estimate;
  364. pvals_ch_bw2_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss1LL.Coefficients.pValue<0.05);
  365. ctwcclm_ch_bw2_ss1LR=fitlm([vccoffSVL_bw2(ss1LR) vccoffSVR_bw2(ss1LR) vccoffchR(ss1LR)], vctccspk(ss1LR));
  366. %zetas_ch_bw2_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw2_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  367. betas_ch_bw2_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss1LR.Coefficients.Estimate;
  368. pvals_ch_bw2_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss1LR.Coefficients.pValue<0.05);
  369. ctwcclm_noch_bw2_ss1LL=fitlm([vccoffSVL_bw2(ss1LL) vccoffSVR_bw2(ss1LL)], vctccspk(ss1LL));
  370. zetas_noch_bw2_ss1LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw2_ss1LL.Residuals.Raw; nan(Ntrs12-length(ss1LL),1)];
  371. betas_noch_bw2_ss1LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw2_ss1LL.Coefficients.Estimate;
  372. pvals_noch_bw2_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw2_ss1LL.Coefficients.pValue<0.05);
  373. ctwcclm_noch_bw2_ss1LR=fitlm([vccoffSVL_bw2(ss1LR) vccoffSVR_bw2(ss1LR)], vctccspk(ss1LR));
  374. zetas_noch_bw2_ss1LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw2_ss1LR.Residuals.Raw; nan(Ntrs12-length(ss1LR),1)];
  375. betas_noch_bw2_ss1LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw2_ss1LR.Coefficients.Estimate;
  376. pvals_noch_bw2_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw2_ss1LR.Coefficients.pValue<0.05);
  377. ctwcclm_ch_bw2_ss1LL_res=fitlm(vccoffchR(ss1LL),ctwcclm_noch_bw2_ss1LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  378. bbetas_ch_bw2_ss1LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss1LL_res.Coefficients.Estimate;
  379. ppvals_ch_bw2_ss1LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss1LL_res.Coefficients.pValue<0.05);
  380. ctwcclm_ch_bw2_ss1LR_res=fitlm(vccoffchR(ss1LR),ctwcclm_noch_bw2_ss1LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  381. bbetas_ch_bw2_ss1LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss1LR_res.Coefficients.Estimate;
  382. ppvals_ch_bw2_ss1LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss1LR_res.Coefficients.pValue<0.05);
  383. % FITTING LM FOR SV: CH/NOCH LL/LR (SS2, BW2)
  384. ctwcclm_ch_bw2_ss2LL=fitlm([vccoffSVL_bw2(ss2LL) vccoffSVR_bw2(ss2LL) vccoffchR(ss2LL)], vctccspk(ss2LL));
  385. %zetas_ch_bw2_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_ch_bw2_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  386. betas_ch_bw2_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss2LL.Coefficients.Estimate;
  387. pvals_ch_bw2_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss2LL.Coefficients.pValue<0.05);
  388. ctwcclm_ch_bw2_ss2LR=fitlm([vccoffSVL_bw2(ss2LR) vccoffSVR_bw2(ss2LR) vccoffchR(ss2LR)], vctccspk(ss2LR));
  389. %zetas_ch_bw2_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_ch_bw2_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  390. betas_ch_bw2_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss2LR.Coefficients.Estimate;
  391. pvals_ch_bw2_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss2LR.Coefficients.pValue<0.05);
  392. ctwcclm_noch_bw2_ss2LL=fitlm([vccoffSVL_bw2(ss2LL) vccoffSVR_bw2(ss2LL)], vctccspk(ss2LL));
  393. zetas_noch_bw2_ss2LL_mat(:,cc,tt,sg)=[ctwcclm_noch_bw2_ss2LL.Residuals.Raw; nan(Ntrs12-length(ss2LL),1)];
  394. betas_noch_bw2_ss2LL_mat(:,cc,tt,sg)=ctwcclm_noch_bw2_ss2LL.Coefficients.Estimate;
  395. pvals_noch_bw2_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_noch_bw2_ss2LL.Coefficients.pValue<0.05);
  396. ctwcclm_noch_bw2_ss2LR=fitlm([vccoffSVL_bw2(ss2LR) vccoffSVR_bw2(ss2LR)], vctccspk(ss2LR));
  397. zetas_noch_bw2_ss2LR_mat(:,cc,tt,sg)=[ctwcclm_noch_bw2_ss2LR.Residuals.Raw; nan(Ntrs12-length(ss2LR),1)];
  398. betas_noch_bw2_ss2LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw2_ss2LR.Coefficients.Estimate;
  399. pvals_noch_bw2_ss2LR_mat(:,cc,tt,sg)=ctwcclm_noch_bw2_ss2LR.Coefficients.pValue;
  400. ctwcclm_ch_bw2_ss2LL_res=fitlm(vccoffchR(ss2LL),ctwcclm_noch_bw2_ss2LL.Residuals.Raw,'Intercept',useinterceptflag==1);
  401. bbetas_ch_bw2_ss2LL_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss2LL_res.Coefficients.Estimate;
  402. ppvals_ch_bw2_ss2LL_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss2LL_res.Coefficients.pValue<0.05);
  403. ctwcclm_ch_bw2_ss2LR_res=fitlm(vccoffchR(ss2LR),ctwcclm_noch_bw2_ss2LR.Residuals.Raw,'Intercept',useinterceptflag==1);
  404. bbetas_ch_bw2_ss2LR_mat(:,cc,tt,sg)=ctwcclm_ch_bw2_ss2LR_res.Coefficients.Estimate;
  405. ppvals_ch_bw2_ss2LR_mat(:,cc,tt,sg)=uint8(ctwcclm_ch_bw2_ss2LR_res.Coefficients.pValue<0.05);
  406. % SAVING CHOICES TO BE USED FOR PREFERRED/NON-PREF. CHOICE
  407. offch_ss0LL_mat(:,cc,tt,sg)=[vccoffchR_flip(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  408. offch_ss0LR_mat(:,cc,tt,sg)=[vccoffchR_flip(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  409. offch_ss1LL_mat(:,cc,tt,sg)=[vccoffchR_flip(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  410. offch_ss1LR_mat(:,cc,tt,sg)=[vccoffchR_flip(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  411. offch_ss2LL_mat(:,cc,tt,sg)=[vccoffchR_flip(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  412. offch_ss2LR_mat(:,cc,tt,sg)=[vccoffchR_flip(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  413. offch_ss0LL_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  414. offch_ss0LR_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  415. offch_ss1LL_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  416. offch_ss1LR_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  417. offch_ss2LL_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  418. offch_ss2LR_noflip_mat(:,cc,tt,sg)=[vccoffchR(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  419. offEVL_ss0LL_mat(:,cc,tt,sg)=[vccoffEVL(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  420. offEVL_ss0LR_mat(:,cc,tt,sg)=[vccoffEVL(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  421. offEVL_ss1LL_mat(:,cc,tt,sg)=[vccoffEVL(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  422. offEVL_ss1LR_mat(:,cc,tt,sg)=[vccoffEVL(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  423. offEVL_ss2LL_mat(:,cc,tt,sg)=[vccoffEVL(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  424. offEVL_ss2LR_mat(:,cc,tt,sg)=[vccoffEVL(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  425. offEVR_ss0LL_mat(:,cc,tt,sg)=[vccoffEVR(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  426. offEVR_ss0LR_mat(:,cc,tt,sg)=[vccoffEVR(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  427. offEVR_ss1LL_mat(:,cc,tt,sg)=[vccoffEVR(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  428. offEVR_ss1LR_mat(:,cc,tt,sg)=[vccoffEVR(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  429. offEVR_ss2LL_mat(:,cc,tt,sg)=[vccoffEVR(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  430. offEVR_ss2LR_mat(:,cc,tt,sg)=[vccoffEVR(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  431. offSVL_bw0ss0LL_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  432. offSVL_bw0ss0LR_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  433. offSVL_bw0ss1LL_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  434. offSVL_bw0ss1LR_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  435. offSVL_bw0ss2LL_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  436. offSVL_bw0ss2LR_mat(:,cc,tt,sg)=[vccoffSVL_bw0(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  437. offSVL_bw1ss1LL_mat(:,cc,tt,sg)=[vccoffSVL_bw1(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  438. offSVL_bw1ss1LR_mat(:,cc,tt,sg)=[vccoffSVL_bw1(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  439. offSVL_bw1ss2LL_mat(:,cc,tt,sg)=[vccoffSVL_bw1(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  440. offSVL_bw1ss2LR_mat(:,cc,tt,sg)=[vccoffSVL_bw1(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  441. offSVL_bw2ss1LL_mat(:,cc,tt,sg)=[vccoffSVL_bw2(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  442. offSVL_bw2ss1LR_mat(:,cc,tt,sg)=[vccoffSVL_bw2(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  443. offSVL_bw2ss2LL_mat(:,cc,tt,sg)=[vccoffSVL_bw2(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  444. offSVL_bw2ss2LR_mat(:,cc,tt,sg)=[vccoffSVL_bw2(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  445. offSVR_bw0ss0LL_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss0LL); nan(Ntrs12-length(ss0LL),1)];
  446. offSVR_bw0ss0LR_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss0LR); nan(Ntrs12-length(ss0LR),1)];
  447. offSVR_bw0ss1LL_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  448. offSVR_bw0ss1LR_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  449. offSVR_bw0ss2LL_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  450. offSVR_bw0ss2LR_mat(:,cc,tt,sg)=[vccoffSVR_bw0(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  451. offSVR_bw1ss1LL_mat(:,cc,tt,sg)=[vccoffSVR_bw1(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  452. offSVR_bw1ss1LR_mat(:,cc,tt,sg)=[vccoffSVR_bw1(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  453. offSVR_bw1ss2LL_mat(:,cc,tt,sg)=[vccoffSVR_bw1(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  454. offSVR_bw1ss2LR_mat(:,cc,tt,sg)=[vccoffSVR_bw1(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  455. offSVR_bw2ss1LL_mat(:,cc,tt,sg)=[vccoffSVR_bw2(ss1LL); nan(Ntrs12-length(ss1LL),1)];
  456. offSVR_bw2ss1LR_mat(:,cc,tt,sg)=[vccoffSVR_bw2(ss1LR); nan(Ntrs12-length(ss1LR),1)];
  457. offSVR_bw2ss2LL_mat(:,cc,tt,sg)=[vccoffSVR_bw2(ss2LL); nan(Ntrs12-length(ss2LL),1)];
  458. offSVR_bw2ss2LR_mat(:,cc,tt,sg)=[vccoffSVR_bw2(ss2LR); nan(Ntrs12-length(ss2LR),1)];
  459. end
  460. warning('on','all')
  461. end
  462. fprintf('%s - done: %d/%d, %2.1f%%\n',datetime('now','Format','HH:mm'),cc,Nccs,cc/Nccs.*100);
  463. end
  464. fprintf('Subgroup generation %d out of %d done.\n',sg,Nsubg)
  465. end
  466. save(['fitlmstats_chR_evR_evL_spk_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_' date '.mat'],'curr_rng','offch*','zeta*','beta*','bbeta*','pval*','ppval*','-v7.3');
  467. else
  468. load('fitlmstats_chR_evR_evL_spk_span_200ms_lag_10ms_01-Mar-2024.mat');
  469. end
  470. disp('done')
  471. error('force stop here')
  472. %% FIG4E - CORRELATION BETWEEN CHOICE AND SV WEIGHTS
  473. close all;
  474. tbins_to_plot=1:58;%21:58;
  475. subg_to_plot=1;
  476. plot_sigbetas=1;
  477. % bw0_ss1
  478. sig_betas_ch_bw0_ss1LL_mat=betas_ch_bw0_ss1LL_mat;
  479. sig_bbetas_ch_bw0_ss1LL_mat=bbetas_ch_bw0_ss1LL_mat;
  480. sig_betas_ch_bw0_ss1LR_mat=betas_ch_bw0_ss1LR_mat;
  481. sig_bbetas_ch_bw0_ss1LR_mat=bbetas_ch_bw0_ss1LR_mat;
  482. % bw0_ss2
  483. sig_betas_ch_bw0_ss2LL_mat=betas_ch_bw0_ss2LL_mat;
  484. sig_bbetas_ch_bw0_ss2LL_mat=bbetas_ch_bw0_ss2LL_mat;
  485. sig_betas_ch_bw0_ss2LR_mat=betas_ch_bw0_ss2LR_mat;
  486. sig_bbetas_ch_bw0_ss2LR_mat=bbetas_ch_bw0_ss2LR_mat;
  487. % bw1_ss1
  488. sig_betas_ch_bw1_ss1LL_mat=betas_ch_bw1_ss1LL_mat;
  489. sig_bbetas_ch_bw1_ss1LL_mat=bbetas_ch_bw1_ss1LL_mat;
  490. sig_betas_ch_bw1_ss1LR_mat=betas_ch_bw1_ss1LR_mat;
  491. sig_bbetas_ch_bw1_ss1LR_mat=bbetas_ch_bw1_ss1LR_mat;
  492. % bw2_ss2
  493. sig_betas_ch_bw2_ss2LL_mat=betas_ch_bw2_ss2LL_mat;
  494. sig_bbetas_ch_bw2_ss2LL_mat=bbetas_ch_bw2_ss2LL_mat;
  495. sig_betas_ch_bw2_ss2LR_mat=betas_ch_bw2_ss2LR_mat;
  496. sig_bbetas_ch_bw2_ss2LR_mat=bbetas_ch_bw2_ss2LR_mat;
  497. % bw1_ss2
  498. sig_betas_ch_bw1_ss2LL_mat=betas_ch_bw1_ss2LL_mat;
  499. sig_bbetas_ch_bw1_ss2LL_mat=bbetas_ch_bw1_ss2LL_mat;
  500. sig_betas_ch_bw1_ss2LR_mat=betas_ch_bw1_ss2LR_mat;
  501. sig_bbetas_ch_bw1_ss2LR_mat=bbetas_ch_bw1_ss2LR_mat;
  502. % bw2_ss1
  503. sig_betas_ch_bw2_ss1LL_mat=betas_ch_bw2_ss1LL_mat;
  504. sig_bbetas_ch_bw2_ss1LL_mat=bbetas_ch_bw2_ss1LL_mat;
  505. sig_betas_ch_bw2_ss1LR_mat=betas_ch_bw2_ss1LR_mat;
  506. sig_bbetas_ch_bw2_ss1LR_mat=bbetas_ch_bw2_ss1LR_mat;
  507. if plot_sigbetas
  508. % bw0_ss1
  509. sig_betas_ch_bw0_ss1LL_mat(pvals_ch_bw0_ss1LL_mat==0)=nan;
  510. sig_bbetas_ch_bw0_ss1LL_mat(ppvals_ch_bw0_ss1LL_mat==0)=nan;
  511. sig_betas_ch_bw0_ss1LR_mat(pvals_ch_bw0_ss1LR_mat==0)=nan;
  512. sig_bbetas_ch_bw0_ss1LR_mat(ppvals_ch_bw0_ss1LR_mat==0)=nan;
  513. % bw0_ss2
  514. sig_betas_ch_bw0_ss2LL_mat(pvals_ch_bw0_ss2LL_mat==0)=nan;
  515. sig_bbetas_ch_bw0_ss2LL_mat(ppvals_ch_bw0_ss2LL_mat==0)=nan;
  516. sig_betas_ch_bw0_ss2LR_mat(pvals_ch_bw0_ss2LR_mat==0)=nan;
  517. sig_bbetas_ch_bw0_ss2LR_mat(ppvals_ch_bw0_ss2LR_mat==0)=nan;
  518. % bw1_ss1
  519. sig_betas_ch_bw1_ss1LL_mat(pvals_ch_bw1_ss1LL_mat==0)=nan;
  520. sig_bbetas_ch_bw1_ss1LL_mat(ppvals_ch_bw1_ss1LL_mat==0)=nan;
  521. sig_betas_ch_bw1_ss1LR_mat(pvals_ch_bw1_ss1LR_mat==0)=nan;
  522. sig_bbetas_ch_bw1_ss1LR_mat(ppvals_ch_bw1_ss1LR_mat==0)=nan;
  523. % bw2_ss2
  524. sig_betas_ch_bw2_ss2LL_mat(pvals_ch_bw2_ss2LL_mat==0)=nan;
  525. sig_bbetas_ch_bw2_ss2LL_mat(ppvals_ch_bw2_ss2LL_mat==0)=nan;
  526. sig_betas_ch_bw2_ss2LR_mat(pvals_ch_bw2_ss2LR_mat==0)=nan;
  527. sig_bbetas_ch_bw2_ss2LR_mat(ppvals_ch_bw2_ss2LR_mat==0)=nan;
  528. % bw1_ss2
  529. sig_betas_ch_bw1_ss2LL_mat(pvals_ch_bw1_ss2LL_mat==0)=nan;
  530. sig_bbetas_ch_bw1_ss2LL_mat(ppvals_ch_bw1_ss2LL_mat==0)=nan;
  531. sig_betas_ch_bw1_ss2LR_mat(pvals_ch_bw1_ss2LR_mat==0)=nan;
  532. sig_bbetas_ch_bw1_ss2LR_mat(ppvals_ch_bw1_ss2LR_mat==0)=nan;
  533. % bw2_ss1
  534. sig_betas_ch_bw2_ss1LL_mat(pvals_ch_bw2_ss1LL_mat==0)=nan;
  535. sig_bbetas_ch_bw2_ss1LL_mat(ppvals_ch_bw2_ss1LL_mat==0)=nan;
  536. sig_betas_ch_bw2_ss1LR_mat(pvals_ch_bw2_ss1LR_mat==0)=nan;
  537. sig_bbetas_ch_bw2_ss1LR_mat(ppvals_ch_bw2_ss1LR_mat==0)=nan;
  538. end
  539. % bw0_ss1
  540. beta1_bw0_ss1LL=nanmean(squeeze(sig_betas_ch_bw0_ss1LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  541. beta2_bw0_ss1LL=nanmean(squeeze(sig_betas_ch_bw0_ss1LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  542. beta3_bw0_ss1LL=nanmean(squeeze(sig_betas_ch_bw0_ss1LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  543. bbeta3_bw0_ss1LL=nanmean(squeeze(sig_bbetas_ch_bw0_ss1LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  544. beta1_bw0_ss1LR=nanmean(squeeze(sig_betas_ch_bw0_ss1LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  545. beta2_bw0_ss1LR=nanmean(squeeze(sig_betas_ch_bw0_ss1LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  546. beta3_bw0_ss1LR=nanmean(squeeze(sig_betas_ch_bw0_ss1LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  547. bbeta3_bw0_ss1LR=nanmean(squeeze(sig_bbetas_ch_bw0_ss1LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  548. % bw0_ss2
  549. beta1_bw0_ss2LL=nanmean(squeeze(sig_betas_ch_bw0_ss2LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  550. beta2_bw0_ss2LL=nanmean(squeeze(sig_betas_ch_bw0_ss2LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  551. beta3_bw0_ss2LL=nanmean(squeeze(sig_betas_ch_bw0_ss2LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  552. bbeta3_bw0_ss2LL=nanmean(squeeze(sig_bbetas_ch_bw0_ss2LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  553. beta1_bw0_ss2LR=nanmean(squeeze(sig_betas_ch_bw0_ss2LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  554. beta2_bw0_ss2LR=nanmean(squeeze(sig_betas_ch_bw0_ss2LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  555. beta3_bw0_ss2LR=nanmean(squeeze(sig_betas_ch_bw0_ss2LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  556. bbeta3_bw0_ss2LR=nanmean(squeeze(sig_bbetas_ch_bw0_ss2LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  557. % bw1_ss1
  558. beta1_bw1_ss1LL=nanmean(squeeze(sig_betas_ch_bw1_ss1LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  559. beta2_bw1_ss1LL=nanmean(squeeze(sig_betas_ch_bw1_ss1LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  560. beta3_bw1_ss1LL=nanmean(squeeze(sig_betas_ch_bw1_ss1LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  561. bbeta3_bw1_ss1LL=nanmean(squeeze(sig_bbetas_ch_bw1_ss1LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  562. beta1_bw1_ss1LR=nanmean(squeeze(sig_betas_ch_bw1_ss1LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  563. beta2_bw1_ss1LR=nanmean(squeeze(sig_betas_ch_bw1_ss1LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  564. beta3_bw1_ss1LR=nanmean(squeeze(sig_betas_ch_bw1_ss1LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  565. bbeta3_bw1_ss1LR=nanmean(squeeze(sig_bbetas_ch_bw1_ss1LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  566. % bw2_ss2
  567. beta1_bw2_ss2LL=nanmean(squeeze(sig_betas_ch_bw2_ss2LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  568. beta2_bw2_ss2LL=nanmean(squeeze(sig_betas_ch_bw2_ss2LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  569. beta3_bw2_ss2LL=nanmean(squeeze(sig_betas_ch_bw2_ss2LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  570. bbeta3_bw2_ss2LL=nanmean(squeeze(sig_bbetas_ch_bw2_ss2LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  571. beta1_bw2_ss2LR=nanmean(squeeze(sig_betas_ch_bw2_ss2LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  572. beta2_bw2_ss2LR=nanmean(squeeze(sig_betas_ch_bw2_ss2LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  573. beta3_bw2_ss2LR=nanmean(squeeze(sig_betas_ch_bw2_ss2LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  574. bbeta3_bw2_ss2LR=nanmean(squeeze(sig_bbetas_ch_bw2_ss2LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  575. % bw1_ss2
  576. beta1_bw1_ss2LL=nanmean(squeeze(sig_betas_ch_bw1_ss2LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  577. beta2_bw1_ss2LL=nanmean(squeeze(sig_betas_ch_bw1_ss2LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  578. beta3_bw1_ss2LL=nanmean(squeeze(sig_betas_ch_bw1_ss2LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  579. bbeta3_bw1_ss2LL=nanmean(squeeze(sig_bbetas_ch_bw1_ss2LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  580. beta1_bw1_ss2LR=nanmean(squeeze(sig_betas_ch_bw1_ss2LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  581. beta2_bw1_ss2LR=nanmean(squeeze(sig_betas_ch_bw1_ss2LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  582. beta3_bw1_ss2LR=nanmean(squeeze(sig_betas_ch_bw1_ss2LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  583. bbeta3_bw1_ss2LR=nanmean(squeeze(sig_bbetas_ch_bw1_ss2LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  584. % bw2_ss1
  585. beta1_bw2_ss1LL=nanmean(squeeze(sig_betas_ch_bw2_ss1LL_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  586. beta2_bw2_ss1LL=nanmean(squeeze(sig_betas_ch_bw2_ss1LL_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  587. beta3_bw2_ss1LL=nanmean(squeeze(sig_betas_ch_bw2_ss1LL_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  588. bbeta3_bw2_ss1LL=nanmean(squeeze(sig_bbetas_ch_bw2_ss1LL_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  589. beta1_bw2_ss1LR=nanmean(squeeze(sig_betas_ch_bw2_ss1LR_mat(2,:,tbins_to_plot,subg_to_plot)),2:3);
  590. beta2_bw2_ss1LR=nanmean(squeeze(sig_betas_ch_bw2_ss1LR_mat(3,:,tbins_to_plot,subg_to_plot)),2:3);
  591. beta3_bw2_ss1LR=nanmean(squeeze(sig_betas_ch_bw2_ss1LR_mat(4,:,tbins_to_plot,subg_to_plot)),2:3);
  592. bbeta3_bw2_ss1LR=nanmean(squeeze(sig_bbetas_ch_bw2_ss1LR_mat(1,:,tbins_to_plot,subg_to_plot)),2:3);
  593. corrmethstr={'Pearson','Spearman'};
  594. for mm=1:2
  595. corrmeth=corrmethstr{mm};
  596. hf=fullfig([0 0 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  597. subplot(2,2,1);
  598. correlplot([[beta3_bw0_ss2LL; beta3_bw0_ss1LL],[beta1_bw0_ss1LL; beta1_bw0_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  599. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  600. subplot(2,2,2);
  601. correlplot([[beta3_bw0_ss2LR; beta3_bw0_ss1LR],[beta1_bw0_ss1LR; beta1_bw0_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  602. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  603. subplot(2,2,3);
  604. correlplot([[beta3_bw0_ss2LL; beta3_bw0_ss1LL],[beta2_bw0_ss1LL; beta2_bw0_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  605. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  606. subplot(2,2,4);
  607. correlplot([[beta3_bw0_ss2LR; beta3_bw0_ss1LR],[beta2_bw0_ss1LR; beta2_bw0_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  608. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  609. supertitle('ss1-bw0/ss2-bw0',8);
  610. hf=fullfig([1/4 0 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  611. subplot(2,2,1);
  612. correlplot([[bbeta3_bw0_ss2LL; bbeta3_bw0_ss1LL],[beta1_bw0_ss1LL; beta1_bw0_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  613. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  614. subplot(2,2,2);
  615. correlplot([[bbeta3_bw0_ss2LR; bbeta3_bw0_ss1LR],[beta1_bw0_ss1LR; beta1_bw0_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  616. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  617. subplot(2,2,3);
  618. correlplot([[bbeta3_bw0_ss2LL; bbeta3_bw0_ss1LL],[beta2_bw0_ss1LL; beta2_bw0_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  619. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  620. subplot(2,2,4);
  621. correlplot([[bbeta3_bw0_ss2LR; bbeta3_bw0_ss1LR],[beta2_bw0_ss1LR; beta2_bw0_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  622. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  623. supertitle('ss1-bw0/ss2-bw0',8);
  624. hf=fullfig([0 1/3 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  625. subplot(2,2,1);
  626. correlplot([[beta3_bw1_ss1LL; beta3_bw2_ss2LL],[beta1_bw2_ss2LL; beta1_bw1_ss1LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  627. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  628. subplot(2,2,2);
  629. correlplot([[beta3_bw1_ss1LR; beta3_bw2_ss2LR],[beta1_bw2_ss2LR; beta1_bw1_ss1LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  630. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  631. subplot(2,2,3);
  632. correlplot([[beta3_bw1_ss1LL; beta3_bw2_ss2LL],[beta2_bw2_ss2LL; beta2_bw1_ss1LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  633. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  634. subplot(2,2,4);
  635. correlplot([[beta3_bw1_ss1LR; beta3_bw2_ss2LR],[beta2_bw2_ss2LR; beta2_bw1_ss1LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  636. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  637. supertitle('ss1-bw1/ss2-bw2',8);
  638. hf=fullfig([1/4 1/3 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  639. subplot(2,2,1);
  640. correlplot([[bbeta3_bw1_ss1LL; bbeta3_bw2_ss2LL],[beta1_bw2_ss2LL; beta1_bw1_ss1LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  641. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  642. subplot(2,2,2);
  643. correlplot([[bbeta3_bw1_ss1LR; bbeta3_bw2_ss2LR],[beta1_bw2_ss2LR; beta1_bw1_ss1LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  644. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  645. subplot(2,2,3);
  646. correlplot([[bbeta3_bw1_ss1LL; bbeta3_bw2_ss2LL],[beta2_bw2_ss2LL; beta2_bw1_ss1LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  647. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  648. subplot(2,2,4);
  649. correlplot([[bbeta3_bw1_ss1LR; bbeta3_bw2_ss2LR],[beta2_bw2_ss2LR; beta2_bw1_ss1LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  650. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  651. supertitle('ss1-bw1/ss2-bw2',8);
  652. hf=fullfig([0 2/3 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  653. subplot(2,2,1);
  654. correlplot([[beta3_bw1_ss2LL; beta3_bw2_ss1LL],[beta1_bw2_ss1LL; beta1_bw1_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  655. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  656. subplot(2,2,2);
  657. correlplot([[beta3_bw1_ss2LR; beta3_bw2_ss1LR],[beta1_bw2_ss1LR; beta1_bw1_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  658. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_1');
  659. subplot(2,2,3);
  660. correlplot([[beta3_bw1_ss2LL; beta3_bw2_ss1LL],[beta2_bw2_ss1LL; beta2_bw1_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  661. title('LookL subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  662. subplot(2,2,4);
  663. correlplot([[beta3_bw1_ss2LR; beta3_bw2_ss1LR],[beta2_bw2_ss1LR; beta2_bw1_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  664. title('LookR subsets 1:2'); xlabel('\beta_3'); ylabel('\beta_2');
  665. supertitle('ss2-bw1/ss2-bw2',8);
  666. hf=fullfig([1/4 2/3 1/4 1/3]+(mm-1)*[.5 0 0 0]);
  667. subplot(2,2,1);
  668. correlplot([[bbeta3_bw1_ss2LL; bbeta3_bw2_ss1LL],[beta1_bw2_ss1LL; beta1_bw1_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  669. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  670. subplot(2,2,2);
  671. correlplot([[bbeta3_bw1_ss2LR; bbeta3_bw2_ss1LR],[beta1_bw2_ss1LR; beta1_bw1_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  672. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_1');
  673. subplot(2,2,3);
  674. correlplot([[bbeta3_bw1_ss2LL; bbeta3_bw2_ss1LL],[beta2_bw2_ss1LL; beta2_bw1_ss2LL]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  675. title('LookL subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  676. subplot(2,2,4);
  677. correlplot([[bbeta3_bw1_ss2LR; bbeta3_bw2_ss1LR],[beta2_bw2_ss1LR; beta2_bw1_ss2LR]],corrmeth,[.1 .1 .1],[-2.5e-3 2.5e-3],[-2.5e-3 2.5e-3]);
  678. title('LookR subsets 1:2'); xlabel('\beta_1\prime'); ylabel('\beta_2');
  679. supertitle('ss2-bw1/ss1-bw2',8);
  680. end
  681. %% FIG 4F - RESIDUALS MAGNITUDES
  682. tbins_to_plot=1:58;%51:58;
  683. Ntb2p=length(tbins_to_plot);
  684. subg_to_plot=1;
  685. addpath('./support_functions')
  686. clc
  687. %% BW0 SS0
  688. close all
  689. clearvars Zstruct*
  690. plot_sigbetas=0;
  691. Zstruct0_trwise=get_bw_ss('bw0','ss0',plot_sigbetas,tbins_to_plot,subg_to_plot);
  692. plot_residuals_comparison_scatter(Zstruct0_trwise,...
  693. './zetas_comparisons_cameraready/bw0_ss0/',['_bw0_ss0_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  694. %plot_residuals_comparison_distributions(Zstruct0_trwise, ...
  695. % './zetas_comparisons/',['_bw0_ss0_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  696. plot_comparisons_choice_prob_cellwise(Zstruct0_trwise,...
  697. './zetas_comparisons_cameraready/bw0_ss0/',['_bw0_ss0_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  698. plot_sigbetas=1;
  699. Zstruct0_trwise=get_bw_ss('bw0','ss0',plot_sigbetas,tbins_to_plot,subg_to_plot);
  700. plot_residuals_comparison_scatter(Zstruct0_trwise,...
  701. './zetas_comparisons_cameraready/bw0_ss0_sig/',['_bw0_ss0_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  702. %plot_residuals_comparison_distributions(Zstruct0_trwise, ...
  703. % './zetas_comparisons/',['_bw0_ss0_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  704. plot_comparisons_choice_prob_cellwise(Zstruct0_trwise,...
  705. './zetas_comparisons_cameraready/bw0_ss0_sig/',['_bw0_ss0_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  706. %% BW0 SS1-SS2
  707. addpath('./support_functions')
  708. close all
  709. clearvars Zstruct*
  710. plot_sigbetas=0;
  711. Zstruct1_trwise=get_bw_ss('bw0','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  712. Zstruct2_trwise=get_bw_ss('bw0','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  713. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  714. % sum(~isnan(nanmean(Zstruct1_trwise.Z_b1_LL_trwise(:,1,:,1),3)))+...
  715. % sum(~isnan(nanmean(Zstruct2_trwise.Z_b1_LL_trwise(:,1,:,1),3))) % b1>0 chL
  716. % sum(~isnan(nanmean(Zstruct1_trwise.Z_b1_LL_trwise(:,1,:,3),3)))+...
  717. % sum(~isnan(nanmean(Zstruct2_trwise.Z_b1_LL_trwise(:,1,:,3),3))) % b1>0 chR
  718. %
  719. % sum(~isnan(nanmean(Zstruct0_trwise.Z_b1_LL_trwise(:,1,:,1),3))) % b1>0 chL
  720. % sum(~isnan(nanmean(Zstruct0_trwise.Z_b1_LL_trwise(:,1,:,3),3))) % b1>0 chR
  721. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  722. './zetas_comparisons_cameraready/bw0_ss12/',['_bw0_ss12_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  723. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  724. './zetas_comparisons_cameraready/bw0_ss12/',['_bw0_ss12_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  725. plot_sigbetas=1;
  726. Zstruct1_trwise=get_bw_ss('bw0','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  727. Zstruct2_trwise=get_bw_ss('bw0','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  728. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  729. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  730. './zetas_comparisons_cameraready/bw0_ss12_sig/',['_bw0_ss12_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  731. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  732. './zetas_comparisons_cameraready/bw0_ss12_sig/',['_bw0_ss12_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  733. %% BW1SS1-BW2SS2
  734. addpath('./support_functions')
  735. close all
  736. clearvars Zstruct*
  737. plot_sigbetas=0;
  738. Zstruct1_trwise=get_bw_ss('bw1','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  739. Zstruct2_trwise=get_bw_ss('bw2','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  740. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  741. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  742. './zetas_comparisons_cameraready/bw12_ss12/',['_bw12_ss12_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  743. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  744. './zetas_comparisons_cameraready/bw12_ss12/',['_bw12_ss12_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  745. plot_sigbetas=1;
  746. Zstruct1_trwise=get_bw_ss('bw1','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  747. Zstruct2_trwise=get_bw_ss('bw2','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  748. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  749. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  750. './zetas_comparisons_cameraready/bw12_ss12_sig/',['_bw12_ss12_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  751. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  752. './zetas_comparisons_cameraready/bw12_ss12_sig/',['_bw12_ss12_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  753. %% BW1SS2-BW1SS2
  754. addpath('support_functions')
  755. close all
  756. clearvars Zstruct*
  757. plot_sigbetas=0;
  758. Zstruct1_trwise=get_bw_ss('bw1','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  759. Zstruct2_trwise=get_bw_ss('bw2','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  760. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  761. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  762. './zetas_comparisons_cameraready/bw12_ss21/',['_bw12_ss21_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  763. [~,~,~,ZLA]=plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  764. './zetas_comparisons_cameraready/bw12_ss21/',['_bw12_ss21_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  765. %%
  766. plot_sigbetas=1;
  767. Zstruct1_trwise=get_bw_ss('bw1','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot);
  768. Zstruct2_trwise=get_bw_ss('bw2','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot);
  769. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  770. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  771. './zetas_comparisons_cameraready/bw12_ss21_sig/',['_bw12_ss21_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  772. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  773. './zetas_comparisons_cameraready/bw12_ss21_sig/',['_bw12_ss21_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  774. %% BW0 SS0 DIFFICULT
  775. close all
  776. clearvars Zstruct*
  777. plot_sigbetas=0; subselectEVdiff=1;
  778. Zstruct0_trwise=get_bw_ss('bw0','ss0',plot_sigbetas,tbins_to_plot,subg_to_plot,subselectEVdiff);
  779. plot_residuals_comparison_scatter(Zstruct0_trwise,...
  780. './zetaplot_comparisons_choice_prob_cellwiseplot_comparisons_choice_prob_cellwises_comparisons_cameraready/bw0_ss0_diff/',['_bw0_ss0_diff_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  781. plot_comparisons_choice_prob_cellwise(Zstruct0_trwise,...
  782. './zetas_comparisons_cameraready/bw0_ss0_diff/',['_bw0_ss0_diff_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  783. plot_sigbetas=1;
  784. Zstruct0_trwise=get_bw_ss('bw0','ss0',plot_sigbetas,tbins_to_plot,subg_to_plot);
  785. plot_residuals_comparison_scatter(Zstruct0_trwise,...
  786. './zetas_comparisons_cameraready/bw0_ss0_diff_sig/',['_bw0_ss0_diff_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  787. plot_comparisons_choice_prob_cellwise(Zstruct0_trwise,...
  788. './zetas_comparisons_cameraready/bw0_ss0_diff_sig/',['_bw0_ss0_diff_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  789. %% BW1SS2-BW2SS1 DIFFICULT
  790. close all
  791. clearvars Zstruct*
  792. plot_sigbetas=0; subselectEVdiff=1;
  793. Zstruct1_trwise=get_bw_ss('bw1','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot,subselectEVdiff);
  794. Zstruct2_trwise=get_bw_ss('bw2','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot,subselectEVdiff);
  795. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  796. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  797. './zetas_comparisons_cameraready/bw12_ss21_diff/',['_bw12_ss21_diff_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  798. [~,~,~,ZLD]=plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  799. './zetas_comparisons_cameraready/bw12_ss21_diff/',['_bw12_ss21_diff_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  800. %%
  801. plot_sigbetas=1; subselectEVdiff=1;
  802. Zstruct1_trwise=get_bw_ss('bw1','ss2',plot_sigbetas,tbins_to_plot,subg_to_plot,subselectEVdiff);
  803. Zstruct2_trwise=get_bw_ss('bw2','ss1',plot_sigbetas,tbins_to_plot,subg_to_plot,subselectEVdiff);
  804. Zstruct12_trwise = combine_subsets(Zstruct1_trwise,Zstruct2_trwise);
  805. plot_residuals_comparison_scatter(Zstruct12_trwise,...
  806. './zetas_comparisons_cameraready/bw12_ss21_diff_sig/',['_bw12_ss21_diff_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  807. plot_comparisons_choice_prob_cellwise(Zstruct12_trwise,...
  808. './zetas_comparisons_cameraready/bw12_ss21_diff_sig/',['_bw12_ss21_diff_sig_' num2str(tbins_to_plot(1)) '-' num2str(tbins_to_plot(end))]);
  809. %%
  810. load('fitlmstats_chR_evR_evL_spk_span_200ms_lag_10ms_11-Mar-2024.mat');
  811. nAll =sum(~isnan(zetas_noch_bw1_ss2LL_mat(:)))+sum(~isnan(zetas_noch_bw1_ss2LR_mat(:)))+...
  812. sum(~isnan(zetas_noch_bw2_ss1LL_mat(:)))+sum(~isnan(zetas_noch_bw2_ss1LL_mat(:)));
  813. load('fitlmstats_chR_evR_evL_spk_span_200ms_lag_10ms_22-Mar-2024.mat');
  814. nDiff=sum(~isnan(zetas_noch_bw1_ss2LL_mat(:)))+sum(~isnan(zetas_noch_bw1_ss2LR_mat(:)))+...
  815. sum(~isnan(zetas_noch_bw2_ss1LL_mat(:)))+sum(~isnan(zetas_noch_bw2_ss1LL_mat(:)));
  816. fprintf('Difficult trials are: %.3f%% of total trials.',nDiff/nAll*100)
  817. %% SUPPORT FUNCTIONS BELOW THIS POINT
  818. %
  819. %
  820. %
  821. %
  822. %
  823. %
  824. %
  825. %
  826. %
  827. %
  828. %
  829. %
  830. %
  831. %
  832. %
  833. %
  834. %
  835. %
  836. %
  837. %% Reshape betas based on beta signs
  838. function [zr_mat_trwise_split,zr_mat_trwise_merged,zr_mat_travg] = reshapez_choice_betas(...
  839. cv_mat,bv_mat,zv_mat,tbins_to_plot,subg_to_plot,plot_sigbetas,pv_mat)
  840. if nargin<6
  841. plot_sigbetas=0;
  842. end
  843. [Ntrs12, Nccs, Ntb2p, Nsubg]=size(zv_mat(:,:,tbins_to_plot,subg_to_plot));
  844. cmv0=cv_mat(:,:,tbins_to_plot,subg_to_plot);%initially ch=1 means chooseR
  845. bmv0=repmat(reshape(squeeze(bv_mat(1,:,tbins_to_plot,subg_to_plot)),[1 Nccs Ntb2p Nsubg]),Ntrs12,1,1);
  846. zmv0=zv_mat(:,:,tbins_to_plot,subg_to_plot);
  847. bmv0=repmat(nanmean(bmv0,3),[1 1 Ntb2p Nsubg]); %time-average betas (optional)
  848. bg0_nm=nan(size(bmv0)); bg0_nm(bmv0>0)=1;
  849. bl0_nm=nan(size(bmv0)); bl0_nm(bmv0<0)=1;
  850. cL0_nm=nan(size(cmv0)); cL0_nm(cmv0==0)=1;
  851. cR0_nm=nan(size(cmv0)); cR0_nm(cmv0==1)=1;
  852. if plot_sigbetas
  853. ps0=double(repmat(reshape(squeeze(pv_mat(1,:,tbins_to_plot,subg_to_plot)),[1 Nccs Ntb2p Nsubg]),Ntrs12,1,1)==1);
  854. ps0(ps0==0)=nan;
  855. zmv0=zmv0.*ps0;
  856. end
  857. %sum(~isnan(nanmedian(zmv0,[1 3])),2)
  858. %sum(sum(~isnan(bg0_nm(1,:,:)),3)==0) %there is some time bins where no beta is >0
  859. pref1=bg0_nm.*cL0_nm;
  860. pref2=bl0_nm.*cL0_nm;
  861. pref3=bg0_nm.*cR0_nm;
  862. pref4=bl0_nm.*cR0_nm;
  863. z0_bpcL=zmv0.*pref1; z_bpcL=nanmean(z0_bpcL,[1 3]);%nanmedian(z0_bpcL,[1 3]);
  864. z0_bncL=zmv0.*pref2; z_bncL=nanmean(z0_bncL,[1 3]);%nanmedian(z0_bncL,[1 3]);
  865. z0_bpcR=zmv0.*pref3; z_bpcR=nanmean(z0_bpcR,[1 3]);%nanmedian(z0_bpcR,[1 3]);
  866. z0_bncR=zmv0.*pref4; z_bncR=nanmean(z0_bncR,[1 3]);%nanmedian(z0_bncR,[1 3]);
  867. %z0_bpcL=zmv0.*pref1; z_bpcL=nanmedian(z0_bpcL,[1 3]);
  868. %z0_bncL=zmv0.*pref2; z_bncL=nanmedian(z0_bncL,[1 3]);
  869. %z0_bpcR=zmv0.*pref3; z_bpcR=nanmedian(z0_bpcR,[1 3]);
  870. %z0_bncR=zmv0.*pref4; z_bncR=nanmedian(z0_bncR,[1 3]);
  871. %(sum(~isnan([z_bpcL; z_bncR; z_bncL; z_bpcR]),2))
  872. %z_bpcL=z_bpcL(:); z_bncL=z_bncL(:); z_bpcR=z_bpcR(:); z_bncR=z_bncR(:);
  873. %Nz=[size(z_bpcL,1)+size(z_bncR,1) size(z_bpcR,1)+size(z_bncL,1)];
  874. %zr_mat_travg=[[z_bpcL; z_bncR; nan(max(Nz)-Nz(1),1)] [z_bncL; z_bpcR; nan(max(Nz)-Nz(2),1)]];
  875. %size([z_bpcL z_bpcR])
  876. %zr_mat_travg=[[z_bpcL' z_bpcR']; [z_bncR' z_bncL']]'; % [2*Nccs, 2]
  877. zr_mat_travg=[z_bpcL z_bncR; z_bpcR, z_bncL]; % [2*Nccs, 2]
  878. %zr_mat_travg=cat(2,cat(1,z_bpcL,z_bncR),cat(1,z_bpcR,z_bncL));
  879. %z_bpcL=z0_bpcL;%nanmedian(z0_bpcL,3);
  880. %z_bncL=z0_bncL;%nanmedian(z0_bncL,3);
  881. %z_bpcR=z0_bpcR;%nanmedian(z0_bpcR,3);
  882. %z_bncR=z0_bncR;%nanmedian(z0_bncR,3);
  883. %Nz=[size(z_bpcL,2)+size(z_bncR,2) size(z_bpcR,2)+size(z_bncL,2)];
  884. %size(z0_bpcL)
  885. zr_mat_trwise_merged=cat(4,cat(2,z0_bpcL,z0_bncR),cat(2,z0_bpcR,z0_bncL)); %[Ntrs12 2*Nccs Ntb2p 2]
  886. zr_mat_trwise_split=cat(4,z0_bpcL,z0_bncR,z0_bpcR,z0_bncL); %[Ntrs12 Nccs Ntb2p 4]
  887. %zr_mat_trwise=cat(4,[z_bpcL z_bncR; nan(max(Nz)-Nz(1),1,N)],[z_bncL z_bpcR; nan(max(Nz)-Nz(2),1)]);
  888. %sum(~isnan(zr_mat),1)
  889. end
  890. %% Combine disjoint subsets into pools of betas
  891. function Zstruct_trwise = combine_subsets(Zstructi,Zstructj)
  892. Z_b1_LL_bw_ssi_trwise=Zstructi.Z_b1_LL_trwise;
  893. Z_b1_LR_bw_ssi_trwise=Zstructi.Z_b1_LR_trwise;
  894. Z_b2_LL_bw_ssi_trwise=Zstructi.Z_b2_LL_trwise;
  895. Z_b2_LR_bw_ssi_trwise=Zstructi.Z_b2_LR_trwise;
  896. Z_b1_LL_bw_ssj_trwise=Zstructj.Z_b1_LL_trwise;
  897. Z_b1_LR_bw_ssj_trwise=Zstructj.Z_b1_LL_trwise;
  898. Z_b2_LL_bw_ssj_trwise=Zstructj.Z_b2_LL_trwise;
  899. Z_b2_LR_bw_ssj_trwise=Zstructj.Z_b2_LL_trwise;
  900. Z_b1_LL_trwise_ij=cat(4,Z_b1_LL_bw_ssi_trwise(:,:,:,1),Z_b1_LL_bw_ssj_trwise(:,:,:,2),...
  901. Z_b1_LL_bw_ssj_trwise(:,:,:,3),Z_b1_LL_bw_ssi_trwise(:,:,:,4));
  902. Z_b1_LR_trwise_ij=cat(4,Z_b1_LR_bw_ssi_trwise(:,:,:,1),Z_b1_LR_bw_ssj_trwise(:,:,:,2),...
  903. Z_b1_LR_bw_ssj_trwise(:,:,:,3),Z_b1_LR_bw_ssi_trwise(:,:,:,4));
  904. Z_b2_LL_trwise_ij=cat(4,Z_b2_LL_bw_ssi_trwise(:,:,:,1),Z_b2_LL_bw_ssj_trwise(:,:,:,2),...
  905. Z_b2_LL_bw_ssj_trwise(:,:,:,3),Z_b2_LL_bw_ssi_trwise(:,:,:,4));
  906. Z_b2_LR_trwise_ij=cat(4,Z_b2_LR_bw_ssi_trwise(:,:,:,1),Z_b2_LR_bw_ssj_trwise(:,:,:,2),...
  907. Z_b2_LR_bw_ssj_trwise(:,:,:,3),Z_b2_LR_bw_ssi_trwise(:,:,:,4));
  908. Z_b1_LL_trwise_ji=cat(4,Z_b1_LL_bw_ssj_trwise(:,:,:,1),Z_b1_LL_bw_ssi_trwise(:,:,:,2),...
  909. Z_b1_LL_bw_ssi_trwise(:,:,:,3),Z_b1_LL_bw_ssj_trwise(:,:,:,4));
  910. Z_b1_LR_trwise_ji=cat(4,Z_b1_LR_bw_ssj_trwise(:,:,:,1),Z_b1_LR_bw_ssi_trwise(:,:,:,2),...
  911. Z_b1_LR_bw_ssi_trwise(:,:,:,3),Z_b1_LR_bw_ssj_trwise(:,:,:,4));
  912. Z_b2_LL_trwise_ji=cat(4,Z_b2_LL_bw_ssj_trwise(:,:,:,1),Z_b2_LL_bw_ssi_trwise(:,:,:,2),...
  913. Z_b2_LL_bw_ssi_trwise(:,:,:,3),Z_b2_LL_bw_ssj_trwise(:,:,:,4));
  914. Z_b2_LR_trwise_ji=cat(4,Z_b2_LR_bw_ssj_trwise(:,:,:,1),Z_b2_LR_bw_ssi_trwise(:,:,:,2),...
  915. Z_b2_LR_bw_ssi_trwise(:,:,:,3),Z_b2_LR_bw_ssj_trwise(:,:,:,4));
  916. Zstruct_trwise.Z_b1_LL_trwise=cat(1,Z_b1_LL_trwise_ij,Z_b1_LL_trwise_ji);
  917. Zstruct_trwise.Z_b1_LR_trwise=cat(1,Z_b1_LR_trwise_ij,Z_b1_LR_trwise_ji);
  918. Zstruct_trwise.Z_b2_LL_trwise=cat(1,Z_b2_LL_trwise_ij,Z_b2_LL_trwise_ji);
  919. Zstruct_trwise.Z_b2_LR_trwise=cat(1,Z_b2_LR_trwise_ij,Z_b2_LR_trwise_ji);
  920. end
  921. %% Reshape residuals based on sign of betas
  922. function Zstruct_trwise=get_bw_ss(bwstr,subsetstr,plot_sigbetas,tbins_to_plot,subg_to_plot,select_diff_trials)
  923. if nargin<6
  924. select_diff_trials=0;
  925. end
  926. % bwstr = 'bw0', 'bw1', 'bw2'
  927. % subsetstr = 'ss0'
  928. if select_diff_trials
  929. disp('loading residuals for diff trials')
  930. load('fitlmstats_chR_evR_evL_spk_span_200ms_lag_10ms_22-Mar-2024.mat');
  931. else
  932. disp('loading residuals for all trials')
  933. load('fitlmstats_chR_evR_evL_spk_span_200ms_lag_10ms_11-Mar-2024.mat');
  934. end
  935. betasLL_mat=eval(['betas_noch_' bwstr '_' subsetstr 'LL_mat']);
  936. betasLR_mat=eval(['betas_noch_' bwstr '_' subsetstr 'LR_mat']);
  937. zetasLL_mat=eval(['zetas_noch_' bwstr '_' subsetstr 'LL_mat']);
  938. zetasLR_mat=eval(['zetas_noch_' bwstr '_' subsetstr 'LR_mat']);
  939. pvalsLL_mat=eval(['pvals_noch_' bwstr '_' subsetstr 'LL_mat']);
  940. pvalsLR_mat=eval(['pvals_noch_' bwstr '_' subsetstr 'LR_mat']);
  941. offchLL_mat=eval(['offch_' subsetstr 'LL_mat']);
  942. offchLR_mat=eval(['offch_' subsetstr 'LR_mat']);
  943. if select_diff_trials
  944. load 'EVSVsubsets.mat';
  945. %SVL_LL_mat=eval(['offSVL_' bwstr swstr 'LL_mat']);
  946. %SVL_LR_mat=eval(['offSVL_' bwstr swstr 'LR_mat']);
  947. %SVR_LL_mat=eval(['offSVR_' bwstr swstr 'LL_mat']);
  948. %SVR_LR_mat=eval(['offSVR_' bwstr swstr 'LR_mat']);
  949. EVL_LL_mat=eval(['offEVL_' subsetstr 'LL_mat']);
  950. EVL_LR_mat=eval(['offEVL_' subsetstr 'LR_mat']);
  951. EVR_LL_mat=eval(['offEVR_' subsetstr 'LL_mat']);
  952. EVR_LR_mat=eval(['offEVR_' subsetstr 'LR_mat']);
  953. EVDiffLL_mask=nan(size(EVL_LL_mat));
  954. EVDiffLL_mask(abs(EVL_LL_mat-EVR_LL_mat)<1)=1;
  955. EVDiffLR_mask=nan(size(EVL_LR_mat));
  956. EVDiffLR_mask(abs(EVL_LR_mat-EVR_LR_mat)<1)=1;
  957. offchLL_mat=offchLL_mat.*EVDiffLL_mask;
  958. offchLR_mat=offchLR_mat.*EVDiffLR_mask;
  959. end
  960. Z_b1_LL_trwise=reshapez_choice_betas(offchLL_mat,betasLL_mat(2,:,:),zetasLL_mat,...
  961. tbins_to_plot,subg_to_plot,plot_sigbetas,pvalsLL_mat(2,:,:));
  962. Z_b1_LR_trwise=reshapez_choice_betas(offchLR_mat,betasLR_mat(2,:,:),zetasLR_mat,...
  963. tbins_to_plot,subg_to_plot,plot_sigbetas,pvalsLR_mat(2,:,:));
  964. Z_b2_LL_trwise=reshapez_choice_betas(offchLL_mat,betasLL_mat(3,:,:),zetasLL_mat,...
  965. tbins_to_plot,subg_to_plot,plot_sigbetas,pvalsLL_mat(3,:,:));
  966. Z_b2_LR_trwise=reshapez_choice_betas(offchLR_mat,betasLR_mat(3,:,:),zetasLR_mat,...
  967. tbins_to_plot,subg_to_plot,plot_sigbetas,pvalsLR_mat(3,:,:));
  968. Zstruct_trwise.Z_b1_LL_trwise=Z_b1_LL_trwise;
  969. Zstruct_trwise.Z_b1_LR_trwise=Z_b1_LR_trwise;
  970. Zstruct_trwise.Z_b2_LL_trwise=Z_b2_LL_trwise;
  971. Zstruct_trwise.Z_b2_LR_trwise=Z_b2_LR_trwise;
  972. end
  973. %% Compute ROC and AUC
  974. function [FPR,TPR,AUC,FP,TP,FN,TN]=get_fpr_tpr_auc(X1,X2,Y,plot_option)
  975. if nargin<4
  976. if nargin<3
  977. Y=0:.001:1;
  978. end
  979. plot_option=0;
  980. end
  981. X1=X1(:)';
  982. X2=X2(:)';
  983. FP=sum(X2>Y',2);
  984. TP=sum(X1>Y',2);
  985. FN=sum(X1<Y',2);
  986. TN=sum(X2<Y',2);
  987. FPR=FP./(TN+FP);
  988. TPR=TP./(FN+TP);
  989. AUC=max(cumtrapz(flip(FPR),flip(TPR)));
  990. if plot_option
  991. figure();
  992. plot(FPR,TPR); hold on; plot([0 1],[0 1]);
  993. text(.3,.1,sprintf('AUC: %.3f',AUC));
  994. end
  995. end