中介效应+调节效应+调节的中介效应示例

作者

刘念夏

发布于

2026-05-22

环境设置

#设置工作目录
#菜单session->set working directory->choose directory
#设置你自己的工作目录
setwd("~/Desktop/Quarto/research-method-new") 

#设置系統中文文字编码(简体中文)
Sys.setlocale(category = "LC_ALL", locale = "zh_CN.UTF-8") 
[1] "zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8"
#使绘图物件中的中文文字能正确呈现
#调用加载"showtext"套件包
library(showtext) 
载入需要的程序包:sysfonts
载入需要的程序包:showtextdb
showtext_auto(enable = TRUE)

1 数据预备(chatgpt_EFA.sav)

#载入数据
library(sjlabelled)
mydata <-read_spss("chatgpt_EFA.sav") 
Converting atomic to factors. Please wait...
names(mydata)
 [1] "F1_1"  "F1_2"  "F1_3"  "F1_4"  "F2_1"  "F2_2"  "F2_3"  "F2_4"  "F2_5" 
[10] "F3_1"  "F3_2"  "F3_3"  "F3_4"  "F3_5"  "F3_6"  "F4_1"  "F4_2"  "F4_3" 
[19] "F4_4"  "F4_5"  "F5_1"  "F5_2"  "F5_3"  "F5_4"  "F5_5"  "F5_6"  "F5_7" 
[28] "F5_8"  "F5_9"  "F5_10" "use"   "sex"   "age"   "year"  "FAC1"  "FAC2" 
[37] "FAC3"  "FAC4"  "FAC5" 

#查看变量的属性

sapply(mydata[ , 1:34], class) 
     F1_1      F1_2      F1_3      F1_4      F2_1      F2_2      F2_3      F2_4 
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" 
     F2_5      F3_1      F3_2      F3_3      F3_4      F3_5      F3_6      F4_1 
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" 
     F4_2      F4_3      F4_4      F4_5      F5_1      F5_2      F5_3      F5_4 
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" 
     F5_5      F5_6      F5_7      F5_8      F5_9     F5_10       use       sex 
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric"  "factor"  "factor" 
      age      year 
"numeric"  "factor" 

2 将变量转为数值变量(numeric)(factor->numeric)

mydata[ , 1:30] <- to_numeric(mydata[ , 1:30])

3 信度分析

3.1 FAC_1 感知開放性

#方法一:使用"performscne"包
x1 <- mydata[, c("F1_1", "F1_2", "F1_3", "F1_4")] 
if (!require("performance")) install.packages("performance")
载入需要的程序包:performance
library(performance) 
item_reliability(x1)
# Item Reliability

Item | Alpha if deleted | Total Correlation | Discrimination
------------------------------------------------------------
F1_1 |             0.85 |              0.86 |           0.76
F1_2 |             0.83 |              0.89 |           0.80
F1_3 |             0.83 |              0.90 |           0.82
F1_4 |             0.90 |              0.79 |           0.63

Mean inter-item-correlation = 0.660  Cronbach's alpha = 0.885
#方法二:使用"psych"包
library(psych)
library(dplyr)

载入程序包:'dplyr'
The following object is masked from 'package:sjlabelled':

    as_label
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
mydata %>%
  dplyr::select(F1_1, F1_2, F1_3, F1_4) %>%
  psych::alpha()  

Reliability analysis   
Call: psych::alpha(x = .)

  raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
      0.89      0.89    0.87      0.66 7.8 0.014  3.4 0.98     0.66

    95% confidence boundaries 
         lower alpha upper
Feldt     0.86  0.89  0.91
Duhachek  0.86  0.89  0.91

 Reliability if an item is dropped:
     raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
F1_1      0.85      0.85    0.82      0.65 5.7    0.019 0.0167  0.64
F1_2      0.83      0.83    0.78      0.62 5.0    0.021 0.0048  0.64
F1_3      0.83      0.83    0.78      0.62 4.8    0.022 0.0171  0.55
F1_4      0.90      0.90    0.86      0.75 8.8    0.013 0.0031  0.77

 Item statistics 
       n raw.r std.r r.cor r.drop mean  sd
F1_1 192  0.86  0.87  0.81   0.76  3.5 1.1
F1_2 192  0.89  0.89  0.87   0.80  3.5 1.1
F1_3 192  0.90  0.90  0.87   0.82  3.4 1.1
F1_4 192  0.79  0.79  0.67   0.63  3.1 1.2

Non missing response frequency for each item
        1    2    3    4    5 miss
F1_1 0.05 0.13 0.22 0.42 0.18    0
F1_2 0.05 0.16 0.21 0.37 0.21    0
F1_3 0.06 0.17 0.24 0.36 0.16    0
F1_4 0.07 0.29 0.23 0.29 0.12    0

Cronbach’s α = 0.885,達到良好信度標準(> 0.8) 刪除任何一題後,α值不会明显提升,因此不需要刪除任何題項。

3.2 FAC_2 实用收益性

x2 <- mydata[, c("F2_1", "F2_2", "F2_3", "F2_4", "F2_5")]
item_reliability(x2)
# Item Reliability

Item | Alpha if deleted | Total Correlation | Discrimination
------------------------------------------------------------
F2_1 |             0.86 |              0.63 |           0.43
F2_2 |             0.79 |              0.83 |           0.71
F2_3 |             0.79 |              0.81 |           0.69
F2_4 |             0.77 |              0.86 |           0.76
F2_5 |             0.81 |              0.76 |           0.62

Mean inter-item-correlation = 0.508  Cronbach's alpha = 0.838

Cronbach’s α = 0.838,達到良好信度標準(> 0.8) 刪除任何一題後,α值不会明显提升,因此不需要刪除任何題項。

3.3 FAC_3 情感收益性

x3 <- mydata[, c("F3_1", "F3_2", "F3_3", "F3_4","F3_5", "F3_6")]
library(performance) 
item_reliability(x3) 
# Item Reliability

Item | Alpha if deleted | Total Correlation | Discrimination
------------------------------------------------------------
F3_1 |             0.89 |              0.62 |           0.48
F3_2 |             0.85 |              0.82 |           0.72
F3_3 |             0.84 |              0.84 |           0.76
F3_4 |             0.85 |              0.80 |           0.70
F3_5 |             0.85 |              0.80 |           0.70
F3_6 |             0.85 |              0.82 |           0.72

Mean inter-item-correlation = 0.537  Cronbach's alpha = 0.876

Cronbach’s α = 0.876,達到良好信度標準(> 0.8) 刪除任何一題後,α值不会明显提升,因此不需要刪除任何題項。

3.4 FAC_4 持续使用

x4 <- mydata[, c("F4_1", "F4_2", "F4_3", "F4_4","F4_5")]
library(performance)
item_reliability(x4) 
# Item Reliability

Item | Alpha if deleted | Total Correlation | Discrimination
------------------------------------------------------------
F4_1 |             0.92 |              0.90 |           0.85
F4_2 |             0.92 |              0.92 |           0.86
F4_3 |             0.92 |              0.93 |           0.88
F4_4 |             0.94 |              0.84 |           0.76
F4_5 |             0.92 |              0.90 |           0.84

Mean inter-item-correlation = 0.757  Cronbach's alpha = 0.939

Cronbach’s α = 0. 939,達到良好信度標準(> 0.8) 刪除任何一題後,α值不会明显提升,因此不需要刪除任何題項。

3.5 FAC_5 AI素养

x5 <- mydata[, c("F5_1", "F5_2", "F5_3", "F5_4","F5_5", "F5_6","F5_7", "F5_8", "F5_9", "F5_10")]
library(performance)
item_reliability(x5) 
# Item Reliability

Item  | Alpha if deleted | Total Correlation | Discrimination
-------------------------------------------------------------
F5_1  |             0.83 |              0.69 |           0.58
F5_2  |             0.83 |              0.68 |           0.59
F5_3  |             0.84 |              0.61 |           0.49
F5_4  |             0.84 |              0.67 |           0.56
F5_5  |             0.83 |              0.71 |           0.64
F5_6  |             0.84 |              0.67 |           0.57
F5_7  |             0.84 |              0.67 |           0.57
F5_8  |             0.84 |              0.62 |           0.51
F5_9  |             0.84 |              0.67 |           0.57
F5_10 |             0.84 |              0.59 |           0.48

Mean inter-item-correlation = 0.368  Cronbach's alpha = 0.852

Cronbach’s α = 0. 852,達到良好信度標準(> 0.8) 刪除任何一題後,α值不会明显提升,因此不需要刪除任何題項。

4 效度检验(EFA因子分析)

针对题目1~题目20进行EFA因子分析

EFA 因子分析(varimax roatation), 呈现转轴後的factor loading及各因子测量题項的Cronbach’s α

4.1 方法一:sjPlot::tab_pca( )

library(sjPlot) 
1tab_pca(mydata[, 1:20],
2        nmbr.fctr = 4,
3        show.var = T,
4        show.msa = T)
1
默認rotation = c(“varimax”) 各因子之间不相关
2
萃取4个因子
3
呈現每一個因子對於测量题项的变异量解释比例
4
呈現KMO(看是否适合進行进行因子分析)(>0.7)
Principal Component Analysis
  Component 1 Component 2 Component 3 Component 4 MSA
