# Universal role of commuting in the reduction of social assortativity in
cities

Eszter Bokányi1,2,∗, Sándor Juhász1,2, Márton Karsai3,4, Balázs Lengyel1,2

(1Corvinus University of Budapest; Laboratory for Networks, Technology and
Innovation
Budapest, H-1093, Hungary
2ELKH Centre for Economic and Regional Studies, Agglomeration and Social
Networks Lendület Research Group
Budapest, H-1097, Hungary
3Central European University; Department of Network and Data Science
Vienna, A-1100, Austria
4Rényi Alfréd Institute of Mathematics,
Budapest, H-1053, Hungary
∗Corresponding author<EMAIL_ADDRESS>
)

###### Abstract

Millions commute to work every day in cities and interact with colleagues,
customers, providers, friends, and strangers. Commuting facilitates the mixing
of people from distant and diverse neighborhoods, but whether this has an
imprint on social inclusion or instead, connections remain assortative is less
explored. In this paper, we aim to better understand income sorting in social
networks inside cities and investigate how commuting distance conditions the
online social ties of Twitter users in the 50 largest metropolitan areas of
the United States. Home and work locations are identified from geolocated
tweets that enable us to infer the socio-economic status of individuals. Our
results show that an above-median commuting distance in cities is associated
with more diverse individual networks in terms of connected peers and their
income. The degree that distant commutes link neighborhoods of different
socio-economic backgrounds greatly varies by city size and structure. However,
we find that above-median commutes are associated with a nearly uniform,
moderate reduction of social tie assortativity across the top 50 US cities
suggesting a universal role of commuting in integrating disparate social
networks in cities. Our results inform policy that facilitating access across
distant neighborhoods can advance the social inclusion of low-income groups.

##  1 Introduction

Cities are champions of diversity [1, 2, 3]. Complex interaction networks of
individuals in urban areas enabled by population density, co-location, and
easy access together made cities the global engines of technological and
economic progress [4, 5, 6, 7]. However, cities are also known for high levels
of segregation [8, 9, 10] where disparate neighborhoods are separated from
each other in the urban space [11, 12, 13, 14, 15]. Furthermore, spatial
segregation by income also fragments social networks, which can hinder
progress and can deepen inequalities [16, 17, 18, 19, 20]. Given the
importance of this problem, a growing community has investigated the patterns
of mobility in cities to better understand mixing potentials across disparate
and diverse neighborhoods [21, 22, 23, 24], which may increase economic
prosperity [25]. Yet, less is known whether mobility mixing has any imprint on
the social connections of people.

Commuting covers a large share of urban mobility [26] and by connecting home
with work locations, the places where people spend most of their time, it
plays an important role in the spatial formation of social connections [27,
28, 29]. Since aggregated social networks form spatially bounded communities
across neighborhoods [17], the further one commutes, the higher the likelihood
that commuting-related social connections will introduce diversity in the
egocentric network of the commuter [30, 31]. Due to spatial segregation,
economically disparate neighborhoods tend to be far from each other [32], thus
long commutes are more likely to link places with different social status [33,
34]. Nevertheless, it is not trivial that long commutes should facilitate
social inclusion, because social interactions might remain assortative even at
places far from home [21, 35, 23]. Meanwhile, the time to develop new social
connections is especially limited for low-income workers who travel to work
during rush hours [36, 37].

The spatial distribution of high versus low-income households determines the
length of travel that can bridge disparate neighborhoods. Since the scale of
socio-economic isolation greatly varies across cities [12], one may expect
that the mobility of people also enables a different degree of social mixture.
However, the assortativity of urban mobility is a universal feature across
cities: individuals have been recently reported to visit locations that are
similar to their home neighborhood [38, 21, 23, 39, 40]. Yet, how
assortativity of commuting and social networks are related and how this
relation is modified by the length of commute in cities is still largely
uncovered.

In this paper, we aim to better understand how mixing in urban social networks
is facilitated by commuting. To answer this question, we use a unique dataset
on 348,850 Twitter users living in the 50 largest metropolitan areas of the US
and track their home and work locations as well as their mutual followership
ties on the platform, which from now on, we call the social network of users.
We project these social networks in the urban space and attribute users with
an average income based on their home locations on an income map extracted
from census data. By comparing ego network indicators between people commuting
to different distances, we find that long commuting is associated with lower
levels of transitivity, the tendency that friends of friends know each other,
and higher levels of income diversity among friends. These results are
consistent across the 50 largest US cities and suggest that long commutes can
indeed facilitate social mixing.

Our results suggest a universal role of commuting in integrating disparate
social networks. The paper contributes to the discussion on the importance of
commuting in cities and shows that longer commutes have a measurable even
though moderate influence on establishing diverse and less segregated social
connections. The findings imply that supporting access to distant work can
help the inclusion of lowest income groups and to a certain degree the richest
as well, regardless of the urban context.

##  2 Results

We use a unique Twitter database that contains all messages and profile
information of 348,850 Twitter users in the top 50 metropolitan areas of the
United States. The data was collected between 2012 and 2015 and due to the
sample selection method described in [41], the database contains a
considerable amount of individuals who allowed automatic GPS data collection
for all their messages. This dataset was used in previous research to detect
dominant language use and temporal patterns connected to socio-economic
indicators such as ethnicity or unemployment in the US, to establish world-
wide communities of users reflecting political and cultural boundaries, and to
model the spreading of viral content [14, 42, 43, 44].

Figure 1 illustrates how commuting and social network information is retrieved
from the data. Home and work locations are detected by the most frequent
locations of tweets in the morning and evening hours or during daytime as
depicted in Figure 1a (and as explained in Materials and Methods). This
process enables us to identify the census tract of home and work locations and
attach socio-economic status, measured by the average household income of
census tracts from the 2012 American Community Survey. Commuting is
characterized by the Euclidean distance between home and work and the socio-
economic status of both locations. Finally, we construct the ego network for
every user from mutual followership of Twitter profiles and characterize egos
and alters by the socio-economic status of their home location. This enables
us to quantify social mixing in terms of commuting and social ties in cities.

Figure 1b shows the census tracts of inner Boston colored by the average
annual household incomes and the home and work locations of a sample user. The
user’s ego network is depicted in panel (c), with colors indicating the income
of the neighbors inferred from their home census tract. Each user in our
sample has at least 1 mutual followership-based connection and has
identifiable home and work locations that are at least 100 metres away from
each other. The distribution of users across the 50 selected cities is
illustrated in Supplementary Information (SI) 1 and 2. For a more detailed
description, see Materials and Methods.

Figure 1: Combination of spatial, temporal and social network data of
geolocated Twitter messages. (a) Home and work locations of users are
identified through the distribution of timestamps on all their collected
tweets within their most frequently visited spatial clusters. We assign a
possible home location (8PM-8AM) and a possible work location (9AM-5PM) to
each user [45, 46] as their most frequently visited location in the given
period. The histogram represents the timeline of tweets for the clusters of a
sample user. (b) Commuting is defined as the overhead distance between users’
home and work locations. The colorbar of the map indicates the income level of
census tracts. (c) Twitter ego network of a sample user based on mutual
followership. The coloring of nodes also corresponds to the level of income in
the home tract of users.

To characterize the relation between $d$, the distance of commutes, and the
social network of individuals, we compare the social networks of people
commuting to $d>{median}$ with $d<{median}$ commuting distances in each of the
50 largest US metropolitan areas. Median commuting distances are calculated on
the basis of the sampled users in each city as illustrated in SI 3. Our
expectation is that commuting may induce more out-of-community independent
social ties for commuters, in turn decreasing the transitivity of their
egocentric networks. We observe this effect by measuring the local clustering
coefficient [47] for each user, which quantifies the tendency that an
individuals’ friends know each other. Another assumption of ours is that these
out-of-community ties introduce stronger diversity in ego networks in terms of
socioeconomic status of neighbors. We quantify this effect via the average
income difference from friends in users’ ego networks, which measures the
income similarity of online social connections (for a formal definition see
Eq. 1 in Materials and Methods).

Figure 2: Network characteristics of users and commuting distance in the top
50 metropolitan areas of the United States. (a) Network closure measured by
the local clustering coefficient is lower in most cities for those users who
commute further than the local median distance. (b) Income mixture, measured
by average income difference from friends, is higher of those who commute
above the local median distance in the majority of metropolitan areas. Non-
transparent symbols indicate that the differences of means are significant
(p$<$0.05).

Figure 2a reports the average of local clustering coefficient and (b) the
average income differences of users commuting above and below the local median
distance in the 50 largest metropolitan areas in the USA. These findings
suggest that, with a few exceptions, an above-median distance commute is
associated with lower local clustering (Figure 2a), and with greater income
difference in the commuters’ ego networks (Figure 2b). This implies that
working further away from home helps people to develop less cohesive and
income-wise more diverse social networks in most metro areas. Note that here
metropolitan areas are sorted in decreasing population order and non-
transparent markers denote significant differences (p $<0.05$) between
averages.

