Linear least-squares fit with coefficients constrained to be nonnegative.
USAGE:
nnls.fit(x, y, weights=<<see below>>, rank.tol=<<see below>>,
zero.tol=<<see below>>)
REQUIRED ARGUMENTS:
x
numeric matrix of observed data. Missing values (NAs) are not allowed.
y
numeric response vector to be fit to the observed data subject to
nonnegativity constraints. Missing values (NAs) are not allowed.
OPTIONAL ARGUMENTS:
weights
a nonnegative numeric vector of length equal to the length of the response
vector. If
weights is supplied, then the sum of squares of each residual
multiplied by the corresponding weight is mimimized subject to nonnegativity
constraints. Rows of the observation matrix
x and elements of the response
vector
y associated with zero weights are removed prior to solution.
By default an unweighted fit is computed.
rank.tol
numeric value used to determine rank deficiency in the data (threshold for
the reciprocal condition number estimate for the triangular factor in a QR
factorizaton). The default is
sqrt(.Machine$double.eps).
zero.tol
the largest positive quantity that is to be considered to be zero for the
purposes of the algorithm. The default is
sqrt(.Machine$double.eps).
VALUE:
a list with the following components :
coefficients
vector of coefficients that represents the best nonnegative fit of the
response to the observations.
residuals
vector of residuals for the fitted values.
dual
vector of dual variables (Lagrange multipliers) associated with the
coefficients. (The product of each dual variable and its corresponding
coefficient should be close to zero).
rkappa
vector of length two whose first element is the reciprocal condition number
estimate for the QR factorization of the columns of the matrix associated with
nonzero coefficients, and whose second element is the minimum reciprocal
condition number estimate encountered during the course of the algorithm
(which fits the response to various subsets of the columns of the matrix).
call
a copy of the call to
nnls.fit.
DETAILS:
The algorithm can detect column rank deficiency in the data but it cannot
solve rank-deficient problems. If
nnls.fit fails to find a solution, try the
function
nlregb.
Note the following differences between the input to
nnls.fit
as opposed to
lm
and
lsfit.
The latter include a column of 1s for an intercept in the
matrix of observed data by default,
and use the square roots of the weights as defined here.
REFERENCES:
Lawson, C. L. and Hanson, R. J. (1974).
Solving Least-Squares Problems.
New York : Prentice-Hall.
SEE ALSO:
.
EXAMPLES:
A <- matrix(rnorm(500), nrow=100, ncol=5)
b <- rnorm(100)
nnls.fit(A, b)