Formation of trade networks by economies of scale and product differentiation

Understanding the structure and formation of networks is a central topic in complexity science. Economic networks are formed by decisions of individual agents and thus not properly described by established random graph models. In this article, we establish a model for the emergence of trade networks that is based on rational decisions of individual agents. The model incorporates key drivers for the emergence of trade, comparative advantage and economic scale effects, but also the heterogeneity of agents and the transportation or transaction costs. Numerical simulations show three macroscopically different regimes of the emerging trade networks. Depending on the specific transportation costs and the heterogeneity of individual preferences, we find centralized production with a star-like trade network, distributed production with all-to-all trading or local production and no trade. Using methods from statistical mechanics, we provide an analytic theory of the transitions between these regimes and estimates for critical parameters values.


Introduction
Trade networks are essential to today's international economy [1,2]. From supply chains to financial transactions, goods and values are exchanged among almost every region on Earth. The importance of economic connectivity and complexity becomes most obvious in case of a disturbance: The world financial crisis of 2007/2008 emerged after interbank claims and liabilities had been growing for decades, enabling a rapid spread of financial risks [3,4]. Similarly, disruptions of global transportation networks due to the Covid-19 pandemic have led to a substantial loss of production in various regions [5].
The emergence of connectivity and the structure of networks are essential topics in complexity science [6,7,8]. Traditionally, ensembles of random networks have been used to describe essential features of real-world networks such as the small-world effect or the emergence of hubs [9,10]. On the one hand, percolation theory enables farreaching insights into the formation and robustness of ensembles of networks [11]. On the other hand, optimization models have been used to describe the structure of biological networks [12,13], assuming that evolution created structures that provide a certain function in an optimal way. Both approaches are of limited use in the modeling of economic networks, where links are neither established at random, nor following a single, global objective. Instead, links are established deliberately on the basis of individual decisions.
The emergence of trade is a central subject of economics. In the celebrated Ricardian model, trade patterns are determined by the regional differences in productivity providing a comparative advantage [14]. Initially formulated in terms of productivity of labor, the Ricardian model was later generalized and formulated in terms of opportunity costs [15]. Predictions of these trade theories have been tested in various empiric studies, see [16] for a recent example. A comparative advantage typically arises when the trading countries have strongly different characteristics. Explaining the emergence of trade between similar countries required a substantial extension of the theory. In a landmark study from 1979 [17], Krugman pointed out the importance of economies of scale and transportation costs. Economic scale effects foster the centralization of production, as they lead to lower production costs for large producers and thus to advantages in competition. Transportation costs may lead to a home market effect, where regions or countries with a higher demand have an advantage and tend to export a good. Mathematical models in this field often feature the Dixit-Stiglitz model of consumer preferences in terms of a utility function with a constant elasticity of substitution [18]. Krugman later extended these ideas towards a comprehensive theory of trade and economic geography [19]. Notably, economies of scale can also lead to lock-in effects [20]. A well readable introduction to this topic is provided in the text book [1].
However, transportation and production costs are not the only attributes that determine economic interactions and trade. Discrete choice theory investigates how economic agents reach a decision on the basis of both observed and unobserved attributes [21,22]. The agents' preferences vary, in particular with respect to the unobserved attributes, and so do the agents' choices. Thus, discrete choice models are intrinsically stochastic, describing the probability of choice on an individual level or the demand for certain goods or brands on an aggregate level. As a consequence, populations of heterogeneous consumers demand differentiated goods [23,24].
Recent research in statistical mechanics and network science has provided a variety of empirical insights into the structure of international trade networks. Early studies of the structure of trade networks have shown a scaling behaviour [25] and the correlations between different commodities [26]. An explanation for the observed scaling has been suggested in [27] in terms of a fitness model. Changes in the world trade network in the last decades were studied in [28,29], pointing out the importance of (fractal) geography to understand trade patterns and quantifying the robustness to economic shocks.
In this article we establish a model for the formation of trade networks combining essential concepts of economics and statistical physics. Trade links are established by the decisions of individual agents taking into account differentiated preferences in the spirit of discrete choice theory. The cost functions incorporate economic scale effects, making the decision problems nonlinear and interdependent. Statistical physics guides the numerical solution of the problem as well as the analysis of the results. We compute the 'phase diagram' of the emergent trade network using a self-consistent method and provide an approximate analytic theory for the transitions between different regimes of the emerging trade network. The current article generalizes previous models [30,31] which neglected product differentiation and focused solely on percolation aspects.

