資料與管理

#讀檔案,這是 CSV 檔(用逗號分隔的檔),可以用 notepad 或 EXCEL 開啟
dta <- read.csv("depress.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 (data = dta, y = 'depress', x = 'stress', w ='support', model = 1,
         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 : 1      
##     Y : depress
##     X : stress 
##     W : support
## 
## Sample size: 100
## 
## Random seed: 495750
## 
## 
## *********************************************************************** 
## Outcome Variable: depress
## 
## Model Summary: 
##           R      R-sq       MSE         F       df1       df2         p
##      0.9818    0.9638    1.9311  852.9588    3.0000   96.0000    0.0000
## 
## Model: 
##              coeff        se         t         p      LLCI      ULCI
## constant   29.2583    0.6909   42.3506    0.0000   27.8870   30.6297
## stress      1.9956    0.1161   17.1855    0.0000    1.7651    2.2261
## support    -0.2356    0.1109   -2.1246    0.0362   -0.4558   -0.0155
## Int_1      -0.3902    0.0188  -20.7538    0.0000   -0.4276   -0.3529
## 
## Product terms key:
## Int_1  :  stress  x  support      
## 
## Test(s) of highest order unconditional interaction(s):
##       R2-chng         F       df1       df2         p
## X*W    0.1622  430.7185    1.0000   96.0000    0.0000
## ----------
## Focal predictor: stress (X)
##       Moderator: support (W)
## 
## Conditional effects of the focal predictor at values of the moderator(s):
##     support    effect        se         t         p      LLCI      ULCI
##      2.5607    0.9963    0.0765   13.0227    0.0000    0.8445    1.1482
##      5.3700   -0.1000    0.0531   -1.8841    0.0626   -0.2053    0.0054
##      8.1793   -1.1963    0.0732  -16.3429    0.0000   -1.3416   -1.0510
## 
## Moderator value(s) defining Johnson-Neyman significance region(s):
##       Value   % below   % above
##      4.8370   41.0000   59.0000
##      5.3837   51.0000   49.0000
## 
## Conditional effect of focal predictor at values of the moderator:
##     support    effect        se         t         p      LLCI      ULCI
##      1.0000    1.6054    0.0998   16.0921    0.0000    1.4073    1.8034
##      1.4737    1.4205    0.0923   15.3840    0.0000    1.2372    1.6038
##      1.9474    1.2357    0.0852   14.5035    0.0000    1.0666    1.4048
##      2.4211    1.0508    0.0784   13.3998    0.0000    0.8952    1.2065
##      2.8947    0.8660    0.0721   12.0093    0.0000    0.7228    1.0091
##      3.3684    0.6811    0.0664   10.2588    0.0000    0.5493    0.8129
##      3.8421    0.4963    0.0614    8.0769    0.0000    0.3743    0.6182
##      4.3158    0.3114    0.0575    5.4203    0.0000    0.1974    0.4255
##      4.7895    0.1266    0.0546    2.3165    0.0227    0.0181    0.2350
##      4.8370    0.1080    0.0544    1.9850    0.0500    0.0000    0.2161
##      5.2632   -0.0583    0.0532   -1.0957    0.2759   -0.1638    0.0473
##      5.3837   -0.1053    0.0530   -1.9850    0.0500   -0.2106   -0.0000
##      5.7368   -0.2431    0.0532   -4.5699    0.0000   -0.3487   -0.1375
##      6.2105   -0.4280    0.0547   -7.8256    0.0000   -0.5365   -0.3194
##      6.6842   -0.6128    0.0575  -10.6518    0.0000   -0.7270   -0.4986
##      7.1579   -0.7977    0.0615  -12.9609    0.0000   -0.9198   -0.6755
##      7.6316   -0.9825    0.0665  -14.7716    0.0000   -1.1146   -0.8505
##      8.1053   -1.1674    0.0722  -16.1586    0.0000   -1.3108   -1.0240
##      8.5789   -1.3522    0.0786  -17.2107    0.0000   -1.5082   -1.1963
##      9.0526   -1.5371    0.0854  -18.0080    0.0000   -1.7065   -1.3676
##      9.5263   -1.7219    0.0925  -18.6151    0.0000   -1.9055   -1.5383
##     10.0000   -1.9068    0.0999  -19.0808    0.0000   -2.1051   -1.7084
## 
## Data for visualizing the conditional effect of the focal predictor:
##      stress   support   depress
##      2.7542    2.5607   31.3990
##      5.3900    2.5607   34.0251
##      8.0258    2.5607   36.6512
##      2.7542    5.3700   27.7177
##      5.3900    5.3700   27.4542
##      8.0258    5.3700   27.1907
##      2.7542    8.1793   24.0363
##      5.3900    8.1793   20.8832
##      8.0258    8.1793   17.7302
## 
## *********************************************************************** 
## 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%
## 
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
## 
## Outcome variable: depress
## 
##              Coeff  BootMean    BootSE  BootLLCI  BootULCI
## constant   29.2583   29.2559    0.6455   27.9890   30.5696
## stress      1.9956    1.9963    0.1190    1.7608    2.2359
## support    -0.2356   -0.2351    0.1010   -0.4367   -0.0348
## Int_1      -0.3902   -0.3905    0.0178   -0.4274   -0.3559
## 
## ******************** 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.
#畫圖,還是得要迴歸
m2 <- lm(depress ~ stress+support+ stress*support, data = dta)

interactions::interact_plot(m2, pred = stress, modx = support, interval = TRUE,
  int.type = "confidence", int.width = .8)

一個獨變項,一個調節變項

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

dta$int <- dta$stress*dta$support
k1 <- mean(dta$support)-sd(dta$support)
k2 <- mean(dta$support)
k3 <- mean(dta$support)+sd(dta$support)
round(c(k1,k2,k3),3)
## [1] 2.561 5.370 8.179
model1 <-'
depress ~ b1*stress + b2*support + b3*int
sslope1 := b1+b3*(2.561)
sslope2 := b1+b3*(5.370)
sslope3 := b1+b3*(8.179)
'
#徑路分析報表
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                         4
## 
##   Number of observations                           100
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   depress ~                                           
##     stress    (b1)    1.996    0.114   17.540    0.000
##     support   (b2)   -0.236    0.109   -2.168    0.030
##     int       (b3)   -0.390    0.018  -21.182    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .depress           1.854    0.262    7.071    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     sslope1           0.996    0.075   13.290    0.000
##     sslope2          -0.100    0.052   -1.923    0.054
##     sslope3          -1.196    0.072  -16.679    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
depress~stressb12    0.114 17.5 0       1.77 2.22   
depress~supportb2-0.2360.109 -2.170.0301  -0.449-0.0226 
depress~intb3-0.39 0.0184-21.2 0       -0.426-0.354  
depress~~depress1.85 0.262 7.071.54e-121.34 2.37   
stress~~stress6.88 0               6.88 6.88   
stress~~support-0.1940               -0.194-0.194  
stress~~int36.8  0               36.8  36.8    
support~~support7.81 0               7.81 7.81   
support~~int40.1  0               40.1  40.1    
int~~int468    0               468    468      
sslope1:=b1+b3*(2.561)sslope10.9960.075 13.3 0       0.8491.14   
sslope2:=b1+b3*(5.370)sslope2-0.1  0.052 -1.920.0545  -0.2020.00192
sslope3:=b1+b3*(8.179)sslope3-1.2  0.0717-16.7 0       -1.34 -1.06   
#畫圖看模型與估計值
lavaanPlot::lavaanPlot(model = fit,
                       edge_options = list(color = "grey"), 
                       coefs = TRUE,
                       stand = TRUE)
#畫圖,還是得要迴歸
m2 <- lm(depress ~ stress+support+ stress*support, data = dta)

interactions::interact_plot(m2, pred = stress, modx = support, interval = TRUE,
  int.type = "confidence", int.width = .8)

一個獨變項,一個調節變項

方法三:調節效果,取用 lm 功能分析

#用迴歸分析並製表
m1 <- lm(depress ~ stress+support , data = dta)
m2 <- lm(depress ~ stress+support+ stress*support, data = dta)

#如果要中心化
#dta$int <- (dta$stress-mean(dta$stress))*(dta$support-(dta$support))
#m1 <- lm(depress ~ stress+support , data = dta)
#m2 <- lm(depress ~ stress+support+ int, data = dta)

options(huxtable.knitr_output_format="md")
jtools::export_summs(m1,m2,
                     model.names = c("depress", "depress"),
                     error_format = "[{conf.low},{conf.high}]")
## Registered S3 methods overwritten by 'broom':
##   method            from  
##   tidy.glht         jtools
##   tidy.summary.glht jtools
## Warning in to_md.huxtable(structure(list(names = c("", "(Intercept)", "", :
## Markdown cannot handle cells with colspan/rowspan > 1
## Warning in to_md.huxtable(structure(list(names = c("", "(Intercept)", "", :
## Can't vary column alignment in markdown; using first row
depress depress
(Intercept) 40.64 *** 29.26 ***
[38.70,42.59] [27.89,30.63]
stress -0.15 2.00 ***
[-0.39,0.10] [1.77,2.23]
support -2.29 *** -0.24 *
[-2.52,-2.06] [-0.46,-0.02]
stress:support -0.39 ***
[-0.43,-0.35]
N 100 100
R2 0.80 0.96
*** p < 0.001; ** p < 0.01; * p < 0.05.
#兩模型的解釋量差異檢定
Rsquared_m1 <- broom::glance(m1)$r.squared
Rsquared_m2 <- broom::glance(m2)$r.squared
mrst <- c(m1_Rsquared=Rsquared_m1,m2_Rsquared=Rsquared_m2,deltaRsquared=Rsquared_m2-Rsquared_m1)
round(mrst,3)
##   m1_Rsquared   m2_Rsquared deltaRsquared 
##         0.802         0.964         0.162
anova(m1,m2)
Res.Df RSS Df Sum of Sq F Pr(>F)
97 1.02e+03
96 185 1 832 431 2.92e-37
#畫圖,還是得要迴歸
m2 <- lm(depress ~ stress+support+ stress*support, data = dta)

interactions::interact_plot(m2, pred = stress, modx = support, interval = TRUE,
  int.type = "confidence", int.width = .8)

simple_slopes(m2)
stress suppor t Test Estima te Std. Error t value df Pr(>|t |)
2.754213 sstest -1.31 0.0687 -19.1 96 1.93e-34
5.39 sstest -2.34 0.0498 -47 96 4.71e-68
8.025787 sstest -3.37 0.0718 -46.9 96 5.5e-68
sstest 2.560726 0.996 0.0765 13 96 6.19e-23
sstest 5.37 -0.1 0.0531 -1.88 96 0.0626
sstest 8.179274 -1.2 0.0732 -16.3 96 1.75e-29