plot_residuals_comparison_scatter.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. %% PLOTTING SCATTERS AND DISTRIBUTIONS COMPARISONS
  2. function plot_residuals_comparison_scatter(Zstruct_trwise,save_folder_path,filename_suffix)
  3. addpath(genpath('../../../../my-tools'));
  4. if nargin<6
  5. filename_suffix='';
  6. end
  7. Z_b1_LL_trwise=Zstruct_trwise.Z_b1_LL_trwise;
  8. Z_b1_LR_trwise=Zstruct_trwise.Z_b1_LR_trwise;
  9. Z_b2_LL_trwise=Zstruct_trwise.Z_b2_LL_trwise;
  10. Z_b2_LR_trwise=Zstruct_trwise.Z_b2_LR_trwise;
  11. ZZ=squeeze(nanmean(Z_b1_LL_trwise,[1 3])); Z_b1_LL=[ZZ(:,1)' ZZ(:,2)'; ZZ(:,3)' ZZ(:,4)'];
  12. ZZ=squeeze(nanmean(Z_b1_LR_trwise,[1 3])); Z_b1_LR=[ZZ(:,1)' ZZ(:,2)'; ZZ(:,3)' ZZ(:,4)'];
  13. ZZ=squeeze(nanmean(Z_b2_LL_trwise,[1 3])); Z_b2_LL=[ZZ(:,1)' ZZ(:,2)'; ZZ(:,3)' ZZ(:,4)'];
  14. ZZ=squeeze(nanmean(Z_b2_LR_trwise,[1 3])); Z_b2_LR=[ZZ(:,1)' ZZ(:,2)'; ZZ(:,3)' ZZ(:,4)'];
  15. hf=fullfig([0 0 .5 1]);
  16. subplot(2,2,1); hold on; title('SV_L delay2 LookL');
  17. plotscatteredmedian(Z_b1_LL,'auto','right',[-1 1]*1.5e-3,...
  18. {'\beta_{1}>0,ch=L; \beta_{1}<0,ch=R','\beta_{1}<0,ch=L; \beta_{1}>0,ch=R'},'residuals');
  19. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.9),sprintf('md1: %.3i',nanmedian(Z_b1_LL(1,:))));
  20. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.8),sprintf('md2: %.3i',nanmedian(Z_b1_LL(2,:))));
  21. %[~,p]=ttest(rmnans(Z_b1_LL(1,:))-rmnans(Z_b1_LL(2,:)),0,'tail','right');
  22. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.7),sprintf('t-test right p:%.3i%s',p,getpstars(p)));
  23. xlabel('preferred non-preferred');
  24. subplot(2,2,2); hold on; title('SV_L delay2 LookR');
  25. plotscatteredmedian(Z_b1_LR,'auto','right',[-1 1]*1.5e-3,...
  26. {'\beta_{1}>0,ch=L; \beta_{1}<0,ch=R','\beta_{1}<0,ch=L; \beta_{1}>0,ch=R'},'residuals');
  27. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.9),sprintf('md1: %.3i',nanmedian(Z_b1_LR(1,:))));
  28. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.8),sprintf('md2: %.3i',nanmedian(Z_b1_LR(2,:))));
  29. %[~,p]=ttest(rmnans(Z_b1_LR(1,:))-rmnans(Z_b1_LR(2,:)),0,'tail','right');
  30. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.7),sprintf('t-test right p:%.3i%s',p,getpstars(p)));
  31. xlabel('preferred non-preferred');
  32. subplot(2,2,3); hold on; title('SV_R delay2 LookL');
  33. plotscatteredmedian(Z_b2_LL,'auto','left',[-1 1]*1.5e-3,...
  34. {'\beta_{2}>0,ch=L; \beta_{2}<0,ch=R','\beta_{2}<0,ch=L; \beta_{2}>0,ch=R'},'residuals');
  35. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.9),sprintf('md1: %.3i',nanmedian(Z_b2_LL(1,:))));
  36. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.8),sprintf('md2: %.3i',nanmedian(Z_b2_LL(2,:))));
  37. %[~,p]=ttest(rmnans(Z_b2_LL(1,:))-rmnans(Z_b2_LL(2,:)),0,'tail','left');
  38. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.7),sprintf('t-test left p:%.3i%s',p,getpstars(p)));
  39. xlabel('non-preferred preferred');
  40. subplot(2,2,4); hold on; title('SV_R delay2 LookR');
  41. plotscatteredmedian(Z_b2_LR,'auto','left',[-1 1]*1.5e-3,...
  42. {'\beta_{2}>0,ch=L; \beta_{2}<0,ch=R','\beta_{2}<0,ch=L; \beta_{2}>0,ch=R'},'residuals');
  43. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.9),sprintf('md1: %.3i',nanmedian(Z_b2_LR(1,:))));
  44. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.8),sprintf('md2: %.3i',nanmedian(Z_b2_LR(2,:))));
  45. %[~,p]=ttest(rmnans(Z_b2_LR(1,:))-rmnans(Z_b2_LR(2,:)),0,'tail','left');
  46. %text(min(get(gca,'XLim'))*.9,max(get(gca,'YLim')*.7),sprintf('t-test left p:%.3i%s',p,getpstars(p)));
  47. xlabel('non-preferred preferred');
  48. saveas(hf,[save_folder_path 'zetas_tr_time_avg_scatter_comparisons' filename_suffix '.png']);
  49. saveas(hf,[save_folder_path 'zetas_tr_time_avg_scatter_comparisons' filename_suffix '.svg']);
  50. saveas(hf,[save_folder_path 'zetas_tr_time_avg_scatter_comparisons' filename_suffix '.fig']);
  51. %print(hf,[save_folder_path 'zetas_tr_time_avg_scatter_comparisons' filename_suffix '.pdf'],'-dpdf','-fillpage');
  52. zbins=-1.6e-3:.25e-4:1.6e-3; ylims=[0 60];
  53. hf=fullfig([.5 0 .5 .5]);
  54. subplot(2,2,1);
  55. histogram(Z_b1_LL(1,:),zbins,'edgecolor','none'); hold on; ylim(ylims);
  56. histogram(Z_b1_LL(2,:),zbins,'edgecolor','none'); plotvline(0,'k-'); box off; gch=gca;
  57. plot(nanmedian(Z_b1_LL(1,:)-Z_b1_LL(2,:)),max(gch.YLim).*.85,'rv');
  58. pv=signrank(Z_b1_LL(1,:),Z_b1_LL(2,:),'tail','right');
  59. text(0,max(gch.YLim).*.9,sprintf('diff pvalue: %.2i %s',pv,getpstars(pv)),'color','r');
  60. text(0,max(gch.YLim).*.95,sprintf('diff median: %.3i',nanmedian(Z_b1_LL(1,:)-Z_b1_LL(2,:))),'color','r');
  61. title('SV_L delay2 LookL'); legend('pref.','non-pref.','location','southeast','box','off'); ylabel('cell count');
  62. subplot(2,2,3);
  63. histogram(Z_b1_LR(1,:),zbins,'edgecolor','none'); hold on; ylim(ylims);
  64. histogram(Z_b1_LR(2,:),zbins,'edgecolor','none'); plotvline(0,'k-'); box off; gch=gca;
  65. plot(nanmedian(Z_b1_LR(1,:)-Z_b1_LR(2,:)),max(gch.YLim).*.85,'kv'); plotvline(0,'k-'); box off
  66. pv=signrank(Z_b1_LR(1,:),Z_b1_LR(2,:),'tail','right');
  67. text(0,max(gch.YLim).*.9,sprintf('diff pvalue: %.2i %s',pv,getpstars(pv)));
  68. text(0,max(gch.YLim).*.95,sprintf('diff median: %.3i',nanmedian(Z_b1_LR(1,:)-Z_b1_LR(2,:))));
  69. title('SV_L delay2 LookR'); legend('pref.','non-pref.','location','southeast','box','off'); xlabel('residual');
  70. subplot(2,2,2);
  71. histogram(Z_b2_LL(1,:),zbins,'edgecolor','none'); hold on; ylim(ylims);
  72. histogram(Z_b2_LL(2,:),zbins,'edgecolor','none'); plotvline(0,'k-'); box off; gch=gca;
  73. plot(nanmedian(Z_b2_LL(1,:)-Z_b2_LL(2,:)),max(gch.YLim).*.85,'kv');
  74. pv=signrank(Z_b2_LL(1,:),Z_b2_LL(2,:),'tail','left');
  75. text(0,max(gch.YLim).*.9,sprintf('diff pvalue: %.2i %s',pv,getpstars(pv)),'color','k');
  76. text(0,max(gch.YLim).*.95,sprintf('diff median: %.3i',nanmedian(Z_b2_LL(1,:)-Z_b2_LL(2,:))));
  77. title('SV_R delay2 LookL'); legend('non-pref.','pref.','location','southeast','box','off'); ylabel('cell count');
  78. subplot(2,2,4);
  79. histogram(Z_b2_LR(1,:),zbins,'edgecolor','none'); hold on; ylim(ylims);
  80. histogram(Z_b2_LR(2,:),zbins,'edgecolor','none'); plotvline(0,'k-'); box off; gch=gca;
  81. plot(nanmedian(Z_b2_LR(1,:)-Z_b2_LR(2,:)),max(gch.YLim).*.85,'rv'); plotvline(0,'k-'); box off
  82. pv=signrank(Z_b2_LR(1,:),Z_b2_LR(2,:),'tail','left');
  83. text(0,max(gch.YLim).*.9,sprintf('diff pvalue: %.2i %s',pv,getpstars(pv)),'color','r');
  84. text(0,max(gch.YLim).*.95,sprintf('diff median: %.3i',nanmedian(Z_b2_LR(1,:)-Z_b2_LR(2,:))),'color','r');
  85. title('SV_R delay2 LookR'); legend('non-pref.','pref.','location','southeast','box','off'); xlabel('residual');
  86. saveas(hf,[save_folder_path 'zetas_tr_time_avg_distrib_comparisons' filename_suffix '.png']);
  87. saveas(hf,[save_folder_path 'zetas_tr_time_avg_distrib_comparisons' filename_suffix '.svg']);
  88. saveas(hf,[save_folder_path 'zetas_tr_time_avg_distrib_comparisons' filename_suffix '.fig']);
  89. %print(hf,[save_folder_path 'zetas_tr_time_avg_distrib_comparisons' filename_suffix '.pdf'],'-dpdf','-fillpage');
  90. end