如何解决连续调节剂和与 lavaan 中潜在变量的交互项
我是 lavaan 的新用户,我一直在尝试构建一个带有连续调节器和带有潜在变量的交互项的调节器模型。我想听听您对我的代码的反馈,尤其是我的方法在事后添加交互项方面是否合适(因为它需要将潜在变量保存在数据框中)。简单描述一下我的研究:我调查了压力和倦怠之间的关系,以及社会支持是否会调节这种关联。不幸的是,我还没有实际数据,因此我无法提供有关可能的警告/错误消息的信息。
#Creating the centered moderator variable SSMCOVID.c
Dataset$SSMCOVID.c <- scale(Dataset$SSMCOVID,scale = FALSE)
#Setting up the measurement model
RQ3 <- '
#Creating the independent TsM variable:
TsM =~ 1*SsM3mo + 1*SsM12mo + 1*SsM4y + 1*SsM4.5y
# Stress-burnout (independent-dependent):
PBAMCOVID ~ b1*TsM
#Support-burnout (moderator-dependent):
PBAMCOVID ~ b2*SSMCOVID.c '
fit.3 <- sem(RQ3,data = Dataset,estimator = 'MLR',missing = 'ML')
summary(fit.3,fit.measures=TRUE,standardized=TRUE)
#Extracting the predicted values of the model and adding them to the dataframe
data <- data.frame(Dataset,predict(fit.3))
#Creating a new variable with the interaction (note: dplyr package needed!)
data <- data %>%
mutate(TsM_x_SSMCOVID.c = TsM * SSMCOVID.c)
#Testing the predefined interaction (moderation):
Moderation <- ' PBAMCOVID ~ b3*TsM_x_SSMCOVID.c '
fit.Mod <- sem(Moderation,data = data,missing = 'ML')
summary(fit.Mod,standardized=TRUE)
解决方法
由于您没有提供实际数据,我将使用 HolzingerSwineford1939 数据框生成一个示例。库 semTools
具有使用不居中、均值居中、双均值居中或剩余居中的指标生成产品的功能:
df_mod <- indProd(data = HolzingerSwineford1939,#create a new data.frame with the interaction indicators
var1 = paste0("x",c(1:3)),#interaction indicators from the first latent
var2 = paste0("x",c(4:6)),#interaction indicators from the second latent
match = T,#use match-paired approach (it produces the product of the first indicators of each variable,the product of the second indicator of each latent variable...
meanC = T,# mean centering the main effect indicator before making the products
residualC = T,#residual centering the products by the main effect indicators
doubleMC = T) #centering the resulting products
head(df_mod[,(ncol(df_mod)-2):ncol(df_mod)]) #check the last three columns of the new data.frame
model_latent_mod <- "
latent_mod =~
x1.x4+
x2.x5+
x3.x6"
fit_lat_mod <- cfa(model = model_latent_mod,data = df_mod) #run your latent interaction measurement model
summary(object = fit_lat_mod,std=T,fit.m=T) #check the summary
然后您只需将此测量模型添加到您的结构模型中即可。这种方法对于产生潜在变量之间的交互很有用,我认为这应该是您的情况。
如果您想要潜在变量和清单变量之间的交互:
model_latent_manifest_inter <- "
latent_mod =~
x1
x2
x3
ageyr ~latent_mod:x4
"
fit_lat_mod <- sem(model = model_latent_manifest_inter,data = HolzingerSwineford1939) #run your latent interaction measurement model
summary(object = fit_lat_mod,fit.m=T) #check the summary
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。