Multivariate Least Squares with Equalities and Inequalities

Description

This function provides a multivariate version of function lsei from the limSolve package. It solves the following optimisation problem for each column b of B

Usage

mlsei(A, B, ..., fulloutput = FALSE, verbose = TRUE)

Arguments

A
numeric matrix containing the coefficients of the quadratic function to be minimised, ||Ax-B||^2; if the columns of A have a names attribute, they will be used to label the output.
B
numeric matrix containing the right-hand side of the quadratic function to be minimised.
fulloutput
if TRUE, also returns the covariance matrix of the solution and the rank of the equality constraints -- only used if type = 1 (see lsei).
verbose
logical that toggles verbose messages
...
extra arguments all passed to lsei.

Value

If fulloutput=TRUE, a list whose elements are the results returned by lsei on each column of B, otherwise a list with the following elements: Xa matrix of dimension ncol(B) x ncol(A) that contain the estimated solution of the least-square problem. IsErrora logical that indicates if an error occured typethe string "lsei", such that how the solution was obtained can be traced solutionNorma vector, whose elements are the sum of absolute values of residuals of equalities and violated inequalities, as computed for each column of B. solutionNorma vector, whose elements are the values of the minimised quadratic function at the solution, i.e. the value of ||Ax-b||^2, as computed for each column of B.

Details

min ||Ax - b||^2

subject to the equality constraints: E x = f

and/or inequality constraints: G x >= h

It applies lsei on each column of a right-hand side matrix, and automatically transpose the input and result matrices back and forth if needed.

Examples


# random left-hand quadratic coefficients
A <- rmatrix(20, 3)
r <- ncol(A)
# random right-hand target matrix
B <- rmatrix(20, 10)
# constrained least-squares: nonnegative and sum up to one
res <- mlsei(A,B, E=matrix(1, 1, r), F=1, G=diag(1, r), H=rep(0,r))