Randomized response is a method of calculating aggregate statistics without compromising individual privacy.

Use cases

  1. Getting honest responses to sensitive questions
  2. Privacy-preserving analytics


These methods can be used both as algorithms and in-person survey interviews. As such, you can substitute coin flips with random booleans, and picking cards with randomly choosing an option.

Card method

For this method, there are three cards. The cards are shuffled and one of them is picked by the subject. The subject then follows the instruction on the card. The cards are as follows.

  1. Say “Yes”.
  2. Say “No”.
  3. Answer the question truthfully.

Since there is a 2/3 chance that the subject doesn’t even answer the question, they cannot be held responsible for their answer even if it is linked back to them.

In [2]:
def response_cards(rate):
    choices = [True, False, real_response(rate)]
    return random.choice(choices)


Because each subject has a chance to answer the question randomly, the result is slightly biased. To be precise, the probability is skewed by the following function.

f(x) = (2/3)x + (1/3)(1 - x)
In [3]:
plot_rate(response_cards, "Cards")
<Figure size 720x480 with 1 Axes>


In order to de-skew the result, we need to use the inverse of the previous function. How do you find the inverse? No idea, ask Wolfram Alpha.

f^-1(x) = 3x - 1
In [4]:
plot_rate(response_cards, "Cards (corrected)", lambda x: 3*x - 1)
<Figure size 720x480 with 1 Axes>

Coin method

// TODO: Fill this section
In [5]:
def response_coin(rate):
    if flip_coin():
        return flip_coin()
        return real_response(rate)
In [6]:
plot_rate(response_coin, "Coin")
<Figure size 720x480 with 1 Axes>


f(x) = (3/4)x - (1/4)(1 - x)


f^-1(x) = 2x - 0.5
In [7]:
plot_rate(response_coin, "Coin", lambda x: x * 2 - 0.5)
<Figure size 720x480 with 1 Axes>

References and useful links