knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package allows for the construction, manipulation and testing of independence models represented by imsets.
An imset is an integer-valued multiset, or a function from the powerset of a collection of variables $V$ to the integers. They can be used to represent arbitrary conditional independence models, by assessing whether or not certain imsets are structural.
The identifier imset $\delta_A$ is a vector indexed by subsets of $V$ with a 1 in the entry that corresponds to $A$, and 0 in all other entries.
A semi-elementary imset is isomorphic to a triple $A,B,C$ of disjoint sets where the order of the first two elements is arbitrary. It is defined as \begin{align} u_{\langle A,B | C\rangle} := \delta_{C} - \delta_{AC} - \delta_{BC} + \delta_{ABC} \end{align}
An imset $u$ is said to be structural if there is some natural number $k \in \mathbb{N}$ such that $k\cdot u$ can be written as a sum of semi-elementary imsets with natural numbers as coefficients. In other words, if \begin{align} \exists k \in \mathbb{N} : \qquad k \cdot u = \sum_{i} k_i \cdot u_{\langle A_i,B_i | C_i\rangle} \qquad \text{for } k_i \in \mathbb{N}. \label{eqn:struc} \end{align} An imset is said to represent an independence $A \perp B \mid C$ if there exists a $k \in \mathbb{N}$ such that \begin{align} k \cdot u - u_{\langle A,B | C\rangle} \end{align} is structural. Note that therefore the imset itself must be structural, and will represent any of the independences in the expansion on the right-hand side of (\ref{eqn:struc}).
You will need the libraries rje
, contingency
and lpSolve
which are available both from
CRAN and from the GitHub page rje42
. You will also need the packages
MixedGraphs
, ADMGs2
and imset
, which are currently only available
from rje42
.
# devtools::install_github("rje42/rje") # devtools::install_github("rje42/contingency") # devtools::install_github("rje42/MixedGraphs") # devtools::install_github("rje42/ADMGs2") # devtools::install_github("rje42/imset") # devtools::install_github("rje42/lpSolve")
We can then load the package in the usual manner.
library(imset)
Then to define an imset, we can use the elem_imset
function.
elem_imset(1,2) elem_imset(1,2,4) elem_imset(1,2,4,n=6)
Note that the argument n
modifies the total number of variables, which is
otherwise assumed to be the largest number specified.
We can test whether a given imset is structural using is_structural
.
up <- elem_imset(1,2) + elem_imset(1,3,2) um <- elem_imset(1,2) - elem_imset(1,3,2) is_structural(up) is_structural(um)
Note that if the imset is structural, then a valid decomposition is returned. It is clear that this is not unique in general.
The standard imset for a DAG is defined in the usual way. We can create a
DAG using the graphCr
function from the MixedGraphs
package.
dag1 <- graphCr("1 -> 3 <- 2, 3 -> 4") u1 <- standard_imset(dag1) u1
The characteristic imset can be obtained by applying char_imset
to either the
graph or the standard imset.
We can also check whether the standard imset defines the model for the DAG.
defines_mod(dag1, u1)
And then test another imset which we know does not:
defines_mod(dag1, elem_imset(1,4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.