fminsearch and different results on estimated parameters.
Show older comments
Dear Matlab users,
I am new to Matlab and intend to later on maximize a customised log-likelihood function. In my early attempts to learn how to do this in Matlab, I decided to first experiment with the exponential distribution model for survival analysis. Below are the codes (I used the censored model for this) for the function to be maximized (admittedly, this may not be the most efficient coding for this problem, so suggestions are very welcome):
function like=expcovariate_mle(params,xb,t,c);
theta=exp(xb*params');
like = -sum(c.*log(theta)-t.*theta);
grad= -sum(c./theta-t);
hess= -sum(-c./(theta.^2));
end
and here are my codes for executing the above:
clear all;
warning off all
format long
cd 'E:\work\'
xlsread('final_data.xls','Sheet1','A2:Y759');
c=ans(:,8);
t=ans(:,1);
data=ans(:,:);
settled=data(:,8);
def=data(:,17);
est=data(:,18);
lia=data(:,19);
nol=data(:,20);
pat=data(:,21);
lap=data(:,22);
nla=data(:,23);
censor=1-settled;
cons=ones(758,1);
xb=[cons,def,est,lia,lap,nla];
options = optimset('MaxFunEvals',10000);
params0=ones(1,6);
[params]=fminsearch(@(params) expcovariate_mle(params,xb,t,c),params0,options);
Out of interest, I have been comparing how the above works when coded in other software (I use STATA and Limdep). What was quite puzzling for me was that when I have up to 6 columns in matrix xb (i.e. xb=[ones(758,1),def,est,lia,nol,pat] the Matlab codes above produce exactly the same results as STATA/Limdep. However, if my xb matrix contains one or two additional variables, ( i.e. xb=[ones(758,1),def,est,lia,nol,pat,lap,nla] ) then Matlab produces very different parameters from STATA/Limdep. I am puzzled as to why this, as I have been experimenting with the above incrementally, i.e. start with 2 columns, three columns, etc in my matrix xb, but this only produces similar results to STATA/Limdep up to including 6 columns in xb. When I add additional variables, I get very different results from STATA/Limdep.
I wrote similar codes in Matlab to estimate the Weibull Accelerated Failure Time Survival model and I have exactly the same problem as above, i.e. the estimated parameters are the same only up to using 6 variables, but more than 6 variables produce different parameters from STATA/Limdep.
Has anyone every experienced this problem before, or am I missing out something obvious from the use of the command fminsearch?
As a novice user, I would very much appreciate any help/suggestions/guidance on this please.
Many thanks, Dev
Accepted Answer
More Answers (1)
Marc
on 21 Nov 2013
0 votes
fminsearch is based on a nelder mean simplex which does not require knowledge of the jacobian. For fitting parameters in odes or DAEs I have found this a my modified version from numerical recipes in fortran 95 to be very good against the solvers in the optimization and global optimization. That said, each method has there strengths. Typically, trivial problems are handled very similarly by each. It's when your needs become more demanding then it really helps to understand the strengths of each.
Good news is that the various functions are all set up very similarly, so it's easy to swap methods or try them all if we are talking seconds.
salt to suit
Categories
Find more on Word games 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!