Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

psychoplot4.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. function varargout=psychoplot4(x_vals, varargin)
  2. % [stats]=psychoplot4(x_vals, went_right)
  3. % [stats]=psychoplot4(x_vals, hits, sides)
  4. %
  5. % Fits a 4 parameter sigmoid to psychophysical data
  6. %
  7. % x_vals the experimenter controlled value on each trial.
  8. % went_right a vector of [0,1]'s the same length as x_vals describing
  9. % the response on that trials
  10. % OR
  11. %
  12. % hits a vector of the correct/incorrect history as [0,1,nan]'s.
  13. % Nans are exluded automatically
  14. % sides a vector of [-1, 1]'s or ['LR']'s that say what the subject
  15. % should have done on that trial
  16. %
  17. % The sigmoid is of the form
  18. % y=y0+a./(1+ exp(-(x-x0)./b));
  19. %
  20. % y0=beta(1) sets the lower bound
  21. % a=beta(2) a+y0 is the upper bound
  22. % x0=beta(3) is the bias
  23. % b=beta(4) is the slope
  24. if nargin==2
  25. went_right=varargin{1};
  26. elseif nargin==3
  27. hits=varargin{1};
  28. sides=varargin{2};
  29. gd=~isnan(hits);
  30. hits=hits(gd);
  31. sides=sides(gd);
  32. x_vals=x_vals(gd);
  33. if isnumeric(sides(1))
  34. went_right=(hits==1 & sides==1) | (hits==0 & sides==-1);
  35. else
  36. sides=lower(sides);
  37. went_right=(hits==1 & sides=='r') | (hits==0 & sides=='l');
  38. end
  39. end
  40. [beta,resid,jacob,sigma,mse] = nlinfit(x_vals,went_right,@sig4,[0.1 .8 nanmean(x_vals) 10]);
  41. x_s=linspace(min(x_vals), max(x_vals), 100);
  42. [y_s,delta] = nlpredci(@sig4,x_s,beta,resid,'covar',sigma);
  43. betaci = nlparci(beta,resid,'covar',sigma);
  44. S.beta=beta;
  45. S.betaci=betaci;
  46. S.resid=resid;
  47. S.mse=mse;
  48. S.sigma=sigma;
  49. S.ypred=y_s;
  50. S.y95ci=delta;
  51. fig_h=figure;
  52. trial_types = unique(x_vals);
  53. if numel(trial_types) > numel(went_right)*0.1,
  54. sortedM=sortrows([x_vals(:) went_right(:)]);
  55. rawD=jconv(normpdf(-10:10, 0, 2), sortedM(:,2)');
  56. ax=plot(sortedM(:,1), rawD,'o');
  57. else
  58. meanD=zeros(size(trial_types));
  59. seD=meanD;
  60. for tx = 1:numel(trial_types),
  61. meanD(tx) = mean(went_right(x_vals == trial_types(tx)));
  62. %seD(tx) = stderr(went_right(x_vals == trial_types(tx)));
  63. % it doesn't make sense to take the stderr of a bernoulli variable.
  64. % instead , just make the error bars 1/sqrt(n);
  65. seD(tx) = sqrt(meanD(tx)*(1-meanD(tx))/sum(x_vals == trial_types(tx)));
  66. end;
  67. ax=errorbar(trial_types, meanD,seD);
  68. set(ax,'MarkerSize', 15);
  69. set(ax,'LineStyle','none')
  70. set(ax,'Marker','.')
  71. end;
  72. hold on
  73. x_s=x_s(:);
  74. y_s=y_s(:);
  75. delta=delta(:);
  76. plot(x_s, y_s,'k');
  77. plot(x_s,y_s-delta,'k:');
  78. plot(x_s,y_s+delta,'k:');
  79. ylim([0 1]);
  80. ylabel('% went right')
  81. set(gca,'YTickLabel',[0:10:100]);
  82. if nargout>=1
  83. varargout{1}=S;
  84. end
  85. if nargout>=2
  86. varargout{2}=ax;
  87. end
  88. function y=sig4(beta,x)
  89. y0=beta(1);
  90. a=beta(2);
  91. x0=beta(3);
  92. b=beta(4);
  93. y=y0+a./(1+ exp(-(x-x0)./b));