algstat (version 0.0.2)

hmat: Construct a Hierarchical Model Matrix

Description

Determine the A matrix associated with a hierarchical model on a contingency table. In algebraic statistics, the A matrix of a log-linear model is the transpose of the design matrix of the (cell-means parameterized) ANOVA corresponding to the model.

Usage

hmat(varlvls, facets)

Arguments

varlvls
a vector containing the number of levels of each variable
facets
the facets generating the hierarchical model, a list of vectors of variable indices

Value

a named matrix

References

Drton, M., B. Sturmfels, and S. Sullivant (2009). Lectures on Algebraic Statistics, Basel: Birkhauser Verlag AG.

Examples

Run this code
# LAS example 1.2.11, p.16
varlvls <- c(2,2,2,2)
facets <- list(c(1,2), c(1,4), c(2,3))
( A <- hmat(varlvls, facets) )

# 2x2 independence example
# following convention, the first index indicates rows
varlvls <- c(2,2)
facets <- list(1,2)
( A <- hmat(varlvls, facets) )

printForMarkov <- function(A){
  cat(paste(nrow(A), ncol(A)))
  cat("\n")
  cat(apply(unname(A), 1, paste, collapse = " "), sep = "\n")
  cat("\n")
}
printForMarkov(A)

Run the code above in your browser using DataCamp Workspace