If I remember correctly, as.vector is not supported by OpenMx. Use the functions cvectorize or rvectorize to perform either row or column vectorization. There is a wiki page with matrix operators and functions but it is missing these two (sorry!). To write your own matrix function, you need to provide an implementation in C for OpenMx. There is a HOWTO on the wiki. You can also define an arbitrary objective function in R. See the user guide for help on that.
Related question: how can I use colMeans() in an mxAlgebra command?
In some releases it appears that colMeans was a legitimate function within mxAlgebra (http://openmx.psyc.virginia.edu/docs/OpenMx/0.2.1-922/_static/Rdoc/mxAlgebra.html).
In the latest manual it is not listed as a viable function under the mxAlgebra command (http://openmx.psyc.virginia.edu/docs/OpenMx/latest/_static/Rdoc/mxAlgebra.html).
Yes. colMeans used to be listed in the documentation, but that was an error as it wasn't implemented. We'll put it on the TODO list, it shouldn't be too hard to implement rowMeans() and colMeans(). At best, you can currently compute the column means explicitly, although it is a pain. For example, if A is a 3 x 3 MxMatrix or MxAlgebra, then the column mean is:
col1 <- mxAlgebra(sum(A[,1])/3, name ="col1")
col2 <- mxAlgebra(sum(A[,2])/3, name ="col2")
col3 <- mxAlgebra(sum(A[,3])/3, name ="col3")
colMean <- mxAlgebra(rbind(col1, col2, col3), name ="colMean")
I don't have access to R at the moment, but I believe that dims(a) will work, where a is a MxMatrix object. Or if that doesn't work try nrow(a) and ncol(a).
Agreed these functions (
ceiling, floor, trunk, round
dim
rowMeans, colMeans
cov2cor)
Would be useful. There are some gotchas with cov2cor - it fails when diagonal elements are non-positive. I guess it will end up with NaNs in the rows and cols of any non-pos elements. In classic Mx it would throw an error which was inconvenient. NaN is much better.
Apologies, I believe I've found my own answer.
For \m2v(X) one can use as.vector(t(X)).
-Scott
If I remember correctly, as.vector is not supported by OpenMx. Use the functions cvectorize or rvectorize to perform either row or column vectorization. There is a wiki page with matrix operators and functions but it is missing these two (sorry!). To write your own matrix function, you need to provide an implementation in C for OpenMx. There is a HOWTO on the wiki. You can also define an arbitrary objective function in R. See the user guide for help on that.
The wiki page is up to date again: http://openmx.psyc.virginia.edu/wiki/matrix-operators-and-functions
Hello again,
Related question: how can I use colMeans() in an mxAlgebra command?
In some releases it appears that colMeans was a legitimate function within mxAlgebra (http://openmx.psyc.virginia.edu/docs/OpenMx/0.2.1-922/_static/Rdoc/mxAlgebra.html).
In the latest manual it is not listed as a viable function under the mxAlgebra command (http://openmx.psyc.virginia.edu/docs/OpenMx/latest/_static/Rdoc/mxAlgebra.html).
Thanks for the quick and helpful replies,
-Scott
Yes. colMeans used to be listed in the documentation, but that was an error as it wasn't implemented. We'll put it on the TODO list, it shouldn't be too hard to implement rowMeans() and colMeans(). At best, you can currently compute the column means explicitly, although it is a pain. For example, if A is a 3 x 3 MxMatrix or MxAlgebra, then the column mean is:
Or with a bit more generality using the number of rows in A and a bit of matrix algebra
v <- mxMatrix("Full", 1, dim(A@values)[1], values=1/dim(A@values)[1], name="v")
colMean <- mxAlgebra(v %*% A, name="colMeansOfA")
And similarly for row means
v <- mxMatrix("Full", 1, dim(A@values)[2], values=1/dim(A@values)[2], name="v")
rowlMean <- mxAlgebra(A %*% v, name="rowMeansOfA")
I don't have access to R at the moment, but I believe that dims(a) will work, where a is a MxMatrix object. Or if that doesn't work try nrow(a) and ncol(a).
Opened a ticket for colMeans and rowMeans: http://openmx.psyc.virginia.edu/issue/2010/06/mxalgebra-wishlist
Agreed these functions (
ceiling, floor, trunk, round
dim
rowMeans, colMeans
cov2cor)
Would be useful. There are some gotchas with cov2cor - it fails when diagonal elements are non-positive. I guess it will end up with NaNs in the rows and cols of any non-pos elements. In classic Mx it would throw an error which was inconvenient. NaN is much better.
Extra vote for a speedy cov2cor() postRelease(1.0) , esp with error catching to return NA :-)