Convert a Matrix into MxMatrix-class

Share:

Description

It converts a matrix into MxMatrix-class via mxMatrix.

Usage

1

Arguments

x

A character or numeric matrix. If x is not a matrix, as.matrix(x) is applied first.

name

An optional character string as the name of the MxMatrix object created by mxModel function. If name is missing, the name of x will be used.

...

Further arguments to be passed to mxMatrix. It should be noted that type, nrow, ncol, values, free, name and labels will be created automatically. Thus, these arguments excepts labels should be avoided in ...

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 is no free parameters in the output matrix.

Value

A MxMatrix-class object with the same dimensions as x

Author(s)

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

See Also

mxMatrix, create.mxMatrix, create.Fmatrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## a and b are free parameters with starting values and labels
(a1 <- matrix(c(1:4, "5*a", 6, "7*b", 8, 9), ncol=3, nrow=3))
#      [,1] [,2]  [,3] 
# [1,] "1"  "4"   "7*b"
# [2,] "2"  "5*a" "8"  
# [3,] "3"  "6"   "9"  

a1 <- as.mxMatrix(a1)

## a and b are fixed parameters without any labels, name="new2"
(a2 <- matrix(1:9, ncol=3, nrow=3))
#      [,1] [,2] [,3]
# [1,]    1    4    7
# [2,]    2    5    8
# [3,]    3    6    9

new2 <- as.mxMatrix(a2, name="new2")

## Free parameters without starting values
(a3 <- matrix(c(1:4, "*a", 6, "*b", 8, 9), ncol=3, nrow=3))
#      [,1] [,2] [,3]
# [1,] "1"  "4"  "*b"
# [2,] "2"  "*a" "8" 
# [3,] "3"  "6"  "9" 

a3 <- as.mxMatrix(a3, lbound=0)

## A free parameter without label
(a4 <- matrix(c(1:4, "5*", 6, "7*b", 8, 9), ncol=3, nrow=3))
#      [,1] [,2] [,3] 
# [1,] "1"  "4"  "7*b"
# [2,] "2"  "5*" "8"  
# [3,] "3"  "6"  "9"  

a4 <- as.mxMatrix(a4)

## Convert a scalar into mxMatrix object
## "name" is required as "3*a" is not a valid name.
(a5 <- as.mxMatrix("3*a", name="a5"))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.