While these results suggest clear trends, they also highlight the
heterogeneity of cities. To support these observations, in SI 4, we compute
the degrees for below and above median distance commuters, and we also repeat
the measurements and find them to be robust for various distance thresholds. A
multivariate regression analysis using continuous variables in SI 5 provides
further evidence that commuting distance correlates negatively with local
clustering even when controlling for the number of connections and income.
These regressions also inform us that commuting distance facilitates mixing in
social networks by enabling commuters to make more friendships.

Figure 3: (a) Commuting assortativity matrix $C$ and (b) social network
assortativity matrix $S$ between the 10 income deciles for Detroit, New York
(c) and (d) and Boston (e) and (f). (h) Distribution of Pearson correlations
$\rho_{C}$ (green) and $\rho_{S}$ (blue) for the assortativity matrices $C$
and $S$ of the top 50 metropolitan areas of the US. (g) Commuting
assortativity and social network assortativity are strongly correlated across
cities. Solid line represent $\rho_{C}=\rho_{S}$.

For a more detailed insight into the structure of social and mobility
assortativity in these cities, next, we analyze social mixing through
commuting and online social ties between income groups. We sort all census
tracts into income deciles based on the income distribution across all census
tracts in the metro area in question and assign an income decile ranging from
1 to 10 to home and work locations. For each metro area, we construct a
commuting assortativity matrix $C$ and a social network assortativity matrix
$S$ to represent connection probabilities between these income deciles. The
elements of the commuting assortativity matrix $C_{ij}$ measure the
probability that a user with home census tract in income decile $i$ commutes
to work in a census tract of income decile $j$. Similarly, elements of the
social network assortativity matrix $S_{ij}$ represent the average probability
that a person living in a tract with income decile $i$ has a mutual
followership tie with a user living in a tract with income decile $j$. For
more details on the construction of the matrices, see Materials and Methods.

The aggregated patterns of commuting $C$ and friendship ties $S$ are presented
in Figures 3a-f for three example metropolitan areas, Detroit, New York, and
Boston. Unlike previous studies [23, 35], we do not observe universal
assortativity patterns over all cities in these networks. In some of the
cities, such as Detroit, the strong diagonal component features strong
segregation patterns, meaning that people tend to commute to neighborhoods
with similar annual household incomes as their home neighborhood, and they
tend to form social ties with people living in neighborhoods with similar
income, as also found in [24]. In cities like Boston, patterns of mobility and
online social ties are less assortative with higher likelihood for diverse,
off-diagonal connections. All commuting and social network matrices are
available in the SI 6 for the 50 metropolitan areas.

To explore this heterogeneity further, we computed the Pearson correlation
coefficient of the above matrices (see Materials and methods equation (4)). We
use these correlation coefficients as a single-number measure of assortativity
in the metropolitan-level networks denoted by $\rho_{C}$ for the commuting,
and $\rho_{S}$ for the social network assortativity matrix. We show the
$\rho_{C}$ and $\rho_{S}$ distributions in Figure 3g. We see here that the
level of assortativity varies remarkably across the 50 metro areas, but
judging by their averages, commuting in metro areas ($\bar{\rho}_{C}=0.31\pm
0.07$) are more income assortative than online social ties
($\bar{\rho}_{S}=0.27\pm 0.05$). Interestingly, our observations in Figure
3a-f further suggest that the measured commuting and social network
assortativity matrices are not independent of each other. Indeed, Figure 3g
illustrates that $\rho_{C}$ and $\rho_{S}$ pairs are strongly correlated
($\rho$=0.84) suggesting a substantial relationship that social networks are
segregated in cities where home-work commuting patterns are assortative.

Figure 4: Panels (a)-(d) show the $C$ and $S$ assortativity matrices for the
below ($d<median$) and above median ($d>median$) commuting users in a selected
metropolitan area, Detroit. (e)-(f) The corresponding distributions of
$\rho_{C}$ (green) and $\rho_{S}$ (blue) for all 50 metropolitan areas for
users with $d>{median}$ and $d<{median}$. (g) Pairwise values of $\rho_{C}$
and $\rho_{S}$ for users with $d>{median}$ and $d<{median}$ by metropolitan
areas. Metropolitan areas are sorted in decreasing order by $\rho_{C}$ for
easier representation. (h) Social network assortativity versus commuting
assortativity for below and above median commuters with selected cities from
Fig. 3 labeled. (i) Decrease in the commuting assortativity and the social
network assortativity measured in percentage. Black horizontal line
corresponds to the average change in social network assortativity. Grey shaded
area marks the standard deviation.

To investigate the association between long-distance commute and social mixing
on the aggregate city-level in more detail, we separate the baseline sample of
the $C$ and $S$ matrices by commuting distance. Thus, we create a $C$ and $S$
matrix from users commuting to a distance $d<{median}$ and $d>{median}$, as in
the example in Figure 4a-d, where we show these four matrices (two for both
$C$ and $S$) for Detroit. These matrices indicate that for users commuting an
above median distance, matrices are less diagonal, and reflect more diverse
and less segregated commuting and social connections. Panels (e) and (f) from
Figure 4 present the distributions of $\rho_{C}$ and $\rho_{S}$ for the two
subgroups of users in all 50 metropolitan areas. As expected, longer commuting
distance is associated with less assortativity because distant workplaces are
likely to be located in socio-economically different environments as compared
to home location. This might be due to spatial clustering of tracts with
similar annual household incomes [12], leading to shorter commute patterns
landing in places with similar income level. In parallel, we observe that
longer commutes are also associated with lower levels of assortativity of
online social network ties such that off-diagonal social ties are relatively
more likely for $d>{median}$ distances than for $d<{median}$. However, while
$\rho_{C}$ falls sharply for $d>{median}$ distances compared to $d<{median}$,
the difference of $\rho_{S}$ is moderate in Figure 4e-f. This finding
indicates that although long-distance commutes can link disparate
neighborhoods, not all of the diversity generated by commuting has imprints on
social connections. Instead, income homophily remains a major yet weaker
factor of social tie selection for long commuters as well.

Despite the heterogeneity of metro areas, results in Figure 4g show general
patterns in two regards. First, assortativity of both commuting and social
networks are lower for long-distance commuters in every metropolitan area.
Second, the assortativity reduction between shorter and longer than median
commutes is decreasing sharply, while the reduction of social network
assortativity is moderate and takes similar values for every metropolitan
area. The Pearson correlation coefficient between the two assortativity values
$\rho_{S}$ and $\rho_{C}$ is 0.80 for short commuters and 0.72 for long
commuters, thus they signify a strong relationship between mobility and social
network assortativity patterns for both user groups (Figure 4h). To understand
the magnitudes of change, we calculate the percentage of social network
assortativity reduction by
($(\rho_{S,d>median}-\rho_{S,d<median})/\rho_{S,d<median}$) and the percentage
of commuting assortativity reduction by
($(\rho_{C,d>median}-\rho_{C,d<median})/\rho_{C,d<median}$) for each city.
Illustrating these metrics, Figure 4i shows that the decrease in commuting
assortativity ranges on a wide scale between -50% and -100%. However, the
decrease in the social network assortativity concentrates around the average
value of $-28\pm 9\%$. Remarkably, this signals a universal pattern of social
mixing potentials across very different urban settings and it explains a
general trend of how mixing through commutes manifests in social inclusion. SI
7 illustrates that the uniform $\sim 30\%$ decrease disappears if we separate
two user groups randomly instead of by commuting distance, but this
observation remains consistent across multiple absolute distance thresholds (3
km, 5 km, and 10 km). In addition, in SI 8, we show that assortativity
reduction by long-distance commute is a result of increasing social mixing of
users from poorest and to some extent, from the richest neighborhoods.

##  3 Discussion

Understanding the complex behavioral patterns of people is crucial to develop
more liveable, equal and sustainable urban environments. Our study contributes
to this challenge by using large-scale geolocated Twitter data to study the
role of commuting in the composition and assortativity of social interaction.
We illustrate that long-distance commuting acts against structural closure and
income homophily of social relationships and reduces segregation between
remote income classes by facilitating connections and mixing. We show that
home-work commutes and online social ties are not equally assortative in every
metropolitan area, but in most cases, commuting is even more likely to point
to places with similar income level than online social connections. Our
findings suggest that longer commutes are more likely to connect places with
different income levels, which contributes to the development of more diverse
and less assortative social ties. Moreover, working further away from home
results in more heterogeneous social connections in every metropolitan area.

Our results suggest that urban mobility has a fundamental role in fulfilling
the promise of social inclusion and reduction of social segregation in cities.
The association between commuting distance and social networks is remarkably
stable across all metropolitan areas with different size and spatial structure
[48]. This universal pattern highlights that commuting-enabled social mixing
follows similar mechanisms regardless of the urban context. We find that
facilitating the access between distant neighborhoods can reduce segregation
in metropolitan areas, while gains in social inclusion are limited to a 30%
reduction of assortativity. These results signal that providing access across
disparate neighborhoods cannot erase mechanisms of social network segregation
but can mitigate the divide between rich and poor.

