o_Figure7_DecodingAlcoholExposed.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. %Plotting decoding analysis
  2. clear all;
  3. load('UnitMdlDSSucrose.mat')
  4. load('UnitMdlDSShuffSucrose.mat')
  5. load('UnitMdlPavSucrose.mat')
  6. load('UnitMdlPavShuffSucrose.mat')
  7. if ~exist('RPPSall'),load('RPPSall.mat'); end
  8. if ~exist('RPSall'),load('RPSall.mat'); end
  9. load('UnitMdlDSAlcohol.mat')
  10. load('UnitMdlDSShuffAlcohol.mat')
  11. load('UnitMdlPavAlcohol.mat')
  12. load('UnitMdlPavShuffAlcohol.mat')
  13. if ~exist('RvppasALL'),load('RvppasALL.mat'); end
  14. if ~exist('RvpppasALL'),load('RvpppasALL.mat'); end
  15. sucrose=[1 0.6 0.1];
  16. maltodextrin=[.9 0.3 .9];
  17. water=[0.00 0.75 0.75];
  18. total=[0.3 0.1 0.8];
  19. DS=[0 0.4470 0.7410];
  20. Pav=[0.8500 0.3250 0.0980];
  21. DSAlcohol=[51/255 160/255 44/255];%[0.4940 0.1840 0.5560];
  22. PavAlcohol=[180/255 41/255 230/255];%[0.9290 0.6940 0.1250];
  23. DSShuff=[0 0 0];
  24. PavShuff=[0 0 0];
  25. xaxis=linspace(-0.75,3.15,13);
  26. selection1=RPPSall.Structure==10 & RPPSall.CSPlusRatio>=.5 & (RPPSall.CSPlusRatio./(RPPSall.CSPlusRatio+RPPSall.CSMinusRatio))>=.7;% & RPPSall.Ev(1).RespDir==1;
  27. selection2=RPSall.Structure==10 & RPSall.CSPlusRatio>=.5 & (RPSall.CSPlusRatio./(RPSall.CSPlusRatio+RPSall.CSMinusRatio))>=.7;% & RPSall.Ev(1).RespDir==1;
  28. selection3=RvpppasALL.Structure==10 & RvpppasALL.CSPlusRatio>=.5 & (RvpppasALL.CSPlusRatio./(RvpppasALL.CSPlusRatio+RvpppasALL.CSMinusRatio))>=.7;% & RvpppasALL.Ev(1).RespDir==1;
  29. selection4=RvppasALL.Structure==10 & RvppasALL.CSPlusRatio>=.5 & (RvppasALL.CSPlusRatio./(RvppasALL.CSPlusRatio+RvppasALL.CSMinusRatio))>=.7;% & RvppasALL.Ev(1).RespDir==1;
  30. %Figure code
  31. figure;
  32. %get average accuracy for each bin
  33. for i = 1:13
  34. AvgAccDSSucrose(1,i)=nanmean(UnitMdlAccDSSucrose(selection1,i)); %average accuracy DS
  35. SEMAccDSSucrose(1,i)=nanste(UnitMdlAccDSSucrose(selection1,i),1); %SEM
  36. AvgAccDSShuffSucrose(1,i)=nanmean(UnitMdlAccDSShuffSucrose(selection1,i)); %average accuracy DSShuff
  37. SEMAccDSShuffSucrose(1,i)=nanste(UnitMdlAccDSShuffSucrose(selection1,i),1); %SEM
  38. AvgAccPavSucrose(1,i)=nanmean(UnitMdlAccPavSucrose(selection2,i)); %average accuracy DSShuff
  39. SEMAccPavSucrose(1,i)=nanste(UnitMdlAccPavSucrose(selection2,i),1); %SEM
  40. AvgAccPavShuffSucrose(1,i)=nanmean(UnitMdlAccPavShuffSucrose(selection2,i)); %average accuracy DSShuff
  41. SEMAccPavShuffSucrose(1,i)=nanste(UnitMdlAccPavShuffSucrose(selection2,i),1); %SEM
  42. DSSigSucrose(1,i) = ttest2(UnitMdlAccDSSucrose(:,i),UnitMdlAccDSShuffSucrose(selection1,i),'Vartype','unequal'); %welch's t-test
  43. PavSigSucrose(1,i) = ttest2(UnitMdlAccPavSucrose(:,i),UnitMdlAccPavShuffSucrose(selection2,i),'Vartype','unequal'); %welch's t-test
  44. end
  45. %get normalized accuracy increase over shuffled for each neuron, then take
  46. %average and find SEM
  47. for i = 1:13
  48. for j = 1:length(UnitMdlAccDSSucrose)
  49. NormAccDSSucrose(j,i) = UnitMdlAccDSSucrose(j,i)-nanmean(nanmean(UnitMdlAccDSShuffSucrose(:,i)));
  50. end
  51. for k = 1:length(UnitMdlAccPavSucrose)
  52. NormAccPavSucrose(k,i) = UnitMdlAccPavSucrose(k,i)-nanmean(nanmean(UnitMdlAccPavShuffSucrose(:,i)));
  53. end
  54. AvgNormDSSucrose(1,i)=nanmean(NormAccDSSucrose(selection1,i)); %average norm accuracy DS
  55. SEMNormDSSucrose(1,i)=nanste(NormAccDSSucrose(selection1,i),1); %SEM
  56. AvgNormPavSucrose(1,i)=nanmean(NormAccPavSucrose(selection2,i)); %average norm accuracy DS
  57. SEMNormPavSucrose(1,i)=nanste(NormAccPavSucrose(selection2,i),1); %SEM
  58. %NormSig(1,i) = ttest2(NormAccDS(:,i),NormAccPav(:,i),'Vartype','unequal'); %welch's t-test
  59. [~,NormSig(1,i)] = ranksum(NormAccDSSucrose(selection1,i),NormAccPavSucrose(selection2,i)); %wilcoxon's ranksum test
  60. end
  61. %prepare shading
  62. upSEMDS1=AvgAccDSSucrose+SEMAccDSSucrose;
  63. downSEMDS1=AvgAccDSSucrose-SEMAccDSSucrose;
  64. upSEMPav1=AvgAccPavSucrose+SEMAccPavSucrose;
  65. downSEMPav1=AvgAccPavSucrose-SEMAccPavSucrose;
  66. upSEMDSShuff1=AvgAccDSShuffSucrose+SEMAccDSShuffSucrose;
  67. downSEMDSShuff1=AvgAccDSShuffSucrose-SEMAccDSShuffSucrose;
  68. upSEMPavShuff1=AvgAccPavShuffSucrose+SEMAccPavShuffSucrose;
  69. downSEMPavShuff1=AvgAccPavShuffSucrose-SEMAccPavShuffSucrose;
  70. upSEMNormDS1=AvgNormDSSucrose+SEMNormDSSucrose;
  71. downSEMNormDS1=AvgNormDSSucrose-SEMNormDSSucrose;
  72. upSEMNormPav1=AvgNormPavSucrose+SEMNormPavSucrose;
  73. downSEMNormPav1=AvgNormPavSucrose-SEMNormPavSucrose;
  74. % %plotting decoder accuracy over time
  75. % subplot(3,4,1); %accumbens
  76. % hold on;
  77. % plot(xaxis,AvgAccDSSucrose(1:13),'Color', DS,'linewidth',3);
  78. % plot(xaxis,AvgAccDSShuffSucrose(1:13),'Color', DSShuff,'linewidth',3);
  79. % %plot(xaxis,DSSigSucrose-0.51,'*','Color', 'k');
  80. % patch([xaxis,xaxis(end:-1:1)],[upSEMDS,downSEMDS(end:-1:1)],DS,'EdgeColor','none');alpha(0.5);
  81. % patch([xaxis,xaxis(end:-1:1)],[upSEMDSShuff,downSEMDSShuff(end:-1:1)],DSShuff,'EdgeColor','none');alpha(0.5);
  82. % xlabel('Seconds post cue');
  83. % legend('Sucrose DS','Shuffled','Location','best');
  84. % %title('Sucrose DS single unit decoding accuracy');
  85. % ylabel('Single Unit Decoding Accuracy');
  86. % axis([-.75 3.15 0.45 0.7]);
  87. %
  88. % subplot(3,4,2); %Pav
  89. % hold on;
  90. % plot(xaxis,AvgAccPavSucrose(1:13),'Color', Pav,'linewidth',3);
  91. % plot(xaxis,AvgAccPavShuffSucrose(1:13),'Color', PavShuff,'linewidth',3);
  92. % %plot(xaxis,PavSig-0.51,'*','Color', 'k');
  93. % patch([xaxis,xaxis(end:-1:1)],[upSEMPav,downSEMPav(end:-1:1)],Pav,'EdgeColor','none');alpha(0.5);
  94. % patch([xaxis,xaxis(end:-1:1)],[upSEMPavShuff,downSEMPavShuff(end:-1:1)],PavShuff,'EdgeColor','none');alpha(0.5);
  95. % xlabel('Seconds post cue');
  96. % %title('Sucrose CS+ single unit decoding accuracy');
  97. % legend('Sucrose CS+','Shuffled','Location','northeast');
  98. % axis([-.75 3.15 0.45 0.7]);
  99. %get average accuracy for each bin
  100. for i = 1:13
  101. AvgAccDSAlcohol(1,i)=nanmean(UnitMdlAccDSAlcohol(selection3,i)); %average accuracy DS
  102. SEMAccDSAlcohol(1,i)=nanste(UnitMdlAccDSAlcohol(selection3,i),1); %SEM
  103. AvgAccDSShuffAlcohol(1,i)=nanmean(UnitMdlAccDSShuffAlcohol(selection3,i)); %average accuracy DSShuff
  104. SEMAccDSShuffAlcohol(1,i)=nanste(UnitMdlAccDSShuffAlcohol(selection3,i),1); %SEM
  105. AvgAccPavAlcohol(1,i)=nanmean(UnitMdlAccPavAlcohol(selection4,i)); %average accuracy DSShuff
  106. SEMAccPavAlcohol(1,i)=nanste(UnitMdlAccPavAlcohol(selection4,i),1); %SEM
  107. AvgAccPavShuffAlcohol(1,i)=nanmean(UnitMdlAccPavShuffAlcohol(selection4,i)); %average accuracy DSShuff
  108. SEMAccPavShuffAlcohol(1,i)=nanste(UnitMdlAccPavShuffAlcohol(selection4,i),1); %SEM
  109. DSSigAlcohol(1,i) = ttest2(UnitMdlAccDSAlcohol(:,i),UnitMdlAccDSShuffAlcohol(selection3,i),'Vartype','unequal'); %welch's t-test
  110. PavSigAlcohol(1,i) = ttest2(UnitMdlAccPavAlcohol(:,i),UnitMdlAccPavShuffAlcohol(selection4,i),'Vartype','unequal'); %welch's t-test
  111. end
  112. %get normalized accuracy increase over shuffled for each neuron, then take
  113. %average and find SEM
  114. for i = 1:13
  115. for j = 1:length(UnitMdlAccDSAlcohol)
  116. NormAccDSAlcohol(j,i) = UnitMdlAccDSAlcohol(j,i)-nanmean(nanmean(UnitMdlAccDSShuffAlcohol(:,i)));
  117. end
  118. for k = 1:length(UnitMdlAccPavAlcohol)
  119. NormAccPavAlcohol(k,i) = UnitMdlAccPavAlcohol(k,i)-nanmean(nanmean(UnitMdlAccPavShuffAlcohol(:,i)));
  120. end
  121. AvgNormDSAlcohol(1,i)=nanmean(NormAccDSAlcohol(selection3,i)); %average norm accuracy DS
  122. SEMNormDSAlcohol(1,i)=nanste(NormAccDSAlcohol(selection3,i),1); %SEM
  123. AvgNormPavAlcohol(1,i)=nanmean(NormAccPavAlcohol(selection4,i)); %average norm accuracy DS
  124. SEMNormPavAlcohol(1,i)=nanste(NormAccPavAlcohol(selection4,i),1); %SEM
  125. %NormSig(1,i) = ttest2(NormAccDS(:,i),NormAccPav(:,i),'Vartype','unequal'); %welch's t-test
  126. [~,NormSig(1,i)] = ranksum(NormAccDSAlcohol(selection3,i),NormAccPavAlcohol(selection4,i)); %wilcoxon's ranksum test
  127. end
  128. %prepare shading
  129. upSEMDS=AvgAccDSAlcohol+SEMAccDSAlcohol;
  130. downSEMDS=AvgAccDSAlcohol-SEMAccDSAlcohol;
  131. upSEMPav=AvgAccPavAlcohol+SEMAccPavAlcohol;
  132. downSEMPav=AvgAccPavAlcohol-SEMAccPavAlcohol;
  133. upSEMDSShuff=AvgAccDSShuffAlcohol+SEMAccDSShuffAlcohol;
  134. downSEMDSShuff=AvgAccDSShuffAlcohol-SEMAccDSShuffAlcohol;
  135. upSEMPavShuff=AvgAccPavShuffAlcohol+SEMAccPavShuffAlcohol;
  136. downSEMPavShuff=AvgAccPavShuffAlcohol-SEMAccPavShuffAlcohol;
  137. upSEMNormDS=AvgNormDSAlcohol+SEMNormDSAlcohol;
  138. downSEMNormDS=AvgNormDSAlcohol-SEMNormDSAlcohol;
  139. upSEMNormPav=AvgNormPavAlcohol+SEMNormPavAlcohol;
  140. downSEMNormPav=AvgNormPavAlcohol-SEMNormPavAlcohol;
  141. % %plotting decoder accuracy over time
  142. % subplot(3,4,5); %accumbens
  143. % hold on;
  144. % plot(xaxis,AvgAccDSAlcohol(1:13),'Color', DSAlcohol,'linewidth',3);
  145. % plot(xaxis,AvgAccDSShuffAlcohol(1:13),'Color', DSShuff,'linewidth',3);
  146. % %plot(xaxis,DSSigAlcohol-0.51,'*','Color', 'k');
  147. % patch([xaxis,xaxis(end:-1:1)],[upSEMDS,downSEMDS(end:-1:1)],DSAlcohol,'EdgeColor','none');alpha(0.5);
  148. % patch([xaxis,xaxis(end:-1:1)],[upSEMDSShuff,downSEMDSShuff(end:-1:1)],DSShuff,'EdgeColor','none');alpha(0.5);
  149. % xlabel('Seconds post cue');
  150. % legend('Suc(alc) DS','Shuffled','Location','northeast');
  151. % %title('Alcohol DS single unit decoding accuracy');
  152. % axis([-.75 3.15 0.45 0.7]);
  153. % ylabel('Single Unit Decoding Accuracy');
  154. %
  155. % subplot(3,4,6); %Pav
  156. % hold on;
  157. % plot(xaxis,AvgAccPavAlcohol(1:13),'Color', PavAlcohol,'linewidth',3);
  158. % plot(xaxis,AvgAccPavShuffAlcohol(1:13),'Color', PavShuff,'linewidth',3);
  159. % %plot(xaxis,PavSig-0.51,'*','Color', 'k');
  160. % patch([xaxis,xaxis(end:-1:1)],[upSEMPav,downSEMPav(end:-1:1)],PavAlcohol,'EdgeColor','none');alpha(0.5);
  161. % patch([xaxis,xaxis(end:-1:1)],[upSEMPavShuff,downSEMPavShuff(end:-1:1)],PavShuff,'EdgeColor','none');alpha(0.5);
  162. % xlabel('Seconds post cue');
  163. % %title('Alcohol CS+ single unit decoding accuracy');
  164. % legend('Suc(alc) CS+','Shuffled','Location','northeast');
  165. % axis([-.75 3.15 0.45 0.7]);
  166. % combined single unit decoding over time
  167. subplot(2,2,1);
  168. hold on;
  169. plot(xaxis,AvgAccDSAlcohol(1:13),'Marker','o','Color', DSAlcohol,'linewidth',1);
  170. plot(xaxis,AvgAccPavAlcohol(1:13),'Marker','o','Color', PavAlcohol,'linewidth',1);
  171. plot(xaxis,AvgAccDSShuffAlcohol(1:13),'Marker','o','Color', DSShuff,'linewidth',1);
  172. plot(xaxis,AvgAccPavShuffAlcohol(1:13),'Marker','o','Color', PavShuff,'linewidth',1);
  173. %plot(xaxis,DSSigAlcohol-0.51,'*','Color', 'k');
  174. patch([0 0.3 0.3 0],[0 0 1 1],[0.5 0.5 0.5],'EdgeColor','none');alpha(0.5);
  175. patch([xaxis,xaxis(end:-1:1)],[upSEMDS,downSEMDS(end:-1:1)],DSAlcohol,'EdgeColor','none');alpha(0.5);
  176. patch([xaxis,xaxis(end:-1:1)],[upSEMDSShuff,downSEMDSShuff(end:-1:1)],DSShuff,'EdgeColor','none');alpha(0.5);
  177. patch([xaxis,xaxis(end:-1:1)],[upSEMPav,downSEMPav(end:-1:1)],PavAlcohol,'EdgeColor','none');alpha(0.5);
  178. patch([xaxis,xaxis(end:-1:1)],[upSEMPavShuff,downSEMPavShuff(end:-1:1)],PavShuff,'EdgeColor','none');alpha(0.5);
  179. %this adds all 4 plots
  180. % plot(xaxis,AvgAccDSSucrose(1:13),'Color', DS,'linewidth',1);
  181. % plot(xaxis,AvgAccDSShuffSucrose(1:13),'Color', DSShuff,'linewidth',1);
  182. % patch([xaxis,xaxis(end:-1:1)],[upSEMDS1,downSEMDS1(end:-1:1)],DS,'EdgeColor','none');alpha(0.5);
  183. % patch([xaxis,xaxis(end:-1:1)],[upSEMDSShuff1,downSEMDSShuff1(end:-1:1)],DSShuff,'EdgeColor','none');alpha(0.5);
  184. % plot(xaxis,AvgAccPavSucrose(1:13),'Color', Pav,'linewidth',1);
  185. % plot(xaxis,AvgAccPavShuffSucrose(1:13),'Color', PavShuff,'linewidth',1);
  186. % patch([xaxis,xaxis(end:-1:1)],[upSEMPav1,downSEMPav1(end:-1:1)],Pav,'EdgeColor','none');alpha(0.5);
  187. % patch([xaxis,xaxis(end:-1:1)],[upSEMPavShuff1,downSEMPavShuff1(end:-1:1)],PavShuff,'EdgeColor','none');alpha(0.5);
  188. xlabel('Seconds post cue');
  189. legend('Suc(alc) DS','Suc(alc) CS+','Shuffled','Location','northeast');
  190. %title('Alcohol DS single unit decoding accuracy');
  191. axis([-.75 3.15 0.45 0.7]);
  192. ylabel('Single Unit Decoding Accuracy');
  193. %plotting cdf plots for DS at time of max predictive power
  194. subplot(2,2,2);
  195. DSbin=4;
  196. [cdfDS,xDS] = ecdf(UnitMdlAccDSAlcohol(selection3,DSbin));
  197. [cdfPav,xPav] = ecdf(UnitMdlAccPavAlcohol(selection4,DSbin));
  198. [cdfDSsuc,xDSsuc] = ecdf(UnitMdlAccDSSucrose(selection1,DSbin));
  199. [cdfPavsuc,xPavsuc] = ecdf(UnitMdlAccPavSucrose(selection2,DSbin));
  200. %subplot(4,3,[3 6]);
  201. hold on;
  202. plot(xDSsuc,cdfDSsuc,'Color',DS,'linewidth',1);
  203. plot(xPavsuc,cdfPavsuc,'Color',Pav,'linewidth',1);
  204. plot(xDS,cdfDS,'Color',DSAlcohol,'linewidth',1);
  205. plot(xPav,cdfPav,'Color',PavAlcohol,'linewidth',1);
  206. plot([.5 .5], [0 1],'LineStyle',':','Color','k');
  207. plot([AvgAccDSSucrose(1,4) AvgAccDSSucrose(1,4)], [0 1],'Color',DS,'linewidth',1);
  208. plot([AvgAccDSAlcohol(1,4) AvgAccDSAlcohol(1,4)], [0 1],'Color',DSAlcohol,'linewidth',1);
  209. plot([AvgAccPavSucrose(1,4) AvgAccPavSucrose(1,4)], [0 1],'Color',Pav,'linewidth',1);
  210. plot([AvgAccPavAlcohol(1,4) AvgAccPavAlcohol(1,4)], [0 1],'Color',PavAlcohol,'linewidth',1);
  211. axis([0.25 1 0 1]);
  212. title(['Cumulative Distribution 0 to .3s']);
  213. xlabel('Decoding Accuracy')
  214. ylabel('Proportion of Population')
  215. legend('Sucrose DS','Sucrose CS+','Suc(alc) DS','Suc(alc) CS+','Location','best');
  216. %Plotting ensemble decoding
  217. clear all;
  218. DS=[0 0.4470 0.7410];
  219. Pav=[0.8500 0.3250 0.0980];
  220. DSAlcohol=[51/255 160/255 44/255];%[0.4940 0.1840 0.5560];
  221. PavAlcohol=[180/255 41/255 230/255];%[0.9290 0.6940 0.1250];
  222. NumNeurons=[1 5 10 25 50 100];
  223. load('PoolMdlAccDSSucrose.mat','PoolMdlAccDSSucrose')
  224. load('PoolMdlAccDSSucroseShuff.mat','PoolMdlAccDSSucroseShuff')
  225. load('PoolMdlAccPavSucrose.mat','PoolMdlAccPavSucrose')
  226. load('PoolMdlAccPavSucroseShuff.mat','PoolMdlAccPavSucroseShuff')
  227. load('PoolMdlAccDSAlcohol.mat','PoolMdlAccDSAlcohol')
  228. load('PoolMdlAccDSAlcoholShuff.mat','PoolMdlAccDSAlcoholShuff')
  229. load('PoolMdlAccPavAlcohol.mat','PoolMdlAccPavAlcohol')
  230. load('PoolMdlAccPavAlcoholShuff.mat','PoolMdlAccPavAlcoholShuff')
  231. for i=1:6
  232. AvgAccDSSucrose(i)=nanmean(PoolMdlAccDSSucrose{i,1}); %average accuracy
  233. SEMAccDSSucrose(i)=nanste(PoolMdlAccDSSucrose{i,1},1); %SEM
  234. AvgAccPavSucrose(i)=nanmean(PoolMdlAccPavSucrose{i,1}); %average accuracy
  235. SEMAccPavSucrose(i)=nanste(PoolMdlAccPavSucrose{i,1},1); %SEM
  236. AvgAccDSAlcohol(i)=nanmean(PoolMdlAccDSAlcohol{i,1}); %average accuracy
  237. SEMAccDSAlcohol(i)=nanste(PoolMdlAccDSAlcohol{i,1},1); %SEM
  238. AvgAccPavAlcohol(i)=nanmean(PoolMdlAccPavAlcohol{i,1}); %average accuracy
  239. SEMAccPavAlcohol(i)=nanste(PoolMdlAccPavAlcohol{i,1},1); %SEM
  240. AvgAccDSSucroseShuff(i)=nanmean(PoolMdlAccDSSucroseShuff{i,1}); %average accuracy
  241. SEMAccDSSucroseShuff(i)=nanste(PoolMdlAccDSSucroseShuff{i,1},1); %SEM
  242. AvgAccPavSucroseShuff(i)=nanmean(PoolMdlAccPavSucroseShuff{i,1}); %average accuracy
  243. SEMAccPavSucroseShuff(i)=nanste(PoolMdlAccPavSucroseShuff{i,1},1); %SEM
  244. AvgAccDSAlcoholShuff(i)=nanmean(PoolMdlAccDSAlcoholShuff{i,1}); %average accuracy
  245. SEMAccDSAlcoholShuff(i)=nanste(PoolMdlAccDSAlcoholShuff{i,1},1); %SEM
  246. AvgAccPavAlcoholShuff(i)=nanmean(PoolMdlAccPavAlcoholShuff{i,1}); %average accuracy
  247. SEMAccPavAlcoholShuff(i)=nanste(PoolMdlAccPavAlcoholShuff{i,1},1); %SEM
  248. end
  249. subplot(2,2,3); %ensemble decoding results
  250. errorbar(NumNeurons, AvgAccDSSucrose,SEMAccDSSucrose,'Color',DS,'linewidth',1);
  251. hold on;
  252. errorbar(NumNeurons, AvgAccPavSucrose,SEMAccPavSucrose, 'Color',Pav,'linewidth',1);
  253. errorbar(NumNeurons, AvgAccDSAlcohol,SEMAccDSAlcohol, 'Color',DSAlcohol,'linewidth',1);
  254. errorbar(NumNeurons, AvgAccPavAlcohol,SEMAccPavAlcohol, 'Color',PavAlcohol,'linewidth',1);
  255. % errorbar(NumNeurons, AvgAccDSSucroseShuff,SEMAccDSSucroseShuff, 'Color','k');
  256. % errorbar(NumNeurons, AvgAccPavSucroseShuff,SEMAccPavSucroseShuff, 'Color','k');
  257. % errorbar(NumNeurons, AvgAccDSAlcoholShuff,SEMAccDSAlcoholShuff, 'Color','k');
  258. % errorbar(NumNeurons, AvgAccPavAlcoholShuff,SEMAccPavAlcoholShuff, 'Color','k');
  259. legend('Sucrose DS','Sucrose CS+','Suc(alc) DS','Suc(alc) CS+','Location','best');
  260. plot([-5 105], [.5 .5],'LineStyle',':','Color','k');
  261. xlabel('Neurons used');
  262. ylabel('Mean Accuracy (+/- SEM)');
  263. xticks([1 5 10 25 50 100])
  264. %xticklabels({'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'})
  265. axis([-5 105 0.4 1]);
  266. %make matrices with bins at all levels
  267. A=[];
  268. B=[];
  269. C=[];
  270. D=[];
  271. A1=[];
  272. B1=[];
  273. C1=[];
  274. D1=[];
  275. for v=1:length(PoolMdlAccDSSucrose)
  276. A=cat(1,A,PoolMdlAccDSSucrose{v,1});
  277. B=cat(1,B,PoolMdlAccPavSucrose{v,1});
  278. C=cat(1,C,PoolMdlAccDSAlcohol{v,1});
  279. D=cat(1,D,PoolMdlAccPavAlcohol{v,1});
  280. A1=cat(1,A1,PoolMdlAccDSSucroseShuff{v,1});
  281. B1=cat(1,B1,PoolMdlAccPavSucroseShuff{v,1});
  282. C1=cat(1,C1,PoolMdlAccDSAlcoholShuff{v,1});
  283. D1=cat(1,D1,PoolMdlAccPavAlcoholShuff{v,1});
  284. end
  285. subplot(2,2,4); %summary of accuracy
  286. errorbar(1,nanmean(A),nanste(A,1),'o','Color',DS,'linewidth',1);
  287. hold on;
  288. errorbar(2,nanmean(C),nanste(C,1),'o', 'Color',DSAlcohol,'linewidth',1);
  289. errorbar(3,nanmean(B),nanste(B,1),'o', 'Color',Pav,'linewidth',1);
  290. errorbar(4,nanmean(D),nanste(D,1),'o', 'Color',PavAlcohol,'linewidth',1);
  291. plot([-5 105], [.5 .5],'LineStyle',':','Color','k');
  292. plot([1 2], [0.93 0.93],'Color','k','linewidth',1);
  293. plot([3 4], [0.86 0.86],'Color','k','linewidth',1);
  294. plot(1.5,.95,'*','Color','k');
  295. plot(3.5,.88,'*','Color','k');
  296. axis([0.5 4.5 0.4 1]);
  297. set(gca,'xtick',[])
  298. ylabel('Mean Accuracy (+/- SEM)');
  299. %xlabel('DS/Suc DS/Suc(a) CS+/Suc CS+/Suc(a)');
  300. legend('Sucrose DS','Suc(alc) DS','Sucrose CS+','Suc(alc) CS+','Location','best');
  301. %% STATS
  302. %Plotting single All decoding
  303. bins = 1; %number of bins
  304. binint = 0.3; %spacing of bins
  305. binstart = 0; %start time of first bin relative to event
  306. Dura=[0 0.3]; %size of bin used for decoding:
  307. NumNeurons=[1 5 10 25 50 100]; %matrix of how many neurons to use on each iteration
  308. repetitions=20; %how many times to run the analysis
  309. %ANOVA for effect of ensemble size, task and reward on accuracy 0-.3 sec
  310. size=[];
  311. for i=1:length(NumNeurons)
  312. size=cat(1,size,i*ones(repetitions,1));
  313. end
  314. size2=cat(1,size,size,size,size);
  315. %shuffd=cat(1,zeros(length(A),1),zeros(length(B),1),ones(length(C),1),zeros(length(D),1));
  316. reward=cat(1,ones(length(A)+length(B),1),zeros(length(C)+length(D),1));
  317. task=cat(1,ones(length(A),1),zeros(length(B),1),ones(length(C),1),zeros(length(D),1));
  318. [~,AccAnova,AccStats]=anovan(cat(1,A,B,C,D),{reward,task,size2},'varnames',{'reward','task','ens size'},'model','full');
  319. %multcompare(AccStats,'Dimension',[1:3])
  320. rewardtask=cat(1,zeros(length(A),1),ones(length(B),1),2*ones(length(C),1),3*ones(length(D),1));
  321. [~,AccAnova,AccStats]=anovan(cat(1,A,B,C,D),{rewardtask,size2},'varnames',{'reward and task','ens size'},'model','full');
  322. size=[];
  323. for i=1:length(NumNeurons)
  324. size=cat(1,size,i*ones(repetitions,1));
  325. end
  326. size1=cat(1,size,size,size,size,size,size,size,size);
  327. shuffd=cat(1,zeros(length(A)+length(B)+length(C)+length(D),1),ones(length(A)+length(B)+length(C)+length(D),1));
  328. reward=cat(1,ones(length(A)+length(B),1),zeros(length(C)+length(D),1),ones(length(A)+length(B),1),zeros(length(C)+length(D),1));
  329. task=cat(1,ones(length(A),1),zeros(length(B),1),ones(length(C),1),zeros(length(D),1),ones(length(A),1),zeros(length(B),1),ones(length(C),1),zeros(length(D),1));
  330. [~,AccAnova,AccStats]=anovan(cat(1,A,B,C,D,A1,B1,C1,D1),{reward,task,size1,shuffd},'varnames',{'reward','task','ens size','shuffled vs real'},'model','full');
  331. rewardtask=cat(1,zeros(length(A),1),ones(length(B),1),2*ones(length(C),1),3*ones(length(D),1));
  332. [~,AccAnova,AccStats]=anovan(cat(1,A,B,C,D),{rewardtask,size2},'varnames',{'reward and task','ens size'},'model','full');
  333. %without shuff vs true
  334. % size3=cat(1,size,size);
  335. % region3=cat(1,ones(length(A),1),zeros(length(C),1));
  336. % [~,AccAnovaNoShuff,~]=anovan(cat(1,A,C),{region3,size3},'varnames',{'region','ens size'},'display','off','model','full');
  337. %% Sinlge Unit Stats
  338. if ~exist('RPPSall'),load('RPPSall.mat'); end
  339. if ~exist('RPSall'),load('RPSall.mat'); end
  340. load('UnitMdlDSAlcohol.mat')
  341. load('UnitMdlDSShuffAlcohol.mat')
  342. load('UnitMdlPavAlcohol.mat')
  343. load('UnitMdlPavShuffAlcohol.mat')
  344. if ~exist('RvppasALL'),load('RvppasALL.mat'); end
  345. if ~exist('RvpppasALL'),load('RvpppasALL.mat'); end
  346. sucrose=[1 0.6 0.1];
  347. maltodextrin=[.9 0.3 .9];
  348. water=[0.00 0.75 0.75];
  349. total=[0.3 0.1 0.8];
  350. DS=[0 0.4470 0.7410];
  351. Pav=[0.8500 0.3250 0.0980];
  352. DSAlcohol=[0.4940 0.1840 0.5560];
  353. PavAlcohol=[0.9290 0.6940 0.1250];
  354. DSShuff=[0 0 0];
  355. PavShuff=[0 0 0];
  356. xaxis=linspace(-0.75,3.15,13);
  357. selection1=RPPSall.Structure==10 & RPPSall.CSPlusRatio>=.5 & (RPPSall.CSPlusRatio./(RPPSall.CSPlusRatio+RPPSall.CSMinusRatio))>=.7;
  358. selection2=RPSall.Structure==10 & RPSall.CSPlusRatio>=.5 & (RPSall.CSPlusRatio./(RPSall.CSPlusRatio+RPSall.CSMinusRatio))>=.7;
  359. selection3=RvpppasALL.Structure==10 & RvpppasALL.CSPlusRatio>=.5 & (RvpppasALL.CSPlusRatio./(RvpppasALL.CSPlusRatio+RvpppasALL.CSMinusRatio))>=.7;
  360. selection4=RvppasALL.Structure==10 & RvppasALL.CSPlusRatio>=.5 & (RvppasALL.CSPlusRatio./(RvppasALL.CSPlusRatio+RvppasALL.CSMinusRatio))>=.7;
  361. %LME for the 2 alc exposed
  362. task=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccDSAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1));
  363. shuffd=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),zeros(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccPavAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1));
  364. rat=cat(1,RvpppasALL.Rat,RvpppasALL.Rat,RvppasALL.Rat,RvppasALL.Rat);
  365. tbl=table(cat(1,UnitMdlAccDSAlcohol(:,4),UnitMdlAccDSShuffAlcohol(:,4),UnitMdlAccPavAlcohol(:,4),UnitMdlAccPavShuffAlcohol(:,4)),task,shuffd,rat,'variablenames',{'Accuracy','Task','Shuffled','Subject'});
  366. lme=fitlme(tbl,'Accuracy~Task+Shuffled+(Task:Shuffled)+(1|Subject)');%+(1|Subject:Task:Shuffled)');
  367. %all 4
  368. load('UnitMdlDSSucrose.mat')
  369. load('UnitMdlDSShuffSucrose.mat')
  370. load('UnitMdlPavSucrose.mat')
  371. load('UnitMdlPavShuffSucrose.mat')
  372. if ~exist('RPPSall'),load('RPPSall.mat'); end
  373. if ~exist('RPSall'),load('RPSall.mat'); end
  374. task=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccDSAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1),ones(length(UnitMdlAccDSSucrose(:,4)),1),ones(length(UnitMdlAccDSSucrose(:,4)),1),zeros(length(UnitMdlAccPavSucrose(:,4)),1),zeros(length(UnitMdlAccPavSucrose(:,4)),1));
  375. shuffd=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),zeros(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccPavAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1),ones(length(UnitMdlAccDSSucrose(:,4)),1),zeros(length(UnitMdlAccDSSucrose(:,4)),1),ones(length(UnitMdlAccPavSucrose(:,4)),1),zeros(length(UnitMdlAccPavSucrose(:,4)),1));
  376. rat=cat(1,RvpppasALL.Rat,RvpppasALL.Rat,RvppasALL.Rat,RvppasALL.Rat,RPPSall.Rat,RPPSall.Rat,RPSall.Rat,RPSall.Rat);
  377. exposure=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccDSAlcohol(:,4)),1),ones(length(UnitMdlAccPavAlcohol(:,4)),1),ones(length(UnitMdlAccPavAlcohol(:,4)),1),zeros(length(UnitMdlAccDSSucrose(:,4)),1),zeros(length(UnitMdlAccDSSucrose(:,4)),1),zeros(length(UnitMdlAccPavSucrose(:,4)),1),zeros(length(UnitMdlAccPavSucrose(:,4)),1));
  378. tbl=table(cat(1,UnitMdlAccDSAlcohol(:,4),UnitMdlAccDSShuffAlcohol(:,4),UnitMdlAccPavAlcohol(:,4),UnitMdlAccPavShuffAlcohol(:,4),UnitMdlAccDSSucrose(:,4),UnitMdlAccDSShuffSucrose(:,4),UnitMdlAccPavSucrose(:,4),UnitMdlAccPavShuffSucrose(:,4)),task,shuffd,rat,exposure,'variablenames',{'Accuracy','Task','Shuffled','Subject','Exposure'});
  379. lme=fitlme(tbl,'Accuracy~Task+Exposure+Task:Exposure+(1|Subject)');%+(1|Subject:Task:Exposure)');
  380. % [~,AccAnova,AccStats]=anovan(cat(1,UnitMdlAccDSAlcohol(:,4),UnitMdlAccDSShuffAlcohol(:,4),UnitMdlAccPavAlcohol(:,4),UnitMdlAccPavShuffAlcohol(:,4)),{task,shuffd,rat},'varnames',{'task','shuff vs true','subject'},'random',[3],'nested',[0 0 0;0 0 0;1 0 0],'model','full');
  381. % %no subject
  382. % [~,AccAnova,AccStats]=anovan(cat(1,UnitMdlAccDSAlcohol(:,4),UnitMdlAccDSShuffAlcohol(:,4),UnitMdlAccPavAlcohol(:,4),UnitMdlAccPavShuffAlcohol(:,4)),{task,shuffd},'varnames',{'task','shuff vs true',},'model','full');
  383. % %no shuff vs true
  384. % fitlme
  385. % task=cat(1,ones(length(UnitMdlAccDSAlcohol(:,4)),1),zeros(length(UnitMdlAccPavAlcohol(:,4)),1));
  386. % rat=cat(1,RvpppasALL.Rat,RvppasALL.Rat);
  387. % [~,AccAnova,AccStats]=anovan(cat(1,UnitMdlAccDSAlcohol(:,4),UnitMdlAccPavAlcohol(:,4)),{task,rat},'varnames',{'task','subject'},'random',[2],'nested',[0 0;1 0],'model','full');