Function nnls solves the least squares problem under
nonnegativity (NN) constraints. It is an R interface to the NNLS
function that is described in Lawson and Hanson (1974, 1995). Its
Fortran implementation is public domain and available at
http://www.netlib.org/lawson-hanson/ (with slight
modifications by Yong Wang for compatibility with the lastest
Fortran compiler.)
Given matrix a and vector b, nnls solves the
nonnegativity least squares problem:
$$\mathrm{minimize \ \ } || a x - b ||,$$
$$\mathrm{\ \ \ subject\ to\ \ } x \ge 0.$$
Function pnnls also solves the above nonnegativity least
squares problem when k=0, but it may also leave the first
k coefficients unrestricted. The output value of k
can be smaller than the input one, if a has linearly
dependent columns. If sum is a positive value, pnnls
solves the problem by further restricting that the NN-restricted
coefficients must sum to the given value.
Function pnnqp solves the quadratic programming problem
$$\mathrm{minimize\ \ } \frac12 x^T q x + p^T x,$$
when only some or all coefficients are restricted by
nonnegativity. The quadratic programming problem is solved by
transforming the problem into a least squares one under the same
constraints, which is then solved by function
pnnls. Arguments k and sum have the same
meanings as for pnnls.
Functions nnls, pnnls and pnnqp are able to
return any zero-valued solution as 0 exactly. This differs from
functions lsei and qp, which may produce very small
values for exactly 0s, thanks to numerical errors.