MyNixOS website logo
Description

Bayesian Structure and Causal Learning of Gaussian Directed Graphs.

A collection of functions for structure learning of causal networks and estimation of joint causal effects from observational Gaussian data. Main algorithm consists of a Markov chain Monte Carlo scheme for posterior inference of causal structures, parameters and causal effects between variables. References: F. Castelletti and A. Mascaro (2021) <doi:10.1007/s10260-021-00579-1>, F. Castelletti and A. Mascaro (2022) <doi:10.48550/arXiv.2201.12003>.

Overview

BCDAG (Bayesian Causal DAG) is a package for Bayesian DAG structure learning and causal effect estimation from observational Gaussian data.

The methodology implemented has been presented in Castelletti, F. & Mascaro, A. (2021). Structural learning and estimation of joint causal effects among network-dependent variables, Statistical Methods & Applications, 1-26

Installation

The package can be installed executing the following code:

# install.packages("devtools")
devtools::install_github("alesmascaro/BCDAG")

How to use

The workflow of the package consists of two sequential steps: causal structure learning, performed through the function learn_DAG() and causal effect estimation, performed through the function get_causaleffect(). For a more detailed description of the inner mechanisms of these two functions, we refer the reader to the vignettes.

Example

Before using the two main functions of the package, we generate some data:

library(BCDAG)
# Randomly generate a DAG and the DAG-parameters
q = 8
w = 0.2
set.seed(123)
DAG = rDAG(q = q, w = w)
outDL = rDAGWishart(n = 1, DAG = DAG, a = q, U = diag(1, q))
L = outDL$L; D = outDL$D
Sigma = solve(t(L))%*%D%*%solve(L)
n = 200
# Generate observations from a Gaussian DAG-model
X = mvtnorm::rmvnorm(n = n, sigma = Sigma)

We can use the function learn_DAG() to perform causal structure learning from the generated observational dataset:

# Run the MCMC
out = learn_DAG(S = 5000, burn = 1000, a = q, U = diag(1,q)/n, data = X, w = w)

Next, we can compute the BMA estimate of the causal effect on a response variable consequent to a hard intervention on a set of nodes by using get_causaleffect():

# the causal effect on node 1 of an intervention on {3,4}
out |>
  get_causaleffect(targets = c(3,4), response = 1)

The three steps here implemented are detailed in the vignettes 1 - Random data generation from Gaussian DAG-models, 2 - MCMC scheme for posterior inference of Gaussian DAG models: the learn_DAG() function and 3 - Elaborate on the output of learn_DAG() using get_ functions

Authors

  • Alessandro Mascaro, Departament d’Economia i Empresa, Universitat Pompeu Fabra, Barcelona, [email protected]
  • Federico Castelletti, Department of Statistical sciences, Università Cattolica del Sacro Cuore, Milan, [email protected].

R-CMD-check

Metadata

Version

1.1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows