Forcing negative coefficients to be zero in MLE with fmincon

2 views (last 30 days)
Hi guys
I am using MLE to estimate a poisson process dependent on lagged y and a few exogenous regressors, X. In this context I am interested in constraining the coefficients in my output to be positive, meaning that any negative estimate should be forced to be zero. Is this possible and if yes, how is it done? I use
function[theta]=estimate(y,X,theta0,lb,opt,p,q,amcov,T)
where X is my exogenous variables, theta0 is my guess at estimate value (these are arbitrary), lb=-Inf*ones(5,1), opt=optimset('Algorithm','interior-point'), amcov is the amount of exogenous regressors and p,q and T does not matter in this context.
theta=fmincon(@nested,[],[],[],[],lb,[],[],opt)
%where
function z=nested(theta)
and I have
gamma=theta(p+q+2:p+q+1+amcov)
and it's the gamma estimate I am having trouble with. Some of my estimates af negative, but I need to constrain those to being positive, i.e. making them zero, since the negative value influences my other variables which I don't want.
Please ask for more information if you need it to help me solve this, I will try to provide it.
Thanks in advance
  2 Comments
Matt J
Matt J on 3 Nov 2014
theta=fmincon(@nested,[],[],[],[],lb,[],[],opt)
This line is obviously not copy/pasted. You are missing an initial point x0.
Kristoffer
Kristoffer on 3 Nov 2014
I accidentally deleted the term theta0 containing the initial points. My bad.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 3 Nov 2014
Edited: Matt J on 3 Nov 2014
Your gamma appear to be just some subset of your theta(i) variables. So, instead of setting lb to -inf(5,1), set it to zero for those theta that need to be non-negative.
Also, since this is a least squares problem with bound constraints only, consider using lsqlin, lsqnonlin, or lsqcurvefit, if applicable, instead of fmincon.
  9 Comments
Matt J
Matt J on 3 Nov 2014
Edited: Matt J on 3 Nov 2014
Just set lb(i) to zero for any theta(i) you want to constrain positive... If you want to keep them all positive,
lb=zeros(size(theta0));

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!