get_causaleffect {BCDAG}R Documentation

Estimate total causal effects from the MCMC output


This function provides causal effect estimates from the output of learn_DAG


  verbose = TRUE



object of class bcdag


numerical (p,1) vector with labels of target nodes


numerical label of response variable


boolean; if TRUE, the Bayesian model averaging (BMA) estimate of the total causal effect is returned; if FALSE, samples from the posterior distribution of causal effect coefficients are returned


if TRUE, progress bar of MCMC sampling is displayed


Output of learn_dag function consists of S draws from the joint posterior of DAGs and DAG-parameters in a zero-mean Gaussian DAG-model; see the documentation of learn_DAG for more details.

The total causal effect on a given variable of interest (response) consequent to a joint intervention on a set of variables (targets) is defined according to Pearl's do-calculus theory and under the Gaussian assumption can be expressed as a function of parameters (D,L), representing a (Cholesky) reparameterization of the covariance matrix.

Specifically, to each intervened variable a causal effect coefficient is associated and the posterior distribution of the latter can be recovered from posterior draws of the DAG parameters returned by learn_DAG. For each coefficient a sample of size S from its posterior is available. If required, the only Bayesian Model Average (BMA) estimate (obtained as the sample mean of the S draws) can be returned by setting BMA = TRUE.

Notice that, whenever implemented with collapse = FALSE, learn_DAG returns the marginal posterior distribution of DAGs only. In this case, get_causaleffect preliminarily performs posterior inference of DAG parameters by drawing samples from the posterior of (D,L).


Either a (p,1) vector containing BMA causal effect estimates, or a (S,p) matrix collecting S draws from the posterior of the p causal effect coefficients.


Federico Castelletti and Alessandro Mascaro


J. Pearl (2000). Causality: Models, Reasoning, and Inference. Cambridge University Press, Cambridge.

F. Castelletti and A. Mascaro (2021) Structural learning and estimation of joint causal effects among network-dependent variables. Statistical Methods and Applications, Advance publication.

P. Nandy, M.H. Maathuis and T. Richardson (2017). Estimating the effect of joint interventions from observational data in sparse high-dimensional settings. Annals of Statistics 45(2), 647-674.


# Randomly generate a DAG and the DAG-parameters
q = 8
w = 0.2
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)
# Run the MCMC (set S = 5000 and burn = 1000 for better results)
out_mcmc = learn_DAG(S = 500, burn = 100, a = q, U = diag(1,q)/n, data = X, w = w,
                     fast = TRUE, save.memory = FALSE)
# Compute the BMA estimate of coefficients representing
# the causal effect on node 1 of an intervention on {3,4}
get_causaleffect(learnDAG_output = out_mcmc, targets = c(3,4), response = 1, BMA = TRUE)

[Package BCDAG version 1.0.0 Index]