hmat: Construct a Hierarchical Model Matrix

View source: R/hmat.r

hmatR Documentation

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.

See Also

genmodel()

Examples


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

# alternatively:
hmat(c(2, 2), 1:2)


# facets = list() returns the matrix that computes the sample size of the table
( A <- hmat(varlvls, list()) )


# 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) )

cat(format_latte(A))


dkahle/algstat documentation built on May 23, 2023, 12:29 a.m.