semTools::semMI. lavaan ERROR [...] not a data.frame

175 views
Skip to first unread message

christop...@gmail.com

unread,
Mar 5, 2023, 10:32:29 AM3/5/23
to lavaan
I am running a lavaan model with semTools::semMI, using the following input:

out <- sem.mi(model, data = data, seed = 1234, ordered = ordered,
                       m = 20, miArgs = list(noms = "county2"))


Lavaan throws an error:

Error in (function (model = NULL, dataList = NULL, dataFunction = NULL,  :
  lavaan ERROR: (generated) data is not a data.frame (or a matrix)


I'm not able to fix this error... Data are in a date frame:

> class(data)
[1] "data.frame"


christop...@gmail.com

unread,
Mar 5, 2023, 10:49:58 AM3/5/23
to lavaan
I might have found the error. Please hold any comment. 

christop...@gmail.com

unread,
Mar 5, 2023, 11:04:43 AM3/5/23
to lavaan
The trick was to read above the error message... 

The following variable(s) are 'factors': 
[...]
You may have wanted to set this as a ID variable to remove it
from the imputation model or as an ordinal or nominal
variable to be imputed.  Please set it as either and
try again.

Terrence Jorgensen

unread,
Mar 7, 2023, 7:17:08 AM3/7/23
to lavaan
out <- sem.mi(model, data = data, seed = 1234, ordered = ordered,
                       m = 20, miArgs = list(noms = "county2"))

Of course, the best thing to do is use multiple-imputation software directly, which allows you more control over the process and further features (e.g., diagnostics in mice).  Imputing "within" runMI() is a legacy feature that will not be supported for much longer. 

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

Reply all
Reply to author
Forward
0 new messages