Error in `[.data.frame`(data, , unlist(ov.names)) : undefined columns selected

2,345 views
Skip to first unread message

frankh...@gmail.com

unread,
Apr 14, 2013, 5:19:43 PM4/14/13
to lav...@googlegroups.com
hi,
sorry, I'm relatively new to R and lavaan. When I try to import a csv file in lavaan, I get this message:
> Error in `[.data.frame`(data, , unlist(ov.names)) : undefined columns selected
Don't see what can have gone wrong. When i list the data, everything seems okay. Any idea? Variable name length perhaps? There are some names exceeding 15 chars.
Thanks
Frank

yrosseel

unread,
Apr 15, 2013, 2:50:08 AM4/15/13
to lav...@googlegroups.com
On 04/14/2013 11:19 PM, frankh...@gmail.com wrote:
> hi,
> sorry, I'm relatively new to R and lavaan. When I try to import a csv
> file in lavaan, I get this message:
> > Error in `[.data.frame`(data, , unlist(ov.names)) : undefined columns
> selected

Assuming your data.frame is called 'Data', and the syntax is in 'Model', try

names(Data)

to see the observed variables names in the dataset, and

lavaanNames(lavaanify(Model))

to see the observed variables names in the model. The latter must be a
subset of the former.

Do you have any spaces in the variables names? If so, remove them.

Yves.

frankh...@gmail.com

unread,
Apr 15, 2013, 3:34:22 AM4/15/13
to lav...@googlegroups.com
Thanks Yves, that helped. I was trying to do a second order factor analysis and assumed that I should use '~' to specify the functions of first to second order factors. That caused lavaan to search for the second order factors in the data set. But with '=~' instead it does the trick.
Frank

Sachnaz Oktarina

unread,
Jul 1, 2013, 9:21:59 PM7/1/13
to lav...@googlegroups.com
Dear All,,,

I have same problem with this, that the statement 'error in data.frame (data, , unlist(ov.names))......' pop out.
I also have tried the trick Mr Rosseel suggested. when I put syntax lavaanNames(lavaanify(my model)). It still turn out wrong. 
its appeared another notif; 

warning message;
In vnames(FLAT,"ov.x", warn=TRUE)
lavaan warning; model syntax contains variance/covariance/intercept formulas involving (an) exogenous variable(s)

I am kinda newbie with this package. should you have any troubleshoot for this, I would be delighted if anyone could help.

many thanks.

yrosseel

unread,
Jul 2, 2013, 3:59:55 AM7/2/13
to lav...@googlegroups.com

> warning message;
> In vnames(FLAT,"ov.x", warn=TRUE)
> lavaan warning; model syntax contains variance/covariance/intercept
> formulas involving (an) exogenous variable(s)

Somewhere in your model syntax, you have specified either a variance, a
covariance or an intercept involving an exogenous (independent)
variable. By default, there is no reason to do so, because lavaan uses
the fixed.x=TRUE argument, implying that the exogenous variables are not
part of the model.

Simply removing these formulas from your syntax should work. To find out
which variables are exogenous, try:

lavNames( lavaanify(myModel), type="ov.x" )

The alternative is to use fixed.x=FALSE, which is mostly harmless, as
long as all your exogenous variables are continuous.

Yves.

Reply all
Reply to author
Forward
0 new messages