## crossprod(x) <- t(x) %*% y

 Project: OpenMx Component: Code Category: feature request Priority: normal Assigned: Unassigned Status: closed
Description

The following algebras would be nice to have. They are currently scheduled for completion after the 1.0 release:

ceiling, floor, trunk, round
dim
rowMeans, colMeans
cov2cor

## Comments

### #1

Scripts often involve computing A %*% t(A) or A %*% t(B)
It would be a handy help to have an mx function return multiply by transpose
I realise that this is not (or at least I can't see) a standard, but it would make scripting more compact and quicker to type and maintain, just as %&% and cov2cor() do.

Perhaps:
tx(A) = A %*% t(A)
tx(A,B) = A %*% t(B)

### #2

Er, we still don't have cov2cor() in the OpenMx backend?

Error: Unknown matrix operator or function 'cov2cor' in mxAlgebra(t(vechs(cov2cor(ACE.expCovMZ))), name = "MZexpcor")

### #3

Oops. I checked in a change to the svn trunk that implements cov2cor in the backend.

### #4

Update for the addition of vec2diag()

Can we have diag() and chol() please?

The functionality of diag() is supported by vec2diag()

Unlike diag, this function always tries to populate a square matrix from a diagonal vector. i.e., vec2diag(3) etc won't act as you expect from using diag(3)

Would still be good to support chol() in algebras

### #5

We have strayed away from diag() because R's behavior is so ambiguous. diag(3), diag(1:3), and diag(matrix(1:9, 3, 3)) are all distinct entities to OpenMx. They are mxMatrix('Diag', 3, 3, FALSE, 1), vec2diag(c(1, 2, 3)), and diag2vec(foo), respectively in OpenMx.

We currently support chol(). Mike Neale added it some time ago, I believe.

### #6

ahh, chol() is in 1.3.2 (tried in a 1.3.1 install)

added chol and cov2cor to the mxAlgebra.Rd

### #7

Not sure their absence is a road block, but of Mike Speigal's initial list, only cov2cor() got over the top as yet.

```m1 = mxModel("m1",
mxMatrix(name="a", "Full", nrow=1, ncol=1, free=T, values=1),
# mxAlgebra(ceiling(3.1), name="ceiling_please"),
# mxAlgebra(floor(3.1), name="floor_please"),
# mxAlgebra(trunk(3.234), name="trunk_please"),
# mxAlgebra(round(3.234), name="round_please"),
# mxAlgebra(dim(a), name="dim_please"),
# mxAlgebra(rowMeans(a), name="rowMeans_please"),
# mxAlgebra(colMeans(a), name="colMeans_please"),
mxAlgebra(cov2cor(a), name="cov2cor_done")
)```

### #8

`qnorm()`, the standard-normal quantile function, would be nice, too. For instance, It would enable thresholds to depend upon definition variables.

### #9

See SVN 3592 for an example of how to add an algebra operator. It's really not very hard.

### #10

 Title: MxAlgebra wishlist » crossprod(x) <- t(x) %*% y

Base R implements crossproduct() and tcrossproduct()

`crossprod(x, y = NULL)`

They say this gives a speed-up over

`t(x) %*% y `

Given how often we do t(x) %*% x in modelling, crossproduct(x) would be a handy addition.

### #11

crossprod() is more typing than the current situation.

crossprod(x): 12 characters
t(x)%*%x: 8 characters

crossprod(x,y): 14 characters
t(x)%*%y: 8 characters

As Mike Neale noted in email, aside from frontend use of mxEval, crossprod will not be faster than t(x)%*%y. Even then, the documentation suggests crossprod would only be slightly faster.

I feel crossprod() is confusing. It's not a cross product (for 3-dimensional vectors, e.g. right-hand rule) or wedge product (for higher dimensional vectors). It's just a matrix multiplication.

That being said, if anyone wants to implement the frontend algebra and have it be a wrapper around matrix multiplication, then I'm not going to stop them.

### #12

 Status: active » closed

Creating a new Issue for this mxAlgebra Wishlist.