This is something that would be really useful if someone who is actually competent in the area would fix it. I did make a start, and I know that some of this is wrong; some is probably not sufficiently general; and some does indeed match the sem output exactly. So it is a start. Someone, please fix it and include with OpenMx, this would be very useful for a whole bunch of ignoramuses like me who occasionally need to run an SEM or path analysis and aren't covered by the sem package (e.g., need multi-group models).
starter R code to compute the usual assortment of fit indices
#
based on (what I understood of):
Tabachnick & Fidell, pp. 697-702
Klein, pp. 135-144
also http://www.tau.ac.il/cc/pages/docs/sas8/stat/chap19/sect34.htm
#
fit.index <- function(indepfit,modelfit) {
indep <- summary(indepfit)
indep.chi <- indep$Chi
indep.df <- indep$degreesOfFreedom
model <- summary(modelfit)
model.chi <- model$Chi
model.df <- model$degreesOfFreedom
model.ml <- as.numeric(modelfit$objective@result)
N <- model$numObs # sample size
N.est.param <- model$estimatedParameters # t
N.manifest <- length(modelfit@manifestVars) # n
observed.cov <- modelfit@data@observed # S
estimate.cov <- modelfit@matrices$S@values[1:N.manifest,1:N.manifest] # C, W
observed.cor <- cov2cor(observed.cov)
estimate.cor <- cov2cor(estimate.cov)
residual.cov <- observed.cov-estimate.cov
residual.cor <- observed.cor-estimate.cor
F0 <- (model.chi-model.df)/N
if (F0<0) { F0 <- 0 }
NFI <- (indep.chi-model.chi)/indep.chi
NNFI <- (indep.chi-indep.df/model.df*model.chi)/(indep.chi-indep.df)
PNFI <- (model.df/indep.df)*NFI
IFI <- (indep.chi-model.chi)/(indep.chi-model.df)
CFI <- 1.0-(model.chi-model.df)/(indep.chi-indep.df)
RMSEA<- sqrt(F0/model.df) # need confidence intervals
MFI <- exp(-0.5*(model.chi-model.df)/N)
GFI <- sum(estimate.cov*estimate.cov)/sum(observed.cov*observed.cov) # definitely not right!
AGFI <- 1.0 - (1.0-GFI)/(1.0-N.est.param/N)
PGFI <- (1.0-N.est.param/N)*GFI
AIC <- model.chi-2*model.df
AIC2 <- model.chi+2*N.est.param
CAIC <- model.chi-(log(N)+1.0)*model.df
CAIC2<- model.chi+(log(N)+1.0)*N.est.param
BIC <- model.chi-log(N)*model.df
BIC2 <- model.chi+log(N)*N.est.param
RMR <- sqrt(2.0*sum((residual.cov*residual.cov)/(N.est.param*(N.est.param+1))))
SRMR <- sqrt(2.0*sum((residual.cor*residual.cor)/(N.est.param*(N.est.param+1)))) # not right!
indices <- rbind(NFI,NNFI,PNFI,IFI,CFI,RMSEA,MFI,GFI,AGFI,PGFI,AIC,AIC2,CAIC,CAIC2,BIC,BIC2,RMR,SRMR)
return(indices)
}