Forcing negative coefficients to be zero in MLE with fmincon

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

theta=fmincon(@nested,[],[],[],[],lb,[],[],opt)
This line is obviously not copy/pasted. You are missing an initial point x0.
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

I've tried the lb=0 for the theta that needs to be non-negative, but I receive this message:
"Warning: Length of lower bounds is < length(x); filling in missing lower bounds with -Inf."
which takes me back to the negative estimate.. Can I work around this somehow? Also thank you for your input on Isqnonlin - I've considered going down that path instead of the fmincon.
The warning means that you haven't provided lower bounds for all the variables. I see that your lb vector has length 5. Do you have more than 5 unknowns? If so, why isn't your lb vector the same length?
The reason it has the length 5 is, that in this particular case I have a constant, y_t lagged once and twice, I have the intensity, lambda, lagged once, and one exogenous regressor. Thus 5 unknown. When I use more exogenous regressors in later models I change 5 to 6 and so on ensuring that the lb vector has the same length as amounts of unknowns. The reason I get the warning is cause I simply set lb=0 when trying to constrain estimates to be positive. I guess this is not how it is done?
The reason I get the warning is cause I simply set lb=0 when trying to constrain estimates to be positive. I guess this is not how it is done?
No, make lb the same size as your initial guess x0. Repeat the entries of zeros and infs where appropriate.
My initial guess for the gamma estimate is 0.2 having theta0=[0.1;0.2;0.2;0.2; 0.2 ] in which the bold 0.2 is the gamma guess. As I am fairly new to Matlab I'm not sure how I am supposed to make lb this size?
So all theta(i) are unconstrained except the final one? If so, then
lb=-inf(size(theta0));
lb(end)=0;
THANK GOD!!! yes that's just what I needed! Thanks a lot. So what if I want to constrain them all to be positive? It worked perfectly for the gamma estimate, but I might experience negative estimates for other estimates in later models.
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));
Thanks for your help, it was just what I needed!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 3 Nov 2014

Commented:

on 3 Nov 2014

Community Treasure Hunt

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

Start Hunting!