Is there a way to run a linear regression with upper and/or lower limits on the coefficients in R?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Yes, you can do this in Lavaan.
Here's an example. We fit a regression model, and find an estimate of 0.10. Then fit a model using lavaan, and get the same parameter estimate. Then fit the model with a constraint that b1 has to be greater than 0.
Yes, you can do it by re-defining linear regression as an optimization problem (a residual sum of squares cost function for example) and solving it using the constraints you want. So to use the numbers as the example from @Jeremy: (Note that in this example we are fitting a model without an intercept)
Ultimately any package you wish to use for constrained regression will do the same thing: formulate a cost function and solve a constrained optimization problem. In the case of ordinary least squares as the one shown here "ordinary" optimizers using "simple" BFGS variants will do just fine; harder problems (eg. GLMM) will require more exotic beasts like BOBYQA.