bdgraph function

Search algorithm in graphical models

Search algorithm in graphical models

As the main function of the BDgraph package, this function consists of several MCMC sampling algorithms for Bayesian model determination in undirected graphical models.

To speed up the computations, the birth-death MCMC sampling algorithms are implemented in parallel using OpenMP in C++.

bdgraph( data, n = NULL, method = "ggm", algorithm = "bdmcmc", iter = 5000, burnin = iter / 2, not.cont = NULL, g.prior = 0.2, df.prior = 3, g.start = "empty", jump = NULL, save = FALSE, cores = NULL, threshold = 1e-8, verbose = TRUE, nu = 1 )

Arguments

  • data: there are two options: (1) an (n×pn \times p) matrix or a data.frame corresponding to the data, (2) an (p×pp \times p) covariance matrix as S=XXS=X'X which XX is the data matrix (nn is the sample size and pp is the number of variables). It also could be an object of class "sim", from function bdgraph.sim. The input matrix is automatically identified by checking the symmetry.
  • n: number of observations. It is needed if the "data" is a covariance matrix.
  • method: character with two options "ggm" (default) and "gcgm". Option "ggm" is for Gaussian graphical models based on Gaussianity assumption. Option "gcgm" is for Gaussian copula graphical models for the data that not follow Gaussianity assumption (e.g. continuous non-Gaussian, count, or mixed dataset).
  • algorithm: character with two options "bdmcmc" (default) and "rjmcmc". Option "bdmcmc" is based on birth-death MCMC algorithm. Option "rjmcmc" is based on reverible jump MCMC algorithm. Option "bd-dmh" is based on birth-death MCMC algorithm using double Metropolis Hasting. Option "rj-dmh" is based on reverible jump MCMC algorithm using double Metropolis Hasting.
  • iter: number of iteration for the sampling algorithm.
  • burnin: number of burn-in iteration for the sampling algorithm.
  • not.cont: for the case method = "gcgm", a vector with binary values in which 11 indicates not continuous variables.
  • g.prior: for determining the prior distribution of each edge in the graph. There are two options: a single value between 00 and 11 (e.g. 0.50.5 as a noninformative prior) or an (p×pp \times p) matrix with elements between 00 and 11.
  • df.prior: degree of freedom for G-Wishart distribution, WG(b,D)W_G(b,D), which is a prior distribution of the precision matrix.
  • g.start: corresponds to a starting point of the graph. It could be an (p×pp \times p) matrix, "empty" (default), or "full". Option "empty" means the initial graph is an empty graph and "full" means a full graph. It also could be an object with S3 class "bdgraph" of R package BDgraph or the class "ssgraph" of R package ssgraph::ssgraph(); this option can be used to run the sampling algorithm from the last objects of previous run (see examples).
  • jump: it is only for the BDMCMC algorithm (algorithm = "bdmcmc"). It is for simultaneously updating multiple links at the same time to update graph in the BDMCMC algorithm.
  • save: logical: if FALSE (default), the adjacency matrices are NOT saved. If TRUE, the adjacency matrices after burn-in are saved.
  • cores: number of cores to use for parallel execution. The case cores = "all" means all CPU cores to use for parallel execution.
  • threshold: threshold value for the convergence of sampling algorithm from G-Wishart for the precision matrix.
  • verbose: logical: if TRUE (default), report/print the MCMC running time.
  • nu: prior parameter for option method = "tgm".

Returns

An object with S3 class "bdgraph" is returned:

  • p_links: upper triangular matrix which corresponds the estimated posterior probabilities of all possible links.

  • K_hat: posterior estimation of the precision matrix.

For the case "save = TRUE" is returned:

  • sample_graphs: vector of strings which includes the adjacency matrices of visited graphs after burn-in.

  • graph_weights: vector which includes the waiting times of visited graphs after burn-in.

  • all_graphs: vector which includes the identity of the adjacency matrices for all iterations after burn-in. It is needed for monitoring the convergence of the BD-MCMC algorithm.

  • all_weights: vector which includes the waiting times for all iterations after burn-in. It is needed for monitoring the convergence of the BD-MCMC algorithm.

References

Mohammadi, R. and Wit, E. C. (2019). BDgraph: An R Package for Bayesian Structure Learning in Graphical Models, Journal of Statistical Software, 89(3):1-30, tools:::Rd_expr_doi("10.18637/jss.v089.i03")

Mohammadi, A. and Wit, E. C. (2015). Bayesian Structure Learning in Sparse Gaussian Graphical Models, Bayesian Analysis, 10(1):109-138, tools:::Rd_expr_doi("10.1214/14-BA889")

Mohammadi, R., Massam, H. and Letac, G. (2023). Accelerating Bayesian Structure Learning in Sparse Gaussian Graphical Models, Journal of the American Statistical Association, tools:::Rd_expr_doi("10.1080/01621459.2021.1996377")

Mohammadi, A. et al (2017). Bayesian modelling of Dupuytren disease by using Gaussian copula graphical models, Journal of the Royal Statistical Society: Series C, 66(3):629-645, tools:::Rd_expr_doi("10.1111/rssc.12171")

Dobra, A. and Mohammadi, R. (2018). Loglinear Model Selection and Human Mobility, Annals of Applied Statistics, 12(2):815-845, tools:::Rd_expr_doi("10.1214/18-AOAS1164")

Vogels, L., Mohammadi, R., Schoonhoven, M., and Birbil, S.I. (2023) Bayesian Structure Learning in Undirected Gaussian Graphical Models: Literature Review with Empirical Comparison, arXiv preprint, tools:::Rd_expr_doi("10.48550/arXiv.2307.02603")

Mohammadi, R., Schoonhoven, M., Vogels, L., and Birbil, S.I. (2023) Large-scale Bayesian Structure Learning for Gaussian Graphical Models using Marginal Pseudo-likelihood, arXiv preprint, tools:::Rd_expr_doi("10.48550/arXiv.2307.00127")

Mohammadi, A. and Dobra A. (2017). The R Package BDgraph for Bayesian Structure Learning in Graphical Models, ISBA Bulletin, 24(4):11-16

Author(s)

Reza Mohammadi a.mohammadi@uva.nl and Ernst Wit

See Also

bdgraph.mpl, bdgraph.dw, bdgraph.sim, summary.bdgraph, compare

Examples

## Not run: set.seed( 10 ) # - - Example 1 # Generating multivariate normal data from a 'random' graph data.sim <- bdgraph.sim( n = 100, p = 10, size = 15, vis = TRUE ) bdgraph.obj <- bdgraph( data = data.sim, iter = 1000, save = TRUE ) summary( bdgraph.obj ) # Confusion Matrix conf.mat( actual = data.sim, pred = bdgraph.obj ) conf.mat.plot( actual = data.sim, pred = bdgraph.obj ) # To compare our result with true graph compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ), vis = T ) # Running algorithm with starting points from previous run bdgraph.obj2 <- bdgraph( data = data.sim, g.start = bdgraph.obj ) compare( list( bdgraph.obj, bdgraph.obj2 ), data.sim, main = c( "Target", "Frist run", "Second run" ) ) # - - Example 2 # Generating mixed data from a 'scale-free' graph data.sim <- bdgraph.sim( n = 200, p = 7, type = "mixed", graph = "scale-free", vis = TRUE ) bdgraph.obj <- bdgraph( data = data.sim, method = "gcgm" ) summary( bdgraph.obj ) compare( bdgraph.obj, data.sim, vis = T ) conf.mat( actual = data.sim, pred = bdgraph.obj ) conf.mat.plot( actual = data.sim, pred = bdgraph.obj ) ## End(Not run)