hmat: Construct a Hierarchical Model Matrix

Description Usage Arguments Value References Examples

View source: R/hmat.r

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 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)

algstat documentation built on May 29, 2017, 10:34 p.m.

Related to hmat in algstat...