knitr::opts_chunk$set(echo = TRUE, tidy = TRUE)
SCPME
is an implementation of the methods described in "Shrinking Characteristics of Precision Matrix Estimators" (link). It estimates a penalized precision matrix via a modified alternating direction method of multipliers (ADMM) algorithm.
A (possibly incomplete) list of functions contained in the package can be found below:
shrink()
computes the estimated precision matrix
data_gen()
data generation function (for convenience)
plot.shrink()
produces a heat map or line graph for cross validation errors
See package website or manual.
# The easiest way to install is from GitHub: # install.packages("devtools") devtools::install_github("MGallow/shrink")
If there are any issues/bugs, please let me know: github. You can also contact me via my website. Pull requests are welcome!
library(SCPME) set.seed(123) # generate data from a sparse oracle precision matrix # we can use the built-in `data_gen` function # generate 100 x 5 X data matrix and 100 x 1 Y data matrix data = data_gen(p = 5, n = 100, r = 1) # the default regression coefficients are sparse data$betas # default oracle precision matrix is also sparse round(qr.solve(data$SigmaX), 5) # now suppose we are interested in estimating the precision # print marginal sample precision matrix for X # this is perhaps a bad estimate (not sparse) sample = (nrow(data$X) - 1)/nrow(data$X)*cov(data$X) round(qr.solve(sample), 5) # now use SCPME to estimate preicison matrix (omega) assuming sparsity # note that this is simply a lasso penalized preicision matrix shrink(data$X, lam = 0.5, crit.cv = "loglik") # what if we instead assumed sparsity in beta? (print estimated omega) # recall that beta is a product of marginal precision of X and cov(X, Y) lam_max = max(abs(t(data$X) %*% data$Y)) (shrink = shrink(data$X, data$Y, B = cov(data$X, data$Y), nlam = 20, lam.max = lam_max)) # print estimated beta shrink$Z # we could also assume sparsity in beta AND omega (print estimated omega) (shrink2 = shrink(data$X, data$Y, B = cbind(cov(data$X, data$Y), diag(ncol(data$X))), nlam = 20, lam.max = 10, lam.min.ratio = 1e-4)) # print estimated beta shrink2$Z[,1, drop = FALSE] # produce CV heat map for shrink plot(shrink, type = "heatmap") # produce line graph for CV errors for shrink plot(shrink, type = "line")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.