You are here

Revision of mxMatrix Help from Thu, 07/08/2010 - 23:18

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

Wiki home page

Matrix Types

Matrices in OpenMx must be one of:

Diag

m11 0 0
0 m22 0
0 0 m33

Full

m11 m21 m31
m21 m22 m32
m31 m32 m33

Iden

1 0 0
0 1 0
0 0 1

Lower

m11 0 0
m21 m22 0
m31 m32 m33

Stand (symmetric, ones on diagonal)

1 m21 m31
m21 1 m32
m31 m32 1

Sdiag (the sub-diagonal lower matrix)

0 0 0
m21 0 0
m31 m32 0

Symm

m11 m21 m31
m21 m22 m32
m31 m32 m33

Unit

1 1 1
1 1 1
1 1 1

Zero

0 0 0
0 0 0
0 0 0

Basic Examples

    require(OpenMx)
    A <- mxMatrix('Full', 1, 1, values = 1, name = 'A')
    B <- mxMatrix('Full', 1, 1, values = 2, name = 'B')
    C <- mxMatrix('Full', 1, 1, values = 3, name = 'C')
    D <- mxMatrix('Full', 3, 1, labels = c('A[1,1]', 'B[1,1]', 'C[1,1]'), name = 'D')
    model <- mxModel('model', A, B, C, D)
    fit <- mxRun(model)
    mxEval(D, fit)
    A <- mxMatrix('Full', 2, 2, values = c(1,2,3,4), byrow = TRUE, name = 'A')
    B <- mxAlgebra(A + A, name = 'B')
    C <- mxMatrix('Full', 2, 2, labels = c('B[2,2]', 'B[2,1]', 
            'B[1,2]', 'B[1,1]'), byrow = TRUE, name = 'C')
    model <- mxModel('model', A, B, C)
    fit <- mxRun(model)
    mxEval(C, fit)

Get the row or column count of an mxMatrix

    myMatrix <- mxMatrix('Full', 3, 5)
    nrow(myMatrix)
    ncol(myMatrix)

Square bracket substitution to set labels

This feature allows you to construct MxMatrix objects, the labels of which refer to another MxMatrix or MxAlgebra. This is done by specifying the name, row, and col of the target matrix or algebra as you would expect to be able to in R, i.e., "foo[row,col]".

The effect of pointing to another cell using bracket notation is just the same as setting the label of the two cells to the same value.

So, given a matrix A with labels:

    aLabels = c(
    "a1", "a2",
    "a3", "a4"
    )

Setting the labels of matrix B to this:

    bLabels = c(
      "a1", "b2",
      "b3", "b4"
    )

Is the same as setting the labels of matrix B to this:

    bLabels = c(
      "A[1,1]", "b2",
      "b3",     "b4"
    )

Both methods forces cell B[1,1] to take the same value as A[1,1].
the benfit of the [] syntax is that you only need to set one label to equate two cells, and you don't need to know what label the other cell has currently, just its location.

Please add material here as you learn...

If you have questions not answers, then add those here: That's how a wiki works.