Linear Regression Function in R with a Constrained (ie Bounded) variable and Binary Variables

  Kiến thức lập trình

I am running a linear regression with 3 independent variables of which 2 are continuous and one is binary representing a holiday. In 7th grade language it would look like

log(Unit_Sales) ~ Intercept + log(Unit_Price) + Log(Unit_Distribution) + Holiday (Binary Variable)

If I run a simple lm regression I get a tight model fit, but the Unit_Distribution Coefficient is above 1 and I need to force it to be less than 1 for a variety of reasons, that I would be happy to expand on.

The full model has more variables than the ones listed above that have pushed the ‘Unit Distribution’ coefficient down, but it remains above one. Rather than adding more variables to the model I want to force the Distribution Coefficient to be less than 1.

I tried using the ‘optim’ function to optimize my model with the constraints on Distribution to be less than 1. I had success with this approach when I excluded the Holiday (Binary Variable), but per my research I learned that ‘optim’ does not work with binary variables.

I tried’Rglpk_solve_LP’ and am getting similar errors. Likely because I am not correctly writing out the constraint, rhs or upper and lower bounds matrixes.

How would you handle this problem? Is there a better package or function that I could use? Can you share the correct syntax for dealing with mixed variables with the Rglpk_solve_LP function or any other solution?

New contributor

Roman Shuster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT