On Wed, 28 Oct 2009, Richard Goldstein wrote:
during a consecutive period of 120 days, if it rains on 7 days and my
client wears a hat on 4 days (these are independent of any knowledge of
the weather), what is the probability that it will rain on 3 of the days
on which he is wearing a hat?
Perhaps beating Maarten to the punch, I immediately thought to do a
simulation, and I came up with 0.00048260, right in line with Al
Feiveson's analytic solution.
----------------------------------------
mata:
rseed(1)
tries = 10000000
totaln = 0
for(i=1; i<=tries; ++i) {
// rain has 7 ones
rain = J(120, 1, 0)
rain[1..7] = J(7,1,1)
// hat has 4 ones
hat = J(120, 1, 0)
hat[1..4] = J(4,1,1)
// shuffle each one
_jumble(rain)
_jumble(hat)
// if there's a match, hat+rain==2
both = rain + hat
matches = sum(both:==2)
// we want to know if there were three matches
if (matches == 3) {
totaln = totaln + 1
}
if (mod(i, 1000) == 0) {
printf(".")
}
}
printf("\n\nProbability is about %10.8f\n", totaln/tries)
end
----------------------------------------
-- Brian Poi
-- [email protected]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/