Skip to content

Instantly share code, notes, and snippets.

@benwhalley
Created October 4, 2018 15:10
Show Gist options
  • Save benwhalley/a00d1607ee39aac8dff94640b514fd53 to your computer and use it in GitHub Desktop.
Save benwhalley/a00d1607ee39aac8dff94640b514fd53 to your computer and use it in GitHub Desktop.
example of droopy densities
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(rstanarm)
library(tidybayes)
m1 <- stan_glm(mpg~wt, data=mtcars, prior_PD = FALSE)
m1.prior <- stan_glm(mpg~wt, data=mtcars, prior_PD = TRUE)
```
```{r}
preds <- add_fitted_samples(m1, newdata=tibble(wt=1))
preds.prior <- add_fitted_samples(m1.prior, newdata=tibble(wt=1))
```
```{r}
both <- bind_rows(preds %>% mutate(dist="posterior"),
preds.prior %>% mutate(dist="prior"))
```
```{r}
both %>%
ggplot(aes(estimate, color=dist)) +
geom_density()
```
```{r}
both %>%
ggplot(aes(estimate, color=dist)) +
geom_density() +
xlim(20,50)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment