problem with ordered factors: Error in lm.fit(y = y, x = X) : NA/NaN/Inf in 'x'

612 views
Skip to first unread message

hans.e...@gmail.com

unread,
Jan 2, 2013, 6:53:08 PM1/2/13
to lav...@googlegroups.com
I have a data set with many ordered factors. I have sucessfully used lavaan 0.4-14 on this set (as far as I understand lavaan 0.4-14 treats ordered factors as numerics and that's OK for me, even if it's not optimal).

lavaan 0.5-10 simple refuses to do sem() with the same set and the same model, see the output given with debug = TRUE in the attached file lavaan.output.txt.

str.txt consists of the output of str() on the data set.
model.txt is the model argument given to sem().

The error message given is:

Error in lm.fit(y = y, x = X) : NA/NaN/Inf in 'x'

There are quite some NA, but no NaN nor Inf, and cases with NA is, by default excluded from the analysis, so what is the problem here?

I can provide the data, or at least a sample, if needed.

Kind regards,

Hans Ekbrand
lavaan.output.txt
str.txt
model.txt

yrosseel

unread,
Jan 3, 2013, 4:58:51 AM1/3/13
to lav...@googlegroups.com
On 01/03/2013 12:53 AM, hans.e...@gmail.com wrote:
> I have a data set with many ordered factors. I have sucessfully used
> lavaan 0.4-14 on this set (as far as I understand lavaan 0.4-14 treats
> ordered factors as numerics and that's OK for me, even if it's not optimal).
>
> lavaan 0.5-10 simple refuses to do sem() with the same set and the same
> model

But it is not the same analysis. 0.5-10 'detects' that many of your
(dependent) variables are 'ordered', and treats them as such. To get
back the original (0.4-14) analysis, you should convert those variables
back to 'numeric'.

> The error message given is:
>
> Error in lm.fit(y = y, x = X) : NA/NaN/Inf in 'x'
>
> There are quite some NA, but no NaN nor Inf, and cases with NA is, by
> default excluded from the analysis, so what is the problem here?

The error occurs when computing the polychoric/polyserial correlations.
I would need to see the data to figure out why.

> I can provide the data, or at least a sample, if needed.

Could you first update and install the current version of lavaan
(0.5-11)? If the error persists, please send me a snippet of the data,
and your model script, so I can reproduce the error.

Yves.

Hans Ekbrand

unread,
Jan 3, 2013, 7:25:16 AM1/3/13
to lav...@googlegroups.com
On 2013-01-03 10:58, yrosseel wrote:
> Could you first update and install the current version of lavaan
> (0.5-11)?

I did that, and lo and behold, sem() started the analysis. Thanks very
much for your advice (and for lavaan)!

However, the analysis ended with another error:

Error: chunk 11 (label = fit.model.one)
Error in DX[th.idx > 0L, ] <- diag(nth) :
number of items to replace is not a multiple of replacement length
In addition: Warning messages:
1: In th[th.idx > 0L] <- TAU[, 1L] :
number of items to replace is not a multiple of replacement length
2: In th[th.idx > 0L] <- TAU[, 1L] :
number of items to replace is not a multiple of replacement length


Do you need the data to tell what is the problem now?

yrosseel

unread,
Jan 3, 2013, 9:58:08 AM1/3/13
to lav...@googlegroups.com
That is strange. I need to investigate this.

> Do you need the data to tell what is the problem now?

Yes, please. Perhaps, it is a bug somewhere. Only a snippet of the data
is enough. As long as it produces this error.

Yves.

Manolo Cabran

unread,
Nov 22, 2019, 4:05:21 AM11/22/19
to lavaan
hi, I am having a similar problem with ordinal data. lavaan version: 0.6-5
this is the error message i get:
> cc_fit_r <- lavaan::cfa(cc_model_r, data = cc, ordered = c("gend", "disab", "orph", "sol", "edu"), conditional.x = FALSE, std.lv = FALSE)
Error in Delta.group[, x.el.idx[[mm]]] <- DELTA :
  number of items to replace
is not a multiple of replacement length
In addition: Warning messages:
1: In th[th.idx > 0L] <- TAU[, 1L] :
  number of items to replace
is not a multiple of replacement length
2: In WLS.obs - WLS.est :
  longer
object length is not a multiple of shorter object length
3: In diff * diff * WLS.VD :
  longer
object length is not a multiple of shorter object length
4: In th[th.idx > 0L] <- TAU[, 1L] :

  number of items to replace
is not a multiple of replacement length

And this is my model:
cc_model_r <- '
cc =~ a*edu + b*sol # 2 reflective items to identify the formative construct
cc <~ c*age + d*gend + e*disab + f*orph # formative construct
'
Data can be retrieved here.
I suspected the issue might be related to NAs. A crosstab revealed that there are 12 NAS between edu and sol and 85 NAs between sol and gend. I tried re-fitting the model using the argument missing = "pairwise", but unsuccessfully.

Regards

Manolo

Terrence Jorgensen

unread,
Nov 22, 2019, 7:09:00 AM11/22/19
to lavaan
This is not the same error, so it would be better to start a new thread than revive an old, unrelated issue.

Two observations:

(1) 

You have a MIMIC model, and already define cc twice as a reflective construct and as a formative construct.  Just pick one.  

cc ~ c*age + d*gend + e*disab + f*orph # same thing  

The <~ operator creates a phantom variable "cc" to mask the fact that formative measurement is not measurement, so at best the formative operator is just an unnecessary redundancy.

(2)

The actual cause of the error is probably that you are declaring exogenous variables as ordered.  You need to create dummy codes to represent exogenous categorical variables.


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

Manolo Cabran

unread,
Nov 24, 2019, 5:40:40 AM11/24/19
to lav...@googlegroups.com
Hi Terrence, 
and thank you very much for your reply. I will open a new thread following your suggestion.
Just one comment on your second point, in the other models where I did not do as you suggested (i.e. dummyfying the ordered variables) lavaan was just issuing a warning that thresholds were created for the exogenous vars. Not to say I am right, of course, just that I was able to fit the models. However I will follow the dummy strategy from now onward. 
Thanks again!


----------------------------------------------

CABRAN Manolo

----------------------------------------------
Please consider the environment before printing this e-mail!
----------------------------------------------


--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Qy5IBGLsZ_w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/86063083-771f-4c5e-9cd1-d01eb64e0e15%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages