Learn R Programming

metaSEM (version 1.4.0)

create.mxMatrix: Create a Vector into MxMatrix-class

Description

It converts a vector into MxMatrix-class via mxMatrix.

Usage

create.mxMatrix(x, type=c("Full","Symm","Diag","Stand"), ncol=NA,
nrow=NA, as.mxMatrix=TRUE, byrow=FALSE, ...)

Value

A MxMatrix-class object with the same dimensions as x

Arguments

x

A character or numeric vector

type

Matrix type similar to those listed in mxMatrix

ncol

The number of columns. It is necessary when type="Full". It is ignored and determined by the length of x for the other types of matrices.

nrow

The number of rows. It is necessary when type="Full". It is ignored and determined by the length of x for the other types of matrices.

as.mxMatrix

Logical. If it is TRUE, the output is a matrix of MxMatrix-class. If it is FALSE, it is a numeric matrix.

byrow

Logical. If FALSE (the default) the matrix is filled by columns, otherwise the matrix is filled by rows.

...

Further arguments to be passed to mxMatrix. Please note that type, nrow, ncol, values, free and labels will be created automatically. Thus, these arguments except labels should be avoided in ...

Author

Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>

Details

If there are non-numeric values in x, they are treated as the labels of the free parameters. If an "*" is present, the numeric value on the left-hand side will be treated as the starting value for a free parameter or a fixed value for a fixed parameter. If it is a matrix of numeric values, there are no free parameters in the output matrix. nrow and ncol will be calculated from the length of x unless type="Full" is specified.

See Also

mxMatrix, create.mxMatrix, create.Fmatrix

Examples

Run this code
## a and b are free parameters with starting values and labels
(a1 <- c(1:4, "5*a", 6, "7*b", 8, 9))

(mat1 <- create.mxMatrix(a1, ncol=3, nrow=3, name="mat1"))

## Arrange the elements by row
(mat2 <- create.mxMatrix(a1, ncol=3, nrow=3, as.mxMatrix=FALSE, byrow=TRUE))

(a3 <- c(1:3, "4*f4", "5*f5", "6*f6"))

(mat3 <- create.mxMatrix(a3, type="Symm", name="mat3"))

## Create character matrix
(mat4 <- create.mxMatrix(a3, type="Symm", as.mxMatrix=FALSE))

## Arrange the elements by row
(mat5 <- create.mxMatrix(a3, type="Symm", as.mxMatrix=FALSE, byrow=TRUE))

(mat6 <- create.mxMatrix(a3, type="Diag", lbound=6:1, name="mat6"))

Run the code above in your browser using DataLab