I would like to visualise the shift from the prior to the posterior as data is gathered (for each new data point).
I can visualise both the prior and the posterior:
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)
Created on 2019-05-25 by the reprex package (v0.3.0)
However, I would like to have all the "intermediate" steps (the progressive shift from prior to posterior for each new data point). Is there a way to retrieve that from the model? Thanks!