Modelling Football Data with Vine Copulas
A tutorial on vine copulas, motivated by and illustrated with football data.
Football is the most popular sport in the World. With an estimated 5 billion fans worldwide according to n.d. (n.d.), it is unique in its ability to generate a feeling of community amongst fans. It also presents participants and observers with opportunities to make considerable sums of money. As such, the generation of accurate football prediction models has become a topic of intense interest among statisticians and data scientists.
In this article we will describe an approach to football modelling structured around an object called a vine copula. It can be read as a tutorial on statistical methodology, for which football provides motivation and context, or as a serious suggestion for sports analysts and enthusiasts looking for new ways to reconcile the many forms of data collected from football matches.
We will begin by introducing copulas: starting with relatively simple bivariate copulas, then moving on to more complicated vine copulas. Along the way we will demonstrate how they can be fitted to real data with the help of the python package vinecopulib. By the end of the post we will be in a position to generate probabilistic predictions from a vine copula, which could inform the decisions of sports analysts and bettors.
What is a copula?
A copula function is a type of probability function, assigning probabilities to events. More specifically, these events describe situations in which a set of random variables with uniform marginal distributions take certain values. This is useful because we can transform a set of variables with arbitrary marginals into a set with uniform marginals by applying the probability inverse transform to each one separately.
Modelling the joint distribution of a set of variables can thus be broken down into the estimation of the marginal distributions, for which there exists a wide range of possibilities that we will mostly not discuss here, and the estimation of a copula function, which we will discuss at length!
Bivariate copulas
While copula functions can theoretically be used to describe any number of random variables, they are most commonly used to model variables two at a time. A bivariate copula function \(C: [0,1]^2 \mapsto [0,1]\) is used to assign joint probabilities to events in which a pair of marginally uniform random variables \((U,V)\) fall in particular regions of the unit square. Specifically, we write \[\begin{align} C(u,v) = P(U \leq u, V \leq v), && u,v \in [0,1], \end{align}\] and insist that \[\begin{align} C(u,0) = C(0,v) = 0, && C(u,1) =P(U\leq u)= u, && C(1,v) =P(V\leq v)= v, \end{align}\] in order to satisfy the assumption of uniform marginals. It is also necessary for \(C\) to satisfy a `non-decreasing’ property ensuring that all rectangular subregions of \([0,1]^2\) are assigned non-negative probability.
Copulas are useful primarily because we can use them to describe the dependence between random variables via their dependence after having been passed through their own cumulative density functions, a transformation that renders them marginally uniformly distributed. Accordingly, we can write \[\begin{align} P(X \leq x,Y \leq y) &= P(F_X(X) \leq F_X(x), F_Y(Y) \leq F_Y(y)) \notag\\ &= P(U \leq u, V \leq v) \notag\\ &= C(u,v), \end{align}\] where \(u=F_X(x)\) and \(v=F_Y(y)\) are the cumulative distribution functions (CDFs) for our random variables evaluated at \(x\) and \(y\), respectively. A central result in the copula literature, known as Sklar’s Theorem and published in Sklar (1959), formalizes the idea that for every function \(P(X \leq x,Y \leq y)\) there exists a corresponding \(C\) and that when \(X,Y\) are continous rabdom variables \(C\) is unique.
For pairs of continuous random variables we can write their joint probability density function as the mixed derivative of their joint cumulative distribution function \[ f(x,y) = \frac{\partial}{\partial x}\frac{\partial}{\partial y} P(X \leq x,Y \leq y) = \frac{\partial u}{\partial x}\frac{\partial v}{\partial y} \frac{\partial}{\partial u}\frac{\partial}{\partial v} C(u,v) = f_X(x) f_Y(y) c(u,v) \tag{1}\] where \[\begin{align} \frac{\partial u}{\partial x} = f_X(x), && \frac{\partial v}{\partial y} = f_Y(y), && \frac{\partial}{\partial u}\frac{\partial}{\partial v} C(u,v) = c(u,v) \end{align}\] from which we see how the copula allows us to factorize a joint density into a pair of marginal densities, \(f_X(x)\) and \(f_Y(y)\), and a copula density function \(c(u,v)\). In doing so we decompose the problem of specifying a joint distribution into more manageable sub-problems.
Upon rearranging, Equation 1 also implies that \[ f(x \mid y) = \frac{f(x,y)}{f_Y(y)} = f_X(x) \, c(u,v), \tag{2}\] which is a result we will use in the sections to come. Specifically, it will allow us to switch out conditional densities with products of marginal densities and copula densities when we have more than two random variables to deal with.
Bivariate copula examples
Gaussian bivariate copula
\[\begin{equation} C_{\text{Gauss}}(u,v;\rho) = \Phi_\rho (\Phi^{-1}(u), \Phi^{-1}(v)), \quad \rho \in (-1,1). \end{equation}\] where \(\Phi\) is the CDF for a unit Normal random variable and \(\Phi_\rho\) is the joint CDF for a pair of bivariate Normal random variables with mean zero and correlation coefficient \(\rho\).
Frank’s bivariate copula
\[\begin{equation} C_{\text{Frank}}(u,v) = -\kappa_F^{-1} \log \left\{ 1-\frac{ (1-\exp (-\kappa_F u)) (1-\exp(-\kappa_F v)) }{ 1-\exp(-\kappa_F) } \right\}, \quad \kappa_F \in [-∞,∞]\backslash \{0\}. \end{equation}\]
Clayton’s bivariate copula
\[\begin{equation} C_{\text{Clayton}}(u,v) = \max\left\{(u^{-\kappa_C}+v^{-\kappa_C}-1)^{-1/\kappa_C},0\right\},\quad \quad \kappa_C \in (0,∞]. \end{equation}\] The parameters \(\rho\), \(\kappa_F\) and \(\kappa_C\) are parameters that we can adjust to better match the relevant copula functions to observed distributions of data.
Independence copula
\[\begin{equation} C_{\text{Ind}}(u,v) = uv. \end{equation}\] The independence copula, with no parameters, is arguably trivial but is often selected on the basis of its AIC when the number of observations available for fitting is small.
Selecting bivariate copulas for their tail behviour
Selection of the parameter values that determine the shape of a particular copula function is typically performed via gradient-based optimization of the log-likelihood. Selection between distinct families of copula function (like the Gaussian, Frank and Clayton families) tends to be done on the basis of their AIC or BIC. In practice, the copula function that fits best to a given data set is often determined by the functions’ behaviour in the corners of the unit square.
This behaviour is characterized by Czado (2019) using quantities referred to as lower- and upper-tail dependence coefficients. They are defined as \[\begin{align} \lambda_{lower} &= \lim_{t\to 0^+} P(Y \leq F_Y^{-1}(t) \mid X \leq F_X^{-1}(t))=\lim_{t\to 0^+}\frac{C(t,t)}{t},\\ \lambda_{upper} &= \lim_{t\to 1^-} P(Y > F_Y^{-1}(t)\mid X> F_X^{-1}(t))=\lim_{t\to 1^-}\frac{1-2t+C(t,t)}{1-t}. \end{align}\] These quantities answer questions of the form: ‘if \(X\) is observed to be far into the tail of its marginal distribution, how probable is it that \(Y\) is just as far into the tail of its marginal?’. They are describing the cooccurrence of extreme values. In the context of the football data we might imagine, for example, that the home team receiving an anomolously large number of yellow cards might increase the probability of the away team receiving just as many yellow cards because the match has become exceedingly aggressive and disorderly. We might also imagine a large number of home yellows being due to match-specific discipline problems that the away team can mostly rise above so that the number of away yellows is not correspondingly high. The choice between these two hypotheses regarding team behaviours maps approximately onto the choice between copulas with different degrees of (upper) tail dependence.
Bivariate copulas for discrete random variables
Unlike a continuous random variable, a discrete random variable cannot be transformed in such a way that it has a (continuous) uniform distribution. So it might look like the copula definition above is useless to us in the discrete setting. Perhaps the main problem, as Genest and Nešlehová (2007) and Geenens (2020) explain in detail, is that the one-to-one correspondence between bivariate cumulative mass functions and copula functions is lost.
However, given the obvious importance of discrete count data in football, we will persevere! Copula densities, whose logarithm we maximize when fitting to observations of continuous random variables, are avoided in the dicrete setting. Instead, for discrete \(X_1, X_2\) we evaluate probabilities, which are subsequently logged and maximized with respect to a copula parameter \(\kappa\). These probabilities can be identified with integrals over rectangles of densities (such as those in Figure 1). An inclusion-exclusion technique is used to derive the integral over a rectangle in the interior of \([0,1]^2\) in terms of rectangles, each of which have a corner at \((0,0)\). Explicitly, we write \[\begin{equation} P(X_1 = x_1, X_2 = x_2) = C(u_1, u_2; \kappa) - C(u_1^-, u_2; \kappa) - C(u_1, u_2^-; \kappa) + C(u_1^-, u_2^-; \kappa) \end{equation}\] where \(u_1^-\) and \(u_2^-\) are the left-sided limits of the CDFs of \(X_1\) and \(X_2\) at \(x_1\) and \(x_2\), respectively.
Vine copulas
You may now be wondering how, given copulas are typically only used between pairs of variables, are we going to generate a prediction model for multiple football variables. Fear not! This is where the titular vine copula come in.
The first pair copula construction (PCC) for a multivariate copula was produced by Joe (1996). His idea was to factorize a multivariate copula relating any number of marginally uniform random variables into building blocks, each of which is a bivariate copula. Later, Bedford and Cooke (2001) and Bedford and Cooke (2002) showed that PCCs could be understood, analysed and discussed more easily with the help of a device they called a vine copula methodology.
The pair copula constructions in three dimensions
A three dimensional probability density function can be decomposed into a product of conditional densities, \[\begin{align} f(x_1,x_2,x_3) = f(x_1) f(x_2 \mid x_1) f(x_3 \mid x_2,x_1). \end{align}\] For convenience we can define conditional random variables \(x_{3 \mid 1} = x_3 \mid x_1\) and \(x_{2 \mid 1} = x_2 \mid x_1\) and write \[\begin{align} f(x_1,x_2,x_3) = f(x_1) f(x_2 \mid x_1) f(x_{3 \mid 1} \mid x_{2\mid 1}). \end{align}\] We can now switch out the conditional densities for products of marginal and copula densities according to Equation 2, i.e. \[\begin{align} f(x_2 \mid x_1) = f(x_2) c_{12}(u_1,u_2), && f(x_{3 \mid 1} \mid x_{2 \mid 1}) = f(x_{3\mid 1}) c_{23 \mid 1}(u_{2 \mid 1},u_{3 \mid 1}). \end{align}\] We can use our switching trick again to get rid of the \(f(x_{3\mid 1})\) above \[\begin{align} f(x_{3\mid 1}) = f(x_{3} \mid x_{1}) = f(x_3) c_{13}(u_1,u_3). \end{align}\] Substituting these terms back in and collect terms, we get \[ f(x_1,x_2,x_3) = f(x_1)f(x_2)f(x_3) \, c_{12}(u_1,u_2) c_{13}(u_1,u_3) c_{23 \mid 1}(u_{2 \mid 1},u_{3 \mid 1}), \tag{3}\] a product of marginal densities and bivariate copula densities.
At this point we make an important assumption - one that we will need in order for downsteam calculations to be tractable. We will need to assume that the bivariate copula density functions involving conditioned variables (e.g. the function \(c_{23 \mid 1}\) above) do not depend on the value of the random variable conditioned on. This is referred to as the ‘simplifying assumption’ in the copula literature.
If you are extemely alert and careful, you may have noticed that, like a magician, I have slipped a couple of things past you. Firstly, I decomposed the joint densities as a product of conditional densities that seems natural if we imagine the variables \(x_1\), \(x_2\) and \(x_3\) being produced in that order, but I needn’t have. Any ordering would have done. Secondly, I arbitrarily decided to define some new variables conditioned on \(x_1\). However, at that point, I could have defined \(x_{3 \mid 2} = x_3 \mid x_2\) and \(x_{1 \mid 2} = x_1 \mid x_2\) and continued the rest of the operations to arrive at an expression that looks slightly different from the one we actually produced (one with the subscripts \(1\) and \(2\) swapped around).
The point is that the PCC is not unique. The choices we make along the way involving the ordering of the variables change the expression we end up with and the simplfying assumption means that, in general, the different expressions we end up with really are different - they are not, in general, the same expressions in disguise.
Before moving on to the next section it will be useful to set up some extra notation and to define an object known as an \(h\)-function. It is nothing more the distribution function for a random variable conditional on another taking a particular value. For example, for random variables \(X_1\), \(X_2\), \(U_1=F_{X_1}(X_1)\), \(U_2=F_{X_2}(X_2)\) we would write the \(h\)-function \[\begin{align} h(u_1|u_2) &:= \frac{\partial}{\partial u_2} C(u_1,u_2) \\ &= P(U_1 \leq u_1, U_2=u_2)\\ &= P(U_1 \leq u_1 \mid U_2=u_2)P(U_2=u_2)\\ &= P(U_1 \leq u_1 \mid U_2=u_2)\\ &= P(X_1 \leq x_1 \mid X_2=x_2) \end{align}\] where, strictly speaking, the quantity \(P(U_2=u_2)\) is a uniform probability density (equal to one for all values) rather than a probability.
Vine copulas are useful for thinking about and keeping track of very large numbers of possible pair copula constructions. This is particularly important in high dimensions where the number of possible decompositions increases very quickly. Morales-Nápoles et al. (2023) showed that the number of regular vines on \(d\) variables is \[\begin{align} \frac{1}{2} \ d! \ 2^{\binom{d-2}{2}}, \end{align}\] meaning that in four dimensions there are 24 decompositions, in six dimensions there are 23040 and in eight dimensions there are 660602880.
PCCs as sequences of trees
The key conceptual breakthrough that provided statisticians with a way to stitch together bivariate copulas in a systematic way appears to have been made independently by H. Joe and R.M. Cooke. The breakthrough was to identify the bivariate copula densities in products such as Equation 3 with edges in trees. More precisely, they proposed using a set of trees that gradually reduce in size. In the example above with three variables there are two copula densities, \(c_{12}\) and \(c_{13}\), that do not involve conditioned variables and one copula density, \(c_{23 \mid 1}\), that does. The first two copula densities are represented as edges in the first tree, which has three nodes corresponding to the three variables. The second tree has two nodes corresponding to the two edges in the first tree and one edge corresponding to the copula density involving conditioned variables.
A vine copula on \(d\) dimensions is a sequence of \(d-1\) trees, each of which has a particular structure that ensures the necessary building blocks are in place for the next tree in the sequence. The first tree has \(d\) nodes corresponding to the \(d\) variables and \(d-1\) edges corresponding to the \(d-1\) bivariate copula densities that do not involve conditioned variables. The second tree has \(d-1\) nodes corresponding to the \(d-1\) edges in the first tree and \(d-2\) edges corresponding to the \(d-2\) bivariate copula densities involving one conditioned variable. The third tree has \(d-2\) nodes corresponding to the \(d-2\) edges in the second tree and \(d-3\) edges corresponding to the \(d-3\) bivariate copula densities involving two conditioned variables. This process continues until we have a final tree with two nodes and one edge corresponding to the single bivariate copula density involving \(d-2\) conditioned variables.
Czado (2019) describes the vine construction more formally as a set of trees \(\mathbb{V}=\{T_1,...,T_{d-1}\}\) satisfying the following conditions:
\[\begin{array}{l} \text{(1) Each tree } T_{j}=\left(N_{j}, E_{j}\right) \text{ is connected, i.e. for all nodes } a, b \in T_{j}, j=1, \ldots, d-1 \text{,}\\ \quad \text{ there exists a path } n_{1}, \ldots, n_{k} \subset N_{j} \text{ with } a=n_{1}, b=n_{k} \text{.}\\ \text{(2) } T_{1} \text{ is a tree with node set } N_{1}=\{1, \ldots, d\} \text{ and edge set } E_{1} \text{.}\\ \text{(3) For } j \geq 2, T_{j} \text{ is a tree with node set } N_{j}=E_{j-1} \text{ and edge set } E_{j} \text{.}\\ \text{(4) [Proximity Condition] For } j=2, \ldots, d-1 \text{ and } \{a, b\} \in E_{j} \text{ it must hold that } |a \cap b|=1 \text{.}\end{array}\]\((1)\) ensures at each tree level all nodes are connected, \((2)\) ensures that nodes in the first tree denote the \(d\) variables, \((3)\) ensures that for all trees after the first the edge set of the previous tree become our new nodes and finally \((4)\) ensures that for any two nodes to be connected in trees after the first, the corresponding edges in the previous tree must share a common node. This ‘proximity condition’ ensures the building blocks required for the higher level conditioning exist in the decomposition.
A vine copula for football data
In this example we will look at some real football data collected over 5 years of Premier League matches. The full data, which at the time of writing can be accessed at https://www.football-data.co.uk/, contains tens of variables relating mostly to event counts of different types and bookmakers’ odds. For our current purposes it will be convenient to pick a subset of six count variables: home goals (\(HG\)), away goals (\(AG\)), home shots (\(HS\)), away shots (\(AS\)), home yellow cards (\(HY\)) and away yellow cards (\(AY\)).
While there are over 20 thousand of possible vine structures in six dimensions, not all will fit the data equally well. As explained in greater depth in Dissmann et al. (2013), the most common approach to selecting a particular vine structure is to use a maximum spanning Tree algorithm (MST). Typically, the MST algorithm is provided with the absolute value of Kendall’s tau (or some other correlation metric such as Spearman’s rho) between all pairs of variables. It then finds the tree that connects all variables in such a way that the sum of correlations between connected variables is maximized.
Once the MST has chosen the tree structure, bivariate copulas are fitted via maximum likelihood to each pair of variables for which the tree has an edge. As mentioned above, we can also select between copula families using AIC-type criteria.
Choosing the vine’s trees
Tree 1
The edges marked in red in Figure 2 represent the maximum spanning tree for the fully-connected graph of football variables. This tree will be used as the first tree in our vine.
For clarity we redraw the tree below. At the same time we modify our notation slightly, switching the variable names for numbers (\(HS=1\), \(AS=2\), \(HY=3\), \(AY=4\), \(HG=5\), \(AG=6\)), to better match the expressions in the previous sections. We will also label the tree’s edges with tuples identifying the nodes that they connect. These are the tuples that appear in the subscripts of the copula densities that will, eventually, contribute to the final vine copula density.
In our example we fit bivariate copulas between the pairs of variables \((1,2)\), \((1,3)\), \((1,5)\), \((2,6)\) and \((3,4)\). Their corresponding copula densities (\(c_{12}, c_{13}, c_{15}, c_{26}, c_{34}\)) will be carried all the way through the vine-building algorithm, contributing as factors to our final expression for the full copula density.
Note that by maximizing the sum of correlations at this stage, without full consideration of how we are setting ourselves up for the next tree in the sequence, we are not necessarily maximizing the overall likelihood of the vine. The approach is one of greedy optimization, which is not guaranteed to find a globally optimal vine, but has been shown to be relatively successful in practice.
Tree 2
The edges from Tree 1 now become nodes to be paired up by Tree 2. In this ‘meta-tree’ setting our rule for identifying new edges becomes slightly more complicated. Firstly, edges can now only form between nodes that share a common variable in the previous tree. For example, the nodes \((1,3)\) and \((3,4)\) can be connected by an edge in Tree 2 because they both share variable \(3\) in Tree 1. However, the nodes \((1,3)\) and \((2,6)\) cannot be connected by an edge in Tree 2 because they share no common variable in Tree 1. This is Czado’s proximity condition. The three trees obeying the proximity condition are presented in Figure 4, where each colour represents a valid tree.
The second issue to address is how we are to interpret the edges in Tree 2. Each edge corresponds to a bivariate copula density involving one conditioned variable. For example, the edge connecting nodes \((1,3)\) and \((3,4)\) corresponds to the bivariate copula density \(c_{1,4;3}\), which is the density of the copula relating \(X_1\) and \(X_4\) conditional on \(X_3\). More generally, edges correspond to bivariate copulas for the set differences of the tuple of numbers in the nodes they connect. They are conditioned on the intersection of the tuple of numbers in the nodes they connect.
The bivariate copulas themselves are fitted to pseudo-observations, which are generated by applying the h-function for the relevant copulas to the original observations. For example, for the edge connecting nodes \((1,3)\) and \((3,4)\) in Tree 2 we define the pseudo-observations derived from the copula functions fitted in Tree 1 \[\begin{align} u_{1|3}= h_{1|3}(u_1|u_3) = \frac{\partial}{\partial u_3} C_{1,3}(u_1,u_3)\\ u_{4|3}= h_{4|3}(u_4|u_3) = \frac{\partial}{\partial u_3} C_{1,4}(u_4,u_3). \end{align}\] The choice of nodes to join with edges, and the corresponding bivariate copulas to fit, is determined by the MST algorithm again. This time the MST is provided with the absolute value of Kendall’s tau between the pseudo-observations.
Suppose according to the MST the optimal tree chosen is the tree represented in pink. We can then add the corresponding edge labels:
The edge labels are the same as the subscripts on the corresponding copula functions.
Tree 3
Construction Tree 3 involves repeating the process used for Tree 2. We look for edges that satisfy the proximity condition, transform variables using h-functions to produce pseudo-observations, use the MST to select a tree, and choose bivariate copula families and estimate their associated parameters via maximum likelihood.
Tree 3 for our football data looks like this:
Tree 4
Tree 4 looks like this:
Tree 5
And Tree 5 looks like this:
Piecing it all together
The final copula density can then be found by multiplying all of the bivariate copulas from each of the trees. In this example we have: \[\begin{align} c(u_1,u_2,u_3,u_4,u_5,u_6) = &\underbrace{c_{45;1,2,3,6}(C_{4|1,2,3,6},C_{4|1,2,3,6})}_{\text{tree 5}} \\ &\underbrace{c_{56;1,2,3}(C_{5|1,2,3},C_{6|1,2,3})\cdot c_{46;1,2,3}(C_{4|1,2,3},C_{6|1,2,3})}_{\text{tree 4}} \\ &\underbrace{c_{36;1,2}(C_{3|1,2},C_{6|1,2})\cdot c_{25;1,3}(C_{2|1,3},C_{5|1,3})\cdot c_{24;1,3}(C_{2|1,3},C_{4|1,3})}_{\text{tree 3}} \\ &\underbrace{c_{16;2}(C_{1|2},C_{6|2})\cdot c_{23:1}(C_{2|1},C_{3|1}) \cdot c_{35;1}(C_{3|1},C_{5|1})\cdot c_{1,4;3}(C_{1|3},C_{4|3})}_{\text{tree 2}} \\ &\underbrace{c_{26}\cdot c_{12} \cdot c_{15} \cdot c_{13} \cdot c_{34}}_{\text{tree 1}} \end{align}\] where we have omitted \(u_i\)’s and parameters to simplify notation.
Constructing vine copulas in python
Hopefully by now you understand how vine copulas work to both capture the dependence structure between \(d\) variables and generate a joint distribution. It can seem like a complex process, but thankfully there are a multitude of software packages that can help us. With that in mind, we will now work through how to generate vine copula models in Python. To do this we will use the library pyvinecopulib from Nagler and Vatter (2025), which is the Python interface to vinecopulib, a C++ library for vine copula models.
Fitting a vine copula to the football data
We start by installing and loading the packages we’ll need % pip install pyvinecopulib % pip install scikit-learn
Code
import pyvinecopulib as pv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split;
from IPython.display import display, Markdown
from scipy.stats import nbinom, poisson, lognormWe then transform the count data with the cumulative mass functions of marginal distributions we have chosen for them. In this case these are a mixture of negative binomial and Poisson distributions whose parameters are chosen to match the first moments of the data. We also transform the counts one less than the observed ones in order to compute the left-sided limits of the discontinuous CDFs. This is acheived using the \(\verb|loc|\) argument for the CDF functions.
Code
seasons = ['2122', '2223', '2324', '2425', '2526']
columns_to_keep = ['FTHG', 'FTAG', 'HY', 'AY', 'HS', 'AS', 'B365H', 'B365D', 'B365A']
dfs = [pd.read_csv(f'E0_{season}.csv')[columns_to_keep].copy() for season in seasons]
X = pd.concat(dfs, axis=0, join='inner', ignore_index=True)
q1 = np.mean(X['HS'])/np.var(X['HS'])
n1 = np.mean(X['HS'])**2/(np.var(X['HS'])-np.mean(X['HS']))
u1 = nbinom.cdf(X['HS'], n1, q1)
um1 = nbinom.cdf(X['HS'], n1, q1,loc=1)
q2 = np.mean(X['AS'])/np.var(X['AS'])
n2 = np.mean(X['AS'])**2/(np.var(X['AS'])-np.mean(X['AS']))
u2 = nbinom.cdf(X['AS'], n2, q2)
um2 = nbinom.cdf(X['AS'], n2, q2,loc=1)
u3 = poisson.cdf(X['HY'], np.mean(X['HY']))
um3 = poisson.cdf(X['HY'], np.mean(X['HY']), loc=1)
u4 = poisson.cdf(X['AY'], np.mean(X['AY']))
um4 = poisson.cdf(X['AY'], np.mean(X['AY']), loc=1)
u5 = poisson.cdf(X['FTHG'], np.mean(X['FTHG']))
um5 = poisson.cdf(X['FTHG'], np.mean(X['FTHG']), loc=1)
u6 = poisson.cdf(X['FTAG'], np.mean(X['FTAG']))
um6 = poisson.cdf(X['FTAG'], np.mean(X['FTAG']), loc=1)
uniform_data = np.column_stack((u1,u2,u3,u4,u5,u6,um1,um2,um3,um4,um5,um6))
uni_train, uni_test = train_test_split(uniform_data, test_size=0.2, random_state=42)Once we have the uniform margins we can move onto fitting the vine. At this point the vinecopulib package provides with many options. We can choose, for example:
which bivariate copula families to try out on selected pairs of variables,
the selection criteria used to choose a family,
whether to truncate the vine (that is to set all bivariate copulas to the independence copula, \(C(u,v) = uv\)) after a given tree depth).
This can be done as follows:
Code
chosen_candidate_families = [
pv.BicopFamily.gaussian,
pv.BicopFamily.clayton,
pv.BicopFamily.frank,
pv.BicopFamily.indep
]
chosen_controls = pv.FitControlsVinecop(
family_set=chosen_candidate_families,
allow_rotations=True,
selection_criterion='aic'
)A full list of controls can be found in the pyvinecopulib documentation.
We can now let the package loose on the data. It will do all the hard work we have described - looking for trees maximizing sums of pairwise absolute correlations and trying out different bivariate copulas on the edges.
Code
RVine = pv.Vinecop.from_data(uni_train, var_types=["d"] * 6, controls=chosen_controls)
print(RVine)<pyvinecopulib.Vinecop> Vinecop model with 6 variables
tree edge conditioned variables conditioning variables var_types family rotation parameters df tau
1 1 4, 3 d, d Clayton 0 0.28 1.0 0.12
1 2 3, 1 d, d Clayton 270 0.19 1.0 -0.09
1 3 5, 1 d, d Gaussian 0 0.42 1.0 0.28
1 4 1, 2 d, d Frank 0 -2.95 1.0 -0.30
1 5 2, 6 d, d Clayton 180 0.53 1.0 0.21
2 1 4, 1 3 d, d Independence 0.00
2 2 3, 5 1 d, d Clayton 270 0.12 1.0 -0.05
2 3 5, 2 1 d, d Gaussian 0 -0.14 1.0 -0.09
2 4 1, 6 2 d, d Independence 0.00
3 1 4, 5 1, 3 d, d Clayton 0 0.07 1.0 0.04
3 2 3, 2 5, 1 d, d Gaussian 0 0.06 1.0 0.04
3 3 5, 6 2, 1 d, d Clayton 270 0.13 1.0 -0.06
4 1 4, 2 5, 1, 3 d, d Independence 0.00
4 2 3, 6 2, 5, 1 d, d Independence 0.00
5 1 4, 6 2, 5, 1, 3 d, d Independence 0.00
Note that here we set \(\verb|var_types|\) as six discrete variables by typing \(\verb|["d"]*6|\). If, instead, we had continuous variables we would have used \(\verb|["c"]*6|\).
We can plot the trees of the fitted vine using
Code
RVine.plot()and we can check the quality of the fit to training and test data.
Code
train_ll = RVine.loglik(uni_train)
test_ll = RVine.loglik(uni_test)
aic = RVine.aic(uni_train)
display(Markdown(f"**Average train Log-Likelihood:** `{train_ll/len(uni_train):.3f}`"))
display(Markdown(f"**Average test Log-Likelihood:** `{test_ll/len(uni_test):.3f}`"))
display(Markdown(f"**Train AIC:** `{aic:.3f}`"))Average train Log-Likelihood: 0.211
Average test Log-Likelihood: 0.173
Train AIC: -620.589
Congratulations, you have now fit your first joint distribution using a vine copula!
Simulating from a vine copula
Having fitted a vine copula to data, a convenient way to understand its implications for future observations is via Monte Carlo simulation. In the context of the football data we might be interested, for example, in the vine copula’s implied probability for the number of home yellow cards exceeding two given that the home team wins the match. This might sound like a strange thing to be interested in, but bookmakers are likely to be concerned about such probabilities when they decide whether and how to offer betting odds on the intersection of multiple events (so-called accumulator bets).
Our approach to simulation follows that of Czado (2019), to whom we refer the reader for a more thorough account. The two key ingredients of the approach are the Rosenblatt transformation and a recursive formulation of conditional distribution function of a random variable.
The Rosenblatt transformation can be considered a multivariate version of the Probabilty Integral Transform, providing us with a way to turn a vector of dependent random variables into a vector of independent standard uniform variables. It does so by applying the conditional distribution functions of the random variables sequentially. More precisely, an instantiation \((x_1,...,x_d)\) of a random vector of dependent random variables \((X_1,...,X_d)\) is transformed to a vector \((u_1,...,u_d)\) according to \[\begin{align} u_1=F_{X_1}(x_1), && u_2=F_{X_2|X_1}(x_2|x_1), && ... && u_d=F_{X_d|X_1,...,X_{d-1}}(x_d|x_1,...,x_{d-1}) \end{align}\] The inverse Rosenblatt transformation does the opposite, transforming a vector of independent standard uniform variables into a vector of dependent random variables with a particular dependence structure. It does so by sequentially applying the inverse conditional distribution functions according to \[\begin{align} x_1=F_{X_1}^{-1}(u_1), && x_2=F_{X_2|X_1}^{-1}(u_2|u_1), && ... && x_d=F_{X_d|X_1,...,X_{d-1}}^{-1}(u_d|u_1,...,u_{d-1}). \end{align}\] Although we will not unpack the calculations here, the conditional inverse distribution functions in the expression above can be computed from a fitted vine copula using its h-functions and an ingeneous recursive formulation of the conditional distribution functions.
Note that we can produce simulated data conditioned on the first few variables taking particular values by simply plugging those values into the relevant steps of the inverse Rosenblatt transformation.
Simulating football data with a vine copula
When predicting the events of a football match it would be disadvantageous to ignore bookmakers odds. We will want to condition on them somehow in our simulations, and there are multiple strategies for doing so.
One strategy involves fitting a vine jointly to the odds data and the count data, but in a way that strictly preserves an ordering of the variables. Those that are to be conditioned on need to appear at the beginning so that we can substitute in observed values during the simulation process. Typically, the ordering is enforced by insisting that the vine’s first tree is a path graph (or linear graph). This constraint filters through to the other trees via the proximity condition.
An alternative strategy is to pre-condition all our count data on the bookmakers odds. One way to do this is to fit Poisson GLMs to our count data. For each match and each count variable the GLM’s predictive distribution can be used as the marginal. From this point onwards the vine fitting procedure described in the preceding sections an be applied.
In the code chunk below we fit Poisson GLMs
Code
from sklearn.linear_model import PoissonRegressor
X['log_odds_ratio'] = np.log(X['B365A'] / X['B365H'])
X_predictor = X[['log_odds_ratio']]
ignore_cols = ['B365H', 'B365A', 'log_odds_ratio']
target_cols = [col for col in X.columns if col not in ignore_cols]
fitted_models = {}
for target in target_cols:
y = X[target]
model = PoissonRegressor(alpha=0, max_iter=1000)
model.fit(X_predictor, y)
fitted_values = model.predict(X_predictor)
fitted_models[target] = {
'model': model,
'intercept': model.intercept_,
'coefficient': model.coef_[0],
'fitted_values': fitted_values
}before computing the \(u\) values as before
Code
stats = ['HS', 'AS', 'HY', 'AY', 'FTHG', 'FTAG']
u_list = []
um_list = []
for stat in stats:
mu = fitted_models[stat]['fitted_values']
u_list.append(poisson.cdf(X[stat], mu))
um_list.append(poisson.cdf(X[stat], mu, loc=1))
uniform_data = np.column_stack(u_list + um_list)
RVine = pv.Vinecop.from_data(uniform_data, var_types=["d"] * 6, controls=chosen_controls)We now pass the simulated \(u\) values through the inverse CDFs conditional on the bookmakers’ odds for a match we want to predict (below we use log odds of zero, corresponding to equal implied winning probabilities for the two teams).
Code
n_sims = 9999
u_sim = RVine.simulate(n=n_sims)
X_sim = {}
for i, stat in enumerate(stats):
mu = np.exp(fitted_models[stat]['intercept'] + fitted_models[stat]['coefficient'] * 0)
u_col = u_sim[:, i]
X_sim[stat] = poisson.ppf(u_col, mu)
X_sim_df = pd.DataFrame(X_sim)And let’s check a subset of the simulated counts.
Code
print(X_sim_df[:8]) HS AS HY AY FTHG FTAG
0 7.0 15.0 4.0 2.0 2.0 1.0
1 6.0 13.0 2.0 3.0 2.0 0.0
2 13.0 14.0 1.0 1.0 1.0 0.0
3 10.0 8.0 1.0 2.0 0.0 2.0
4 18.0 12.0 2.0 2.0 2.0 1.0
5 16.0 17.0 1.0 3.0 3.0 2.0
6 18.0 13.0 4.0 3.0 1.0 6.0
7 16.0 13.0 1.0 3.0 0.0 0.0
and compute proportions relevant to the hypothetical question we considered at the beginning of the section.
Code
p_card = (X_sim_df['HY'] > 2).mean()
p_hwin = (X_sim_df['FTHG'] - X_sim_df['FTAG'] > 0).mean()
p_card_hwin = ((X_sim_df['HY'] > 2) & (X_sim_df['FTHG'] - X_sim_df['FTAG'] > 0)).mean()Based on our vine copula simulations we see that, given equal winning odds for the teams,
The probability of the home team receiving more than 2 yellow cards is 26.8%.
The probability of the home team winning is 36.0%.
The probability of the home team receiving more than 2 yellow cards given the home team wins is 25.5%.
i.e. we have estimated one conditional probability among many in a way that, at least partially, accounts for the dependencies between variables.
Concluding remarks
We have now reached the end of our tutorial. Hopefully by now you will have a greater understanding on what vine copulas are and how they can be used to model multi-dimensional data. In particular we utilised vines to model a six dimensional football data set and generated conditional simulations of the match event counts.
An obvious question is how far can we push the methodology? Which components are most likely to break or stall as we head towards 20 or 100 variables? How can we sidestep these problems? And how does the vine copula compare with other methods for dealing with multivariate data? These are questions that we are working on in India’s PhD work and we hope to be able to share some of the answers in future articles.
- About the authors
-
India Richmond is a PhD student and Ben Powell is a lecturer in the Department of Mathematics at the University of York.
- Copyright and licence
-
© 2026 India Richmond and Ben Powell.
This article is licensed under a Creative Commons Attribution 4.0 (CC BY 4.0) International licence. Thumbnail photo credit and licence goes here.
- How to cite
-
Richmond, I. and Powell, B. 2026. “Modelling football data with vine copulas”, August 18, 2026. URL
References
Citation
@online{richmond2026,
author = {Richmond, India and Powell, Ben},
title = {Modelling {Football} {Data} with {Vine} {Copulas}},
date = {2026-10-02},
langid = {en}
}