0
$\begingroup$

I am trying to compare the odds of two events happening (what are the odds of one happening first). I know that the first one occurs in an average of 10 months with a sigma of 3 months. The second occurs in an average of 84 months with a sigma of 30 months. First, is there an analytical way of solving this? Second, I attempted to solve this by simulating it (Monte-Carlo), but it is not giving me the expected results. In particular, if I ask it to just simulate just one of the events, the reported average is way before the expected average. I tried simulating both with a gaussian and a cumulative gaussian. What am I missing?

import math
import random
from scipy.stats import norm

otherStart = 2*365                              #estimate for earliest donation
otherEnd = 8*365                                #estimate for latest donation
otherMu = (otherStart + otherEnd)/2             #average
otherSig = (otherEnd - otherStart)/5            #get some semblance of a sigma

meStart = 7*31
meEnd = 13*31
meMu = (meStart + meEnd)/2
meSig = (meEnd - meStart)/5

def cdfDist(x,mu,sig):                          #cdf function
    y = norm.cdf(x,mu,sig)
    return y

#def gaussDist(x,mu,sig):
#    y = (1/(sig*math.sqrt(2*math.pi)))*math.exp(-0.5*((x-mu)/sig)*((x-mu)/sig))
#    return y

def rollDiceUntilWin():
    day = 0                                             #start at day 0
    while True:
        chancesOther = random.uniform(0, 1)                 #roll a dice
        otherOdds = cdfDist(day+2*365,otherMu,otherSig)     #find odds for that day (it has been 2 years since that counter started)
#        otherOdds = gaussDist(day+2*365,otherMu,otherSig)
        if (chancesOther < otherOdds):                          #did it win
#            print(day)
            return 1
        chancesMe = random.uniform(0,1)
        meOdds = cdfDist(day,meMu,meSig)
        if(chancesMe < meOdds):
#            print(day)
            return 2
        day = day + 1                                   #if noone won, go to next day
#        if (day > 10000):
#            day = 0

if __name__ == "__main__":
    numRolls = 100                                      #number of rolls
    meGive = 0                                          #counter of wins
    otherGive = 0
    for i in range(numRolls):
        outCome = rollDiceUntilWin()
        if outCome == 1:
            otherGive = otherGive + 1                   #if win, add 1
        if outCome == 2:
            meGive = meGive + 1

    chances = meGive / (meGive + otherGive)             #get chances
    print(chances)
$\endgroup$

1 Answer 1

0
$\begingroup$

Comment: the time to a future event cannot be gaussian because a gaussian random variable has a non-zero probability of being negative, but it could be a reasonable approximation in some cases.

Do you want the probability or the odds of the event?
If $X$ is gaussian with mean 10 and standard deviation 3 and $Y$ is gaussian with mean 84 and standard deviation 30, and they are independent, then $X-Y$ is gaussian with mean -20 and standard deviation $\sqrt{10^2+30^3}$. The probability that $X<Y$ is $$P[X<Y]=P[X-Y<0]=P\left[\frac{X-Y-(-20)}{\sqrt{10^2+30^2}}<\frac{0-(-20)}{\sqrt{10^2+30^2}}\right]$$ Now, find the probability that a standard normal random variable is less than the number $\frac{0-(-20)}{\sqrt{10^2+30^2}}$. After you have found the probability (p) of the event, the odds of the event is p/(1-p).

$\endgroup$
3
  • $\begingroup$ find the probability that a number in 0 to 1 (a standard normal random variable) is less than 1 ($\frac{0-(-20)}{\sqrt{10^2+30^2}}$.)? isn't that 100%? $\endgroup$
    – user332573
    Commented Aug 17, 2021 at 17:01
  • $\begingroup$ A standard normal random variable has mean 0 and standard deviation 1. It can be negative or positive and can be greater than 1 with positive probability. $\endgroup$
    – John L
    Commented Aug 17, 2021 at 17:42
  • $\begingroup$ So like find how much of the area of a Gaussian distribution (with mean 0 and std dev 1) lies past positive 1? $\endgroup$
    – user332573
    Commented Aug 17, 2021 at 19:47

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.