forked from jrnold/bugs-examples-in-stan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflorida.Rmd
42 lines (36 loc) · 1.53 KB
/
florida.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Florida: Learning About an Unknown Proportion from Survey Data {#florida}
```{r florida_setup,message=FALSE,cache=FALSE}
library("tidyverse")
library("rstan")
```
In this example, beliefs about an unknown proportion are updated from new survey data.
The particular example is using survey update beliefs about support for Bush in Florida in the 2000 presidential election campaign [@Jackman2004a].[^florida-src]
```{r florida_mod,results='hide',cache.extra=tools::md5sum("stan/florida.stan")}
florida_mod <- stan_model("stan/florida.stan")
```
```{r echo=FALSE,cache=FALSE,results='asis'}
florida_mod
```
The prior polls had a mean of 49.1% in support for Bush, with a standard deviation of 2.2%.
The new poll shows 55% support for Bush, with a standard deviation of 2.2%.
```{r florida_data}
florida_data <- list(
mu_mean = 49.1,
mu_sd = 2.2,
y_sd = 2.2,
y = 55
)
```
```{r florida_fit,results='hide'}
florida_fit <- sampling(florida_mod, data = florida_data)
```
```{r}
florida_fit
```
```{r include=FALSE}
post_mean <- round(summary(florida_fit)$summary["mu", "mean"], 1)
post_2.5 <- round(summary(florida_fit)$summary["mu", "2.5%"], 1)
post_97.5 <- round(summary(florida_fit)$summary["mu", "97.5%"], 1)
```
After observing the new poll, the mean for the posterior is `r post_mean`, with a 95% credible interval of `r post_2.5`--`r post_97.5`.
[^florida-src]: This example is derived from Simon Jackman, "Florida," *BUGS Examples,* 2007-07-24, [URL](https://web-beta.archive.org/web/20070724034219/http://jackman.stanford.edu/mcmc/florida.zip).