Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify correlation between latent and observed variable in lavaan?

Tags:

r

r-lavaan

I would like to calculate the correlation between latent and observed variables using lavaan in R.

Here's a simple example of what I'm trying to do. We have some data and a lavaan model.

data(bfi)
names(bfi) <- tolower(names(bfi))
mod <- "
 agree =~ a1 + a2 + a3 + a4 + a5
 consc =~ c1 + c2 + c3 + c4 + c5
 age ~~ agree 
 age ~~ consc
"
lavaan::cfa(mod, bfi)

agree is a latent variable with 5 indicators. Age is an observed variable and I want to get the correlation between the observed variable age and the latent variable agree. The general way of specify covariance in lavaan is by putting ~~ in between the variables. But this doesn't seem to work when one of the variables is observed.

When I run the above, I get the following error:

Error in lav_model(lavpartable = lavpartable, representation = lavoptions$representation,  : 
  lavaan ERROR: parameter is not defined: agree ~~ age

In other SEM software, such as Amos, you'd just draw a double headed arrow between the latent and observed variable.

How do you include correlations between latent and observed variables in lavaan?

like image 801
Jeromy Anglim Avatar asked Jul 25 '16 05:07

Jeromy Anglim


People also ask

What does ~~ mean in Lavaan?

In this formula, the tilde (“ ~ ”) is the regression operator. On the left-hand side of the operator, we have the dependent variable ( y ), and on the right-hand side, we have the independent variables, separated by the “ + ” operator.

What is the difference between a latent variable and an observed variable?

Observed variables are represented by rectangular nodes in SEM and latent variables are represented by circles or ellipses. An important difference between the two types of variables is that an observed variable usually has a measurement error associated with it, while a latent variable does not.

How do you fix covariance in Lavaan?

Fixing parameters Recall that, by default, all exogenous latent variables in a CFA model are correlated. But if you wish to fix the correlation (or covariance) between a pair of latent variables to zero, you need to explicity add a covariance-formula for this pair, and fix the parameter to zero.

Can be directly observed to give proofs to latent variables?

A manifest variable is a variable or factor that can be directly measured or observed. It is the opposite of a latent variable, which is a factor that cannot be directly observed, and which needs a manifest variable assigned to it as an indicator to test whether it is present.


2 Answers

One workaround that seems to work is to trick lavaan into thinking an observed variable is a factor:

data(bfi)
names(bfi) <- tolower(names(bfi))
mod <- "
 agree =~ a1 + a2 + a3 + a4 + a5
 consc =~ c1 + c2 + c3 + c4 + c5
 agefac =~ age
 agefac ~~ agree
 agefac ~~ consc
"
lavaan::cfa(mod, bfi)

I.e., agefac is a latent version of age but because age is the only indicator and the coefficient of that indicator is constrained to 1, it will be the same thing as the observed age variable. You can then use this quasi-latent variable to correlate with actual latent variables.

like image 129
Jeromy Anglim Avatar answered Oct 21 '22 04:10

Jeromy Anglim


If the model isn't going to change, you can regress your observed variable on the latent. The resulting standardised regression coefficient will be equivalent to a correlation between the latent and a "quasi-latent" as described by @Jeromy. For example:

mod <- "
  agree =~ a1 + a2 + a3 + a4 + a5
  age ~ agree  # regression instead of correlation
"
lavaan::cfa(mod, bfi) %>% summary(standardized = TRUE)

The standardized regression coefficient of age on agree will be the same whether you run this or the model described by @Jeromy. Note, however, that the unstandardized coefficient will not be the same.

like image 21
Simon Jackson Avatar answered Oct 21 '22 03:10

Simon Jackson