[This article was first published on Statistical Graphics and more » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Each year after the group stage, there is the much awaited drawing of the eighth-final, which essentially defines a team’s fate. So far the thing is not too complicated, as there are 16 teams out of which we need to generate 8 games – no problem if it would be possible to draw the teams without restrictions. But there are quite a few:

1. Group winners only play group runner up
2. You can’t play a team which was in the same group
3. Teams from the same league can’t play each others

Thus there is some combinatorics to solve. Sebastian created a shiny app and the necessary R-Code to generate the probabilities of who plays whom:

Here we immediately see the restrictions as 0% probability, as there are 8 zeros on the diagonal (restriction 2) and 7 zeros off-diagonal (restriction 3). As each row and column must add up to one (a fact that the friends at SPON got wrong as they initially posted a false solution), combinations at intersections of rows and columns with many zeros get higher probabilities. So the most likely draws (greedy) are:

• FC Chelsea vs. Bayer 04 Leverkusen
• FC Bayern Munich vs. FC Arsenal
• Borussia Dortmund vs. Manchester City
• AS Monaco vs. FC Schalke 04

If these matches would be drawn, we would end up with equal probabilities and still three different opponents for all the remaining teams:

Things look quite different, when we go for the least probable matches for each draw, these are e.g.:

• Real Madrid vs. FC Shakthar Donetsk (1 out of 9 with 11%)
• FC Porto vs. FC Basel (9.3%)
• FC Barcelona vs. Juventus Turin (13%)
• AS Monaco vs. Manchester City (1 out of 7 with 16.7%)

Now, only after 4 draws, the remaining matches are all fixed by one of the restrictions:

Now we see what makes the drawing so interesting. Given what matches were already drawn, the remaining matches are more or less fixed.

Thanks to Sebastian for the nice tool, and have fun to play around – maybe you find three matches which already fix all remaining?! Let’s see what happens on Monday, when the actual drawimg takes place.

Anyway a fantastic example of how useful shiny can be.