## Generate a hub example
dat <- huge::huge.generator(100, 40, 'hub', verbose=FALSE)
## Simple correlation thresholding
corrthresh <- function(data, lambda) {
S <- cor(data)
path <- lapply(lambda, function(lam) {
tmp <- abs(S) > lam
diag(tmp) <- FALSE
as(tmp, 'lMatrix')
})
list(path=path)
}
## Inspect output
lam <- getLamPath(getMaxCov(dat$sigmahat), 1e-4, 10)
out.cor <- pulsar(dat$data, corrthresh, fargs=list(lambda=lam))
out.cor
if (FALSE) {
## Additional examples
## quic
library(QUIC)
quicr <- function(data, lambda, ...) {
S <- cov(data)
est <- QUIC(S, rho=1, path=lambda, msg=0, tol=1e-2, ...)
est$path <- lapply(seq(length(lambda)), function(i) {
## convert precision array to adj list
tmp <- est$X[,,i]; diag(tmp) <- 0
as(tmp!=0, "lMatrix")
})
est
}
## clime
library(clime)
climer <- function(data, lambda, tol=1e-5, ...) {
est <- clime(data, lambda, ...)
est$path <- lapply(est$Omegalist, function(x) {
diag(x) <- 0
as(abs(x) > tol, "lMatrix")
})
est
}
## inverse cov shrinkage Schafer and Strimmer, 2005
library(corpcor)
icovshrink <- function(data, lambda, tol=1e-3, ...) {
path <- lapply(lambda, function(lam) {
tmp <- invcov.shrink(data, lam, verbose=FALSE)
diag(tmp) <- 0
as(abs(tmp) > tol, "lMatrix")
})
list(path=path)
}
## Penalized linear model, only
library(glmnet)
lasso <- function(data, lambda, respind=1, family="gaussian", ...) {
n <- length(lambda)
tmp <- glmnet(data[,-respind], data[,respind],
family=family, lambda=lambda, ...)
path <-lapply(1:n, function(i) as(tmp$beta[,i,drop=FALSE], "lMatrix"))
list(path=path)
}
## alternative stability selection (DIFFERENT from hdi package)
out <- pulsar(dat$data, lasso, fargs=list(lambda=lam))
mergmat <- do.call('cbind', tmp$stars$merge)
image(mergmat)
}
Run the code above in your browser using DataLab