【问题标题】:Mediated Moderation Model in R (Lavaan)R中的中介调节模型(Lavaan)
【发布时间】:2019-11-12 03:57:05
【问题描述】:

假设您有一个结果变量(Y;连续变量)、一个自变量(X;虚拟变量)和一个调节变量(W;虚拟变量)。假设您想测试另一个变量(M;连续)是否介导了 X 和 W 之间的联系。您将如何在 R 中编写此测试(使用 lavaan)?

离我最近的帖子是:Creating a first stage mediated moderation model, syntax issues

但是,提供的答案处理的问题与我的不同。我的问题是关于调解调解,而答案涉及调解调解

【问题讨论】:

    标签: r mediator r-lavaan


    【解决方案1】:

    假设XW 都是虚拟变量,您可以使用: 运算符:

    library(lavaan)
    #> This is lavaan 0.6-7
    #> lavaan is BETA software! Please report any bugs.
    df <- data.frame(id=1:301)
    df$w <- dummies::dummy(HolzingerSwineford1939$school)[,1]
    #> Warning in model.matrix.default(~x - 1, model.frame(~x - 1), contrasts = FALSE):
    #> non-list contrasts argument ignored
    df$x <- dummies::dummy(HolzingerSwineford1939$sex)[,1]
    #> Warning in model.matrix.default(~x - 1, model.frame(~x - 1), contrasts = FALSE):
    #> non-list contrasts argument ignored
    df$y <- HolzingerSwineford1939$x9
    df$m <- HolzingerSwineford1939$agemo
    
    model <- "
    #x9 will be your Y
    #sex will be your X
    #school will be your W
    #agemo will be your M
    y ~ x + w + c*x:w + b*m
    m ~ a*x:w
    
    # indirect effect (a*b)
    ab := a*b
    # total effect
    total := c + (a*b)
    "
    
    fit <- sem(model = model, data = df)
    summary(object = fit, std=T)
    #> lavaan 0.6-7 ended normally after 33 iterations
    #> 
    #>   Estimator                                         ML
    #>   Optimization method                           NLMINB
    #>   Number of free parameters                          7
    #>                                                       
    #>   Number of observations                           301
    #>                                                       
    #> Model Test User Model:
    #>                                                       
    #>   Test statistic                                 0.041
    #>   Degrees of freedom                                 2
    #>   P-value (Chi-square)                           0.980
    #> 
    #> Parameter Estimates:
    #> 
    #>   Standard errors                             Standard
    #>   Information                                 Expected
    #>   Information saturated (h1) model          Structured
    #> 
    #> Regressions:
    #>                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    #>   y ~                                                                   
    #>     x                -0.131    0.161   -0.812    0.417   -0.131   -0.065
    #>     w                -0.130    0.162   -0.805    0.421   -0.130   -0.065
    #>     x:w        (c)    0.086    0.232    0.373    0.709    0.086    0.037
    #>     m          (b)    0.008    0.017    0.478    0.633    0.008    0.027
    #>   m ~                                                                   
    #>     x:w        (a)   -0.238    0.465   -0.511    0.609   -0.238   -0.029
    #> 
    #> Variances:
    #>                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    #>    .y                 1.010    0.082   12.268    0.000    1.010    0.995
    #>    .m                11.865    0.967   12.268    0.000   11.865    0.999
    #> 
    #> Defined Parameters:
    #>                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    #>     ab               -0.002    0.005   -0.349    0.727   -0.002   -0.001
    #>     total             0.085    0.232    0.364    0.716    0.085    0.036
    

    reprex package (v0.3.0) 于 2021 年 3 月 16 日创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多