F1开放性_1随着对话的进行,chatgpt越来越能够应对各种情况 0.20 -0.12 0.83 0.15 0.89
F1开放性_2随着对话的进行,chatgpt越来越成长 0.17 -0.05 0.88 0.15 0.82
F1开放性_3随着对话的进行,chatgpt越来越成熟 0.12 -0.21 0.87 0.08 0.85
F1开放性_4随着对话的进行,chatgpt越来越了解我 0.14 -0.32 0.70 0.05 0.91
F2实用收益_1对chatgpt下达指令并很容易获得服务 0.06 -0.04 0.04 0.76 0.80
F2实用收益_2让我更轻松的完成工作 0.31 -0.04 0.15 0.77 0.85
F2实用收益_3提高了我的工作效率 0.54 -0.02 0.26 0.56 0.92
F2实用收益_4提供的服务是我需要的 0.58 -0.07 0.12 0.61 0.91
F2实用收益_5很好的反应了我所关心的方面 0.46 -0.18 0.14 0.53 0.91
F3情绪收益_1愉快有趣的 0.53 -0.38 0.30 0.05 0.96
F3情绪收益_2不再孤单 0.20 -0.78 0.19 -0.10 0.87
F3情绪收益_3朋友一样 0.12 -0.86 0.07 -0.05 0.87
F3情绪收益_4交流使我感到被安慰 0.07 -0.80 0.17 0.12 0.90
F3情绪收益_5可以与我共情 0.26 -0.74 0.12 0.13 0.90
F3情绪收益_6理解我的想法和情绪 0.12 -0.81 0.14 0.18 0.87
F4持续使用意图_1有意愿持续使用 0.86 -0.12 0.15 0.22 0.93
F4持续使用意图_2会更频繁使用 0.85 -0.17 0.17 0.19 0.95
F4持续使用意图_3有计划继续使用 0.90 -0.06 0.14 0.18 0.91
F4持续使用意图_4会向他人推荐使用 0.77 -0.22 0.08 0.16 0.93
F4持续使用意图_5有意愿未来增加使用频率 0.83 -0.24 0.12 0.16 0.94
Proportion of Variance 41.17 % 14.28 % 9.96 % 6.02 %
Cumulative Proportion 41.17 % 55.45 % 65.40 % 71.42 %
Cronbach's α 0.93 0.89 0.89 0.84
Kaiser-Meyer-Olkin 0.90
varimax-rotation

结果:

  1. F2_3, F2_4,F2_5在因子4的因子载荷较低(< 0.7),但仍大于0.5,故仍可保留。

  2. F3_1題項于因子1的因子载荷=.53,因子2的因子载荷= -0.38,该题可删除,亦可不删。(此处选择不删题目)

整体来说,题目1~题目20分别可以收敛于四个因子,具备一定的收敛效度与区别效度。

4.2 方法二:psych::principal( )

library(psych)
efa_result <- principal(mydata[, 1:20], 
                 nfactors = 4,
                 rotate = "varimax")

print(efa_result, cut = 0.5)  # 隐藏负荷量小於 0.5 
Principal Components Analysis
Call: principal(r = mydata[, 1:20], nfactors = 4, rotate = "varimax")
Standardized loadings (pattern matrix) based upon correlation matrix
      RC1  RC2  RC3   RC4   h2   u2 com
F1_1           0.83       0.76 0.24 1.2
F1_2           0.88       0.84 0.16 1.1
F1_3           0.87       0.83 0.17 1.2
F1_4           0.70       0.61 0.39 1.5
F2_1                 0.76 0.58 0.42 1.0
F2_2                 0.77 0.72 0.28 1.4
F2_3 0.54            0.56 0.67 0.33 2.4
F2_4 0.58            0.61 0.73 0.27 2.1
F2_5                 0.53 0.55 0.45 2.4
F3_1 0.53                 0.52 0.48 2.5
F3_2      0.78            0.69 0.31 1.3
F3_3      0.86            0.76 0.24 1.1
F3_4      0.80            0.69 0.31 1.2
F3_5      0.74            0.65 0.35 1.4
F3_6      0.81            0.72 0.28 1.2
F4_1 0.86                 0.82 0.18 1.2
F4_2 0.85                 0.82 0.18 1.3
F4_3 0.90                 0.86 0.14 1.1
F4_4 0.77                 0.68 0.32 1.3
F4_5 0.83                 0.79 0.21 1.3

                       RC1  RC2  RC3  RC4
SS loadings           5.04 3.69 3.13 2.43
Proportion Var        0.25 0.18 0.16 0.12
Cumulative Var        0.25 0.44 0.59 0.71
Proportion Explained  0.35 0.26 0.22 0.17
Cumulative Proportion 0.35 0.61 0.83 1.00

Mean item complexity =  1.5
Test of the hypothesis that 4 components are sufficient.

The root mean square of the residuals (RMSR) is  0.03 
 with the empirical chi square  78.27  with prob <  1 

Fit based upon off diagonal values = 0.99
fa.diagram(efa_result)

结果同 sjPlot::tab_pca( )

5 建构综合指标分数

5.1 因子1的综合指标分数

因子1(component 3 )由F1_1 to F1_4四题构成。因此,将受访者对于这四题的态度分数予以加总,并求平均,得到因子1的综合指标分数(FAC_1)。

library(dplyr)
mydata <- mydata |> 
  mutate(FAC_1 = rowMeans(across(F1_1:F1_4), na.rm = TRUE))
mydata[1:10, c("FAC1", "FAC_1")]
   FAC1 FAC_1
1  3.25  3.25
2  4.00  4.00
3  1.75  1.75
4  2.00  2.00
5  4.00  4.00
6  1.00  1.00
7  3.00  3.00
8  1.00  1.00
9  3.00  3.00
10 4.00  4.00

5.2 因子2的综合指标分数

因子2(component 4 )由F2_1 to F2_4五题构成。因此,将受访者对于这五题的态度分数予以加总,并求平均,得到因子2的综合指标分数(FAC_2)。

mydata <- mydata |> 
  mutate(FAC_2 = rowMeans(across(F2_1:F2_5), na.rm = TRUE))
mydata[1:10, c("FAC2", "FAC_2")]
   FAC2 FAC_2
1   4.6   4.6
2   4.0   4.0
3   3.2   3.2
4   2.8   2.8
5   1.8   1.8
6   1.0   1.0
7   3.4   3.4
8   3.0   3.0
9   3.8   3.8
10  3.6   3.6

5.3 因子3的综合指标分数

因子3(component 2 )由F3_1到F3_6六题构成。因此,将受访者对于这六题的态度分数予以加总,并求平均,得到因子3的综合指标分数(FAC_3)。

mydata <- mydata |>
  mutate(FAC_3 = rowMeans(across(F3_1:F3_6), na.rm = TRUE))
mydata[1:10, c("FAC3", "FAC_3")]
       FAC3    FAC_3
1  1.500000 1.500000
2  3.000000 3.000000
3  2.666667 2.666667
4  1.166667 1.166667
5  3.666667 3.666667
6  1.500000 1.500000
7  4.666667 4.666667
8  1.000000 1.000000
9  1.500000 1.500000
10 3.833333 3.833333

5.4 因子4的综合指标分数

因子4(component 1 )由F4_1到F4_5五题构成。因此,将受访者对于这五题的态度分数予以加总,并求平均,得到因子3的综合指标分数(FAC_4)。

mydata <- mydata |> 
  mutate(FAC_4 = rowMeans(across(F4_1:F4_5), na.rm = TRUE))
mydata[1:10, c("FAC4", "FAC_4")]
   FAC4 FAC_4
1   4.2   4.2
2   3.0   3.0
3   3.8   3.8
4   1.2   1.2
5   4.0   4.0
6   1.6   1.6
7   4.2   4.2
8   1.8   1.8
9   4.0   4.0
10  3.6   3.6

5.5 因子5的综合指标分数

因子5由F5_1到F5_10十题构成。因此,将受访者对于这十题的态度分数予以加总,并求平均,得到因子5的综合指标分数(FAC_5)。

mydata <- mydata |> 
  mutate(FAC_5 = rowMeans(across(F5_1:F5_10), na.rm = TRUE))
mydata[1:10, c("FAC5", "FAC_5")]
   FAC5 FAC_5
1   4.4   4.4
2   1.0   1.0
3   3.2   3.2
4   2.2   2.2
5   1.9   1.9
6   1.4   1.4
7   2.3   2.3
8   2.6   2.6
9   2.9   2.9
10  2.9   2.9

6 不同因子综合指标分数间的相關分析

names(mydata)
 [1] "F1_1"  "F1_2"  "F1_3"  "F1_4"  "F2_1"  "F2_2"  "F2_3"  "F2_4"  "F2_5" 
[10] "F3_1"  "F3_2"  "F3_3"  "F3_4"  "F3_5"  "F3_6"  "F4_1"  "F4_2"  "F4_3" 
[19] "F4_4"  "F4_5"  "F5_1"  "F5_2"  "F5_3"  "F5_4"  "F5_5"  "F5_6"  "F5_7" 
[28] "F5_8"  "F5_9"  "F5_10" "use"   "sex"   "age"   "year"  "FAC1"  "FAC2" 
[37] "FAC3"  "FAC4"  "FAC5"  "FAC_1" "FAC_2" "FAC_3" "FAC_4" "FAC_5"
#设置因子变量的标签
library(sjlabelled)

mydata$FAC_1 <- set_label(mydata$FAC_1, 
 label = "FAC_1 感知开放综合指标分数(1-5)")
mydata$FAC_2 <- set_label(mydata$FAC_2, 
 label = "FAC_2 实用收益综合指标分数(1-5)")
mydata$FAC_3 <- set_label(mydata$FAC_3, 
 label = "FAC_3 情绪收益综合指标分数(1-5)")
mydata$FAC_4 <- set_label(mydata$FAC_4, 
 label = "FAC_4 持续使用综合指标分数(1-5)" )
