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

indep indep.chi indep.df

model model.chi model.df

model.ml N N.est.param N.manifest observed.cov estimate.cov observed.cor estimate.cor residual.cov residual.cor F0 if (F0

NFI NNFI PNFI IFI CFI RMSEA MFI GFI AGFI PGFI AIC AIC2 CAIC CAIC2 BIC BIC2 RMR SRMR

indices return(indices)

}

This looks good! We already have a few of these in the summary function, but we should add a few of these as well. I'll try to find some time to double-check the equations and define them in terms of likelihoods whenever possible. I'll pose a few question for you and the community:

-Which of these functions is very important to you? Which do you not care to see?

-Are there any additional functions you'd like to see?

If these all get forwarded into summary, I'd propose something like this:

-Information criteria are put in a data frame, making a 4 x 2 (or 2 x 4) table of AIC, BIC, CBIC and sBIC with both the -2*observedStatistics and +2*parameters corrections

-*FI get put in a data frame because there's a lot of them. If there is no saturated model given, an NA or character message is presented instead

-RMSEA (and its CI) remain their own object

-RMR and SRMR are put together, as I understand SRMR to be the standardized version of RMR. (This will have to wait for an explicit output of the estimated and observed covariances; i have no idea what to do with these with ordinal data).

My impression is that the most important (judging by what seems most reported or recommended in the literature) are CFI, RMSEA (with CI), and SRMR, followed by GFI and NNFI, AIC, and/or BIC. Of these, I think I got CFI and NNFI right, but GFI and SRMR wrong. AIC/BIC seem OK or off by a factor of 2.

By all means it's better to have something that works for the most common cases than wait for something that would be perfectly general for any possible situation (ordinal data or what have you).

Another thing that would be extremely useful is the calculation of standardized coefficients. I have probably misunderstood how that's supposed to be done, because my first attempt is very definitely wrong:

my.std.coef

