Sunday, September 22, 2013

Theoretical vs. Experimental Probability

Here was the problem on my last homework assignment in the Probability Theory class I'm taking:
Three identical fair coins are thrown simultaneously until all three show the same face.  What is the probability that they are thrown more than three times?
When three coins are tossed there are 8 possible outcomes, two of which are (HHH and TTT) have all three coins showing the same face.  Therefore, the probability of getting all three coins with the same face is 2 out of 8, or 1/4.

I solved this problem two different ways.  First, I used a formula derived in an earlier problem and calculated P(X>3) directly and got ~.4219.  Wanting to check this, I next used the "brute force and ignorance" method and calculated P(X>3) = 1-[P(X=1) + P(X=2) + P(X=3)] and again got an answer of ~.4219.

The math department chair at my school enjoys programming so I asked him to program this, run it 10,000 times, and see how the experimental probability matches up with the theoretical probability.  Here is the text of the email I just received from him:
I just finished coding the program to test your coin flipping problem. The program considers 10,000 test cases. I ran it 10 times with the following results. Also, I've included the program if you want to see what it looks like. I wrote it in Python.
Pretty good results. I'd say your answer is correct.

i = 0
s = 0
def role():
x = int(np.random.random_sample() + .5)
y = int(np.random.random_sample() + .5)
z = int(np.random.random_sample() + .5)
return (x,y,z)

while i < 10000:
    t = True
    c = 0
    while t == True:
        r = role()
        c += 1
        if r == (1,1,1) or r == (0,0,0):
            t = False
            if c > 3:
                s += 1
    i += 1
p = s / 10000.00
print p


jerry Doctor said...

Probability they match is 1/4 so probability they don't is 3/4. Three trials so 3/4 x 3/4 x 3/4 = 27/64.

maxutils said...

Nerd. ;)

Anonymous said...

Hi, this is totally off topic, but I could use some advice. My sophomore daughter is taking Algebra II. She did mediocre on the first exam. I would like to get the test back from the teacher so that my dd could go over the material, see what she did wrong and learn/relearn the material she clearly didn't understand the first time.

The teacher doesn't return tests. Any suggestion on how my DD could learn the material with getting the test back?

Darren said...

What is a DD?

Darren said...

jerry Doctor, that's essentially what I did the first time.

Anonymous: I understand the issue of not returning tests. However, a student should definitely be told what topics he/she did well on and which ones he/she did *not* do well on. If the teacher is withholding *that* information, your only alternative would be to talk to either a vice/assistant principal or the principal him/herself.

Anonymous said...

Could you explain the issue of not returning tests because I don"t understand it. This is a math test so the teacher should be able to change some numbers each year and give a new test.

Anonymous said...

Darren: "Anonymous: I understand the issue of not returning tests."

In a math class? What would the reason be? It isn't like you can't make new problems with different numbers, right?

-Mark Roulo

Anonymous said...

How do you compute P(X>3) = 1-[P(X=1) + P(X=2) + P(X=3)]?

Darren said...

Each of the probabilities is binomial.

Anonymous said...

What does that mean?

Darren said...!

maxutils said...

To anonymous ... I collected tests after reviewing them, but didn't particularly care if they didn't come back, as I wrote my own tests every year. If you have a teacher who gives test taken from the textbook manufacturer, it's more problematic. The solution would be to make an appointment to go in and review the material at the school. Annoying, but it would work. For me? I'd just give you the test. With most of the credit coming from the work,I don't really care if you know what I'm going to ask. If you can memorize the amount of work that needs to be shown on one of my tests, that in and of itself is worth something.