Error in cat(list(...), file, sep, fill, labels, append)

2,870 views
Skip to first unread message

Flor Giuliani

unread,
Aug 20, 2015, 11:00:41 AM8/20/15
to lav...@googlegroups.com
Hello, I a phd student from Mar del Plata, Argentina, and I a brand new at working with R. I am doing a cfa with categorical data and, when I get the following warning:

Warning messages:
1: In pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method = optim.method,  ... :
  lavaan WARNING: empty cell(s) in bivariate table of i2 x i1 
Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 2 (type 'S4') cannot be handled by 'cat'

I checked and there are no missing values. 
What can I do to solve this?
Thanks!








María Florencia Giuliani
Lic. en Psicología 
Becaria Doctoral CONICET
Grupo de Investigación en  Evaluación Psicológica
Facultad de Psicología, Universidad Nacional de Mar del Plata

Terrence Jorgensen

unread,
Aug 21, 2015, 5:25:06 AM8/21/15
to lavaan

Warning messages:
1: In pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method = optim.method,  ... :
  lavaan WARNING: empty cell(s) in bivariate table of i2 x i1 

This warning is not about missing data.  It is saying that not all possible response patterns have been observed.  This occurs often with categorical data, especially when there are more than 2 categories and/or the sample size is not huge.  You can print out a contingency table of the 2 variables it mentions (i2 and i1) to see what it is talking about.  When all cells have expected of 5 or more, then the chi-squared test statistic is actually distributed as a chi-squared random variable.  When there are missing values, it is not.  But that is OK -- you just have to use the column labeled "robust" in the summary output.

Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 2 (type 'S4') cannot be handled by 'cat'

I'm not sure what is causing this.  Providing an R script an enough data to reproduce the error might help someone on the board figure out what the problem is.

Terry

Flor Giuliani

unread,
Aug 21, 2015, 9:36:42 AM8/21/15
to lavaan

Thank you very much!!!  I´ve checked and there are many cells with less than 5. 
I am ver ver grateful!!!

Florencia

Peter Taylor

unread,
Dec 23, 2016, 6:01:38 AM12/23/16
to lavaan
I've been having the same error - I understand the issue with blank cells for categorical data - but the second part bother me


Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 2 (type 'S4') cannot be handled by 'cat'

I've not seen this previously, does anyone know yet what the cause of this is?

Thanks

Peter

Terrence Jorgensen

unread,
Dec 23, 2016, 6:21:09 AM12/23/16
to lavaan
Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 2 (type 'S4') cannot be handled by 'cat'
I've not seen this previously, does anyone know yet what the cause of this is?

Somewhere, somehow, the cat() function is trying to operate on an S4 object.  You can see this returns an error if you try to "cat" (print to the screen, or a file) any S4 class object, such as a fitted lavaan object.  

example(cfa)
cat("This is my output", fit)

I don't know why this operation would be happening internally in lavaan (maybe in the summary() method?), so we would need more information to see how this is happening.  First, check that the problem hasn't already been fixed in the development version of lavaan:

install.packages("lavaan", repos = "http://www.da.ugent.be", type = "source")

If the error still occurs, please try posting an R script and portion of your data (or some similar-looking fake data) that can reproduce the problem.

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

Peter Taylor

unread,
Dec 23, 2016, 11:33:35 AM12/23/16
to lavaan
Thanks Terrence. I'm still getting this with the development version. Here's the script, - i've attached a portion of the data as a STATA file

library(foreign)

 fm <- read.dta()

 

fm[,c("PHLMS_1", "PHLMS_3", "PHLMS_5", "PHLMS_7", "PHLMS_9", "PHLMS_11", "PHLMS_13", "PHLMS_15", "PHLMS_17", "PHLMS_19", "PHLMS_2R", "PHLMS_4R", "PHLMS_6R", "PHLMS_8R", "PHLMS_10R", "PHLMS_12R", "PHLMS_14R", "PHLMS_16R", "PHLMS_18R", "PHLMS_20R")] <- lapply(fm[,c("PHLMS_1", "PHLMS_3", "PHLMS_5", "PHLMS_7", "PHLMS_9", "PHLMS_11", "PHLMS_13", "PHLMS_15", "PHLMS_17", "PHLMS_19", "PHLMS_2R", "PHLMS_4R", "PHLMS_6R", "PHLMS_8R", "PHLMS_10R", "PHLMS_12R", "PHLMS_14R", "PHLMS_16R", "PHLMS_18R", "PHLMS_20R")], ordered)

library(lavaan)

model1 <-  '

# latent variable definitions

ACCEPT =~ PHLMS_2R + PHLMS_4R + PHLMS_6R + PHLMS_8R + PHLMS_10R + PHLMS_12R + PHLMS_14R + PHLMS_16R + PHLMS_18R + PHLMS_20R

AWARE =~ PHLMS_1 + PHLMS_3 + PHLMS_5 + PHLMS_7 + PHLMS_9 + PHLMS_11 + PHLMS_13 + PHLMS_15 + PHLMS_17 + PHLMS_19'

 

fit1 <- sem(model1, data = fm)

 

summary(fit1, standardized = TRUE, fit.measures = TRUE, modindices = TRUE)



It only happens if I treat the data as categorical - so seems tied up with the zero cell counts issue.


fm prep2.dta

Yves Rosseel

unread,
Dec 23, 2016, 11:45:31 AM12/23/16
to lav...@googlegroups.com
On 12/23/2016 05:33 PM, Peter Taylor wrote:
> Thanks Terrence. I'm still getting this with the development version.

It works fine here, both with lavaan 0.5-22 and the dev version (see
attach). Can you show us the output of

sessionInfo()

If you remove the modindices = TRUE argument from the summary() call, do
you still get the error?

Yves.
out.txt

Peter Taylor

unread,
Dec 23, 2016, 11:57:59 AM12/23/16
to lavaan
Thanks for looking at this

I'm not sure i've been clear - so I get told there are 50 or more warnings in the output, and it is only when I use warnings(fit1) that I get the error - this is with lavaan (0.5-23.1044). Do you not get this error message even if you use warnings() ?

Yves Rosseel

unread,
Dec 23, 2016, 1:38:09 PM12/23/16
to lav...@googlegroups.com
On 12/23/2016 05:57 PM, Peter Taylor wrote:
> warnings in the output, and it is only when I use warnings(fit1) that I
> get the error

It is just warnings(), not warnings(fit1)

warnings() is a generic R function to show the last warnings; it is not
a lavaan function.

Yves.

Peter Taylor

unread,
Dec 23, 2016, 2:38:53 PM12/23/16
to lavaan
Ah, that's fixed it, just had the warnings syntax wrong, thanks
Reply all
Reply to author
Forward
0 new messages