資料與管理

#讀檔案,這是 CSV 檔(用逗號分隔的檔),可以用 notepad 或 EXCEL 開啟
dta <- read.csv("modmed1.csv", header = TRUE)

調節徑路分析模型:第二階段中介效果調節模型

方法一:調節效果,用 PROCESS 功能分析

#載入 PROCESS,特別記得要讓 process.r 可讀取(在同目錄,或特定目錄)
source('process.r')
## 
## ********************* PROCESS for R Version 4.3.1 ********************* 
##  
##            Written by Andrew F. Hayes, Ph.D.  www.afhayes.com              
##    Documentation available in Hayes (2022). www.guilford.com/p/hayes3   
##  
## *********************************************************************** 
##  
## PROCESS is now ready for use.
## Copyright 2020-2023 by Andrew F. Hayes ALL RIGHTS RESERVED
## Workshop schedule at http://haskayne.ucalgary.ca/CCRAM
## 
#用 PROCESS 處理
#套件的變項要用字串符號括入(統計能力好,程式能力待加強)
process (data = dta, y = 'Y', x = 'X', m='M',w ='Z', model = 14,
         moments = 1,jn = 1,plot=1, modelbt= 1, boot = 999)
## 
## ********************* PROCESS for R Version 4.3.1 ********************* 
##  
##            Written by Andrew F. Hayes, Ph.D.  www.afhayes.com              
##    Documentation available in Hayes (2022). www.guilford.com/p/hayes3   
##  
## *********************************************************************** 
##           
## Model : 14
##     Y : Y 
##     X : X 
##     M : M 
##     W : Z 
## 
## Sample size: 1000
## 
## Random seed: 393923
## 
## 
## *********************************************************************** 
## Outcome Variable: M
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.4336    0.1880    1.0128  231.0512    1.0000  998.0000    0.0000
## 
## Model: 
##              coeff        se         t         p      LLCI      ULCI
## constant    0.0410    0.0318    1.2895    0.1975   -0.0214    0.1035
## X           0.4880    0.0321   15.2004    0.0000    0.4250    0.5511
## 
## *********************************************************************** 
## Outcome Variable: Y
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.5706    0.3256    0.9795  120.1094    4.0000  995.0000    0.0000
## 
## Model: 
##              coeff        se         t         p      LLCI      ULCI
## constant   -0.0063    0.0313   -0.1998    0.8417   -0.0678    0.0552
## X           0.0054    0.0351    0.1549    0.8770   -0.0634    0.0743
## M           0.4933    0.0311   15.8381    0.0000    0.4322    0.5544
## Z           0.3625    0.0323   11.2217    0.0000    0.2991    0.4259
## Int_1       0.1208    0.0305    3.9585    0.0001    0.0609    0.1806
## 
## Product terms key:
## Int_1  :  M  x  Z      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## M*W    0.0106   15.6698    1.0000  995.0000    0.0001
## ----------
## Focal predictor: M (M)
##       Moderator: Z (W)
## 
## Conditional effects of the focal predictor at values of the moderator(s):
##           Z    effect        se         t         p      LLCI      ULCI
##     -0.9985    0.3727    0.0439    8.4811    0.0000    0.2865    0.4590
##     -0.0201    0.4909    0.0312   15.7517    0.0000    0.4297    0.5520
##      0.9582    0.6090    0.0423   14.3835    0.0000    0.5259    0.6921
## 
## Moderator value(s) defining Johnson-Neyman significance region(s):
##       Value   % below   % above
##     -2.6627    0.1000   99.9000
## 
## Conditional effect of focal predictor at values of the moderator:
##           Z    effect        se         t         p      LLCI      ULCI
##     -2.8485    0.1493    0.0928    1.6081    0.1081   -0.0329    0.3314
##     -2.6627    0.1717    0.0875    1.9624    0.0500   -0.0000    0.3435
##     -2.5351    0.1871    0.0839    2.2310    0.0259    0.0225    0.3517
##     -2.2216    0.2250    0.0751    2.9965    0.0028    0.0777    0.3723
##     -1.9081    0.2629    0.0665    3.9526    0.0001    0.1324    0.3934
##     -1.5946    0.3007    0.0582    5.1648    0.0000    0.1865    0.4150
##     -1.2811    0.3386    0.0504    6.7173    0.0000    0.2397    0.4375
##     -0.9677    0.3764    0.0433    8.6960    0.0000    0.2915    0.4614
##     -0.6542    0.4143    0.0373   11.1114    0.0000    0.3411    0.4875
##     -0.3407    0.4522    0.0330   13.6986    0.0000    0.3874    0.5169
##     -0.0272    0.4900    0.0312   15.7197    0.0000    0.4288    0.5512
##      0.2863    0.5279    0.0322   16.3936    0.0000    0.4647    0.5911
##      0.5998    0.5657    0.0358   15.7824    0.0000    0.4954    0.6361
##      0.9132    0.6036    0.0414   14.5710    0.0000    0.5223    0.6849
##      1.2267    0.6414    0.0483   13.2890    0.0000    0.5467    0.7362
##      1.5402    0.6793    0.0559   12.1483    0.0000    0.5696    0.7890
##      1.8537    0.7172    0.0641   11.1912    0.0000    0.5914    0.8429
##      2.1672    0.7550    0.0726   10.4011    0.0000    0.6126    0.8975
##      2.4806    0.7929    0.0813    9.7486    0.0000    0.6333    0.9525
##      2.7941    0.8307    0.0902    9.2056    0.0000    0.6537    1.0078
##      3.1076    0.8686    0.0993    8.7495    0.0000    0.6738    1.0634
##      3.4211    0.9065    0.1084    8.3624    0.0000    0.6937    1.1192
## 
## Data for visualizing the conditional effect of the focal predictor:
##           M         Z         Y
##     -1.0674   -0.9985   -0.7659
##      0.0489   -0.9985   -0.3499
##      1.1652   -0.9985    0.0662
##     -1.0674   -0.0201   -0.5374
##      0.0489   -0.0201    0.0105
##      1.1652   -0.0201    0.5585
##     -1.0674    0.9582   -0.3089
##      0.0489    0.9582    0.3710
##      1.1652    0.9582    1.0508
## 
## *********************************************************************** 
## Bootstrapping progress:
## 
  |                                                                    
  |                                                              |   0%
  |                                                                    
  |                                                              |   1%
  |                                                                    
  |>                                                             |   1%
  |                                                                    
  |>                                                             |   2%
  |                                                                    
  |>>                                                            |   2%
  |                                                                    
  |>>                                                            |   3%
  |                                                                    
  |>>                                                            |   4%
  |                                                                    
  |>>>                                                           |   4%
  |                                                                    
  |>>>                                                           |   5%
  |                                                                    
  |>>>                                                           |   6%
  |                                                                    
  |>>>>                                                          |   6%
  |                                                                    
  |>>>>                                                          |   7%
  |                                                                    
  |>>>>>                                                         |   7%
  |                                                                    
  |>>>>>                                                         |   8%
  |                                                                    
  |>>>>>                                                         |   9%
  |                                                                    
  |>>>>>>                                                        |   9%
  |                                                                    
  |>>>>>>                                                        |  10%
  |                                                                    
  |>>>>>>>                                                       |  10%
  |                                                                    
  |>>>>>>>                                                       |  11%
  |                                                                    
  |>>>>>>>                                                       |  12%
  |                                                                    
  |>>>>>>>>                                                      |  12%
  |                                                                    
  |>>>>>>>>                                                      |  13%
  |                                                                    
  |>>>>>>>>                                                      |  14%
  |                                                                    
  |>>>>>>>>>                                                     |  14%
  |                                                                    
  |>>>>>>>>>                                                     |  15%
  |                                                                    
  |>>>>>>>>>>                                                    |  15%
  |                                                                    
  |>>>>>>>>>>                                                    |  16%
  |                                                                    
  |>>>>>>>>>>                                                    |  17%
  |                                                                    
  |>>>>>>>>>>>                                                   |  17%
  |                                                                    
  |>>>>>>>>>>>                                                   |  18%
  |                                                                    
  |>>>>>>>>>>>                                                   |  19%
  |                                                                    
  |>>>>>>>>>>>>                                                  |  19%
  |                                                                    
  |>>>>>>>>>>>>                                                  |  20%
  |                                                                    
  |>>>>>>>>>>>>>                                                 |  20%
  |                                                                    
  |>>>>>>>>>>>>>                                                 |  21%
  |                                                                    
  |>>>>>>>>>>>>>                                                 |  22%
  |                                                                    
  |>>>>>>>>>>>>>>                                                |  22%
  |                                                                    
  |>>>>>>>>>>>>>>                                                |  23%
  |                                                                    
  |>>>>>>>>>>>>>>>                                               |  23%
  |                                                                    
  |>>>>>>>>>>>>>>>                                               |  24%
  |                                                                    
  |>>>>>>>>>>>>>>>                                               |  25%
  |                                                                    
  |>>>>>>>>>>>>>>>>                                              |  25%
  |                                                                    
  |>>>>>>>>>>>>>>>>                                              |  26%
  |                                                                    
  |>>>>>>>>>>>>>>>>                                              |  27%
  |                                                                    
  |>>>>>>>>>>>>>>>>>                                             |  27%
  |                                                                    
  |>>>>>>>>>>>>>>>>>                                             |  28%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>                                            |  28%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>                                            |  29%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>                                            |  30%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>                                           |  30%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>                                           |  31%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>                                          |  31%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>                                          |  32%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>                                          |  33%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>                                         |  33%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>                                         |  34%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>                                         |  35%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>                                        |  35%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>                                        |  36%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>                                       |  36%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>                                       |  37%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>                                       |  38%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>                                      |  38%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>                                      |  39%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>                                      |  40%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>                                     |  40%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>                                     |  41%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>                                    |  41%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>                                    |  42%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>                                    |  43%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>                                   |  43%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>                                   |  44%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                  |  44%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                  |  45%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                  |  46%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                 |  46%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                 |  47%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                 |  48%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                |  48%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                                |  49%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                               |  49%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                               |  50%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                               |  51%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                              |  51%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                              |  52%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                             |  52%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                             |  53%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                             |  54%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                            |  54%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                            |  55%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                            |  56%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                           |  56%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                           |  57%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                          |  57%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                          |  58%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                          |  59%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                         |  59%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                         |  60%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                        |  60%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                        |  61%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                        |  62%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                       |  62%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                       |  63%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                       |  64%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                      |  64%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                      |  65%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                     |  65%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                     |  66%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                     |  67%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                    |  67%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                    |  68%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                    |  69%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                   |  69%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                   |  70%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                  |  70%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                  |  71%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                  |  72%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                 |  72%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                 |  73%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                |  73%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                |  74%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                |  75%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               |  75%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               |  76%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               |  77%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>              |  77%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>              |  78%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>             |  78%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>             |  79%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>             |  80%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>            |  80%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>            |  81%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>           |  81%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>           |  82%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>           |  83%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>          |  83%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>          |  84%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>          |  85%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>         |  85%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>         |  86%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        |  86%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        |  87%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>        |  88%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>       |  88%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>       |  89%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>       |  90%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>      |  90%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>      |  91%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     |  91%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     |  92%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     |  93%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    |  93%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    |  94%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   |  94%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   |  95%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   |  96%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  |  96%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  |  97%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  |  98%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |  98%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |  99%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|  99%
  |                                                                    
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
## 
## **************** DIRECT AND INDIRECT EFFECTS OF X ON Y ****************
## 
## Direct effect of X on Y:
##      effect        se         t         p      LLCI      ULCI
##      0.0054    0.0351    0.1549    0.8770   -0.0634    0.0743
## 
## Conditional indirect effects of X on Y:
## 
## INDIRECT EFFECT:
## 
## X    ->    M    ->    Y
## 
##           Z    Effect    BootSE  BootLLCI  BootULCI
##     -0.9985    0.1819    0.0251    0.1347    0.2339
##     -0.0201    0.2396    0.0223    0.1977    0.2839
##      0.9582    0.2972    0.0282    0.2442    0.3544
## 
##      Index of moderated mediation:
##       Index    BootSE  BootLLCI  BootULCI
## Z    0.0589    0.0150    0.0302    0.0887
## 
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
## 
## Outcome variable: M
## 
##              Coeff  BootMean    BootSE  BootLLCI  BootULCI
## constant    0.0410    0.0406    0.0318   -0.0220    0.1023
## X           0.4880    0.4886    0.0308    0.4282    0.5485
## ----------
## Outcome variable: Y
## 
##              Coeff  BootMean    BootSE  BootLLCI  BootULCI
## constant   -0.0063   -0.0070    0.0312   -0.0676    0.0534
## X           0.0054    0.0053    0.0360   -0.0655    0.0756
## M           0.4933    0.4933    0.0327    0.4288    0.5582
## Z           0.3625    0.3626    0.0315    0.2996    0.4243
## Int_1       0.1208    0.1208    0.0302    0.0627    0.1801
## 
## ******************** ANALYSIS NOTES AND ERRORS ************************ 
## 
## Level of confidence for all confidence intervals in output: 95
## 
## Number of bootstraps for percentile bootstrap confidence intervals: 5000
## 
## W values in conditional tables are the mean and +/- SD from the mean.
#畫圖,這圖意義不大
m3 <- lm(Y ~ X+M+M:Z, data = dta)

