Monday, December 29, 2014

Bayesian Analysis - Different priors

In the previous post, I showed using python to do simulation of coin tossing, and plot the evolution of the posterior pdf changing as the number of tosses increasing (example is grabbed from the book Data analysis).  I used uniform distribution as the prior last time to represent we don't have much idea of the fairness of the coin. In this post, I will use different priors that used in the book to generate the following figure.
The effect of different priors. The blue solid line is the uniform prior we used in the last post, and the red dashed line is beta distribution with alpha and beta taking a value of 0.5, and the green dotted line is also beta distribution with alpha and beta 100. The case for two alternative priors, reflecting slightly different assumptions in the conditioning information I. The 3 numbers on the bottom right are number of heads, number of tails, and total number of tosses. For comparison purpose, I scaled them vertically, so that the maximum value is 1.

The figure above shows 3 different priors, with the red and green lines are beta distribution with different parameters. (The beta distribution is the conjugate prior to the binomial distribution, so it will make the compute easier, as the posterior will also be a beta distribution).

We can see the 3 posterior pdfs are quit different initially, and then gradually converge to the same answer. This makes sense, as when we have few data, our initial beliefs have a large effect on the posterior pdfs. With more and more data comes in, the posterior is then dominated by the likelihood function, and becomes irrelevant of the prior we chose. Also, we can see the blue and red curves are converging very fast, and it takes much more observed data for the green curve to shift to the same result. The reason lies the prior we chose. We can see from the first subplot, the green curve has a relative narrow peak around 0.5, this means that we have a strong belief that the coin is a fair coin, so it need much more observations to change our belief. That is why it takes much longer for the green curve to move to the true answer.

You can download the python script from my github: Qingkai's github

4 comments:

  1. Great, thanks for sharing it. Also, check this out if you are looking for professional website or logo design services:


    Buy Logo

    ReplyDelete
  2. Five weeks ago my boyfriend broke up with me. It all started when i went to summer camp i was trying to contact him but it was not going through. So when I came back from camp I saw him with a young lady kissing in his bed room, I was frustrated and it gave me a sleepless night. I thought he will come back to apologies but he didn't come for almost three week i was really hurt but i thank Dr.Azuka for all he did i met Dr.Azuka during my search at the internet i decided to contact him on his email dr.azukasolutionhome@gmail.com he brought my boyfriend back to me just within 48 hours i am really happy. What’s app contact : +44 7520 636249‬

    ReplyDelete
  3. First I want to tell you Thank you for sharing it with us.
    I am really Happy and impressed to see this blog!
    law essay writing help

    ReplyDelete
  4. DR EMU WHO HELP PEOPLE IN ANY TYPE OF LOTTERY NUMBERS
    It is a very hard situation when playing the lottery and never won, or keep winning low fund not up to 100 bucks, i have been a victim of such a tough life, the biggest fund i have ever won was 100 bucks, and i have been playing lottery for almost 12 years now, things suddenly change the moment i came across a secret online, a testimony of a spell caster called dr emu, who help people in any type of lottery numbers, i was not easily convinced, but i decided to give try, now i am a proud lottery winner with the help of dr emu, i won $1,000.0000.00 and i am making this known to every one out there who have been trying all day to win the lottery, believe me this is the only way to win the lottery.

    Dr Emu can also help you fix this issues

    (1)Ex back.
    (2)Herbal cure & Spiritual healing.
    (3)You want to be promoted in your office.
    (4)Pregnancy spell.
    (5)Win a court case.

    Contact him on email Emutemple@gmail.com
    What's app +2347012841542
    Website Https://emutemple.wordpress.com/
    Https://web.facebook.com/Emu-Temple-104891335203341

    ReplyDelete