{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Think Bayes\n", "\n", "This notebook presents example code and exercise solutions for Think Bayes.\n", "\n", "Copyright 2018 Allen B. Downey\n", "\n", "MIT License: https://opensource.org/licenses/MIT" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Configure Jupyter so figures appear in the notebook\n", "%matplotlib inline\n", "\n", "# Configure Jupyter to display the assigned value after an assignment\n", "%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'\n", "\n", "# import classes from thinkbayes2\n", "from thinkbayes2 import Hist, Pmf, Suite" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Exercise:** This exercise is from one of my favorite books, David MacKay's \"Information Theory, Inference, and Learning Algorithms\":\n", "\n", "> Elvis Presley had a twin brother who died at birth. What is the probability that Elvis was an identical twin?\"\n", " \n", "To answer this one, you need some background information: According to the Wikipedia article on twins: \"Twins are estimated to be approximately 1.9% of the world population, with monozygotic twins making up 0.2% of the total---and 8% of all twins.''" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Pmf({'fraternal': 0.92, 'identical': 0.08})" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Solution\n", "\n", "# Here's a Pmf with the prior probability that Elvis \n", "# was an identical twin (taking the fact that he was a \n", "# twin as background information)\n", "\n", "pmf = Pmf(dict(fraternal=0.92, identical=0.08))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fraternal 0.8518518518518517\n", "identical 0.14814814814814814\n" ] } ], "source": [ "# Solution\n", "\n", "# And here's the update. The data is that the other twin\n", "# was also male, which has likelihood 1 if they were identical\n", "# and only 0.5 if they were fraternal.\n", "\n", "pmf['fraternal'] *= 0.5\n", "pmf['identical'] *= 1\n", "pmf.Normalize()\n", "pmf.Print()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }