g_Fig3FigS6Decoding.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. clear all;
  2. load ('R_2R.mat');
  3. load ('RAW.mat');
  4. load ('PoolDec_2R.mat');
  5. load ('UnitDec_2R.mat');
  6. sucrose=[1 0.6 0.1];
  7. maltodextrin=[.9 0.3 .9];
  8. water=[0.00 0.75 0.75];
  9. total=[0.3 0.1 0.8];
  10. NAc=[0.5 0.1 0.8];
  11. VP=[0.3 0.7 0.1];
  12. NAcP{5,1}=[1 0.7 1];
  13. NAcP{4,1}=[0.85 0.3 0.9];
  14. NAcP{3,1}=[0.6 0.1 0.8];
  15. NAcP{2,1}=[0.3 0.05 0.5];
  16. NAcP{1,1}=[0.2 0 0.3];
  17. VPP{5,1}=[0.6 1 0.25];
  18. VPP{4,1}=[0.4 0.9 0.15];
  19. VPP{3,1}=[0.3 0.7 0.1];
  20. VPP{2,1}=[0.1 0.4 0.05];
  21. VPP{1,1}=[0.03 0.2 0];
  22. NAcShuff=[0.3 0.05 0.5];
  23. VPShuff=[0.05 0.4 0];
  24. %load parameters
  25. BinDura=R_2R.Param.BinDura;
  26. bins=R_2R.Param.bins;
  27. binint=R_2R.Param.binint;
  28. binstart=R_2R.Param.binstart;
  29. NumNeurons=R_2R.Param.NumNeurons;
  30. repetitions=length(PoolDec{1,1}.True{1,1}(:,1));
  31. xaxis=linspace(binstart+BinDura(2)/2,binstart+(bins-1)*binint+BinDura(2)/2,bins); %include all bins
  32. %% single unit decoding
  33. %divide neurons up by region
  34. NAneurons=strcmp(R_2R.Ninfo(:,3),'NA');
  35. VPneurons=strcmp(R_2R.Ninfo(:,3),'VP');
  36. for e=1:3 %different selections of neurons
  37. figure;
  38. %pick which set of neurons: all, reward-specific, or non-reward specific
  39. if e==1 selection=R_2R.SucN<2; end %all neurons
  40. if e==2 selection=R_2R.SucN | R_2R.MalN; end %reward-selective neurons
  41. if e==3 selection=(R_2R.SucN | R_2R.MalN) == 0; end %reward-nonselective neurons
  42. %get average accuracy for each bin and run stats comparing region
  43. for i = 1:bins
  44. AvgAccNAc(1,i)=nanmean(UnitDec.True(NAneurons&selection,i)); %average accuracy NAc
  45. SEMAccNAc(1,i)=nanste(UnitDec.True(NAneurons&selection,i),1); %SEM
  46. AvgAccNAcShuff(1,i)=nanmean(UnitDec.Shuff(NAneurons&selection,i)); %average accuracy NAcShuff
  47. SEMAccNAcShuff(1,i)=nanste(UnitDec.Shuff(NAneurons&selection,i),1); %SEM
  48. AvgAccVP(1,i)=nanmean(UnitDec.True(VPneurons&selection,i)); %average accuracy NAcShuff
  49. SEMAccVP(1,i)=nanste(UnitDec.True(VPneurons&selection,i),1); %SEM
  50. AvgAccVPShuff(1,i)=nanmean(UnitDec.Shuff(VPneurons&selection,i)); %average accuracy NAcShuff
  51. SEMAccVPShuff(1,i)=nanste(UnitDec.Shuff(VPneurons&selection,i),1); %SEM
  52. end
  53. %prepare shading
  54. upSEMNAc=AvgAccNAc+SEMAccNAc;
  55. downSEMNAc=AvgAccNAc-SEMAccNAc;
  56. upSEMVP=AvgAccVP+SEMAccVP;
  57. downSEMVP=AvgAccVP-SEMAccVP;
  58. upSEMNAcShuff=AvgAccNAcShuff+SEMAccNAcShuff;
  59. downSEMNAcShuff=AvgAccNAcShuff-SEMAccNAcShuff;
  60. upSEMVPShuff=AvgAccVPShuff+SEMAccVPShuff;
  61. downSEMVPShuff=AvgAccVPShuff-SEMAccVPShuff;
  62. %plotting decoder accuracies over time
  63. subplot(2,3,1);
  64. hold on;
  65. plot(xaxis,AvgAccNAc(1:bins),'Color', NAc,'linewidth',1.5); %accumbens
  66. plot(xaxis,AvgAccVP(1:bins),'Color', VP,'linewidth',1.5); %vp
  67. %shuffled
  68. plot(xaxis,AvgAccNAcShuff(1:bins),'Color', 'k','linewidth',1.5);
  69. plot(xaxis,AvgAccVPShuff(1:bins),'Color', 'k','linewidth',1.5);
  70. %error
  71. patch([xaxis,xaxis(end:-1:1)],[upSEMNAc,downSEMNAc(end:-1:1)],NAc,'EdgeColor','none');alpha(0.5);
  72. patch([xaxis,xaxis(end:-1:1)],[upSEMNAcShuff,downSEMNAcShuff(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  73. patch([xaxis,xaxis(end:-1:1)],[upSEMVP,downSEMVP(end:-1:1)],VP,'EdgeColor','none');alpha(0.5);
  74. patch([xaxis,xaxis(end:-1:1)],[upSEMVPShuff,downSEMVPShuff(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  75. xlabel('Seconds from reward delivery');
  76. ylabel('Accuracy');
  77. title('Unit decoding accuracy');
  78. legend('NAc units','VP units','Shuffled','Location','northwest');
  79. axis([xaxis(1) xaxis(end) 0.47 max(AvgAccVP)+0.04]);
  80. %find and plot bins exceeding confidence interval
  81. for i=1:bins
  82. %confidence interval for NAc
  83. x = UnitDec.Shuff(NAneurons&selection,i); % Create Data
  84. SEM = nanstd(x)/sqrt(length(x)); % Standard Error
  85. ts = tinv([0.005 0.995],length(x)-1); % T-Score
  86. CI = nanmean(x) + ts*SEM; % Confidence Intervals
  87. if nanmean(UnitDec.True(NAneurons&selection,i))>CI(2) NAcConf(1,i)=1; else NAcConf(1,i)=0; end
  88. %confidence interval for VP
  89. x = UnitDec.Shuff(VPneurons&selection,i); % Create Data
  90. SEM = nanstd(x)/sqrt(length(x)); % Standard Error
  91. ts = tinv([0.005 0.995],length(x)-1); % T-Score
  92. CI = nanmean(x) + ts*SEM; % Confidence Intervals
  93. if nanmean(UnitDec.True(VPneurons&selection,i))>CI(2) VPConf(1,i)=1; else VPConf(1,i)=0; end
  94. end
  95. %find consecutive bins
  96. R_2R.UnitNAcComp{e,1}=zeros(1,bins);
  97. R_2R.UnitVPComp{e,1}=zeros(1,bins);
  98. for i=2:bins-1
  99. if NAcConf(1,i)==1
  100. if NAcConf(1,i-1)==1 | NAcConf(1,i+1)==1
  101. R_2R.UnitNAcComp{e,1}(1,i)=1;
  102. end
  103. end
  104. if VPConf(1,i)==1
  105. if VPConf(1,i-1)==1 | VPConf(1,i+1)==1
  106. R_2R.UnitVPComp{e,1}(1,i)=1;
  107. end
  108. end
  109. end
  110. %check to see if the first bin above shuffled data would be different
  111. %if using fewer VP neurons to match NAc
  112. for j=1:20
  113. for i=1:bins
  114. matchedneurons=cat(1,ones(sum(NAneurons&selection),1),zeros(sum(VPneurons&selection)-sum(NAneurons&selection),1));
  115. matchedneurons=(matchedneurons(randperm(length(matchedneurons)))==1);
  116. %confidence interval for VP
  117. VPselectionSh=UnitDec.Shuff(VPneurons&selection,i);
  118. VPselection=UnitDec.True(VPneurons&selection,i);
  119. x = VPselectionSh(matchedneurons,1); % Create Data
  120. SEM = nanstd(x)/sqrt(length(x)); % Standard Error
  121. ts = tinv([0.005 0.995],length(x)-1); % T-Score
  122. CI = nanmean(x) + ts*SEM; % Confidence Intervals
  123. if nanmean(VPselection(matchedneurons,1))>CI(2) R_2R.VPaboveshuff{e,1}(j,i)=1; else R_2R.VPaboveshuff{e,1}(j,i)=0; end
  124. end
  125. end
  126. %plot
  127. plot(xaxis,R_2R.UnitVPComp{e,1}*0.48,'*','Color',VP);
  128. plot(xaxis,R_2R.UnitNAcComp{e,1}*0.485,'*','Color',NAc);
  129. %multiple comparisons for NAc vs VP
  130. %make a matrix indicating which region each neuron-bin comes from
  131. nbinregion=[];
  132. binname=[];
  133. for i=1:bins
  134. nbinregion=cat(2,nbinregion,NAneurons);
  135. binname=cat(2,binname,i*ones(length(NAneurons),1));
  136. end
  137. testtrue=UnitDec.True(selection,:);
  138. testshuff=UnitDec.Shuff(selection,:);
  139. testregion=nbinregion(selection,:);
  140. testbins=binname(selection,:);
  141. %find effects of real vs shuffled, region, and bins on accuracy
  142. [~,R_2R.UnitDecStats{e,1},R_2R.UnitDecStats{e,2}]=anovan(cat(1,testtrue(:),testshuff(:)),{cat(1,zeros(length(testtrue(:)),1),ones(length(testshuff(:)),1)),cat(1,testregion(:),testregion(:)),cat(1,testbins(:),testbins(:))},'varnames',{'real vs shuffled','region','bins'},'display','off','model','full');
  143. %do post-hoc comparisons
  144. [c,~,~,names]=multcompare(R_2R.UnitDecStats{e,2},'Dimension',[1 2 3],'CType','tukey-kramer','display','off');
  145. %find post-hoc differences
  146. for i=1:bins
  147. %NAc vs VP
  148. Sel=c(:,1)==4*(i-1)+1 & c(:,2)==4*(i-1)+3;
  149. if c(Sel,6)<0.05 R_2R.UnitNAcVPComp{e,1}(1,i)=1; else R_2R.UnitNAcVPComp{e,1}(1,i)=0; end
  150. R_2R.UnitNAcVPComp{e,1}(2,i)=c(Sel,6);
  151. end
  152. %add it to plot
  153. plot(xaxis,R_2R.UnitNAcVPComp{e,1}(1,:)*(max(AvgAccVP)+0.015),'*','Color','k');
  154. %plotting CDF at peak bin
  155. subplot(2,3,4)
  156. hold on;
  157. %NAc
  158. [~,NAcbin]=max(AvgAccNAc);
  159. [cdfNAc,xNAc] = ecdf(UnitDec.True(NAneurons&selection,NAcbin));
  160. [cdfNAcSh,xNAcSh] = ecdf(UnitDec.Shuff(NAneurons&selection,NAcbin));
  161. plot(xNAc,cdfNAc,'Color',NAc,'linewidth',1.5);
  162. %VP
  163. [~,VPbin]=max(AvgAccVP);
  164. [cdfVP,xVP] = ecdf(UnitDec.True(VPneurons&selection,VPbin));
  165. [cdfVPSh,xVPSh] = ecdf(UnitDec.Shuff(VPneurons&selection,VPbin));
  166. plot(xVP,cdfVP,'Color',VP,'linewidth',1.5);
  167. %shuffled
  168. plot(xNAcSh,cdfNAcSh,'Color','k','linewidth',1.5);
  169. xlabel('Decoding accuracy')
  170. plot(xVPSh,cdfVPSh,'Color','k','linewidth',1.5);
  171. axis([0 1 0 1]);
  172. plot([0.5 0.5],[0 1],':','color','k','linewidth',0.75);
  173. title(['Accuracy at peak bin: ' num2str(((NAcbin-1)*binint)+(binstart+BinDura(2)/2)) 's NAc, ' num2str(((VPbin-1)*binint)+(binstart+BinDura(2)/2)) 's VP']);
  174. xlabel('Decoding accuracy');
  175. ylabel('Cumulative fraction of population');
  176. legend('NAc units','VP units','Shuffled','Location','northwest');
  177. %stats comparing peak bins
  178. [~,R_2R.UnitDecPeakBin{e,1},~]=anovan(cat(1,UnitDec.True(NAneurons&selection,NAcbin),UnitDec.Shuff(NAneurons&selection,NAcbin),UnitDec.True(VPneurons&selection,VPbin),UnitDec.Shuff(VPneurons&selection,VPbin)),...
  179. {cat(1,zeros(sum(NAneurons&selection),1),ones(sum(NAneurons&selection),1),zeros(sum(VPneurons&selection),1),ones(sum(VPneurons&selection),1)),...
  180. cat(1,zeros(sum(NAneurons&selection),1),zeros(sum(NAneurons&selection),1),ones(sum(VPneurons&selection),1),ones(sum(VPneurons&selection),1))},'varnames',{'real vs shuffled','region'},'display','off','model','full');
  181. %% pooled decoding
  182. %reset matrices for stats analysis
  183. A=[];
  184. B=[];
  185. C=[];
  186. D=[];
  187. %get average accuracy for each bin
  188. for v=1:length(PoolDec{e,1}.True) %each condition (number of neurons used)
  189. for i = 1:bins
  190. %NAc
  191. if length(PoolDec{e,1}.True{v,1})>1 %in case analysis wasn't run because not enough neurons
  192. PoolAccNAc{v,1}(1,i)=nanmean(PoolDec{e,1}.True{v,1}(:,i)); %average accuracy NAc
  193. PoolSEMNAc{v,1}(1,i)=nanste(PoolDec{e,1}.True{v,1}(:,i),1); %SEM
  194. PoolAccNAcShuff{v,1}(1,i)=nanmean(PoolDec{e,1}.Shuff{v,1}(:,i)); %average accuracy NAcShuff
  195. PoolSEMNAcShuff{v,1}(1,i)=nanste(PoolDec{e,1}.Shuff{v,1}(:,i),1); %SEM
  196. else
  197. PoolAccNAc{v,1}(1,i)=NaN;
  198. PoolSEMNAc{v,1}(1,i)=NaN;
  199. PoolAccNAcShuff{v,1}(1,i)=NaN;
  200. PoolSEMNAcShuff{v,1}(1,i)=NaN;
  201. end
  202. %VP
  203. if length(PoolDec{e,2}.True{v,1})>1 %in case analysis wasn't run because not enough neurons
  204. PoolAccVP{v,1}(1,i)=nanmean(PoolDec{e,2}.True{v,1}(:,i)); %average accuracy VP
  205. PoolSEMVP{v,1}(1,i)=nanste(PoolDec{e,2}.True{v,1}(:,i),1); %SEM
  206. PoolAccVPShuff{v,1}(1,i)=nanmean(PoolDec{e,2}.Shuff{v,1}(:,i)); %average accuracy VPshuff
  207. PoolSEMVPShuff{v,1}(1,i)=nanste(PoolDec{e,2}.Shuff{v,1}(:,i),1); %SEM
  208. else
  209. PoolAccVP{v,1}(1,i)=NaN;
  210. PoolSEMVP{v,1}(1,i)=NaN;
  211. PoolAccVPShuff{v,1}(1,i)=NaN;
  212. PoolSEMVPShuff{v,1}(1,i)=NaN;
  213. end
  214. end
  215. %find the time of the most accurate bin for each of the repetitions
  216. for j = 1:repetitions
  217. %NAc
  218. if length(PoolDec{e,1}.True{v,1})>1 %in case analysis wasn't run because not enough neurons
  219. [~,PeakBinsNAc{v,1}(j,1)]=max(PoolDec{e,1}.True{v,1}(j,:));
  220. PeakBinsNAc{v,1}(j,2)=binstart-binint+PeakBinsNAc{v,1}(j,1)*binint+BinDura(2)/2;
  221. else
  222. PeakBinsNAc{v,1}(j,1)=NaN;
  223. PeakBinsNAc{v,1}(j,2)=NaN;
  224. end
  225. %VP
  226. if length(PoolDec{e,2}.True{v,1})>1 %in case analysis wasn't run because not enough neurons
  227. [~,PeakBinsVP{v,1}(j,1)]=max(PoolDec{e,2}.True{v,1}(j,:));
  228. PeakBinsVP{v,1}(j,2)=binstart-binint+PeakBinsVP{v,1}(j,1)*binint+BinDura(2)/2;
  229. else
  230. PeakBinsVP{v,1}(j,1)=NaN;
  231. PeakBinsVP{v,1}(j,2)=NaN;
  232. end
  233. end
  234. %prepare shading
  235. PupSEMNAc{v,1}=PoolAccNAc{v,1}+PoolSEMNAc{v,1};
  236. PdownSEMNAc{v,1}=PoolAccNAc{v,1}-PoolSEMNAc{v,1};
  237. PupSEMVP{v,1}=PoolAccVP{v,1}+PoolSEMVP{v,1};
  238. PdownSEMVP{v,1}=PoolAccVP{v,1}-PoolSEMVP{v,1};
  239. PupSEMNAcShuff{v,1}=PoolAccNAcShuff{v,1}+PoolSEMNAcShuff{v,1};
  240. PdownSEMNAcShuff{v,1}=PoolAccNAcShuff{v,1}-PoolSEMNAcShuff{v,1};
  241. PupSEMVPShuff{v,1}=PoolAccVPShuff{v,1}+PoolSEMVPShuff{v,1};
  242. PdownSEMVPShuff{v,1}=PoolAccVPShuff{v,1}-PoolSEMVPShuff{v,1};
  243. %here I plot the main lines for each condition that will have an entry
  244. %in the legend (legend goes by order plotted)
  245. %plotting decoder accuracy over time
  246. subplot(2,3,2); %accumbens
  247. hold on;
  248. plot(xaxis,PoolAccNAc{v,1}(1:66),'Color', NAcP{v,1},'linewidth',1);
  249. %plot(xaxis,PoolAccNAcShuff{v,1}(1:66),'Color', NAcShuff,'linewidth',3);
  250. %plot(xaxis,NAcSig{v,1}-0.53,'*','Color', 'k');
  251. %patch([xaxis,xaxis(end:-1:1)],[PupSEMNAc{v,1},PdownSEMNAc{v,1}(end:-1:1)],NAc{v,1},'EdgeColor','none');alpha(0.5);
  252. %patch([xaxis,xaxis(end:-1:1)],[PupSEMNAcShuff{v,1},PdownSEMNAcShuff{v,1}(end:-1:1)],NAcShuff,'EdgeColor','none');alpha(0.5);
  253. xlabel('Seconds post reward delivery');
  254. ylabel('Accuracy');
  255. title('NAc decoding accuracy');
  256. axis([xaxis(1) xaxis(end) 0.4 1]);
  257. subplot(2,3,3); %VP
  258. hold on;
  259. plot(xaxis,PoolAccVP{v,1}(1:66),'Color', VPP{v,1},'linewidth',1);
  260. %plot(xaxis,PoolAccVPShuff{v,1}(1:66),'Color', VPShuff,'linewidth',3);
  261. %plot(xaxis,VPSig{v,1}-0.53,'*','Color','k');
  262. %patch([xaxis,xaxis(end:-1:1)],[PupSEMVP{v,1},PdownSEMVP{v,1}(end:-1:1)],VP{v,1},'EdgeColor','none');alpha(0.5);
  263. %patch([xaxis,xaxis(end:-1:1)],[PupSEMVPShuff{v,1},PdownSEMVPShuff{v,1}(end:-1:1)],VPShuff,'EdgeColor','none');alpha(0.5);
  264. xlabel('Seconds post reward delivery');
  265. ylabel('Accuracy');
  266. title('VP decoding accuracy');
  267. axis([xaxis(1) xaxis(end) 0.4 1]);
  268. %comparison at best bin
  269. subplot(2,3,5);
  270. hold on;
  271. [~,NAcbin]=max(PoolAccNAc{v,1});
  272. [~,VPbin]=max(PoolAccVP{v,1});
  273. if length(PoolDec{e,1}.True{v,1})>1 && length(PoolDec{e,2}.True{v,1})>1
  274. %make matrices that will include best bin at all levels
  275. A=cat(1,A,PoolDec{e,1}.True{v,1}(:,NAcbin));
  276. B=cat(1,B,PoolDec{e,1}.Shuff{v,1}(:,NAcbin));
  277. C=cat(1,C,PoolDec{e,2}.True{v,1}(:,VPbin));
  278. D=cat(1,D,PoolDec{e,2}.Shuff{v,1}(:,VPbin));
  279. end
  280. errorbar(NumNeurons(v),PoolAccNAc{v,1}(NAcbin),PoolSEMNAc{v,1}(NAcbin),'*','Color', NAcP{v,1},'linewidth',1.5);
  281. errorbar(NumNeurons(v),PoolAccVP{v,1}(VPbin),PoolSEMVP{v,1}(VPbin),'*','Color', VPP{v,1},'linewidth',1.5);
  282. xlabel('Neurons used');
  283. ylabel('Accuracy');
  284. title('Accuracy for most predictive bin');
  285. legend('NAc','VP','Location','southeast');
  286. axis([0 155 0.5 1]);
  287. %plotting time of most accurate bin
  288. subplot(2,3,6);
  289. hold on;
  290. errorbar(NumNeurons(v),nanmean(PeakBinsNAc{v,1}(:,2)),nanste(PeakBinsNAc{v,1}(:,2),1),'*','Color', NAcP{v,1},'linewidth',1.5);
  291. errorbar(NumNeurons(v),nanmean(PeakBinsVP{v,1}(:,2)),nanste(PeakBinsVP{v,1}(:,2),1),'*','Color', VPP{v,1},'linewidth',1.5);
  292. xlabel('Neurons used');
  293. ylabel('Seconds post reward delivery')
  294. title('Time of most accurate bin');
  295. %legend('NAc','VP','Location','southeast');
  296. axis([0 155 0 2.5]);
  297. legend('NAc','VP','location','southeast')
  298. end %conditions
  299. %now plot the shading, significance, and the shuffled separately
  300. for v=1:length(PoolDec{e,1}.True) %each condition (number of neurons used)
  301. %plotting decoder accuracy over time
  302. subplot(2,3,2); %accumbens
  303. hold on;
  304. plot(xaxis,PoolAccNAcShuff{v,1}(1:66),'Color', 'k','linewidth',1);
  305. patch([xaxis,xaxis(end:-1:1)],[PupSEMNAc{v,1},PdownSEMNAc{v,1}(end:-1:1)],NAcP{v,1},'EdgeColor','none');alpha(0.5);
  306. patch([xaxis,xaxis(end:-1:1)],[PupSEMNAcShuff{v,1},PdownSEMNAcShuff{v,1}(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  307. xlabel('Seconds post reward delivery');
  308. title('NAc decoding accuracy');
  309. axis([xaxis(1) xaxis(end) 0.4 1]);
  310. legend('10 units','25 units','50 units','100 units','150 units','Shuffled','location','northwest')
  311. subplot(2,3,3); %VP
  312. hold on;
  313. plot(xaxis,PoolAccVPShuff{v,1}(1:66),'Color', 'k','linewidth',1);
  314. patch([xaxis,xaxis(end:-1:1)],[PupSEMVP{v,1},PdownSEMVP{v,1}(end:-1:1)],VPP{v,1},'EdgeColor','none');alpha(0.5);
  315. patch([xaxis,xaxis(end:-1:1)],[PupSEMVPShuff{v,1},PdownSEMVPShuff{v,1}(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  316. xlabel('Seconds post reward delivery');
  317. title('VP decoding accuracy');
  318. axis([xaxis(1) xaxis(end) 0.4 1]);
  319. legend('10 units','25 units','50 units','100 units','150 units','Shuffled','location','northwest')
  320. end
  321. %stats!
  322. %ANOVA for effects of number of neurons and region on time of peak accuracy
  323. %time
  324. PeakTimes=[];
  325. for i=1:length(NumNeurons)
  326. if length(PoolDec{e,1}.True{i,1})>1 && length(PoolDec{e,2}.True{i,1})>1
  327. PeakTimes(1:repetitions,i)=PeakBinsNAc{i,1}(:,2);
  328. PeakTimes(1+repetitions:repetitions+repetitions,i)=PeakBinsVP{i,1}(:,2);
  329. end
  330. end
  331. [~,R_2R.PoolDecTimeStats{e,1},R_2R.PoolDecTimeStats{e,2}]=anova2(PeakTimes,repetitions,'off'); %columns is ensemble size, rows is region
  332. %ANOVA for effect of ensemble size, region, and shuff vs true on accuracy
  333. %of peak bin
  334. size=[];
  335. for i=1:length(NumNeurons)
  336. if length(PoolDec{e,1}.True{i,1})>1 && length(PoolDec{e,2}.True{i,1})>1
  337. size=cat(1,size,i*ones(repetitions,1));
  338. end
  339. end
  340. %with shuff vs true
  341. % size2=cat(1,size,size,size,size);
  342. % shuffd=cat(1,ones(length(A),1),zeros(length(B),1),ones(length(C),1),zeros(length(D),1));
  343. % region=cat(1,ones(length(A)+length(B),1),zeros(length(C)+length(D),1));
  344. % [~,R_2R.AccAnova,~]=anovan(cat(1,A,B,C,D),{shuffd,region,size2},'varnames',{'real vs shuffled','region','ens size'},'display','off','model','full');
  345. %without shuff vs true
  346. size3=cat(1,size,size);
  347. region3=cat(1,ones(length(A),1),zeros(length(C),1));
  348. [~,R_2R.PoolDecAccStats{e,1},R_2R.PoolDecAccStats{e,2}]=anovan(cat(1,A,C),{region3,size3},'varnames',{'region','ens size'},'display','off','model','full');
  349. end %selections
  350. save('R_2R.mat','R_2R');