# How can I add minimum and maximum constraints to a coefficient in a regression in R?

I have an array ($Y$) with a series of data to which I must fit the sum of some other arrays $(X_1,X_2,X_3)$. The expression is:

$Y = c_1*X_1 + c_2*X_2 + c_3*X_3 + e$

I need to add some constraints (min and max values of $c_1$).

• Why do you need (do you?) those constraints? – Tim Jun 1 '17 at 11:26
• This is an extremely bad idea, you will not estimate any quantity of interest. Your inference will be wrong, your estimates will be biased, and the predictions will be off the charts – Repmat Jun 1 '17 at 16:46

• If $c_1$ meets the constraints, you are done.
• If $c_1$ is outside the constraints, take $c_1$ as the maximum or minimum constraint - whichever is closer to the fitted value. From this moment, $c_1$ is a constant and not a parameter to be estimated.
$$Y - c_1*X_1 = c_2*X_2 + c_3*X_3 + e$$
That is, now your response is $Y - c_1*X_1$ (an array of known values) and your predictors are $X_2$ and $X_3$.