
mxMatrix(type = "Full", nrow = NA, ncol = NA,
free = FALSE, values = NA, labels = NA, lbound = NA,
ubound = NA, byrow = getOption('mxByrow'), dimnames = NA, name = NA,
condenseSlots=getOption('mxCondenseMatrixSlots'),
..., joinKey=as.character(NA), joinModel=as.character(NA))
NA
.NA
.FALSE
(default), the ‘values’, ‘free’, ‘labels’, ‘lbound’, and ‘ubound’ matrices are populated by column rather than by row. TRUE
, then the resulting MxMatrix will "condense" its ‘labels’, ‘free’, ‘lbound’, and ‘ubound’ down to 1x1 matrices if they contain only FALSE
(‘free’) or NA
(the other three). If FALSE
, those four matrices and the ‘values’ matrix will all be of equal dimensions. mxAlgebra()
, mxBounds()
, mxConstraint()
and mxModel()
functions.'data.'
can be used if the MxMatrix is to be used in an MxModel object that has a raw dataset (i.e., an MxData object of type="raw"
). Such a label instructs OpenMx to use a particular column of the raw dataset to fill in the value of that element. For historical reasons, the variable contained in that column is called a "definition variable." For example, if an MxMatrix element has the label 'data.x'
, then OpenMx will use the first value of the data column named "x" when evaluating the fitfunction for the first row, and will use the second value of column "x" when evaluating the fitfunction for the second row, and so on. After the call to mxRun()
, the values for elements labeled with 'data.x'
are returned as the value from the first (i.e., first before any automated sorting is done) element of column "x" in the data. Objects created by the mxMatrix()
function are of a specific ‘type’, which specifies the number and location of parameters in the ‘labels’ matrix and the starting values in the ‘values’ matrix. Input ‘values’, ‘free’, and ‘labels’ matrices must be of appropriate shape and have appropriate values for the matrix type requested. Nine types of matrices are supported: ‘Diag’ | matrices must be square, and only elements on the principal diagonal may be specified as free parameters or take non-zero values. All other elements are required to be fixed parameters with a value of 0. |
‘Full’ | matrices may be either rectangular or square, and all elements in the matrix may be freely estimated. This type is the default for the mxMatrix() function. |
‘Iden’ | matrices must be square, and consist of no free parameters. Matrices of this type have a value of 1 for all entries on the principal diagonal and the value 0 in all off-diagonal entries. |
‘Lower’ | matrices must be square, with a value of 0 for all entries in the upper triangle and no free parameters in the upper triangle. |
‘Sdiag’ | matrices must be square, with a value of 0 for all entries in the upper triangle and along the diagonal. No free parameters in the upper triangle or along the diagonal. |
‘Symm’ | matrices must be square, and elements in the principle diagonal and lower triangular portion of the matrix may be free parameters of any value. Elements in the upper triangular portion of the matrix are constrained to be equal to those in the lower triangular portion, such that the value and parameter specificiation of the element in row i and column j is identical to to the value and specification of the element in row j and column i. |
‘Stand’ | matrices are symmetric matrices (see 'Symm') with 1's along the main diagonal. |
‘Unit’ | matrices may be either rectangular or square, and contain no free parameters. All elements in matrices of this type have a value of 1 for all elements. |
‘Zero’ | matrices may be either rectangular or square, and contain no free parameters. All elements in matrices of this type have a value of 0 for all elements. |
# Create a 3 x 3 identity matrix
idenMatrix <- mxMatrix(type = "Iden", nrow = 3,
ncol = 3, name = "I")
# Create a full 4 x 2 matrix from existing
# value matrix with all free parameters
vals <- matrix(1:8, nrow = 4)
fullMatrix <- mxMatrix(type = "Full", values = vals,
free = TRUE, name = "foo")
# Create a 3 x 3 symmetric matrix with free off-
# diagonal parameters and starting values
symmMatrix <- mxMatrix(type = "Symm", nrow = 3, ncol = 3,
free = c(FALSE, TRUE, TRUE, FALSE, TRUE, FALSE),
values = c(1, .8, .8, 1, .8, 1),
labels = c(NA, "free1", "free2", NA, "free3", NA),
name = "bar")
# Create an mxMatrix from a character matrix. All numbers are
# interpreted as fixed and non-numbers are interpreted as free
# parameters.
matrixFromChar <- function(inputm, name=NA) {
inputmFixed <- suppressWarnings(matrix(
as.numeric(inputm),nrow = nrow(inputm), ncol = ncol(inputm)))
inputmCharacter <- inputm
inputmCharacter[!is.na(inputmFixed)] <- NA
mxMatrix(nrow=nrow(inputm), ncol=ncol(inputm),
free=!is.na(inputmCharacter),
values=inputmFixed,
labels=inputmCharacter,
dimnames=dimnames(inputm), name=name)
}
# Demonstrate some of the behavior of the condensed slots
# Create a 3x3 matrix with condensed slots
a <- mxMatrix('Full', 3, 3, values=1, condenseSlots=TRUE)
a@free # at operator returns the stored 1x1 matrix
a$free # dollar operator constructs full matrix for printing
# assignment with the dollar operator
# de-condenses the slots to create the
# full 3x3 matrix
a$free[1,1] <- TRUE
a@free
Run the code above in your browser using DataLab