Path analysis with continuous and categorical variables

1,538 views
Skip to first unread message

Joe Glass

unread,
Nov 21, 2012, 2:20:20 PM11/21/12
to lav...@googlegroups.com
Dear list,

I am enjoying learning lavaan, and I have been trying to specify a model that contains a combination of continuous and categorical variables.  I seem to run into a problem when I have two dependent variables, one that is latent and the other is a continuous variable.  The latent has ordinal indicators.  I receive the error:

Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types,  : 
  unknown ov.types:integer

Below is my syntax:
structure <-   '  withdrawal =~ q21 + q22 + q23 + q24 + q26
                  pas =~ q50 + q51 + q52 + q53 + q55 + q56 + q58
                  continuousdv ~ withdrawal + pas
                  withdrawal ~ pas + audit10 + female + k6raw'
fit <- sem(structure, data=stig1, ordered=c(withdrawal.ordered, pas.ordered))

This error only occurs when I include the continuous dependent variable.  If I replace that variable with a latent, everything works fine.  Would this be a problem with my code?

Thanks,
Joe Glass

Joseph E. Glass, Ph.D.
Assistant Professor
School of Social Work
University of Wisconsin-Madison
1350 University Ave.
Madison, WI 53706

yrosseel

unread,
Nov 21, 2012, 2:54:08 PM11/21/12
to lav...@googlegroups.com
On 11/21/2012 08:20 PM, Joe Glass wrote:
> Dear list,
>
> I am enjoying learning lavaan, and I have been trying to specify a model
> that contains a combination of continuous and categorical variables. I
> seem to run into a problem when I have two dependent variables, one that
> is latent and the other is a continuous variable. The latent has
> ordinal indicators. I receive the error:
>
> Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types =
> ov.types, :
> unknown ov.types:integer
>
> Below is my syntax:
> structure <- ' withdrawal =~ q21 + q22 + q23 + q24 + q26
> pas =~ q50 + q51 + q52 + q53 + q55 + q56 + q58
> continuousdv ~ withdrawal + pas
> withdrawal ~ pas + audit10 + female + k6raw'
> fit <- sem(structure, data=stig1, ordered=c(withdrawal.ordered,
> pas.ordered))

I'm not sure, but could you remove the 'ordered' argument in your sem()
function call? From you explanation, I get that only the q21/q22/...
indicators are ordered. But not 'withdrawal.ordered' and 'pas.ordered'
(which do not appear under these names in your model syntax)?

Would you be able to send me your full R script and a snippet of the
data (so I can reproduce the error)?

Yves.

Aaron Franzen

unread,
Dec 10, 2012, 8:57:59 PM12/10/12
to lav...@googlegroups.com
Hello All, 
I seem to get a similar error message and am trying to figure out how to fix it/figure out what it is telling me. I have specified my dichotomous variables in the data frame already. My syntax and subsequent error code is below (with dummy variables in bold... since my 'ordered' specification was not in the model):

bread.model3 <-'eg=~q20g+q20h+q20c+q20d+q21c+q21d
j1=~q20e+q20f+q21b
j2=~q21m+q21n+q21o

improve~eg+j1+j2+educ+south+married+white+Male+q68+q79+q4+q42+evang

j1~1*j2
eg~j1
eg~j2
'
bread.fit3<-sem(bread.model3, data=data2)

Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types,  : 
  unknown ov.types:integer

The same model did run before I specified which variables were dummy variables.  

R: 2.15
lavaan: 0.5-10

Aaron 

yrosseel

unread,
Dec 11, 2012, 2:09:17 PM12/11/12
to lav...@googlegroups.com
On 12/11/2012 02:57 AM, Aaron Franzen wrote:
> Hello All,
> I seem to get a similar error message and am trying to figure out how to
> fix it/figure out what it is telling me. I have specified my dichotomous
> variables in the data frame already. My syntax and subsequent error code
> is below (with dummy variables in bold... since my 'ordered'
> specification was not in the model):
>
> bread.model3 <-'eg=~q20g+q20h+q20c+q20d+q21c+q21d
> j1=~q20e+q20f+q21b
> j2=~q21m+q21n+q21o
>
> *improve*~eg+j1+j2+educ+*south*+*married*+*white*+*Male*+q68+q79+q4+q42+*evang*
>
> j1~1*j2
> eg~j1
> eg~j2
> '
> bread.fit3<-sem(bread.model3, data=data2)
>
> Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types =
> ov.types, :
> unknown ov.types:integer

Could you send me a snippet of the data (say, the first 40 cases) so I
can replicate this?

In any case, it seems to me that only 'improve' should be declared as
ordered (only dependent variables!). Everything else should be numeric.

Yves.

TW

unread,
Sep 6, 2016, 3:15:39 PM9/6/16
to lavaan
Dear all,

unfortunately, I receive a similar response when trying to predict a continuous variable by a model consisting of categorial variables (5-point Likert scale). I also used the 'ordered' argument, hoping that it's working now.

That's what I got:
Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types,  : 
  unknown ov.types:factor
lavaan WARNING: unordered factor(s) with more than 2 levels detected in data

How can I fix / manage this problem?


Terrence Jorgensen

unread,
Sep 7, 2016, 3:56:50 AM9/7/16
to lavaan
Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types,  : 
  unknown ov.types:factor
lavaan WARNING: unordered factor(s) with more than 2 levels detected in data

You didn't post your R script, so I can't be sure, but it looks like your data contains variables of class "factor" instead of class c("ordered","factor").  That's something you can see how to change:  ?ordered

Also, you say that you are predicting a continuous outcome?  Does that mean that your categorical variables are exogenous predictors?  If so, you need to code them as dummy codes rather than using a factor variable as a predictor:


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

May Yang

unread,
Nov 14, 2018, 7:27:53 PM11/14/18
to lavaan
I have the same issue here. 
Reply all
Reply to author
Forward
0 new messages