mxFitFunctionML {OpenMx}R Documentation

Create MxFitFunctionML Object


This function creates a new MxFitFunctionML object.


mxFitFunctionML(vector = FALSE, rowDiagnostics = FALSE, ..., fellner =
  as.logical(NA), verbose=0L, profileOut=c(), rowwiseParallel=as.logical(NA))



A logical value indicating whether the objective function result is the likelihood vector.


A logical value indicating whether the row-wise results of the objective function should be returned as an attribute of the fit function.


Not used. Forces remaining arguments to be specified by name.


Whether to fully expand the covariance matrix for maximum flexibility.


Level of diagnostic output


Character vector naming constant coefficients to profile out of the likelihood (sometimes known as REML)


For raw data only, whether to use OpenMP to parallelize the evaluation of rows


Fit functions are functions for which free parameter values are optimized such that the value of a cost function is minimized. The mxFitFunctionML function computes -2*(log likelihood) of the data given the current values of the free parameters and the expectation function (e.g., mxExpectationNormal or mxExpectationRAM) selected for the model.

The 'vector' argument is either TRUE or FALSE, and determines whether the objective function returns a column vector of the likelihoods, or a single -2*(log likelihood) value.

The 'rowDiagnostics' arguent is either TRUE or FALSE, and determines whether the row likelihoods are returned as an attribute of the fit function. It is sometimes useful to inspect the likelihoods for outliers, diagnostics, or other anomalies.

When vector=FALSE and rowDiagnostics=TRUE, fitfunction can be referenced in the model and included in algebras as a scalar. The row likelihoods are an attribute of the fit function but are not accessible in the model during optimization. The row likelihoods are accessible to the user after the model has been run.

Usage Notes:

The results of the optimization can be reported using the summary function, or accessed directly in the 'output' slot of the resulting model (i.e., modelName$output). Components of the output may be referenced using the Extract functionality.


Returns a new MxFitFunctionML object. One and only one MxFitFunctionML object should be included in each model along with an associated mxExpectationNormal or mxExpectationRAM object.


The OpenMx User's guide can be found at

See Also

Other fit functions: mxFitFunctionMultigroup, mxFitFunctionWLS, mxFitFunctionAlgebra, mxFitFunctionGREML, mxFitFunctionR, mxFitFunctionRow

More information about the OpenMx package may be found here.


# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionML


# Simulate some data

x=rnorm(1000, mean=0, sd=1)
y= 0.5*x + rnorm(1000, mean=0, sd=1)
tmpFrame <- data.frame(x, y)
tmpNames <- names(tmpFrame)

# Define the matrices

M <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0), 
              free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")
S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1), 
              free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")
A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0), 
              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")
I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")

# Define the expectation

expCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")
expFunction <- mxExpectationNormal(covariance="expCov", means="M", dimnames=tmpNames)

# Choose a fit function

fitFunction <- mxFitFunctionML(rowDiagnostics=TRUE)
# also return row likelihoods, even though the fit function
#  value is still 1x1

# Define the model

tmpModel <- mxModel(model="exampleModel", M, S, A, I, expCov, expFunction, fitFunction, 
                    mxData(observed=tmpFrame, type="raw"))

# Fit the model and print a summary

tmpModelOut <- mxRun(tmpModel)

fitResOnly <- mxEval(fitfunction, tmpModelOut)
attributes(fitResOnly) <- NULL

# Look at the row likelihoods alone
fitLikeOnly <- attr(mxEval(fitfunction, tmpModelOut), 'likelihoods')

[Package OpenMx version 2.6.8 Index]