"as.matrix" in openmx
Posted on

Forums
Hi everybody,
I have a simple question that might be a bit stupid. But I can't find an equivalent to the 'as.matrix' command in R. I understand that 'rvectorize' is the equivalent to 'as.vector' so I'm surprised that I can't find the 'as.matrix' thing anywhere.
Or is it maybe not yet implemented in openmx?
I have a simple question that might be a bit stupid. But I can't find an equivalent to the 'as.matrix' command in R. I understand that 'rvectorize' is the equivalent to 'as.vector' so I'm surprised that I can't find the 'as.matrix' thing anywhere.
Or is it maybe not yet implemented in openmx?
Thanks for your help
Greetings
Jan
Ah right. The OpenMx backend
You could perform this transformation with a combination of the matrix subscript operator (A[x,y]), and the functions cbind() and rbind(). But perhaps we need to implement the resize function explicitly.
Log in or register to post comments
In reply to Ah right. The OpenMx backend by mspiegel
Yeah thanks, i allready did
i allready did that by hand. But in combination with what i asked yesterday (the mxAlgebra thing) it gets quite complicated, so i thought that there might be an easier way.
But still thanks for the reply
Log in or register to post comments
In reply to Yeah thanks, i allready did by Janosch
Would it be OK to post to the
Log in or register to post comments
In reply to Would it be OK to post to the by mspiegel
Mhm I wouldn't feel too
I have this expression which is to be implemented in an mxAlgebra (I think its not that important what all the names stand for..):
(solve(DRIFTHATCH)%*%((EVECH%*%(exp(1%x%EVAH)-tempb)%*%solve(EVECH))-(II%x%II))%*%rvectorize(Q))
The result of that is a vector (N-variables**2 x 1).
Using square brackets indexing, I wanna refer to the elements in that vector in my 'S' matrix. But of course, in the 'S' matrix the elements are matrices. So the vector would have to be a matrix as well, in order for me to refer correctly.
What i did until now is to create two new mxMatrix objects (K and L). For two variables, they are:
K = (1,0,0,0, L = (0,0,1,0,
____0,1,0,0) ____0,0,0,1)
Now I multiply the vector (say v_vector=c(1,2,3,4)) with both of those matrices and rbind the result, so i get:
v_matrix = (1,3,
_________2,4)
This new matrix can then be used to refer to the elements in the 'S' matrix. For two or three variables this is no problem. But i wanna be able to write my skript in a way so that it can handle any number of variables. And the problem is that the matrices L and K get bigger with every variable and, even worse, that I need as many matrices as there are variables, in order to convert the vector to a matrix. So it basically becomes impossible when we are speaking of e.g. 100 variables.
So if I had a function that would do that for me I could get rid of all those K and L matrices and just use one expression.
I hope that this makes any sense in that compressed form. If you would like further information, let me know.
Greetings
Log in or register to post comments