Discrete choice Theory
Discrete choice theory considers individual agents or consumers which may choose from different discrete options. The preferences of the individuals vary leading to product differentiation [22,21,23,32] To formalize this model, we consider a set of nodes or vertices i ∈ {1, . . . , N } representing well-defined spatial units, each inhabited by a large number of agents D i . A single agent a at node i chooses to purchase a good from different nodes j ∈ {1, . . . , N } at different effective pricesp ji . However, the price is not the only factor that determines consumer behavior and preferences generally differ. Hence, the utility of an individual agent a for a good from node j is with a constant term U 0 > 0. It is assume that the utility of a good from node j decreases as the effective pricep ji increases which holds for all agents alike. The difference of the individual preferences of the agents a are summarized in the ϵ a (j), which is typically unknown a priori and thus modeled as random variables. The parameter T > 0 measures how strongly preferences vary between individual agents. A common assumption in the economic literature is that the ϵ a (j) are independent and identically Gumbel distributed, which leads to the classic multinomial logit model [23,32]. The probability of an agent a at node i choosing alternative j is then given by Now consider the cumulative purchases S ji made by all agents at node i from all nodes j ∈ {1, . . . , N }. Assuming that the number of agents D i at node i is sufficiently large, we can replace the amount by its expected value and obtain This expression is the starting point of our analysis. In the limiting case T → 0, differences between the agents at a node i vanish and all agents purchase from the same node j = i * for which the prices are smallest, where i * = argmin jp ji . Finally, we remark that the total expenses of all agents at node i in the discrete choice model are given by

Transportation costs and economies of scale
An important goal of our work is to study the role of transportation costs and scale effects on the formation of economic networks. We incorporate these aspects in terms of the consumer pricesp ji that an agent at node i has to pay when buying goods from node j. First, we assume that consumers have to pay for the transportation of the good from the production site. As a first order approximation, transportation costs increase linearly with the distance E ij = E ji of the nodes i and j. Hence, the price per good for a consumer at node i is the sum of the local pricep jj at the production location and the transportation costs per unit good, The symbolp T denotes the transportation costs per unit of goods and per unit of distance. This quantity typically decreases over time as the technology in the transportation sector advances. The transportation network and the distance E ji are discussed in detail below. Second, we assume that the production is subject to economies of scale. The higher the total production, the lower the production costs per unit. Denoting the total production at the node j as S j , we thus assume thatp jj (the price without transportation) decreases monotonically with S j . In this article, we assume an affine linear relation for the sake of simplicitỹ where the parameterã describes the strength of the scale effects. We assume that the parametersb j andã are such thatp jj (S j ) > 0 is always satisfied. To close the model, we express the production S j in terms of the purchases S ji . Assuming that the production is sold completely, it must equal the purchases from all other nodes in the network such that For the further analysis, we define the total production at the largest supplier in the system S * = max{S 1 , S 2 , ..., S N } (9) to characterize the degree of centralization of production. To summarize, the consumer prices that an agent at node i has to pay for goods from node j are given bỹ The economic model is now complete up to the definition of the E ji which will be provided in the following section. Notably, the choices of the agents at a node i depend on the choices of all other agents via the total production S j entering the prices. This interdependency introduces strong collective effects and essentially complicates the numerical solution as discussed in section 2.5.
In summary, we have introduced a model that describes different preferences of the agents as well as a complex cost function featuring production costs, transportation costs and economies of scale. The model includes three global parameters: (i) the parameter T that describes the importance of the diversity of the agents' preferences compared to the price differences, (ii) the specific transportation costsp T and (iii) the strength of economic scale effectsã.  The roles of the system parametersp T and T are sketched in figure 1. If the specific transportation costsp T are high and the diversity of preferences T is low, we find local production, that is S ii = D i and S ji = 0 for i ̸ = j. A trade network can then emerge through two different mechanisms: (i) Ifp T decreases, it becomes cheaper for an agent to satisfy its demand by imports than by local production. This route to trade is strongly promoted by the scale effects of production [30]. Once a node starts to export goods, production costs per unit and thus the pricesp jj (S k ) decrease, facilitating further exports. (ii) If T increases, the preference for a diverse supply causes agents to more evenly distribute their purchases despite additional transportation costs. Eventually, an all-to-all connected network of trades emerges. We study the different routes to the emergence of a trade network in detail in sections 3 and 4.

