Error in if (abs(ll.old - ll.new) < convergence) run <- FALSE

60 views
Skip to first unread message

周露阳

unread,
May 22, 2019, 1:52:04 PM5/22/19
to lavaan
My code for LMS are as follows:
+++++++++++++++++
library("nlsem")

model <- specify_sem(num.x = 20, num.y = 3, num.xi = 7, num.eta = 1,
                     xi = "x1-x3, x4-x6, x7-x9, x10-x12, x13-x15, x16-x18, x19-x20", 
                     eta = "y1-y3", interaction = "xi1:xi2")

load("part2b.RData")

set.seed(11111)
start <- runif(count_free_parameters(model))

res <- em(model, part2b, start, qml = F, convergence=0.01, verbose=TRUE, max.iter=99999, neg.hessian = TRUE)

summary(res)
coef(res)
logLik(res)
AIC(res)
BIC(res)
++++++++++++++++++

After being run, the results are:
+++++++++++++++++++
......
> res <- em(model, part2b, start, qml = F, convergence=0.01, verbose=TRUE, max.iter=99999, neg.hessian = TRUE)
-----------------------------------
Starting EM-algorithm for singleClass 
Convergence:  0.01 
-----------------------------------
-----------------------------------
Iteration 1 
Doing expectation-step 
Doing maximization-step 
Results of maximization 
Loglikelihood: -Inf
Convergence message: 0
Number of iterations: 1
----------------------------------- 
Iteration 2 
Doing expectation-step 
Doing maximization-step 
Results of maximization 
Loglikelihood: -Inf
Convergence message: 0
Number of iterations: 1
----------------------------------- 
Error in if (abs(ll.old - ll.new) < convergence) run <- FALSE : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In value[[3L]](cond) :
  Starting parameters for Phi are not positive definite. Identity matrix was used instead.
> summary(res)
......
+++++++++++++++++++++++++++++++

How can I do on my codes following the warnings?

When running within Mplus, everything is OK.

周露阳

unread,
May 22, 2019, 2:05:10 PM5/22/19
to lavaan
Bellow are the codes in lavaan grammar:

++++++++++++++++++
library("nlsem")

modLMS.model <- "
                 xi1 =~ x1 + x2 + x3
                 xi2 =~ x4 + x5 + x6
                 xi3 =~ x7 + x8 + x9 
                 xi4 =~ x10 + x11 + x12
                 xi5 =~ x13 + x14 + x15
                 xi6 =~ x16 + x17 + x18
                 xi7 =~ x19 + x20
                 eta =~ y1 + y2 + y3
                 eta ~ xi1 + xi2 + xi3 + xi4 + xi5 + xi6 + xi7 + xi1:xi2
               "
model <- lav2nlsem(modLMS.model)

load("part2b.RData")

set.seed(1111)
start <- runif(count_free_parameters(model))

res <- em(model, part2b, start, qml = F, convergence=0.01, verbose=TRUE, max.iter=99999, neg.hessian = TRUE, logger=TRUE, optimizer="nlminb")

summary(res)
coef(res)
logLik(res)
AIC(res)
BIC

dev.new()
plot(res)

+++++++++++++++++++++

But I faced with the same problem as shown below:


++++++++++++++++++++

> res <- em(model, part2b, start, qml = F, convergence=0.01, verbose=TRUE, max.iter=99999, neg.hessian = TRUE, logger=TRUE, optimizer="nlminb")

++++++++++++++++







Reply all
Reply to author
Forward
0 new messages