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

使用R语言rstanarm包拟合贝叶斯Cox PH模型时提示找不到stan_surv函数

解决"could not find function 'stan_surv'"错误

错误原因

stan_surv并非rstanarm包中的函数,你混淆了贝叶斯Cox模型的函数名——rstanarm中拟合贝叶斯Cox比例风险模型的正确函数是stan_coxph()。

修正后的代码

# 先确保加载rstanarm包
library(rstanarm)

# 拟合贝叶斯Cox PH模型
bayes_cox <- stan_coxph(Surv(time, status) ~ Sex + Treatment + Stage, data = df, method = "breslow")

额外说明

  • 如果尚未安装rstanarm,先执行安装命令:install.packages("rstanarm")
  • 若你确实需要使用stan_surv函数,该函数属于survivalstan包,需先安装加载此包,但这和你原本想用rstanarm的需求不符,优先推荐使用rstanarm自带的stan_coxph()。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 11:17:09