Transportation and trade networks
The model introduced above describes the emergence of trades in terms of the purchases S ji on a underlying transportation network, determining the distances E ji . To study the model numerically, we generate ensembles of geographically embedded transportation networks as follows. First, a number of nodes is placed uniformly at random in the unit square with periodic boundary conditions, which is equivalent to a two-dimensional torus. Second, these nodes are connected using Delaunay triangulation. The length of an edge (i, j) is given by the Euclidean distance of the terminal nodes i and j with respect to the periodic boundary conditions. The distance E ij from node j to node i is then given by the geodesic distance on the transportation network. Figure 2 shows an example of the generated transportation network as well as the emerging trade network from an exemplary simulation for T = 0 and decreasing specific transportation costp T . For very high values ofp T the supply matrix is diagonal, S ii = D i and S ji = 0 for j ̸ = i, such that the trade network is fully disconnected. Whenp T is gradually lowered, some nodes start to purchase their goods at other nodes, represented by colored stars. The emerging trade network is thus composed of clusters with a single supplier (identified by different colors in figure 2). For very smallp T , the production becomes increasingly centralized such that one cluster grows until it contains all nodes.

Aggregated Interpretation
In this section we provide an alternative interpretation for the purchases (3) on an aggregate level. Consider the functions for all nodes i = 1, . . . , N with a constant F 0 and Now consider the purchases that maximize the function F i while respecting the constraint That is, all purchases made by agents at the node i must sum to D i . The maximum can be computed by using the method of Lagrangian multipliers, leading to the conditions Solving these conditions yields which is equivalent to the expression (3). The maximum of the function F i has be to be evaluated for all nodes i = 1, . . . , N -but these optimization problems are not independent. Every function K i depends on the production S j at all nodes and hence on the results of the optimization problems of all nodes in the network. We thus have to interpret the purchases (15) as a Nash equilibrium: No node i can further increase the function F i by changing its purchases S 1i , . . . , S N i while the purchases of all other nodes remain constant.
We have thus introduced an alternative, macroscopic approach that reproduces the aggregated purchases obtained from discrete choice theory. The aggregated purchases of node i maximize the function F i (S 1i , . . . , S N i ), which may thus be interpreted as an aggregated effective utility function. We propose the following interpretation of this aggregated utility, proceeding term by term. First, there is a constant term F 0 describing the utility from using a good. Second the function H i coincides with the Gibbs entropy, which measures the diversity of the purchases. Hence, the aggregated utility increases with the diversity of supply. The strength of this effect is measured by the parameter T . Finally, the utility is reduced by the function K i . We consider the case of a large network with N nodes where production is not fully centralized such that Then we have Hence, K i is approximately equal to the total expenses (5) of the agents at node i divided by the number of agents D i . We finally note that the negative function, −F i = K i − T H i , has a similar form as the Helmholtz free energy in the study of closed thermodynamic systems. Because of this structural similarity, we refer to the weighting factor T as the effective temperature of the economic system in the following. The similarities to statistical physics will further guide our analysis of the system and provide methods to quantitatively understand the transitions between different trade regimes.

