Implements a Bayesian approach for inference on mixed graphical models. Estimates conditional independencies between variables of mixed types (continuous, discrete, categorical, zero-inflated count data) using an MCMC algorithm for posterior inference.

bmgm(
  X,
  type,
  nburn = 1000,
  nsample = 1000,
  theta_priors,
  v_0 = 0.05,
  v_1 = 1,
  pi_beta,
  seed,
  context_spec = TRUE,
  bfdr = 0.05,
  cont = FALSE,
  verbose = TRUE,
  ...
)

Arguments

X

A numeric matrix or data frame containing the data (mixed type variables). Categorical variables (type "m") must be coded as positive integers (1, 2, ..., K), where K is the number of categories. Category 1 is used as the reference level.

type

A character vector indicating the type of each variable. Options: "c" (continuous), "d" (discrete), "z" (zero-inflated count), "m" (categorical).

nburn

Number of burn-in iterations for MCMC. Default is 1000.

nsample

Number of MCMC samples to collect after burn-in. Default is 1000.

theta_priors

List of priors for node parameters.

v_0

Prior variance for the spike in spike-and-slab. Default is 0.05.

v_1

Prior variance for the slab in spike-and-slab. Default is 1.

pi_beta

Prior probability of edge inclusion. Default is `2/(p-1)`.

seed

Random seed for reproducibility.

context_spec

Logical, whether to compute the context-specific adjacency matrix. Default is TRUE.

bfdr

Bayesian False Discovery Rate threshold for edge selection. Default is 0.05.

cont

Logical, whether to transform continuous variables. Default is FALSE.

verbose

Logical, whether to display a progress bar during MCMC sampling. Default is TRUE.

...

Additional arguments.

Value

A list containing:

post_Beta

Posterior samples of the precision matrix.

post_theta

Posterior samples of node parameters.

post_Z

Posterior samples of edge indicators.

adj_Beta

Estimated adjacency matrix for dependencies.

adj_G

Adjacency matrix for edge selection.

lambda

Estimated transformation parameter.

Examples

# Simulated example data
set.seed(123)
n <- 100
X1 <- rpois(n, lambda = 3)
X2 <- rnorm(n, mean = 5)
X3 <- rnorm(n, mean = X2)
X4 <- rnorm(n, mean = X1)
X <- cbind(X1,X2,X3,X4)
type <- c("d", "c", "c", "c")

# \donttest{
# Fit Bayesian Mixed Graphical Model
fit <- bmgm(X, type, nburn = 1000, nsample = 2000)

# Print adjacency matrix
print(fit$adj_G)
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    1    1
#> [2,]    0    0    1    0
#> [3,]    1    1    0    0
#> [4,]    1    0    0    0
# }