The methodology applied in this paper could easily be extended to other cities
with large populations of geolocated Twitter users, and where granular census
data with similar spatial resolution is available. However, this approach is
not without limitations. While we are confident in our approach to identify
home and work locations of users, we cannot confirm whether the identified
work locations are actual workplaces or any another facility that people visit
frequently during daytime (such as restaurants, schools, etc.). We measure
commuting distances as the Euclidean distance between the home location and
the work location, whereas in multiple cities, physical obstacles such as
rivers might considerably increase to travel times or change the socio-
economic segregation patterns of settlements [49]. We are not aware of the
available modalities to reach work destinations, but we admit that it would
also introduce a large variability into travel times. We choose this
simplification because both travel times with a car or public transportation
might depend on the exact time of the day and varying traffic conditions. Both
the underestimation of commuting distances and the inclusion of users who
might not have a regular workplace can result that the observed commuting in
our case (see SI Figure 3) falls behind the commuting distances reported in
the American Community Survey. Because we do not use an absolute threshold to
distinguish long and short commutes, and we use the city-wise median to divide
the users into categories, we believe that the aforementioned biases do not
affect our results drastically. However, we test both the results of Figure 2
and Figure 4i for different absolute distance thresholds, 3 km, 5 km and 10
km, where our results still hold (see SI 4 and SI 7).

Even though the fraction of users present in the analysis is proportional to
the population size of the 50 metropolitan areas (see SI Figure 2), we have to
highlight that our dataset is not representative for the US population and
results have to be interpreted accordingly. [50] finds that African American
users are overrepresented on the platform, and Twitter users are predominantly
young, well-educated [51, 52] and unrepresentative of other ethnicities [53,
54]. Therefore, we cannot generalize our findings to the whole population of
these metropolitan areas. Another limitation of the study could be that the
free 1% sample from Twitter Streaming API was used for the initial data
collection. [55, 56] confirms that tweets filtered to containing GPS
coordinates are retrieved to almost 90% of the time compared to the full
dataset. By imposing strict count limits, spatio-temporal constraints and
mutual followership for ties, we believe that our sample is less distorted
from bot activity than what [57] would suggest.

Despite the imperfection of the data, we believe that the presented exercise
offers useful insights to the structure of social connections within urban
areas. Such large-scale, micro-level analysis enables us to uncover the
fundamental patterns behind segregation, inequality or the lack of inclusion
inside cities. Publicly available online social network data can complementing
official census reports or surveys and can provide opportunities to detect and
react to societal patterns and changes.

##  4 Materials and methods

###  4.1 Data collection and combination methods

We focus on users of the online social networking site of Twitter who posted
tweets frequently containing precise geographic information. More
specifically, we use a unique, historical database rich in tweets containing
GPS coordinates [41, 58]. These tweets originate from users who enabled the
exact geolocation option on their smartphones. Overall, we detect the three
most frequent tweeting locations of users as spatial clusters of their
locations in the 50 most populated metropolitan areas of the United States. We
use the Friend-of-Friend algorithm [59] to cluster the spatial coordinates for
each user. This algorithm is a paralellizable, scalable clustering algorithm
known from astronomy, and it is widely used to identify galaxy clusters [60].
In our case, any two tweet coordinates of the same person are considered to
belong to the same spatial cluster if their separation is less than 1 km. For
each cluster, we determine the first two moments of the coordinate
distribution. Before calculating the mean coordinates of the cluster, we trim
data points until all points are inside a $3\sigma$ radius to eliminate
outliers. We keep the aforementioned three highest cardinality clusters per
user [41, 42].

To determine the possible home and work locations of users, we follow the
approach proposed by [46]. We assume that the home and work locations of users
are within the previously detected three clusters. We select users for whom at
least two out of the three clusters are within the same metropolitan area from
the top 50 metropolitan areas of the United States and one of these clusters
is their top cardinality location. First, we calculate the daily timeline of
clusters for each user based on the timestamp of the tweets with hourly
aggregation, converting all UTC tweet timestamps to local times across the
whole US. We only consider users with more than 15 tweets on weekdays (Monday
to Friday) in total. Local aggregated weekday timelines of two clusters for a
sample user are presented in Figure 1a. We calculate the share of tweets sent
between 9AM and 5PM on weekdays to capture messages predominantly sent during
the working hours. Similarly, we calculate the share of tweets sent between
8PM and 8AM on weekdays contributing to a possible home tweeting fraction.
Then, the cluster with the highest work tweet share or home tweet share
becomes the work and home cluster of the user.

Commuting of users is characterized by the overhead distance between their
home and work locations. We restricted our sample to users with at least 0.1
km commutes. Thus, we have 975,492 users in our sample. The distribution of
observed commuting distances for each metro area are presented in SI 3.
Additionally, we attach socio-economic data to each home and work location in
the observed metropolitan areas from the 2012 American Community Survey. More
precisely, we map the home locations of users into the census tracts of the
top 50 US metropolitan areas and attribute the average annual household income
of the census tract to each user living there. After that, we sort users into
city-wise income deciles based on the average annual household incomes, and we
apply the same approach to determine the average income and the income decile
of their workplaces. Figure 1b shows the commute of the same sample user and
the income level of the surrounding census tracts.

Social connections of users are defined as their mutual followership relations
on Twitter as they represent relative stronger ties in context of online
social networks [61]. Figure 1c represents a sample ego network that we
construct for every user from our home-work sample who has at least 1 mutual
followership tie within the same metropolitan area. In the end, we have
348,850 users for whom we have both the home and work location information,
and a mutual followership ego network. The composition and spatial
distribution of our final sample is presented in SI 1. Through the home
location of the user’s friends, we can infer their income, thus, we are able
to characterize the socio-economic status of the neighbors in the ego networks
by identifying their income deciles. Figure 1c shows this characterization by
using the same colorscale for both the ego and its first neighbors as the
choropleth map in Figure 1b.

At the individual level, commuting and online social ties of our users are
characterized by multiple different indicators. We measure user commutes by
the Euclidean distance $d$ between their inferred home and work locations. We
calculate degree and local clustering coefficient from their ego networks. We
also measure the average income difference between their own home income and
the home income of their friends, following the formula below:

