I am modeling the logarithm of wages for 154 employees. The predictors are a binary matrix, where the rows are employees, the columns are work competencies, and the intersection is either 1 or 0 (i.e., whether the employee has the competency or not).
I need to get integer coefficients for all 63 predictors.
For the linear programming problem, I was given the objective function and the constraints:
objective function: sum(n1+n2) –> min
constraints:
-
main constraint matrix: Ax+En1-En2-ylambda – b = 0, where:
A – binary matrix (154×63)
x – integer coefficients which I need to take after modeling
n1 – vector of excess logarithm of wages (positive difference between the predicted wage Ax and the real one)
n2 – vector of logarithm deficiency (positive difference between the predicted wage Ax and the real one)
y – logarithm of wages
lambda – some parameter, honestly I didn’t understand from where I can take it, maybe from model, but I’m not sure (i think it is exogenous)
b – similar to lambda
E – maybe it is exogenous matrix -
x need to be integer
-
x >= 1
I tried to write R code, but I don’t know how linear programming works:
obj <- c(1, 1) # Minimize sum(n1 + n2)
A <- as.matrix(X)
E <- matrix(rep(1), nrow = 154, ncol = 63) # just randomly for the first time
b <- as.vector(offset_test) # just randomly for the first time
y <- as.vector(log(grades_and_salaries$salary))
lambda <- as.vector(lambda.min) # just randomly
mat <- cbind(A, E, -E, -y, rep(-lambda, nrow(A)))
dir <- rep("==", nrow(A))
x.dir <- rep(">=", length(obj)) # x >= 1
mat <- rbind(mat, diag(length(obj)))
dir <- c(dir, x.dir)
rhs <- c(b, rep(1, length(obj)))
lp.model <- lp("min", obj, mat, dir, rhs, all.int = TRUE)
I got something strange, but I expected to get vector of integer coefficients for x.
How can I solve my task in R with all constraints and get integer coefficients?