interactions::interact_plot(m3, pred = M, modx = Z, interval = TRUE,
  int.type = "confidence", int.width = .8)

調節徑路分析模型:第二階段中介效果調節模型

方法二:調節效果,用 lavaan 功能分析

dta$int1 <- dta$M*dta$Z

k1 <- mean(dta$Z)-sd(dta$Z)
k2 <- mean(dta$Z)
k3 <- mean(dta$Z)+sd(dta$Z)
round(c(k1,k2,k3),3)
## [1] -0.998 -0.020  0.958
model1 <-'
M ~ a*X
Y ~ c*X + b1*M + b2*int1
sslope1med1 := (b1+b2*(-.998))*a
sslope1med2 := (b1+b2*(-0.020))*a
sslope1med3 := (b1+b2*(0.958))*a
'
#徑路分析報表
fit <- lavaan::sem(model1, data=dta)
summary(fit)
## lavaan 0.6.15 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         6
## 
##   Number of observations                          1000
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.445
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.505
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   M ~                                                 
##     X          (a)    0.488    0.032   15.216    0.000
##   Y ~                                                 
##     X          (c)   -0.008    0.037   -0.219    0.827
##     M         (b1)    0.502    0.033   15.241    0.000
##     int1      (b2)    0.166    0.032    5.178    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .M                 1.011    0.045   22.361    0.000
##    .Y                 1.098    0.049   22.361    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     sslope1med1       0.164    0.025    6.610    0.000
##     sslope1med2       0.244    0.023   10.731    0.000
##     sslope1med3       0.323    0.031   10.566    0.000
#以拔靴法看徑路係數與簡單中介效果信賴區間
set.seed(1234)
fit <- lavaan::sem(model1, data=dta, test="bootstrap", bootstrap=501)
parameterEstimates(fit,ci=TRUE,boot.ci.type="bca.simple")
lhsoprhslabelestsezpvalueci.lowerci.upper
M~Xa0.488  0.032115.2  0       0.425 0.551 
Y~Xc-0.008120.0371-0.2190.827   -0.08090.0647
Y~Mb10.502  0.033 15.2  0       0.438 0.567 
Y~int1b20.166  0.032 5.18 2.25e-070.103 0.228 
M~~M1.01   0.045222.4  0       0.922 1.1   
Y~~Y1.1    0.049122.4  0       1     1.19  
X~~X0.982  0                0.982 0.982 
X~~int10.0492 0                0.04920.0492
int1~~int11.07   0                1.07  1.07  
sslope1med1:=(b1+b2*(-.998))*asslope1med10.164  0.02496.61 3.84e-110.116 0.213 
sslope1med2:=(b1+b2*(-0.020))*asslope1med20.244  0.022710.7  0       0.199 0.288 
sslope1med3:=(b1+b2*(0.958))*asslope1med30.323  0.030510.6  0       0.263 0.382 
#畫圖看模型與估計值
lavaanPlot::lavaanPlot(model = fit,
                       edge_options = list(color = "grey"), 
                       coefs = TRUE,
                       stand = TRUE)
#畫圖,這圖意義不大
m3 <- lm(Y ~ X+M+M:Z, data = dta)

interactions::interact_plot(m3, pred = M, modx = Z, interval = TRUE,
  int.type = "confidence", int.width = .8)