Numerical solution
The equilibrium state of the trade network will be analyzed via numerical simulations. In all numerical simulations we fix the system parameters as follows. First, we assume that the nodes are chosen such that they contain the same number of agents such that where D tot is the total number of agents. Furthermore, we will a denote the purchases S ji and productions S i in units of D tot . In these rescaled units, all purchases sum up to one, j,i S ji = 1. Furthermore, we have S ii = 1/N when the purchases are fully local (i.e. S ji is diagonal) and S * = 1 when the production is fully centralized at a single node. The pricesp ji depend on three essential parameters,ã,b j andp T . For consistency with prior work, we scale all these parameters with the factor D, Hence, the approximation (18) now reads K i = ℓ p ℓi S ℓi . The parameter b i is chosen uniformly at random from an interval b 0 +[0, 0.005] for each node. The parameters a and p T are varied to analyze how scale effects and transportation costs scale the emerging trade network. In the simulations, we use N = 300 unless stated otherwise.
In the model developed in the previous section, purchases and prices are linked via the conditions (10) and (3). Notably, both equations are coupled: The purchases depend on the prices, but the prices also depend on the purchases through the production S j . Both equations have to be solved self-consistently.
Based on these considerations, we establish the following self-consistent algorithm to compute the equilibrium purchases as a function of the system parameters. Starting from a suitable initial guess for the purchases S ji , we compute the resulting prices (10). Given these prices we can directly compute a new value for the purchases (3). This procedure is iterated until no further changes in the purchases occur. Once the iteration converged, the resulting state satisfies both conditions (10) and (3) simultaneously such that we arrived at an equilibrium.
We emphasize that the model can support multiple solutions [30]. In such a situation it depends on the initial guess which one is found and if the iteration terminates at all. In the numerical simulations, we use the following algorithm to compute how the equilibrium states depends on the parameters a, p T and T : (i) We fix a value of a > 0 and a transportation network as described above.
(ii) We start at T = 0 and p T = ∞, where the equilibrium state is given by S ii = 1/N and S ji = 0 for j ̸ = i, i.e. fully local production.
(iii) We then compute the equilibrium states along the line T = 0 by decreasing p T to zero. This computation follows the semi-analytic algorithm introduced in [30].
(iv) We define a grid of values for p T and T for which the supply matrix S ji is to be computed. We choose the minimum (maximum) value of p T such that production is fully centralized (local) for T = 0. The step size is chosen uniformly on a logarithmic scale. We then compute the equilibrium states as a function of T and p T : (a) For each value of p T on the grid, we proceed from T = 0 to T = T max .
(b) For a given value of p T and T we start from an initial guess for the purchases S ji . For T > 0 we use the solution of the previous, smaller value of T . For T = 0 the exact solution S ji is known from the step (iii). (c) We compute the prices p ji from equation (10) and update the purchases S ji using equation (3). (d) We iterate this procedure until it converges. Convergence is assumed when the Frobenius norm of the difference of the previously calculated and the updated purchase matrix decreases below 10 −8 .
(v) The procedure is repeated for different random realizations of networks to average out the impact a single network might have on the position and behavior at the phase transition.

Phase diagram of the trade network
How do the decisions of individual agents lead to the emergence of trade? In this section we provide an overview of the emerging trade networks and how they depend on the preferences of the agents, the properties of the transportation network, and the economic scale effects. To this end, we compute the equilibrium purchases S ji using the self-consistent method introduced in section 2.5 as a function of the parameters p T , T , and a. We average over 100 random realizations of the transportation network model (cf. section 2.3) to map out the typical behavior independent of the randomly chosen network. Single realizations will be treated in a subsequent section. Figure 3 shows two macroscopic observables that characterize the emerging trade network on large scales. The normalized maximum production, quantifies the degree of centralization of the production, where the brackets denote the average over the transportation network ensemble. If µ S is close to unity, the production is strongly centralized at a single node. The average entropy measures the diversity of supply as described in section 2.
Based on the observables µ S and µ H , we identify three different regions in parameter space that display qualitatively different patterns of the emerging trade networks: I. If the specific transportation costs p T are high and the effective temperature T is low, we have That is, all agents purchase their goods locally as imports would be too expensive.
No trading takes place in this phase such that the purchase matrix is given by We refer to this phase as the local production phase in the following.
II. If the unit transportation costs p T decrease, while the effective temperature T is still low, we find That is, the production becomes completely centralized at a single node j and the purchase matrix can be written as We refer to this phase as the centralized production phase in the following.
III. If the effective temperature T is high, the differences of the agents' preferences dominate while different prices play a negligible role. Hence, we observe a phase with an average entropy close to the maximum possible value, In this phase every node purchases a similar amount of goods from every other node such that the purchase matrix reads We thus find a globally connected trade network, where every node produces the same amount of goods, lim T →∞ µ S = 1/N , as in phase I but exports and imports from all other nodes. We refer to this phase as the diverse production phase in the following.
For a better overview, we extract a comprehensive phase diagram from the values of µ S and µ H in our simulations as follows. For both quantities, we determine the minimum and maximum values found in the simulations and choose the midpoints of the respective intervals as a threshold value. We then compute the areas in the phase diagram, where the observables µ S and µ H are above or below the respective thresholds. The red and green lines in figure 3 depict the boundary between these areas. Together, they reveal the boundary between the different phases I, II and III.
The resulting phase diagram in figure 3 on the right shows most clearly how the equilibrium trade network depends on the parameters p T and T as well as the strength of the scale effects a. We find that the three phases exist for all values a, but the location and nature of the phase boundaries depend strongly on a. Scale effects foster a centralization of production, such that the parameter region corresponding to centralized production (phase II) increases with a.
We observe qualitatively different transitions between the three phases: • The transition between local and diverse production (I-III) is smooth. The phase boundary is a straight line p T /T = const.
• The transition from local to centralized production (I-II) is rather sharp and the phase boundary is almost given by a horizontal line, i.e. a constant value of p T . However, a slight incline of the phase boundary becomes visible for large a, such that the transition can in principle also be triggered by a decrease in T . In economic terms, centralization of production is driven by a reduction in the specific transportation costs p T . This process is facilitated by scale effects, which make the transition occur earlier (i.e. for larger values of p T ) and more rapid. This scenario is mostly, but not perfectly, independent of the consumer preferences expressed by the parameter T .
• The transition between centralized and diverse production (II-III) is also very sharp and the phase boundary is almost given by a vertical line, i.e. a constant value of T .
In economic terms, a change in the nodes' preferences can trigger a transition at low specific transportation costs p T . If the agents' preferences vary only little (low T ), then decisions are dominated by prices and production is centralized at a single node. If the agents' preferences vary strongly (high T ), prices play a minor role and the production is decentralized. Remarkably, the transition occurs abruptly as T increases.
• A particular behavior is observed around the triple point of the phases I, II, and III.
For certain values of T , we find a non-monotonic behavior of µ H . Decreasing the unit transportation costs first induces a transition from local to diverse production, and then a transition to centralized production. Hence, µ H first increases and then decreases back to values around zero. We note, however, that the system can have multiple equilibria [30], of which only one is analyzed here.

