資料與管理

#讀檔案,這是 CSV 檔(用逗號分隔的檔),可以用 notepad 或 EXCEL 開啟
dta <- read.csv("modmed2.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 = 59,
         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 : 59
##     Y : Y 
##     X : X 
##     M : M 
##     W : Z 
## 
## Sample size: 2000
## 
## Random seed: 112672
## 
## 
## *********************************************************************** 
## Outcome Variable: M
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.4081    0.1665    0.9716  132.9261    3.0000 1996.0000    0.0000
## 
## Model: 
##              coeff        se         t         p      LLCI      ULCI
## constant   -0.0142    0.0221   -0.6442    0.5195   -0.0575    0.0290
## X           0.3874    0.0220   17.5794    0.0000    0.3441    0.4306
## Z           0.0140    0.0222    0.6336    0.5264   -0.0294    0.0575
## Int_1       0.2068    0.0219    9.4498    0.0000    0.1639    0.2498
## 
## Product terms key:
## Int_1  :  X  x  Z      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## X*W    0.0373   89.2985    1.0000 1996.0000    0.0000
## ----------
## Focal predictor: X (X)
##       Moderator: Z (W)
## 
## Conditional effects of the focal predictor at values of the moderator(s):
##           Z    effect        se         t         p      LLCI      ULCI
##     -0.9949    0.1816    0.0310    5.8631    0.0000    0.1208    0.2423
##      0.0012    0.3876    0.0220   17.5902    0.0000    0.3444    0.4308
##      0.9973    0.5936    0.0310   19.1307    0.0000    0.5328    0.6545
## 
## Moderator value(s) defining Johnson-Neyman significance region(s):
##       Value   % below   % above
##     -2.4157    0.7000   99.3000
##     -1.4983    6.6500   93.3500
## 
## Conditional effect of focal predictor at values of the moderator:
##           Z    effect        se         t         p      LLCI      ULCI
##     -3.2621   -0.2874    0.0747   -3.8469    0.0001   -0.4339   -0.1409
##     -2.8949   -0.2114    0.0671   -3.1524    0.0016   -0.3430   -0.0799
##     -2.5276   -0.1355    0.0595   -2.2754    0.0230   -0.2522   -0.0187
##     -2.4157   -0.1123    0.0573   -1.9612    0.0500   -0.2246    0.0000
##     -2.1604   -0.0595    0.0522   -1.1409    0.2541   -0.1618    0.0428
##     -1.7931    0.0165    0.0450    0.3660    0.7144   -0.0718    0.1047
##     -1.4983    0.0775    0.0395    1.9612    0.0500   -0.0000    0.1549
##     -1.4259    0.0924    0.0382    2.4204    0.0156    0.0175    0.1673
##     -1.0586    0.1684    0.0320    5.2687    0.0000    0.1057    0.2311
##     -0.6914    0.2444    0.0267    9.1453    0.0000    0.1920    0.2968
##     -0.3241    0.3203    0.0231   13.8413    0.0000    0.2749    0.3657
##      0.0432    0.3963    0.0221   17.9673    0.0000    0.3530    0.4395
##      0.4104    0.4723    0.0238   19.8398    0.0000    0.4256    0.5189
##      0.7777    0.5482    0.0279   19.6802    0.0000    0.4936    0.6028
##      1.1449    0.6242    0.0334   18.6962    0.0000    0.5587    0.6897
##      1.5122    0.7001    0.0398   17.6005    0.0000    0.6221    0.7782
##      1.8794    0.7761    0.0467   16.6242    0.0000    0.6846    0.8677
##      2.2467    0.8521    0.0539   15.8066    0.0000    0.7464    0.9578
##      2.6140    0.9280    0.0613   15.1317    0.0000    0.8078    1.0483
##      2.9812    1.0040    0.0689   14.5733    0.0000    0.8689    1.1391
##      3.3485    1.0800    0.0766   14.1074    0.0000    0.9298    1.2301
##      3.7157    1.1559    0.0843   13.7148    0.0000    0.9906    1.3212
## 
## Data for visualizing the conditional effect of the focal predictor:
##           X         Z         M
##     -0.9713   -0.9949   -0.2045
##      0.0293   -0.9949   -0.0229
##      1.0299   -0.9949    0.1588
##     -0.9713    0.0012   -0.3907
##      0.0293    0.0012   -0.0028
##      1.0299    0.0012    0.3850
##     -0.9713    0.9973   -0.5768
##      0.0293    0.9973    0.0172
##      1.0299    0.9973    0.6112
## 
## *********************************************************************** 
## Outcome Variable: Y
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.5565    0.3097    0.9955  178.9354    5.0000 1994.0000    0.0000
## 
## Model: 
##              coeff        se         t         p      LLCI      ULCI
## constant   -0.0138    0.0223   -0.6198    0.5355   -0.0576    0.0299
## X           0.0008    0.0245    0.0325    0.9741   -0.0472    0.0488
## M           0.5001    0.0227   22.0683    0.0000    0.4557    0.5446
## Z           0.2894    0.0224   12.8998    0.0000    0.2454    0.3334
## Int_1      -0.0256    0.0245   -1.0443    0.2965   -0.0737    0.0225
## Int_2       0.1905    0.0226    8.4435    0.0000    0.1463    0.2348
## 
## Product terms key:
## Int_1  :  X  x  Z      
## Int_2  :  M  x  Z      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## X*W    0.0004    1.0905    1.0000 1994.0000    0.2965
## M*W    0.0247   71.2925    1.0000 1994.0000    0.0000
## ----------
## Focal predictor: X (X)
##       Moderator: Z (W)
## 
## Data for visualizing the conditional effect of the focal predictor:
##           X         Z         Y
##     -0.9713   -0.9949   -0.3289
##      0.0293   -0.9949   -0.3026
##      1.0299   -0.9949   -0.2763
##     -0.9713    0.0012   -0.0168
##      0.0293    0.0012   -0.0161
##      1.0299    0.0012   -0.0153
##     -0.9713    0.9973    0.2952
##      0.0293    0.9973    0.2705
##      1.0299    0.9973    0.2457
## ----------
## 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.9949    0.3105    0.0316    9.8339    0.0000    0.2486    0.3725
##      0.0012    0.5003    0.0227   22.0775    0.0000    0.4559    0.5448
##      0.9973    0.6901    0.0323   21.3935    0.0000    0.6269    0.7534
## 
## Moderator value(s) defining Johnson-Neyman significance region(s):
##       Value   % below   % above
##     -2.0903    1.9500   98.0500
## 
## Conditional effect of focal predictor at values of the moderator:
##           Z    effect        se         t         p      LLCI      ULCI
##     -3.2621   -0.1215    0.0766   -1.5860    0.1129   -0.2717    0.0287
##     -2.9133   -0.0550    0.0691   -0.7958    0.4263   -0.1905    0.0805
##     -2.5644    0.0115    0.0617    0.1861    0.8524   -0.1096    0.1325
##     -2.2155    0.0780    0.0545    1.4313    0.1525   -0.0289    0.1848
##     -2.0903    0.1018    0.0519    1.9612    0.0500    0.0000    0.2036
##     -1.8666    0.1444    0.0474    3.0457    0.0024    0.0514    0.2375
##     -1.5177    0.2109    0.0407    5.1844    0.0000    0.1311    0.2907
##     -1.1688    0.2774    0.0344    8.0582    0.0000    0.2099    0.3449
##     -0.8199    0.3439    0.0290   11.8725    0.0000    0.2871    0.4007
##     -0.4710    0.4104    0.0248   16.5232    0.0000    0.3617    0.4591
##     -0.1221    0.4768    0.0228   20.9385    0.0000    0.4322    0.5215
##      0.2268    0.5433    0.0233   23.2854    0.0000    0.4976    0.5891
##      0.5757    0.6098    0.0263   23.1439    0.0000    0.5581    0.6615
##      0.9246    0.6763    0.0311   21.7365    0.0000    0.6153    0.7373
##      1.2735    0.7428    0.0370   20.0984    0.0000    0.6703    0.8152
##      1.6224    0.8092    0.0434   18.6266    0.0000    0.7240    0.8944
##      1.9713    0.8757    0.0503   17.3992    0.0000    0.7770    0.9744
##      2.3201    0.9422    0.0575   16.3943    0.0000    0.8295    1.0549
##      2.6690    1.0087    0.0648   15.5705    0.0000    0.8816    1.1357
##      3.0179    1.0752    0.0722   14.8893    0.0000    0.9335    1.2168
##      3.3668    1.1416    0.0797   14.3199    0.0000    0.9853    1.2980
##      3.7157    1.2081    0.0873   13.8384    0.0000    1.0369    1.3793
## 
## Data for visualizing the conditional effect of the focal predictor:
##           M         Z         Y
##     -1.0840   -0.9949   -0.6376
##     -0.0051   -0.9949   -0.3026
##      1.0737   -0.9949    0.0325
##     -1.0840    0.0012   -0.5558
##     -0.0051    0.0012   -0.0161
##      1.0737    0.0012    0.5237
##     -1.0840    0.9973   -0.4741
##     -0.0051    0.9973    0.2705
##      1.0737    0.9973    1.0150
## 
## *********************************************************************** 
## 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 ****************
## 
## Conditional direct effect(s) of X on Y:
##           Z    effect        se         t         p      LLCI      ULCI
##     -0.9949    0.0263    0.0319    0.8233    0.4104   -0.0363    0.0889
##      0.0012    0.0008    0.0245    0.0313    0.9751   -0.0472    0.0488
##      0.9973   -0.0248    0.0371   -0.6681    0.5042   -0.0974    0.0479
## 
## Conditional indirect effects of X on Y:
## 
## INDIRECT EFFECT:
## 
## X    ->    M    ->    Y
## 
##           Z    Effect    BootSE  BootLLCI  BootULCI
##     -0.9949    0.0564    0.0107    0.0369    0.0787
##      0.0012    0.1939    0.0143    0.1668    0.2230
##      0.9973    0.4097    0.0285    0.3550    0.4676
## 
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
## 
## Outcome variable: M
## 
##              Coeff  BootMean    BootSE  BootLLCI  BootULCI
## constant   -0.0142   -0.0143    0.0222   -0.0574    0.0293
## X           0.3874    0.3870    0.0220    0.3430    0.4302
## Z           0.0140    0.0143    0.0213   -0.0274    0.0560
## Int_1       0.2068    0.2068    0.0203    0.1664    0.2456
## ----------
## Outcome variable: Y
## 
##              Coeff  BootMean    BootSE  BootLLCI  BootULCI
## constant   -0.0138   -0.0143    0.0225   -0.0586    0.0299
## X           0.0008    0.0004    0.0242   -0.0480    0.0484
## M           0.5001    0.5004    0.0228    0.4546    0.5454
## Z           0.2894    0.2896    0.0221    0.2472    0.3332
## Int_1      -0.0256   -0.0257    0.0239   -0.0730    0.0208
## Int_2       0.1905    0.1905    0.0218    0.1475    0.2327
## 
## ******************** 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+X:Z+M:Z, data = dta)

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

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

調節徑路分析模型:總效果模型

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

dta$int1 <- dta$X*dta$Z
dta$int2 <- 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.995  0.001  0.997
model1 <-'
M ~ a1*X+a2*int1+a3*Z
Y ~ c1*X +c2*int1+c3*Z+b1*M + b2*int2
sslope1med1 := (b1+b2*(-.995))*(a1+a2*(-.995))
sslope1med2 := (b1+b2*(-0.001))*(a1+a2*(-0.001))
sslope1med3 := (b1+b2*(0.997))*(a1+a2*(0.997))
'
#徑路分析報表
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                        10
## 
##   Number of observations                          2000
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.816
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.366
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   M ~                                                 
##     X         (a1)    0.387    0.022   17.597    0.000
##     int1      (a2)    0.207    0.022    9.459    0.000
##     Z         (a3)    0.014    0.022    0.634    0.526
##   Y ~                                                 
##     X         (c1)    0.001    0.024    0.033    0.974
##     int1      (c2)   -0.026    0.024   -1.047    0.295
##     Z         (c3)    0.289    0.022   12.919    0.000
##     M         (b1)    0.500    0.023   22.106    0.000
##     int2      (b2)    0.191    0.023    8.458    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .M                 0.970    0.031   31.623    0.000
##    .Y                 0.993    0.031   31.623    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     sslope1med1       0.056    0.011    5.028    0.000
##     sslope1med2       0.194    0.014   13.761    0.000
##     sslope1med3       0.410    0.029   14.343    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~Xa10.387   0.022 17.6   0       0.344  0.431  
M~int1a20.207   0.02199.46  0       0.164  0.25   
M~Za30.014   0.02210.634 0.526   -0.0293 0.0574 
Y~Xc10.0007950.02440.03260.974   -0.047  0.0486 
Y~int1c2-0.0256  0.0245-1.05  0.295   -0.0736 0.0223 
Y~Zc30.289   0.022412.9   0       0.245  0.333  
Y~Mb10.5     0.022622.1   0       0.456  0.544  
Y~int2b20.191   0.02258.46  0       0.146  0.235  
M~~M0.97    0.030731.6   0       0.91   1.03   
Y~~Y0.993   0.031431.6   0       0.931  1.05   
X~~X1       0                 1      1      
X~~int1-0.00142 0                 -0.00142-0.00142
X~~Z-0.0112  0                 -0.0112 -0.0112 
X~~int20.21    0                 0.21   0.21   
int1~~int11.02    0                 1.02   1.02   
int1~~Z0.0452  0                 0.0452 0.0452 
int1~~int20.421   0                 0.421  0.421  
Z~~Z0.992   0                 0.992  0.992  
Z~~int20.0284  0                 0.0284 0.0284 
int2~~int21.2     0                 1.2    1.2    
sslope1med1:=(b1+b2*(-.995))*(a1+a2*(-.995))sslope1med10.0564  0.01125.03  4.96e-070.0344 0.0784 
sslope1med2:=(b1+b2*(-0.001))*(a1+a2*(-0.001))sslope1med20.194   0.014113.8   0       0.166  0.221  
sslope1med3:=(b1+b2*(0.997))*(a1+a2*(0.997))sslope1med30.41    0.028614.3   0       0.354  0.466  
#畫圖看模型與估計值
lavaanPlot::lavaanPlot(model = fit,
                       edge_options = list(color = "grey"), 
                       coefs = TRUE,
                       stand = TRUE)
#畫圖,這圖意義不大
m3 <- lm(Y ~ X+M+X:Z+M:Z, data = dta)

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

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