dprime_simple.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. % Karin (2024). dprime_simple.m (https://www.mathworks.com/matlabcentral/fileexchange/47711-dprime_simple-m), MATLAB Central File Exchange.
  2. function [dp,c] = dprime_simple(h,fA)
  3. % DPRIME_SIMPLE d' calculation given hit/false alarm rates
  4. % dp = dprime_simple(h,fA) returns the d' value dp
  5. % for the hit rate h and false alarm rate fA
  6. % Karin Cox 8/31/14
  7. % updates:
  8. % 8/31/14 added criterion output c, input arg checks
  9. %
  10. % inputs:
  11. % h = hit rate, as float (0 < h < 1)
  12. % fA = false alarm rate, as float (0 < fA < 1)
  13. %
  14. % outputs:
  15. % dp = d'
  16. % c = criterion c (negative values --> bias towards yes responses)
  17. %
  18. % Example:
  19. % [dp,c] = dprime_simple(0.9,0.05)
  20. % dp =
  21. % 2.9264
  22. % c =
  23. % 0.1817
  24. %
  25. % formulas: Stanislaw, H., & Todorov, N. (1999). Calculation of signal
  26. % detection theory measures. Behavior research methods, instruments, &
  27. % computers, 31(1), 137-149.
  28. % check n args
  29. narginchk(2,2);
  30. % check for values out of bounds, also issue errors or warnings if =1 or 0
  31. if or(or(h>1,h<0),or(fA>1,fA<0))
  32. error('input arguments must fall in the 0 to 1 range')
  33. % standard d' formula returns NaN or Inf results for 0 or 1 inputs,
  34. % corrections may be required (see article above for suggestions)
  35. elseif or(or(h==1,h==0),or(fA==1,fA==0))
  36. warning('This function will not return finite values when h or fA = 0 or 1.')
  37. end
  38. % d prime = z(h)-z(fA)
  39. dp = norminv(h)-norminv(fA);
  40. % c = -0.5*[z(h)+z(fA)]
  41. c = -0.5*(norminv(h)+ norminv(fA));
  42. end