Wed, 05/26/2010 - 10:33

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?

Thanks for your help

Greetings

Jan

Ah right. The OpenMx backend understands only matrix types. So cvectorize() and rvectorize() resize the input matrices into (n x 1) and (1 x n) matrices. We do not have a generic resize() function that transforms an input matrix into a n x m matrix.

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.

Yeah thanks,

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

Would it be OK to post to the forums either your script or maybe just the relevant portion that needs the matrix resize function? We're trying to get a feeling for the types of models that would need this function. If this is work in progress and you'd prefer not to put it on the forums, I would completely understand.

Mhm I wouldn't feel too comfortable to post the whole code. But i can try to show you a bit better, where i would need the function.

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