**BCDAG** (**B**ayesian
**C**ausal **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

The package can be installed executing the following code:

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

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.

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

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

We can use the function `learn_DAG()`

to perform causal
structure learning from the generated observational dataset:

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

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

- Alessandro Mascaro, Departament dâ€™Economia i Empresa, Universitat Pompeu Fabra, Barcelona, alessandro.mascaro@upf.edu
- Federico Castelletti, Department of Statistical sciences, UniversitĂ Cattolica del Sacro Cuore, Milan, federico.castelletti@unicatt.it