This notebook presents example code and exercise solutions for Think Bayes.
Copyright 2018 Allen B. Downey
MIT License: https://opensource.org/licenses/MIT
In [1]:
# Configure Jupyter so figures appear in the notebook
%matplotlib inline
# Configure Jupyter to display the assigned value after an assignment
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'
# import classes from thinkbayes2
from thinkbayes2 import Pmf, Suite, Beta
import thinkplot
import numpy as np
Whenever you survey people about sensitive issues, you have to deal with social desirability bias, which is the tendency of people to shade their answers in the direction they think shows them in the most positive light.
One of the ways to improve the quality of the results is to collect responses in indirect ways. For example, here's a clever way one research group estimated the prevalence of atheists.
Another way is randomized response, as described in this presentation or this video.
As an example, suppose you ask 100 people to flip a coin and:
If they get heads, they report YES.
If they get tails, they honestly answer the question "Do you believe in God?"
And suppose you get 80 YESes and 20 NOs.
Estimate the prevalence of believers in the surveyed population (by which, as always, I mean compute a posterior distribution).
How efficient is this method? That is, how does the width of the posterior distribution compare to the distribution you would get if 100 people answered the question honestly?
In [2]:
# Solution goes here
In [3]:
# Solution goes here
In [4]:
# Solution goes here
In [5]:
# Solution goes here
In [6]:
# Solution goes here
In [7]:
# Solution goes here
In [8]:
# Solution goes here
In [9]:
# Solution goes here
In [ ]: