mxAlgebra(expression, name = NA, dimnames = NA, ..., fixed = FALSE,
          joinKey=as.character(NA), joinModel=as.character(NA), verbose=0L)MxMatrix 
objects and the mxFitFunctionAlgebra function. 
The mxFitFunctionAlgebra function must reference by name the MxAlgebra object to be evaluated. Note that, if the result for an MxAlgebra depends upon one or more "definition variables" (see mxMatrix()), then the value returned after the call to mxRun() will be computed using the values of those definition variables in the first (i.e., first before any automated sorting is done) row of the raw dataset. The following operators and functions are supported in mxAlgebra: Operators solve()t()^%^%+-%*%*/%x%%&%%&% B ==  A %*% B %*% t(A)cov2corcholcbindrbindcolSumsrowSumsdettrsummeanprodmaxminabssinsinhasinasinhcoscoshacosacoshtantanhatanatanhexplogsqrtp2zlogp2zlgammalgamma1peigenvalrvectorizecvectorizevechvechsvech2fullvechs2fullvec2diagdiag2vecexpmlogmomxExponentialomxMnoromxAllIntomxNotomxAndomxOromxGreaterThanomxLessThanomxApproxEqualsomxSelectRowsomxSelectColsomxSelectRowsAndColsmxEvaluateOnGridFALSE, and non-zero numerical values as logical values of TRUE.  For most of these functions, OpenMx cycles over values of arguments other than the first, by column (i.e., in column-major order), to the length of the first argument.  Notable exceptions are the log, log.p, and lower.tail arguments to probability-distribution-related functions, for which only the [1,1] element is used.  It is recommended that all arguments after the first be either (1) scalars, or (2) matrices with the same dimensions as the first argument.
| Function | Arguments | Notes | 
| besselI&besselK | x,nu,expon.scaled | Note that OpenMx does cycle over the elements of expon.scaled. | 
| besselJ&besselY | x,nu | |
| dbeta | x,shape1,shape2,ncp,log | The algorithm for the non-central beta distribution is used for non-negative values of ncp.  Negativencpvalues are ignored, and the algorithm for the central beta distribution is used. | 
| pbeta | q,shape1,shape2,ncp,lower.tail,log.p | Values of ncpare handled as withdbeta(). | 
| dbinom | x,size,prob,log | |
| pbinom | q,size,prob,lower.tail,log.p | |
| dcauchy | x,location,scale,log | |
| pcauchy | q,location,scale,lower.tail,log.p | |
| dchisq | x,df,ncp,log | The algorithm for the non-central chi-square distribution is used for non-negative values of ncp.  Negativencpvalues are ignored, and the algorithm for the central chi-square distribution is used. | 
| pchisq | q,df,ncp,lower.tail,log.p | Values of ncpare handled as withdchisq(). | 
| omxDnbinom | x,size,prob,mu,log | Exactly one of arguments size,prob, andmushould be negative, and therefore ignored.  Otherwise,muis ignored, possibly with a warning, and the values ofsizeandprobare used, irrespective of whether they are in the parameter space.  If onlyprobis negative, the algorithm for the alternativesize-muparameterization is used.  Ifsizeis negative, a value forsizeis calculated asmu*prob/(1-prob), and the algorithm for thesize-probparameterization is used (note that this approach is ill-advised whenprobis very close to 0 or 1). | 
| omxPnbinom | q,size,prob,mu,lower.tail,log.p | Arguments are handled as with omxDnbinom(). | 
| dpois | x,lambda,log | |
| ppois | q,lambda,lower.tail,log.p | 
expression argument and the function that creates them. More information about the OpenMx package may be found here.
A <- mxMatrix("Full", nrow = 3, ncol = 3, values=2, name = "A")
# Simple example: algebra B simply evaluates to the matrix A
B <- mxAlgebra(A, name = "B")
# Compute A + B
C <- mxAlgebra(A + B, name = "C")
# Compute sin(C)
D <- mxAlgebra(sin(C), name = "D")
# Make a model and evaluate the mxAlgebra object 'D'
A <- mxMatrix("Full", nrow = 3, ncol = 3, values=2, name = "A")
model <- mxModel(model="AlgebraExample", A, B, C, D )
fit   <- mxRun(model)
mxEval(D, fit)
# Numbers in mxAlgebras are upgraded to 1x1 matrices
# Example of Kronecker powering (%^%) and multiplication (%*%)
A  <- mxMatrix(type="Full", nrow=3, ncol=3, value=c(1:9), name="A")
m1 <- mxModel(model="kron", A, mxAlgebra(A %^% 2, name="KroneckerPower"))
mxRun(m1)$KroneckerPower
# Running kron 
# mxAlgebra 'KroneckerPower' 
# $formula:  A %^% 2 
# $result:
#      [,1] [,2] [,3]
# [1,]    1   16   49
# [2,]    4   25   64
# [3,]    9   36   81
Run the code above in your browser using DataLab