mxRObjective {OpenMx}R Documentation

Function to Create MxRObjective Object


This function creates a new MxRObjective object.




objfun A function that accepts two arguments.


The objfun argument must be a function that accepts two arguments. The first argument is the mxModel that should be evaluated, and the second argument is some persistent state information that can be stored between one iteration of optimization to the next iteration. It is valid for the function to simply ignore the second argument.

The function must return either a single numeric value, or a list of exactly two elements. If the function returns a list, the first argument must be a single numeric value and the second element will be the new persistent state information to be passed into this function at the next iteration. The single numeric value will be used by the optimizer to perform optimization.

The initial default value for the persistant state information is NA.


Returns a new MxRObjective object.


The OpenMx User's guide can be found at


A <- mxMatrix(nrow = 2, ncol = 2, values = c(1:4), free = TRUE, name = 'A')

squared <- function(x) { x ^ 2 }

objFunction <- function(model, state) {
        values <- model[['A']]@values 
        return(squared(values[1,1] - 4) + squared(values[1,2] - 3) +
                squared(values[2,1] - 2) + squared(values[2,2] - 1))
objective <- mxRObjective(objFunction)

model <- mxModel('model', A, objective)

[Package OpenMx version 1.0.0-1448 Index]