Search code examples
matlabmatlab-figuregamma-functionlog-likelihood

Matlab: Error using gammaln... while plotting psychometric functions


I'm using the toolbox psignifit to plot psychometric functions from a dataset. My code looks essentially like the following:

load data.mat
options = struct; 
options.sigmoidname = 'logistic';
result = psignifit(data,options);  % this is where the error occurs
result.Fit
result.conf_Intervals
plotPsych(result)

and my data has essentially the same form as the sample data given in the toolbox,

data =    [...
0.0010,   45.0000,   90.0000;...
0.0015,   50.0000,   90.0000;...
0.0020,   44.0000,   90.0000;...
0.0025,   44.0000,   90.0000;...
0.0030,   52.0000,   90.0000;...
0.0035,   53.0000,   90.0000;...
0.0040,   62.0000,   90.0000;...
0.0045,   64.0000,   90.0000;...
0.0050,   76.0000,   90.0000;...
0.0060,   79.0000,   90.0000;...
0.0070,   88.0000,   90.0000;...
0.0080,   90.0000,   90.0000;...
0.0100,   90.0000,   90.0000];

When I run the demo, the plotPsych function returns a figure as it is supposed to, but when I execute my script, I get the following series of errors. My question is why am I getting the error about using gammaln and what might be the right fix?

Error using gammaln
Input must be nonnegative.

Error in logLikelihood (line 75)
    p     = p + gammaln(n - k + b);

Error in psignifitCore>@(X)-logLikelihood(data,options,X(1),X(2),X(3),X(4),X(5)) (line 80)
fun = @(X) -logLikelihood(data, options, X(1), X(2), X(3), X(4), X(5));

Error in fminsearch (line 325)
x(:) = xr; fxr = funfcn(x,varargin{:});

Error in psignifitCore (line 97)
  Fit = fminsearch(fun, x0,optimiseOptions); %MATLAB standard choice

Error in psignifit (line 242)
result = psignifitCore(data, options);

Error in signifit_myscript (line 31)
result = psignifit(data,HDDV);

I've run the toolbox on my data in the past with success, so I first tried to restart Matlab, to no avail. I then tried to remove and add back psignifit-master to the path, but this also didn't seem to solve the issue.

Thanks in advance.


Solution

  • I had the same problem while running the psignifit function with my 2AFC data.

    The reason was very simple, the psignifit function causes this error message if you try to process data exceeding the 0 to 1 limits, for example 1.0000000001