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

为何指定coef_map后modelsummary不显示交互项?

解决modelsummary中coef_map不显示交互项的问题

问题核心

你只在coef_map里定义了p95的交互项映射,但model2的交互项是p05:Financial_Open_Logged(lmer默认交互分隔符是:),model3是p50:Financial_Open_Logged,这些都没被放进映射表,所以会被自动过滤;另外你之前用的×是modelsummary显示时的美化符号,模型内部的交互项名称实际是:分隔的,用×匹配当然无效。

修正后的代码

先确认模型系数的准确名称,再把所有要显示的变量都加入coef_map:

# 先查看各模型的系数名称,确保匹配
coef(model)
coef(model2)
coef(model3)

# 构建完整的coef_map,覆盖所有需要展示的变量
cm <- c(
  '(Intercept)' = 'Intercept',
  'p95' = 'Preferences of the richest 5%',
  'p05' = 'Preferences of the poorest 5%',
  'p50' = 'Preferences of the median',
  'Financial_Open_Logged' = 'Logged Financial Openness',
  'IIP_GDP' = 'International Investment Position',
  'gent' = 'gent', # 可根据需求修改别名
  'loggdpt' = 'loggdpt',
  'growtht' = 'growtht',
  'unempt' = 'unempt',
  # 三个模型的交互项,用lmer默认的:分隔符
  'p95:Financial_Open_Logged' = 'Richest 5% × Logged Financial Openness',
  'p05:Financial_Open_Logged' = 'Poorest 5% × Logged Financial Openness',
  'p50:Financial_Open_Logged' = 'Median × Logged Financial Openness',
  # 批量匹配固定效应项,避免逐个写
  grep('factor(topic)', names(coef(model)), value = TRUE) = 'Topic Fixed Effects',
  grep('factor(wave)', names(coef(model)), value = TRUE) = 'Wave Fixed Effects'
)

# 重新生成表格
modelsummary(models1, vcov = vcov, stars = TRUE, coef_map = cm)

关键提醒

  • coef_map是白名单机制,只有表里列出来的变量才会显示,所以控制变量、固定效应、所有模型的交互项都得加进去。
  • 交互项名称必须和模型输出完全一致:lmer里用*构建交互,实际系数名是:分隔,别用显示用的×去匹配。
  • 如果不需要展示factor(topic)和factor(wave)的单个水平,也可以用coef_omit参数直接过滤,不用在coef_map里写。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 01:28:24