auc.m 815 B

123456789101112131415161718192021222324252627282930313233
  1. function [y]=auc(stim,nostim)
  2. % computes the area under the curve.
  3. % [y]=auc(stim,nostim)
  4. % stim is an a x n matrix
  5. % nostim is an b x n matrix
  6. % y is a 1 x n matrix
  7. %
  8. % y(x) is the auc of the non-nan values of stim(:,x) and nostim(:,x)
  9. if isvector(stim)
  10. if all(isnan(stim)) || all(isnan(nostim))
  11. y=nan;
  12. else
  13. stim=stim(~isnan(stim));
  14. nostim=nostim(~isnan(nostim));
  15. labels=[ones(numel(stim),1); zeros(numel(nostim),1)];
  16. values=[stim(:);nostim(:)];
  17. % Count observations by class
  18. nTarget = numel(stim);
  19. nBackground = numel(nostim);
  20. % Rank data
  21. R = tiedrank(values); % 'tiedrank' from Statistics Toolbox
  22. % Calculate AUC
  23. y = (sum(R(labels == 1)) - (nTarget^2 + nTarget)/2) / (nTarget * nBackground);
  24. end
  25. else
  26. for cx=1:size(stim,2)
  27. y(cx)=stats.auc(stim(:,cx), nostim(:,cx));
  28. end
  29. end