Macaulay2 » Documentation
Packages » GraphicalModels :: covarianceMatrix
next | previous | forward | backward | up | index | toc

covarianceMatrix -- covariance matrix of a Gaussian graphical model

Synopsis

Description

This method returns the $n \times{} n$ covariance matrix of the Gaussian graphical model where $n$ is the number of random variables in the model. If the gaussianRing was created using a graph, $n$ will be the number of vertices of the graph. If this function is called without a graph $G$, it is assumed that $R$ is the gaussianRing of a directed acyclic graph.

i1 : compactMatrixForm =false;
i2 : covarianceMatrix gaussianRing 4

o2 = |  s     s     s     s     |
     |   1,1   1,2   1,3   1,4  |
     |                          |
     |  s     s     s     s     |
     |   1,2   2,2   2,3   2,4  |
     |                          |
     |  s     s     s     s     |
     |   1,3   2,3   3,3   3,4  |
     |                          |
     |  s     s     s     s     |
     |   1,4   2,4   3,4   4,4  |

                                                          4                                                   4
o2 : Matrix (QQ[s   ..s   , s   ..s   , s   ..s   , s   ])  <-- (QQ[s   ..s   , s   ..s   , s   ..s   , s   ])
                 1,1   1,4   2,2   2,4   3,3   3,4   4,4             1,1   1,4   2,2   2,4   3,3   3,4   4,4
i3 : G = digraph {{a,{b,c}}, {b,{c,d}}, {c,{}}, {d,{}}}

o3 = Digraph{a => {c, b}}
             b => {c, d}
             c => {}
             d => {}

o3 : Digraph
i4 : R = gaussianRing G

o4 = R

o4 : PolynomialRing
i5 : S = covarianceMatrix R

o5 = |  s     s     s     s     |
     |   a,a   a,b   a,c   a,d  |
     |                          |
     |  s     s     s     s     |
     |   a,b   b,b   b,c   b,d  |
     |                          |
     |  s     s     s     s     |
     |   a,c   b,c   c,c   c,d  |
     |                          |
     |  s     s     s     s     |
     |   a,d   b,d   c,d   d,d  |

             4      4
o5 : Matrix R  <-- R

This function also works for gaussianRings created with a graph or mixedGraph.

i6 : G = graph({{a,b},{b,c},{c,d},{a,d}})

o6 = Graph{a => {b, d}}
           b => {a, c}
           c => {b, d}
           d => {a, c}

o6 : Graph
i7 : R = gaussianRing G

o7 = R

o7 : PolynomialRing
i8 : S = covarianceMatrix R

o8 = |  s     s     s     s     |
     |   a,a   a,b   a,c   a,d  |
     |                          |
     |  s     s     s     s     |
     |   a,b   b,b   b,c   b,d  |
     |                          |
     |  s     s     s     s     |
     |   a,c   b,c   c,c   c,d  |
     |                          |
     |  s     s     s     s     |
     |   a,d   b,d   c,d   d,d  |

             4      4
o8 : Matrix R  <-- R
i9 : G = mixedGraph(digraph {{b,{c,d}},{c,{d}}},bigraph {{a,d}})

o9 = MixedGraph{Bigraph => Bigraph{a => {d}}   }
                                   d => {a}
                Digraph => Digraph{b => {c, d}}
                                   c => {d}
                                   d => {}
                Graph => Graph{}

o9 : MixedGraph
i10 : R = gaussianRing G

o10 = R

o10 : PolynomialRing
i11 : S = covarianceMatrix R

o11 = |  s     s     s     s     |
      |   a,a   a,b   a,c   a,d  |
      |                          |
      |  s     s     s     s     |
      |   a,b   b,b   b,c   b,d  |
      |                          |
      |  s     s     s     s     |
      |   a,c   b,c   c,c   c,d  |
      |                          |
      |  s     s     s     s     |
      |   a,d   b,d   c,d   d,d  |

              4      4
o11 : Matrix R  <-- R

See also

Ways to use covarianceMatrix :

For the programmer

The object covarianceMatrix is a method function.