R package (Version 1, 2015-11-04)

Homepage @ Github | Homepage @ Wei Chen's Lab | Source Code

Introduction

FastGGM is used to study conditional dependence among variables, which is well known as the Gaussian graphical model (GGM). It uses scaled Lasso regression to obtain asympotically efficient estimation of each entry of a precision matrix under a sparseness condition. It not only estimates the conditional dependence between each pair of variables but also supplies p-value and confidence interval. This is a fast package even for a high-dimensional data set.

Installation

Windows needs to install Rtools, Mac nees to install Xcode. This package relies on libraries "Rcpp" and "RcppParallel". R commands for installation:

install.packages("Rcpp")
install.packages("RcppParallel")
# Install from .tar.gz file
install.packages(pkgs = "FastGGM.tar.gz", repos = NULL, type = "source")
# Or install from GitHub
library(devtools)
install_github("wt2015-github/FastGGM")

Usage

FastGGM(x, lambda)
FastGGM_Parallel(x, lambda)
FastGGM_edgs(x, pairs, lambda)

Arguments

Details

FastGGM and FastGGM_Parallel are used for construct global Gaussian graphical model with one and multiple CPUs. FastGGM_edges is used for analyzing specified edges (variable pairs) conditionally on all other variables.

Values

Example:

# Simulate a sparse precision matrix Omega and sample a data matrix X based on it:
library(MASS) 
prop <- 0.02  # Sparseness
p <- 100  # Number of variables
n <- 50  # Number of samples
for(k in 1:100){
  Omega0.tmp <- matrix(sample(c(0.3, 0.6, 1), p*p, replace=T), p, p)*matrix(rbinom(p*p, 1, prop), p, p) 
  Omega0 <- Omega0.tmp 
  for(i in 1:(p-1)){
    for(j in (i+1):p){
      Omega0[j, i] <- Omega0.tmp[i, j]    
    }    
  } 
  p_prime <- p/2
  Omega <- Omega0
  Omega[(p_prime+1):(2*p_prime), (p_prime+1):(2*p_prime)] <- 2*Omega0[1:p_prime,1:p_prime]
  diag(Omega) <- c(rep(4, p_prime), rep(8, p_prime))
  eigenvalue <- eigen(Omega)$values
  ratio <- max(eigenvalue)/min(eigenvalue)
  cat(k, max(eigenvalue), min(eigenvalue), ratio, '\n')
  if(ratio > 0){
    break
  }
}
cov <- solve(Omega)
X <- mvrnorm(n, rep(0, p), cov)

# Run FastGGM
library(FastGGM)
outlist1 <- FastGGM(X)

library(RcppParallel)
setThreadOptions(numThreads = 4) # set 4 threads for parallel computing
# If not use the above two commands, it will automatically use all available CPUs
outlist2 <- FastGGM_Parallel(X)

# To calculate for edges/variable pairs (1,4), (2,5) and (3,6)
pairs <- matrix(1:6, ncol=2)
outlist3 <- FastGGM_edges(X, pairs)
}

Publications

Contact

Ting Wang (email), Zhao Ren (email), Wei Chen (email).