Learn R Programming

bigutilsr (version 0.3.11)

regul_glasso: Regularization with the graphical lasso

Description

Use the graphical lasso algorithm to regularize a square symmetric matrix (e.g. a covariance or correlation matrix) by assuming that its inverse has many zeros.

Usage

regul_glasso(
  mat,
  lambda,
  maxiter_outer = 200,
  maxiter_lasso = 200,
  tol = 1e-04,
  verbose = FALSE
)

Value

The regularized matrix, where the diagonal should be the same and zeros should be kept as well. It also returns the lambda used as an attribute.

Arguments

mat

A square symmetric matrix.

lambda

Strength of regularization. It needs to be scaled with mat. It should also be the maximum difference between the two matrices.

maxiter_outer

Maximum number of iterations of the outer loop. Default is 200.

maxiter_lasso

Maximum number of iterations of each lasso solver. Default is 200.

tol

Tolerance for assessing convergence. Default is 1e-4 and it needs to be scaled with mat.

verbose

Whether to print iterations and differences. Default is FALSE.

Examples

Run this code
(cov <- cov(iris[1:4]))
lambda <- 1 / sqrt(nrow(iris))
(cov_regul <- regul_glasso(cov, lambda))

Run the code above in your browser using DataLab