Level 1 latent variable as dependent variable in regression

85 views
Skip to first unread message

Syedah Iqbal

unread,
Jan 19, 2025, 4:20:12 PM1/19/25
to lavaan
Dear community, 

I am trying to implement a multilevel SEM. I am laying out the code below. 
All lines of code, except for this one: #diclima + dirins + tais + emotions ~  sesf1 + amotivation + external_s + external_m + introjected + identified + intrinsic ' work well. 

For this line, I get the error: Error: lavaan->lav_lavaan_step02_options():
missing observed variables in dataset: diclima dirins tais emotions

In my understanding, R is not accepting the latent variables created at level 1 as dependent variables in Level 2.
Would highly appreciate support in how this can be fixed. 

Thanks a lot!

Aroob.

#Multilevel SEM:
h2_1 <- '
#Measurement Model:

level: 1

diclima =~ infoclass_notlistening + infoclass_noise + infoclass_longwait
dirins =~ infoclass_review + infoclass_overview + infoclass_checkunderstand
tais =~ infoclass_proactive + infoclass_explanation + infoclass_adaption + infoclass_adjustment + infoclass_indsupport + infoclass_feedback + infoclass_encouragement
emotions =~ assessment_liketeaching + assessment_enjoy + assessment_inspiring + assessment_encouragement + assessment_respect + assessment_understanding
#regression:
diclima + dirins + tais + emotions ~  sesf1


level: 2
#BNSF
need_satisfaction =~ as1 + as2 + as3 + as4 +
rs1 + rs2 + rs3 + rs4 +
cs1 + cs2 + cs3 + cs4
need_frustration =~ rf1 + rf2 + rf3 + rf4 + cf1 + cf2 + cf3 + cf4

#MWMS
amotivation =~ m_1 + m_2 + m_3
external_s =~ m_4 + m_5 + m_6
external_m =~ m_7 + m_8 + m_9
introjected =~  m_12 + m_13
identified =~ m_10 + m_11 + m_14 + m_15 + m_16
intrinsic =~ m_17 + m_18 + m_19

#Regressions
amotivation + external_s + external_m + introjected + identified + intrinsic ~ need_satisfaction + need_frustration '
#diclima + dirins + tais + emotions ~  sesf1 + amotivation + external_s + external_m + introjected + identified + intrinsic '

fit1 <- lavaan::sem(h2_1, data = df, std.lv = TRUE, cluster = "school_id",fixed.x = FALSE)
summary(fit1,fit.measures = TRUE, standardized = TRUE, rsquare = TRUE)
lavaan.diagram(fit1)

Yago Luksevicius de Moraes

unread,
Jan 20, 2025, 8:42:02 AM1/20/25
to lavaan

Hi, Aroob.

The message missing observed variables in dataset: diclima dirins tais emotions says that the dataframe does not have any column with the same name as the variables diclima dirins tais emotions. Check if there is any misspelling.

Best,
Yago

​

Syedah Iqbal

unread,
Jan 20, 2025, 10:21:04 AM1/20/25
to lavaan
Thanks a lot Yago,

These are level 1 latent variables that are being created in the initial lines in the model :
"diclima =~ infoclass_notlistening + infoclass_noise + infoclass_longwait
dirins =~ infoclass_review + infoclass_overview + infoclass_checkunderstand
tais =~ infoclass_proactive + infoclass_explanation + infoclass_adaption + infoclass_adjustment + infoclass_indsupport + infoclass_feedback + infoclass_encouragement
emotions =~ assessment_liketeaching + assessment_enjoy + assessment_inspiring + assessment_encouragement + assessment_respect + assessment_understanding"

But when I try to use these in the level 2 regression, they are not being recognized. In the level 1 regression, the same variables are recognized and I get the regression results. 

Thanks a lot and look forward!
Aroob.

Yago Luksevicius de Moraes

unread,
Jan 21, 2025, 8:33:19 AM1/21/25
to lavaan
Hi, Aroob.

Thanks for the clarification.
Unfortunately, I have no experience with multilevel SEM, but it seems `lavaan` does not transpose the latent variables from one level to another. Perhaps, someone with more experience than me knows how to do what you want, but I think you will have to create the latent variables in both levels.

Best,
Yago 

Łukasz Stasiełowicz

unread,
Jan 22, 2025, 4:42:17 PM1/22/25
to lavaan

Dear Aroob,

 

As Yago mentioned, lavaan probably expects variables to be defined at each level at which you want to use them.


For example, if you want to look at motivation from both the within and between perspectives, then you might have to define it at both levels. For example:

level: 1

amotivation_within =~ m_1 + m_2 + m_3

level: 2

amotivation_between =~ m_1 + m_2 + m_3

 

Check out the official lavaan tutorial for a reproducible example:

https://lavaan.ugent.be/tutorial/multilevel.html

 

Best,

Lukasz

Reply all
Reply to author
Forward
0 new messages