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

调用stan_betareg报错“Invalid stanfit object produced”的排查求助

stan_betareg初始化失败的排查方向

已确认响应变量PercentLoss取值在(0,1)区间内,且已更新相关包,但运行stan_betareg时出现初始化失败错误,具体信息如下:

运行代码

model <- stan_betareg(
  linformula,
  link = c('logit'),
  data = train,
  model = TRUE,
  x = TRUE,
  y = TRUE,
  contrasts = NULL,
  weights = Insured.Acres,
  QR = TRUE,
  refresh = 0,
  prior = normal(0,2),
  prior_intercept = normal(0,2)
)

模型公式

linformula通过as.formula定义:

PercentLoss ~ LossRatio.11 + ZeroIndemnities.11 + LossRatio.15 + 
    ZeroIndemnities.15 + LossRatio.16 + ZeroIndemnities.16 + 
    LossRatio.41 + ZeroIndemnities.41 + LossRatio.51 + ZeroIndemnities.51 + 
    LossRatio.78 + ZeroIndemnities.78 + LossRatio.81 + ZeroIndemnities.81 + 
    LossRatio.91 + ZeroIndemnities.91 + prec + dday0C + dday10C + 
    dday30C + prec2 + weightCovLevel.84 + totalpolicies | totalpolicies + 
    weightCovLevel.84  

报错信息

[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
[1] "error occurred during calling the sampler; sampling not done"
Error in check_stanfit(stanfit) :
Invalid stanfit object produced please report bug

使用环境

  • R版本:4.2.1
  • rstanarm版本:2.21.3

排查方向

  • 协变量尺度问题:检查协变量是否存在极端值或尺度差异过大(比如部分变量取值范围是0-1,另一部分是1e6级别)。Beta回归对协变量尺度敏感,建议先对所有协变量做标准化(如Z-score转换)后再尝试拟合。
  • 权重变量验证:确认Insured.Acres是否全为正数值,无0或负数;同时检查权重量级是否过大,可能导致初始化时参数值异常。
  • 模型复杂度简化:当前模型包含大量协变量(线性预测部分+精度部分),且启用了QR分解。可先尝试关闭QR分解(QR=FALSE),或拟合仅含少量核心协变量的简单模型,确认能正常运行后再逐步添加变量定位问题。
  • 先验设置调整:当前normal(0,2)先验若搭配未标准化的协变量,可能与参数实际取值范围不匹配。可尝试放宽先验(如normal(0,5)),或改用鲁棒性更强的弱信息先验(如student_t(3,0,10))。
  • 数据质量检查:再次确认训练集train无缺失值(可先用na.omit(train)尝试拟合),排查协变量中的极端异常值(如用箱线图逐个检查变量分布)。
  • 版本兼容性确认:rstanarm 2.21.3属于较旧版本,与R 4.2.1可能存在兼容问题。确认是否安装了适配R 4.2.x的最新rstanarm版本(注意rstanarm需与rstan版本匹配)。
  • 初始化参数调整:尝试添加init_r=0.1参数缩小初始化的随机取值范围,帮助采样器找到合理的初始参数值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 02:30:57