Rでモデルを推定し、係数の1つを他の係数よりも小さくする制約を追加したいと思います。どうやってやるの?
1 に答える
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.