GithubHelp home page GithubHelp logo

haowang47 / fastggm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wt2015-github/fastggm

0.0 1.0 0.0 50 KB

An efficient R package for the inference of Gaussian graphical model

Home Page: http://wt2015-github.github.io/FastGGM/

R 1.08% C++ 98.92%

fastggm's Introduction

FastGGM

An efficient R (Rcpp) package for the inference of Gaussian graphical model.

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

  • x: a n*p matrix with n samples and p variables.
  • pairs: a 2-column matrix of variable index for edges (variable pairs), each row has two indexes of a variable pair, start from 1. Note if only one edge, it should be a 1*2 matrix.
  • lambda: penalty parameter in Lasso regression, larger lambda results in faster calculation and a sparser graph, if don't set then use default sqrt(2*log(p/sqrt(n))/n).

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

  • precision: a matrix of precision for the GGM or a vector of precision for the variable pairs.
  • p_precision: a matrix of p-value for the precision matrix or a vector of p-value for the precision of the variable pairs.
  • partialCor: a matrix of partial correlation for the GGM or a vector of partial correlation for the vairable pairs.
  • p_partialCor: a matrix of p-value for the partial correlation matrix or a vector of p-value for the partial correlation of the variable pairs.
  • CI_low_parCor: a matrix of lower value of 95% confidence interval for partial correlation of the GGM or a vector of lower value of 95% confidence interval for partial correlation of the variable pairs.
  • CI_high_parCor: a matrix of higher value of 95% confidence interval for partial correlation or a vector of higher value of 95% confidence interval for partial correlation for the variable pairs.

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

  • Wang, Ting et al. "FastGGM: An efficient algorithm for the inference of Gaussian graphical model in biological networks." PloS Computational Biology 12.2 (2016): e1004755.
  • Ren, Zhao, et al. "Asymptotic normality and optimalities in estimation of large Gaussian graphical models." The Annals of Statistics 43.3 (2015): 991-1026.

Contact

Ting Wang ([email protected]), Zhao Ren ([email protected]), Wei Chen ([email protected]).

fastggm's People

Contributors

wt2015-github avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.