3

随着数据的收集(对于每个新数据点),我想可视化从先验到后验的转变。

我可以同时想象之前和之后:

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 包(v0.3.0)于 2019 年 5 月 25 日创建

但是,我希望拥有所有“中间”步骤(每个新数据点从之前到后的渐进式转变)。有没有办法从模型中检索它?谢谢!

4

0 回答 0