> I think I have a basic problem in my dataset which due to my lack of
> understanding of R I can't solve. My dataset contains numeric values
> from a Likert-type survey (1 to 5). Here is the code
>
> study1<-read.table("F:/TULIP_RESEARCH/Study 1/study1_forinputR.csv", sep
> = ";")
>
is.na(study1)
> study1[study1==8888888]<-NA
>
is.na(study1)
>
> install.packages("lavaan", dependencies = TRUE)
> library(lavaan)
>
> AE.model <- '
> dkw =~V6 + V7 +V8 +V9 +V10
> mc =~V11 + V12 +V13 +V14
> c =~V15 + V16 + V17+V18+V19+V20+V21+V22
> '
>
> fit<-cfa(AE.model, data=study1)
>
> and this is the warning message I receive:
>
> Warning messages:
> 1: In if (f.names %in% unlist(ov.names)) warning(paste("lavaan WARNING:
> unordered factor(s) detected in data:", :
> the condition has length > 1 and only the first element will be used
> 2: In getDataFull(data = data, group = group, group.label = group.label, :
> lavaan WARNING: unordered factor(s) detected in data: V6 V7 V8 V9 V10
> V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22
Your dataset contains unordered factors (categorical variables). [which
is weird, if they are just numeric values 1,2,3,4,5; I would check the
input file; perhaps all the numbers are quoted? In that case, remove the
quotes; OR, did you forget 'header=TRUE' in the call to read.table to
get the variable names?]
To treat them as ordinal variables, you need to declare them as
'ordered'. You can do this before you call lavaan as follows:
Data[,] <- lapply(Data[,], ordered)
(here I assume *all* variables are ordered; if only a selection is
ordinal, while others are continuous, use something like:
Data[,c("item1","item2","item3","item4")] <-
lapply(Data[,c("item1","item2","item3","item4")], ordered)
If you now call the cfa() function, lavaan will treat the 'ordered'
variables as ordinal.
Another approach is to leave the data as it is, and to declare variables
as ordered usin the 'ordered' argument in the cfa() call:
fit<-cfa(AE.model, data=study1, ordered=c("V1","V2","V3",....) )
The latter approach has the advantage that you can switch between a
continuous approach and an ordinal approach to deal with likert scale items.
Hope this helps,
Yves.