I estimate a model in R and I would like to add constraint that would force one of the coefficients to be smaller than the other one. How can I do that?
If you really need to use either lm or nls and can't use anything that lets you specify constraints, one way is to reparameterize the model so that the difference in coefficients is itself a parameter.
For example if you have a model with b1*x1+b2*x2 in it, but where b2 > b1 you could code that as b1*x3+d*x2 where x3=x1+x2 and d represents b2-b1. Now you need to force d > 0. You simply reparameterize again, d = exp(k), say, and use nls to fit the new model b1*x3+exp(k)*x2 where your parameters are b1 and k. Once estimated, you can then compute an estimate of b2 as b1+exp(k). Then b1 is guaranteed to be less than b2.
However, nls allows you to specify upper and lower bounds, so you should be able to just put 0 in as a lower bound for d (though that may not guarantee a strict inequality).
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With