<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/game-of-friendship-paradox/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://freakonometrics.hypotheses.org/53310"> R-english – Freakonometrics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In the introduction of my course next week, I will (briefly) mention networks, and I wanted to provide some illustration of the Friendship Paradox. On <a rel="nofollow" href="https://www.macalester.edu/~abeverid/thrones.html" target="_blank">network of thrones</a> (discussed in <a rel="nofollow" href="https://www.maa.org/sites/default/files/pdf/Mathhorizons/NetworkofThrones%20(1).pdf" target="_blank">Beveridge and Shan (2016)</a>), there is a dataset with the network of characters in <a rel="nofollow" href="https://en.wikipedia.org/wiki/Game_of_Thrones" target="_blank">Game of Thrones</a>. The word “friend” might be abusive here, but let’s continue to call connected nodes “friends”. The friendship paradox states that</p>
<blockquote>
<p>People on average have fewer friends than their friends</p>
</blockquote>
<p>This was discussed in <a rel="nofollow" href="http://www.macroeconomics.tu-berlin.de/fileadmin/fg124/networks/Lectures/Summer2012/Material/American_Journal_of_Sociology_1991_Feld.pdf" target="_blank">Feld (1991)</a> for instance, or <a rel="nofollow" href="http://www.psych.nyu.edu/jost/Zuckerman%20&amp;%20Jost%20(2001)%20What%20Makes%20You%20Think%20You%27re%20So%20Popular1.pdf" target="_blank">Zuckerman &amp; Jost (2001)</a>. Let’s try to see what it means here. First, let us get a copy of the dataset</p>
<div><table><tr><td><pre>1
2
3
4
</pre></td><td><pre><span>download.<span>file</span></span><span>(</span><span>&quot;https://www.macalester.edu/~abeverid/data/stormofswords.csv&quot;</span>,<span>&quot;got.csv&quot;</span><span>)</span>
GoT<span>=</span><span>read.<span>csv</span></span><span>(</span><span>&quot;got.csv&quot;</span><span>)</span>
<span>library</span><span>(</span>networkD3<span>)</span>
simpleNetwork<span>(</span>GoT<span>[</span>,<span>1</span><span>:</span><span>2</span><span>]</span><span>)</span></pre></td></tr></table></div>
<p>Because it is difficult for me to incorporate some <a rel="nofollow" href="https://en.wikipedia.org/wiki/D3.js" target="_blank">d3js</a> script in the blog, I will illustrate with a more basic graph,<br>
<img alt="" src="https://i1.wp.com/f-origin.hypotheses.org/wp-content/blogs.dir/253/files/2018/06/graph-of-thrones.png?w=456&ssl=1" data-recalc-dims="1"><br>
Consider a vertex <img alt="v\in V" title="v\in V" src="https://s0.wp.com/latex.php?latex=v%5Cin+V&bg=ffffff&fg=000&s=0" class="latex"> in the undirected graph <img alt="G=(V,E)" title="G=(V,E)" src="https://s0.wp.com/latex.php?latex=G%3D%28V%2CE%29&bg=ffffff&fg=000&s=0" class="latex"> (with classical graph notations), and let <img alt="d(v)" title="d(v)" src="https://s0.wp.com/latex.php?latex=d%28v%29&bg=ffffff&fg=000&s=0" class="latex"> denote the number of edges touching it (i.e. <img alt="v" title="v" src="https://s0.wp.com/latex.php?latex=v&bg=ffffff&fg=000&s=0" class="latex"> has <img alt="d(v)" title="d(v)" src="https://s0.wp.com/latex.php?latex=d%28v%29&bg=ffffff&fg=000&s=0" class="latex"> friends). The average number of friends of a random person in the graph is <img alt="\mu = \frac{1}{n_V}\sum_{v\in V} d(v)=\frac{2 n_E}{n_V}" title="\mu = \frac{1}{n_V}\sum_{v\in V} d(v)=\frac{2 n_E}{n_V}" src="https://s0.wp.com/latex.php?latex=%5Cmu+%3D+%5Cfrac%7B1%7D%7Bn_V%7D%5Csum_%7Bv%5Cin+V%7D+d%28v%29%3D%5Cfrac%7B2+n_E%7D%7Bn_V%7D&bg=ffffff&fg=000&s=0" class="latex"> The average number of friends that a typical friend has is<br>
<img alt="\frac{1}{n_V}\sum_{v\in V} \left(\frac{1}{d(v)}\sum_{v'\in E_v} d(v')\right)" title="\frac{1}{n_V}\sum_{v\in V} \left(\frac{1}{d(v)}\sum_{v'\in E_v} d(v')\right)" src="https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7Bn_V%7D%5Csum_%7Bv%5Cin+V%7D+%5Cleft%28%5Cfrac%7B1%7D%7Bd%28v%29%7D%5Csum_%7Bv%27%5Cin+E_v%7D+d%28v%27%29%5Cright%29&bg=ffffff&fg=000&s=0" class="latex">But<br>
<span data-display="true" class="wp-katex-eq">\sum_{v\in V} \left(\frac{1}{d(v)}\sum_{v’\in E_v} d(v’)\right)=\sum_{v,v’ \in G} \left(<br><br>
\frac{d(v’)}{d(v)}+\frac{d(v)}{d(v’)}\right)</span><img alt="=\sum_{v,v' \in G}\left(\frac{d(v')^2+d(v)^2}{d(v)d(v')}\right)=\sum_{v,v' \in G} \left(\frac{(d(v')-d(v))^2}{d(v)d(v')}+2\right){\color{red}{\succ}}\sum_{v,v' \in G} \left(2\right)=\sum_{v\in V} d(v)" title="=\sum_{v,v' \in G}\left(\frac{d(v')^2+d(v)^2}{d(v)d(v')}\right)=\sum_{v,v' \in G} \left(\frac{(d(v')-d(v))^2}{d(v)d(v')}+2\right){\color{red}{\succ}}\sum_{v,v' \in G} \left(2\right)=\sum_{v\in V} d(v)" src="https://s0.wp.com/latex.php?latex=%3D%5Csum_%7Bv%2Cv%27+%5Cin+G%7D%5Cleft%28%5Cfrac%7Bd%28v%27%29%5E2%2Bd%28v%29%5E2%7D%7Bd%28v%29d%28v%27%29%7D%5Cright%29%3D%5Csum_%7Bv%2Cv%27+%5Cin+G%7D+%5Cleft%28%5Cfrac%7B%28d%28v%27%29-d%28v%29%29%5E2%7D%7Bd%28v%29d%28v%27%29%7D%2B2%5Cright%29%7B%5Ccolor%7Bred%7D%7B%5Csucc%7D%7D%5Csum_%7Bv%2Cv%27+%5Cin+G%7D+%5Cleft%282%5Cright%29%3D%5Csum_%7Bv%5Cin+V%7D+d%28v%29&bg=ffffff&fg=000&s=0" class="latex"><br>
Thus,<img alt="\frac{1}{n_V}\sum_{v\in V} \left(\frac{1}{d(v)}\sum_{v'\in E_v} d(v')\right)\succ \frac{1}{n_V}\sum_{v\in V} d(v)" title="\frac{1}{n_V}\sum_{v\in V} \left(\frac{1}{d(v)}\sum_{v'\in E_v} d(v')\right)\succ \frac{1}{n_V}\sum_{v\in V} d(v)" src="https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7Bn_V%7D%5Csum_%7Bv%5Cin+V%7D+%5Cleft%28%5Cfrac%7B1%7D%7Bd%28v%29%7D%5Csum_%7Bv%27%5Cin+E_v%7D+d%28v%27%29%5Cright%29%5Csucc+%5Cfrac%7B1%7D%7Bn_V%7D%5Csum_%7Bv%5Cin+V%7D+d%28v%29&bg=ffffff&fg=000&s=0" class="latex"><br>
Note that this can be related to the variance decomposition <img alt="\text{Var}[X]=\mathbb{E}[X^2]-\mathbb{E}[X]^2" title="\text{Var}[X]=\mathbb{E}[X^2]-\mathbb{E}[X]^2" src="https://s0.wp.com/latex.php?latex=%5Ctext%7BVar%7D%5BX%5D%3D%5Cmathbb%7BE%7D%5BX%5E2%5D-%5Cmathbb%7BE%7D%5BX%5D%5E2&bg=ffffff&fg=000&s=0" class="latex">i.e.<img alt="\frac{\mathbb{E}[X^2]}{\mathbb{E}[X]} =\mathbb{E}[X]+\frac{\text{Var}[X]}{\mathbb{E}[X]}\succ\mathbb{E}[X]" title="\frac{\mathbb{E}[X^2]}{\mathbb{E}[X]} =\mathbb{E}[X]+\frac{\text{Var}[X]}{\mathbb{E}[X]}\succ\mathbb{E}[X]" src="https://s0.wp.com/latex.php?latex=%5Cfrac%7B%5Cmathbb%7BE%7D%5BX%5E2%5D%7D%7B%5Cmathbb%7BE%7D%5BX%5D%7D+%3D%5Cmathbb%7BE%7D%5BX%5D%2B%5Cfrac%7B%5Ctext%7BVar%7D%5BX%5D%7D%7B%5Cmathbb%7BE%7D%5BX%5D%7D%5Csucc%5Cmathbb%7BE%7D%5BX%5D&bg=ffffff&fg=000&s=0" class="latex">(Jensen inequality). But let us get back to our network. The list of nodes is</p>
<div><table><tr><td><pre>1
2
</pre></td><td><pre>M<span>=</span><span>(</span><span>rbind</span><span>(</span><span>as.<span>matrix</span></span><span>(</span>GoT<span>[</span>,<span>1</span><span>:</span><span>2</span><span>]</span><span>)</span>,<span>as.<span>matrix</span></span><span>(</span>GoT<span>[</span>,<span>2</span><span>:</span><span>1</span><span>]</span><span>)</span><span>)</span><span>)</span>
nodes<span>=</span><span>unique</span><span>(</span>M<span>[</span>,<span>1</span><span>]</span><span>)</span></pre></td></tr></table></div>
<p>and we each of them, we can get the list of friends, and the number of friends</p>
<div><table><tr><td><pre>1
2
</pre></td><td><pre>friends <span>=</span> <span>function</span><span>(</span>x<span>)</span> <span>as.<span>character</span></span><span>(</span>M<span>[</span><span>which</span><span>(</span>M<span>[</span>,<span>1</span><span>]</span><span>==</span>x<span>)</span>,<span>2</span><span>]</span><span>)</span>
nb_friends <span>=</span> <span>Vectorize</span><span>(</span><span>function</span><span>(</span>x<span>)</span> <span>length</span><span>(</span>friends<span>(</span>x<span>)</span><span>)</span><span>)</span></pre></td></tr></table></div>
<p>as well as the number of friends friends have, and the average number of friends </p>
<div><table><tr><td><pre>1
2
</pre></td><td><pre>friends_of_friends <span>=</span> <span>function</span><span>(</span>y<span>)</span> <span>(</span><span>Vectorize</span><span>(</span><span>function</span><span>(</span>x<span>)</span> <span>length</span><span>(</span>friends<span>(</span>x<span>)</span><span>)</span><span>)</span><span>(</span>friends<span>(</span>y<span>)</span><span>)</span><span>)</span>
nb_friends_of_friends <span>=</span> <span>Vectorize</span><span>(</span><span>function</span><span>(</span>x<span>)</span> <span>mean</span><span>(</span>friends_of_friends<span>(</span>x<span>)</span><span>)</span><span>)</span></pre></td></tr></table></div>
<p>We can look at the density of the number of friends, for a random node,</p>
<div><table><tr><td><pre>1
2
3
4
5
6
</pre></td><td><pre>Nb  <span>=</span> nb_friends<span>(</span>nodes<span>)</span>
Nb2 <span>=</span> nb_friends_of_friends<span>(</span>nodes<span>)</span>
<span>hist</span><span>(</span>Nb,breaks<span>=</span><span>0</span><span>:</span><span>40</span>,<span>col</span><span>=</span><span>rgb</span><span>(</span><span>1</span>,<span>0</span>,<span>0</span>,.2<span>)</span>,border<span>=</span><span>&quot;white&quot;</span>,probability <span>=</span> TRUE<span>)</span>
<span>hist</span><span>(</span>Nb2,breaks<span>=</span><span>0</span><span>:</span><span>40</span>,<span>col</span><span>=</span><span>rgb</span><span>(</span><span>0</span>,<span>0</span>,<span>1</span>,.2<span>)</span>,border<span>=</span><span>&quot;white&quot;</span>,probability <span>=</span> TRUE,add<span>=</span>TRUE<span>)</span>
<span>lines</span><span>(</span><span>density</span><span>(</span>Nb<span>)</span>,<span>col</span><span>=</span><span>&quot;red&quot;</span>,lwd<span>=</span><span>2</span><span>)</span>
<span>lines</span><span>(</span><span>density</span><span>(</span>Nb2<span>)</span>,<span>col</span><span>=</span><span>&quot;blue&quot;</span>,lwd<span>=</span><span>2</span><span>)</span></pre></td></tr></table></div>
<p><img alt="" src="https://i0.wp.com/f-origin.hypotheses.org/wp-content/blogs.dir/253/files/2018/06/GoT-paradox.png?w=456&ssl=1" data-recalc-dims="1"><br>
and we can also compute the averages, just to check</p>
<div><table><tr><td><pre>1
2
3
4
</pre></td><td><pre><span>mean</span><span>(</span>Nb<span>)</span>
<span>[</span><span>1</span><span>]</span> <span>6.579439</span>
<span>mean</span><span>(</span>Nb2<span>)</span>
<span>[</span><span>1</span><span>]</span> <span>13.94243</span></pre></td></tr></table></div>
<p>So, indeed, people on average have fewer friends than their friends.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://freakonometrics.hypotheses.org/53310"> R-english – Freakonometrics</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/YPD329jjbik" height="1"></a></div>