Transitions between different regimes
We now investigate the transitions between the three phases of the trade network in more detail. We discuss the type of the transition and derive approximate analytic expressions for the locations of the phase boundaries.

From local to centralized production
The transition from phase I to phase II describes the centralization of production as the price for transportation decreases, while the diversity of the agents' preferences does not play a central role. The remarkable feature of this transition is that it can be either continuous or discontinuous depending on the value of a [30]. A discontinuity is the direct consequence of scale effects in the production. If agents at a node i chooses to purchase goods at a node j instead of locally, the production costs per unit at node j decrease due to scale effects. Now the agents at another node i ′ can purchase goods from j at a lower price. If this effect is strong enough, agents at i ′ may also choose to change their purchases and buy at j instead, which leads to a further decrease of production costs at j. Eventually, we may find a cascade of decisions, where a large fraction of agents simultaneously change their purchases and the production is centralized at node j.
We analyze the transition in more detail, starting from the simplest case T = 0 [30]. In this case the differences between the preferences of agents vanish and all agents at a node i purchase from same node i * which yields the lowest price, see equation (4). We will thus treat a node as a single entity in the following analysis.
If a = 0 (and T = 0) the maximum production S * changes in discrete steps of D as p T is reduced. For T = 0, all agents at a node i have the same preferences and choose a single supplier node. If node i chooses to buy at node j instead of a node ℓ, the effective price node i pays per units changes by Hence, a node i will change its purchases if . These values of p T are distinct for all nodes and potential suppliers with probability 1, such that changes in the purchases occur only in single events at different values of p T . Hence, in the thermodynamic limit N → ∞ with constant total demand N D constant, the transition from phase I to phase II is continuous [30]. If a is large (and T = 0), the transition is generally discontinuous in the following sense. If p T is reduced, the maximum production S * changes by a macroscopically large amount ∆S * at a critical value of p T . This is due to a cascade of decisions of the individual nodes: If a node i chooses to purchase from another node j instead of buying locally, the price p jj at node j decrease by an amount aD. This decrease may be sufficiently strong to cause another node i ′ to also purchase from j instead of buying locally. In the end, a macroscopic fraction of the nodes decides to change its purchases simultaneously. We note that the difference between continuous or discontinuous transitions is not visible in figure 3, as the phase diagram shows the average over many random realizations of the underlying transportation network. In contrast, a clear difference is observed for a single realization as shown in figure 4.
For extremely large values of a we may even find a complete centralization in a single event, i.e., ∆S * = (N − 1)D. We make this statement more precise now. To this end, we order the nodes n ∈ {1, . . . , N } as follows. The nodes (j, i) = (1, 2) are chosen such that they have the lowest value of (b j − b i ) + E ji , that is The remaining nodes n ∈ {3, . . . , N } are ordered such that the series is monotonically increasing. Furthermore, we assume that This condition is typically satisfied if the differences in the parameters b i are small. Then we find the following statement: If scale effects are extremely strong, the maximum production changes from S * = D to S * = N D when the transportation costs per unit are decreased below a critical value A proof of this statement is given in Appendix A. For large a we may thus compute the critical point directly from the network topology and the local values b i .

