Given data and a topological ordering of the causal graph this function will estimate the causal graph itself.

graph_from_top(X, top, measure = "deviance", which = "1se")

Arguments

X

A matrix containing the observed variables

top

A topological ordering of the variables

measure

Either "mse", "mae"

which

Either "min" or "1se"

Value

the coefficient graph estimated from the data. This is a graph which has values different from zero iff there is an arrow in the estimated causal graph. The values of the non-zero entries in this matrix are the estimated (causal) effects.

Details

To estimate the graph, the parents of each variable is fund via model selection. As the underlying grap is assumed to be a DAG the parents of a variable \(X_{(j)}\) must be found among the variables with a lower ordering \((X_{(i)})_{i<j}\).

All model selection is done via cross-validation lasso.

See also

The wrapper function graph_est combines the function top_order, which estimates the topological ordering of the causal graph from data, and graph_from_top into one function that estimates the causal graph from the data.

Examples

# we create some data from the graph B n <- 1000 B <- matrix(c(0,1,0,1, 0,0,2,0, 0,0,0,1, 0,0,0,0), ncol = 4, nrow = 4, byrow = TRUE) X <- matrix(0, ncol = 4, nrow = n) for (i in 1:4) { X[ ,i] <- X %*% B[ ,i] + rnorm(n) } # we then find the graph using a topological ordering top <- c(1,2,3,4) # from B we know this to be the true ordering graph_from_top(X, top)
#> [,1] [,2] [,3] [,4] #> [1,] 0 0.8393626 0.000000 0.9290599 #> [2,] 0 0.0000000 1.887375 0.0000000 #> [3,] 0 0.0000000 0.000000 0.9639889 #> [4,] 0 0.0000000 0.000000 0.0000000