3

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!

Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
  • 2
    No, but there is a `posterior_vs_prior` [function](http://mc-stan.org/rstanarm/reference/posterior_vs_prior.html) for the influence of the whole dataset. – Ben Goodrich May 25 '19 at 16:01
  • 1
    There is also `loo(..., plot = TRUE)` which gives some indication as to which observations have the most influence. – Ben Goodrich May 26 '19 at 05:39

0 Answers0