0
$\begingroup$

I have a doubt whether the uniformly distributed random generator is the most appropriate to use for simulating biased coin toss.

https://stackoverflow.com/questions/477237/how-do-i-simulate-flip-of-biased-coin-in-python

Let's say a chance of Democrat winning in a state is 0.6. Ok, so I thought at first it makes sense to use uniform..., in infinite number of trials, in 60% occasions the value will be below 0.6 (democrat winning).

However I was also wondering, should I use normal distribution instead?

So let's assign the value (x) = 0 for democrat, and value 1 for republican. In the chart, we can draw a bar whose height is 0.6 on x(0), and another bar 0.4 on x(1).

That makes the expected value (mu) = 0x0.6 + 0x0.4 = 0.4 The std deviation would be: square root of pow(0 - 0.4,2)*0.6 + pow(1-0.4,2)*0.4 = sort(24/100) = 0.49

Now, I execute random.gauss on python:

import random
random.gauss(0.4, 0.49)

I got: 0.9193140340408493

What do I make of that value? Should I interpret it as a win for Republican (under the rule: anything to the right of mean value goes to republican, the rest to democrat) ?

If that's not true, please help me pointing out the flaw in my reasoning, and a pointer to a topic in stats book to fix that.

Thanks in advance, Raka

ADDITION: background: I want to implement spinner similar to the one I see in NYT site: http://www.nytimes.com/newsgraphics/2014/senate-model/ .

The reason I was wondering if we should use normal random is because when I saw the source code of that page, it also uses normal random. Here's a snippet of the source code from that page (it's the click event handler; function named 'click'):

// Compute the national bias.
  var nationalErrorScale = data.parameters.nationalErrorScale,
      nationalBias = normalRandom() * nationalErrorScale,
      localErrorScale = Math.sqrt(1 - nationalErrorScale * nationalErrorScale);

  // For each race,
  race.each(function(race) {

    // Pick one of the potential matchups based on probabilities of each.
    var matchup = race.matchups[bisectCumulative(race.matchups, Math.random())];

    // Compute the local bias.
    var localBias = normalRandom() * localErrorScale;

    race.spinnerResult = matchup.mean + matchup.scale * (localBias + nationalBias) > 0 ? "dem" : "rep";
  });
$\endgroup$

3 Answers 3

1
$\begingroup$

You want to draw from Bernuli(p=0.4), but you draw from Normal(mu=0.4, sigma^2 = 0.24). It seems you are these to be the same because they have the same mean and variance. That is not correct.

Here is a way to construct a Bernuli(p=0.4) from a Normal(mu=0.4, sigma^2 = 0.24): If A has distribution Normal(mu=0.4, sigma^2 = 0.24), then
P(A<= a) = phi( a-0.4)/sqrt(0.24)),
so if a is chosen as a = 0.4 + sqrt(0.24)phi_inverse(0.4) = 0.4 + 0.489897..(-0.2533471) = 0.2758858, then X = (A <= a) satisfies:
P(X=1) = P(A<=a) = 0.4

If A = 0.9193140340408493.., then the corresponding X is 0 (since 0.9193140340408493..>0.2758858..)

There are many other ways of constructing a Bernuli(p=0.4) from a Normal(mu=0.4, sigma^2 = 0.24).

Using a uniform random variable is simpler, because one does not need to use the cumulative distribution function of a normal random variable.

$\endgroup$
1
  • $\begingroup$ Thanks for clarifying the relation and difference between those two concepts (bernoulli trial and normal distribution). I was actually looking for something along that line (didn't know how to express that accurately). $\endgroup$ Commented Aug 6, 2014 at 17:47
2
$\begingroup$

Your proposed computation makes no sense because $0.4$ and $0.6$ represent probabilities, not the value of a random variable. If you are modeling something as a normal distribution with mean $\mu = 0.4$ and standard deviation $0.49$, then you are saying that there is some underlying random process that generates a real number that, loosely speaking, on average tends to be "close" to $0.4$ with a "spread" of $0.49$. Such a distribution would have a significant chance of giving you a number less than $0$ or greater than $1$. If you are modeling realizations of an unknown proportion, such a choice of mean and standard deviation is decidedly not realistic.

This leads to another flaw in your interpretation: the parameter of interest in this case--i.e., the probability of a particular candidate to win an election--is assumed to be known to you. You have some kind of belief or prior evidence to suggest this value. If you wish to simulate outcomes of success/failure, then this is the value you're going to use. In other words, if I give you a coin and tell you that it has a $0.6$ probability of landing heads and $0.4$ probability of landing tails, then your expectation of the outcome from tossing it many times is that out of $n$ trials, approximately $0.6n$ heads and $0.4n$ tails will be observed. Now, you can do some hypothesis testing to determine if my claim about this coin is in fact true--for instance, would you believe me if you tossed the coin $100$ times and had obtained $10$ heads and $90$ tails? Under an appropriate hypothesis test, you could actually quantify the probability that you obtained as extreme a result as this had my claim been true. But as I have noted, this is not germane to simulating the outcomes of individual coin tosses themselves.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer, I know from the start there's a crack in my understanding, I didn't really know what it was. The explanation below about constructing bernoulli out of normal more or less clarify that. I will have to dig again to really understand the relation (and difference) between those two. $\endgroup$ Commented Aug 6, 2014 at 17:47
0
$\begingroup$

Why would you doubt that the uniform is appropriate?

You stated that the Democrat wins 60% of the time. The uniform will give you that (except for sampling error). The normal, as you note, gives a vastly higher number.

The uniform is correct.

$\endgroup$
2
  • $\begingroup$ Hi, the thing is I want to implement a spinner similar to the one I saw on this site [link]nytimes.com/newsgraphics/2014/senate-model[/link], and I saw in the source code it is using normal distribution random generator. Let me edit my original question, adding snippet of the code from the NYT page. $\endgroup$ Commented Aug 6, 2014 at 17:12
  • $\begingroup$ That is a very different question! That is about whether the Republicans will take over the senate, not whether they will win any individual race. $\endgroup$
    – Peter Flom
    Commented Aug 6, 2014 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.