You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

runMI()后绘制SEM行动者-伙伴互依模型(APIM)的问题

多重插补APIM模型绘图偏差原因与规范解决方案

一、绘图数值偏差的原因

  1. 参数顺序错位:你手动过滤:=衍生参数后直接赋值,但standardizedsolution()返回的参数顺序和semPlotModel@Pars中的参数顺序并不完全对应,导致估计值被错误分配到路径上,出现偏差。
  2. 指标类型混淆:你用了standardizedsolution()的标准化估计值(est.std),但summary()展示的是未标准化估计值,两者数值本身存在差异,这也是偏差的直接来源。

二、规范绘制lavaan.mi对象的方法

方法1:修正手动匹配逻辑(适配semPlot)

通过参数的lhs-op-rhs键精准匹配,确保估计值赋值正确:

# 1. 提取Rubin合并后的未标准化估计值(与summary输出一致)
est_df <- data.frame(parameterEstimates(sem_model)) %>%
  filter(op != ":=") # 过滤衍生参数

# 2. 为semPlot模型的参数创建匹配键
baseplot <- semPlot::semPlotModel(sem(myapim, data = df))
plot_pars <- baseplot@Pars %>%
  mutate(match_key = paste(lhs, op, rhs, sep = "-"))

# 3. 合并估计值到绘图参数表
est_df <- est_df %>% mutate(match_key = paste(lhs, op, rhs, sep = "-"))
plot_pars <- left_join(plot_pars, est_df[, c("match_key", "est")], by = "match_key")

# 4. 替换参数并绘图
baseplot@Pars$est <- plot_pars$est
semPaths(baseplot, 
         nCharNodes = 0, what = "est",
         fade = FALSE, layout = "tree2", 
         rotation = 2, style = "ram",
         intercepts = FALSE, residuals = FALSE, 
         optimizeLatRes = TRUE, curve = 3.1, nDigits = 3,
         sizeMan = 12, sizeMan2 = 10, 
         label.cex = 1.2, edge.label.position = 0.45, edge.label.cex = 1.5)

方法2:使用tidySEM原生支持(更简便可靠)

tidySEM包原生支持lavaan.mi对象,自动调用Rubin合并后的参数,无需手动处理:

# 安装tidySEM(首次使用)
install.packages("tidySEM")
library(tidySEM)

# 直接绘制多重插补APIM模型的路径图
graph_sem(sem_model, 
          layout = "tree2",
          node_size = 12,
          edge_label_size = 1.5,
          show_residuals = FALSE,
          show_intercepts = FALSE)

内容的提问来源于stack exchange,提问作者jrcalabrese

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 05:45:37