MarginalMatrix {cmm} | R Documentation |

Returns marginal matrix; i.e., matrix required to obtained marginal frequencies

`MarginalMatrix(var, marg, dim, SubsetCoding = "Identity", vec = NULL)`

`var` |
character or numeric vector containing variables |

`marg` |
list of character or numeric indicating marginals |

`dim` |
numeric vector indicating the dimension of |

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

`vec` |
Vector containing the observed frequencies of all observed cells and possibly some cells with frequency equal to zero.
The rownames of |

Gives the matrix which, multiplied by a probability vector, gives the marginal probabilities.
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)))`

.

Special case of transposed `DesignMatrix`

:

MarginalMatrix <- function(var,marg,dim,SubsetCoding="Identity") t(DesignMatrix(var,marg,dim,SubsetCoding=SubsetCoding,MakeSubsets=FALSE))

Allows weighted sums of probabilities using `SubsetCoding`

matrix

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

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.

Van der Ark, L. A., Bergsma, W. P., & Koopman L. (2023) Maximum augmented empirical likelihood estimation of categorical marginal models for large sparse contingency tables. Paper submitted for publication.

`ConstraintMatrix`

, `DesignMatrix`

, `DirectSum`

, `RecordsToFrequencies`

, `Margins`

```
# Computing marginal frequencies
n <- c(1:6) #example list of frequencies
var <- c("A","B")
marg <- list(c("A"),c("B"))
dim <- c(2,3)
at <- MarginalMatrix(var,marg,dim)
# list of marginal frequencies:
at
# identitymatrix: several ways of specifying:
marg <- c("A","B")
MarginalMatrix(var, marg,dim)
MarginalMatrix(var, marg, dim,
SubsetCoding = list(c("A", "B"), list("Identity", "Identity")))
MarginalMatrix(var, marg, dim,
SubsetCoding = list(c("A","B"), list(rbind(c(1,0),c(0,1)), rbind(c(1,0,0),c(0,1,0),c(0,0,1)))))
# omit second category of first variable
at <- MarginalMatrix(var, marg, dim,
SubsetCoding = list(c("A","B"), list(rbind(c(1,0)),"Identity")))
at
# Example of maximum augmented empirical likelihood (MAEL) estimation
data(acl)
dat <- acl[, 1:2] + 1 # select 2 items from ACL
var <- 1 : ncol(dat) # define the variables
marg <- Margins(var, c(0, 1)) # margins are total (0) and 1st order
dim <- rep(5, length(var))
n.obs <- RecordsToFrequencies(dat, var, dim, "obs") # frequency vector with observed cells
t(n.obs)
n.1k <- RecordsToFrequencies(dat, var, dim, "1k") # frequency vector with observed and
# some unobserved cells
t(n.1k)
at.obs <- MarginalMatrix(var, marg, dim, vec = n.obs) # marginal matrix based on n.obs
at.obs
at.1k <- MarginalMatrix(var, marg, dim, vec = n.1k) # marginal matrix based on n.1k
at.1k
```

[Package *cmm* version 1.0 Index]