1

I was wondering if the R ‘Quadprog’ package has the ability to incorporate box constraints of the following form: -L*1 <= v <= L*1

Where 1 is a vector of 1’s and L is a constant. The variable to optimize is v. Basically all individual elements of v must be bounded between –lambda and lambda.

If not, are there other packages to get around this problem?

Many thanks for your help

SRM
  • 11
  • 1

1 Answers1

1

Yes, you can.

Given the function:

solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=0)

Amat and bvec means Amat * v >= bvec.

So setting in this way:

Amat <- cbind(diag(length(v)), -diag(length(v))) 
bvec <- c(rep(-L, length(v)), rep(-L, length(v)))

means v > -L and -v > -L (that is the same than v < L) for every individual element of v.

Note meq means "number of equalities", and because in your case all are inequalities it must be put to 0.

If you need to put equalities constrains, put it in the "left" side of Amat and bvec and the number of equalities in meq.

Alnair
  • 938
  • 8
  • 10