/MatlabCode/branches/Greg's Branch/Analysis/DetectionTask/boot2ci.m

http://horwitzlab.googlecode.com/ · MATLAB · 60 lines · 40 code · 8 blank · 12 comment · 4 complexity · 4936d7309fe1ebeb60c3ef3c7709a491 MD5 · raw file

  1. function ci = boot2ci(monk, cell, expt, nStraps, confInterval)
  2. % This funtion will accept neurometric and psychometric data and create
  3. % confidence intervals for the threshold ratio(s) via nonparametric
  4. % bootstrap. The first three input arguments are created by DTmocsUnpack.m.
  5. % "confInterval" should be a percentage between 0 and 1;
  6. %
  7. % CAH 11/11/09
  8. %create distributions of thresholds for all color/sfs combos. Do this for
  9. %both the psychometric and neurometric functions.
  10. nStraps = ceil(sqrt(nStraps));%b/c I'm going to use all pairwise comparisons;
  11. pairs = fullfact([nStraps, nStraps]);
  12. alphaLevel = 1-confInterval;
  13. nSfs = length(expt.sfs);
  14. nColors = size(expt.standColors,1);
  15. for a = 1:nColors;
  16. for b = 1:nSfs;
  17. if isnan(cell.alpha(a,b)) %bail if the neurometric function is flat
  18. ci.up(a,b) = nan;
  19. ci.lo(a,b) = nan;
  20. else
  21. psyErrs = btstrapPsyFun(monk.alpha(a,b), monk.beta(a,b), monk.gamma(a,b),...
  22. expt.norms{a,b}, monk.nTrials{a,b}, nStraps, 100);
  23. neuroErrs = btstrapPsyFun(cell.alpha(a,b), cell.beta(a,b), cell.gamma(a,b),...
  24. expt.norms{a,b}, cell.nTrialsIn{a,b}, nStraps, 100);
  25. btTRs = neuroErrs.alpha(pairs(:,1)) ./ psyErrs.alpha(pairs(:,2)); %all pairwise comparisons
  26. %filter out the neurons that give rise to super high btstrp
  27. %estimates (i.e. 10^308).... which cause inf TRs.
  28. if any(isinf(btTRs))
  29. ci.up(a,b) = nan;
  30. ci.lo(a,b) = nan;
  31. else
  32. %determine the bias
  33. TRest = cell.alpha(a,b) ./ monk.alpha(a,b);
  34. totalStraps = nStraps^2;
  35. bias = sum(btTRs < TRest)./totalStraps; %proportion less than the estimate...
  36. bias = norminv(bias, 0, 1); %inv of normcdf evaluated at proportion < estimate
  37. %determine the acceleration
  38. accel = 0; %I don't know how to estimate this, so for now I'm setting it to zero.
  39. a_low = getAlphaLev(bias, accel, alphaLevel./2) .* 100; %put in % b/w 1 and 100 for prctile.m
  40. a_high = getAlphaLev(bias, accel, 1-(alphaLevel./2)) .* 100;
  41. ci.up(a,b) = prctile(btTRs, a_high);
  42. ci.lo(a,b) = prctile(btTRs, a_low);
  43. end
  44. end
  45. end %sfs
  46. end %colors
  47. end% function
  48. function BCalpha = getAlphaLev(bias, accel, alphaLevel)
  49. z_alpha = norminv(alphaLevel, 0, 1);
  50. phi = bias + ((bias + z_alpha) ./ (1 - accel.*(bias + z_alpha)));
  51. BCalpha = normcdf(phi, 0, 1);
  52. end