My First Look at RStan for Bayesian Data Analysis

David Angeles
CUNY CSI MTH594 Bayesian Data Analysis
2 min readOct 29, 2019

After reading through this we are left with an interesting task under “Over to You”. Where we are to tackle some of Laplace's’ work. Laplace worked on data pertaining to births in Paris from 1745 to 1770

Given:

  • # Girls born : 241,945
  • # Boys born: 251,527
  • # Total born: 493,472

we are to test as to whether or not 50% was a reasonable estimate for the proportion of girls born.

Using the base outline from this we will setup as follows.

```{stan, output.var="model"}
data {
int<lower=0> N;
int<lower=0,upper=N> S;
}
parameters {
real<lower=0,upper=1> theta;
}
model {
theta ~ beta(1,1);
S ~ binomial(N, theta);
}
```

With the uniform beta distribution as our prior and the binomial distrbution as our model

```{r}fit = sampling(model, data=list(N=493472,S=241945))
# skipped LOTS of printouts here
print(fit, digits=3)
```

we fit our model with N=the total number of births and S= the number of female births between 1745 to 1770

```{r}
quietgg(stan_dens(fit))
```

we reject the the null hypothesis that 50% is a good estimate for female birth rates, since 50% = 0.5 falls out side of our interval (0.489,0.492)

--

--