plotBootstrapCoeffOfVariationTest.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function plotBootstrapCoeffOfVariationTest(widthCell, figDir, threshold, rSquareThreshold, varargin)
  2. if nargin > 4
  3. xLabels = varargin{1};
  4. nameSuffix = varargin{2};
  5. else
  6. xLabels = {'X OFF', 'Y OFF', 'X ON', 'Y ON'};
  7. nameSuffix = '';
  8. end
  9. qualityMeasure = 'responseQuality';
  10. [isSignificant, cvArray, ~, ...
  11. centralDecisionLineCV, ldlCV, udlCV] = bootstrapCoeffOfVariation(widthCell);
  12. error = (udlCV - ldlCV) / 2;
  13. colors = getONOFFXYColors;
  14. if numel(widthCell) > 4
  15. colors = repmat(colors, ceil(numel(widthCell) / 4), 1);
  16. end
  17. % Fill space.
  18. hFig = createPrintFig(5 * [1 0.7]);
  19. dummyVec = ones(1, numel(widthCell) + 2);
  20. hAx = gca;
  21. [hLine, hPatch] = plotErrorPatch(hAx, 0: numel(widthCell) + 1, ...
  22. centralDecisionLineCV * dummyVec, ...
  23. error * dummyVec, ...
  24. [1 1 1] * 0.2, [1 1 1] * 0.85);
  25. hLine.LineWidth = 2;
  26. hPatch.FaceAlpha = 1;
  27. for iGroup = 1: numel(widthCell)
  28. scatter(iGroup, cvArray(iGroup), 50, colors(iGroup, :), ...
  29. 'MarkerFaceColor', colors(iGroup, :), ...
  30. 'MarkerFaceAlpha', isSignificant(iGroup), ...
  31. 'LineWidth', 2);
  32. end
  33. ylabel('$$CV=\frac{s}{\bar{x}}$$', 'Interpreter', 'latex', 'Rotation', 90)
  34. hAx.XTick = 1: numel(widthCell);
  35. hAx.XTickLabel = xLabels;
  36. arrayfun(@prettifyAxes, [hAx]);
  37. arrayfun(@offsetAxes, hAx);
  38. setFontForThesis([hAx], hFig)
  39. figFileName = ['fhwmCV-' nameSuffix qualityMeasure '-' num2str(threshold) ...
  40. '-rSquare-' num2str(rSquareThreshold)];
  41. % set(gcf,'renderer','painters')
  42. % set(gcf, 'PaperPositionMode', 'auto');
  43. print(hFig, [figDir figFileName '.pdf'], '-dpdf')
  44. print(hFig, [figDir figFileName '.png'], '-dpng', '-r300')
  45. end
  46. function [isSignificant, cvArray, varargout] = bootstrapCoeffOfVariation(widthCell)
  47. %% Bootstrap analysis of CV.
  48. cvArray = cellfun(@calcCoeffOfVariation, widthCell);
  49. bootsCV = cellfun(@(x) bootstrp(5000, @calcCoeffOfVariation, x), widthCell, 'uni', 0);
  50. bootsCVArray = cell2mat(bootsCV);
  51. meanCVPerBoot = mean(bootsCVArray, 2);
  52. centralDecisionLineCV = mean(meanCVPerBoot);
  53. standardErrorCV = sqrt(mean((meanCVPerBoot - centralDecisionLineCV) .^ 2));
  54. alpha = 0.05;
  55. lowerDecisionLineCV = centralDecisionLineCV - norminv(1 - alpha / 2) * standardErrorCV;
  56. upperDecisionLineCV = centralDecisionLineCV + norminv(1 - alpha / 2) * standardErrorCV;
  57. error = norminv(1 - alpha / 2) * standardErrorCV;
  58. isSignificant = cvArray < lowerDecisionLineCV | cvArray > upperDecisionLineCV;
  59. varargout{1} = bootsCVArray;
  60. varargout{2} = centralDecisionLineCV;
  61. varargout{3} = lowerDecisionLineCV;
  62. varargout{4} = upperDecisionLineCV;
  63. end