Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

posdefify

Find a Close Positive Definite Matrix


Description

From a matrix m, construct a "close" positive definite one.

Usage

posdefify(m, method = c("someEVadd", "allEVadd"),
          symmetric = TRUE, eigen.m = eigen(m, symmetric= symmetric),
          eps.ev = 1e-07)

Arguments

m

a numeric (square) matrix.

method

a string specifying the method to apply; can be abbreviated.

symmetric

logical, simply passed to eigen (unless eigen.m is specified); currently, we do not see any reason for not using TRUE.

eigen.m

the eigen value decomposition of m, can be specified in case it is already available.

eps.ev

number specifying the tolerance to use, see Details below.

Details

We form the eigen decomposition

m = V L V'

where L is the diagonal matrix of eigenvalues, L[j,j] = l[j], with decreasing eigenvalues l[1] >= l[2] >= ... >= l[n].

When the smallest eigenvalue l[n] are less than Eps <- eps.ev * abs(lambda[1]), i.e., negative or “almost zero”, some or all eigenvalues are replaced by positive (>= Eps) values, L~[j,j] = l~[j]. Then, m~ = V L~ V' is computed and rescaled in order to keep the original diagonal (where that is >= Eps).

Value

a matrix of the same dimensions and the “same” diagonal (i.e. diag) as m but with the property to be positive definite.

Note

As we found out, there are more sophisticated algorithms to solve this and related problems. See the references and the nearPD() function in the Matrix package. We consider nearPD() to also be the successor of this package's nearcor().

Author(s)

Martin Maechler, July 2004

References

Section 4.4.2 of Gill, P.~E., Murray, W. and Wright, M.~H. (1981) Practical Optimization, Academic Press.

Cheng, Sheung Hun and Higham, Nick (1998) A Modified Cholesky Algorithm Based on a Symmetric Indefinite Factorization; SIAM J. Matrix Anal.\ Appl., 19, 1097–1110.

Knol DL, ten Berge JMF (1989) Least-squares approximation of an improper correlation matrix by a proper one. Psychometrika 54, 53–61.

Highham (2002) Computing the nearest correlation matrix - a problem from finance; IMA Journal of Numerical Analysis 22, 329–343.

Lucas (2001) Computing nearest covariance and correlation matrices. A thesis submitted to the University of Manchester for the degree of Master of Science in the Faculty of Science and Engeneering.

See Also

eigen on which the current methods rely. nearPD() in the Matrix package. (Further, the deprecated nearcor() from this package.)

Examples

set.seed(12)
 m <- matrix(round(rnorm(25),2), 5, 5); m <- 1+ m + t(m); diag(m) <- diag(m) + 4
 m
 posdefify(m)
 1000 * zapsmall(m - posdefify(m))

sfsmisc

Utilities from 'Seminar fuer Statistik' ETH Zurich

v1.1-11
GPL (>= 2)
Authors
Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), Werner Stahel [ctb] (Functions: compresid2way(), f.robftest(), last(), p.scales(), p.dnorm()), Andreas Ruckstuhl [ctb] (Functions: p.arrows(), p.profileTraces(), p.res.2x()), Christian Keller [ctb] (Functions: histBxp(), p.tachoPlot()), Kjetil Halvorsen [ctb] (Functions: KSd(), ecdf.ksCI()), Alain Hauser [ctb] (Functions: cairoSwd(), is.whole(), toLatex.numeric()*), Christoph Buser [ctb] (to function Duplicated()), Lorenz Gygax [ctb] (to function p.res.2fact()), Bill Venables [ctb] (Functions: empty.dimnames(), primes()), Tony Plate [ctb] (to inv.seq()), Isabelle Fl<fc>ckiger [ctb], Marcel Wolbers [ctb], Markus Keller [ctb], Sandrine Dudoit [ctb], Jane Fridlyand [ctb], Greg Snow [ctb] (to loessDemo()), Henrik Aa. Nielsen [ctb] (to loessDemo()), Vincent Carey [ctb], Ben Bolker [ctb], Philippe Grosjean [ctb], Fr<e9>d<e9>ric Ibanez [ctb], Caterina Savi [ctb], Charles Geyer [ctb], Jens Oehlschl<e4>gel [ctb]
Initial release
2021-04-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.