Moralize a directed acyclic graph which means marrying parents and dropping directions.

moralize(object, ...)

# Default S3 method
moralize(object, result = NULL, ...)

Arguments

object

A directed acyclic graph represented either as a graphNEL object, an igraph, a (dense) matrix, a (sparse) dgCMatrix.

...

Additional arguments, currently not used

result

The representation of the moralized graph. When NULL the representation will be the same as the input object.

Value

A moralized graph represented either as a graphNEL, a dense matrix or a sparse dgCMatrix.

Note

The workhorse is the moralizeMAT function.

See also

Author

Søren Højsgaard, sorenh@math.aau.dk

Examples


daG <- dag(~me+ve,~me+al,~ve+al,~al+an,~al+st,~an+st)
moralize(daG)
#> IGRAPH 51bfdae UN-- 12 0 -- 
#> + attr: name (v/c), label (v/c)
#> + edges from 51bfdae (vertex names):

daG <- dag(~me+ve,~me+al,~ve+al,~al+an,~al+st,~an+st, result="matrix")
moralizeMAT(daG)
#>    me ve al an st
#> me  0  0  0  0  0
#> ve  0  0  0  0  0
#> al  0  0  0  0  0
#> an  0  0  0  0  0
#> st  0  0  0  0  0

if (require(igraph)){
M <- matrix(c(1,2,3,3), nrow=2)
G <- graph.edgelist(M)
G
V(G)$name
moralize(G)
}
#> Loading required package: igraph
#> 
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:gRbase’:
#> 
#>     edges, is_dag, topo_sort
#> The following objects are masked from ‘package:stats’:
#> 
#>     decompose, spectrum
#> The following object is masked from ‘package:base’:
#> 
#>     union
#> Warning: `graph.edgelist()` was deprecated in igraph 2.0.0.
#>  Please use `graph_from_edgelist()` instead.
#> IGRAPH ff1512d UN-- 3 3 -- 
#> + attr: name (v/c), label (v/c)
#> + edges from ff1512d (vertex names):
#> [1] 1--2 1--3 2--3