amatType: Types and Display of Adjacency Matrices in Package 'pcalg'

Description Arguments Details See Also Examples

Description

Two types of adjacency matrices are used in package pcalg: Type amat.cpdag for DAGs and CPDAGs and type amat.pag for MAGs and PAGs. The required type of adjacency matrix is documented in the help files of the respective functions or classes. If in some functions more detailed information on the graph type is needed (i.e. DAG or CPDAG; MAG or PAG) this information will be passed in a separate argument (see e.g. gac and the examples below).

Note that you get (‘extract’) such adjacency matrices as (S3) objects of class "amat" via the usual as(., "<class>") coercion,

1
  as(from, "amat")

Arguments

from

an R object of

class pcAlgo, as returned from skeleton() or pc() or an object of

class fciAlgo, as from fci() (or rfci, fciPlus, and dag2pag), or an object of

class "LINGAM" as returned from lingam().

Details

Adjacency matrices are integer valued square matrices with zeros on the diagonal. They can have row- and columnnames; however, most functions will work on the (integer) column positions in the adjacency matrix.

Coding for type amat.cpdag:

0:

No edge or tail

1:

Arrowhead

Note that the edgemark-code refers to the row index (as opposed adjacency matrices of type mag or pag). E.g.:

1
2
3
4
    amat[a,b] = 0  and  amat[b,a] = 1   implies a --> b.
    amat[a,b] = 1  and  amat[b,a] = 0   implies a <-- b.
    amat[a,b] = 0  and  amat[b,a] = 0   implies a     b.
    amat[a,b] = 1  and  amat[b,a] = 1   implies a --- b.

Coding for type amat.pag:

0:

No edge

1:

Circle

2:

Arrowhead

3:

Tail

Note that the edgemark-code refers to the column index (as opposed adjacency matrices of type dag or cpdag). E.g.:

1
2
3
4
5
  amat[a,b] = 2  and  amat[b,a] = 3   implies   a --> b.
  amat[a,b] = 3  and  amat[b,a] = 2   implies   a <-- b.
  amat[a,b] = 2  and  amat[b,a] = 2   implies   a <-> b.
  amat[a,b] = 1  and  amat[b,a] = 3   implies   a --o b.
  amat[a,b] = 0  and  amat[b,a] = 0   implies   a     b.

See Also

E.g. gac for a function which takes an adjacency matrix as input; fciAlgo for a class which has an adjacency matrix in one slot.

getGraph(x) extracts the graph object from x, whereas as(*, "amat") gets the corresponding adjacency matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##################################################
## Function gac() takes an adjecency matrix of
## any kind as input.  In addition to that, the
## precise type of graph (DAG/CPDAG/MAG/PAG) needs
## to be passed as a different argument
##################################################
## Adjacency matrix of type 'amat.cpdag'
m1 <- matrix(c(0,1,0,1,0,0, 0,0,1,0,1,0, 0,0,0,0,0,1,
               0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), 6,6)
## more detailed information on the graph type needed by gac()
gac(m1, x=1,y=3, z=NULL, type = "dag")

## Adjacency matrix of type 'amat.cpdag'
m2 <- matrix(c(0,1,1,0,0,0, 1,0,1,1,1,0, 0,0,0,0,0,1,
               0,1,1,0,1,1, 0,1,0,1,0,1, 0,0,0,0,0,0), 6,6)
## more detailed information on the graph type needed by gac()
gac(m2, x=3, y=6, z=c(2,4), type = "cpdag")

## Adjacency matrix of type 'amat.pag'
m3 <- matrix(c(0,2,0,0, 3,0,3,3, 0,2,0,3, 0,2,2,0), 4,4)
## more detailed information on the graph type needed by gac()
mg3 <- gac(m3, x=2, y=4, z=NULL, type = "mag")
pg3 <- gac(m3, x=2, y=4, z=NULL, type = "pag")


############################################################
## as(*, "amat") returns an adjacency matrix incl. its type
############################################################
## Load predefined data
data(gmG)
n <- nrow    (gmG8$x)
V <- colnames(gmG8$x)

## define sufficient statistics
suffStat <- list(C = cor(gmG8$x), n = n)
## estimate CPDAG
skel.fit <- skeleton(suffStat, indepTest = gaussCItest,
                     alpha = 0.01, labels = V)
## Extract the "amat" [and show nicely via  'print()' method]:
as(skel.fit, "amat")

##################################################
## Function fci() returns an adjacency matrix
## of type amat.pag as one slot.
##################################################
set.seed(42)
p <- 7
## generate and draw random DAG :
myDAG <- randomDAG(p, prob = 0.4)

