Utilities for regularization of a matrix
regularize
can be used to regularize (nearly-)singular correlation matrices. It may also be used to regularize covariance matrices but will not keep their diagonal constant. Use on other types of matrices may give nonsense. The regularization corrects the diagonal of matrices with high condition number so that the condition number of a corrected matrix is the maximum value specified by maxcondnum
. For that purpose, it needs the extreme eigenvalues of the matrix, by default provided by the function extreme_eig
. Calls functions from RSpectra if available, and falls back on base functions otherwise.
extreme_eig(M, symmetric, required = TRUE) regularize(A, EEV=extreme_eig(A,symmetric=TRUE), maxcondnum=1e12)
M |
Square matrix. Sparse matrices of class |
A |
Square matrix as |
symmetric |
Whether the matrix is symmetric. Helpful to select efficient methods for this case if the matrix class does not implies its symmetry. |
required |
Whether the computation should be attempted independently of the size of the matrix. |
EEV |
Two extreme eigenvalue in the return format of |
maxcondnum |
Target condition number when regularization is performed |
extreme_eig
returns a vector of length 2, the largest and the smallest eigenvalues in this order.
regularize
returns a matrix, possibly in sparse format.
H10 <- Matrix::Hilbert(10) extreme_eig(H10,symmetric=TRUE) # ratio > 1e13 rH10 <- regularize(H10) extreme_eig(rH10,symmetric=TRUE) # ratio = 1e12
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.