5
$\begingroup$

I'm learning stats, and I've reasoned about this for many days and I'm losing sleep over it.

Say I have a binomial distribution B(k; n, p) simulating a hypothesis p value for some events:

B(14; 41, 0.5)

In R:

dbinom(14, 41, 0.5) #=> 0.016

So in English, this could be said as "the probability of exactly 14 successes in a series of 41 fifty-fifty events is about 1.6%. OK, makes sense (a poor hypothesis).

Now, lets try iterating over different p values using R:

p <- seq(0, 1, by = 0.01)
qplot(
  x = p,
  y = dbinom(14, 41, p)
)

This is clearly starting to form a shape of the probabilities for different probability values:

I understand this is not the "proper" way to do a beta distribution because of the fact that probability is continuous, and this graph needs to be integrated, it doesn't add up to 1, etc.

With that said... it seems the above chart IS perfectly "accurate", because each single value by itself is accurate.

Question 1: how IS the graph above "different" than a proper beta distribution in terms of what they describe in English?

  • Incorrect beta distribution is saying (I think...) "For these 100 exact values, chart the probability (Y) that each probability (X) is correct"
  • Correct beta distribution is saying (I think...) "For all possible values, chart the probability density (Y) that each probability (X) is correct"

Question 2: Are the charts related somehow? Like can they convert between them? It's clear from the incorrect chart I CAN compute a probability of a probability in a non-continuous way, yet in the second chart it appears there's no way I can do this unless I say something like p > 0.49 & p < 0.51). How can both charts be "correct" (to my knowledge) yet in the continous one the probability of choosing that item is 0, and in the non-continous chart I can compute it just fine?

qplot(
  x = p,
  y = dbeta(p, 14, 41)
)

enter image description here

$\endgroup$
  • 1
    $\begingroup$ From Wikipedia: "The binomial distribution and beta distribution are different views of the same model of repeated Bernoulli trials. The binomial distribution is the PMF of k successes given n independent events each with a probability p of success. Mathematically, when α = k + 1 and β = n − k + 1, the beta distribution and the binomial distribution are related by a factor of n + 1" $\endgroup$ – Dave2e Jan 12 at 3:58
  • 2
    $\begingroup$ You are plotting the likelihood function $L(p|x)$, which is not a density in the parameter $p$. $\endgroup$ – Xi'an Jan 12 at 6:58
  • $\begingroup$ The Beta density of $p$ is a Bayesian posterior distribution associated with the prior assumption that $p$ is Uniform distributed. $\endgroup$ – Xi'an Jan 12 at 6:59
  • 1
    $\begingroup$ Your second graph is a duplicate of the first rather than what you get from your dbeta(p, 14, 41) code $\endgroup$ – Henry Jan 12 at 9:00
  • 1
    $\begingroup$ Darn sorry... I didn't realize I put 41 instead of 27. Ugh... $\endgroup$ – Tallboy Jan 13 at 22:58
7
$\begingroup$

The function you have plotted is the kernel of a beta density function (i.e., it is a positive multiple of the beta density). Since you have really just plotted the binomial likelihood function for a particular observed outcome, from a Bayesian perspective your plotted function is proportionate to the posterior density that emerges from using a uniform prior for $p$. In Bayesian modelling terms, what you have illustrated here is that:

$$\underbrace{\text{Beta}(p | 15, 28)}_\text{Posterior} \ \propto \ \underbrace{\text{Bin}(14|41, p)}_\text{Likelihood} \times \underbrace{\text{U}(p|0,1)}_\text{Prior}.$$

(Note also that your last plot just appears to be a repitition of the first plot. Your code for the beta distribution uses the wrong parameters; see the parameterisation of the beta distribution to see why the parameters should be as shown here.) To plot the posterior density in this problem we can use the following R code:

#Plot posterior density
library(ggplot2)
XX <- seq(0, 1, by = 0.001)
DD <- dbeta(XX, shape1 = 15, shape2 = 28)
qplot(XX, DD, geom = 'line') + xlab('p') + ylab('Posterior Density')

enter image description here

$\endgroup$
  • $\begingroup$ Hmm... this is a great answer. Can you explain more what the proper code should be? I actually got this from offline, where they did this: xs <- seq(0,1.0,by=0.01); qplot(xs,dbeta(xs,2*100,3*100),geom="line") + theme_bw(). it looked like this was manually making a sequence for all possible probabilities $\endgroup$ – Tallboy Jan 12 at 17:13
  • $\begingroup$ In the present case you would use qplot(xs, dbeta(xs, shape1 = 15, shape2 = 28), geom = "line") instead. $\endgroup$ – Ben Jan 13 at 21:34
  • $\begingroup$ OOOOOoooooo I didn't even notice that. I thought everyone was saying arg1 was wrong, I didn't even notice that I accidentally put 'all' instead of 'failures'. dang $\endgroup$ – Tallboy Jan 13 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.