Impact of temperature on the centralization
A reduction in the specific transportation costs p T generally leads to a centralization of production. But how does the diversity of agent's preferences, measured by the parameter T , affect this scenario? Simulation results for different values of T and a are shown in figure 4.
In the case of strong scale effects, a = 10 0 , we observe almost no differences between the curves for different T . In this case, the price effects dominate the decision of the agents: The centralization of production leads to strong changes of the price p ji which outweighs the individual differences T ϵ j in the agents' utility function (1).
In contrast, a substantial impact is found in the case of weak scale effects, e.g. a = 10 −2 . Results for two intermediate values for T are compared in the upper row of figure 4. Not surprisingly, the differences in the agents' preferences measured by T ϵ j counteracts centralization, as the impact of price differences due to scale effects is less pronounced. Hence, the maximum production S * for intermediate values of p T is typically the lower, the higher T . Correspondingly, there are more nodes that contribute significantly to the production. Nevertheless, we still see a transition to complete centralization for the given values of T as p T decreases further. Remarkably, the final step of the centralization process takes place in an even more abrupt way as T is increased. The difference is even more pronounced in the aggregated entropy H = i H i . For T = 4 × 10 −6 we first observe a smooth increase of H, indicating the emergence of all-to-all trade, until it drops sharply to low values associated with centralization. We thus find that the diversity of preferences can delay centralization of the trade network, until the centralization occurs in an 'explosive' way. Similar explosive effects where found for a variety of different models in percolation theory [33,34]. We finally recall that for even higher values of T the emergence of centralization is entirely absent as shown in the phase diagrams in figure 3.

From local to diverse production
The differences in the agent's preferences induces a transition from local production to a diverse supply if either the effective temperature T is increased or the specific transportation costs p T are decreased. The boundary between the two regimes appears as a straight line with slope one in the double-logarithmic phase diagram (figure 3), except for the parameter region with both p T and T small leading to centralized production (phase II). In the following paragraphs, we provide a detailed analysis of the transition from local to diverse production and derive an analytical estimate for the location of the transition.
We first note that in both phases the local production of each node equals S j = D. Hence, we assume that scale effects play no role for the transition and equation (3) for the purchases simplifies to The differences in the local parameters b k are small compared to p T E ki in all simulations and can thus be neglected in the following analysis. We conclude that the transportation costs parameter p T and the effective temperature T enter only via the ratio Hence, also the entropy H will depend on p T and T only via the ratio β and the phase boundary is given by a straight line Indeed, the numerical simulations presented in figure 3 confirm this finding. The boundary between phases I and III is a straight line as long as p T and T are large enough such that no centralization occurs, i.e., far away from phase II. The second conclusion we draw from the expression (35) is that we can treat all nodes i = 1, . . . , N separately. We note that this assumption is strictly true only for a = 0, while it represents a useful approximation for a > 0. Indeed, the success of this assumption is surprising from a conceptual view at first glance. If a node i would independently redistribute its purchases, this would invalidate the assumption S j ≈ D = const. which allowed us to neglect scale effects and treat all nodes separately. This apparent contradiction is resolved as follows: Typically, The decision of a node i to purchase from j is mirrored by a simultaneous decision of j to purchase at i if b i and b j do not differ too much. Hence, the decisions are not independent a priori but their effect on the prices cancels out such that the decisions of the nodes effectively separate and can be treated independently in the calculation.
Using these assumptions, we now provide an explicit approximate expression for the entropy H i and the critical parameter β crit . We first note that the entropy can be rewritten as (cf. Appendix B) where can be interpreted as a partition function and the expression in the bracket as a free energy. To evaluate the Q i , we just need the information of how many nodes are found at a given distance E. We encode this in the counting function where Θ denotes the Heaviside function. Notably, the function (40) can be interpreted as an integrated density of states. To obtain an analytic approximation for Q i , we have to approximate N i by a function that keeps the essential properties but allows to carry out the sum in equation (39) in closed form. Three properties have to be taken into account: (i) The function N i scales quadratically withÊ on coarse scales. (ii) We have to take into account that the set of distances E ij is discrete such that N i does not increase smoothly but in discrete steps. In fact, it is essential to take into account that the distance to the nearest neighbor is always finite. In an analog physical model, this would correspond to a finite 'energy gap' between the ground and first excited state. (iii) Finally, it must be taken into account that the number of states is finite. These requirements can be met by a staircase function with steps of regular position and size. For the time being, we restrict ourselves to networks where the number of nodes can be written as N = (M + 1)(M + 2)/2 with M ∈ N. The function N i (Ê) can then be approximated by where E 0 = 1/ √ 4N is the expected value of the distance to the nearest neighbor on a two-dimensional plane with node density ρ = N . Using this approximation, the partition function can be computed as We test this approximation in figure 5 for a sample network with N = 105 nodes and find a very good agreement with the numerically exact values. For large networks and low effective temperatures, we can further simplify expression (42) by noting that e −βE 0 (M +1) /e −βE 0 → 0 for β → ∞ or in large networks M → ∞. We then obtain In this limit, the entropy can be computed from equation (38) as We find that the entropy vanishes for low effective temperatures, indicating that all nodes i choose a single supplier. In fact, the production is local in this limit. The entropy differs substantially from zero when βE 0 is of the order of unity leading to the estimate β crit ≈ E −1 0 for the critical value. A slightly more accurate approximation can be obtained by computing the value for which the entropy H equals half of its maximum value which yields the implicit condition For higher values of the effective temperature (lower values of β), the approximation (44) is no longer valid as indicated in figure 5

