get_edgeprobs {BCDAG} | R Documentation |
This function computes the posterior probability of inclusion for each edge u -> v
given the MCMC output of learn_DAG
;
get_edgeprobs(learnDAG_output)
learnDAG_output |
object of class |
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 posterior probability of inclusion of u -> v
is estimated as the frequency of DAGs visited by the MCMC which contain the directed edge u -> v
.
Posterior probabilities are collected in a (q,q)
matrix with (u,v)
-element representing the estimated posterior probability
of edge u -> v
.
A (q,q)
matrix with posterior probabilities of edge inclusion
Federico Castelletti and Alessandro Mascaro
F. Castelletti and A. Mascaro (2021). Structural learning and estimation of joint causal effects among network-dependent variables. Statistical Methods and Applications, Advance publication.
# 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)
# Generate observations from a Gaussian DAG-model
n = 200
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 = 0.1,
fast = TRUE, save.memory = FALSE)
# Compute posterior probabilities of edge inclusion
get_edgeprobs(out_mcmc)