1
$\begingroup$

I have a Python file that simulates 10 000 hypothetical soccer matches between two teams. This is done by generating two sets of 10 000 random numbers between 0 to 1 (10 000 for each team). This is then passed through a Poisson inverse function for each team, which uses the expected goals per team for the match (a value that considers expected goals scored and received per match), to calculate goals per team for each one of the 10 000 matches. I then count the percentage of wins, ties and losses, which will vary depending on the teams considered and their expected goals per match.

I have noticed that if I run this code for a particular team playing against itself, or two teams that have the exact same number of expected goals for a match against each other, the percentage of wins, ties and losses is not consistent, within a margin of error of about 2 %. Roughly speaking, I have not calculated this. This means that a team will for example win against itself 38 % of the time and lose against itself 37 % of the time. I would expect the same percentage of wins/losses for the same team agsinst itself. The discrepancy is in the counts, and is not explained by rounding up the percentages. I am trying to get a better understanding of what is going on, to take this into consideration in the code. Does this have to do with the way Python generates random numbers? Or is there an intrinsic aspect of the Poisson inverse that causes this? In any case, what could be going on here? I have the feeling that there is a very simple explanation that I am overseeing.

$\endgroup$
3
  • $\begingroup$ This is pretty vague. Can you simplify the problem to a minimal working example that demonstrates the unexpected behavior? When you do, please include the code and the specific results that surprise you. I'm not certain, but I think that Python relies on the operating system to provide it with random numbers, so I don't think there will be any strangeness with the generation specific to the language. Could be wrong about that. $\endgroup$
    – ShawSa
    Commented Sep 7, 2022 at 22:12
  • $\begingroup$ There are multiple ways to use Python to do what you are describing, and without knowing the specific code it is almost impossible to answer your question. The right way to ask a question like this is to try to reproduce the behavior you are describing in a few readable lines of code (i.e. remove all the code which is non-essential to the phenomenon you observe), include a code into your question, and ask a question about the behavior of that code snippet. $\endgroup$
    – fiktor
    Commented Sep 7, 2022 at 22:51
  • 2
    $\begingroup$ It has nothing to do with Python and not much to do with a Poisson distribution, but everything to do with the noise inherent in simulations. Flip a coin $10000$ times and you should not be surprised if the numbers of heads and tails differ $\endgroup$
    – Henry
    Commented Sep 7, 2022 at 23:21

1 Answer 1

4
$\begingroup$

If you are surprised that a large proportion of your simulation runs have an absolute difference between wins and losses of more than $50$ games i.e. more than $\pm 0.5\%$ of the $10000$ games simulated, you should not be. This may happen about $56\%$ of the time.

Suppose the probability of a win against your clone was $37.5\%$, and similarly the probability of a loss was also $37.5\%$, and a draw $25\%$, then in a single game the probability of win-loss being $+1$ is $0.375$ and being $-1$ is $0.375$ and being $0$ is $0.25$. This distribution has mean $0$ and variance $0.75$.

Take $10000$ i.i.d. simulations and the total wins-losses has mean $0$ and variance $7500$, i.e. a standard deviation of $\sqrt{7500} \approx 86.6$. As a proportion of the $10000$ games, that standard deviation is $0.00866$ or $0.866\%$.

So seeing a simulated difference betweens wins and losses in a range of $\pm200$ games or $\pm 2\%$ of the games is more or less what you might expect: it is about $\pm 2.3$ standard deviations from the mean, and you might expect about $98\%$ of your simulation runs to fall inside this interval.

$\endgroup$
3
  • $\begingroup$ Thanks! I think this pretty much sums up what is going on. I had a feeling it was a simple explanation. I could share the code and results, but considering your suggestion, this behavior is rather independent of the method, and to be expected as noise in a probabilistic scenario like this one. $\endgroup$
    – AVT_DB
    Commented Sep 9, 2022 at 6:28
  • 1
    $\begingroup$ Not that it matters, but you get those probabilities if each team independently scored a Poisson distributed number of goals each with expectation about $1.4274$ $\endgroup$
    – Henry
    Commented Sep 9, 2022 at 7:24
  • $\begingroup$ By the way, I realized that I was confusing "inconsistency" in Python's method to generate random numbers, or Python's inverse Poisson function, with "randomness". All methods can be consistent, but there will still be randomness in such a simulation. And that is the whole point of the simulation, contrary to just getting the probabilities for each possible score with a Poisson function (not its inverse and random numbers), which renders the exact same result for the same expected goals. The whole point of simulating like this is to create a random situation that resembles reality closer. $\endgroup$
    – AVT_DB
    Commented Sep 14, 2022 at 5:03

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.