Bayesian analysis example: gender of a random sample of people

20 people are randomly picked off a city street in France. Whether they are male or female is noted on 20 identical pieces of paper, put into a hat and the hat is brought to me. I have not seen these 20 people. I take out five pieces of paper from the hat and read them - three are female. I am then asked to estimate the number of females in the original group of twenty.

I can express my estimate as a confidence distribution of the possible values. I could argue that prior to reading the five names I had no knowledge of the number of people who would be female. Actually, roughly 50% of people are female and so I do have quite a specific prior: = Binomial(20, 50%). ModelRisk has a function that automatically calculates the Binomial probability mass function:

p(q) =VoseBinomialProb(q,20,0.5,0)

The likelihood function relating to sampling five people from the population is hypergeometric, where we know the total population (i.e. M = 20), we know the sample size (n = 5), we know the number observed in the sample with the required property (x = 3) but don't know the number of females D, which we denote q as it is the parameter to be estimated. Thus, we can use the ModelRisk Hypergeometric probability calculation function to calculate the likelihood function:

l(X|q) = VoseHypergeoProb(3,5,q,20)

This model is provided the example model gender.xls.

Figure 1 below shows the resultant posterior distribution, together with the likelihood function and the prior. Here we can see that the prior is very strong and the amount of information imbedded in the likelihood function is small, so the posterior distribution is quite close to the prior.

The posterior distribution is a balance between the prior and likelihood function. Hence, the peak of the posterior distribution now lies somewhere between the peaks of the prior and likelihood function. The effect of the likelihood function is small because the sample is small (a sample of five) and because it is in reasonable agreement with the prior (the prior has a maximum at q = 10, and this value of q also produces one of the highest likelihood function values).

See Also



Monte Carlo simulation in Excel. Learn more


Adding risk and uncertainty to your project schedule. Learn more



For Microsoft Excel

Download your free copy of ModelRisk Basic today. Professional quality risk modeling software and no catches

Download ModelRisk Basic now


For Primavera & Microsoft Project

Download your free copy of Tamara Basic today. Professional quality project risk software and no catches.

Download Tamara Basic now