Flip a coin. If it is heads, flip again and answer Yes for heads and No for tails. If the first coin is tails, answer the question: "Have you ever cheated on your spouse?"
Now, what is the probability the person is a cheater given they answered yes?
Flip a coin. If it is heads, flip again and answer Yes for heads and No for tails. If the first coin is tails, answer the question: "Have you ever cheated on your spouse?"
Now, what is the probability the person is a cheater given they answered yes?
Anyway, here is the code below: http://jsfiddle.net/nQ3Gu/
var runs = 1000,
honest_admissions = 0,
automatic_admissions = 0;
function flip() {
return Math.random() < 0.5 ? 'h' : 't';
}
for (var i = 0; i < runs; i++) {
if (flip() == 't') {
honest_admissions++;
} else if (flip() == 'h') {
automatic_admissions++;
}
}
document.write('The "yes" is honest ' + honest_admissions / (honest_admissions + automatic_admissions) + ' of the time.')
2/3 of yeses are honest and 1/3 didn't have to answer the question!I think this is indeterminate. You have to know the ratio of total yesses to total participants.
The real world use-case I was recalling is simpler: flip a coin and answer honestly if it's heads and "yes" if it's tails. Any individual response is non-incriminating, but if N is large enough where you can assume N/2 got heads, you can know the number of "honest cheaters."
I'll label the four outcomes 1Y, 1N, 2Y, 2N. Let X = probability person cheated on spouse.
If I flip heads first, I get yes or no equally. So the first two outcomes are: 1Y(50%) or 1N (50%).
If I flip tails, I answer 2Y (X) or 2N (1-X).
So the distinct pdf is: 1Y (25%) 1N (25%) 2Y (0.5X) 2N (1-0.5X)
And combined, Y = 0.25+0.5X
What am I missing? (Wait, oh, is this a stupid joke about whether they lied about cheating on their spouse? Dammit.)