Created
October 4, 2018 15:10
-
-
Save benwhalley/a00d1607ee39aac8dff94640b514fd53 to your computer and use it in GitHub Desktop.
example of droopy densities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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