{'fraction_non_alphanumeric': 0.03368451083080309, 'fraction_numerical': 0.009985124202718399, 'mean_word_length': 4.641986663600828, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Enhanced Gravity Model of trade: reconciling macroeconomic and network models

The structure of the International Trade Network (ITN), whose nodes and links represent world countries and their trade relations respectively, affects key economic processes worldwide, including globalization, economic integration, industrial production, and the propagation of shocks and instabilities. Characterizing the ITN via a simple yet accurate model is an open problem. The traditional Gravity Model (GM) successfully reproduces the volume of trade between connected countries, using macroeconomic properties such as GDP, geographic distance, and possibly other factors. However, it predicts a network with complete or homogeneous topology, thus failing to reproduce the highly heterogeneous structure of the ITN. On the other hand, recent maximum-entropy network models successfully reproduce the complex topology of the ITN, but provide no information about trade volumes. Here we integrate these two currently incompatible approaches via the introduction of an Enhanced Gravity Model (EGM) of trade. The EGM is the simplest model combining the GM with the network approach within a maximum-entropy framework. Via a unified and principled mechanism that is transparent enough to be generalized to any economic network, the EGM provides a new econometric framework wherein trade probabilities and trade volumes can be separately controlled by any combination of dyadic and country-specific macroeconomic variables. The model successfully reproduces both the global topology and the local link weights of the ITN, parsimoniously reconciling the conflicting approaches. It also indicates that the probability that any two countries trade a certain volume should follow a geometric or exponential distribution with an additional point mass at zero volume.


Introduction
The International Trade Network (ITN) is the complex network of trade relationships existing between pairs of countries in the world. The nodes (or vertices) of the ITN represent nations and the edges (or links) represent their (weighted) trade connections. In a global economy extending across national borders, there is increasing interest in understanding the mechanisms involved in trade interactions and how the position of a country within the ITN may affect its economic growth and integration [1,2,3,4,5]. Moreover, in the wake of recent financial crises the interconnectedness of economies has become a matter of concern as a source of instability [6]. As the modern architecture of industrial production extends over multiple countries via geographically wider supply chains, sudden changes in the exports of a country (due e.g. to unpredictable financial, environmental, technological or even political circumstances) can rapidly propagate to other countries via the ITN. The assessment of the associated trade risks requires detailed information about the underlying network structure [7]. In general, among the possible channels of interaction among countries, trade plays a major role [2,3,4].
The above considerations imply that the empirical structure of the ITN plays a crucial role in increasingly many economic phenomena of global relevance. It is therefore becoming more and more important to characterize the ITN via simple but accurate models that identify both the basic ingredients and the mathematical expressions required to accurately reproduce the details of the empirical network structure. Reliable models of the ITN can better inform economic theory, foreign policy, and the assessment of trade risks and instabilities worldwide.
In this paper, we emphasize that current models of the ITN have strong limitations, and that none of them is satisfactory, from either a theoretical or a phenomenological point of view. We point out equally strong (and largely complementary) problems affecting on one hand traditional macroeconomic models, which focus on the local weight of the links of the network, and on the other hand more recent network models, which focus on the existence of links, i.e. on the global topology of the ITN. We then introduce a new model of the ITN that preserves all the good ingredients of the models proposed so far, while at the same time improving upon the limitations of such approaches. The model can be easily generalized to any (economic) network and provides an explicit specification of the full probability distribution that a given pair of countries is connected by a certain volume of trade, fixing an otherwise arbitrary choice in previous approaches. This distribution is found to be either geometric (for discrete volumes) or exponential (for continuous volumes), with an additional point mass at zero volume. This feature, which is different from all previous specifications of international trade models, is shown to replicate both the local trade volumes and the global topology of the empirical ITN remarkably well.

Preliminaries: building blocks of the model
Before we fully specify our model, we preliminarily identify its building blocks by reviewing the strengths and weaknesses of the two main modelling frameworks adopted so far.

Gravity models of trade
We start by discussing traditional macroeconomic models of international trade. These models have mainly focused on the volume (i.e. the value e.g. in dollars) of trade between countries, largely because economic theory perceives trade volumes as being a priori more informative than the topology of the ITN: the striking heterogeneity of trade volumes observed between different pairs of countries is clearly not captured by a purely 'binary' description where all connections are effectively given the same weight. Based on this argument, emphasis has been put on explaining the (expected) volume of trade between two countries, given certain dyadic and country-specific macroeconomic properties.
Jan Tinbergen, the physics-educated 1 Dutch economist who was awarded the first Nobel memorial prize in economics, introduced the so-called Gravity Model (GM) of trade [8]. The GM aims at inferring the volume of trade from the knowledge of Gross Domestic Product, mutual geographic distance, and possibly additional dyadic factors of macroeconomic relevance [9,10]. In one of its simplest forms, the gravity model predicts that, if i and j label two different countries (i, j = 1, N where N is the total number of countries in the world), then the expected volume of trade from i to j is where GDP k is the Gross Domestic Product of country k, R ij is the geographic distance between countries i and j, and c, α, β, γ are free global parameters to be estimated. In the above directed specification of the GM, the flows w ij and w ji can be different. An analogous undirected specification exists, where the volumes of trade from i to j and from j to i are added together into a single value w ij = w ji of bilateral trade. In the latter case, 1 still holds but with the symmetric choice α = β. With this in mind, we will keep our discussion entirely general throughout the paper and, unless otherwise specified, allow all quantities to be interpreted either as directed or as undirected. Only in our final empirical analysis we will adopt an undirected description for simplicity. More complicated variants of 1 use additional factors (with associated free parameters) either favoring or resisting trade [9,10]. Like the GDP and geographic distances, these factors can be country-specific (e.g. population) or dyadic (e.g. common currency, trade agreements, shared borders, common language, etc.). In general, if we collectively denote with n i the set of node-specific factors and with D ij the set of dyad-specific factors used, 1 can be generalized to where the functional form of F φ (n i , n j , D ij ) need not be of the same type as in 1, and φ is a vector containing all the free parameters of the model (like c, α, β, γ for the particular case above). Indeed, although in this paper we focus on the GM applied to the international trade network, our discussion equally applies to many other models of (socio-economic) networks as well. For instance, the recently proposed Radiation Model (RM) [11] is also described by 2, where n i and D ij include certain geographical and demographical variables. Our following discussion applies to both the GM and the RM, as well as any other model described by 2. Similarly, it does not only apply to trade networks, since both the GM and the RM have been successfully applied to other systems as well, including mobility and traffic flows [11,12,13,14], communication networks [15], and migration patterns [16] (the latter representing -to our knowledgethe earliest application of the GM to a socio-economic system, dating back to 1889 [17]). It is generally accepted that the expected trade volumes postulated by the GM, already in its simplest form given by 1, are in good agreement with the observed flows between trading countries. To illustrate this result, in Fig. 1 we show a typical log-log plot comparing the empirical volume of the realized (bilateral) international trade flows with the corresponding expected values calculated under the GM as defined in 1. The figure shows the typical good agreement between the GM and the empirical non-zero trade volumes. However, it should be noted that, while 1 and 2 define the expected value of w ij , the full probability distribution from which this expected value is calculated is not specified, and actually depends on how the model is implemented in practice. In the GM case, the distribution is chosen to be either Gaussian (corresponding to additive noise, in which case the expected weights can be fitted to the observed ones via a simple linear regression [18,19]), log-normal (corresponding to multiplicative noise and requiring a linear regression of log-transformed weights [20]), Poisson [20], or more sophisticated [21] (see [22] for a review). The arbitrariness of the weight distribution already highlights a fundamental weakness of the traditional formulation of the model. Moreover, for both additive and multiplicative Gaussian noise, the model can produce undesired negative values.
A related and more important limitation of the GM is that, at least in its simplest and most natural implementations, it cannot generate zero volumes -thereby predicting a fully connected network [23,22,24]. This means that the GM can be fitted only to the non-zero weights, i.e. the volumes existing between pairs of connected countries. If used in this way, the model effectively disregards the empirical structure of the network, both as input (thus making predictions on the basis of incomplete data) and as output (thus failing to reproduce the topology). Operatively, the GM can be used only after the presence of a trade link has been established independently [22]. As observed in [21], "Omitting zero-flow observations implies that we loose information on the causes of (very) low trade", because any fit to positive-only flows would significanlty underestimate the effects of factors that diminish trade. This problem is particularly critical since roughly half of the possible links are found to be not realized in the real ITN [25,26,27,28]. Clearly, the same problem holds for the RM and any more general model of the form specified in 2.
While there are variants and extensions of the GM that do generate zero weights and a realistic link density (e.g. the so-called Poisson pseudo-maximum likelihood models [20] and 'zero-inflated' gravity models [21]), these variants systematically fail in repro-ducing the observed topology [22,10]. In other words, while these models can generate the correct number of connections, they tend to put many of the latter in the 'wrong place' in the network. Indeed, even in its generalized forms, the GM predicts a largely homogeneous network structure, while the empirical topology of the ITN is much more heterogeneous and complex [23,22]. Established empirical signatures of this heterogeneity include a broad distribution of the degree (number of connections) and the strength (total trade volume) of countries [25,26,27,28,29,30,31,32,33,34,35], the rich-club phenomenon (whereby well-connected countries are also connected to each other) [36,37], strong clustering and (dis)assortative patterns [26,27]. These highly skewed structural properties are remarkably stable over time. However, their are not replicated by any current version of the GM [22].

Network models of trade
As we mentioned at the beginning, many processes of great economic relevance crucially depend on the large-scale topology of the ITN. In light of this result, the sharp contrast between the observed topological complexity of the ITN and the homogeneity of the network structure generated by the GM (including its extensions) calls for major improvements in the modelling approach. In particular, in assessing the performance of a model of the ITN, emphasis should be put on how reliably the (global) empirical network structure, besides the (local) volume of trade, is replicated. In the network science literature, successful models of the ITN have been derived from the maximum entropy principle [25,26,27,28,24,38,39,40,41,42]. These models construct ensembles of random networks that have some desired topological property (taken as input from empirical data) and are maximally random otherwise. Typically, the constrained properties are chosen to be the degrees and/or the strenghts of all nodes. In this way the models can perfectly replicate the observed strong heterogeneity of these purely local properties, and at the same time illustrate its immediate (i.e. prior to invoking any other more complicated network formation mechanism) structural effects on any higher-order topological property of the network.
In general, different choices of the constrained properties lead to different degrees of agreement between the model and the data. This can generate intriguing and counterintuitive insight about the structure of the ITN. For instance, contrary to what naive economic reasoning would predict, it turns out that the knowledge of purely binary local properties (e.g. node degrees) can be more informative than the knowledge of the corresponding weighted properties (e.g. node strengths). Indeed, while the binary network reconstructed only from the knowledge of the degrees of all countries is found to be topologically very similar to the real ITN, the weighted network reconstructed only from the strengths of all countries is found to be much denser and very different from the real network [26,27,28]. This is somewhat surprising, given that economic theory postulates that weighted properties are per se more informative than the corresponding binary ones.
The solution to this apparent paradox lies in the fact that, while the knowledge of the entire weighted network is necessarily more informative than that of its binary projection (in accordance with economic postulates), the knowledge of certain marginal properties of the weighted network can be unexpectedly less informative than the knowledge of the corresponding marginal properties of the binary network. In fact, it turns out that if the degrees of countries are (not) specified in addition to the strengths of countries, the resulting maximum-entropy model can(not) reproduce the empirical weighted network of international trade satisfactorily [27,40,41].
An important take-home message is that, in contrast with the mainstream literature, models of the ITN should aim at reproducing not only the strength of countries (as the GM automatically does by approximately reproducing all non-zero weights), but also their degree (i.e. the number of trade partners) [26,27,28,41]. In order to devise improved models of the ITN, one should therefore include the degrees, which are purely topological properties, among the main target quantities to replicate. This is the guideline we will follow in this paper.
Unlike the GM, maximum-entropy models of trade are a priori non-explanatory, i.e. they take as input structural properties (as opposed to explanatory economic factors) to explain other structural properties. However, they can in fact be used to select a posteriori an explicit, empirically validated functional dependence of the structure of the ITN on underlying explanatory factors. For models with country-specific constraints, this operation can be carried out as follows. Mathematically, controlling for node-specific properties is realized by assigning one or more Lagrange multipliers, also known as 'hidden variables' or 'fitness parameters' x i , to each node. If a certain choice of local constraints is found to replicate the higher-order properties of the real-world network satisfactorily, then one can look for an empirical relationship between the values of the associated hidden variables and those of candidate non-topological, country-specific factors of the type n i , like the GDP or total import/export. If the hidden variables are indeed (at least approximately) found to be functions of some country-specific factors (i.e. if x i ≈ f (n i )), then one can replace x i with f (n i ) in the maximum-entropy model, thus reformulating the latter as a model with explanatory variables (i.e. 'regressors') of trade, precisely like the GM. Already more than a decade ago, the approach outlined above led to the definition of a GDP-driven model for the binary topology of the ITN, where x i ∝ GDP i . The model, which is a reformulation of a maximum-entropy model for binary networks with given degrees, predicts that the probability of a trade connection existing from country i to country j is where δ is a free parameter that allows to reproduce the empirical link density. The model has been tested successfully in multiple ways [24,25,30,32,38]. The GM in 1 and the maximum-entropy model in 3 have complementary strengths and weaknesses, the former being a good model for non-zero volumes (while being a bad model for the topology) and the latter being a good model for the topology (while providing no information about trade volumes). An attempt to reconcile these two complementary and currently incompatible approaches has been recently proposed via the definition of an extension of the maximum-entropy model to the case of weighted networks [42]. Since, as we mentioned, a maximum-entropy model of weighted networks with given strengths and degrees [40] can correctly replicate many structural properties of the ITN [41], it makes sense to reformulate such model as an economically inspired model of the ITN. Indeed, like in the binary case, the hidden variables enforcing the constraints are found to be strongly correlated with the GDP, thus allowing to express both p ij and w ij as functions of the GDP [42]. The resulting model is confirmed to be in good accordance with both the topology and the volumes observed in the real ITN.
Unfortunately, in the above approach the choice of country-specific constraints (degrees and strengths) only allows for regressors that have a corresponding country-specific nature. This makes the model incompatible with the inclusion of dyadic variables of the type D ij and represents a strong limitation for (at least) two reasons. Firstly, one of the main lessons learnt from the traditional GM is that the addition of geographic distances improves the fit to the empirical volumes significantly. Indeed, in the light of the large body of knowledge accumulated in the international economics literature, it is hard to imagine a realistic and economically meaningful model of international trade that does not allow for simple pair-wise quantities controlling for trade 'costs' and 'incentives', including geography [9,10]. Secondly, even if the structure of the ITN can be replicated satisfactorily in terms of the 'GDP-only' model defined in 3 [25,30,32], recent analyses have found evidence that certain metric (although not necessarily geographic 2 ) distances do also play a role in determining the topology of the ITN [43]. Together, these two pieces of evidence call for an inclusion of dyadic factors in w ij and p ij , and highlight a limitation of current maximum-entropy models based only on country-specific constraints.
Combining all the above considerations, it is clear that an improved model of the ITN should aim at retaining the realistic trade volumes postulated by models based on 2 (including the GM, the RM, and possibly many more), while combining them with a realistic network topology generated by (extensions of) maximum-entropy models. Such a model should also aim at providing the full probability distribution, and not only the expected values as in 1, of trade flows and, unlike the GDP-only model in 3 [25] or its current weighted extension [42], allow for the inclusion of both dyadic and node-specific macroeconomic factors.

The Enhanced Gravity Model of international trade
In this Section, we introduce what we call the Enhanced Gravity Model (EGM) of trade. The EGM mathematically formalizes the two ingredients that, in the light of the previous discussion, any 'good' model of economic networks should feature: namely, realistic (trade) volumes and a realistic topology, both controllable by macroeconomic factors.

A single model for topology and weights
The first lesson we have learnt is that 2 is successful in reproducing link weights only after the existence of the links themselves has been preliminarly established. This implies that 2, as a model of real-world trade flows, is actually unsatisfactory and should rather be reformulated as a conditional expectation of the weight w ij , given that w ij > 0. In other words, if a ij denotes the entry of the adjacency matrix of the ITN (defined as a ij = 1 if w ij > 0 and a ij = 0 if w ij = 0), an improved model should be such that 2 is replaced by where w ij |a ij = 1 is the conditional expected weight of the trade link from country i to country j, given that such link exists. This operation ensures that, whatever the new model looks like, its predictions for the expected trade volume between connected pairs of countries remain identical to the ones proposed in more traditional macroeconomic models. For instance, ij as in 1 allows us to retain (in almost intact form) all the empirical knowledge that has accumulated in the econometrics literature since Jan Tinbergen's introduction of the GM. An important difference, however, is that in our model the trade volumes will be drawn from a different probability distribution.
The second lesson we have learnt is that, in analogy with 4, 3 should be generalized to allow for both dyadic (D ij ) and node-specific (n i ) factors as follows: where a crucial requirement is that G can in general be different from F in 4 and, correspondingly, the vector ψ of parameters can be different from φ. Note that, since p ij is monotonic in G, the above expression is entirely general, i.e. we have put no restriction on the functional form of p ij . It is also worth noticing that the explanatory factors used in 4 and 5 need not coincide. However, to avoid using different symbols for the arguments of the two functions, we adopt the convention that D ij and n i denote the sets of all factors used as arguments of either F or G, and that these functions can have flat (i.e. no) dependence on some of their arguments. For instance, 5 reduces to 3 by setting n i = GDP i and assuming flat dependence on D ij , or it reduces to the hyperbolic model in Ref. [43] by setting D ij equal to the hyperbolic distance and assuming flat dependence on n i . We want our model to produce both 4 as the desired (gravity-like) conditional expectation for link weights and 5 as a realistic expected topology. To do so, we introduce the full probability P (W) that the model produces a weighted network specified by the N × N matrix W with entries (w ij ). Without loss of generality, we assume that w ij is a non-negative integer number (allowing for non-negative real numbers is straightforward, upon taking the limit of a vanishing unit of weight, as we briefly discuss later). The probability P (W) is the key quantity that fully specifies the model and determines both the topology and the link weights of the ITN. From P (W), we can define the dyadic (marginal) probability q ij (w) that w ij takes the particular value w. Note that the event w = 0 indicates the absence of a trade link and is included as a possible outcome in q ij (w). The normalization condition is therefore w≥0 q ij (w) = 1 for all i, j. Note that we are not assuming independence of the trade volumes w ij and w kl between two distinct country pairs, or equivalently the factorization of P (W) into the product i,j q ij (w ij ) of dyadic probabilities. However, we will later find that the desired model has precisely this independence property. Importantly, unlike the traditional GM, in our approach dyadic independence is a consequence and not a postulate.
We now look for the form of q ij (w) that enforces both 4 and 5. Let us consider the latter first. In terms of q ij (w), the probability p ij that i and j are connected (irrespective of the volume of trade) is given by the complement of the probability q ij (0) that they are not connected, i.e.
Imposing that 6 has the form dictated by 5 leads to the following unique choice for q ij (0): We now relate q ij (w) to 4 in a similar manner. The expected trade volume, irrespective of whether a link exists, is while the conditional expectation, given that the link exists, is where q ij (w|a ij = 1) = q ij (w) is the conditional probability that w ij equals w, given that the link is realized. Setting 9 equal to 4 leads to 11 carries an important message. It reveals us that, while a superficial inspection of 8 might suggest that the expected trade volume w ij is independent on the topology of the ITN, i.e. on q ij (0) or equivalently G, this is actually not the case. In fact, q ij (0) is coupled to the other values q ij (w) (with w > 0) through the normalization condition manifest in 6. This necessarily implies that the topology of the ITN must have an immediate effect on the expected volume of trade between any two countries. This effect is rigorously quantified in 11, which shows that w ij depends on both F and G. This result confirms the inconsistency of the traditional GM defined in terms of 1 and of any of its extensions of the form 2. By contrast, the expected topology of the ITN is independent on the expected volumes of trade, since p ij depends on G but not on F . This simple but, to the best of our knowledge, previously unrecognized result highlights a nontrivial asymmetry between weights and topology in the ITN and, by extension, in any (economic) network described by our generic expressions involving F and G. This basic finding provides a natural explanation for the aforementioned empirical observation that the topology of the ITN and several other networks can be satisfactorily reconstructed from aggregate local constraints [26,40], while the same result does not hold for the weighted structure of the same network(s) [27,28], unless topological information is explicitly included as an additional constraint [40,41].
Maximum entropy construction 7 and 11 fix two important properties we require for q ij (w) and ultimately P (W), but they do not specify these probability distributions uniquely. To do so, we take the maximum-entropy approach and look for the form of P (W) that maximizes the entropy where the sum extends over all weighted graphs with N nodes and non-negative integer edge weights, subject to the constraints specified by 7 and 11. The maximum-entropy method ensures that the resulting functional form of P (W) is maximally random, given the desired constraints. As well known, this procedure is guaranteed to lead to the least biased inference, i.e. to introduce no unjustified 'hidden' assumption in picking a specific form of P (W). Since 7 is equivalent to 5, we select a ij and w ij as the two sets of constraints specifying our model. In this way, if we introduce α ij and β ij as the (real-valued) Lagrange multipliers required to enforce the expected value of a ij = Θ(w ij ) and w ij respectively (where Θ(x) = 1 if x > 0 and Θ(x) = 0 otherwise), then the maximumentropy problem becomes equivalent to one solved exactly in Ref. [44]. There, it was shown that upon introducing the so-called Hamiltonian (representing a linear combination of the quantities whose expected value is being constrained) and the partition function Z = W e −H(W) , the maximum-entropy probability P * (W) with constraints a ij and w ij is found to be where, given x ij ≡ e −α ij ∈ (0, +∞) and y ij ≡ e −β ij ∈ (0, 1), is the resulting (maximum-entropy) probability that the link from node i to node j carries a weight w. This probability is called the Bose-Fermi distribution, as it unifies the Bose-Einstein and Fermi-Dirac distributions encountered in quantum statistical physics [44]. We stress again that all our formulas apply to both directed and undirected representations of the network and, correspondingly, the sums and products over i, j should be interpreted as i = j in the directed case (where the pairs i, j and j, i are different) and as i < j in the undirected one (where the pair i, j is the same as the pair j, i). As we had anticipated, the factorization of P * (W) in terms of products of q * ij (w) shows that, for this particular choice of the constraints, pairs of nodes turn out to be statistically independent as in the standard GM approach, even if we have not assumed this independence as a postulate in our approach.
Importantly, while the constraints used in the maximum-entropy models of the ITN considered so far in the literature are observed topological properties (e.g. the degrees and/or the strengths of nodes), the constraints considered here are economically-driven expectations, namely 5 and 11. This key step allows us to reconcile macroeconomic and network approaches within a generalized framework, and represents an important difference with respect to previous models. In particular, we use 6, 8 and 9 to express p ij , w ij and w ij |a ij = 1 in terms of x ij and y ij [44]: Now, equating 16 to 5 and 17 to 11 (or, equivalently, 18 to 4) allows us to find the values of x ij and y ij solving the original problem: Inserting 19 and 20 into 15, we finally get the explicit probability of any two countries trading a volume w, as a function of any choice of the factors n i and D ij . In terms of conditional probabilities, our model becomes extremely simple: establishing a link from country i to country j is a Bernoulli trial with success probability p ij given by 5; if realized, this link acquires a weight w with probability which is a geometric distribution representing the chance of w − 1 consecutive successes, each with probability y ij , followed by a failure with probability 1 − y ij . The above result provides an insightful interpretation of the realized volumes in the model in terms of processes of link establishment and link reinforcement (see Discussion).

Maximum-likelihood parameter estimation
We now take an econometric perspective and discuss how the model parameters can be chosen to optimally fit a specific empirical instance of the network. To this end, we use the Maximum Likelihood principle applied to network models [38]. If W * denotes the weight matrix (with entries w * ij ) of the empirical network, our model generates this particular matrix with probability P * (W * ). We therefore define the log-likelihood function as (where we have dropped the dependence of F and G on n i , n j and D ij ) and look for the parameter values φ * , ψ * that maximize L by requiring that all the first derivatives with respect to φ and ψ vanish simultaneously: Upon checking that the second derivatives have the correct sign, i.e. that L(φ * , ψ * ) is indeed a maximum for L, the solution (φ * , ψ * ) to the above equations yields the optimal parameter values in our model. Selecting these values into 19 and 20 yields the values x * ij and y * ij that, when inserted into 15, fully specify the model. The above expressions, which are valid any specification of the EGM, show that the estimation of the parameter φ nicely separates from that of ψ. This result solves, in a single shot, two major problems encountered in previous econometric approaches: on one hand, in most alternative models the estimation of the parameters determining the expected weights is badly affected by the presence of the zeroes; on the other hand, the expected number of zeroes may paradoxically depend on the (arbitrary) units of measure for the weights. For instance, if q ij (w) is a Poisson distribution as in zeroinflated GMs [20,21,22], then its only parameter (the mean) determines both the magnitude of link weights and the connection probability p ij . As the units of money in the data are changed arbitrarily (e.g. from dollars to thousands of dollars), so will the estimated mean and the resulting expected number of zeroes. By contrast, in our model the zeroes affect ψ but not φ and the money units affect ψ but not φ.

Empirical analysis
We can finally test the predictions of our model against empirical international trade data. These predictions are found to improve dramatically upon those of the traditional GM.

Model specification
We adopt an undirected network description (where the connection between two countries carries a weight equal to the total trade in either direction) to facilitate the definition of the topological properties characterizing the ITN. Previous work has shown that, given the highly symmetric structure of the ITN, the undirected representation retains all the basic properties of the network [30,26,27].
We choose F φ (n i , n j , D ij ) in such a way that the expected non-zero trade flow w ij |a ij = 1 is the same as in the GM defined by 1 (now interpreted as a conditional expectation). This means choosing n i = GDP i , D ij = R ij , φ = (c, α, γ) and where we have set β = α due to undirectedness. Similarly, we choose G ψ (n i , n j , D ij ) in such a way that the probability p ij is the same as in the model defined in 3, i.e. ψ = δ and With the above specification, the expected topology does not depend on any dyadic factor. This is the simplest choice that is found to reproduce the topology of the ITN very well [25,30,32,38] and is supported by empirical evidence that dyadic factors like geographic distances [45] and trade agreements [43] have a much weaker effect on the purely binary topology of the ITN than on trade volumes. Of course our formalism has been designed in such a way that we can immediately add dyadic factors, and is therefore much more general. For instance, we might easily add 'hidden' metric distances inferred via an optimal geometric embedding [43] (although they would not be identifiable with some empirically measurable, 'external' macroeconomic factors like those used elsewhere in our model). Given the above model specification, for a given instance W * of the empirical network we find the optimal parameter values c * , α * , γ * and δ * through the maximum likelihood conditions given by 23 and 24. Importantly, 24 reads in this case ∂L/∂δ = 0 and yields a value δ * that ensures that the expected number of links i,j p ij = i,j G ψ /(1 + G ψ ) is exactly equal to the empirical number L * = i,j a * ij , irrespective of the volumes of trade. This result, which is equivalent to what is found for the purely binary model defined by 3 [38], shows that, unlike the standard GM, our model always generates the correct number of links and, unlike some more complicated variants of the GM, it does so independently of the money units chosen for the volumes.

Testing the model against real data
We first test the performance of the EGM in replicating the empirical trade volumes, i.e. the purely local structure of the ITN. In Fig. 1, superimposed to the previous results for the standard GM given by 1, the empirical non-zero link weights w * ij are also compared with their conditional expected value w ij |a ij = 1 under the EGM given by 25. As expected, the two sets of points largely overlap, confirming that, in terms of trade volumes, the EGM cannot do worse than the GM. Moreover, the EGM is more parsimonious than the GM as it achieves a narrower scatter of points while having no dedicated free parameter to tune the variance.
We then check the performance of the EGM in replicating the purely binary topology of the ITN. As a first illustration, in Fig. 2 we show all the trade links of the country with maximum degree (USA), the one with minimum degree (Western Sahara) and one with intermediate degree (Vanuatu). We also show the corresponding predictions under the standard GM (where 1 is first fitted to the non-zero flows and then extended to all pairs of countries) and the EGM. Since the traditional GM predicts a fully connected network, i.e. an expected degree k i GM = N − 1 for all i, its prediction is correct only for the country with maximum degree and deteriorates dramatically as the degree decreases. By contrast, the EGM gives an expected degree k i EGM = j =i p ij (see Materials and Methods) which is in good agreement with the empirical one for the entire range of connectivity.
We now consider higher-order topological properties as a more stringent and quantitative test. In the top left panel of Fig. 3 we plot the average degree (k nn i ) of the trade partners of each country i versus the number of such partners, i.e. the degree (k i ) of country i itself. Similarly, in the top right panel of Fig. 3 we plot the clustering coefficient (c i ), i.e. the fraction of trade partners of country i that trade with each other, again versus the number (k i ) of such partners. The empirical quantities are compared with the expected quantities under the GM and the EGM. The exact expressions for both empirical and expected quantities are provided in Materials and Methods. The decreasing empirical trends observed in both plots shows that the trade partners of poorly connected countries (small k i ) are on average highly connected, both to the rest of the world (large k nn i ) and among themselves (large c i ). By contrast, countries that trade with a high-degree country (large k i ) are on average poorly connected, both to the rest of the world (small k nn i ) and among themselves (small c i ). For both properties, we find that the EGM is in excellent agreement with the empirical ITN, as opposed to the classical GM which systematically generates nearly constant and much higher values, as a result of predicting a complete network.
Having checked that the EGM does very well in separately replicating both the local link weights and the global topology of the ITN, we now perform a last and most severe test monitoring properties that combine topological and weighted information together. In the bottom left panel of Fig. 3  . These two plots are in some sense the weighted counterparts of the purely binary plots considered above. We find that, on average, countries connected to countries with a low trade activity (small s i ) trade a lot with the rest of the world (large s nn i ) but relatively less among themselves (small c w i ). Countries connected to countries with a large volume of trade (large s i ) have instead a small trade activity with the rest of the world (small s nn i ), but trade relatively strongly with each other (large c w i ). Again, we find that both trends are replicated very well by the EGM, while the standard GM fails systematically.

Discussion
In this paper we have introduced the EGM as a novel, advanced model for the ITN and economic networks in general. Phenomenologically, the EGM allows us to reconcile two very different approaches that have remained incompatible so far: on one hand, the established GM which successfully reproduces non-zero trade volumes in terms of GDP and distance, while failing in predicting the correct topology [22]; on the other hand, network models which have been successful in reproducing the topology [25] but are more limited in predicting link weights [42]. To our knowledge, the EGM is the first model that can successfully reproduce the binary and the weighted empirical properties of the ITN simultaneously. Just like the standard GM, the RM [11] or similar models, the EGM can accomodate additional economic factors in terms of extra dyadic and country-specific properties.
The agreement between the EGM and trade data calls for an interpretation of the process generating the network in the model. In this respect, we notice that 15 and 21 allow us to interpret the realized trade volumes in the EGM as the outcome of two equivalent processes (a serial and a parallel one) of link creation and link reinforcement. In the serial process, for a given pair of countries i, j a trade link of unit weight is first established with success probability p ij and its volume is then incremented in unit steps, each with success probability y ij . After the first failure, the process stops and starts again for a different pair of countries, and so on for all pairs. In the equivalent parallel process, all pairs of countries simultaneously explore the mutual benefits of trade and engage in a first connection, each with its probability p ij . Then, all pairs of nodes for which the previous event has been successful reinforce their existing connection by a unit weight, each with its probability y ij . The process stops as soon as there are no more successful events. In either case, 15 is the resulting probability that the realized volume is w.
Importantly, 15 implies that q * ij (w) is a geometric distribution with an extra point mass q * ij (0) at zero volume, i.e. the first event has a probability p ij which is in general different from the probability y ij of all subsequent events. This distinguishing property of the Bose-Fermi distribution [44] ensures a realistic network formation mechanism where the establishment of a trade connection for the first time is intrinsically different (and therefore associated to a different 'cost') from the reinforcement of an already ex-isting trade connection. This desirable distinction, interpretable for instance in terms of profitability of trade, has been advocated in previous studies [9,10,21]. Here, it is implemented naturally within the maximum-entropy framework via 13, where the (expected) binary topology is enforced separately from the (expected) link weights. Notice that the distinction disappears if the parameter α ij in 13 is set to zero, i.e. if the constraint on the expected value of Θ(w ij ) (the expected topology) is removed as in the standard GM. In such a case, p ij becomes equal to y ij (i.e. link creation and link reinforcement become equally likely) and therefore q * ij (w), not only q * ij (w|a ij = 1), becomes a geometric distribution.
Consistently with the fact that trade volumes are always reported as integer multiples of some indivisible money unit (e.g. dollars), we have assumed non-negative integer weights. It is easy to show that, if we take the limit of a vanishing money unit, trade volumes become non-negative real numbers and q * ij (w) becomes an exponential density with an extra point mass at zero volume, while q * ij (w|a ij = 1) becomes a purely exponential density. Crucially, the extra point mass q * ij (0) ensures that, even in this continuous limit, p ij is unchanged and the topology is still described by 5. In absence of α ij , in this limit the network would become fully connected as in all specifications of the GM with continuous volumes [39].
Our results may have strong implications for the theoretical foundations of trade models and for the resulting policy implications. It is known that the traditional GM is consistent with a number of (possibly conflicting) micro-founded model specifications [46,47,48,49]. For instance, a gravity-like relation can emerge as the equilibrium outcome of models of trade specialization and monopolistic competition with intra-industry trade [10,50]. The empirical failure of the standard GM highlights a previously unrecognized limitation of these micro-founded models, at least in their current form, and indicates the need for an appropriate reformulation that makes these model consistent with the EGM, i.e. with a realistic topology of the ITN. How policy implications change as the result of such a reformulation of current micro-founded models is an important point to add to the future research agenda. We therefore believe that the EGM can represent a novel benchmark supporting improved theories of trade and refined policy scenarios.

Data
We have used international trade and GDP data from the database curated by Gleditsch [51] for the years 1950, 1960, 1970, 1980, 1990 and 2000. This database includes yearly trade volumes w ij (which we have symmetrized by taking the sum of w ij + w ji ), yearly GDP values, and the (time-independent) distance matrix R ij . The numer N of countries increases over time from roughly 85 in 1950 to approximately 200 in 2000. Both GDP and trade date are reported in U.S. dollars. To produce Fig. 2, we have used the BACI database [52], which reports imports and exports between N = 208 countries in 2011. The BACI data were originally in disaggregated form, where total trade was resolved into 96 different non-overlapping commodity classes. We have aggregated all these commodity classes together, and again symmetrized, to obtain a dataset consistent with the Gleditsch data used for the earlier years.

Observed network properties
Given a weighted undirected network with weight matrix W and adjacency matrix A, with entries related through a ij = Θ(w ij ), the degree of node i is defined as the average nearest-neighbor degree of node i is defined as and the (binary) clustering coefficient of node i is defined as The average nearest neighbor strength of node i is defined as (where s i = j =i w ij is the strength of node i) and the weighted clustering coefficient of node i is defined as

Expected network properties
The expected value (under the EGM) of each of the network properties defined above can be calculated either numerically, by averaging over many network realizations sampled independently from the probability P * (W) in 14, or analytically, using the following approach. First of all, in this model the expected value of all ratios can be approximated by the ratio of the expected values [40,41]. Secondly, all numerators and denominators involve only products over distinct pairs of nodes, which are statistically independent in the model. Using 15, the expected values of such products can therefore be calculated exactly in terms of x ij and y ij as follows: i,j,k,... a ij · a jk · ... = i,j,k,... a ij · a jk · ... , i,j,k,... w α ij · w β jk · ... = i,j,k,... w α ij · w β jk · ... , where a ij = p ij , as given by 16, and Li n (z) = ∞ l=1 z l l n denoting the so-called n−th polylogarithm of z. From the above two considerations, it follows that the expected properties of all quantities of interest can be approximated with entirely analytical expressions obtained by simply replacing a ij with p ij and w γ ij with w γ ij in 27, 28, 29, 30 and 31. Via x ij and y ij , the expected values are ultimately a function of only the GDPs and distances. In our analysis, after preliminary checking that the analytical expressions matched extremely well with the numerical averages over realizations, we have systematically adopted the analytical approach, which requires no sampling of networks and is therefore extremely efficient. 2000. The black line is the identity line corresponding to the ideal, perfect match that would be achieved if empirical weights were exactly equal to their (conditional) expected values, i.e. in absence of randomness. The results for the two models largely overlap, the main difference being in the fitting procedure and resulting from the fact that the EGM predicts an exponential (plus delta at zero) volume distribution, while the GM predicts a multiplicative gaussian distribution. Note that, even though the expression for the conditional volumes are the same and the same macroeconomic factors have been chosen in both models, the EGM is more parsimonious as it achieves a narrower scatter of points while not requiring an extra free parameter (which is instead required in the GM) to estimate the variance. . The GM produces always the maximum number (N − 1) of connections. By contrast, the EGM produces connections randomly with probability p ij , so links change from realization to realization. The expected degree is however independent of the individual realizations and is close to the empirical one for all countries. We have selected a typical realization that produces a degree equal to the expected degree for each of the three countries.