mydata$FAC_5 <- set_label(mydata$FAC_5, 
 label = "FAC_5 AI素养综合指标分数(1-5)" )

#因子间的相关系数(表格)
names(mydata)
 [1] "F1_1"  "F1_2"  "F1_3"  "F1_4"  "F2_1"  "F2_2"  "F2_3"  "F2_4"  "F2_5" 
[10] "F3_1"  "F3_2"  "F3_3"  "F3_4"  "F3_5"  "F3_6"  "F4_1"  "F4_2"  "F4_3" 
[19] "F4_4"  "F4_5"  "F5_1"  "F5_2"  "F5_3"  "F5_4"  "F5_5"  "F5_6"  "F5_7" 
[28] "F5_8"  "F5_9"  "F5_10" "use"   "sex"   "age"   "year"  "FAC1"  "FAC2" 
[37] "FAC3"  "FAC4"  "FAC5"  "FAC_1" "FAC_2" "FAC_3" "FAC_4" "FAC_5"
library(sjPlot) 
tab_corr(mydata[, 40:44], triangle = "upper")
  FAC_1 感知开放综合指标分数(1-5) FAC_2 实用收益综合指标分数(1-5) FAC_3 情绪收益综合指标分数(1-5) FAC_4 持续使用综合指标分数(1-5) FAC_5 AI素养综合指标分数(1-5)
FAC_1 感知开放综合指标分数(1-5)   0.380*** 0.437*** 0.378*** 0.200**
FAC_2 实用收益综合指标分数(1-5)     0.315*** 0.673*** 0.362***
FAC_3 情绪收益综合指标分数(1-5)       0.457*** 0.079
FAC_4 持续使用综合指标分数(1-5)         0.373***
FAC_5 AI素养综合指标分数(1-5)          
Computed correlation used pearson-method with listwise-deletion.
#因子间的相关系数(图)
if (!require("ggcorrplot")) install.packages("ggcorrplot")
载入需要的程序包:ggcorrplot
载入需要的程序包:ggplot2

载入程序包:'ggplot2'
The following object is masked from 'package:sjPlot':

    set_theme
The following objects are masked from 'package:psych':

    %+%, alpha
The following object is masked from 'package:sjlabelled':

    as_label
library(ggcorrplot)
cor_mat <- cor(mydata[, 40:44], use = "complete.obs")
ggcorrplot(cor_mat,
           type = "upper",
           lab = TRUE,
           lab_size = 8,
           colors = c("#6D9EC1", "white", "#E46726"),
           ggtheme = theme_bw(),
           title = "FAC_1~FAC_5 相关系数矩阵")
Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
ℹ Please use tidy evaluation idioms with `aes()`.
ℹ See also `vignette("ggplot2-in-packages")` for more information.
ℹ The deprecated feature was likely used in the ggcorrplot package.
  Please report the issue at <https://github.com/kassambara/ggcorrplot/issues>.

7 FAC_4(持续使用) <- FAC_1(感知开放性) 回归分析(控制其他人口变量)

7.1 一般回归分析

#进行回归分析
mod1 <- lm(FAC_4 ~ FAC_1 + use + sex + age + year, data = mydata)

#呈现回归分析摘要表
library(sjPlot) 
tab_model(mod1,
          prefix.labels = "label", #呈现变量与变量值名称
          show.reflvl = T, #呈现参照类
          show.se = T) #呈现std. Error
  FAC_4 持续使用综合指标分数(1-5)
Predictors Estimates std. Error CI p
(Intercept) 4.22 1.14 1.98 – 6.47 <0.001
FAC_1 感知开放综合指标分数(1-5) 0.34 0.07 0.21 – 0.47 <0.001
年龄 -0.08 0.05 -0.17 – 0.01 0.073
使用chatgpt的经历: 有 Reference
使用chatgpt的经历: 无 -0.42 0.14 -0.70 – -0.14 0.004
性别: 男 Reference
性别: 女 0.14 0.17 -0.20 – 0.48 0.420
学年: 大一 Reference
学年: 大二 0.19 0.37 -0.54 – 0.93 0.606
学年: 大三 0.29 0.35 -0.39 – 0.98 0.402
学年: 大四 0.27 0.37 -0.46 – 0.99 0.466
学年: 研究生 0.65 0.39 -0.13 – 1.42 0.102
Observations 192
R2 / R2 adjusted 0.226 / 0.192

FAC_1的beta=0.34, non-robust se的CI区间[0.21-0.47]

7.2 robust se (vcov = “HC3”)

tab_model(mod1,
          prefix.labels = "label",
          show.reflvl = T,
          show.se=T,
          string.se="robust std.error",
          vcov.fun = "HC3") #robust se string.se="robust se"
  FAC_4 持续使用综合指标分数(1-5)
Predictors Estimates robust std.error CI p
(Intercept) 4.22 1.27 1.72 – 6.73 0.001
FAC_1 感知开放综合指标分数(1-5) 0.34 0.08 0.18 – 0.50 <0.001
年龄 -0.08 0.04 -0.17 – 0.01 0.071
使用chatgpt的经历: 有 Reference
使用chatgpt的经历: 无 -0.42 0.17 -0.76 – -0.08 0.016
性别: 男 Reference
性别: 女 0.14 0.19 -0.24 – 0.51 0.464
学年: 大一 Reference
学年: 大二 0.19 0.63 -1.05 – 1.44 0.760
学年: 大三 0.29 0.61 -0.91 – 1.50 0.634
学年: 大四 0.27 0.61 -0.93 – 1.47 0.659
学年: 研究生 0.65 0.61 -0.55 – 1.84 0.288
Observations 192
R2 / R2 adjusted 0.226 / 0.192

FAC_1的beta=0.34, robust se的CI区间[0.18-0.50],比non-robust se的CI区间[0.21-0.47],要来的宽,表示比较不易得到显著结果(比较严谨)。

7.3 bootstrap se

library(parameters)
set.seed(12345) #设置固定数字->使bootstrap se CI,每次运行都一致
tab_model(mod1,
          prefix.labels = "label",
          show.reflvl = T,
          show.se=TRUE,
          bootstrap=T, 
          string.ci="Bootstrap CI")
  FAC_4 持续使用综合指标分数(1-5)
Predictors Estimates Bootstrap CI p
(Intercept) 4.23 1.74 – 6.54 0.002
FAC_1 感知开放综合指标分数(1-5) 0.34 0.19 – 0.48 <0.001
年龄 -0.08 -0.17 – 0.01 0.070
使用chatgpt的经历: 有 Reference
使用chatgpt的经历: 无 -0.40 -0.74 – -0.07 0.014
性别: 男 Reference
性别: 女 0.13 -0.22 – 0.50 0.480
学年: 大一 Reference
学年: 大二 0.17 -0.84 – 1.46 0.773
学年: 大三 0.26 -0.66 – 1.58 0.649
学年: 大四 0.21 -0.70 – 1.55 0.695
学年: 研究生 0.61 -0.28 – 1.93 0.234
Observations 192
R2 / R2 adjusted 0.226 / 0.192

FAC_1的beta=0.34, bootstrap se 的CI区间[0.19-0.48],和robust se的CI区间[0.18-0.50]相比,bootstrap se 的CI区间稍微小一些,但大于一般se 的CI区间。

8 中介效果(两个中介变量)

8.1 使用psych::mediate( )

library(psych)
set.seed(2025) # 固定随机种子 → 让系数永远一致
mod.mediate <- psych::mediate(FAC_4 ~ FAC_1 + (FAC_2) + (FAC_3),
                              data = mydata, n.iter = 5000)

summary(mod.mediate) #输出直接效果+中介结果摘要表
Call: psych::mediate(y = FAC_4 ~ FAC_1 + (FAC_2) + (FAC_3), data = mydata, 
    n.iter = 5000)

