TensorFlow 上的 Tadpoles:使用 tfprobability 进行分层部分池化

这篇文章首次介绍了使用 tfprobability(TensorFlow Probability (TFP) 的 R 接口)进行 MCMC 建模。我们的示例是一个描述蝌蚪死亡率的多级模型,读者可能从 Richard McElreath 的精彩作品“统计反思”中了解到这一点。

来源:RStudio AI博客

在我们讨论技术细节之前:这篇文章当然是献给 McElreath 的,他写了一本我们所知的最有趣的贝叶斯(或者我们应该说 - 科学?)建模书籍。如果您还没有读过《统计再思考》,并且对建模感兴趣,您肯定想看看。在这篇文章中,我们不会尝试重新讲述这个故事:相反,我们的明确重点是演示如何使用 tfprobability 进行 MCMC。

统计再思考 tfprobability

具体来说,这篇文章分为两部分。第一部分是如何使用 tfd_joint_sequential_distribution 构建模型,然后使用汉密尔顿蒙特卡洛从中抽样的快速概述。此部分可用于快速查找代码,或作为整个过程的简洁模板。第二部分将更详细地介绍多层模型,展示如何提取、后处理和可视化采样以及诊断输出。

tfd_joint_sequential_distribution

Reedfrogs

数据来自重新思考包。

重新思考
'data.frame': 48 obs. 5 个变量中的:$ density :int 10 10 10 10 10 10 10 10 10 10 10 ... $ pred :具有 2 个水平的因子“no”,“pred”:1 1 1 1 1 1 1 1 2 2 ... $ size :具有 2 个水平的因子“big”,“small”:1 1 1 1 2 2 2 2 1 1 ... $ surv :int 9 10 7 10 9 9 10 9 4 9 ... $ propsurv:num 0.9 1 0.7 1 0.9 0.9 1 0.9 0.4 0.9 ...
'data.frame':48 obs。 5 个变量:$ density : int 10 10 10 10 10 10 10 10 10 10 10 ... $ pred : 因子 w/ 2 水平 "no","pred": 1 1 1 1 1 1 1 1 2 2 ... $ size : 因子 w/ 2 水平 "big","small": 1 1 1 1 2 2 2 2 1 1 ... $ surv : int 9 10 7 10 9 9 10 9 4 9 ... $ propsurv: num 0.9 1 0.7 1 0.9 0.9 1 0.9 0.4 0.9 ... density surv variations cutions

使用构建模型tfd_joint_distribution_sequence

tfd_joint_distribution_sequence tfd_joint_distribution_sequence

这是模型规范在 Stan 中的样子:

Stan

这是 tfd_joint_distribution_sequence:

tfd_joint_distribution_sequence ( )