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

# Use cases

- Getting honest responses to sensitive questions
- Privacy-preserving analytics

# Methods

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.

- Say “Yes”.
- Say “No”.
- 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.

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

### Skew

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)
```

plot_rate(response_cards, "Cards")

### De-skewing

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
```

plot_rate(response_cards, "Cards (corrected)", lambda x: 3*x - 1)

## Coin method

```
// TODO: Fill this section
```

def response_coin(rate): if flip_coin(): return flip_coin() else: return real_response(rate)

plot_rate(response_coin, "Coin")

### Skew

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

### De-skewing

```
f^-1(x) = 2x - 0.5
```

plot_rate(response_coin, "Coin", lambda x: x * 2 - 0.5)

# References and useful links

- Randomized response on Wikipedia
- Differential privacy on Wikipedia