cmm (version 0.12)

DesignMatrix: DesignMatrix

Description

Returns hierarchical model design matrix

Usage

DesignMatrix(var, suffconfigs, dim, SubsetCoding = "Automatic", MakeSubsets=TRUE)

Value

matrix

Arguments

var

character or numeric vector containing variables

suffconfigs

subvector or list of subvectors of var indicating the sufficient configurations or highest order interactions in model

dim

numeric vector indicating the dimension of var (must be same length as var)

SubsetCoding

allows a (character) type or a matrix to be assigned to variables for each element of suffconfigs

, see examples

MakeSubsets

boolean, indicates whether or not to use subsets of suffconfigs (used as option in MarginaMatrix)

Author

W. P. Bergsma w.p.bergsma@lse.ac.uk

Details

The design matrix for a model \(\mu_{ij}=\alpha+\beta_{i}+\gamma_j\), where \(i\) and \(j\) each have three possible values, would be: Designmatrix(c(1,2),list(c(1),c(2)),c(3,3)). For readability, the use of characters is recommended for variable names, e.g., Designmatrix(c("A","B"),list(c("A"),c("B")),c(3,3)). The probability vector is assumed to be a vectorized form of the probabilities in a table, such that the last variable changes value fastest, then the before last variable, etc. For example, the cells of a \(2 \times 3\) table are arranged in vector form as (11,12,13,21,22,23). To achieve this, the appropriate way to vectorize a data frame dat is using c(t(ftable(dat))).

The optional argument SubsetCoding is useful for e.g.\ specifying various regression models, a linear by nominal model, grouping categories of a variable, or omitting a category. SubsetCoding has default value "Automatic", which is the same as the value "Nominal". Other options are "Linear", "Quadratic", "Cubic", "Quartic", "Quintic", "Identity".\ The command ConstraintMatrix is often more useful than DesignMatrix for specification of models for use in SampleStatistics, ModelStatistics or MarginalModelFit.

References

Bergsma, W. P. (1997). Marginal models for categorical data. Tilburg, The Netherlands: Tilburg University Press. http://stats.lse.ac.uk/bergsma/pdf/bergsma_phdthesis.pdf

Bergsma, W. P., Croon, M. A., & Hagenaars, J. A. P. (2009). Marginal models for dependent, clustered, and longitudunal categorical data. Berlin: Springer.

See Also

ConstraintMatrix, MarginalMatrix, DirectSum

Examples

Run this code

# Design matrix for independence model
var <- c("A","B")
suffconfigs <- list(c("A"),c("B"))
dim <- c(3, 3)
DesignMatrix(var,suffconfigs,dim)
# notation in one line
DesignMatrix(c("A","B"),list(c("A"),c("B")),c(3,3))


# Design matrix for saturated model, two short specifications giving same result
DesignMatrix(c("A","B"),c("A","B"),c(3,3))
DesignMatrix(c("A","B"),list(c("A","B")),c(3,3))


# Design matrix for univariate quadratic regression model
var <- c("A")
suffconfigs <- c("A")
dim <- c(5)
DesignMatrix(var,suffconfigs,dim,SubsetCoding=list(c("A"),"Quadratic"))
# notation in one line
DesignMatrix(c("A"),c("A"),c(5),SubsetCoding=list(c("A"),"Quadratic"))


# Design matrix for linear by nominal model, various methods:
# simplest method which assumes equidistant centered scores:
DesignMatrix(
 var = c("A","B"),
 suffconfigs = c("A", "B"),
 dim = c(3,3),
 SubsetCoding = list(c("A","B"),list("Linear","Nominal")))
# alternative specification with same result as above:
DesignMatrix(
 var = c("A", "B"),
 suffconfigs = c("A", "B"),
 dim = c(3, 3),
 SubsetCoding = list(c("A","B"),list(rbind(c(-1,0,1)),rbind(c(1,0,0),c(0,1,0)))))
# specifying your own category scores
scores <- c(1,2,5);
DesignMatrix(
 var = c("A","B"),
 suffconfigs = c("A","B"),
 dim = c(3, 3),
 SubsetCoding = list(c("A","B"), list(rbind(scores), "Nominal")))

# Design matrix for nominal by nominal model, equating parameters 
# of last two categories of second variable:
DesignMatrix(
 var = c("A", "B"),
 suffconfigs = c("A","B"),
 dim = c(3,3),
 SubsetCoding = list(c("A", "B"), list("Nominal", rbind(c(1, 0, 0), c(0, 1, 1)))))

Run the code above in your browser using DataLab