## find skeleton and PAG using the FCI algorithm
suffStat <- list(C = cov2cor(trueCov(myDAG)), n = 10^9)
res <- fci(suffStat, indepTest=gaussCItest,
           alpha = 0.9999, p=p, doPdsep = FALSE)
str(res)
## get the a(djacency) mat(rix)  and nicely print() it:
as(res, "amat")

##################################################
## pcAlgo object
##################################################
## Load predefined data
data(gmG)
n <- nrow    (gmG8$x)
V <- colnames(gmG8$x)

## define sufficient statistics
suffStat <- list(C = cor(gmG8$x), n = n)
## estimate CPDAG
skel.fit <- skeleton(suffStat, indepTest = gaussCItest,
                     alpha = 0.01, labels = V)
## Extract Adjacency Matrix - and print (via method 'print.amat'):
as(skel.fit, "amat")

pc.fit <- pc(suffStat, indepTest = gaussCItest,
             alpha = 0.01, labels = V)
pc.fit # (using its own print() method 'print.pcAlgo')

as(pc.fit, "amat")

Example output

$gac
[1] TRUE

$res
[1] TRUE TRUE TRUE

$f
[1] 2 3 5 6

$gac
[1] TRUE

$res
[1] TRUE TRUE TRUE

$f
[1] 6

Adjacency Matrix 'amat' (8 x 8) of type 'cpdag':
       Author Bar Ctrl Goal V5 V6 V7 V8
Author      .   1    .    .  .  1  .  1
Bar         1   .    1    .  1  .  .  .
Ctrl        .   1    .    .  .  .  .  .
Goal        .   .    .    .  .  .  .  .
V5          .   1    .    .  .  1  .  1
V6          1   .    .    .  1  .  1  .
V7          .   .    .    .  .  1  .  .
V8          1   .    .    .  1  .  .  .
Formal class 'fciAlgo' [package "pcalg"] with 10 slots
  ..@ amat            : num [1:7, 1:7] 0 0 1 0 1 1 3 0 0 0 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:7] "1" "2" "3" "4" ...
  .. .. ..$ : chr [1:7] "1" "2" "3" "4" ...
  ..@ allPdsep        :List of 7
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ n.edgetestsPDSEP: num 0
  ..@ max.ordPDSEP    : int 0
  ..@ call            : language fci(suffStat = suffStat, indepTest = gaussCItest, alpha = 0.9999, p = p,      doPdsep = FALSE)
  ..@ n               : int(0) 
  ..@ max.ord         : int 5
  ..@ n.edgetests     : num [1:6] 39 142 198 151 37 0
  ..@ sepset          :List of 7
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : int(0) 
  .. .. ..$ : NULL
  .. .. ..$ : int 3
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : int(0) 
  .. .. ..$ : int(0) 
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : int 3
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : int [1:3] 1 2 3
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. ..$ :List of 7
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : int [1:4] 1 2 3 6
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  .. .. ..$ : NULL
  ..@ pMax            : num [1:7, 1:7] 1 1 0 1 0 0 0 1 1 1 ...
Adjacency Matrix 'amat' (7 x 7) of type 'pag':
  1 2 3 4 5 6 7
1 . . 1 . 2 2 2
2 . . . . 2 2 2
3 1 . . 1 2 2 2
4 . . 1 . . 2 .
5 1 1 1 . . . 2
6 1 1 1 1 . . 2
7 3 3 3 . 1 3 .
Adjacency Matrix 'amat' (8 x 8) of type 'cpdag':
       Author Bar Ctrl Goal V5 V6 V7 V8
Author      .   1    .    .  .  1  .  1
Bar         1   .    1    .  1  .  .  .
Ctrl        .   1    .    .  .  .  .  .
Goal        .   .    .    .  .  .  .  .
V5          .   1    .    .  .  1  .  1
V6          1   .    .    .  1  .  1  .
V7          .   .    .    .  .  1  .  .
V8          1   .    .    .  1  .  .  .
Object of class 'pcAlgo', from Call:
pc(suffStat = suffStat, indepTest = gaussCItest, alpha = 0.01, 
    labels = V)
Number of undirected edges:  2 
Number of directed edges:    6 
Total number of edges:       8 
Adjacency Matrix 'amat' (8 x 8) of type 'cpdag':
       Author Bar Ctrl Goal V5 V6 V7 V8
Author      .   1    .    .  .  .  .  .
Bar         1   .    1    .  .  .  .  .
Ctrl        .   1    .    .  .  .  .  .
Goal        .   .    .    .  .  .  .  .
V5          .   1    .    .  .  .  .  .
V6          1   .    .    .  1  .  .  .
V7          .   .    .    .  .  1  .  .
V8          1   .    .    .  1  .  .  .

pcalg documentation built on June 5, 2018, 1:05 a.m.