Puzzling warnings and errors with lavaan.mi and plausibleValues

302 views
Skip to first unread message

Pat Malone

unread,
Mar 22, 2022, 5:05:43 PM3/22/22
to lav...@googlegroups.com
Hi.

I'm using semTools to generate results on imputed data and plausible values from those for the first time. I'm running into two problems, which may be linked.

With the syntax:

fitted.cfa.mi <- sem.mi(lavcfasyntax, data=df, m = 3)

I get these warnings:

Warning messages:
1: In amelia.prep(x = x, m = m, idvars = idvars, empri = empri, ts = ts,  :
  You have a small number of observations, relative to the number, of variables in the imputation model.  Consider removing some variables, or reducing the order of time polynomials to reduce the number of parameters.
2: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
3: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate

#1 I'm aware of. But #2 and #3 don't make sense. When I run varTable(df), the lowest variance in the observed data is 0.178 and the highest is 3.019--clearly not off by a factor of 1000.

When I press on and run:

RT.pv <- plausibleValues(fitted.cfa.mi, nDraws = 3, omit.imps = c("no.conv", "no.se"))

I get:

Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,  :
  number of items to replace is not a multiple of replacement length
In addition: Warning messages:
1: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
2: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate

trace_back() didn't give me any insight. My guess is whatever is causing the "factor of 1000" issue is making the plausible values generations fail, so there is no result to feed back.

When I use mice instead of amelia in sem.mi(), and everything else identical, I get no errors or warnings at the sem.mi() step, but still the "Error in LAMBDA..." at the plausibleValues() step (and no warnings).

Help?

Thanks,
Pat
--
Patrick S. Malone, PhD
Sr Research Statistician, FAR HARBΦR
This message may contain confidential information; if you are not the intended recipient please notify the sender and delete the message.

Pat Malone

unread,
Mar 22, 2022, 5:13:59 PM3/22/22
to lav...@googlegroups.com
I should add that:

fitted.cfa <- sem(lavcfasyntax, data=df, missing="ml", em.h1.iter.max=5000)

Using ML for missing produces mostly-sensible results with no warnings or errors, though one model-implied correlation is >1. There are no surprises in residual or LV variances. Fit is poor, but not absurd (this is not the final model).

Pat


Terrence Jorgensen

unread,
Mar 24, 2022, 8:26:53 AM3/24/22
to lavaan
When I run varTable(df), the lowest variance in the observed data is 0.178 and the highest is 3.019--clearly not off by a factor of 1000.

Did you run varTable() on each imputation?  Those are what the model is being fitted to.  Maybe Amelia's imputations are wacky.  That would explain why mice doesn't give you the same problem, since its default is predictive mean matching (i.e., only observed values are used as candidates to impute missing values).


Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,  :
  number of items to replace is not a multiple of replacement length

This doesn't look like anything in semTools.  Try fitting the model to 1 imputed data set in lavaan, then running lavPredict() on it to see if the same error occurs.  If I had to guess, your model has higher-order factors, and lavaan is trying to extract some loadings from the Beta matrix, but I can't tell what is going wrong.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Pat Malone

unread,
Mar 25, 2022, 1:23:11 PM3/25/22
to lav...@googlegroups.com
Thanks, Terrence.

You were correct on the first part--one variable got outlandish imputed values out of Amelia. I removed that variable from the dataset for now, and sem.mi() ran with only the small-N warning.

The error on plausibleValues() remains, though.

fitted.cfa2.1mi <- sem(lavcfasyntax2, data=RTmi.amelia$imputations$imp1)

runs fine.

Your suggestion of

predicted <- lavPredict(fitted.cfa2.1mi)

also (like plausibleValues) returns

Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,  :
  number of items to replace is not a multiple of replacement length


So it does seem to be happening at the lavaan step. The model has several first-order factors, and a saturated set of explicit covariances among the factors and several more observed variables. All variables numeric. 

str(fitted.cfa2.1mi@Model) doesn't show a beta matrix (or an MLIST entry at all)--only GLIST with lambda, theta, and psi.

Any ideas? This was lavaan 0.6-10, but also happens with the development version. Email Yves?

str(fitted.cfa2.1mi@Model)
Formal class 'lavModel' [package "lavaan"] with 63 slots
  ..@ GLIST            :List of 3
  .. ..$ lambda: num [1:44, 1:19] 1 0.807 0.95 0 0 ...
  .. ..$ theta : num [1:44, 1:44] 0.661 0 0 0 0 ...
  .. ..$ psi   : num [1:19, 1:19] 0.363 -0.383 -0.168 -0.15 -0.368 ...
  ..@ dimNames         :List of 3
  .. ..$ :List of 2
  .. .. ..$ : chr [1:44] "A5.BPNF.Aut" "A5.BPNF.Com" "A5.BPNF.Rel" "A5.BPNS.Aut" ...
  .. .. ..$ : chr [1:19] "NeedF" "NeedS" "PerCTSID" "PerPSE" ...
  .. ..$ :List of 2
  .. .. ..$ : chr [1:44] "A5.BPNF.Aut" "A5.BPNF.Com" "A5.BPNF.Rel" "A5.BPNS.Aut" ...
  .. .. ..$ : chr [1:44] "A5.BPNF.Aut" "A5.BPNF.Com" "A5.BPNF.Rel" "A5.BPNS.Aut" ...
  .. ..$ :List of 2
  .. .. ..$ : chr [1:19] "NeedF" "NeedS" "PerCTSID" "PerPSE" ...
  .. .. ..$ : chr [1:19] "NeedF" "NeedS" "PerCTSID" "PerPSE" ...
  ..@ isSymmetric      : logi [1:3] FALSE TRUE TRUE
  ..@ mmSize           : int [1:3] 836 990 190
  ..@ representation   : chr "LISREL"
  ..@ modprop          :List of 6
  .. ..$ uvreg  : logi FALSE
  .. ..$ uvord  : logi FALSE
  .. ..$ mvreg  : logi FALSE
  .. ..$ nexo   : int 0
  .. ..$ acyclic: logi NA
  .. ..$ bowfree: logi NA
  ..@ meanstructure    : logi FALSE
  ..@ categorical      : logi FALSE
  ..@ multilevel       : logi FALSE
  ..@ group.w.free     : logi FALSE
  ..@ link             : chr "default"
  ..@ nblocks          : int 1
  ..@ ngroups          : int 1
  ..@ nefa             : int 0
  ..@ nmat             : int 3
  ..@ nvar             : int 44
  ..@ num.idx          :List of 1
  .. ..$ : int [1:44] 1 2 3 4 5 6 7 8 9 10 ...
  ..@ th.idx           :List of 1
  .. ..$ : NULL
  ..@ nx.free          : int 248
  ..@ nx.user          : int 256
  ..@ m.free.idx       :List of 3
  .. ..$ : int [1:25] 2 3 49 50 96 97 98 144 145 146 ...
  .. ..$ : int [1:33] 1 46 91 136 181 226 271 316 361 406 ...
  .. ..$ : int [1:361] 1 2 3 4 5 6 7 8 9 10 ...
  ..@ x.free.idx       :List of 3
  .. ..$ : int [1:25] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ : int [1:33] 197 198 199 200 201 202 203 204 205 206 ...
  .. ..$ : int [1:361] 241 142 120 33 143 131 50 144 66 81 ...
  ..@ m.user.idx       :List of 3
  .. ..$ : int [1:33] 1 2 3 48 49 50 95 96 97 98 ...
  .. ..$ : int [1:33] 1 46 91 136 181 226 271 316 361 406 ...
  .. ..$ : int [1:361] 1 2 3 4 5 6 7 8 9 10 ...
  ..@ x.user.idx       :List of 3
  .. ..$ : int [1:33] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ : int [1:33] 205 206 207 208 209 210 211 212 213 214 ...
  .. ..$ : int [1:361] 249 150 128 41 151 139 58 152 74 89 ...
  ..@ x.def.idx        : int(0)
  ..@ x.ceq.idx        : int(0)
  ..@ x.cin.idx        : int(0)
  ..@ x.free.var.idx   : int [1:44] 197 198 199 200 201 202 203 204 205 206 ...
  ..@ eq.constraints   : logi FALSE
  ..@ eq.constraints.K : num[0 , 0 ]
  ..@ eq.constraints.k0: num(0)
  ..@ def.function     :function ()  
  ..@ ceq.function     :function ()  
  ..@ ceq.jacobian     :function ()  
  ..@ ceq.JAC          : num[0 , 1:248]
  ..@ ceq.rhs          : num(0)
  ..@ ceq.linear.idx   : int(0)
  ..@ ceq.nonlinear.idx: int(0)
  ..@ cin.function     :function ()  
  ..@ cin.jacobian     :function ()  
  ..@ cin.JAC          : num[0 , 1:248]
  ..@ cin.rhs          : num(0)
  ..@ cin.linear.idx   : int(0)
  ..@ cin.nonlinear.idx: int(0)
  ..@ ceq.efa.JAC      : num[0 , 0 ]
  ..@ con.jac          : num[0 , 0 ]
  ..@ con.lambda       : num(0)
  ..@ nexo             : int 0
  ..@ conditional.x    : logi FALSE
  ..@ fixed.x          : logi FALSE
  ..@ parameterization : chr "delta"
  ..@ ov.x.dummy.ov.idx:List of 1
  .. ..$ : int(0)
  ..@ ov.x.dummy.lv.idx:List of 1
  .. ..$ : int(0)
  ..@ ov.y.dummy.ov.idx:List of 1
  .. ..$ : int [1:11] 34 35 36 37 38 39 40 41 42 43 ...
  ..@ ov.y.dummy.lv.idx:List of 1
  .. ..$ : int [1:11] 9 10 11 12 13 14 15 16 17 18 ...
  ..@ ov.efa.idx       :List of 1
  .. ..$ : NULL
  ..@ lv.efa.idx       :List of 1
  .. ..$ : NULL
  ..@ rv.ov            : list()
  ..@ rv.lv            : list()
  ..@ H                : list()
  ..@ lv.order         : list()
  ..@ estimator        : chr "ML"
  ..@ estimator.args   : list()



--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/d4591de3-e3fb-4338-8cff-b48c4cabed24n%40googlegroups.com.

Terrence Jorgensen

unread,
Mar 28, 2022, 9:16:51 AM3/28/22
to lavaan
So no higher-order factors, but a lot of them (19 with 44 indicators).  I can't guess further without seeing a pattern matrix; could you post one (or a path diagram, if legible) showing the factor structure?  I'm wondering if this is one of those situations where lambda can't be inverted, although that wouldn't explain the error message.  Does this happen when you set method = "Bartlett" too?

Email Yves?

Probably (I'm out of ideas), or open a GitHub issue:  https://github.com/yrosseel/lavaan/issues

Terrence Jorgensen

unread,
Mar 28, 2022, 10:34:34 AM3/28/22
to lavaan
Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,

This syntax only appears in the source code in a hidden function computeLAMBDA.LISREL(), and it looks like it is related to when an observed variable is given a phantom latent automatically, so that it can have an effect on another latent variable.  lavaan will automatically label the phantom latent the same as the observed variable's name. 
 
  number of items to replace is not a multiple of replacement length

This still confuses me, but it might make sense once you share your factor structure.

Pat Malone

unread,
Mar 31, 2022, 11:29:15 AM3/31/22
to lav...@googlegroups.com
Thanks again, Terrence. Sorry I've been slow to reply on this.

I found the problem. There's still a suggestion of an error, or a missed error-check, somewhere in lavPredict.

Part of what puzzled me was the estimation completes as expected with missing="ml" on Swiss-cheese data and with no difference in the model syntax. 

What I discovered on closer investigation is grossly increased nonnormality (in different places) in the amelia-imputed datasets. But problem also occurs using mice, as previously noted. Even using mice, there are still two horribly leptokurtic variables, also true in the original data. What I had not tried before is using lavPredict on the ML solution, and it also returns the error. So my guess is in plausibleValuesplaus.lavaan (which I don't know how to see directly) calls lavPredict (as noted in help), and that's where the non-normality makes plausibleValues fail.

I'm not github-savvy, but unless you have any further thoughts, I'll consolidate the conversation in an email to Yves about the error-checking.

Thank you!



--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.

Terrence Jorgensen

unread,
Mar 31, 2022, 6:12:51 PM3/31/22
to lavaan
using lavPredict on the ML solution also returns the error

You mean when using FIML?  That should have returned a more informative error message from semTools.

 
So my guess is in plausibleValuesplaus.lavaan (which I don't know how to see directly)

You can access hidden functions with the triple-colon operator:  ?":::"

semTools:::plaus.lavaan # view source code



calls lavPredict (as noted in help), and that's where the non-normality makes plausibleValues fail.

I still can't verify that it is the nonnormality per se that makes plausibleValues() fail, although that would be an interesting reprex to send to Yves.
plausibleValues() already fails for FIML, and you already discovered that it is lavPredict() that fails for your at least some imputations, which would indeed cause plausibleValues() to fail.

Pat Malone

unread,
Apr 4, 2022, 12:29:50 PM4/4/22
to lav...@googlegroups.com
Terrence,

Thanks.

To address the first part, I hadn't tried plausibleValues from the FIML solution, because of the limitation on those for incomplete data. But no, the messages with lavPredict are not more informative:

> fitted.cfa2 <- sem(lavcfasyntax2, data=df, missing="ml", em.h1.iter.max=5000)
> predicted.fiml <- lavPredict(fitted.cfa2)
Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,  :
  number of items to replace is not a multiple of replacement length


> PV.fiml <- plausibleValues(fitted.cfa2, nDraws = 3)
Error in FUN(X[[i]], ...) :
  Plausible values not available (yet) for missing data + fiml.
       Multiple imputations can be used via lavaan.mi()

.

I'll set up a reprex for Yves. And noted on the :::, thank you.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.

Pat Malone

unread,
Apr 19, 2022, 7:14:44 AM4/19/22
to lav...@googlegroups.com, yros...@gmail.com
Terrence, cc'ing Yves

I found what was breaking both lavPredict() and plausibleValues(). It was how I was handling the combination of latent and observed variables in the model with saturated covariances.

When the model was:

A <-> B, F1, F2
B <-> F1, F2
F1 <-> F2

(where A and B are observed and F1 and F2 are multiple-indicator latents)

I got the lavPredict() error 

Error in LAMBDA[ov.y.dummy.ov.idx, ] <- MLIST$beta[ov.y.dummy.lv.idx,  :
  number of items to replace is not a multiple of replacement length

Even though there is no beta matrix.

When I constructed the equivalent model:

A <-> B (explicit)
A -> F1, F2
B -> F1, F2
F1 <-> F2 (implicit)

It ran fine.

Yves, if this isn't enough to reproduce it, I can do a full reprex for you.

Hope this helps, and thanks.
Pat
Reply all
Reply to author
Forward
0 new messages