diag() overloading
Posted on

Hi, I was wanting to get the diagonal of an openmx output matrix and tried "diag()" as shown below with the matrix.
Question: should (can?) we overload "standard" R functions, or is there to be an mxDiag() equivalent?
If the latter, it would be nice if where possible it worked (to parameters) as the {base} library functions do.
I guess that it would be VERY helpful if code like
a = mxRun(factorModel) round(diag(a$S), 2) # worked, i.e, output a matrix rounded to 2 decimal places
> diag(a$S) Error in y[1L + 0L:(m - 1L) * (n + 1L)] <- x : incompatible types (from S4 to double) in subassignment type fix > a$S SymmMatrix 'S' Labels matrix: No labels assigned. Values matrix: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.04081422 0.00000000 0.0000000 0.00000000 0.00000000 0 [2,] 0.00000000 0.03802001 0.0000000 0.00000000 0.00000000 0 [3,] 0.00000000 0.00000000 0.0408272 0.00000000 0.00000000 0 [4,] 0.00000000 0.00000000 0.0000000 0.03938708 0.00000000 0 [5,] 0.00000000 0.00000000 0.0000000 0.00000000 0.03628711 0 [6,] 0.00000000 0.00000000 0.0000000 0.00000000 0.00000000 1
Hi Tim, The recommended way
Hi Tim,
The recommended way to do this is to use the mxEvaluate() function. In this fashion, we do not have to rewrite our own version of all the matrix operations.
factorModelOut <- mxRun(factorModel)
mxEvaluate(diag(S), factorModelOut)
Log in or register to post comments
In reply to Hi Tim, The recommended way by mspiegel
Ha, in r705 I just committed
EDIT: removed it in 707.
Log in or register to post comments
In reply to Ha, in r705 I just committed by Jeff
Thanks for removing the
Log in or register to post comments
In reply to Thanks for removing the by mspiegel
I understand your point,
Log in or register to post comments
I agree with Michael on this.
Log in or register to post comments
In reply to I agree with Michael on this. by Steve
This is a small point, but
It didn't occurred to me to use mxEvaluate() to do this, mostly because, unlike matrix, there is nothing in R called "evaluate", so mxEvaluate is not analogous to an existing function with that name.
What it seems to be analogous, to is with()
So I'd like to suggest:
It easier to read and easier to stumble across and remember
Log in or register to post comments
In reply to This is a small point, but by tbates
Actually, eval() is
We could rename to mxEval(). I am not sure why the longer name was chosen.
Log in or register to post comments
In reply to Actually, eval() is by Steve
Ahh: then I vote the mx
Log in or register to post comments