Monday, October 5, 2009

A Question for all the Java Jockeys Out There

Last week my class discussed the statistical question of what the likelihood
was of a family with two kids having both of them be girls. We knew that it
was supposed to be 25%, but the programs that my students wrote all came up
with likelihoods in the area of of 40%, and this was after multiple runs
with sets of 100, 1000, and even 30,000,000 families.

I decided to find out what they were doing wrong by writing the code myself
(without looking at theirs) and checking for the correct proporotion of boys
and girls in each column. It worked like a charm - except that even I got
the skewed stats of roughly 40% for two-girl families. In fact, I was
getting roughly 40% for families with both two girls and two boys, while
families with one of each were roughly 20%

I checked this out with my sister the statistician, who said that my logic
was correct, and then wrote it herself in SAS. She got the expected figures.
But we're all still a bit confused as to why we keep getting the right stats
for each column (Kid A and Kid B), but totally wrong stats for BB, BG, and
GG.

Do any of you Java experts out there want to take a look at my code to
either try to figure out what we're doing wrong, or maybe run it in a
different environment to see if you get different results? We've been doing
it in BlueJ on Macs. Do you get different results in BlueJ in Windows or
Linux? Do you get different results in a different programming environment?

The main code in question is at:
http://www.gatling.us/keith/class/javajive/TwoKids.java
The gatling class it refers to for gatling.randomInt is at
http://www.gatling.us/keith/class/gatling.java
For what it's worth, the gatling.randomInt method is merely an interface to
the standard Java method of creating random numbers.

Can anyone solve this conundrum for us?

Thanks!
--

keg

========================================
Keith E Gatling
Email: keith@gatling.us
Blog: http://wordfromg.blogspot.com
Website: http://www.gatling.us/keith
The fact that I'm open-minded doesn't mean that I have to agree with you.
========================================

[ For info on ISED-L see http://www.gds.org/ISED-L ]
Submissions to ISED-L are released under a creative commons, attribution, non-commercial, share-alike license.
RSS Feed, http://listserv.syr.edu/scripts/wa.exe?RSS&L=ISED-L