He got as far as "What's the probability density function that describes the value h after seeing a few outcomes?" but that was two years ago.

- Thread starter AngleWyrm
- Start date

He got as far as "What's the probability density function that describes the value h after seeing a few outcomes?" but that was two years ago.

Edit: I got 57% of values landing in this range, but I could have buggered this a little.

Code:

```
# define grid
p_grid <- seq( from=0 , to=1 , length.out=100 )
# define prior
prior <- rep( 1 , 100 )
# compute likelihood at each value in grid
likelihood <- dbinom( 7 , size=10 , prob=p_grid )
# compute product of likelihood and prior
unstd.posterior <- likelihood * prior
# standardize the posterior, so it sums to 1
posterior <- unstd.posterior / sum(unstd.posterior)
plot( p_grid , posterior , type="b" ,
xlab="probability of Heads" , ylab="posterior probability")
abline(v = c(0.6,0.8), col = "red", lty = 3)
# Calculate the probability
sum(posterior[60:80])
```

So of all the realizations that could have happened, how many times were these within the below range / sum of all possibilities.

View attachment 3956

Edit: I got 57% of values landing in this range, but I could have buggered this a little.

View attachment 3956

Edit: I got 57% of values landing in this range, but I could have buggered this a little.

Code:

```
# define grid
p_grid <- seq( from=0 , to=1 , length.out=100 )
# define prior
prior <- rep( 1 , 100 )
# compute likelihood at each value in grid
likelihood <- dbinom( 7 , size=10 , prob=p_grid )
# compute product of likelihood and prior
unstd.posterior <- likelihood * prior
# standardize the posterior, so it sums to 1
posterior <- unstd.posterior / sum(unstd.posterior)
plot( p_grid , posterior , type="b" ,
xlab="probability of Heads" , ylab="posterior probability")
abline(v = c(0.6,0.8), col = "red", lty = 3)
# Calculate the probability
sum(posterior[60:80])
```

Code:

```
> diff(pbeta(c(.6, .8), 1+7, 1+3))
[1] 0.5425765
```

Code:

```
> p_grid <- seq( from=0 , to=1 , length.out=100 )
> p_grid[60:80]
[1] 0.5959596 0.6060606 0.6161616 0.6262626 0.6363636 0.6464646 0.6565657
[8] 0.6666667 0.6767677 0.6868687 0.6969697 0.7070707 0.7171717 0.7272727
[15] 0.7373737 0.7474747 0.7575758 0.7676768 0.7777778 0.7878788 0.7979798
```

Code:

```
p_grid <- seq( from=0 , to=1 , length.out=1000 )
# define prior
prior <- rep( 1 , 1000 )
# compute likelihood at each value in grid
likelihood <- dbinom( 7 , size=10 , prob=p_grid )
# compute product of likelihood and prior
unstd.posterior <- likelihood * prior
# standardize the posterior, so it sums to 1
posterior <- unstd.posterior / sum(unstd.posterior)
plot( p_grid , posterior , type="b" ,
xlab="probability of Heads" , ylab="posterior probability")
abline(v = c(0.6,0.8), col = "red", lty = 3)
# Calculate the probability
sum(posterior[which(p_grid >= .6 & p_grid <= .8)])
```

Code:

```
> sum(posterior[which(p_grid >= .6 & p_grid <= .8)])
[1] 0.5430052
```

Good point on my use of sum(posterior[60:80]), I had wanted to do it your way but was too lazy and didn't think hard enough to realize a couple values outside the bounds could have snuck in.

What I want to know is at what point can I reasonably declare the box is fair?

For any given number of pulls on the lever how confident can I be the result is drawn from the stated population of 1/2 win 1/2 lose?