kappa
Compute or Estimate the Condition Number of a Matrix
The condition number of a regular (square) matrix is the product of the norm of the matrix and the norm of its inverse (or pseudoinverse), and hence depends on the kind of matrixnorm.
kappa()
computes by default (an estimate of) the 2norm
condition number of a matrix or of the $R$ matrix of a $QR$
decomposition, perhaps of a linear fit. The 2norm condition number
can be shown to be the ratio of the largest to the smallest
nonzero singular value of the matrix.
rcond()
computes an approximation of the reciprocal
condition number, see the details.
 Keywords
 math
Usage
kappa(z, ...)
"kappa"(z, exact = FALSE, norm = NULL, method = c("qr", "direct"), ...)
"kappa"(z, ...)
"kappa"(z, ...)
.kappa_tri(z, exact = FALSE, LINPACK = TRUE, norm = NULL, ...)
rcond(x, norm = c("O","I","1"), triangular = FALSE, ...)
Arguments
 z, x
 A matrix or a the result of
qr
or a fit from a class inheriting from"lm"
.  exact
 logical. Should the result be exact?
 norm
 character string, specifying the matrix norm with respect
to which the condition number is to be computed, see also
norm
. Forrcond
, the default is"O"
, meaning the One or 1norm. The (currently only) other possible value is"I"
for the infinity norm.  method
 a partially matched character string specifying the method to be used;
"qr"
is the default for backcompatibility, mainly.  triangular
 logical. If true, the matrix used is just the lower
triangular part of
z
.  LINPACK
 logical. If true and
z
is not complex, the LINPACK routinedtrco()
is called; otherwise the relevant LAPACK routine is.  ...
 further arguments passed to or from other methods;
for
kappa.*()
, notablyLINPACK
whennorm
is not"2"
.
Details
For kappa()
, if exact = FALSE
(the default) the 2norm
condition number is estimated by a cheap approximation. However, the
exact calculation (via svd
) is also likely to be quick
enough.
Note that the 1 and Infnorm condition numbers are much faster to
calculate, and rcond()
computes these reciprocal
condition numbers, also for complex matrices, using standard Lapack
routines.
kappa
and rcond
are different interfaces to
partly identical functionality.
.kappa_tri
is an internal function called by kappa.qr
and
kappa.default
.
Unsuccessful results from the underlying LAPACK code will result in an error giving a positive error code: these can only be interpreted by detailed study of the FORTRAN code.
Value

The condition number, $kappa$, or an approximation if
exact = FALSE
.
Source
The LAPACK routines DTRCON
and ZTRCON
and the LINPACK
routine DTRCO
. LAPACK and LINPACK are from http://www.netlib.org/lapack and
http://www.netlib.org/linpack and their guides are listed
in the references.
References
Anderson. E. and ten others (1999) LAPACK Users' Guide. Third Edition. SIAM. Available online at http://www.netlib.org/lapack/lug/lapack_lug.html.
Chambers, J. M. (1992) Linear models. Chapter 4 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Dongarra, J. J., Bunch, J. R., Moler, C. B. and Stewart, G. W. (1978) LINPACK Users Guide. Philadelphia: SIAM Publications.
See Also
norm
;
svd
for the singular value decomposition and
qr
for the $QR$ one.
Examples
library(base)
kappa(x1 < cbind(1, 1:10)) # 15.71
kappa(x1, exact = TRUE) # 13.68
kappa(x2 < cbind(x1, 2:11)) # high! [x2 is singular!]
hilbert < function(n) { i < 1:n; 1 / outer(i  1, i, "+") }
sv9 < svd(h9 < hilbert(9))$ d
kappa(h9) # pretty high!
kappa(h9, exact = TRUE) == max(sv9) / min(sv9)
kappa(h9, exact = TRUE) / kappa(h9) # 0.677 (i.e., rel.error = 32%)
Community examples
Two methods were used to identify mosquito samples.The methods are morphological identification and molecular identification.There were 200 samples where morphological idenntification classified 90 samples as An. gambiae and 110 as An. funestus.Molecular identification classified 2 as An arabiensis, 7 as An quad, 7 An funstsus ss, 181 An leesoni .kappatri