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

使用marginaleffects包处理mids对象时newdata参数失效问题

使用marginaleffects处理mice插补数据集时,newdata参数报错问题

尝试用marginaleffects::avg_comparisons函数处理通过mice包插补得到的mids对象数据集,不加newdata参数时代码可正常运行,但添加该参数后出现报错。

可正常运行的代码

with(data_imputed, avg_comparisons(my_model, variables = list(Allocation = c("Control", "Intervention")), type = "link"))

添加newdata参数后报错的代码

with(data_imputed, avg_comparisons(my_model, variables = list(Allocation = c("Control", "Intervention")), type = "link", newdata=datagrid(age=50)))

报错信息

Error in evalup(calltmp) :
Unable to compute predicted values with this model. This error can arise when
insight::get_data() is unable to extract the dataset from the model object, or when the
data frame was modified since fitting the model. You can try to supply a different dataset
to the newdata argument.

Error in model.frame.default(delete.response(terms(object, fixed.only = TRUE, : variable
lengths differ (found for 'scale(age)')

补充说明

  • 无论是否使用with()函数,只要添加newdata参数就会出现相同报错
  • 模型拟合代码如下:
with(data_imputed, glmer(reponse_variable ~ scale(age) + Allocation +
   scale(age)*Allocation + (1|RandomEffect), family="binomial",
   control=glmerControl(optimizer="bobyqa",optCtrl = list(maxfun =
   2e5))))
  • 使用的marginaleffects版本为0.25.0
  • 后续将提供最小可复现示例

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 21:22:42