rstanarm:可视化/提取证据积累的数据(从后验前移)

时间:2019-05-25 04:24:13

标签: r bayesian stan rstan rstanarm

我想在收集数据时(对于每个新数据点)可视化从后验到后验的变化。

我可以可视化先验和后验:

library(ggplot2)
library(rstanarm)
library(insight)
library(bayestestR)

model <- stan_glm(mpg ~ wt, data = mtcars, chains = 2, iter = 500)

priors <- insight::get_priors(model)
priors <- priors[priors$parameter == "wt", ]

prior <- bayestestR::distribution_normal(n = 500,
                                        mean = priors$location,
                                        sd = priors$adjusted_scale)
prior <- data.frame(x = prior, type = "prior")

posterior <- data.frame(x = insight::get_parameters(model)$wt, type = "posterior")
df <- rbind(prior, posterior)


ggplot(df, aes(x=x, fill=type)) +
  geom_density(alpha=0.5)

reprex package(v0.3.0)于2019-05-25创建

但是,我想进行所有“中间”步骤(每个新数据点从后到前的逐步转换)。有没有办法从模型中检索出来?谢谢!

0 个答案:

没有答案