From centralized to diverse production
We finally consider the transition between the diverse (III) and the centralized production regime (II). This transition is driven by the competition of the two terms in the agents' utility function (1) -the individual differences and the universal prices. A diverse production is found if the preferences are sufficiently different, i.e. if the weight parameter (the effective temperature) T exceeds a critical value T crit , cf. (11) in the two regimes. If production is fully diversified, then the supply matrix is given by S ji = D/N (cf. equation. (28)) and the free energy (11) is thus given by whereĒ i is the average distance from node i to all other nodes,Ē i = N −1 j E ij and b = N −1 j b j . If production is fully centralized at a node n, then the supply matrix is given by S ji = Dδ jn using the Kronecker delta symbol (cf. equation (26)). In this case, the free energy (11) reads We expect the production to be purely centralized when F i,cen > F i,div for all nodes i and to be diverse if F i,div > F i,cen for all i. If scale effects are sufficiently strong, then the differences between the nodes i are negligible and the transition is abrupt. We then expect the transition to take place at a critical temperature T crit given by Neglecting the inhomogeneities in the b i and the transportation distances, we finally obtain We conclude that the transition between diverse and centralized production is driven by the competition of scale effects scaling linearly in a and diversity in preferences scaling linearly in T , while transportation effects play a negligible role. Hence, the critical effective temperature T crit scales linearly in a, while it is largely independent of the specific transportation costs p T . However, this reasoning is only valid as long as local production is not competitive, i.e. as long as p T is small enough. A surprising behavior is found for weak scale effects and intermediate values of the specific transportation costs p T (figure 6, upper row, dashed line). We find that the maximum production S * jumps to one when the effective temperature T increases above approximately 10 −6 . That is, an increase in the diversity of preferences leads to a decrease in product diversification. This counter-intuitive behavior is a consequence of the multistability of the economic system. Two Nash equilibria exist for T ≪ 10 −6 , one with an incomplete and one with a complete centralization of production. Due to the design of our numerical experiments the initial state features an incomplete centralization. An increase in T fosters trade, strengthening one producer at the expense of another one. Eventually, the Nash equilibrium with incomplete centralization becomes unstable, and the system relaxes to the centralized equilibrium, offering lower total costs due to scale effects. Notably, a further increase of the effective temperature finally leads to a fully diversified production as expected.

