Estimating probit using fminsearch yields different results from glmfit

I am trying to estimate a Probit model by maximizing a log likelihood function with fminsearch. The vector of coefficients returned from fminsearch is different from what I get when I run a probit regression (using glmfit).
I did some basic debugging by printing my variables and manually checking the function against some input-output pairs. Is there something wrong with how I defined my function?
Here is my function code:
%function
function val = probit2(b,y,x)
val2 = y'*log(normcdf(x*b'));
val3 = (1-y)'*log(1-normcdf(x*b'));
val = -1.*(sum(val2 + val3));
end;
Here is my code for fminsearch:
%load data
filename = 'admit.xls';
admit = xlsread(filename);
y = admit(:,1);
x = admit(:,2:4);
%coefficients
b_true = glmfit(x,y,'binomial','link','probit');
%set options
options=optimset('MaxFunEvals',2000,'MaxIter',2000);
%initial guess
b0=[.001 0.464 -0.331];
%fminsearch
[b,fval,exitflag,output]=fminsearch('probit2',b0,options,y,x);
end;

 Accepted Answer

glmfit() puts in a constant term that your probit2 does not handle.
Note: the semi-colon following your 'end' in your probit2 function is not valid syntax. The 'end' terminates the function, so the ';' after it is outside of any function. The 'end;' in your script does not match to any control statement and so is not valid syntax either.
Note: please learn to parameterize functions . You are using an undocumented facility of fminsearch that stopped being documented in MATLAB 5.1, and which could disappear at any time, and which could accidentally interfere with other undocumented fminsearch capability.

1 Comment

Ah, of course! Thank you very much Walter. I parameterized the function, removed the extraneous semi-colon and "end;" term, and added a vector of ones to the x matrix in order to estimate the constant.

Sign in to comment.

More Answers (0)

Categories

Find more on Verification, Validation, and Test in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!