s s[which(modelfit@matrices$A@free)] t for (i in 1:nrow(s)) {t[i]

std rownames(std)=rownames(s)

colnames(std)=colnames(s)

for (i in 1:nrow(s)) {std[i,] std

mod nparam stdcoef for (i in 1:nparam) { stdcoef[i]

z p

augcoef return(augcoef)

}

If you will be my god and fix these so that we can run our usual analyses with OpenMx I'll have one more reason to convince my students to use R for everything!

Thanks for the information.

I've already written a RAM model standardization function, which can be found here: http://openmx.psyc.virginia.edu/thread/718. It shows up as posted by anonymous for some reason, but let me know if you have any questions.

Works like a charm! Except for model[[nM]]@values[,] because my model has M=NA, but I got rid of that line and the rest is perfect. Thanks so much!!

I guess that was a bit too fast... Not everything works like a charm. Specifically, the variance of the endogenous latent is not shown and the loadings of its indicators are incorrect (it seems that the unstandardized loadings are divided by the standard deviation of the latent instead of being multiplied). The rest seem fine in my test case but that's no reassurance because the exogenous latents' variance was fixed to 1.0 for identification. I'll see if I can understand enough of your code to try and address the discrepancies.

That's odd. If you don't mind, post code to generate your model and I'll take a look.

Thanks a lot for looking into it. Code (stdtest.R) and data (rcdata.txt) attached. Here are the results:

(I hope the code shows up correctly with all the angle brackets in there... I don't know how to get the tabs to align in the posting, so I am also attaching the output separately)

The problem is evident in comparing rows 11-13 of semTwo.std to rows 7-8 of mxTwo.std (there's no standardized disturbance of R in mxTwo). The corresponding unstandardized coefficients match fine.

Fixed. I'll update and detail the standardizeRAM change in the original thread.

I've altered your code to make comparison easier. I used R's merge() function to allow for more direct comparison of the sem and OpenMx output.

I've also changed all of your '->' assignment operators to '

Thank you very much for fixing the standardization code, I greatly appreciate it!

(as for the left/right assignment, it is one of the things I really like about R :-) )

Hi,

Thanks to the script below (suggested by Athanassios Protopapas and further developed by Paolo Ghisletta, thank you!!!) I was able to obtain a large number of fit indices, but I still can't get the 90% confidence interval for RMSEA and p close (the test of the null hypothesis that RMSEA (in the population) in less than .05). Can anyone help me?

fit.cov options(scipen=3)

indep model deviance Chi indep.chi df p.Chi Chi.df indep.df N N.parms N.manifest q N.latent observed.cov observed.cor A S F I estimate.cov estimate.cor Id.manifest residual.cov residual.cor F0 if (F0 NFI NNFI.TLI PNFI RFI IFI CFI if (CFI>1) {CFI=1}

PRATIO PCFI NCP RMSEA MFI GH GFI AGFI PGFI AICchi AICdev BCCchi BCCdev BICchi BICdev CAICchi CAICdev ECVIchi ECVIdev MECVIchi MECVIdev RMR SRMR indices rbind(N,deviance,N.parms,Chi,df,p.Chi,Chi.df,AICchi,AICdev,BCCchi,BCCdev,BICchi,BICdev,CAICchi,CAICdev,RMSEA,SRMR,RMR,GFI,AGFI,PGFI,NFI,RFI,IFI,NNFI.TLI,CFI,PRATIO,PNFI,PCFI,NCP,ECVIchi,ECVIdev,MECVIchi,MECVIdev,MFI,GH)

return(indices)

}

fit.cov(indepfit,modelfit)

See this thread for a proposal of CI for RMSEA: http://openmx.psyc.virginia.edu/thread/1269#comment-4919

cheers,

Andreas

So you *are* my god! Thanks so much! I think I need to upgrade things to get this to work for me, I'll try it out and let you know if there are any problems.

Update on fit statistics.

First, I've noted your observation that AIC and BIC "seemed OK or off by a factor of 2." For some reason, we were multiplying BIC by 0.5. This will be checked in for the next binary release; we should support AIC and BIC with both the -2*df and the +2*parameters corrections soon, as well as sample size adjusted BIC.

The bigger issue pertains to fit statistics like CFI that require not just a saturated likelihood, but an independence model likelihood and df for all models as well. This will take a few more additions to the summary function and optimization, and may take a little time to make sure we get the specification right.

Thanks a lot for the update. This is beyond my competence, as you have seen, so I'll just be looking forward to future releases for the fit indices. I appreciate your continued effort.

again on fit statistics:

I updated and extended Oavasns original function (I think I found a couple of minor mistakes and hopefully was able to fix them). Any check by the OpenMx team or anybody else would be appreciated. The code can certainly be simplified. For instance, I ignore how to extract a model's estimated covariance matrix (called 'estimate.cov' below), hence got this with RAM algebra. The Confidence Interval of the RMSEA is still missing.

fit.index indep indep.chi indep.df model model.chi model.dev model.df model.ml N N.est.param N.manifest N.latent observed.cov A S F I estimate.cov observed.cor estimate.cor Id.manifest residual.cov residual.cor F0 if (F0 NFI NNFI.TLI PNFI IFI CFI if (CFI>1) {CFI=1}

RMSEA MFI GH GFI (sum(diag((solve(estimate.cor)%*%observed.cor)%*%(solve(estimate.cor)%*%observed.cor)))))

AGFI PGFI #AIC AIC #CAIC CAIC #BIC BIC RMR SRMR indices return(indices)

}

Thanks, Paolo. These formulae look correct based on my casual inspection, but I'll put look at them more carefully soon. We're working on adding automatic calculation of the independence model, which should make these a lot easier.

If I am reading Paolo's code correctly, it expects the saturated model likelihood to be in the model being evaluated.

Can I just stick this in there before using his fuction?

To facilitate use & development of additional fit indices with OpenMx 2, umx::umxFitIndices(model) supports code from @0avasns, @paologhisletta, @brauer, and, especially, @bwiernik for bug fixes to RMR and SRMR and for adding MAR/SMAR fit indices…

noteThis is beta code, not tested for robustness to, for instance, multiple group models, missing data, definition variables, matrix-based models. Bang on the code: pull requests to https://github.com/tbates/umxumx::umxFitIndices(model) returns:

N, deviance, N.parms, Chi, df, p.Chi, Chi.df, AICchi, AICdev, BCCchi, BCCdev, BICchi, BICdev, CAICchi, CAICdev, RMSEA, SRMR, RMR, MAR, SMAR, GFI, AGFI, PGFI, NFI, RFI, IFI, NNFI.TLI, CFI, PRATIO, PNFI, PCFI, NCP, ECVIchi, ECVIdev, MECVIchi, MECVIdev, MFI, GH