Direct effect estimates (traditional regression)    (c') X + M on Y 
          FAC_4   se     t  df     Prob
Intercept  0.03 0.27  0.10 188 9.23e-01
FAC_1      0.05 0.06  0.83 188 4.06e-01
FAC_2      0.73 0.07 10.35 188 3.83e-20
FAC_3      0.28 0.06  4.48 188 1.30e-05

R = 0.72 R2 = 0.52   F = 68.22 on 3 and 188 DF   p-value:  6.82e-30 

 Total effect estimates (c) (X on Y) 
          FAC_4   se     t  df     Prob
Intercept  2.49 0.23 10.71 190 3.04e-21
FAC_1      0.37 0.07  5.63 190 6.26e-08

 'a'  effect estimates (X on M) 
          FAC_2   se     t  df     Prob
Intercept  2.84 0.18 15.47 190 1.80e-35
FAC_1      0.29 0.05  5.67 190 5.34e-08
          FAC_3   se    t  df     Prob
Intercept  1.46 0.21 6.97 190 5.08e-11
FAC_1      0.40 0.06 6.69 190 2.44e-10

 'b'  effect estimates (M on Y controlling for X) 
      FAC_4   se     t  df     Prob
FAC_2  0.73 0.07 10.35 188 3.83e-20
FAC_3  0.28 0.06  4.48 188 1.30e-05

 'ab'  effect estimates (through all  mediators)
      FAC_4 boot   sd lower upper
FAC_1  0.32 0.32 0.06  0.22  0.44

 'ab' effects estimates for each mediator for FAC_4 
            boot   sd lower upper
FAC_1       0.32 0.06  0.22  0.44
FAC_2*FAC_1 0.22 0.05  0.12  0.32
FAC_3*FAC_1 0.11 0.03  0.06  0.17
# 输出中介结果
mod.mediate #简洁文字说明直接效果+中介结果

Mediation/Moderation Analysis 
Call: psych::mediate(y = FAC_4 ~ FAC_1 + (FAC_2) + (FAC_3), data = mydata, 
    n.iter = 5000)

The DV (Y) was  FAC_4 . The IV (X) was  FAC_1 . The mediating variable(s) =  FAC_2 FAC_3 .

Total effect(c) of  FAC_1  on  FAC_4  =  0.37   S.E. =  0.07  t  =  5.63  df=  190   with p =  6.3e-08
Direct effect (c') of  FAC_1  on  FAC_4  removing  FAC_2 FAC_3  =  0.05   S.E. =  0.06  t  =  0.83  df=  188   with p =  0.41
Indirect effect (ab) of  FAC_1  on  FAC_4  through  FAC_2 FAC_3   =  0.32 
Mean bootstrapped indirect effect =  0.32  with standard error =  0.06  Lower CI =  0.22    Upper CI =  0.44
R = 0.72 R2 = 0.52   F = 68.22 on 3 and 188 DF   p-value:  1.4e-35 

 To see the longer output, specify short = FALSE in the print statement or ask for the summary
#中介结果绘图
mediate.diagram(mod.mediate)

ps:表中的效果efect,是未標準化的beta

FAC_1 -> FAC_4的直接效果(排除FAC_2与FAC_3的影响)=0.05 #(Direct effect estimates (traditional regression))

FAC_1 -> FAC_4的间接效果(透过FAC_2与FAC_3的影响) =(0.290.73)+(0.400.28)=0.32 #(‘ab’ effect estimates (through all mediators))

FAC_1 -> FAC_4的总效果=0.05(直接效果)+0.32(间接效果)=0.37 #(Total effect estimates (c) (X on Y) )

8.1.1 中介效果检验

FAC_1 -> FAC_2-> FAC_4的中介效果 =(bootstrap Beta)0.21,se=0.05, [0.12, 0.31]#正向影響 #(‘ab’ effects estimates for each mediator for FAC_4 :FAC_2*FAC_1)

FAC_1 -> FAC_3 -> FAC4的中介效果 =(bootstrap beta)0.11,se=0.03, [0.05, 0.17]#正向顯著影響 #(‘ab’ effects estimates for each mediator for FAC_4 :FAC_3*FAC_1)

所有中介效果總和=0.21+0.11=0.32 #(‘ab’ effect estimates (through all mediators)) #(‘ab’ effects estimates for each mediator for FAC_4 :FAC_1))

8.1.2 淨直接效果检验

FAC_1 -> FAC_4, (控制FAC_2, FAC_3), bata=0.05(P=0.406 > 0.05) #不显著

8.1.3 小结:

FAC_1 -> FAC_4的影响,是透过FAC_2, FAC_3進行影响,

FAC_2, FAC_3扮演完全中介效果。

用psych套件跑出來的結果,和用spss process套件跑出來的結果,結果一致

8.2 使用processR(套件包或网址)

if(!require("devtools")) install.packages("devtools")
载入需要的程序包:devtools
载入需要的程序包:usethis

载入程序包:'usethis'
The following object is masked from 'package:sjlabelled':

    tidy_labels
devtools::install_github("cardiomoon/processR")  
Using GitHub PAT from the git credential store.
Skipping install of 'processR' from a github remote, the SHA1 (c6c817b5) has not changed since last install.
  Use `force = TRUE` to force installation
#中介/调节变量绘图 process macro model
library(processR)

载入程序包:'processR'
The following object is masked from 'package:psych':

    corPlot
pmacroModel(4) #一个中介变量示意图

pmacroModel(4.2) #二个中介变量,分別中介示意图

pmacroModel(6) #二个中介变量,兩次中介示意图

pmacroModel(8) #调节的中介示意图

statisticalDiagram(4) #模型4系数图

statisticalDiagram(4.2) #模型4.2系数图

statisticalDiagram(6) #模型6系数图

statisticalDiagram(8) #模型8系数图

# 带变量名称的调节模型路径图
labels <- list(X = "FAC_1", Y = "FAC_2", W = "FAC5")
pmacroModel(1, labels = labels)

statisticalDiagram(1, labels = labels)

点击这个网址,在该网站进行分析: https://cardiomoon.shinyapps.io/processR/

  1. Select data 上传数据档,例如:chatgpt_EFA.sav
  2. Select Process Macro Model Number 选择模型图[例如:pmacroModel(4.2)]
  3. Assign Variables 例如: X: FAC_1 M1: FAC_2 M2: FAC_3 Y: FAC_4
  4. Make Equation 产生R代码(如下)
  5. Analysis 在R区块中执行代码,即得分析结果。亦可在网站上直接进行分析,得出结果。
# Mediation Effect
#模型建构
library(lavaan)
This is lavaan 0.6-21
lavaan is FREE software! Please report any bugs.

载入程序包:'lavaan'
The following object is masked from 'package:psych':

    cor2cov
model <- '
  FAC_4 ~ b1*FAC_2 + b2*FAC_3 + c1*FAC_1
  FAC_2 ~ a1*FAC_1
  FAC_3 ~ a2*FAC_1
  ind1 := a1*b1
  ind2 := a2*b2
  total1 := c1 + a1*b1 + a2*b2
'

#模型参数估计
fit_lavaan = sem(model = model,
        data = mydata,
        se = 'bootstrap',
        bootstrap = 1000,
        missing = 'pairwise') 

#摘要模型估计值(方法1)
summary(fit_lavaan,
        fit.measures = TRUE,  
        standardize = TRUE, 
        rsquare = TRUE)
lavaan 0.6-21 ended normally after 2 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         8

  Number of observations                           192
  Number of missing patterns                         1

Model Test User Model:
                                                      
  Test statistic                                 6.258
  Degrees of freedom                                 1
  P-value (Chi-square)                           0.012

Model Test Baseline Model:

  Test statistic                               218.253
  Degrees of freedom                                 6
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.975
  Tucker-Lewis Index (TLI)                       0.851

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -624.776
  Loglikelihood unrestricted model (H1)       -621.647
                                                      
  Akaike (AIC)                                1265.551
  Bayesian (BIC)                              1291.611
  Sample-size adjusted Bayesian (SABIC)       1266.270

Root Mean Square Error of Approximation:

  RMSEA                                          0.165
  90 Percent confidence interval - lower         0.062
  90 Percent confidence interval - upper         0.299
  P-value H_0: RMSEA <= 0.050                    0.036
  P-value H_0: RMSEA >= 0.080                    0.918

Standardized Root Mean Square Residual:

  SRMR                                           0.057

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  FAC_4 ~                                                               
    FAC_2     (b1)    0.727    0.078    9.375    0.000    0.727    0.587
    FAC_3     (b2)    0.275    0.069    4.004    0.000    0.275    0.261
    FAC_1     (c1)    0.048    0.057    0.845    0.398    0.048    0.050
  FAC_2 ~                                                               
    FAC_1     (a1)    0.294    0.059    5.004    0.000    0.294    0.380
  FAC_3 ~                                                               
    FAC_1     (a2)    0.398    0.060    6.611    0.000    0.398    0.437

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .FAC_4             0.436    0.062    7.049    0.000    0.436    0.501
   .FAC_2             0.485    0.062    7.816    0.000    0.485    0.855
   .FAC_3             0.636    0.060   10.668    0.000    0.636    0.809

R-Square:
                   Estimate
    FAC_4             0.499
    FAC_2             0.145
    FAC_3             0.191

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    ind1              0.214    0.048    4.425    0.000    0.214    0.223
    ind2              0.109    0.029    3.734    0.000    0.109    0.114
    total1            0.371    0.068    5.428    0.000    0.371    0.387
#摘要模型估计值(方法2)
parameterEstimates(fit_lavaan,
                   boot.ci.type = 'bca.simple',
                   level = .95,
                   ci = TRUE,
                   standardized = FALSE)
      lhs op            rhs  label   est    se      z pvalue ci.lower ci.upper
1   FAC_4  ~          FAC_2     b1 0.727 0.078  9.375  0.000    0.567    0.864
2   FAC_4  ~          FAC_3     b2 0.275 0.069  4.004  0.000    0.134    0.413
3   FAC_4  ~          FAC_1     c1 0.048 0.057  0.845  0.398   -0.059    0.153
4   FAC_2  ~          FAC_1     a1 0.294 0.059  5.004  0.000    0.175    0.405
5   FAC_3  ~          FAC_1     a2 0.398 0.060  6.611  0.000    0.285    0.515
6   FAC_4 ~~          FAC_4        0.436 0.062  7.049  0.000    0.324    0.576
7   FAC_2 ~~          FAC_2        0.485 0.062  7.816  0.000    0.381    0.630
8   FAC_3 ~~          FAC_3        0.636 0.060 10.668  0.000    0.531    0.763
9   FAC_1 ~~          FAC_1        0.946 0.000     NA     NA    0.946    0.946
10   ind1 :=          a1*b1   ind1 0.214 0.048  4.425  0.000    0.120    0.308
11   ind2 :=          a2*b2   ind2 0.109 0.029  3.734  0.000    0.056    0.174
12 total1 := c1+a1*b1+a2*b2 total1 0.371 0.068  5.428  0.000    0.235    0.499

結果:和使用 psych 套件包的结果一致

ps.

  1. 中介效果分析中,processR產生的beta系数,是沒有经过平減的beta

  2. spss则可以產生平減與未平減的beta,但兩者跑出來的数据相同

9 调节效果

模型图使用 process model 1 利用processR Shiny App產生R代码, 复制并贴到下方R区块:

9.1 FAC_5 在FAC_1 与FAC_2之间,扮演调节作用

# 调节模型示意图
library(processR)
pmacroModel(1)

# 带变量名称的调节模型路径图
labels <- list(X = "FAC_1", Y = "FAC_2", W = "FAC5")
pmacroModel(1, labels = labels)

statisticalDiagram(1, labels = labels)

#模型建立
library(lavaan)
model.1 <- '
  FAC_2 ~ b1*FAC_1 + b2*FAC_5 + b3*FAC_1:FAC_5
  FAC_5 ~ FAC_5.mean*1
  FAC_5 ~~ FAC_5.var*FAC_5
'

#模型参数估计
fit1=sem(model=model.1,
        data=mydata,
        se='bootstrap',
        bootstrap=1000,
        missing='pairwise') 

#摘要模型估计值(方法1)
summary(fit1,
        fit.measures = TRUE,  
        standardize = TRUE, 
        rsquare = TRUE)
lavaan 0.6-21 ended normally after 9 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         7

  Number of observations                           192
  Number of missing patterns                         1

Model Test User Model:
                                                      
  Test statistic                               460.791
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               521.617
  Degrees of freedom                                 5
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.112
  Tucker-Lewis Index (TLI)                      -1.220

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -379.001
  Loglikelihood unrestricted model (H1)       -148.606
                                                      
  Akaike (AIC)                                 772.002
  Bayesian (BIC)                               794.805
  Sample-size adjusted Bayesian (SABIC)        772.631

Root Mean Square Error of Approximation:

  RMSEA                                          1.093
  90 Percent confidence interval - lower         1.010
  90 Percent confidence interval - upper         1.178
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.421

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  FAC_2 ~                                                               
    FAC_1     (b1)    0.955    0.241    3.965    0.000    0.955    0.851
    FAC_5     (b2)    1.085    0.239    4.535    0.000    1.085    0.652
    FAC_1:FAC (b3)   -0.217    0.070   -3.113    0.002   -0.217   -0.853

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    3.355    0.047   70.983    0.000    3.355    5.117
   .FAC_2            -0.543    0.806   -0.674    0.500   -0.543   -0.498

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    0.430    0.050    8.629    0.000    0.430    1.000
   .FAC_2             0.413    0.049    8.463    0.000    0.413    0.347

R-Square:
                   Estimate
    FAC_2             0.653
#摘要模型估计值(方法2)
parameterEstimates(fit1,
                   boot.ci.type = 'bca.simple',
                   level = .95,
                   ci = TRUE,
                   standardized = FALSE)
           lhs op         rhs      label    est    se      z pvalue ci.lower
1        FAC_2  ~       FAC_1         b1  0.955 0.241  3.965  0.000    0.398
2        FAC_2  ~       FAC_5         b2  1.085 0.239  4.535  0.000    0.573
3        FAC_2  ~ FAC_1:FAC_5         b3 -0.217 0.070 -3.113  0.002   -0.346
4        FAC_5 ~1             FAC_5.mean  3.355 0.047 70.983  0.000    3.259
5        FAC_5 ~~       FAC_5  FAC_5.var  0.430 0.050  8.629  0.000    0.346
6        FAC_2 ~~       FAC_2             0.413 0.049  8.463  0.000    0.330
7        FAC_1 ~~       FAC_1             0.946 0.000     NA     NA    0.946
8        FAC_1 ~~ FAC_1:FAC_5             3.512 0.000     NA     NA    3.512
9  FAC_1:FAC_5 ~~ FAC_1:FAC_5            18.363 0.000     NA     NA   18.363
10       FAC_2 ~1                        -0.543 0.806 -0.674  0.500   -1.902
11       FAC_1 ~1                         3.391 0.000     NA     NA    3.391
12 FAC_1:FAC_5 ~1                        11.502 0.000     NA     NA   11.502
   ci.upper
1     1.347
2     1.522
3    -0.069
4     3.446
5     0.545
6     0.527
7     0.946
8     3.512
9    18.363
10    1.286
11    3.391
12   11.502
#调节效果绘图(Simple Slope Plot)

#1)建立含交互项的 lm 模型(与 lavaan 结果一致)
mod_int.1 <- lm(FAC_2 ~ FAC_1 * FAC_5, data = mydata)

#2)计算调节变量FAC5的mean +sd 
fac_5_mean <- mean(mydata$FAC_5, na.rm = TRUE)
fac_5_sd  <- sd(mydata$FAC_5, na.rm = TRUE)

#3)Simple Slope Plot:
#以 FAC_5 高、均值、低分组呈现 FAC_1->FAC_2的不同斜率图
library(interactions)
interact_plot(mod_int.1,
              pred = FAC_1,
              modx = FAC_5,
              modx.values = c(fac_5_mean - fac_5_sd,
                              fac_5_mean,
                              fac_5_mean + fac_5_sd),
              x.label = "感知开放性(FAC_1)",
              y.label = "实用收益(FAC_2)",
              legend.main = "AI素养(FAC_5)",
              modx.labels = c("低(-1 SD)", 
                              "均值", 
                              "高(+1 SD)"))

#4) Johnson-NeymanPlot:
# 调节变量FAC_5不同水平下,FAC_1->FAC_2斜率估计+统计检验+JOHNSON-NEYMAN plot

#FAC_1->FAC_2斜率估计+统计检验+JOHNSON-NEYMAN plot
sim_slopes(mod_int.1,
           pred = FAC_1,
           modx = FAC_5,
           jnplot = T)
JOHNSON-NEYMAN INTERVAL

When FAC_5 is OUTSIDE the interval [3.83, 6.24], the slope of FAC_1 is p <
.05.

Note: The range of observed values of FAC_5 is [1.00, 5.00]

SIMPLE SLOPES ANALYSIS

Slope of FAC_1 when FAC_5 = 2.697326 (- 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.37   0.06     6.01   0.00

Slope of FAC_1 when FAC_5 = 3.354687 (Mean): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.23   0.05     4.55   0.00

Slope of FAC_1 when FAC_5 = 4.012049 (+ 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.08   0.07     1.18   0.24
#JOHNSON-NEYMAN plot+呈现临界值 
jn1 <- johnson_neyman(mod_int.1, 
                      pred = FAC_1, 
                      modx = FAC_5)
jn1$plot +
  annotate("text",
           x = jn1$bounds[1],
           y = 0.5,
           label = paste0("临界值\nFAC_5 = ", round(jn1$bounds[1], 2)),
           hjust = -0.1,
           color = "red",
           size = 5)

Johnson-Neyman Plot 。解读如下:

  1. 蓝色区域(p < .05): FAC5 < 3.83 时,FAC1→FAC2 的斜率显著为正

  2. 红色区域(n.s.): FAC5 ≥ 3.83 时,斜率不显著(斜率置信区间跨越零)

  3. 黑色水平横线: FAC5的实际观测范围(1~5),临界值(交叉线) =3.83

也就是说,样本中约有 FAC5 ≤ 3.83 的受访者才能观察到 FAC1 对 FAC2 的显著正向影响。

9.2 FAC_5 在FAC_1 与FAC_3之间,扮演调节作用

library(lavaan)
pmacroModel(1) #一个调节变量

# 带变量名称的调节模型路径图
labels <- list(X = "FAC_1", Y = "FAC_3", W = "FAC_5")
pmacroModel(1, labels = labels)

statisticalDiagram(1, labels = labels)

#模型建立
model.2 <- '
  FAC_3 ~ b1*FAC_1 + b2*FAC_5 + b3*FAC_1:FAC_5
  FAC_5 ~ FAC_5.mean*1
  FAC_5 ~~ FAC_5.var*FAC_5
'

#模型参数估计
fit2 <- sem(model = model.2,
        data = mydata,
        se = 'bootstrap',
        bootstrap = 200,
        missing = 'pairwise') 

#摘要模型估计值(方法1)
summary(fit2,
        fit.measures = TRUE,  
        standardize = TRUE, 
        rsquare = TRUE)
lavaan 0.6-21 ended normally after 9 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         7

  Number of observations                           192
  Number of missing patterns                         1

Model Test User Model:
                                                      
  Test statistic                               460.791
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               505.840
  Degrees of freedom                                 5
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.084
  Tucker-Lewis Index (TLI)                      -1.290

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -418.127
  Loglikelihood unrestricted model (H1)       -187.732
                                                      
  Akaike (AIC)                                 850.255
  Bayesian (BIC)                               873.057
  Sample-size adjusted Bayesian (SABIC)        850.884

Root Mean Square Error of Approximation:

  RMSEA                                          1.093
  90 Percent confidence interval - lower         1.010
  90 Percent confidence interval - upper         1.178
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.235

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws              200
  Number of successful bootstrap draws             200

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  FAC_3 ~                                                               
    FAC_1     (b1)    0.951    0.269    3.534    0.000    0.951    0.920
    FAC_5     (b2)    0.568    0.300    1.892    0.059    0.568    0.371
    FAC_1:FAC (b3)   -0.170    0.078   -2.169    0.030   -0.170   -0.723

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    3.355    0.047   70.899    0.000    3.355    5.117
   .FAC_3            -0.368    1.003   -0.367    0.713   -0.368   -0.366

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    0.430    0.051    8.452    0.000    0.430    1.000
   .FAC_3             0.621    0.061   10.259    0.000    0.621    0.615

R-Square:
                   Estimate
    FAC_3             0.385
#摘要模型估计值(方法2)
parameterEstimates(fit2,
                   boot.ci.type = 'bca.simple',
                   level = .95,
                   ci = TRUE,
                   standardized = FALSE)
           lhs op         rhs      label    est    se      z pvalue ci.lower
1        FAC_3  ~       FAC_1         b1  0.951 0.269  3.534  0.000    0.187
2        FAC_3  ~       FAC_5         b2  0.568 0.300  1.892  0.059   -0.070
3        FAC_3  ~ FAC_1:FAC_5         b3 -0.170 0.078 -2.169  0.030   -0.315
4        FAC_5 ~1             FAC_5.mean  3.355 0.047 70.899  0.000    3.256
5        FAC_5 ~~       FAC_5  FAC_5.var  0.430 0.051  8.452  0.000    0.343
6        FAC_3 ~~       FAC_3             0.621 0.061 10.259  0.000    0.507
7        FAC_1 ~~       FAC_1             0.946 0.000     NA     NA    0.946
8        FAC_1 ~~ FAC_1:FAC_5             3.512 0.000     NA     NA    3.512
9  FAC_1:FAC_5 ~~ FAC_1:FAC_5            18.363 0.000     NA     NA   18.363
10       FAC_3 ~1                        -0.368 1.003 -0.367  0.713   -2.419
11       FAC_1 ~1                         3.391 0.000     NA     NA    3.391
12 FAC_1:FAC_5 ~1                        11.502 0.000     NA     NA   11.502
   ci.upper
1     1.466
2     1.136
3     0.015
4     3.451
5     0.539
6     0.764
7     0.946
8     3.512
9    18.363
10    1.881
11    3.391
12   11.502
#调节效果绘图(Simple Slope Plot)

#1)建立含交互项的 lm 模型(与 lavaan 结果一致)
mod_int.2 <- lm(FAC_3 ~ FAC_1 * FAC_5, data = mydata)

#2)计算调节变量FAC5的mean +sd 
fac_5_mean <- mean(mydata$FAC_5, na.rm = TRUE)
fac_5_sd   <- sd(mydata$FAC_5, na.rm = TRUE)

#3)Simple Slope Plot:
#以 FAC5_ 高、均值、低分组呈现 FAC_1->FAC_3的不同斜率图
library(interactions)
interact_plot(mod_int.2,
              pred = FAC_1,
              modx = FAC_5,
              modx.values = c(fac_5_mean - fac_5_sd,
                              fac_5_mean,
                              fac_5_mean + fac_5_sd),
              x.label = "感知开放性(FAC1)",
              y.label = "情感收益(FAC3)",
              legend.main = "AI素养(FAC5)",
              modx.labels = c("低(-1 SD)", 
                              "均值", 
                              "高(+1 SD)"))

#4) Johnson-NeymanPlot:
# 调节变量FAC_5不同水平下,FAC_1->FAC_3斜率估计+统计检验+JOHNSON-NEYMAN plot

#FAC_1->FAC_3斜率估计+统计检验+JOHNSON-NEYMAN plot
sim_slopes(mod_int.2,
           pred = FAC_1,
           modx = FAC_5,
           jnplot = T)
JOHNSON-NEYMAN INTERVAL

When FAC_5 is OUTSIDE the interval [4.35, 44.01], the slope of FAC_1 is p <
.05.

Note: The range of observed values of FAC_5 is [1.00, 5.00]

SIMPLE SLOPES ANALYSIS

Slope of FAC_1 when FAC_5 = 2.697326 (- 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.49   0.08     6.56   0.00

Slope of FAC_1 when FAC_5 = 3.354687 (Mean): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.38   0.06     6.27   0.00

Slope of FAC_1 when FAC_5 = 4.012049 (+ 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.27   0.09     3.14   0.00
#JOHNSON-NEYMAN plot +呈现临界数值
jn2 <- johnson_neyman(mod_int.2, 
                      pred = FAC_1, 
                      modx = FAC_5)
  
jn2$plot +
  annotate("text",
           x = jn2$bounds[1],
           y = 0.5,
           label = paste0("临界值\nFAC_5 = ", 
                          round(jn2$bounds[1], 2)),
           hjust = -0.1,
           color = "red",
           size = 5)

在本样本中,只有当 AI 素养(FAC_5)低于 4.35 时,感知开放性(FAC_1)对情绪收益性(FAC_3)才有显著正向影响。高于 4.35 后调节效果消失。

但实际上 FAC_5 = 4.35 已接近量表上限(5分),绝大多数受访者的 FAC_1→FAC_3 影响仍显著。

9.3 FAC_5 在FAC_1 与FAC_4之间,扮演调节作用

library(lavaan)
pmacroModel(1) #一个调节变量

# 带变量名称的调节模型路径图
labels <- list(X = "FAC_1", Y = "FAC_4", W = "FAC_5")
pmacroModel(1, labels = labels)

statisticalDiagram(1, labels = labels)

#模型建立
model.3 <- '
  FAC_4 ~ b1*FAC_1 + b2*FAC_5 + b3*FAC_1:FAC_5
  FAC_5 ~ FAC_5.mean*1
  FAC_5 ~~ FAC_5.var*FAC_5
'

#模型参数估计
fit3 <- sem(model = model.3,
        data = mydata,
        se = 'bootstrap',
        bootstrap = 1000,
        missing = 'pairwise') 

#摘要模型估计值(方法1)
summary(fit3,
        fit.measures = TRUE,  
        standardize = TRUE, 
        rsquare = TRUE)
lavaan 0.6-21 ended normally after 9 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         7

  Number of observations                           192
  Number of missing patterns                         1

Model Test User Model:
                                                      
  Test statistic                               460.791
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               521.578
  Degrees of freedom                                 5
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.112
  Tucker-Lewis Index (TLI)                      -1.220

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -424.475
  Loglikelihood unrestricted model (H1)       -194.079
                                                      
  Akaike (AIC)                                 862.949
  Bayesian (BIC)                               885.752
  Sample-size adjusted Bayesian (SABIC)        863.578

Root Mean Square Error of Approximation:

  RMSEA                                          1.093
  90 Percent confidence interval - lower         1.010
  90 Percent confidence interval - upper         1.178
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.393

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  FAC_4 ~                                                               
    FAC_1     (b1)    1.147    0.301    3.806    0.000    1.147    0.829
    FAC_5     (b2)    1.329    0.320    4.146    0.000    1.329    0.648
    FAC_1:FAC (b3)   -0.257    0.086   -2.985    0.003   -0.257   -0.819

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    3.355    0.047   70.983    0.000    3.355    5.117
   .FAC_4            -1.638    1.102   -1.486    0.137   -1.638   -1.218

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    FAC_5   (FAC_)    0.430    0.050    8.629    0.000    0.430    1.000
   .FAC_4             0.664    0.087    7.644    0.000    0.664    0.367

R-Square:
                   Estimate
    FAC_4             0.633
#摘要模型估计值(方法2)
parameterEstimates(fit3,
                   boot.ci.type = 'bca.simple',
                   level = .95,
                   ci = TRUE,
                   standardized = FALSE)
           lhs op         rhs      label    est    se      z pvalue ci.lower
1        FAC_4  ~       FAC_1         b1  1.147 0.301  3.806  0.000    0.586
2        FAC_4  ~       FAC_5         b2  1.329 0.320  4.146  0.000    0.792
3        FAC_4  ~ FAC_1:FAC_5         b3 -0.257 0.086 -2.985  0.003   -0.432
4        FAC_5 ~1             FAC_5.mean  3.355 0.047 70.983  0.000    3.259
5        FAC_5 ~~       FAC_5  FAC_5.var  0.430 0.050  8.629  0.000    0.346
6        FAC_4 ~~       FAC_4             0.664 0.087  7.644  0.000    0.514
7        FAC_1 ~~       FAC_1             0.946 0.000     NA     NA    0.946
8        FAC_1 ~~ FAC_1:FAC_5             3.512 0.000     NA     NA    3.512
9  FAC_1:FAC_5 ~~ FAC_1:FAC_5            18.363 0.000     NA     NA   18.363
10       FAC_4 ~1                        -1.638 1.102 -1.486  0.137   -4.001
11       FAC_1 ~1                         3.391 0.000     NA     NA    3.391
12 FAC_1:FAC_5 ~1                        11.502 0.000     NA     NA   11.502
   ci.upper
1     1.750
2     1.985
3    -0.111
4     3.446
5     0.545
6     0.852
7     0.946
8     3.512
9    18.363
10    0.274
11    3.391
12   11.502
#调节效果绘图(Simple Slope Plot)

#1)建立含交互项的 lm 模型(与 lavaan 结果一致)
mod_int.3 <- lm(FAC_4 ~ FAC_1 * FAC_5, data = mydata)

#2)计算调节变量FAC5的mean +sd 
fac_5_mean <- mean(mydata$FAC_5, na.rm = TRUE)
fac_5_sd   <- sd(mydata$FAC_5, na.rm = TRUE)

#3)Simple Slope Plot:
#以 FAC_5 高、均值、低分组呈现 FAC_1->FAC_4的不同斜率图
library(interactions)
interact_plot(mod_int.3,
              pred = FAC_1,
              modx = FAC_5,
              modx.values = c(fac_5_mean - fac_5_sd,
                              fac_5_mean,
                              fac_5_mean + fac_5_sd),
              x.label = "感知开放性(FAC_1)",
              y.label = "持续使用意愿(FAC_4)",
              legend.main = "AI素养(FAC_5)",
              modx.labels = c("低(-1 SD)", 
                              "均值", 
                              "高(+1 SD)"))

#4) Johnson-NeymanPlot:
# 调节变量FAC_5不同水平下,FAC_1->FAC_4斜率估计+统计检验+JOHNSON-NEYMAN plot

#FAC_1->FAC_4斜率估计+统计检验+JOHNSON-NEYMAN plot
sim_slopes(mod_int.3,
           pred = FAC_1,
           modx = FAC_5,
           jnplot = T)
JOHNSON-NEYMAN INTERVAL

When FAC_5 is OUTSIDE the interval [3.85, 6.77], the slope of FAC_1 is p <
.05.

Note: The range of observed values of FAC_5 is [1.00, 5.00]

SIMPLE SLOPES ANALYSIS

Slope of FAC_1 when FAC_5 = 2.697326 (- 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.45   0.08     5.83   0.00

Slope of FAC_1 when FAC_5 = 3.354687 (Mean): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.28   0.06     4.51   0.00

Slope of FAC_1 when FAC_5 = 4.012049 (+ 1 SD): 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  0.12   0.09     1.29   0.20
#JOHNSON-NEYMAN plot +呈现临界数值
jn3 <- johnson_neyman(mod_int.3, 
                      pred = FAC_1, 
                      modx = FAC_5)
  
jn3$plot +
  annotate("text",
           x = jn3$bounds[1],
           y = 0.5,
           label = paste0("临界值\nFAC_5 = ", 
                          round(jn3$bounds[1], 2)),
           hjust = -0.1,
           color = "red",
           size = 5)

在本样本中,只有当 AI 素养(FAC_5)低于 3.85 时,感知开放性(FAC_1)对持续使用意愿(FAC_4)才有显著正向影响。高于 3.85 后调节效果消失。

10 调节的中介效果

10.1 呈现示意模型图与统计参数图

library(processR)
library(lavaan) 
library(mediation) 
载入需要的程序包:MASS

载入程序包:'MASS'
The following object is masked from 'package:dplyr':

    select
载入需要的程序包:Matrix
载入需要的程序包:mvtnorm

载入程序包:'mvtnorm'
The following object is masked from 'package:processR':

    standardize
载入需要的程序包:sandwich
Registered S3 method overwritten by 'lme4':
  method           from
  na.action.merMod car 
mediation: Causal Mediation Analysis
Version: 4.5.1

载入程序包:'mediation'
The following object is masked from 'package:psych':

    mediate
pmacroModel(8)  # 调节的中介模型,模型示意图

statisticalDiagram(8) #调节的中介模型 统计参数图

10.2 将实际分析变量名称,代入到模型

labels = list(X="FAC_1",M="FAC_2",Y="FAC_4",W="FAC_5") 
pmacroModel(8,labels=labels) 

statisticalDiagram(8,labels=labels )

10.3 呈現完整的模型方程式(processR::tripleEquation( ) )

moderator = list(name = "FAC_5", site = list(c("a","c"))) 
library(processR) 
model =  tripleEquation(X = "FAC_1", M = "FAC_2",Y = "FAC_4", 
                        moderator = moderator)

cat(model)
FAC_2~a1*FAC_1+a2*FAC_5+a3*FAC_1:FAC_5
FAC_4~c1*FAC_1+c2*FAC_5+c3*FAC_1:FAC_5+b*FAC_2
FAC_5 ~ FAC_5.mean*1
FAC_5 ~~ FAC_5.var*FAC_5
CE.XonM :=a1+a3*FAC_5.mean
indirect :=(a1+a3*FAC_5.mean)*(b)
index.mod.med :=a3*b
direct :=c1+c3*FAC_5.mean
total := direct + indirect
prop.mediated := indirect / total
CE.XonM.below :=a1+a3*(FAC_5.mean-sqrt(FAC_5.var))
indirect.below :=(a1+a3*(FAC_5.mean-sqrt(FAC_5.var)))*(b)
CE.XonM.above :=a1+a3*(FAC_5.mean+sqrt(FAC_5.var))
indirect.above :=(a1+a3*(FAC_5.mean+sqrt(FAC_5.var)))*(b)
direct.below:=c1+c3*(FAC_5.mean-sqrt(FAC_5.var))
direct.above:=c1+c3*(FAC_5.mean+sqrt(FAC_5.var))
total.below := direct.below + indirect.below
total.above := direct.above + indirect.above
prop.mediated.below := indirect.below / total.below
prop.mediated.above := indirect.above / total.above

10.4 呈现模型参数估计值(lavaan::sem( ))

library(lavaan) 
semfit = sem(model = model,data = mydata)  #模型:model; 数据名: data
summary(semfit) #呈现模型参数估计值(a1, a2, a3, c1,c2,c3, b)
lavaan 0.6-21 ended normally after 20 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        13

  Number of observations                           192

Model Test User Model:
                                                      
  Test statistic                               460.791
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  FAC_2 ~                                             
    FAC_1     (a1)    0.955    0.089   10.778    0.000
    FAC_5     (a2)    1.085    0.071   15.331    0.000
    FAC_1:FAC (a3)   -0.217    0.020  -10.808    0.000
  FAC_4 ~                                             
    FAC_1     (c1)    0.480    0.119    4.040    0.000
    FAC_5     (c2)    0.571    0.112    5.116    0.000
    FAC_1:FAC (c3)   -0.105    0.027   -3.904    0.000
    FAC_2      (b)    0.698    0.076    9.149    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
    FAC_5   (FAC_)    3.355    0.047   70.897    0.000
   .FAC_2            -0.543    0.292   -1.862    0.063
   .FAC_4            -1.259    0.311   -4.044    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    FAC_5   (FAC_)    0.430    0.044    9.798    0.000
   .FAC_2             0.413    0.042    9.798    0.000
   .FAC_4             0.462    0.047    9.798    0.000

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)
    CE.XonM           0.226    0.049    4.580    0.000
    indirect          0.158    0.039    4.095    0.000
    index.mod.med    -0.152    0.022   -6.983    0.000
    direct            0.126    0.054    2.336    0.019
    total             0.284    0.062    4.558    0.000
    prop.mediated     0.555    0.128    4.334    0.000
    CE.XonM.below     0.368    0.053    6.901    0.000
    indirect.below    0.257    0.047    5.509    0.000
    CE.XonM.above     0.083    0.050    1.678    0.093
    indirect.above    0.058    0.035    1.651    0.099
    direct.below      0.195    0.062    3.154    0.002
    direct.above      0.057    0.052    1.111    0.267
    total.below       0.453    0.067    6.714    0.000
    total.above       0.116    0.063    1.843    0.065
    prop.medtd.blw    0.568    0.099    5.741    0.000
    prop.meditd.bv    0.504    0.270    1.864    0.062

10.5 从模型中提取参数估计值 (processR::estimatesTable)

library(processR) 
estimatesTable(semfit) #提取参数估计值 
  Variables  Predictors label     B   SE      z       p    β
1     FAC_2       FAC_1    a1  0.96 0.09  10.78 < 0.001  0.85
2     FAC_2       FAC_5    a2  1.08 0.07  15.33 < 0.001  0.65
3     FAC_2 FAC_1:FAC_5    a3 -0.22 0.02 -10.81 < 0.001 -0.85
4     FAC_4       FAC_1    c1  0.48 0.12   4.04 < 0.001  0.35
5     FAC_4       FAC_5    c2  0.57 0.11   5.12 < 0.001  0.28
6     FAC_4 FAC_1:FAC_5    c3 -0.11 0.03  -3.90 < 0.001 -0.34
7     FAC_4       FAC_2     b  0.70 0.08   9.15 < 0.001  0.57
estimatesTable2(semfit,vanilla = TRUE) #以三线表形式,呈现参数估计值 (这是我们要的)

Variables

Predictors

label

B

SE

z

p

β

FAC_2

FAC_1

a1

0.955

0.089

10.778

< 0.001

0.851

FAC_2

FAC_5

a2

1.085

0.071

15.331

< 0.001

0.652

FAC_2

FAC_1:FAC_5

a3

-0.217

0.020

-10.808

< 0.001

-0.853

FAC_4

FAC_1

c1

0.480

0.119

4.040

< 0.001

0.347

FAC_4

FAC_5

c2

0.571

0.112

5.116

< 0.001

0.278

FAC_4

FAC_1:FAC_5

c3

-0.105

0.027

-3.904

< 0.001

-0.335

FAC_4

FAC_2

b

0.698

0.076

9.149

< 0.001

0.567

#将参数估计值,带入到模型,统计参数图(这是我们要的)
library(processR) 
statisticalDiagram(8,labels = labels,fit = semfit,whatLabel ="est")

11 用回归的方式计算中介效果的调节效应(另一种方法)

library(processR)
#make regression equations for moderator and dependent variables.
equations = regEquation(X = "FAC_1", M = "FAC_2",Y = "FAC_4",
                        moderator = moderator)
cat(equations) 
FAC_2 ~ FAC_1
FAC_4 ~  FAC_1+FAC_2+FAC_1*FAC_5
#FAC2 ~ FAC1
#FAC4 ~  FAC1 + FAC2 + FAC1 * FAC5
#First, use moderator as a dependent variable.
eq  = unlist(strsplit(equations,"\n"))
fit_lm = lapply(1:2,function(i) { lm(as.formula(eq[i]),data = mydata) })
summary(fit_lm[[1]]) #FAC_1->FAC_2的参数估计(直接效果)

Call:
lm(formula = as.formula(eq[i]), data = mydata)

Residuals:
     Min       1Q   Median       3Q      Max 
-2.50831 -0.34818  0.08617  0.49415  1.46963 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.83589    0.18332  15.469  < 2e-16 ***
FAC_1        0.29448    0.05197   5.666 5.34e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.7003 on 190 degrees of freedom
Multiple R-squared:  0.1446,    Adjusted R-squared:  0.1401 
F-statistic: 32.11 on 1 and 190 DF,  p-value: 5.344e-08
#second, regression model uses dependent variable.
summary(fit_lm[[2]]) #FAC_1,FAC_2, FAC_5, FAC_1*FAC_5->FAC_4的参数估计(直接效果)

Call:
lm(formula = as.formula(eq[i]), data = mydata)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.2012 -0.2895  0.1240  0.3784  1.7990 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.25906    0.82332  -1.529   0.1279    
FAC_1        0.47963    0.24524   1.956   0.0520 .  
FAC_2        0.69826    0.07733   9.029   <2e-16 ***
FAC_5        0.57102    0.26536   2.152   0.0327 *  
FAC_1:FAC_5 -0.10530    0.07209  -1.461   0.1458    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6889 on 187 degrees of freedom
Multiple R-squared:  0.4926,    Adjusted R-squared:  0.4817 
F-statistic: 45.38 on 4 and 187 DF,  p-value: < 2.2e-16
library(processR) 
x = modelsSummary(fit_lm,labels = labels) 
modelsSummaryTable(x) #模型的统计参数的三线表形式 (这是我们要的)

Consequent

FAC_2(M)

FAC_4(Y)

Antecedent

Coef

SE

t

p

Coef

SE

t

p

FAC_1(X)

a

0.294

0.052

5.666

<.001

c'1

0.480

0.245

1.956

.052

FAC_2(M)

b

0.698

0.077

9.029

<.001

FAC_5(W)

c'2

0.571

0.265

2.152

.033

FAC_1:FAC_5(X:W)

c'3

-0.105

0.072

-1.461

.146

Constant

iM

2.836

0.183

15.469

<.001

iY

-1.259

0.823

-1.529

.128

Observations

192

192

R2

0.145

0.493

Adjusted R2

0.140

0.482

Residual SE

0.700 ( df = 190)

0.689 ( df = 187)

F statistic

F(1,190) = 32.106, p < .001

F(4,187) = 45.385, p < .001

11.1 Conditional direct and indirect effects

library(processR)
x2 = modmedSummary(semfit,mod = "FAC_5") #FAC_5:调节效果
#呈现调节变量FAC_5在mean-1sd, mean, mean+1sd条件下的
# indirect effect+ direct effect
modmedSummaryTable(x2) #(这是我们要的)

Indirect Effect
(a1+a3*W)*(b)

Direct Effect
c1+c3*W

FAC_5(W)

estimate

95% Bootstrap CI

estimate

95% Bootstrap CI

2.699

0.257

(0.166 to 0.349)

0.195

(0.074 to 0.317)

3.355

0.158

(0.082 to 0.233)

0.126

(0.020 to 0.232)

4.010

0.058

(-0.011 to 0.127)

0.057

(-0.044 to 0.158)

boot.ci.type = perc

#Plots for conditional direct and indirect effects 
library(processR)
conditionalEffectPlot(semfit,data = mydata,mod = "FAC_5")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ℹ The deprecated feature was likely used in the processR package.
  Please report the issue at <https://github.com/cardiomoon/processR/issues>.
Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
of ggplot2 3.3.4.
ℹ The deprecated feature was likely used in the processR package.
  Please report the issue at <https://github.com/cardiomoon/processR/issues>.

图形解读:

  1. 当调节变量的数值愈大,如果中介效果线呈水平线,则”不存在”调节的中介效应
  2. 当调节变量的数值愈大,如果中介效果线呈左下至右上的斜线,,则”存在”调节的中介效应(正向增强调节:调节变量的数值愈大,中介效果愈大)
  3. 当调节变量的数值愈大,如果中介效果线呈左上至右下的斜线,则”存在”调节的中介效应(负向抑制调节:调节变量的数值愈大,中介效果愈小)

12 Index of Moderated Mediation(调节中介效应指数)

调节中介效应指数(Index of Moderated Mediation,IMM)由 Hayes (2015) 提出,用于检验间接效果是否随调节变量的变化而系统性改变。

计算公式(Model 8):

\[\text{IMM} = a_3 \times b\]

  • \(a_3\):交互项(FAC_1 × FAC_5 → FAC_2)的系数,即调节变量对 a 路径的影响
  • \(b\):FAC_2 → FAC_4 的系数

若 IMM 的 95% Bootstrap CI 不包含 0,则调节的中介效应成立。

# 用 bootstrap 估计 IMM 及其 95% BCa CI
library(lavaan)
set.seed(2025)
semfit_boot <- sem(model = model,
                   data = mydata,
                   se = "bootstrap",
                   bootstrap = 1000)
Warning: lavaan->lav_model_vcov_se():  
   The following boostrapped defined parameters have a high (>5) ratio of 
   standard deviation to median absolute deviation: prop.mediated.above. 
   P-values and confidence intervals may not match.
# 提取 index of moderated mediation
parameterEstimates(semfit_boot,
                   boot.ci.type = "bca.simple",
                   level = .95,
                   ci = TRUE) |>
  subset(label == "index.mod.med")
             lhs op  rhs         label    est    se      z pvalue ci.lower
21 index.mod.med := a3*b index.mod.med -0.152 0.053 -2.846  0.004   -0.274
   ci.upper
21   -0.058

结果:IMM = -0.152,95% CI [-0.274, -0.058],不包含 0,说明调节的中介效应显著成立。

即:随着 AI 素养(FAC_5)提高,感知开放性(FAC_1)通过实用收益(FAC_2)影响持续使用意愿(FAC_4)的间接效果显著减弱

附记:

  1. 直接看processR Shiny App产生的结果即可

  2. processR的结果=SPSS PROCESS(indirect effect & direct effect,controlling Mean-1sd, Mean, Mean+1sd)

  3. processR 本身沒有 Index of moderated mediation,但可透过 lavaan::sem() + bootstrap,在模型中定义 index.mod.med := a3*b(由 tripleEquation() 自动生成),即可得到与 SPSS PROCESS 相同的 IMM 及其 Bootstrap CI。

  4. SPSS PROCESS 與 R(lavaan bootstrap)均可計算 Index of moderated mediation + CI,用以准确判断间接效果是否因调节变量水准不同而有显著差异。

13 输出结果手工计算

#1) 当FAC_5(调节变量w)=mean时
print(fac_5_mean) #3.354687
[1] 3.354687
#直接效果
#FAC_1->FAC_4的Direct Effect=c1+c3*mean
#c1:FAC_1->FAC_4 的beta(0.48)
#c3: FAC_1*FAC_5->FAC4 的beta(-0.105)
#FAC_5=mean=3.354687

DE.w.mean <- 0.48 + (-0.105)*3.354687
DE.w.mean #0.1277579近似0.126
[1] 0.1277579
#间接效果
##FAC_1->FAC_4的Indirect Effect =(a1+a3*mean)*b
#a1:FAC_1->FAC_2的beta(0.955)
#a3:FAC_1*FAC_5->FAC_2 的beta(-0.217)
#FAC_5=mean=3.354687
#b=FAC_2->FAC_4的beta(0.698)

IE.w.mean <- (0.955 + (-0.217)*3.354687) * 0.698  
IE.w.mean #0.158469=0.158
[1] 0.158469
############
#2)当FAC5(调节变量w)=mean-1SD时
print(fac_5_mean - fac_5_sd) #2.697326
[1] 2.697326
#直接效果
#FAC_1->FAC_4的Direct Effect=c1+c3*(mean-1sd)
#c1:FAC_1->FAC_4 的beta(0.48)
#c3: FAC_1*FAC_5->FAC_4 的beta(-0.105)
#FAC_5=(mean-sd)=2.697326

DE.w.mean_lower <- 0.48 + (-0.105)*2.697326
DE.w.mean_lower # 0.1967808 近似 0.195
[1] 0.1967808
#间接效果
##FAC_1->FAC_4的Indirect Effect =(a1+a3*(mean-1sd))*b
#a1:FAC_1->FAC_2的beta(0.955)
#a3:FAC_1*FAC_5->FAC_2 的beta(-0.217)
#FAC_5=mean-sd=2.697326
#b=FAC_2->FAC_4的beta(0.698)

IE.w.mean_lower <- (0.955 + (-0.217)*2.697326) * 0.698  
IE.w.mean_lower #0.2580368 近似0.257
[1] 0.2580368
############
#3)当FAC5(调节变量w)=mean+1SD时
print(fac_5_mean + fac_5_sd) #4.012049
[1] 4.012049
#直接效果
#FAC_1->FAC_4的Direct Effect=c1+c3*(mean+1sd)
#c1:FAC_1->FAC_4 的beta(0.48)
#c3: FAC_1*FAC_5->FAC_4 的beta(-0.105)
#FAC_5=(mean+sd)=4.012049

DE.w.mean_upper <- 0.48 + (-0.105)*4.012049
DE.w.mean_upper # 0.05873485 近似 0.057
[1] 0.05873485
#间接效果
##FAC_1->FAC_4的Indirect Effect =(a1+a3*(mean+1sd))*b
#a1:FAC_1->FAC_2的beta(0.955)
#a3:FAC_1*FAC_5->FAC_2 的beta(-0.217)
#FAC_5=mean+sd=4.012049
#b=FAC_2->FAC_4的beta(0.698)

IE.w.mean_upper <- (0.955 + (-0.217)*4.012049) * 0.698  
IE.w.mean_upper  #0.05890099 = 0.058
[1] 0.05890099

参考文献

Hayes, A. F. (2015). An Index and Test of Linear Moderated Mediation. Multivariate Behavioral Research, (50), 1~22. https://doi.org/10.1080/00273171.2014.962683
|