MATLAB: Estimating probit using fminsearch yields different results from glmfit

fminsearchlog likelihoodprobit

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;

Best 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.
Related Question