DAG: Directed acyclic graphs (DAGs)

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

A simple way to define a DAG by means of regression model formulae.

Usage

1

Arguments

...

a sequence of model formulae

order

logical, defaulting to FALSE. If TRUE the nodes of the DAG are permuted according to the topological order. If FALSE the nodes are in the order they first appear in the model formulae (from left to right).

Details

The DAG is defined by a sequence of recursive regression models. Each regression is defined by a model formula. For each formula the response defines a node of the graph and the explanatory variables the parents of that node. If the regressions are not recursive the function returns an error message.

Some authors prefer the terminology acyclic directed graphs (ADG).

Value

the adjacency matrix of the DAG, i.e. a square Boolean matrix of order equal to the number of nodes of the graph and a one in position (i,j) if there is an arrow from i to j and zero otherwise. The rownames of the adjacency matrix are the nodes of the DAG.

If order = TRUE the adjacency matrix is permuted to have parents before children. This can always be done (in more than one way) for DAGs. The resulting adjacency matrix is upper triangular.

Note

The model formulae may contain interactions, but they are ignored in the graph.

Author(s)

G. M. Marchetti

References

Lauritzen, S. (1996). Graphical models. Oxford: Clarendon Press.

See Also

UG, topSort, edgematrix, fitDag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## A Markov chain
DAG(y ~ x, x ~ z, z ~ u)

## Another DAG
DAG(y ~ x + z + u, x ~ u, z ~ u)

## A DAG with an isolated node
DAG(v ~ v, y ~ x + z, z ~ w + u)

## There can be repetitions
DAG(y ~ x + u + v, y ~ z, u ~ v + z)

## Interactions are ignored
DAG(y ~ x*z + z*v, x ~ z)

## A cyclic graph returns an error!
## Not run: DAG(y ~ x, x ~ z, z ~ y)

## The order can be changed
DAG(y ~ z, y ~ x + u + v,  u ~ v + z)

## If you want to order the nodes (topological sort of the DAG)
DAG(y ~ z, y ~ x + u + v,  u ~ v + z, order=TRUE)

Example output

Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union


Attaching package: 'ggm'

The following object is masked from 'package:igraph':

    pa

  y x z u
y 0 0 0 0
x 1 0 0 0
z 0 1 0 0
u 0 0 1 0
  y x z u
y 0 0 0 0
x 1 0 0 0
z 1 0 0 0
u 1 1 1 0
  v y x z w u
v 0 0 0 0 0 0
y 0 0 0 0 0 0
x 0 1 0 0 0 0
z 0 1 0 0 0 0
w 0 0 0 1 0 0
u 0 0 0 1 0 0
  y x u v z
y 0 0 0 0 0
x 1 0 0 0 0
u 1 0 0 0 0
v 1 0 1 0 0
z 1 0 1 0 0
  y x z v
y 0 0 0 0
x 1 0 0 0
z 1 1 0 0
v 1 0 0 0
  y z x u v
y 0 0 0 0 0
z 1 0 0 1 0
x 1 0 0 0 0
u 1 0 0 0 0
v 1 0 0 1 0
  v x z u y
v 0 0 0 1 1
x 0 0 0 0 1
z 0 0 0 1 1
u 0 0 0 0 1
y 0 0 0 0 0

ggm documentation built on March 26, 2020, 7:49 p.m.

Related to DAG in ggm...