$\Delta
I=\frac{1}{\textrm{\\#neighbors}}\sum_{f\in\textrm{neighbors}}\log_{10}\left|I_{f}-I_{ego}\right|$
(1)

###  4.2 Assortativity metrics

At the aggregated, metropolitan area level, we create multiple different
assortativity matrices between income deciles $D$ for each metropolitan area.
First, an assortativity matrix of commuting is constructed, where we capture
the probability $C_{ij}$ that a user $u$ belonging to a home census tract in
income decile $D=i$ commutes to a tract with income decile $D=j$ to work.
Second, we measure the conditional probabilities of social ties across home
census tracts in different income deciles, the social network assortativity
matrix $S$. The element $S_{ij}$ of this matrix measures the probability that
a user $u$ from income decile $D=i$ has a mutual followership tie to a user in
income decile $D=j$. Formally, the two matrices can be calculated as

$\displaystyle\displaystyle C_{ij}$
$\displaystyle=\frac{\sum\limits_{\left\\{u\in
U\left|D_{u,\mathrm{home}=j},D_{u,\mathrm{work}=i}\right.\right\\}}1}{\sum\limits_{\left\\{u\in
U\left|D_{u,\mathrm{home}=j}\right.\right\\}}1}$ (2) $\displaystyle S_{ij}$
$\displaystyle=\frac{\sum\limits_{\left\\{u\in
U\left|D_{u,\mathrm{home}}=j\right.\right\\}}\frac{1}{k_{u}}\sum\limits_{\left\\{e_{uf}\in
E_{u}\left|D_{f,\mathrm{home}=i}\right.\right\\}}1}{\sum\limits_{\left\\{u\in
U\left|D_{u,\mathrm{home}=j}\right.\right\\}}1},$ (3)

where $U$ is the user set within a metropolitan area for which we calculate
the matrices, $E_{u}$ is the set of edges connected to the user $u$, $k_{u}$
is the degree of ego user $u$ in the ego network, $e_{u}f$ is the undirected
edge between user $u$ and $f$, $D_{u}$ and $D_{f}$ are the (home or work)
deciles of users $u$ and $f$, respectively. We also measure two additional
friendship and commuting assortativity matrices, $S^{d>\mathrm{median}}$,
$S^{d<\mathrm{median}}$, $C^{d>\mathrm{median}}$ and $C^{d<\mathrm{median}}$,
for users commuting more or less than the median commute in the given
metropolitan area. In these cases, the set $U$ is what is different in the
matrices from Eq. 3.

We measure assortativity in these matrices by calculating the Pearson
correlation coefficient $\rho$ of the matrix entries. If we normalize the
elements of matrix $X$ such that $\tilde{X}_{ij}=X_{ij}/n$, where
$n=\sum_{i,j}X_{ij}$, the sum of the elements of a matrix, then $\rho$
captures how diagonal these matrices are:

${\displaystyle\rho_{X}=\frac{\sum\limits_{i,j}ij\tilde{X}_{ij}-\sum\limits_{i,j}i\tilde{X}_{ij}\sum\limits_{i,j}j\tilde{X}_{ij}}{\sqrt{\sum\limits_{i,j}i^{2}\tilde{X}_{ij}-\left(\sum\limits_{i,j}i\tilde{X}_{ij}\right)^{2}}\sqrt{\sum\limits_{i,j}j^{2}\tilde{X}_{ij}-\left(\sum\limits_{i,j}j\tilde{X}_{ij}\right)^{2}}}},$
(4)

where the summation for $i$ and $j$ both go over all of the income deciles
$D=1,\dots,10$. An assortativity value $\rho=+1$ would mean a completely
diagonal, thus, completely assortative matrix, whereas $\rho\approx 0$ values
indicate the lack of any preference for people following others from the very
same income class of their own.

## References

  * [1] Jane Jacobs  “The death and life of great American cities”  Vintage, 2016
  * [2] Edward Glaeser  “Cities, productivity, and quality of life”  In _Science_ 333.6042 American Association for the Advancement of Science, 2011, pp. 592–594
  * [3] Luís M A Bettencourt  “The Origins of Scaling in Cities”  In _Science_ 340.6139, 2013, pp. 1438–1441  DOI: 10.1126/science.1235823
  * [4] Gilles Duranton and Diego Puga  “The economics of urban density”  In _Journal of Economic Perspectives_ 34.3, 2020, pp. 3–26  DOI: 10.1257/jep.34.3.3
  * [5] Michael Storper and Anthony J Venables  “Buzz: Face-to-face contact and the urban economy”  In _Journal of Economic Geography_ 4.4 Oxford University Press, 2004, pp. 351–370  DOI: 10.1093/jnlecg/lbh027
  * [6] Francesco Calabrese, Zbigniew Smoreda, Vincent D Blondel and Carlo Ratti  “Interplay between telecommunications and face-to-face interactions: A study using mobile phone data”  In _PLoS ONE_ 6.7 Public Library of Science, 2011, pp. e20814  DOI: 10.1371/journal.pone.0020814
  * [7] Shi Kai Chong et al.  “Economic outcomes predicted by diversity in cities”  In _EPJ Data Science_ 9.1 Springer Berlin Heidelberg, 2020, pp. 17  DOI: 10.1140/epjds/s13688-020-00234-x
  * [8] Robert J. Sampson  “Moving to Inequality: Neighborhood Effects and Experiments Meet Social Structure”  In _American Journal of Sociology_ 114.1, 2008, pp. 189–231  DOI: 10.1086/589843
  * [9] Edward L Glaeser, Matt Resseger and Kristina Tobio  “Inequality in cities”  In _Journal of Regional Science_ 49.4 Wiley Online Library, 2009, pp. 617–646  DOI: 10.1111/j.1467-9787.2009.00627.x
  * [10] Richard Florida and Charlotta Mellander  “Segregated city: The geography of economic segregation in America’s metros”  In _Martin Prosperity Institute_ , 2015  URL: https://www.diva-portal.org/smash/get/diva2:868382/FULLTEXT01.pdf
  * [11] Elizabeth Oltmans Ananat  “The wrong side(s) of the tracks: The causal effects of racial segregation on urban poverty and inequality”  In _American Economic Journal: Applied Economics_ 3.2, 2011, pp. 34–66  DOI: 10.1257/app.3.2.34
  * [12] Philip S Chodrow  “Structure and information in spatial segregation”  In _Proceedings of the National Academy of Sciences of the United States of America_ 114.44, 2017, pp. 11591–11596  DOI: 10.1073/pnas.1708201114
  * [13] Richard Fry and Paul Taylor  “The rise of residential segregation by income”  In _Pew Research Center_ , 2012  URL: https://www.pewresearch.org/wp-content/uploads/sites/3/2012/08/Rise-of-Residential-Income-Segregation-2012.2.pdf
  * [14] Eszter Bokányi et al.  “Race, religion and the city: twitter word frequency patterns reveal dominant demographic dimensions in the United States”  In _Palgrave Communications_ 2.1 Nature Publishing Group, 2016, pp. 16010  DOI: 10.1057/palcomms.2016.10
  * [15] Douglas S Massey and Nancy A Denton  “The dimension of residential segregation”  In _Social Forces_ 67.2, 1988, pp. 281–315
  * [16] Nathan Eagle, Alex Pentland and David Lazer  “Inferring friendship network structure by using mobile phone data”  In _Proceedings of the National Academy of Sciences of the United States of America_ 106.36, 2009, pp. 15274–15278  DOI: 10.1073/pnas.0900282106
  * [17] Michael Bailey, Patrick Farrell, Theresa Kuchler and Johannes Stroebel  “Social connectedness in urban areas”  In _Journal of Urban Economics_ 118, 2020, pp. 103264  DOI: 10.1016/j.jue.2020.103264
  * [18] Lukas Norbutas and Rense Corten  “Network structure and economic prosperity in municipalities: A large-scale test of social capital theory using social media data”  In _Social Networks_ 52 Elsevier B.V., 2018, pp. 120–134  DOI: 10.1016/j.socnet.2017.06.002
  * [19] Jacob Levy Abitbol and Marton Karsai  “Interpretable socioeconomic status inference from aerial imagery through urban patterns”  In _Nature Machine Intelligence_ 2.11 Nature Publishing Group, 2020, pp. 684–692
  * [20] Gergő Tóth et al.  “Inequality is rising where social network segregation interacts with urban topology”  In _arXiv_ 12.1 Nature Publishing Group, 2019, pp. 1–9  DOI: 10.1038/s41467-021-21465-0
  * [21] Qi Wang, Nolan Edward Phillips, Mario L Small and Robert J Sampson  “Urban mobility and neighborhood isolation in America’s 50 largest cities”  In _Proceedings of the National Academy of Sciences_ 115.30, 2018, pp. 7735–7740  DOI: 10.1073/pnas.1802537115
  * [22] Luca Pappalardo, Dino Pedreschi, Zbigniew Smoreda and Fosca Giannotti  “Using big data to study the link between human mobility and socio-economic development”  In _Proceedings - 2015 IEEE International Conference on Big Data, IEEE Big Data 2015_ , 2015, pp. 871–878  IEEE  DOI: 10.1109/BigData.2015.7363835
  * [23] Xiaowen Dong et al.  “Segregated interactions in urban and online space”  In _EPJ Data Science_ 9.1, 2020, pp. 20  DOI: 10.1140/epjds/s13688-020-00238-7
  * [24] Cate Heine et al.  “Analysis of mobility homophily in Stockholm based on social network data”  In _PLoS ONE_ 16.3 March, 2021, pp. 1–14  DOI: 10.1371/journal.pone.0247996
  * [25] Nathan Eagle, Michael Macy and Rob Claxton  “Network diversity and economic development”  In _Science_ 328.5981 American Association for the Advancement of Science, 2010, pp. 1029–1031  DOI: 10.1126/science.1186605
  * [26] Shan Jiang et al.  “The TimeGeo modeling framework for urban motility without travel surveys”  In _Proceedings of the National Academy of Sciences of the United States of America_ 113.37 National Acad Sciences, 2016, pp. E5370–E5378  DOI: 10.1073/pnas.1524261113
  * [27] Eric Dahlin, Erin Kelly and Phyllis Moen  “Is work the new neighborhood? Social ties in the workplace, family, and neighborhood”  In _Sociological Quarterly_ 49.4, 2008, pp. 719–736  DOI: 10.1111/j.1533-8525.2008.00133.x
  * [28] Francesco Calabrese, Zbigniew Smoreda, Vincent D. Blondel and Carlo Ratti  “Interplay between Telecommunications and Face-to-Face Interactions: A Study Using Mobile Phone Data”  In _PLoS ONE_ 6.7, 2011, pp. e20814  DOI: 10.1371/journal.pone.0020814
  * [29] Mario L. Small and Laura Adler  “The Role of Space in the Formation of Social Ties”  In _Annual Review of Sociology_ 45, 2019, pp. 111–132  DOI: 10.1146/annurev-soc-073018-022707
  * [30] Gil Viry  “Residential mobility and the spatial dispersion of personal networks: Effects on social support”  In _Social Networks_ 34.1 Elsevier B.V., 2012, pp. 59–72  DOI: 10.1016/j.socnet.2011.07.003
  * [31] Joshua Blumenstock, Guanghua Chi and Xu Tan  “Migration and the Value of Social Networks”  In _CEPR Discussion Papers_ , 2019
  * [32] Elizabeth Roberto  “The Spatial Proximity and Connectivity Method for Measuring and Analyzing Residential Segregation”  In _Sociological Methodology_ 48.1, 2018, pp. 182–224  DOI: 10.1177/0081175018796871
  * [33] Maarten Ham, Tiit Tammaru and Heleen J Janssen  “A multi-level model of vicious circles of socio-economic segregation”  In _Divided Cities_ 615159.8774 OECD, 2018, pp. 135–153  DOI: 10.1787/9789264300385-8-en
  * [34] Jaap Nieuwenhuis et al.  “Does segregation reduce socio-spatial mobility? Evidence from four European countries with different inequality and segregation contexts”  In _Urban Studies_ 57.1 SAGE Publications Ltd, 2020, pp. 176–197  DOI: 10.1177/0042098018807628
  * [35] Alfredo J. Morales, Xiaowen Dong, Yaneer Bar-Yam and Alex ‘Sandy’ Pentland  “Segregation and polarization in urban areas”  In _Royal Society Open Science_ 6.10, 2019, pp. 190573  DOI: 10.1098/rsos.190573
  * [36] Manuel A Florez et al.  “Measuring the impacts of economic well being in commuting networks — A case study of Columbia”  In _Transportation Research Board, 96th Annual Meeting_ 17.03745, 2016
  * [37] Teodoro Dannemann, Boris Sotomayor-Gómez and Horacio Samaniego  “The time geography of segregation during working hours”  In _Royal Society Open Science_ 5.10, 2018, pp. 180749  DOI: 10.1098/rsos.180749
  * [38] Nibir Bora, Yu-Han Chang and Rajiv Maheswaran  “Mobility Patterns and User Dynamics in Racially Segregated Geographies of US Cities”  In _Proceedings of the international conference on social computing, behavioral-cultural modeling, and prediction_ , 2014, pp. 11–18  DOI: 10.1007/978-3-319-05579-4˙2
  * [39] Yannick Leo et al.  “Socioeconomic correlations and stratification in social-communication networks”  In _Journal of The Royal Society Interface_ 13.125, 2016, pp. 20160598  DOI: 10.1098/rsif.2016.0598
  * [40] Ngai Ming Yip, Ray Forrest and Shi Xian  “Exploring segregation and mobilities: Application of an activity tracking app on mobile phone”  In _Cities_ 59, 2016, pp. 156–163  DOI: 10.1016/j.cities.2016.02.003
  * [41] Laszlo Dobos et al.  “A multi-terabyte relational database for geo-tagged social network data”  In _2013 IEEE 4th International Conference on Cognitive Infocommunications (CogInfoCom)_ IEEE, 2013, pp. 289–294  DOI: 10.1109/CogInfoCom.2013.6719259
  * [42] Zsófia Kallus, Norbert Barankai, János Szüle and Gábor Vattay  “Spatial Fingerprints of Community Structure in Human Interaction Network for an Extensive Set of Large-Scale Regions”  In _PLOS ONE_ 10.5, 2015, pp. e0126713  DOI: 10.1371/journal.pone.0126713
  * [43] Zsófia Kallus et al.  “Video Pandemics: Worldwide Viral Spreading of Psy’s Gangnam Style Video”  In _ICT Innovations 2017: Data-Driven Innovation_ 778 Cham: Springer International Publishing, 2017, pp. 3–12  DOI: 10.1007/978-3-319-67597-8˙1
  * [44] Eszter Bokányi, Zoltán Lábszki and Gábor Vattay  “Prediction of employment and unemployment rates from Twitter daily rhythms in the US”  In _EPJ Data Science_ 6.1, 2017, pp. 14  DOI: 10.1140/epjds/s13688-017-0112-x
  * [45] Renaud Lambiotte et al.  “Geographical dispersal of mobile communication networks”  In _Physica A: Statistical Mechanics and its Applications_ 387.21, 2008, pp. 5317–5325  DOI: 10.1016/j.physa.2008.05.014
  * [46] Graham McNeill, Jonathan Bright and Scott A. Hale  “Estimating local commuting patterns from geolocated Twitter data”  In _EPJ Data Science_ 6.1 SpringerOpen, 2017, pp. 24  DOI: 10.1140/epjds/s13688-017-0120-x
  * [47] Duncan J. Watts and Steven H. Strogatz  “Collective dynamics of ’small-world9 networks”  In _Nature_ 393.6684 Macmillan Magazines Ltd, 1998, pp. 440–442  DOI: 10.1038/30918
  * [48] Geoff Boeing  “Urban spatial order: street network orientation, configuration, and entropy”  In _Applied Network Science_ 4.1 Applied Network Science, 2019, pp. 67  DOI: 10.1007/s41109-019-0189-1
  * [49] Gergő Tóth et al.  “Inequality is rising where social network segregation interacts with urban topology”  In _Nature Communications_ 12.1, 2021, pp. 1143  DOI: 10.1038/s41467-021-21465-0
  * [50] Eszter Hargittai and Eden Litt  “The tweet smell of celebrity success: Explaining variation in Twitter adoption among a diverse group of young adults”  In _New Media & Society_ 13.5, 2011, pp. 824–842  DOI: 10.1177/1461444811405805
  * [51] Tom Webster  “Twitter Usage In America : 2010”  In _Edison Research/ Arbitron Internet and Multimedia Study._ , 2010  URL: http://www.onecommunity.org/wp-content/uploads/2010/04/Twitter%7B%5C_%7DUsage%7B%5C_%7DIn%7B%5C_%7DAmerica%7B%5C_%7D2010.pdf
  * [52] Luke Sloan, Jeffrey Morgan, Pete Burnap and Matthew Williams  “Who Tweets? Deriving the Demographic Characteristics of Age, Occupation and Social Class from Twitter User Meta-Data”  In _PLOS ONE_ 10.3, 2015, pp. e0115545  DOI: 10.1371/journal.pone.0115545
  * [53] Alan Mislove et al.  “Understanding the Demographics of Twitter Users”  In _Int’l AAAI Conference on Weblogs and Social Media (ICWSM)_ , 2011, pp. 554–557  URL: http://www.aaai.org/ocs/index.php/ICWSM/ICWSM11/paper/viewFile/2816/3234
  * [54] Momin M Malik, Hemank Lamba, Constantine Nakos and Jürgen Pfeffer  “Population bias in geotagged tweets”  In _AAAI Workshop - Technical Report_ WS-15-18, 2015, pp. 18–27
  * [55] Kenneth Joseph, Peter M. Landwehr and Kathleen M. Carley  “Two 1%s Don’t Make a Whole: Comparing Simultaneous Samples from Twitter’s Streaming API”  In _Association fo the Advanced of Artificial Intelligence_ , 2014, pp. 75–83  DOI: 10.1007/978-3-319-05579-4˙10
  * [56] Fred Morstatter, Jürgen Pfeffer and Huan Liu  “When is it biased?”  In _Proceedings of the 23rd International Conference on World Wide Web - WWW ’14 Companion_ New York, New York, USA: ACM Press, 2014, pp. 555–556  DOI: 10.1145/2567948.2576952
  * [57] Jürgen Pfeffer, Katja Mayer and Fred Morstatter  “Tampering with Twitter’s Sample API”  In _EPJ Data Science_ 7.1 The Author(s), 2018, pp. 50  DOI: 10.1140/epjds/s13688-018-0178-0
  * [58] Dániel Kondor et al.  “Efficient classification of billions of points into complex geographic regions using hierarchical triangular mesh”  In _Proceedings of the 26th International Conference on Scientific and Statistical Database Management - SSDBM ’14_ New York, New York, USA: ACM Press, 2014, pp. 1–4  DOI: 10.1145/2618243.2618245
  * [59] J P Huchra and M.. Geller  “Groups of galaxies. I - Nearby groups”  In _The Astrophysical Journal_ 257, 1982, pp. 423  DOI: 10.1086/160000
  * [60] Yongchul Kwon et al.  “Scalable clustering algorithm for N-body simulations in a shared-nothing cluster”  In _Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics)_ 6187 LNCS, 2010, pp. 132–150  DOI: 10.1007/978-3-642-13818-8˙11
  * [61] János Szüle et al.  “Lost in the City: Revisiting Milgram’s Experiment in the Age of Social Networks”  In _PLoS ONE_ 9.11, 2014, pp. e111973  DOI: 10.1371/journal.pone.0111973

##  5 Acknowledgements

Eszter Bokányi was supported by the ÚNKP-20-4 New National Excellence Program
of the Ministry for Innovation and Technology from the source of the National
Research, Development and Innovation Fund of Hungary. Márton Karsai
acknowledges support from the H2020 SoBigData++ project (H2020-871042) and the
DataRedux ANR project (ANR-19-CE46-0008). Balázs Lengyel and Sándor Juhász
acknowledge support from the Hungarian Scientific Research Fund (OTKA
K-129207). We thank for the usage of ELKH Cloud (https://science-cloud.hu/)
that significantly helped us achieving the results published in this paper. We
thank József Stéger for helping in the maintenance of the Twitter database,
and Szabolcs Tóth-Zs. (https://bandart.eu/) for figure design.

## Supplementary information

### SI 1: Observed users across the top 50 US metropolitan areas

Figure 5: (A) Map of the selected 50 metropolitan areas with the highest
population in the US. (B) The histogram represents the number of observed
users with home and work locations, minimum 100 meter commute and minimum 1
connection to a user with discovered home and work locations in the same metro
area. The metro areas are ordered by population.

### SI 2: Population and observed users in metro areas

Figure 6: Population size and observed users in the selected 50 metropolitan
areas of the US. Observed users have detected home and work locations, commute
at least 100 meter and have at least 1 friendship tie to users with discovered
home and work locations inside the same metro area.

### SI 3: Distribution of commuting distances

Figure 7: The distribution of commuting distances in the selected 50
metropolitan areas represented by boxplots. Black dots represent the average
commuting distance in each metro area in our data. We only consider those
users for whom home and work locations are identifiable, home and work is
separated by a minimum 100 meter commute, and the user has minimum 1 friend
with identified home and work locations in the same metro area. The metro
areas are ordered by population and outlier individuals are not presented.

### SI 4: Effect of different distance thresholds

Figure 8: Network characteristics of users commuting above and below 3 km
distance in the top 50 metropolitan areas of the United States. The slightly
more transparent signs indicate that differences of means are not significant
(p$>$0.05).  Figure 9: Network characteristics of users commuting above or
below 5 km distance in the top 50 metropolitan areas of the United States. The
slightly more transparent signs indicate that differences of means are not
significant (p$>$0.05).  Figure 10: Network characteristics of users commuting
above or below 10 km distance in the top 50 metropolitan areas of the United
States. The slightly more transparent signs indicate that differences of means
are not significant (p$>$0.05).

### SI 5: Regression on network characteristics and commuting

Table 1 presents 8 linear regression models to complement Figure 2 of the main
text. For these robustness checks we log transferred (indicated in the table)
or normalized the variables. We introduce control variables step-by-step.
Model (1)-(4) further strengthens our previous findings at Figure 2a as longer
commuting is connected to lower local clustering in the mutual followership
ego network of users. However, the positive and significant quadratic term
suggests that commuting distance has an increasing return on network
clustering. This relationship is stable even while controlling for the degree,
home income and metro area of users. Model (5) shows that longer commutes are
linked to ego networks with lower income difference between friends and
commuting distance has a diminishing return on income difference to friends.
However, this relationship does not hold while controlling for the degree and
home income of users in Model (8) whereas controllers introduced in Models
(6)-(7) are stable.

Table 1: Relationship between commuting and network characteristics | Dependent variable
---|---
| Local clustering | Income diff. (log)
| (1) | (2) | (3) | (4) | (5) | (6) | (7) | (8)
Distance (log) | $-0.056^{***}$ |  |  | $-0.036^{***}$ | $0.078^{**}$ |  |  | $-0.035$
| $(0.003)$ |  |  | $(0.003)$ | $(0.031)$ |  |  | $(0.028)$
|  |  |  |  |  |  |  |
Distance2 (log) | $0.023^{***}$ |  |  | $0.013^{***}$ | $-0.059^{***}$ |  |  | $0.008$
| $(0.002)$ |  |  | $(0.001)$ | $(0.016)$ |  |  | $(0.014)$
|  |  |  |  |  |  |  |
Degree (log) |  | $-0.178^{***}$ |  | $-0.179^{***}$ |  | $0.368^{***}$ |  | $0.422^{***}$
|  | $(0.001)$ |  | $(0.001)$ |  | $(0.005)$ |  | $(0.005)$
|  |  |  |  |  |  |  |
Income (log) |  |  | $0.018^{***}$ | $-0.003^{**}$ |  |  | $3.506^{***}$ | $3.546^{***}$
|  |  | $(0.001)$ | $(0.001)$ |  |  | $(0.013)$ | $(0.013)$
|  |  |  |  |  |  |  |
Constant | $0.155^{***}$ | $0.369^{***}$ | $0.049^{***}$ | $0.404^{***}$ | $1.049^{***}$ | $0.651^{***}$ | $-14.394^{***}$ | $-15.014^{***}$
| $(0.002)$ | $(0.002)$ | $(0.007)$ | $(0.006)$ | $(0.020)$ | $(0.016)$ | $(0.059)$ | $(0.060)$
|  |  |  |  |  |  |  |
Metro FE | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes
Observations | 261,283 | 261,283 | 258,949 | 258,949 | 348,728 | 348,728 | 345,610 | 345,610
R2 | 0.009 | 0.243 | 0.007 | 0.244 | 0.009 | 0.023 | 0.182 | 0.200
Adjusted R2 | 0.008 | 0.243 | 0.007 | 0.244 | 0.009 | 0.023 | 0.182 | 0.200
Note: |  ∗p$<$0.1; ∗∗p$<$0.05; ∗∗∗p$<$0.01

Table 2 presents 3 additional linear regression models to uncover the
relationship between the degree of users and their commuting distance. Results
are in line with the trends of SI 4 Figure 8-10 as longer commuting is
connected to higher degree, however, commuting distance has diminishing
returns on user degree.

Table 2: Relationship between degree and commuting | Dependent variable
---|---
| Degree
| (1) | (2) | (3)
Distance (log) | $0.146^{***}$ |  | $0.144^{***}$
| $(0.010)$ |  | $(0.010)$
|  |  |
Distance2 (log) | $-0.074^{***}$ |  | $-0.073^{***}$
| $(0.005)$ |  | $(0.005)$
|  |  |
Income (log) |  | $-0.096^{***}$ | $-0.096^{***}$
|  | $(0.005)$ | $(0.005)$
|  |  |
Constant | $1.047^{***}$ | $1.528^{***}$ | $1.474^{***}$
| $(0.007)$ | $(0.021)$ | $(0.021)$
|  |  |
Metro FE | Yes | Yes | Yes
Observations | 348,728 | 345,610 | 345,610
R2 | 0.007 | 0.007 | 0.008
Adjusted R2 | 0.007 | 0.007 | 0.008
Note: |  ∗p$<$0.1; ∗∗p$<$0.05; ∗∗∗p$<$0.01

### SI 6: All assortativity matrices for the top 50 US metropolitan areas

Figure 11: Assortativity matrices $C$ and $S$ in all 50 investigated US
metropolitan areas for the overall, mobile and non-mobile users. $\rho$-values
are indicated in the labels.

Figure 11: (continued) Assortativity matrices $C$ and $S$ in all 50
investigated US metropolitan areas for the overall, mobile and non-mobile
users. $\rho$-values are indicated in the labels.

Figure 11: (continued) Assortativity matrices $C$ and $S$ in all 50
investigated US metropolitan areas for the overall, mobile and non-mobile
users. $\rho$-values are indicated in the labels.

Figure 11: (continued) Assortativity matrices $C$ and $S$ in all 50
investigated US metropolitan areas for the overall, mobile and non-mobile
users. $\rho$-values are indicated in the labels.

Figure 11: (continued) Assortativity matrices $C$ and $S$ in all 50
investigated US metropolitan areas for the overall, mobile and non-mobile
users. $\rho$-values are indicated in the labels.

Figure 11: (continued) Assortativity matrices $C$ and $S$ in all 50
investigated US metropolitan areas for the overall, mobile and non-mobile
users. $\rho$-values are indicated in the labels.

### SI 7: Different distance thresholds and assortativity change

Figure 12: Change in the assortativity of the social network matrices vs. the
commuting matrices for different distance thresholds Figure 13: Change in the
assortativity of the social network matrices vs. the commuting matrices for
two random user groups

### SI 8: Diversity in commuting and social connections

We measure the diversity $S_{C}$ and $S_{S}$ of the matrices $C$ and $S$ (or
for any matrices on the smaller user base, e.g. $S_{d>{median}}$) by averaging
the normalized entropies of the columns of the matrices. Formally, for a
$10\times 10$ matrix $X$, where the sum of the columns $\sum_{j}X_{ij}=1$ for
every possible $j$,

$S_{X}=\frac{1}{10}\cdot\sum\limits_{j=1}^{10}\frac{1}{\log
10}\sum\limits_{i=1}^{10}X_{ij}\cdot\log X_{ij},$ (5)

which means that $S_{X}=0$ corresponds to a matrix in which every column
contains exactly one element that is 1, and the others are 0, and $S_{X}=1$
corresponds to the case when every element of the matrix is equal,
$\frac{1}{10}$. Thus, $S_{X}$ values closer to 1 mean matrices in which
commuting or friendship ties in a column are on average more distributed over
multiple income classes, whereas smaller $S_{X}$ values mean matrix columns
with rather one dominant element.

In parallel to the decreasing assortativity with longer commutes, we can
observe an increasing average diversity for the connection patterns of both
matrices, if measured by the averaged entropy of the column-wise probability
distributions $S_{S}$ and $S_{C}$ (see Section 4 for details on this measure).
This increase in the diversity is shown for all 50 metropolitan areas. Again,
there is a higher increase in diversity for the commuting assortativity
matrix, if we compare long commuters to short commuters, but this increase in
the diversity is in parallel with the increase in the friendship assortativity
matrix. If we measure which income deciled contribute to the increasing
entropy values in both the mobility and the social network patterns, we can
see that the lowest and highest income classes have the most diversity
increase (see the inset). Therefore, it is most likely that rearrangement of
the social connections of the richest and poorest deciles contribute most to
the 30% decrease in social network assortativity that comes with longer
commutes.

Figure 14: Diversity Figure 15: Assortativity of commuting and social network
matrices by income groups.


# Machine Learning the Square-Lattice Ising Model

Burak Çivitcioğlu1 Rudolf A. Römer2 and Andreas Honecker1 1 Laboratoire de
Physique Théorique et Modélisation, CNRS UMR 8089, CY Cergy Paris Université,
Cergy-Pontoise, France  2 Department of Physics, University of Warwick,
Coventry, CV4 7AL, United Kingdom<EMAIL_ADDRESS>
###### Abstract

Recently, machine-learning methods have been shown to be successful in
identifying and classifying different phases of the square-lattice Ising
model. We study the performance and limits of classification and regression
models. In particular, we investigate how accurately the correlation length,
energy and magnetisation can be recovered from a given configuration. We find
that a supervised learning study of a regression model yields good predictions
for magnetisation and energy, and acceptable predictions for the correlation
length.

##  1 Introduction

Condensed-matter physics studies the properties of matter with many
constituents and interactions [1]. One central task in condensed-matter and
statistical physics is to identify different phases of the system and locate
the critical points separating these in the space of parameters. Machine
learning (ML) is the study of algorithms that improve their performance by
gaining experience from data. It has been used for image classification,
object detection, self-driving cars, speech recognition and many other tasks
that rely on data [2]. ML is commonly categorised into supervised,
unsupervised and reinforcement learning. Recently, ML methods have been
employed to tackle condensed-matter problems and have shown promising
predictions in topics such as studying the phases of the Ising model [3, 4,
5], disordered quantum systems [6, 7], phase transitions in the Bose-Hubbard
[8, 9], the Blume-Capel model [10], a highly degenerate biquadratic-exchange
spin-one Ising variant, and the two-dimensional (2D) XY model [10], as well as
material properties [11].

The square-lattice Ising model is an exactly solved model [12].
Notwithstanding its exact solution, it is commonly employed in the ML context
[3, 4, 5, 13, 14, 15, 16, 17, 18]. Motivations for such ML studies of the
Ising model in 2D include the readily available comparison to the exact
solution and that training data can be easily generated using standard Monte-
Carlo simulations. Here, we continue along these lines and investigate the
problem of predicting the temperature dependence of energy $E$, magnetisation
$m$ and correlation length $\xi$ for the square-lattice Ising model by ML of
configurations.

(a)  (b)  (c)

Figure 1: Configurations of the Ising model on a $100\times 100$ square
lattice with periodic boundary conditions at temperatures (a) $T=1.5<T_{c}$,
(b) $2.3\sim T_{c}$ and (c) $4>T_{c}$. In each configuration, black and white
pixels represent spin up and spin down states, respectively. Panel (a) shows a
ferromagnetic configuration at low temperature, (b) a critical configuration
close to $T_{c}$ and (c) a paramagnetic configuration at high temperatures.

##  2 Ising Model, Methods, Data and the ML Model

The ferromagnetic Ising model is defined by the Hamiltonian

$E=-\sum_{\langle i,j\rangle}s_{i}s_{j},$ (1)

where $s_{i}$ is the spin at site $i$ that can point up ($+1$) or down ($-1)$
and $\langle i,j\rangle$ are nearest-neighbour pairs [19, 20]. Here we focus
on $100\times 100$ square lattices subject to periodic boundary conditions.
This choice of system size is mainly motivated by the ML context where the
codes have been optimised for treating images whose size does not exceed a few
hundred times a few hundred pixels. For a given configuration, we define the
magnetisation $m$ and the correlation length $\xi$, respectively, as

$m=\frac{1}{N}\left|\sum_{i}s_{i}\right|,\quad\xi^{2}=\frac{\sum_{r}r^{2}g(r)}{\sum_{r}g(r)},$
(2)

where $g(r)=\sum_{i\neq j}s_{i}s_{j}-m^{2}$ denotes the connected two-point
correlation function and $r=|i-j|$ is the distance between lattice sites $i$,
$j$ [21]. We note that the correlation length $\xi$ quantifies the
characteristic scale of an individual spin configuration.

We employ the Metropolis algorithm to generate many $100\times 100$
configurations as data for the ML approach [22, 19, 20]. We start the
simulations from an initial, hot temperature $T=100$. This is subsequently
slowly reduced to $T=4$ in 1000 Monte-Carlo sweeps (as usual, a Monte-Carlo
sweep is defined as one attempt on average to flip each spin in the system).
We then collect five spin configurations at $T=4$, again with $1000$ MC sweeps
between each measurement. Next, we reduce to $T=3.95$ in $1000$ further MC
sweeps and then again collect another five, well-separated, spin
configurations. This procedure then repeats until we reach $T=1.5$. We then
restart the data generation for another sample, with the overall ensemble
consisting of $416$ such samples. The training and cross-validation data hence
consists of overall $2080$ configurations for each of the $51$ distinct
temperatures $T=1.5,1.55,1.6,\ldots,4$. Ten percent of this data is reserved
as cross-validation data for ML. The test set consists of $250$ additional
configurations for each $T$ with the same parameters as the training and
cross-validation data. Each sample consists of the spatial configuration and
its $m$, $E$, $\xi$ and $g(r)$ values. Examples of configurations are shown in
Fig. 1 with (b) close to the critical temperature, exactly known in the
thermodynamic limit to be $T_{c}=2/\ln(1+\sqrt{2})\approx 2.269$ [12], (a) in
the ferromagnetic phase, $T<T_{c}$ and (b) in the paramagnetic phase,
$T>T_{c}$.

For the ML classification and regression tasks with $E$, $m$ and $\xi$, we use
the same convolutional neural network (CNN) architecture with eight
convolutional layers (with a $3\times 3$ kernel, stride $1$ in each layer and
the number of feature maps/filters increasing as $16,16,32,32,\ldots,128$),
and $2\times 2$ pooling layers with $\mathrm{ReLU}(x)=\max(0,x)$ activation
function, and $25\%$ dropout between layers. This is capped by three dense
layers (of size $512$, $128$, while the last dense layer has variable size $K$
for classification and $1$ for regression). For classification, $K$ expresses
the number of categories, and the softmax activation function
$S:\mathbb{R}^{K}\rightarrow[0,1]^{K},S(\mathbf{r})_{i}=e^{r_{i}}/\sum_{j=1}e^{r_{j}}$,
with $\mathbf{r}=(r_{1},r_{2},\ldots,r_{K})\in\mathbb{R}^{K}$,
$i=(1,2,\ldots,K)$, is used in the output layer. The loss function is
categorical cross entropy [2]. For regression, although we stay with the same
CNN architecture, we adjust the output layer to a regression problem. Instead
of the softmax activated output layer, a single dense node is used with no
activation function. This single node returns the desired numerical estimate.
As loss function we now work with the mean squared error (MSE). Overall, this
results in six separately trained networks with separate weights, but shared
architecture. We have used the TensorFlow implementation 2.4.1 for all machine
learning tasks described here [23].

##  3 Results

Figure 2:  Confusion matrices for temperature classification. Horizontal axes
denote the true values while the vertical axes indicate the predicted ones.
The colour bar represents the number of samples in each entry. (a) Two
classes: $T\in\\{1.5,4.0\\}$, (b) three classes: $T=1.5$, $2.3\sim T_{c}$ and
$4.0$, (c) seven classes: $T\in\\{1.50,1.75,2.05,2.30,2.55,2.85,3.10\\}$.

Our results for the confusion matrices of the classification model for
different numbers of categories are presented in Fig. 2. A “confusion matrix”
represents the predicted label of the class as a function of the true one in
matrix form, with an error-free prediction corresponding to a diagonal matrix.
In Fig. 2(a), the categories of the phases, namely the ferromagnetic phase at
$T=1.5$ and the paramagnetic phase at $T=4.0$, are correctly identified for
all the test samples. Similarly, in Fig. 2(b), the categories are classified
correctly for all the test samples, namely $T=1.5$, $T=2.3\sim T_{c}$ and
$T=4.0$. When the number of categories is increased to seven, the confusion
matrix develops off-diagonal terms, indicating ”confusion”, i.e. false
positives and false negatives, mostly with neighbouring temperatures as shown
in Fig. 2(c). Such misclassification in the $T>T_{c}$, paramagnetic phase is
observed only among neighbouring temperatures, with a total of $39$
misclassifications corresponding to $5.2\%$ of all cases. In the $T<T_{c}$,
ferromagnetic phase, there are $82$ misclassifications corresponding to
$10.9\%$, and only one of them is confused with a temperature that is not a
neighbouring one, namely a $T=2.05$ case is misclassified as $T=3.1$. For
$T=2.3\sim T_{c}$, only $7$ out of $250$ cases, i.e., $2.8\%$ are
misclassified, and only one of them ($T=1.5$) is not a neighbouring
temperature. We note that most of the confusion occurs at the highest and
lowest $T$’s. Indeed, the probability of a given configuration is controlled
by its energy $E$. For a given $T$ and on a finite system, the energy
distribution has a certain width $\sigma_{E}$, and, as shown below in Fig. 4
for our case, these are consistent with the order of the confusion that we
observe, at least between $T=1.5\leftrightarrow 1.75$ and $2.85\leftrightarrow
3.1$, respectively. Thus, the classification according to $7$ distinct
temperatures reaches the physical limits of the $100\times 100$ lattice.

Figure 3: Correlation length $\xi$ as a function of $T$. We show averages
$\langle\xi_{T}\rangle$ ($\star$) obtained via Monte-Carlo simulations as well
as predictions $\langle\xi_{P}\rangle$ (red $\times$) for the test data. The
grey shaded region denotes the standard deviation of the training data.
$\xi_{T}$ (blue) and $\xi_{P}$ (green $+$) are the Monte-Carlo results and ML
predictions for a one specific sample, respectively. The thin black vertical
line indicates the critical temperature $T_{c}$ of an infinite system. Lines
connecting data values are guides-to-the-eye only. The training was done only
for the temperature values that are indicated by a grey vertical line in the
background. The inset shows the relation of the true values and the predicted
values with the diagonal giving the perfect result $\xi_{T}=\xi_{P}$.  Figure
4: Energy per site $E$ as a function of $T$. Averages $\langle E_{T}\rangle$,
$\langle E_{P}\rangle$ and single-sample values $E_{T}$ and $E_{P}$ are
indicated by symbols, as in Fig. 3. The inset shows the deviations from the
perfect result $E_{T}=E_{P}$. Figure 5: Magnetisation $m$ as a function of
$T$. Averages $\langle m_{T}\rangle$, $\langle m_{P}\rangle$ and single-sample
values $m_{T}$ and $m_{P}$ are indicated by symbols, as in Fig. 3. The inset
shows the deviations from a perfect result $m_{T}=m_{P}$.

We now turn to the regression models. Results for $\xi$, $E$ and $m$ are
presented in Figs. 3, 4 and 5, respectively. Averages of the test data are
denoted by black stars and their respective standard deviations
$\sigma_{\xi}$, $\sigma_{E}$ and $\sigma_{m}$, respectively, are indicated by
the grey shaded region in the background. These standard deviations indicate
the fluctuations for each quantity on the $100\times 100$ lattice. The
fluctuations are largest for $\xi$ (Fig. 3), still significant for $m$ around
$T_{c}$ (Fig. 5) and smallest but still non-negligible for $E$ (Fig. 4).
Values for one concrete configuration are shown in blue and as a function of
$T$ one observes indeed fluctuations on the scale of the standard deviations.
We have used only every second temperature value for training; these are
marked by the grey vertical lines in the background. Averages of the
predictions are shown by red crosses. These lie within or close to the grey
shaded region, showing that the network is indeed able to reconstruct $\xi$,
$E$ and $m$ from a given configuration. This is also valid for the
intermediate temperatures for which the network has not been trained, thus
demonstrating the ability of the network to generalise. For more detail, we
also show by green pluses the predicted values for the specific sample whose
raw Monte-Carlo values were shown in blue. The fluctuations of these
predictions generally follow those of the true values. Just for $\xi$ (Fig.
3), the predictions do not fully reproduce the outliers of the raw data, i.e.,
ML appears to be trying to actually smooth out the sample-to-sample
fluctuations. The insets of Figs. 3, 4 and 5 show the correlation between the
predicted values and the true labels. Here, red symbols are for averages and
green ones for the selected specific sample; closed symbols denote cases for
which the CNN has been trained, open ones for temperature values where this is
not the case. Again, one observes overall good performance of the network at
measuring these values. Nevertheless, for $\xi$ (inset of Fig. 3) one observes
a systematic trend of the predicted values to lie below the true ones. For
$m$, in particular intermediate values tend to be predicted slightly larger
than their true value (inset of Fig. 5). We have observed other but comparable
deviations in other trained CNNs and thus believe these deviations from the
diagonal to represent the limits of the accuracy of the neural network.

##  4 Discussion and Conclusions

We have shown that the specified CNN model is able to successfully classify
configurations according to their temperatures until it reaches the physical
limits of a $100\times 100$ system for our choice of the $7$ categories. We
also found that a regression model is able to extract the correlation length
$\xi$, energy $E$ and magnetisation $m$ with an accuracy that is consistent
with the fluctuations of these quantities on the $100\times 100$ lattice. The
fact that this also works for intermediate temperatures, where the network has
not been trained, demonstrates the ability of the CNN to learn more general
features. One possible next step is to investigate transfer learning for the
models that are trained here. Indeed, the case investigated here is the
$J_{1}=1$, $J_{2}=0$ special case of the $J_{1}$-$J_{2}$ Ising model that has
recently been investigated from the machine-learning perspective [17, 18], and
it would be interesting to see how our neural networks trained on the case
$J_{2}/J_{1}=0$ perform for other values of $J_{2}/J_{1}$.

## References

## References

  * [1] Domb C and Green M S 1972–1976 Phase Transitions and Critical Phenomena vols. 1, 2, 5B (Academic Press)
  * [2] Alpaydin E 2004 Introduction to Machine Learning 4th ed (The MIT Press) ISBN 9780262012119 URL https://mitpress.mit.edu/books/introduction-machine-learning
  * [3] Tanaka A and Tomiya A 2017 J. Phys. Soc. Jpn. 86 063001 URL http://doi.org/10.7566/JPSJ.86.063001
  * [4] Walker N, Tam K M, Novak B and Jarrell M 2018 Phys. Rev. E 98 053305 URL https://doi.org/10.1103/PhysRevE.98.053305
  * [5] Alexandrou C, Athenodorou A, Chrysostomou C and Paul S 2020 Eur. Phys. J. B 93 226 URL https://doi.org/10.1140/epjb/e2020-100506-5
  * [6] Ohtsuki T and Ohtsuki T 2016 J. Phys. Soc. Jpn. 85 123706 URL http://doi.org/10.7566/JPSJ.85.123706
  * [7] Ohtsuki T and Mano T 2020 J. Phys. Soc. Jpn. 89 022001 URL http://doi.org/10.7566/JPSJ.89.022001
  * [8] Huembeli P, Dauphin A and Wittek P 2018 Phys. Rev. B 97 134109 URL https://doi.org/10.1103/PhysRevB.97.134109
  * [9] Dong X Y, Pollmann F and Zhang X F 2019 Phys. Rev. B 99 121104 URL https://doi.org/10.1103/PhysRevB.99.121104
  * [10] Hu W, Singh R R P and Scalettar R T 2017 Phys. Rev. E 95 062122 URL https://doi.org/10.1103/PhysRevE.95.062122
  * [11] Pilania G, Wang C, Jiang X, Rajasekaran S and Ramprasad R 2013 Sci. Rep. 3 2810 URL https://doi.org/10.1038/srep02810
  * [12] Onsager L 1944 Phys. Rev. 65 117–149 URL https://doi.org/10.1103/PhysRev.65.117
  * [13] Morningstar A and Melko R G 2018 J. Mach. Learn. Res. 18 1–17 URL http://jmlr.org/papers/v18/17-527.html
  * [14] Walker N, Tam K M and Jarrell M 2020 Sci. Rep. 10 13047 URL https://doi.org/10.1038/s41598-020-69848-5
  * [15] D’Angelo F and Böttcher L 2020 Phys. Rev. Research 2 023266 URL https://doi.org/10.1103/PhysRevResearch.2.023266
  * [16] Carrasquilla J and Melko R G 2017 Nat. Phys. 13 431–434 URL http://doi.org/10.1038/nphys4035
  * [17] Corte I, Acevedo S, Arlego M and Lamas C 2021 Comput. Mater. Sci. 198 110702 URL https://doi.org/10.1016/j.commatsci.2021.110702
  * [18] Acevedo S, Arlego M and Lamas C A 2021 Phys. Rev. B 103 134422 URL https://doi.org/10.1103/PhysRevB.103.134422
  * [19] Berg, B. Markov Chain Monte Carlo Simulations and Their Statistical Analysis with Web-Based Fortran Code. (World Scientific Publishing Company,2004), URL https://doi.org/10.1142/5602
  * [20] Landau D P and Binder K 2014 A Guide to Monte Carlo Simulations in Statistical Physics 4th ed (Cambridge University Press) URL https://doi.org/10.1017/CBO9781139696463
  * [21] Montroll E W, Potts R B and Ward J C 1963 J. Math. Phys. 4 308–322 URL https://doi.org/10.1063/1.1703955
  * [22] Metropolis N, Rosenbluth A W, Rosenbluth M N, Teller A H and Teller E 1953 J. Chem. Phys. 21 1087–1092 URL https://doi.org/10.1063/1.1699114
  * [23] Abadi M et al. 2015 TensorFlow: Large-scale machine learning on heterogeneous systems software available from tensorflow.org URL https://www.tensorflow.org/