nnls: Nonnegative Least Squares

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/nnls.R

Description

Solves the following inverse problem:

\min(||Ax-b||^2)

subject to

x>=0

Uses subroutine nnls (FORTRAN) from Linpack

Usage

1
nnls(A, B, tol = sqrt(.Machine$double.eps), verbose = TRUE)

Arguments

A

numeric matrix containing the coefficients of the equality constraints Ax~=B; if the columns of A have a names attribute, the names will be used to label the output.

B

numeric vector containing the right-hand side of the equality constraints.

tol

tolerance (for singular value decomposition and for the "equality" constraints).

verbose

logical to print nnls error messages.

Value

a list containing:

X

vector containing the solution of the nonnegative least squares problem.

residualNorm

scalar, the sum of absolute values of residuals of violated inequalities (i.e. sumof x[<0]); should be zero or very small if the problem is feasible.

solutionNorm

scalar, the value of the quadratic function at the solution, i.e. the value of \min(||Ax-b||^2).

IsError

logical, TRUE if an error occurred.

type

the string "nnls", such that how the solution was obtained can be traced.

numiter

the number of iterations.

Author(s)

Karline Soetaert <[email protected]>

References

Lawson C.L.and Hanson R.J. 1974. Solving Least Squares Problems, Prentice-Hall

Lawson C.L.and Hanson R.J. 1995. Solving Least Squares Problems. SIAM classics in applied mathematics, Philadelphia. (reprint of book)

See Also

ldei, which includes equalities

Examples

1
2
3
A <- matrix(nrow = 2, ncol = 3, data = c(3, 2, 2, 4, 2, 1))
B <- c(-4, 3)
nnls(A, B)

Example output

$X
[1] 0.0 0.2 0.0

$residualNorm
[1] 0

$solutionNorm
[1] 6.6

$IsError
[1] FALSE

$type
[1] "nnls"

$numiter
[1] 1

limSolve documentation built on Aug. 14, 2017, 3:01 p.m.