near_posdef: Nearest Positive-Definite Matrix

View source: R/cov_help_funcs.R

near_posdefR Documentation

Nearest Positive-Definite Matrix

Description

Implements the algorithm of \insertCitehigham2002computing;textualcovestim to compute the nearest positive-definite matrix to an approximate one, typically a correlation or variance-covariance matrix.

Usage

near_posdef(
  mat,
  corr = FALSE,
  keep_diag = FALSE,
  do_dykstra = TRUE,
  eig_tol = 1e-06,
  conv_tol = 1e-07,
  posd_tol = 1e-08,
  maxit = 100,
  trace = FALSE
)

Arguments

mat

a pxp matrix.

corr

a logical, indicating if the result should be a correlation matrix. Default value is FALSE.

keep_diag

a logical, indicating if the result should have the same diagonal as the original matrix mat.

do_dykstra

a logical, indicating if Dykstra's correlation is to be used. Default value is TRUE.

eig_tol

a double, defining the relative positiveness of eigenvalues compared to the largest eigenvalue. Default value is 1e-6.

conv_tol

a double, defining the convergence tolerance for the Higham algorithm. Default value is 1e-7.

posd_tol

a double, defining the tolerance for enforcing positive definiteness. Default value is 1e-8.

maxit

maximum number of iterations. Default value is 100.

trace

a logical, indicating whether iterations are to be traced (printed out). Default value is FALSE.

Details

Note that setting corr = TRUE just sets diag(.) <- 1 within the algorithm. The near_posdef() is originally found under \insertCitematrixpackage;textualcovestim.

Value

a positive-definite matrix.

References

\insertAllCited

Examples


data(rets_m)
ml_sigma <- cov_estim_wrapper2(rets_m, "ML")
ml_sigma_near_posdef <- near_posdef(ml_sigma, eig_tol = 1e-8)


antshi/CovEstim documentation built on June 10, 2025, 3:11 a.m.