> set.seed(40850) > f <- c(.7, .9, .2, .8) > u <- diag(1 - f*f) > Sigma <- f %*% t(f) + u > N <- 1000 > require(MASS) Loading required package: MASS > X <- mvrnorm(N, rep(0, 4), Sigma) > obsCov <- cov(X) > vn <- paste("V", 1:4, sep="") > dn <- list(vn, vn) > dimnames(obsCov) <- dn > colnames(X) <- vn > require(OpenMx) Loading required package: OpenMx Loading required package: digest Loading required package: parallel > > fpat <- mxMatrix(name="fpat", type="Full", nrow=4, ncol=1, + free=T, values=f) > umat <- mxMatrix(name="u", type="Diag", nrow=4, free=T, + values=u) > preCov <- mxAlgebra(fpat %*% t(fpat) + u, name="preCov", + dimnames=dn) > obsData <- mxData(obsCov, type="cov", numObs=N) > fval <- mxAlgebra(.5*(N - 1)*(log(det(preCov)) + + tr(obsCov %*% solve(preCov))), name="fval") > mod1 <- mxModel("model1", fpat, umat, preCov, obsData, fval, + mxExpectationNormal("preCov", + dimnames=vn), + mxFitFunctionML()) > mod1Results <- mxRun(mod1) Running model1 > summary(mod1Results) Summary of model1 free parameters: name matrix row col Estimate Std.Error 1 model1.fpat[1,1] fpat 1 1 0.6922512 0.02908601 2 model1.fpat[2,1] fpat 2 1 0.8559875 0.02785426 3 model1.fpat[3,1] fpat 3 1 0.1512013 0.03283339 4 model1.fpat[4,1] fpat 4 1 0.7908501 0.02824966 5 model1.u[1,1] u 1 1 0.4859995 0.02650013 6 model1.u[2,2] u 2 2 0.2283604 0.02517079 7 model1.u[3,3] u 3 3 0.9119640 0.04097630 8 model1.u[4,4] u 4 4 0.3298020 0.02460171 observed statistics: 10 estimated parameters: 8 degrees of freedom: 2 fit value ( -2lnL units ): 2560.021 saturated fit value ( -2lnL units ): 2558.23 number of observations: 1000 chi-square: X2 ( df=2 ) = 1.791264, p = 0.4083494 Information Criteria: | df Penalty | Parameters Penalty | Sample-Size Adjusted AIC: -2.208736 17.79126 NA BIC: -12.024246 57.05331 31.64486 CFI: 1.000168 TLI: 1.000504 (also known as NNFI) RMSEA: 0 *(Non-centrality parameter is negative) [95% CI (0, 0.06808518)] Prob(RMSEA <= 0.05): 0.8859716 OpenMx does not recommend using GFI, AGFI, NFI (aka Bentler-Bonett), or SRMR: See help(mxSummary) for why. timestamp: 2015-05-26 21:24:12 Wall clock time (HH:MM:SS.hh): 00:00:00.24 OpenMx version number: 2.2.2 Need help? See help(mxSummary) > # note: fval gives -log(likelihood): > mod1Results@output$minimum [1] 2560.021 > 2*mod1Results$fval$result [,1] [1,] 2560.021 > > # so why doesn't this work given that it has the same > # start values and fval equals -log(likelihood)? > mod2 <- mxModel("model2", fpat, umat, preCov, obsData, fval, + mxFitFunctionAlgebra("fval")) > mod2Results <- mxRun(mod2) Running model2 Error: The job for model 'model2' exited abnormally with the error message: 1:Determinant Calculation: Nonsingular matrix (at row 4) on LUP decomposition. 2:Determinant Calculation: Nonsingular matrix (at row 4) on LUP decomposition. 3:Determinant Calculation: Nonsingular matrix (at row 4) on LUP decomposition. 4:Determinant Calculation: Nonsingular matrix (at row 4) on LUP decomposition. In addition: Warning message: In model 'model2' Optimizer returned a non-zero status code 6. The model does not satisfy the first-order optimality conditions to the required accuracy, and no improved point for the merit function could be found during the final linesearch (Mx status RED) Execution halted