would it be worth getting this to work for Mx as an accessor function for AIC, with the benefit of being consilient with other functions in R?

AIC(fit1)

Error in UseMethod("logLik") :

no applicable method for 'logLik' applied to an object of class "MxModel"

I very much like the idea to place the class MxModel into the generic R framework for likelihood-based calculations. I hacked together the function and this seems to work ad hoc.

This can be used to obtain log-likelihood and/or AIC, e.g., by typing

There is one more thing. As far as I understand, R defines the AIC based on the -2loglikelihood and degrees of freedom equal to the freely estimated parameters in the model, whereas OpenMx defines AIC based on the chi^2 and the degrees of freedom equal to the difference of parameters between the model and the saturated model. The AIC difference between any two models will come out the same, either way, but this has great potential to confuse users. So, if this function was integrated into OpenMx, the different ways to calculate AIC should be stated in the summary()-function.

I attach a patch to OpenMx (rev. 2295) that adds the capability as described above. With this patch applied (in trunk directory) and with adding the attached MxLogLik.R into subdirectory "R", I am able to obtain log-likelihood, AIC, and BIC via the generic accessors from the stats-package, e.g.:

It's much nicer for people if the standard over-loaded functions work.

Definately nice to be able to say AIC(model)

probably we should also implement a version of plot() which plots a model as a RAM graph...