如何使用 processR 包调整经过审核的中介模型?
How adjust a moderated moderated mediation model with processR package?
我想用 lavaan
和 processR
包调整一个调节调节的中介模型。型号如下:
我尝试创建以下节制:
Innovativeness:Age
和
PBC:Innovativeness:Age
我的数据(df
):
df <- structure(list(Attitude = structure(c(33, 30, 37, 29, 36, 42,
27, 35, 35, 27, 22, 25, 42, 25, 38, 35, 38, 36, 34, 40), label = "Attitude", format.spss = "F8.2"),
SubNorm = structure(c(46, 53, 30, 27, 55, 37, 14, 55, 55,
57, 37.4, 48, 68, 43, 55, 39, 51.7, 36, 51.7, 60), label = "Subjective Norm", format.spss = "F8.2"),
PBC = structure(c(50, 50, 45, 38, 48, 41, 34, 40, 47, 42,
22, 38, 56, 42, 48, 38, 33, 30, 46, 45), label = "Perceived Behavior Control", format.spss = "F8.2"),
Intent = structure(c(21, 17, 14, 15, 15, 21, 18, 18, 19,
15, 10, 12, 21, 10, 19, 15, 21, 21, 19, 21), label = "Intention", format.spss = "F8.2"),
Behavior = structure(c(59, 36, 44, 35, 62, 60, 38, 38, 68,
42, 35, 16, 77, 24, 73, 35, 64, 35, 69, 60), label = "Behavior", format.spss = "F8.2"),
Religiosity = c(28L, 28L, 24L, 30L, 19L, 25L, 23L, 21L, 20L,
15L, 21L, 20L, 21L, 17L, 27L, 29L, 24L, 23L, 17L, 25L), Education = c(45L,
55L, 46L, 28L, 52L, 48L, 48L, 55L, 53L, 30L, 60L, 31L, 31L,
33L, 46L, 58L, 53L, 55L, 38L, 27L), Innovativeness = c(38L,
39L, 37L, 54L, 40L, 49L, 30L, 53L, 58L, 45L, 59L, 32L, 43L,
49L, 57L, 59L, 37L, 54L, 52L, 43L), Age = c(46L, 35L, 27L,
33L, 42L, 56L, 49L, 42L, 41L, 31L, 31L, 43L, 45L, 59L, 44L,
57L, 28L, 48L, 28L, 55L)), row.names = c(NA, -20L), class = c("tbl_df",
"tbl", "data.frame"))
我试过这个:
library(lavaan)
library(processR)
md_1 <- tripleEquation(
labels = list(X = "PBC", M = "Intent", Y = "Behavior"),
covar = list(name = c("SubNorm", "Attitude"),
site = c("M", "M")),
moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'),
site = list('a', 'a2', 'b'))
)
a2
是创新度 (W) 的流动 - 参见统计图表图像。
分析:
fit_1 <- sem(
model = md_1,
estimator = 'ML',
data = df,
se = 'bootstrap',
bootstrap = 10,
fixed.x = TRUE
)
但是:
estimatesTable(fit_1)
Variables Predictors label B SE z p β
1 Intent PBC a1 -0.16 0.44 -0.37 0.711 -0.31
2 Intent Innovativeness a2 -0.01 0.22 -0.02 0.982 -0.01
3 Intent PBC:Innovativeness a3 0.00 0.01 -0.02 0.982 -0.02
4 Intent Age a4 -0.06 0.15 -0.41 0.681 -0.16
5 Intent PBC:Age a5 0.00 0.00 0.67 0.506 0.34
6 Intent SubNorm f1 0.03 0.04 0.69 0.492 0.09
7 Intent Attitude f2 0.44 0.08 5.82 < 0.001 0.78
8 Behavior PBC c 0.72 0.52 1.37 0.171 0.33
9 Behavior Intent b1 0.98 2.67 0.37 0.714 0.23
10 Behavior Religiosity b2 0.08 2.05 0.04 0.967 0.02
11 Behavior Intent:Religiosity b3 0.02 0.11 0.21 0.834 0.17
流 Innovativeness:Age
和 PBC:Innovativeness:Age
未生成。
如何调整这条线:
moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'),
site = list('a', 'a2', 'b'))
获得这些所需的流量?
谢谢。
我终于得到了你问题的答案。由于此站点或任何其他站点上没有其他答案,我将 post 我的解决方案。
您缺少的是 vars
参数,您可以在其中确定应该在三重交互中的变量。所以在你的情况下你有一个模型 25,并且应该有三重交互 WZX。模型 25 的通用模板如下(只需替换字符串中的变量名称):
moderator <- list(name=c('W', 'Z', 'V'),
site=list(c('a'), c('a'), c('b')))
# Next part forces the triple interaction
# Two variables, both on the site 'a'
# X is added to these two variables to form a triple interacion
vars <- list(name=list(c('W', 'Z')),
site=list(c('a', 'a')))
model1 <- tripleEquation(X='X',
M='M',
Y='Y',
moderator=moderator,
vars=vars)
接下来我们输出公式
cat(model1)
你可以观察到的是,确实有一个新词:a7*interaction0
。这个interaction0
是W、Z、X的三重交互。但是,你的数据没有一列interaction0
,所以你必须做一个。
df$interaction0 <- df$W * df$Z * df$X
只有现在你才能运行以下拟合模型并输出。
semfit <- sem(model=model1, data=df)
summary(semfit)
这适用于型号 11、12、13、18、19、20、25、26、27、32、33、34、37、38、39、42、43、44、46、47、48 , 51, 52, 53, 54, 55, 56, 57...
我想用 lavaan
和 processR
包调整一个调节调节的中介模型。型号如下:
我尝试创建以下节制:
Innovativeness:Age
和
PBC:Innovativeness:Age
我的数据(df
):
df <- structure(list(Attitude = structure(c(33, 30, 37, 29, 36, 42,
27, 35, 35, 27, 22, 25, 42, 25, 38, 35, 38, 36, 34, 40), label = "Attitude", format.spss = "F8.2"),
SubNorm = structure(c(46, 53, 30, 27, 55, 37, 14, 55, 55,
57, 37.4, 48, 68, 43, 55, 39, 51.7, 36, 51.7, 60), label = "Subjective Norm", format.spss = "F8.2"),
PBC = structure(c(50, 50, 45, 38, 48, 41, 34, 40, 47, 42,
22, 38, 56, 42, 48, 38, 33, 30, 46, 45), label = "Perceived Behavior Control", format.spss = "F8.2"),
Intent = structure(c(21, 17, 14, 15, 15, 21, 18, 18, 19,
15, 10, 12, 21, 10, 19, 15, 21, 21, 19, 21), label = "Intention", format.spss = "F8.2"),
Behavior = structure(c(59, 36, 44, 35, 62, 60, 38, 38, 68,
42, 35, 16, 77, 24, 73, 35, 64, 35, 69, 60), label = "Behavior", format.spss = "F8.2"),
Religiosity = c(28L, 28L, 24L, 30L, 19L, 25L, 23L, 21L, 20L,
15L, 21L, 20L, 21L, 17L, 27L, 29L, 24L, 23L, 17L, 25L), Education = c(45L,
55L, 46L, 28L, 52L, 48L, 48L, 55L, 53L, 30L, 60L, 31L, 31L,
33L, 46L, 58L, 53L, 55L, 38L, 27L), Innovativeness = c(38L,
39L, 37L, 54L, 40L, 49L, 30L, 53L, 58L, 45L, 59L, 32L, 43L,
49L, 57L, 59L, 37L, 54L, 52L, 43L), Age = c(46L, 35L, 27L,
33L, 42L, 56L, 49L, 42L, 41L, 31L, 31L, 43L, 45L, 59L, 44L,
57L, 28L, 48L, 28L, 55L)), row.names = c(NA, -20L), class = c("tbl_df",
"tbl", "data.frame"))
我试过这个:
library(lavaan)
library(processR)
md_1 <- tripleEquation(
labels = list(X = "PBC", M = "Intent", Y = "Behavior"),
covar = list(name = c("SubNorm", "Attitude"),
site = c("M", "M")),
moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'),
site = list('a', 'a2', 'b'))
)
a2
是创新度 (W) 的流动 - 参见统计图表图像。
分析:
fit_1 <- sem(
model = md_1,
estimator = 'ML',
data = df,
se = 'bootstrap',
bootstrap = 10,
fixed.x = TRUE
)
但是:
estimatesTable(fit_1)
Variables Predictors label B SE z p β
1 Intent PBC a1 -0.16 0.44 -0.37 0.711 -0.31
2 Intent Innovativeness a2 -0.01 0.22 -0.02 0.982 -0.01
3 Intent PBC:Innovativeness a3 0.00 0.01 -0.02 0.982 -0.02
4 Intent Age a4 -0.06 0.15 -0.41 0.681 -0.16
5 Intent PBC:Age a5 0.00 0.00 0.67 0.506 0.34
6 Intent SubNorm f1 0.03 0.04 0.69 0.492 0.09
7 Intent Attitude f2 0.44 0.08 5.82 < 0.001 0.78
8 Behavior PBC c 0.72 0.52 1.37 0.171 0.33
9 Behavior Intent b1 0.98 2.67 0.37 0.714 0.23
10 Behavior Religiosity b2 0.08 2.05 0.04 0.967 0.02
11 Behavior Intent:Religiosity b3 0.02 0.11 0.21 0.834 0.17
流 Innovativeness:Age
和 PBC:Innovativeness:Age
未生成。
如何调整这条线:
moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'),
site = list('a', 'a2', 'b'))
获得这些所需的流量?
谢谢。
我终于得到了你问题的答案。由于此站点或任何其他站点上没有其他答案,我将 post 我的解决方案。
您缺少的是 vars
参数,您可以在其中确定应该在三重交互中的变量。所以在你的情况下你有一个模型 25,并且应该有三重交互 WZX。模型 25 的通用模板如下(只需替换字符串中的变量名称):
moderator <- list(name=c('W', 'Z', 'V'),
site=list(c('a'), c('a'), c('b')))
# Next part forces the triple interaction
# Two variables, both on the site 'a'
# X is added to these two variables to form a triple interacion
vars <- list(name=list(c('W', 'Z')),
site=list(c('a', 'a')))
model1 <- tripleEquation(X='X',
M='M',
Y='Y',
moderator=moderator,
vars=vars)
接下来我们输出公式
cat(model1)
你可以观察到的是,确实有一个新词:a7*interaction0
。这个interaction0
是W、Z、X的三重交互。但是,你的数据没有一列interaction0
,所以你必须做一个。
df$interaction0 <- df$W * df$Z * df$X
只有现在你才能运行以下拟合模型并输出。
semfit <- sem(model=model1, data=df)
summary(semfit)
这适用于型号 11、12、13、18、19、20、25、26、27、32、33、34、37、38、39、42、43、44、46、47、48 , 51, 52, 53, 54, 55, 56, 57...