Comparison to numeric results
As a final step of our analysis, we compare the analytical estimates for the location of the phase boundaries to the numerical results in figure 7. We find that the estimate (45) for the phase boundary between the localized and diversified phase accurately matches the numerical results with no visible differences. The estimate (46) slightly overestimates the critical value T crit for the transition from centralized to diversified production. However, the analytical estimate faithfully reproduces the order of magnitude of T crit as well as the scaling with the parameter a. Similarly, the estimate (34) provides a fair overall estimate for the critical value p T crit for the transition from localized to centralized production. The scaling with a is overestimated such that analytical estimates are larger than the numerically exact values for large a. This is not surprising as we expect a smooth crossover between the two different scaling regimes. For medium to large values of a, we expect a proportional scaling of p T crit with a as described by (34). In contrast, p T crit should tend to a constant for small values of a as there is still a (continuous) centralization at a finite p T crit due to the small inhomogeneity in the b i .

Conclusion and outlook
In this article, we have established a model for the formation of trade networks based on the decisions of economic agents. The model combines two driving factors for the emergence of trade: On the supply side, trade is established if regional differences in production costs, including economic scale effects, exceed the transportation costs. On the demand side, the diversity of the agents' preferences fosters trading even if this increases costs. The model was derived from the decisions of individual agents in terms of discrete choice theory. Every agent decides for a supplier based on both the price and an individual factor modeled as a random variable. On an aggregated scale, a set of agents thus purchases goods from different suppliers at different locations. On this aggregated level, the model shows strong connections to ensembles in statistical thermodynamics as the equilibrium on the agent level coincides with an equilibrium of the effective free energy (11). However, all decisions are coupled through scale effects: The decision of any agent changes the prices for all other agents and may thus trigger further decisions. Hence, the common equilibrium of statistical physics must be generalized to a Nash equilibrium. Nevertheless, statistical thermodynamics provides essential concepts to compute the equilibrium states and to understand the emergence of a trade network.
We have shown that the model bears three different regimes of trade. If transportation costs are high and the diversity of preferences is weak, then all goods are produced locally. A trade network can emerge in two different ways rooted in either the supply or demand side. Decreasing transportation costs makes it cheaper to import goods thus fostering the emergence of trade. This process is essentially driven by economies of scale, as every increase of production leads to lower prices fostering further increase in exports. Eventually, this process leads to a complete centralization of production and a directed star-like trade network. An increase in the diversity of preferences drives the emergence of bilateral trade and eventually leads to an allto-all coupled trade network. We have developed a comprehensive analytical theory of the transitions between these regimes and derived analytical estimates for critical parameter values. Remarkably, the transition to a phase with centralized production can be continuous as well as discontinuous if economic scale effects are strong enough.
The model describes some essential mechanisms in the formation of trade networks -but of course it cannot capture all facets of this complex process. For instance, our model captures the importance of economies of scale, diverse preferences and emergent hysteresis effects [20,30]. A limitation of the model is found in the emerging production patterns: When transportation costs continue to decrease, production will either be centralized completely or not at all depending on the parameter T . In reality, one often observes multi-center structures, for example in urban systems [35,36] as a result of spatial constraints or congestion at high levels of centralization. In the proposed modeling framework, this would be possible if scale effects saturated or if transportation capacities were limited.
From a more fundamental viewpoint, the model starts from discrete choice theory and then aggregates over many agents to obtain the total purchases between the nodes of a network. Other economic models, such as the celebrated Dixit-Stiglitz model maximize utility for a given budget [18]. From a statistical viewpoint, a thorough treatment of the thermodynamic limit remains challenging due to the different scaling behaviors in the utility function. This analysis is well beyond the scope of the present analysis, so we have focused on finite systems. or at node j = 1 at a price By our assumption (33), we find that p 13 < p 33 such that node i ′ = 3 changes its purchases from local to import simultaneously with node i = 2. The same argument now applies to all nodes i ′′ = 4 . . . , N . Hence, we conclude that at p T = p T crit all nodes simultaneously change their purchases such that we find for p T > p T crit : S ii = D, for p T < p T crit : S 1i = D, for all nodes i = 1 . . . , N .

Appendix B. Entropy and partition function
In this appendix we briefly recall the relation of the entropy and the partition function (39). In particular, we show that the expression (38) for the entropy H i is equivalent to the definition (12). Differentiating the partition function Q i with respect to β yields