An R package for simulating positive definite matrices constrained by acyclic directed and undirected graphs.

Build Status codecov Lifecycle: maturing CRAN downloads CRAN status

Installation

The package is available on CRAN, to get the latest stable version use:

Alternatively, using the R package devtools one may install the development version:

The only R package required for gmat is igraph, which can also be installed from CRAN.

An example of use

First, we generate a random undirected graph with 3 nodes and density 0.5. Then we generate, using our port() function, 2 matrices consistent with such random graphical structure.

We appreciate how the zero pattern is shared by all of the simulated matrices. The return value is an array, and so the individual matrices can be accessed as matrices[, , n], where n is the index of the matrix we want to retrieve from the sample, ranging from 1 to N.

We may also sample correlation matrices using i.i.d. coefficients in their upper Cholesky factor U.

A specific zero pattern can be enforced in U using an acyclic digraph.

See more examples and paper references at the documentation website for the package.