<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ben Davies</title>
    <link>https://bldavies.com/</link>
    <description>Recent content on Ben Davies</description>
    <generator>Hugo -- gohugo.io</generator>
    <lastBuildDate>Tue, 16 Sep 2025 00:00:00 +0000</lastBuildDate>
    
      <atom:link href="https://bldavies.com/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>The value of conceptual knowledge</title>
      <link>https://bldavies.com/blog/value-conceptual-knowledge/</link>
      <pubDate>Tue, 16 Sep 2025 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/value-conceptual-knowledge/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://sites.google.com/view/anirudh-sankar&#34;&gt;Anirudh&lt;/a&gt; and I have &lt;a href=&#34;https://arxiv.org/abs/2509.09170&#34;&gt;a new paper&lt;/a&gt;.
It explores the role that conceptual knowledge plays in human learning and decision-making.&lt;/p&gt;
&lt;h2 id=&#34;a-motivating-example&#34;&gt;A motivating example&lt;/h2&gt;
&lt;p&gt;Suppose a farmer wants to learn which fertilizers are most effective.
He views them as &lt;a href=&#34;https://en.wikipedia.org/wiki/Black_box&#34;&gt;black boxes&lt;/a&gt;: he knows &lt;em&gt;that&lt;/em&gt; they help plants grow, but doesn&amp;rsquo;t know &lt;em&gt;why&lt;/em&gt;.
He doesn&amp;rsquo;t know how fertilizers&amp;rsquo; effects relate and can&amp;rsquo;t extrapolate one from another.
So when he tries different fertilizers to learn their effects, he has to try them one at a time.&lt;/p&gt;
&lt;p&gt;Now suppose the farmer knows about nitrogen, a nutrient that helps plants grow.
This tells him how fertilizers&amp;rsquo; effects relate: they share a common &amp;ldquo;nitrogen component.&amp;rdquo;
It allows him to extrapolate one fertilizer&amp;rsquo;s effect from another&amp;rsquo;s.
So when he tries different fertilizers to learn their effects, he can combine them to isolate the nitrogen component.
This is better than trying each fertilizer separately: it allows him to learn their effects from one trial rather than many.&lt;/p&gt;
&lt;p&gt;The farmer&amp;rsquo;s knowledge of nitrogen is conceptual: it&amp;rsquo;s in his mind, rather than his data.
Nonetheless it allows him to collect better data.
&lt;em&gt;How much better&lt;/em&gt;?
That&amp;rsquo;s the question &lt;a href=&#34;https://arxiv.org/abs/2509.09170&#34;&gt;our paper&lt;/a&gt; answers!&lt;/p&gt;
&lt;h2 id=&#34;what-we-do&#34;&gt;What we do&lt;/h2&gt;
&lt;p&gt;We generalize the farming example as follows:
Imagine you want to learn some unknown &amp;ldquo;states&amp;rdquo; (e.g., fertilizer effects).
Conceptual knowledge tells you how the states relate.
It allows you to represent them as combinations of structural &amp;ldquo;features&amp;rdquo; (e.g., nutrient effects).
If you know about these features, then you can collect data on them; if you don&amp;rsquo;t, then you have to collect data on the states instead.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s better to collect data on features because it makes use of states&amp;rsquo; structural relationships.
&lt;em&gt;How much better&lt;/em&gt; is a quantity we define in our paper.
We call it &amp;ldquo;the value of conceptual knowledge.&amp;rdquo;
It equals the welfare gain from knowing how states relate and using that knowledge to collect better data.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://arxiv.org/abs/2509.09170&#34;&gt;Our paper&lt;/a&gt; offers three main insights:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Conceptual knowledge is more valuable when states are more &amp;ldquo;reducible.&amp;quot;&lt;/strong&gt;
If only one feature matters, then collecting data on it helps you learn about many states at once.
But if many features matter, then you can&amp;rsquo;t do much better than learn about each state on its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The value of conceptual knowledge depends on how much data you can collect.&lt;/strong&gt;
If you can&amp;rsquo;t collect much, then it&amp;rsquo;s valuable to know which features matter most.
But if you can collect lots of data, then you don&amp;rsquo;t need to know which features matter because you can &amp;ldquo;let the data speak.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;People with deeper knowledge are better off and need less data.&lt;/strong&gt;
The more you know about which features matter, the more you can learn from a given amount of data, and so the less you need to reach a given welfare goal.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;implications&#34;&gt;Implications&lt;/h2&gt;
&lt;p&gt;Our paper highlights how humans and machines differ.
Humans know how to &amp;ldquo;ask the right questions&amp;rdquo; and can learn a lot from limited data.
In contrast, machines rely on pattern recognition and need lots of data.
So the less data are available, the better it is to have humans collect and interpret them.&lt;/p&gt;
&lt;p&gt;Our paper also speaks to interventions that give people data.
They won&amp;rsquo;t work if people don&amp;rsquo;t have the conceptual tools to interpret data.
So we should give people those tools too.
Anirudh and I did that with farmers in Uganda (see &lt;a href=&#34;https://drive.google.com/file/d/11ZYBbbUYx-K0eJmqU4_jaIJIe7F8DdM0/view&#34;&gt;here&lt;/a&gt;): we gave some both knowledge and data, and others data only.
Farmers with deeper knowledge made more profitable decisions and more accurate predictions.&lt;/p&gt;
&lt;p&gt;Finally, our paper positions knowledge as an economic good.
It is valuable but scarce, just like data.
So we can study the trade-off between knowledge and data using the same tools economists use to study other goods.
Are knowledge and data complements or substitutes?
Are they normal or inferior?
How do their values depend on how states relate?
These are questions &lt;a href=&#34;https://arxiv.org/abs/2509.09170&#34;&gt;our paper&lt;/a&gt; helps answer.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Protein pancakes</title>
      <link>https://bldavies.com/blog/protein-pancakes/</link>
      <pubDate>Wed, 30 Jul 2025 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/protein-pancakes/</guid>
      <description>&lt;p&gt;I make pancakes from scratch most mornings.
Here&amp;rsquo;s my method:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Blend 45 grams of rolled oats.&lt;/li&gt;
&lt;li&gt;Mix the blended oats with
&lt;ul&gt;
&lt;li&gt;a tablespoon of cornstarch,&lt;/li&gt;
&lt;li&gt;half a teaspoon of baking powder,&lt;/li&gt;
&lt;li&gt;40 grams of vanilla protein powder,&lt;/li&gt;
&lt;li&gt;a teaspoon of cinnamon,&lt;/li&gt;
&lt;li&gt;half a teaspoon of nutmeg, and&lt;/li&gt;
&lt;li&gt;a pinch of salt.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;In a separate bowl, combine
&lt;ul&gt;
&lt;li&gt;two whisked eggs,&lt;/li&gt;
&lt;li&gt;120 grams of greek yoghurt,&lt;/li&gt;
&lt;li&gt;a splash of milk,&lt;/li&gt;
&lt;li&gt;a finely diced (almost mashed) banana, and&lt;/li&gt;
&lt;li&gt;half a cup of blueberries.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Combine the wet and dry ingredients.&lt;/li&gt;
&lt;li&gt;Make some coffee while the batter rests for 5&amp;ndash;10 minutes.&lt;/li&gt;
&lt;li&gt;Fry the batter on medium heat, flipping once when bubbles form.&lt;/li&gt;
&lt;li&gt;Serve with yoghurt, strawberries, and a sprinkle of cinnamon.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The finished product looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;example.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I use oats, rather than flour, to make my pancakes slightly healthier and nuttier.
Casein protein powder holds more moisture than whey; I use 20 grams of each.
If I&amp;rsquo;m out of yoghurt, then I use cottage cheese.
It tastes similar but burns easier and leaves more lumps.
Sometimes I replace the banana and blueberries with pumpkin purée.&lt;/p&gt;
&lt;p&gt;Happy stacking!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Economic theory as storytelling</title>
      <link>https://bldavies.com/blog/economic-theory-storytelling/</link>
      <pubDate>Fri, 25 Apr 2025 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/economic-theory-storytelling/</guid>
      <description>&lt;p&gt;Today I&amp;rsquo;ll speak at an event run by the &lt;a href=&#34;https://economics.stanford.edu/undergraduate/stanford-economics-association-sea&#34;&gt;Stanford Economics Association&lt;/a&gt;.
They asked me to talk about (micro)economic theory and doing research on it.
You can read my slides &lt;a href=&#34;slides.pdf&#34;&gt;here&lt;/a&gt; and my notes below.
They draw from my posts on &lt;a href=&#34;https://bldavies.com/blog/what-economic-model&#34;&gt;economic models&lt;/a&gt; and how we &lt;a href=&#34;https://bldavies.com/blog/judging-economic-models&#34;&gt;judge&lt;/a&gt; them.&lt;/p&gt;
&lt;h2 id=&#34;what-do-theorists-do&#34;&gt;What do theorists do?&lt;/h2&gt;
&lt;p&gt;If you read an economic theory paper, you will probably see a lot of math.
Modern theorists are mathematicians.
They write papers full of theorems and proofs.
They use math as a common language for expressing ideas, making precise claims, and explaining their arguments clearly and concisely.&lt;/p&gt;
&lt;p&gt;Economic theorists are also scientists.
They use &lt;a href=&#34;https://bldavies.com/blog/what-economic-model&#34;&gt;models&lt;/a&gt; to run experiments that are too hard or expensive to run in reality.
This helps us design real-world systems, as &lt;a href=&#34;https://doi.org/10.1007/978-3-030-18050-8_72&#34;&gt;Jackson (2019)&lt;/a&gt; argues:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;One would never design a large airliner without carefully modeling its aeronautic properties, and testing it thoroughly via simulations and test flights of prototypes, before loading it with passengers.
Why should designing a market for health insurance be any different?
Models have the virtue of offering us insight in to what should we expect in scenarios that have never been tried before.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But the best theorists are more than mathematicians and scientists.
They&amp;rsquo;re storytellers.
They start their papers by setting the scene: a world in which people make choices.
Next, they introduce characters: who they are, what they want, what they know, and what they can do.
Then the theorist lets their story unfold.
They take us on a journey from premise to conclusion.
Along the way they share details about the characters&amp;rsquo; world.
Good theorists, like good storytellers, know which details matter to the story and which do not.
They share the right details at the right time so that we don&amp;rsquo;t get lost or overwhelmed.
They help us discover the moral of their story: the lessons we should take away; the meaning of all the math.&lt;/p&gt;
&lt;h2 id=&#34;two-seminal-stories&#34;&gt;Two seminal stories&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/The_Market_for_Lemons&#34;&gt;Akerlof (1970)&lt;/a&gt; tells a classic story.
It&amp;rsquo;s set in the market for used cars.
There are two characters: a seller (he) and a buyer (she).
They want to transact at fair prices.
The seller knows more about cars&amp;rsquo; qualities than the buyer.&lt;/p&gt;
&lt;p&gt;Akerlof&amp;rsquo;s story unfolds as follows:
The buyer knows she knows less than the seller.
She expects him to rip her off.
So she rejects all his offers to sell at high prices.
But if he can only sell at low prices, then the seller will only sell low-quality cars.
Thus, in equilibrium, only &amp;ldquo;lemons&amp;rdquo; get sold.
Whereas if the buyer knew cars&amp;rsquo; qualities, then she could buy &amp;ldquo;peaches&amp;rdquo; at a high prices and lemons at low prices.
And that&amp;rsquo;s the moral of Akerlof&amp;rsquo;s story: information asymmetries lead to market failures.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1257/aer.101.6.2590&#34;&gt;Kamenica and Gentzkow (2011)&lt;/a&gt;&amp;mdash;hereafter &amp;ldquo;KG&amp;rdquo;&amp;mdash;tell another story about information.
Theirs plays out in a courtroom.
Again, there are two characters: a prosecutor (he) and a judge (she).
The prosecutor wants the judge to convict a defendant.
The judge wants to convict if and only if the defendant is guilty.
Neither knows if the defendant is guilty.
The prosecutor can share evidence selectively, but the judge knows how evidence is selected.
KG show that although the prosecutor has transparent motives that differ from the judge&amp;rsquo;s, he gets what he wants more often than not.
Indeed, in KG&amp;rsquo;s leading example, the judge convicts 60% of defendants despite knowing 70% are innocent!&lt;/p&gt;
&lt;p&gt;One moral of KG&amp;rsquo;s story is that people can &amp;ldquo;design&amp;rdquo; information to get what they want.
Another is that people gain credibility by committing.
In KG&amp;rsquo;s model, the prosecutor publicly commits to a method for selecting evidence.
This contrasts with &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Cheap_talk&#34;&gt;cheap talk&lt;/a&gt;&amp;rdquo; models that lack such commitment.
In those models, communication breaks down when the sender and receiver have different goals.
This is because the sender has &lt;a href=&#34;https://bldavies.com/blog/persuading-anecdotes/&#34;&gt;persuasion temptations&lt;/a&gt; that make him untrustworthy.
That was the moral of &lt;a href=&#34;https://doi.org/10.2307/1913390&#34;&gt;Crawford and Sobel&amp;rsquo;s (1982)&lt;/a&gt; story.
Kamenica and Gentzkow retell that story, but they start from a different premise and so lead to a different conclusion.&lt;/p&gt;
&lt;h2 id=&#34;what-makes-a-good-story&#34;&gt;What makes a good story?&lt;/h2&gt;
&lt;p&gt;Good theory papers are like good stories.
They describe and explore worlds similar to our own, and give us insights we can apply to our everyday lives.
Akerlof and KG&amp;rsquo;s insight is that information matters.
They share that insight by telling stories that are &lt;strong&gt;relatable&lt;/strong&gt;: we can imagine ourselves in a car yard or courtroom, or in other situations where different people know different things.&lt;/p&gt;
&lt;p&gt;Good theory papers, like good stories, also have an element of &lt;strong&gt;surprise&lt;/strong&gt;.
They tell us something we didn&amp;rsquo;t expect or know before.
Akerlof surprised a top journal&amp;rsquo;s referees: they rejected his story because they couldn&amp;rsquo;t believe it.
Kamenica and Gentzkow surprised me: I didn&amp;rsquo;t think people could be persuaded when knew they were being persuaded.&lt;/p&gt;
&lt;p&gt;Finally, good theory papers are &lt;strong&gt;simple&lt;/strong&gt; yet &lt;strong&gt;general&lt;/strong&gt;.
They are &amp;ldquo;simple&amp;rdquo; in that they contain caricatures of reality, highlighting a few features and ignoring the rest.
They are &amp;ldquo;general&amp;rdquo; in that the highlighted features capture something fundamental and transcendent.
Of course, such features are hard to find.
That&amp;rsquo;s what makes doing theory so challenging.
But it&amp;rsquo;s also what makes doing theory so rewarding.
I love drawing connections between ideas and distilling them to their essence.
If you love that too, then I recommend becoming a theorist!&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://bingliu723.github.io&#34;&gt;Bing Liu&lt;/a&gt; for reading a draft version of this post.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Research incentives and artificial intelligence</title>
      <link>https://bldavies.com/blog/research-incentives-artificial-intelligence/</link>
      <pubDate>Thu, 20 Mar 2025 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/research-incentives-artificial-intelligence/</guid>
      <description>&lt;p&gt;In one of my favorite papers (summarized &lt;a href=&#34;https://bldavies.com/blog/research-incentives-evolution-knowledge/&#34;&gt;here&lt;/a&gt;), &lt;a href=&#34;https://doi.org/10.3982/ECTA22144&#34;&gt;Carnehl and Schneider (2025)&lt;/a&gt; study the choice between two types of research:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;research that &amp;ldquo;deepens&amp;rdquo; our knowledge by filling gaps between answered questions;&lt;/li&gt;
&lt;li&gt;research that &amp;ldquo;expands&amp;rdquo; our knowledge by answering questions beyond the frontier.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&#34;https://www.nber.org/papers/w33566&#34;&gt;Gans (2025)&lt;/a&gt; considers how this choice is impacted by artificial intelligence.
He argues that AI helps researchers fill gaps:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;AI tools &amp;hellip; excel at interpolation, precisely answering queries located within a defined operational range around known data points.
&amp;hellip;
[Their] primary strength [is the] efficient recombination of existing information, rather than extending the domain of knowledge itself.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;How might we &lt;a href=&#34;https://bldavies.com/blog/what-economic-model/&#34;&gt;model&lt;/a&gt; the impact of AI on researchers&amp;rsquo; choices?
One approach is to assume AI lowers the cost of research that deepens.
This has two effects:
a &lt;a href=&#34;https://en.wikipedia.org/wiki/Substitution_effect&#34;&gt;substitution effect&lt;/a&gt; that leads to more research that deepens, and
an &lt;a href=&#34;https://en.wikipedia.org/wiki/Consumer_choice#Income_effect&#34;&gt;income effect&lt;/a&gt; that leads to more research overall.
The net impact on researchers&amp;rsquo; choices&amp;mdash;i.e., how much they try to fill gaps vis-à-vis push boundaries&amp;mdash;depends on the two effects&amp;rsquo; relative sizes.&lt;/p&gt;
&lt;p&gt;Gans takes a different modeling approach.
He assumes that when researchers answer a question, AI answers similar questions for free.
What counts as &amp;ldquo;similar&amp;rdquo; depends on AI&amp;rsquo;s operational range.
Gans treats this range as an exogenous parameter.
He offers an example from biology:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;With AI tools like &lt;a href=&#34;https://en.wikipedia.org/wiki/AlphaFold&#34;&gt;AlphaFold&lt;/a&gt;, if we know the structures of two somewhat related proteins (separated by a [sufficiently small distance] in the space of amino acid sequences), the AI can accurately predict the structure of any protein between them without requiring additional experimental data. However, for proteins that are too distant from known structures (beyond the frontier), the AI’s predictions become unreliable, and new experiments are needed.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Carnehl and Schneider&amp;rsquo;s model is the special case of Gans&amp;rsquo; in which AI has an operational range of zero.
Extending this range changes researchers&amp;rsquo; incentives and leads to different choices.&lt;/p&gt;
&lt;p&gt;For example, in Carnehl and Schneider&amp;rsquo;s model, researchers tend to do incremental work that pushes the frontier in small steps.
This is because small steps are less risky than large steps.
The step size depends on researchers&amp;rsquo; private incentives, which change over time as the set of answered questions changes.&lt;/p&gt;
&lt;p&gt;In contrast, in Gans&amp;rsquo; model, researchers always take steps equal to AI&amp;rsquo;s operational range.
This makes the most of AI&amp;rsquo;s ability to fill gaps.
It means they push the frontier at a steady pace, which gets faster as AI improves.&lt;/p&gt;
&lt;p&gt;This difference in dynamics leads to different policy recommendations.
Carnehl and Schneider recommend subsidies for &amp;ldquo;moonshots:&amp;rdquo; research on questions more novel than is privately optimal.
These subsidies correct the market failure that arises from researchers not internalizing the positive externalities their work has on future researchers.&lt;/p&gt;
&lt;p&gt;Gans shows that AI makes moonshots more valuable.
He also recommends another policy: make AI better by raising its operational range.
This allows researchers to create knowledge at a faster pace.
It empowers them to pursue their comparative advantage&amp;mdash;to ask novel questions&amp;mdash;rather than do the incremental work at which AI excels.&lt;/p&gt;
&lt;p&gt;One thing missing from Carnehl, Schneider, and Gans&amp;rsquo; models is competition among researchers.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
The authors assume researchers work one-at-a-time.
In reality, researchers work many-at-a-time.
They fight for &lt;a href=&#34;https://en.wikipedia.org/wiki/Scientific_priority&#34;&gt;priority&lt;/a&gt; by answering questions no-one else can.
This discourages them from filling obvious gaps.
AI discourages them even more: if anyone can use it to fill gaps for free, then researchers can&amp;rsquo;t bank on being the first ones to do so.
They have to keep pushing the frontier.
So AI could boost the pace of innovation more than Gans suggests!&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Thanks to &lt;a href=&#34;https://bingliu723.github.io&#34;&gt;Bing Liu&lt;/a&gt; for pointing this out. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>A model of self-sabotage</title>
      <link>https://bldavies.com/blog/model-self-sabotage/</link>
      <pubDate>Thu, 14 Nov 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/model-self-sabotage/</guid>
      <description>&lt;p&gt;On &lt;a href=&#34;https://www.ted.com/podcasts/malcolm-gladwell-on-the-importance-of-self-correction-transcript&#34;&gt;this week&amp;rsquo;s episode&lt;/a&gt; of the &lt;em&gt;ReThinking&lt;/em&gt; podcast, &lt;a href=&#34;https://adamgrant.net&#34;&gt;Adam Grant&lt;/a&gt; describes how people sabotage themselves:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Let&amp;rsquo;s say you&amp;rsquo;re going into a difficult math test and you&amp;rsquo;re afraid of finding out that you&amp;rsquo;re not smart enough to do it.
What do you do?
You don&amp;rsquo;t start studying until the night before, or you don&amp;rsquo;t study at all.
And then, when you fail, you can say, &amp;ldquo;well, I didn&amp;rsquo;t try.&amp;rdquo;
And you don&amp;rsquo;t have to face the threat to your fundamental aptitude.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This argument reminds me of the literature on &amp;ldquo;career concerns.&amp;rdquo;
That literature explores the incentive problems that arise when employees care about their reputations.
One problem is that they avoid taking profitable but risky actions (see, e.g., &lt;a href=&#34;https://doi.org/10.1257/mic.20150083&#34;&gt;Aghion and Jackson (2016)&lt;/a&gt;).
This happens when the actions&amp;rsquo; outcomes provide information about the employee&amp;rsquo;s ability.&lt;/p&gt;
&lt;p&gt;For example, consider fund managers.
Good managers can identify good investments; bad managers cannot.
But some good investments go bad by chance, making good managers look bad and getting them fired.
This discourages managers from making risky investments (see, e.g., &lt;a href=&#34;https://doi.org/10.1162/003355399556034&#34;&gt;Chevalier and Ellison (1999)&lt;/a&gt;).
Instead they make safe bets, hiding their ability but hurting the fund&amp;rsquo;s performance.&lt;/p&gt;
&lt;p&gt;Adam&amp;rsquo;s test-taker has similar incentives.
They don&amp;rsquo;t want to find out their &amp;ldquo;fundamental aptitude&amp;rdquo; is low.
If they don&amp;rsquo;t prepare for the test and fail it, then they can blame their lack of preparation rather than their lack of talent.
But they might pass the test if they prepare for it!
So when deciding how hard to study, the test-taker needs to consider two forces: studying harder&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;makes them more likely to pass but also&lt;/li&gt;
&lt;li&gt;makes their (in)ability harder to ignore if they fail.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These forces can complement or compete with each other, depending on their magnitudes and directions.
I illustrate this dependence in the &lt;a href=&#34;https://bldavies.com/blog/what-economic-model/&#34;&gt;model&lt;/a&gt; below.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h2 id=&#34;model&#34;&gt;Model&lt;/h2&gt;
&lt;p&gt;Suppose I can either succeed &lt;code&gt;\((s=1)\)&lt;/code&gt; or fail &lt;code&gt;\((s=0)\)&lt;/code&gt; at achieving a goal.
The probability with which I succeed depends on my effort &lt;code&gt;\(e\)&lt;/code&gt;, which I can choose to be low &lt;code&gt;\((e=L)\)&lt;/code&gt; or high &lt;code&gt;\((e=H)\)&lt;/code&gt;.
It also depends on my ability &lt;code&gt;\(a\)&lt;/code&gt;, which is also low &lt;code&gt;\((a=L)\)&lt;/code&gt; or high &lt;code&gt;\((a=H)\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If I choose low effort, then I&amp;rsquo;m equally likely to succeed regardless of my ability:
&lt;code&gt;$$\Pr(s=1\mid e=L,a)=0.5$$&lt;/code&gt;
for each &lt;code&gt;\(a\in\{L,H\}\)&lt;/code&gt;.
But if I choose high effort, then my success probability improves if and only if I have high ability:
&lt;code&gt;$$\Pr(s=1\mid e=H,a)=\begin{cases} 0.5 &amp;amp; \text{if}\ a=L \\ 0.5+p &amp;amp; \text{if}\ a=H \end{cases}$$&lt;/code&gt;
with &lt;code&gt;\(0&amp;lt;p\le 0.5\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t know my ability and don&amp;rsquo;t get to choose it.
My prior belief is that I&amp;rsquo;m equally likely to have high or low ability: &lt;code&gt;\(\Pr(a=H)=0.5\)&lt;/code&gt;.
I use &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayes&amp;rsquo; rule&lt;/a&gt; to update this belief based on my effort &lt;code&gt;\(e\)&lt;/code&gt; and outcome &lt;code&gt;\(s\)&lt;/code&gt;.
My posterior belief is
&lt;code&gt;$$\begin{align} q(e,s) &amp;amp;\equiv \Pr(a=H\mid e,s) \\ &amp;amp;= \frac{\Pr(s\mid e,a=H)\Pr(a=H)}{\Pr(s\mid e)} \\ &amp;amp;= \begin{cases} 0.5 &amp;amp; \text{if}\ e=L \\ \frac{0.5-p}{1-p} &amp;amp; \text{if}\ e=H\ \text{and}\ s=0 \\ \frac{0.5+p}{1+p} &amp;amp; \text{if}\ e=H\ \text{and}\ s=1. \end{cases} \end{align}$$&lt;/code&gt;
My beliefs never change if I choose low effort.
This choice makes &lt;code&gt;\(s\)&lt;/code&gt; an uninformative &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;signal&lt;/a&gt; because I&amp;rsquo;m equally likely to succeed regardless of my ability.
In contrast, my beliefs always change if I choose high effort.
This choice makes &lt;code&gt;\(s\)&lt;/code&gt; an informative signal because I&amp;rsquo;m more likely to succeed if my ability is high than if it is low.
Increasing &lt;code&gt;\(p\)&lt;/code&gt; &lt;a href=&#34;https://en.wikipedia.org/wiki/Deconvolution&#34;&gt;deconvolutes&lt;/a&gt; the signal and makes it more informative, leading to more extreme posterior beliefs.&lt;/p&gt;
&lt;p&gt;My payoff has two components.
The first depends on my outcome: I receive &lt;code&gt;\(b&amp;gt;0\)&lt;/code&gt; if &lt;code&gt;\(s=1\)&lt;/code&gt; and zero otherwise.
The second component depends on my beliefs: I receive &amp;ldquo;ego utility&amp;rdquo;
&lt;code&gt;$$u(q)=\left(\frac{q}{0.5}\right)^\alpha-1$$&lt;/code&gt;
from having posterior belief &lt;code&gt;\(q\)&lt;/code&gt; about my ability.
The function &lt;code&gt;\(u\)&lt;/code&gt; is increasing in &lt;code&gt;\(q\)&lt;/code&gt; and has value &lt;code&gt;\(u(0.5)=0\)&lt;/code&gt; if my beliefs don&amp;rsquo;t change.
The parameter &lt;code&gt;\(\alpha&amp;gt;0\)&lt;/code&gt; determines the function&amp;rsquo;s curvature: it is concave if &lt;code&gt;\(\alpha&amp;lt;1\)&lt;/code&gt;, linear if &lt;code&gt;\(\alpha=1\)&lt;/code&gt;, and convex if &lt;code&gt;\(a&amp;gt;1\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I choose the effort &lt;code&gt;\(e^*\in\{L,H\}\)&lt;/code&gt; that maximizes my &lt;em&gt;ex ante&lt;/em&gt; expected payoff
&lt;code&gt;$$\begin{align*} U(e) &amp;amp;\equiv \Pr(s=1\mid e)\ b \\ &amp;amp;\quad +\Pr(s=1\mid e)\ u(q(e,1))+\Pr(s=0\mid e)\ u(q(e,0)), \end{align*}$$&lt;/code&gt;
which has values
&lt;code&gt;$$U(L)=0.5b$$&lt;/code&gt;
and
&lt;code&gt;$$\begin{align*} U(H) &amp;amp;= 0.5(1+p)b \\ &amp;amp;\quad +0.5(1+p)\left(\frac{1+2p}{1+p}\right)^\alpha+0.5(1-p)\left(\frac{1-2p}{1-p}\right)^\alpha-1. \end{align*}$$&lt;/code&gt;
I choose high effort if and only if the difference
&lt;code&gt;$$D\equiv U(H)-U(L)$$&lt;/code&gt;
is positive.
This difference depends on the parameters &lt;code&gt;\(p\)&lt;/code&gt;, &lt;code&gt;\(b\)&lt;/code&gt;, and &lt;code&gt;\(\alpha\)&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;If I choose high effort, then increasing &lt;code&gt;\(p\)&lt;/code&gt; has two effects:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it makes me more likely to succeed;&lt;/li&gt;
&lt;li&gt;it makes the random outcome &lt;code&gt;\(s\)&lt;/code&gt; more informative about my ability.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first effect always makes me better off.
The second effect makes me better off when &lt;code&gt;\(\alpha&amp;gt;1\)&lt;/code&gt; but worse off when &lt;code&gt;\(\alpha&amp;lt;1\)&lt;/code&gt;.
This is because &lt;code&gt;\(\alpha\)&lt;/code&gt; controls whether I like &lt;code&gt;\((\alpha&amp;gt;1)\)&lt;/code&gt; or dislike &lt;code&gt;\((\alpha&amp;lt;1)\)&lt;/code&gt; variation in my posterior beliefs.
If &lt;code&gt;\(\alpha&amp;lt;1\)&lt;/code&gt;, then I have diminishing returns to ego boosts: I lose more from learning I have low ability than I gain from learning I have high ability.
This makes me want a narrower distribution of posterior beliefs.
So I&amp;rsquo;m tempted to sabotage myself, choosing low effort to protect my ego.
This temptation is strongest when the benefit &lt;code&gt;\(b\)&lt;/code&gt; of achieving my goal is small and when the signal &lt;code&gt;\(s\)&lt;/code&gt; is very informative (i.e., when &lt;code&gt;\(p\)&lt;/code&gt; is large).&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I present a similar model in &lt;a href=&#34;https://bldavies.com/blog/why-experts-give-simple-advice&#34;&gt;my paper on simple advice&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Principal repayments</title>
      <link>https://bldavies.com/blog/principal-repayments/</link>
      <pubDate>Tue, 22 Oct 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/principal-repayments/</guid>
      <description>&lt;p&gt;Suppose I borrow &lt;code&gt;\(B_0\)&lt;/code&gt; at an annual interest rate of &lt;code&gt;\(r\)&lt;/code&gt;.
I repay the loan by making constant payments of &lt;code&gt;\(P\)&lt;/code&gt; at the end of each year for &lt;code&gt;\(N\)&lt;/code&gt; years.
So, after &lt;code&gt;\(n\in\{0,1,\ldots,N\}\)&lt;/code&gt; years, the remaining balance on my loan equals
&lt;code&gt;$$B_n\equiv\frac{P}{r}\left(1-\frac{1}{(1+r)^{N-n}}\right).$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Although I make the same payment &lt;code&gt;\(P\)&lt;/code&gt; each year, the share
&lt;code&gt;$$\begin{align*} S_n &amp;amp;\equiv \frac{B_{n-1}-B_n}{P} \\ &amp;amp;= \frac{1}{r}\left[\left(1-\frac{1}{(1+r)^{N-(n-1)}}\right)-\left(1-\frac{1}{(1+r)^{N-n}}\right)\right] \\ &amp;amp;= \frac{1}{(1+r)^{N-n+1}} \end{align*}$$&lt;/code&gt;
of my payment that goes toward the principal rises each year.
Indeed it rises at rate
&lt;code&gt;$$\begin{align*} \frac{S_{n+1}-S_n}{S_n} &amp;amp;= \frac{(1+r)^{-(N-(n+1)+1)}-(1+r)^{-(N-n+1)}}{(1+r)^{-(N-n+1)}} \\ &amp;amp;= r. \end{align*}$$&lt;/code&gt;
Intuitively, each payment lowers the remaining balance on which interest accrues.
So the interest added to my loan falls each year, raising the share of my constant payments that go toward the principal.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://people.stanford.edu/jbulow/&#34;&gt;Jeremy Bulow&lt;/a&gt; for inspiring this post.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Reflections on grad school: Years 3 and 4</title>
      <link>https://bldavies.com/blog/reflections-grad-school-years-3-4/</link>
      <pubDate>Sat, 21 Sep 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/reflections-grad-school-years-3-4/</guid>
      <description>&lt;p&gt;This post summarizes the past two years of &lt;a href=&#34;https://bldavies.com/blog/stanford&#34;&gt;my PhD program&lt;/a&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
I describe my &lt;a href=&#34;#research&#34;&gt;research&lt;/a&gt; and &lt;a href=&#34;#teaching&#34;&gt;teaching&lt;/a&gt; experience, and offer some &lt;a href=&#34;#advice&#34;&gt;advice&lt;/a&gt; to other students.&lt;/p&gt;
&lt;h2 id=&#34;research&#34;&gt;Research&lt;/h2&gt;
&lt;p&gt;I worked at &lt;a href=&#34;https://www.motu.nz&#34;&gt;Motu&lt;/a&gt; before starting my PhD.
My job was to write research papers.
I had two supervisors&amp;mdash;&lt;a href=&#34;https://bldavies.com/blog/lessons-dave-mare/&#34;&gt;Dave Maré&lt;/a&gt; and &lt;a href=&#34;https://www.motu.nz/about-us/people/adam-jaffe/&#34;&gt;Adam Jaffe&lt;/a&gt;&amp;mdash;who guided me through the research process.
I left Motu thinking research was easy and that I knew how to do it.&lt;/p&gt;
&lt;p&gt;I thought wrong.&lt;/p&gt;
&lt;p&gt;Dave and Adam made research easy by telling me what to work on.
I didn&amp;rsquo;t have to come up with research questions.
Instead, I answered theirs.
I learned a lot along the way&amp;mdash;especially about &lt;a href=&#34;https://bldavies.com/topics/networks/&#34;&gt;networks&lt;/a&gt; and writing &lt;a href=&#34;https://bldavies.com/blog/relatedness-complexity-local-growth-redux/&#34;&gt;publishable&lt;/a&gt; &lt;a href=&#34;https://bldavies.com/blog/research-funding-collaboration/&#34;&gt;papers&lt;/a&gt;.
But I didn&amp;rsquo;t learn how to ask my own questions.
That&amp;rsquo;s where I (and many other PhD students) struggle.
It&amp;rsquo;s hard to find questions that are interesting and important, and can only be answered by me.&lt;/p&gt;
&lt;p&gt;I had some help from my classmate, &lt;a href=&#34;https://sites.google.com/view/anirudh-sankar&#34;&gt;Anirudh&lt;/a&gt;.
We wrote our second-year papers on similar topics.
Mine asked &lt;a href=&#34;https://bldavies.com/blog/why-experts-give-simple-advice/&#34;&gt;why experts give simple advice&lt;/a&gt;.
Ani&amp;rsquo;s asked how people learn from coarse information.
He had an empirical setting in mind: farmers learn from others&amp;rsquo; outcomes (e.g., crop yields), which depend on conditions (e.g., fertilizers and soils used) that are not always observed.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
It sounded interesting and important.
It also sounded like a question I could help answer theoretically.
So we combined our ideas and started working together.&lt;/p&gt;
&lt;p&gt;Ani and I have refined our ideas since.
We&amp;rsquo;ve settled on a question that excites us: how do people use conceptual knowledge to learn and make decisions?
We&amp;rsquo;re answering that question in two papers, &lt;a href=&#34;https://bldavies.com/blog/value-conceptual-knowledge/&#34;&gt;one theoretical&lt;/a&gt; and &lt;a href=&#34;https://drive.google.com/file/d/11ZYBbbUYx-K0eJmqU4_jaIJIe7F8DdM0/view&#34;&gt;the other empirical&lt;/a&gt;.
The theory and empirics support and motivate each other.
Likewise Ani and I support and motivate each other.
Working with him has been the highlight of my PhD.&lt;/p&gt;
&lt;p&gt;One way Ani and I refined our ideas was by presenting them at seminars.
We learned a lot from our audiences.
They told us what they found interesting, what was novel, and what we needed to explain better.
They prompted us to figure out some technical details and to clarify our key insights.&lt;/p&gt;
&lt;p&gt;Most of our audiences&amp;rsquo; comments were encouraging and useful.
But some were discouraging and useless.
During one of my presentations, a professor said they liked our question but not our &lt;a href=&#34;https://bldavies.com/blog/what-economic-model/&#34;&gt;model&lt;/a&gt;.
(Another said they liked our model but not our question!)
I asked how we could make our model better.
They responded with &amp;ldquo;I don&amp;rsquo;t know&amp;rdquo; and yet &amp;ldquo;I&amp;rsquo;ve already published this in the &lt;em&gt;QJE&lt;/em&gt;.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The same professor told me to be less ambitious: to make technical contributions to well-known problems, rather than conceptual contributions to novel problems.
They said I have &amp;ldquo;the rest of my career to work on big ideas.&amp;rdquo;
Many PhD students follow that advice&amp;mdash;especially students of economic theory.
They feel pressured to show off their technical skills, using complicated math to explain shallow ideas.
I would rather use simple math to explain deep ideas.&lt;/p&gt;
&lt;h2 id=&#34;teaching&#34;&gt;Teaching&lt;/h2&gt;
&lt;p&gt;Stanford pays PhD students to work as teaching assistants.
I TA&amp;rsquo;d two finance courses: &lt;a href=&#34;https://explorecourses.stanford.edu/search?q=ECON43&#34;&gt;one&lt;/a&gt; aimed at freshman and &lt;a href=&#34;https://explorecourses.stanford.edu/search?q=ECON135&#34;&gt;another&lt;/a&gt; aimed at seniors.
I don&amp;rsquo;t research finance but enjoy teaching it.
I can share examples from my own life (e.g., as an investor and credit cardholder) to make the lecture material more concrete.&lt;/p&gt;
&lt;p&gt;The best part of TAing was meeting my students.
Few came to my sections or office hours, but the ones who did were curious and thoughtful.
They asked interesting questions and engaged with my answers.
Some questions were practical (e.g., &amp;ldquo;how do I build a credit score?&amp;quot;), some were topical (e.g., &amp;ldquo;why did Silicon Valley Bank collapse?&amp;quot;), some were about me (e.g., &amp;ldquo;what&amp;rsquo;s it like doing a PhD?&amp;quot;), and some were about them (e.g., &amp;ldquo;how do I make friends?&amp;quot;).
I loved hearing my students&amp;rsquo; stories, sharing my own, and becoming their mentor.&lt;/p&gt;
&lt;p&gt;Most of my students were anxious about their grades.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
That surprised me.
Stanford students have already proven themselves by becoming Stanford students.
They&amp;rsquo;ll get great jobs at great companies who trust the university&amp;rsquo;s brand.
Society already believes in them.
Their lives will be fine regardless of their grades.&lt;/p&gt;
&lt;p&gt;Besides, most of my students had better things to do than study.
Some interned at banks or hedge funds; others worked for research labs or start-ups.
All were ambitious and awesome.
But their peers were ambitious and awesome too.
So my students didn&amp;rsquo;t notice how impressive they were.
I reminded them often.
They would have been stars at &lt;a href=&#34;https://www.canterbury.ac.nz&#34;&gt;my alma mater&lt;/a&gt;, where few had big dreams and fewer pursued them.&lt;/p&gt;
&lt;h2 id=&#34;advice&#34;&gt;Advice&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Find collaborators who &amp;ldquo;speak your language.&amp;quot;&lt;/strong&gt;
Anirudh and I are math geeks with sociological bents.
We understand how each other thinks and get excited by similar ideas.
That makes our meetings more fruitful and fun.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make time to reflect.&lt;/strong&gt;
I have a list of questions I ask myself every Sunday:
What did I achieve this week?
What did I struggle with?
What made me proud?
These and other questions prompt me to pay attention.
As does sending newsletters to family and friends back home.
I want them to know what I&amp;rsquo;m doing and where I&amp;rsquo;m going, which means I have to know too.
So I take stock regularly.
It punctuates my PhD and makes it seem like less of a grind.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If you&amp;rsquo;re studying abroad, try to live near an international airport.&lt;/strong&gt;
It&amp;rsquo;s much easier and cheaper to fly home if you can fly directly.
It&amp;rsquo;s also easier for family and friends to visit.
Mine flew via SFO on their way to other countries.
Rather than hang out at LAX for a few hours, they could hang out with me for a few days.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Try to stay healthy, but don&amp;rsquo;t over-do it.&lt;/strong&gt;
I exercised too much, ate too little, and gave myself &lt;a href=&#34;https://en.wikipedia.org/wiki/Iron-deficiency_anemia&#34;&gt;anemia&lt;/a&gt;.
It made me anxious and apathetic.
I had no energy to be social or do research.
In short: life sucked.
0/10, would not recommend.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Remember that research is hard.&lt;/strong&gt;
You&amp;rsquo;re allowed to be bad it at.
If you already knew how to do it well, then you wouldn&amp;rsquo;t need to do a PhD!&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://bldavies.com/blog/reflections-grad-school-years-1-2&#34;&gt;here&lt;/a&gt; for reflections on my first two years. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Hence &lt;a href=&#34;https://bldavies.com/blog/estimating-treatment-effects-ols/&#34;&gt;this blog post&lt;/a&gt;. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Adam Mastroianni has &lt;a href=&#34;https://www.experimental-history.com/p/i-wanted-to-be-a-teacher-but-they&#34;&gt;a great Substack post&lt;/a&gt; on grade anxiety. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>What is an &#34;economic model?&#34;</title>
      <link>https://bldavies.com/blog/what-economic-model/</link>
      <pubDate>Tue, 13 Aug 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/what-economic-model/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Statistical_model&#34;&gt;Statistical models&lt;/a&gt; have a formal definition: they comprise
(i) a sample space and
(ii) a probability distribution (or set of distributions) over that space.&lt;/p&gt;
&lt;p&gt;Economic models, in contrast, do not have a formal definition.
The closest I&amp;rsquo;ve found is by &lt;a href=&#34;https://doi.org/10.7551/mitpress/14884.001.0001&#34;&gt;Spiegler (2024, page 152)&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Most economic models have two built-in parts: a description of the model&amp;rsquo;s &lt;em&gt;primitives&lt;/em&gt; and the &lt;em&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Solution_concept&#34;&gt;solution concept&lt;/a&gt;&lt;/em&gt; that one applies to these primitives.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Spiegler focuses on game theoretic models.
Primitives define the strategic environment: who are the players, what do they know, what can they do?
Solution concepts tell us what players actually will do (e.g., whether &lt;a href=&#34;https://en.wikipedia.org/wiki/Prisoner%27s_dilemma&#34;&gt;prisoners&lt;/a&gt; will cooperate or defect).&lt;/p&gt;
&lt;p&gt;Spielger&amp;rsquo;s definition also works for non-game theoretic models.
Consider the textbook model of supply and demand.
Its primitives are the supply and demand schedules.
The solution concept is the type of market equilibrium: competitive, monopolistic, or something in-between.&lt;/p&gt;
&lt;p&gt;Other authors define economic models informally.
&lt;a href=&#34;https://doi.org/10.11647/obp.0020&#34;&gt;Rubinstein (2012, page 16)&lt;/a&gt; likens them to &amp;ldquo;tales:&amp;rdquo;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;The author of a tale seeks to impart a lesson about life to his readers.
He does this by creating a story that hovers between fantasy and reality.
&amp;hellip;
We will take the tale’s message with us when we return from the world of fantasy to the real world, and apply it judiciously when we encounter situations similar to those portrayed in the tale.&lt;/p&gt;
&lt;p&gt;&amp;hellip; An economic model is also somewhere between fantasy and reality.
Models can be denounced for being simplistic and unrealistic, but modeling is essential because it is the only method we have of clarifying concepts, evaluating assumptions, verifying conclusions and acquiring insights that will serve us when we return from the model to real life.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Rubinstein defines models by analogy.
&lt;a href=&#34;https://www.amazon.com/Models-Behaving-Badly-Confusing-Illusion-Reality-Disaster/dp/1439164983&#34;&gt;Derman (2011, page 6)&lt;/a&gt; says models &lt;em&gt;are&lt;/em&gt; analogies; they are &amp;ldquo;metaphors that compare the object of their attention to something else that it resembles.&amp;rdquo;
He describes an example on &lt;a href=&#34;https://www.econtalk.org/derman-on-theories-models-and-science/&#34;&gt;&lt;em&gt;EconTalk&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;[S]tock prices or the returns on stock prices behave like smoke diffusing.
And there&amp;rsquo;s something similar about them, but it&amp;rsquo;s not an accurate description in the way that, say, Newton&amp;rsquo;s Laws attempt to be an accurate description.
It&amp;rsquo;s really based on an analogy to something you do understand, which is smoke diffusing, and saying maybe stock prices behave a lot like that.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Statistical models are analogies too.
Most real-world data are not normally distributed.
We assume they are so that we can describe them in a commonly understood language: we can say things like &amp;ldquo;Alice&amp;rsquo;s height is two standard deviations above the mean for her age.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Statistical models give us parameters to estimate.
We can use these estimates to make predictions.
Economic models are similar.
We build them to describe things we&amp;rsquo;ve seen before, and can use them to predict things we haven&amp;rsquo;t seen before.
&lt;a href=&#34;https://bldavies.com/blog/judging-economic-models/&#34;&gt;Good models&lt;/a&gt; make good predictions.&lt;/p&gt;
&lt;p&gt;Good models also give us insights.
They focus our attention on some details and abstract away from others.
This helps us gain insights without getting confused.
As Rubinstein and Derman point out, models may be unrealistic or inaccurate.
But the good ones are insightful nonetheless.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>*Armchair Expert* episodes</title>
      <link>https://bldavies.com/blog/armchair-expert-episodes/</link>
      <pubDate>Fri, 26 Jul 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/armchair-expert-episodes/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://armchairexpertpod.com&#34;&gt;&lt;em&gt;Armchair Expert&lt;/em&gt;&lt;/a&gt; is a podcast hosted by &lt;a href=&#34;https://en.wikipedia.org/wiki/Dax_Shepard&#34;&gt;Dax Shepard&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Monica_Padman&#34;&gt;Monica Padman&lt;/a&gt;.
They interview celebrities, scientists, and other public figures.
They also publish some subsidiary &amp;ldquo;shows&amp;rdquo; via the podcast&amp;rsquo;s main feed.
The table below counts episodes by show:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Show&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Episodes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Interviews&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;655&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Armchair Anonymous&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;98&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Flightless Bird&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;94&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Synced&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;52&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Armchaired &amp;amp; Dangerous&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Race to 35&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;We Are Supported By&amp;hellip;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Monica &amp;amp; Jess Love Boys&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Race to 270&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Yearbook&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Total&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;974&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I store episodes&amp;rsquo; metadata in the R package &lt;a href=&#34;https://github.com/bldavies/ArmchairExpert&#34;&gt;ArmchairExpert&lt;/a&gt;.
It contains a single table, &lt;code&gt;episodes&lt;/code&gt;, with a row for each episode and seven columns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;id&lt;/code&gt;: Episode ID on Spotify&lt;/li&gt;
&lt;li&gt;&lt;code&gt;date&lt;/code&gt;: Episode release date&lt;/li&gt;
&lt;li&gt;&lt;code&gt;title&lt;/code&gt;: Episode title&lt;/li&gt;
&lt;li&gt;&lt;code&gt;show&lt;/code&gt;: Show to which episode belongs&lt;/li&gt;
&lt;li&gt;&lt;code&gt;number&lt;/code&gt;: Within-show episode number&lt;/li&gt;
&lt;li&gt;&lt;code&gt;duration&lt;/code&gt;: Episode length (in seconds)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;description&lt;/code&gt;: Episode description&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- I list episodes&#39; Spotify IDs because I collect their metadata via the [Spotify API](https://developer.spotify.com/documentation/web-api). --&gt;
&lt;p&gt;The first &lt;em&gt;Armchair Expert&lt;/em&gt; episode&amp;mdash;an interview with Dax&amp;rsquo;s wife, &lt;a href=&#34;https://en.wikipedia.org/wiki/Kristen_Bell&#34;&gt;Kristen Bell&lt;/a&gt;&amp;mdash;was released in February 2018.
The earliest show (&lt;a href=&#34;https://armchairexpertpod.com/monica-jess-love-boys&#34;&gt;Monica &amp;amp; Jess Love Boys&lt;/a&gt;) started in February 2020 and ended two months later.
Other shows have been and gone, and three are ongoing:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/show-timelines-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;My favorite show is &lt;a href=&#34;https://armchairexpertpod.com/flightless-bird&#34;&gt;Flightless Bird&lt;/a&gt;.
It&amp;rsquo;s hosted by &lt;a href=&#34;https://en.wikipedia.org/wiki/David_Farrier&#34;&gt;David Farrier&lt;/a&gt;, a fellow Kiwi who reflects on &lt;a href=&#34;https://bldavies.com/blog/living-america/&#34;&gt;living in the USA&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The median episode is about 93 minutes long.
But most interviews are longer and most shows are shorter:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/lengths-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Most interviews end with a &amp;ldquo;fact check,&amp;rdquo; during which Dax and Monica discuss the interview and their lives.
Fact checks can be as long as the interviews themselves.&lt;/p&gt;
&lt;p&gt;Dax and Monica have interviewed some people many times.
They&amp;rsquo;ve interviewed Kristen Bell five times, and &lt;a href=&#34;https://en.wikipedia.org/wiki/David_Sedaris&#34;&gt;David Sedaris&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Sanjay_Gupta&#34;&gt;Sanjay Gupta&lt;/a&gt; four times each.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
My favorite interviews are with &lt;a href=&#34;https://en.wikipedia.org/wiki/Esther_Perel&#34;&gt;Esther Perel&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Wendy_Mogel&#34;&gt;Wendy Mogel&lt;/a&gt;, and &lt;a href=&#34;https://en.wikipedia.org/wiki/Terry_Crews&#34;&gt;Terry Crews&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Adam Grant, Ashton Kutcher, Jason Bateman, Vincent D&amp;rsquo;Onofrio, and Yuval Noah Harari have been interviewed three times each. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Decomposing matrices of pairwise minima</title>
      <link>https://bldavies.com/blog/decomposing-matrices-pairwise-minima/</link>
      <pubDate>Sun, 05 May 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/decomposing-matrices-pairwise-minima/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(A\)&lt;/code&gt; be the &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix with &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(A_{ij}=\min\{i,j\}\)&lt;/code&gt;.
From &lt;a href=&#34;https://bldavies.com/blog/inverting-matrices-pairwise-minima/&#34;&gt;a previous post&lt;/a&gt;, we know &lt;code&gt;\(A\)&lt;/code&gt; has a tridiagonal inverse &lt;code&gt;\(A^{-1}\)&lt;/code&gt; with &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$\left[A^{-1}\right]_{ij}=\begin{cases} 2 &amp;amp; \text{if}\ i=j&amp;lt;n \\ 1 &amp;amp; \text{if}\ i=j=n \\ -1 &amp;amp; \text{if}\ \lvert i-j\rvert=1 \\ 0 &amp;amp; \text{otherwise}. \end{cases}$$&lt;/code&gt;
For example, if &lt;code&gt;\(n=4\)&lt;/code&gt; then
&lt;code&gt;$$A=\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 3 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 4 \end{bmatrix}$$&lt;/code&gt;
has inverse
&lt;code&gt;$$A^{-1}=\begin{bmatrix} 2 &amp;amp; -1 &amp;amp; 0 &amp;amp; 0 \\ -1 &amp;amp; 2 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; -1 &amp;amp; 2 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 1 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We can use our knowledge of &lt;code&gt;\(A^{-1}\)&lt;/code&gt; to &lt;a href=&#34;https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix&#34;&gt;eigendecompose&lt;/a&gt; &lt;code&gt;\(A\)&lt;/code&gt;.
To see how, let &lt;code&gt;\(\{(\lambda_j,v_j)\}_{j=1}^n\)&lt;/code&gt; be the eigenpairs of &lt;code&gt;\(A^{-1}\)&lt;/code&gt;.
&lt;a href=&#34;https://scholar.google.com/scholar?cluster=3799141027630354794&#34;&gt;Yueh (2005, Theorem 1)&lt;/a&gt; shows that the eigenvector &lt;code&gt;\(v_j\in\mathbb{R}^n\)&lt;/code&gt; corresponding to the &lt;code&gt;\(j^\text{th}\)&lt;/code&gt; eigenvalue
&lt;code&gt;$$\lambda_j=2\left(1+\cos\left(\frac{2j\pi}{2n+1}\right)\right)$$&lt;/code&gt;
has &lt;code&gt;\(i^\text{th}\)&lt;/code&gt; component
&lt;code&gt;$$[v_j]_i=\alpha\sin\left(\frac{2ij\pi}{2n+1}\right),$$&lt;/code&gt;
where &lt;code&gt;\(\alpha\in\mathbb{R}\)&lt;/code&gt; is an arbitrary scalar.
This vector has length
&lt;code&gt;$$\begin{align} \lvert\vert v_j\rvert\rvert &amp;amp;\equiv \sqrt{\sum_{i=1}^n\left([v_j]_i\right)^2} \\ &amp;amp;= \sqrt{\sum_{i=1}^n\alpha^2\sin^2\left(\frac{2ij\pi}{2n+1}\right)} \\ &amp;amp;= \lvert\alpha\rvert\sqrt{\frac{2n+1}{4}}, \end{align}$$&lt;/code&gt;
where the last equality can be verified using Wolfram Alpha and proved using complex analysis.
So choosing &lt;code&gt;\(\alpha=2/\sqrt{2n+1}\)&lt;/code&gt; ensures that the eigenvectors &lt;code&gt;\(v_1,v_2,\ldots,v_n\)&lt;/code&gt; of &lt;code&gt;\(A^{-1}\)&lt;/code&gt; have unit length.
Then, by the &lt;a href=&#34;https://en.wikipedia.org/wiki/Spectral_theorem&#34;&gt;spectral theorem&lt;/a&gt;, these vectors form an &lt;a href=&#34;https://en.wikipedia.org/wiki/Orthonormal_basis&#34;&gt;orthonormal basis&lt;/a&gt; for &lt;code&gt;\(\mathbb{R}^n\)&lt;/code&gt;.
As a result, the &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix
&lt;code&gt;$$V=\begin{bmatrix} v_1 &amp;amp; v_2 &amp;amp; \cdots &amp;amp; v_n\end{bmatrix}$$&lt;/code&gt;
with &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(V_{ij}=[v_j]_i\)&lt;/code&gt; is &lt;a href=&#34;https://en.wikipedia.org/wiki/Orthogonal_matrix&#34;&gt;orthogonal&lt;/a&gt;.
Moreover, letting &lt;code&gt;\(\Lambda\)&lt;/code&gt; be the &lt;code&gt;\(n\times n\)&lt;/code&gt; diagonal matrix with &lt;code&gt;\({ii}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(\Lambda_{ii}=\lambda_i\)&lt;/code&gt; yields the eigendecomposition
&lt;code&gt;$$\begin{align} A^{-1} &amp;amp;= V\Lambda V^T \\ &amp;amp;= \sum_{j=1}^n\lambda_jv_jv_j^T \end{align}$$&lt;/code&gt;
of &lt;code&gt;\(A^{-1}\)&lt;/code&gt;.
It follows from the orthogonality of &lt;code&gt;\(V\)&lt;/code&gt; that
&lt;code&gt;$$\begin{align} A &amp;amp;= \left(V\Lambda V^T\right)^{-1} \\ &amp;amp;= V\Lambda^{-1} V^T \\ &amp;amp;= \sum_{j=1}^n\frac{1}{\lambda_j}v_jv_j^T \end{align}$$&lt;/code&gt;
is the eigendecomposition of &lt;code&gt;\(A\)&lt;/code&gt;.
Thus &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(A^{-1}\)&lt;/code&gt; have the same eigenvectors, but the eigenvalues of &lt;code&gt;\(A\)&lt;/code&gt; are the reciprocated eigenvalues of &lt;code&gt;\(A^{-1}\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s one scenario in which this decomposition is useful:
Suppose I observe data &lt;code&gt;\(\mathcal{D}=\{(x_i,y_i)\}_{i=1}^n\)&lt;/code&gt; generated by the process
&lt;code&gt;$$\DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \newcommand{\veps}{\sigma_\epsilon^2} \newcommand{\R}{\mathbb{R}} \renewcommand{\epsilon}{\varepsilon} \begin{align} y_i &amp;amp;= f(x_i)+\epsilon_i \\ \epsilon_i &amp;amp;\overset{\text{iid}}{\sim} \mathcal{N}(0,\veps), \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\{f(x)\}_{x\ge0}\)&lt;/code&gt; is a sample path of a standard &lt;a href=&#34;https://bldavies.com/blog/simulating-wiener-ornstein-uhlenbeck-processes/&#34;&gt;Wiener process&lt;/a&gt; and where the errors &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; are iid normally distributed with variance &lt;code&gt;\(\veps\)&lt;/code&gt;.
I use these data to estimate &lt;code&gt;\(f(x)\)&lt;/code&gt; for some &lt;code&gt;\(x\ge0\)&lt;/code&gt;.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
My estimator &lt;code&gt;\(\hat{f}(x)\equiv\E[f(x)\mid\mathcal{D}]\)&lt;/code&gt; has conditional variance
&lt;code&gt;$$\Var\left(\hat{f}(x)\mid\mathcal{D}\right)=\Var(f(x))-w^T\Sigma^{-1} w,$$&lt;/code&gt;
where &lt;code&gt;\(w\in\R^n\)&lt;/code&gt; is the vector with &lt;code&gt;\(i^\text{th}\)&lt;/code&gt; component &lt;code&gt;\(w_i=\Cov(y_i,f(x))\)&lt;/code&gt; and where &lt;code&gt;\(\Sigma\in\R^{n\times n}\)&lt;/code&gt; is the covariance matrix with &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(\Sigma_{ij}=\Cov(y_i,y_j)\)&lt;/code&gt;.
If &lt;code&gt;\(x_i=i\)&lt;/code&gt; for each &lt;code&gt;\(i\in\{1,2,\ldots,n\}\)&lt;/code&gt;, then we can express this matrix as the sum
&lt;code&gt;$$\Sigma=A+\veps I,$$&lt;/code&gt;
where &lt;code&gt;\(A\)&lt;/code&gt; is the &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix defined above and where &lt;code&gt;\(I\)&lt;/code&gt; is the &lt;code&gt;\(n\times n\)&lt;/code&gt; identity matrix.
But we know &lt;code&gt;\(A=V\Lambda^{-1}V^T\)&lt;/code&gt;.
We also know &lt;code&gt;\(I=VV^T\)&lt;/code&gt;, since &lt;code&gt;\(V\)&lt;/code&gt; is orthogonal.
It follows that
&lt;code&gt;$$\begin{align*} \Sigma^{-1} &amp;amp;= \left(V\Lambda^{-1}V^T+\veps VV^T\right)^{-1} \\ &amp;amp;= V\left(\Lambda+\frac{1}{\veps}I\right)V^T, \end{align*}$$&lt;/code&gt;
from which we can derive a (relatively) closed-form expression for the conditional variance of &lt;code&gt;\(\hat{f}(x)\)&lt;/code&gt; given &lt;code&gt;\(\mathcal{D}\)&lt;/code&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;One can verify this claim by showing &lt;code&gt;\(AA^{-1}\)&lt;/code&gt; equals the identity matrix. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I discuss this estimation problem in &lt;a href=&#34;https://arxiv.org/abs/2404.00784&#34;&gt;a recent paper&lt;/a&gt; and apply its solution in &lt;a href=&#34;https://bldavies.com/blog/value-conceptual-knowledge/&#34;&gt;another&lt;/a&gt;. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Delayed saving</title>
      <link>https://bldavies.com/blog/delayed-saving/</link>
      <pubDate>Wed, 01 May 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/delayed-saving/</guid>
      <description>&lt;p&gt;Suppose I want to retire at time &lt;code&gt;\(T&amp;gt;0\)&lt;/code&gt;.
I make constant payments to a savings account that earns continuously compounded interest &lt;code&gt;\(r&amp;gt;0\)&lt;/code&gt;.
I want my retirement fund to be worth &lt;code&gt;\(V&amp;gt;0\)&lt;/code&gt; today (time &lt;code&gt;\(0\)&lt;/code&gt;).
How much bigger do my payments have to be if I delay them?&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(X_d\)&lt;/code&gt; be the payments I have to make if I start saving at time &lt;code&gt;\(d\in[0,T]\)&lt;/code&gt;.
These payments form an &lt;a href=&#34;https://en.wikipedia.org/wiki/Annuity&#34;&gt;annuity&lt;/a&gt; with value
&lt;code&gt;$$\frac{X_d}{r}\left(1-e^{-r(T-d)}\right)$$&lt;/code&gt;
at time &lt;code&gt;\(d\)&lt;/code&gt;.
I want this value to equal &lt;code&gt;\(Ve^{rd}\)&lt;/code&gt;.
So my payments must equal
&lt;code&gt;$$\begin{align} X_d &amp;amp;= \frac{r}{1-e^{-r(T-d)}}\times Ve^{rd} \\ &amp;amp;= \frac{rV}{e^{-rd}-e^{-rT}}. \end{align}$$&lt;/code&gt;
Therefore, delaying to time &lt;code&gt;\(d\)&lt;/code&gt; increases my payments by a factor of
&lt;code&gt;$$\frac{X_d}{X_0}=\frac{1-e^{-rT}}{e^{-rd}-e^{-rT}}.$$&lt;/code&gt;
The chart below shows how &lt;code&gt;\(X_d/X_0\)&lt;/code&gt; grows with the proportion of time &lt;code&gt;\(d/T\)&lt;/code&gt; I delay saving.
Part of this growth comes from having less time remaining: if my savings earn no interest, then the factor
&lt;code&gt;$$\lim_{r\to0}\frac{X_d}{X_0}=\frac{T}{T-d}$$&lt;/code&gt;
equals the ratio of time until retirement and time spent saving.
Raising &lt;code&gt;\(r\)&lt;/code&gt; raises &lt;code&gt;\(X_d/X_0\)&lt;/code&gt; because I forgo more opportunities to earn interest on my interest the longer I delay.
This is especially true when I&amp;rsquo;m far from retiring (i.e., &lt;code&gt;\(T\)&lt;/code&gt; is large).&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://profiles.stanford.edu/michael-boskin&#34;&gt;Michael Boskin&lt;/a&gt; for inspiring this post.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learning about a changing state</title>
      <link>https://bldavies.com/blog/learning-changing-state/</link>
      <pubDate>Mon, 08 Jan 2024 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-changing-state/</guid>
      <description>&lt;p&gt;I have a &lt;a href=&#34;https://arxiv.org/abs/2401.03607&#34;&gt;new paper&lt;/a&gt; on Bayesian learning.
It extends my model of &lt;a href=&#34;https://bldavies.com/blog/paying-precision/&#34;&gt;paying for precision&lt;/a&gt; to a setting where the unknown state changes over time.
This makes the agent keep buying new information as his existing information becomes out of date.
I show how his demand for information depends on whether he is myopic or forward-looking, and on the &lt;a href=&#34;https://en.wikipedia.org/wiki/Gaussian_process&#34;&gt;Gaussian process&lt;/a&gt; defining how the state evolves.&lt;/p&gt;
&lt;p&gt;The paper stems from my research with &lt;a href=&#34;https://sites.google.com/view/anirudh-sankar&#34;&gt;Anirudh Sankar&lt;/a&gt; on how people learn across contexts.
Suppose I ask you for advice, and you say &amp;ldquo;X worked for me.&amp;rdquo;
But will X work for me?
We&amp;rsquo;re different people with different contexts (e.g., physical and social positions).
Our outcomes might be different.&lt;/p&gt;
&lt;p&gt;Imagine there&amp;rsquo;s a function mapping contexts to outcomes.
If I know this function then I can invert it, taking information generated in your context and porting it into mine.
But if I don&amp;rsquo;t know the function then I can&amp;rsquo;t invert it, which makes learning from you hard.
Anirudh and my research formalizes this idea: the more I know about the function mapping contexts to outcomes, the easier it is to learn across contexts.&lt;/p&gt;
&lt;p&gt;Mathematically, learning across contexts is like learning across time: the function mapping contexts to outcomes is like a stochastic process mapping times to states.
But contexts, unlike time, can have many dimensions and may not be &lt;a href=&#34;https://en.wikipedia.org/wiki/Total_order&#34;&gt;totally orderable&lt;/a&gt;.
Contexts are more general, and so models of learning across them can lead to more general insights.
I hope to share some of those insights in the future.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Update (2025-09-16): The future has arrived&amp;mdash;see &lt;a href=&#34;https://bldavies.com/blog/value-conceptual-knowledge/&#34;&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learning from correlated signals</title>
      <link>https://bldavies.com/blog/learning-correlated-signals/</link>
      <pubDate>Fri, 24 Nov 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-correlated-signals/</guid>
      <description>&lt;p&gt;Suppose I want to learn the value of a parameter &lt;code&gt;\(\theta\in\mathbb{R}\)&lt;/code&gt;.
My prior is that &lt;code&gt;\(\theta\)&lt;/code&gt; is normally distributed with variance &lt;code&gt;\(\sigma_0^2\)&lt;/code&gt;.
I observe &lt;code&gt;\(n\ge1\)&lt;/code&gt; signals
&lt;code&gt;$$\DeclareMathOperator{\Cor}{Cor} \DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \newcommand{\R}{\mathbb{R}} \renewcommand{\epsilon}{\varepsilon} s_i=\theta+\epsilon_i$$&lt;/code&gt;
of &lt;code&gt;\(\theta\)&lt;/code&gt;.
The errors &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; in these signals are independent of &lt;code&gt;\(\theta\)&lt;/code&gt;.
They are jointly normally distributed with equal variances &lt;code&gt;\(\Var(\epsilon_i)=\sigma^2\)&lt;/code&gt; and pairwise correlations
&lt;code&gt;$$\Cor(\epsilon_i,\epsilon_j)=\begin{cases} 1 &amp;amp; \text{if}\ i=j \\ \rho &amp;amp; \text{otherwise}. \end{cases}$$&lt;/code&gt;
I assume &lt;code&gt;\(-1/(n-1)\le\rho\le1\)&lt;/code&gt; so that this distribution is feasible.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Observing &lt;code&gt;\(s_1,s_2,\ldots,s_n\)&lt;/code&gt; is the same to observing the sample mean
&lt;code&gt;$$\bar{s}_n\equiv\frac{1}{n}\sum_{i=1}^ns_i,$$&lt;/code&gt;
which is normally distributed and has conditional variance
&lt;code&gt;$$\Var(\bar{s}_n\mid\theta)=\frac{(1+(n-1))\rho\sigma^2}{n}$$&lt;/code&gt;
under my prior.
The posterior distribution of &lt;code&gt;\(\theta\)&lt;/code&gt; given &lt;code&gt;\(\bar{s}_n\)&lt;/code&gt; is also normal and has variance
&lt;code&gt;$$\Var(\theta\mid\bar{s}_n)=\left(\frac{1}{\sigma_0^2}+\frac{n}{(1+(n-1)\rho)\sigma^2}\right)^{-1}.$$&lt;/code&gt;
Both variances are
(i) decreasing in &lt;code&gt;\(n\)&lt;/code&gt; when &lt;code&gt;\(\rho&amp;lt;1\)&lt;/code&gt; and
(ii) increasing in &lt;code&gt;\(\rho\)&lt;/code&gt; when &lt;code&gt;\(n&amp;gt;1\)&lt;/code&gt;.
Intuitively, if the signals are not perfectly correlated then observing more gives me more information about &lt;code&gt;\(\theta\)&lt;/code&gt;.
If they are negatively correlated then their errors &amp;ldquo;cancel out&amp;rdquo; and the sample mean &lt;code&gt;\(\bar{s}_n\)&lt;/code&gt; gives me a precise estimate of &lt;code&gt;\(\theta\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The chart below shows how &lt;code&gt;\(\Var(\bar{s}_n\mid\theta)\)&lt;/code&gt; and &lt;code&gt;\(\Var(\theta\mid\bar{s}_n)\)&lt;/code&gt; vary with &lt;code&gt;\(\rho\)&lt;/code&gt; and &lt;code&gt;\(n\)&lt;/code&gt; when &lt;code&gt;\(\sigma_0=\sigma=1\)&lt;/code&gt;.
If &lt;code&gt;\(\rho=-1/(n-1)\)&lt;/code&gt; then &lt;code&gt;\(\epsilon_1+\epsilon_2+\cdots+\epsilon_n=0\)&lt;/code&gt;, and so &lt;code&gt;\(\Var(\bar{s}_n\mid\theta)=0\)&lt;/code&gt; and &lt;code&gt;\(\Var(\theta\mid\bar{s}_n)=0\)&lt;/code&gt; because &lt;code&gt;\(\bar{s}_n=\theta\)&lt;/code&gt;.
Whereas if &lt;code&gt;\(\rho=1\)&lt;/code&gt; then signals &lt;code&gt;\(s_2\)&lt;/code&gt; through &lt;code&gt;\(s_n\)&lt;/code&gt; provide the same information as &lt;code&gt;\(s_1\)&lt;/code&gt;, and so &lt;code&gt;\(\Var(\bar{s}_n\mid\theta)=\Var(s_1\mid\theta)\)&lt;/code&gt; and &lt;code&gt;\(\Var(\theta\mid\bar{s}_n)=\Var(\theta\mid s_1)\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/variances-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;For example, it is impossible for three normal variables to have equal variances and pairwise correlations of &lt;code&gt;\(-1\)&lt;/code&gt;.
See &lt;a href=&#34;https://bldavies.com/blog/transitivity-positive-correlations/&#34;&gt;here&lt;/a&gt; for an explanation. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Simulating Wiener and Ornstein-Uhlenbeck processes</title>
      <link>https://bldavies.com/blog/simulating-wiener-ornstein-uhlenbeck-processes/</link>
      <pubDate>Tue, 29 Aug 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/simulating-wiener-ornstein-uhlenbeck-processes/</guid>
      <description>&lt;p&gt;A (standard) &lt;a href=&#34;https://en.wikipedia.org/wiki/Wiener_process&#34;&gt;Wiener process&lt;/a&gt; is a continuous-time stochastic process &lt;code&gt;\(\{W(t)\}_{t\ge0}\)&lt;/code&gt; with initial value &lt;code&gt;\(W(0)=0\)&lt;/code&gt; and instantaneous increments
&lt;code&gt;$$\newcommand{\der}{\mathrm{d}} \der W(t)\sim N(0,\der t).$$&lt;/code&gt;
We can simulate such a process as follows.
First, create a sequence of times &lt;code&gt;\(t\)&lt;/code&gt; at which to store the value of &lt;code&gt;\(W(t)\)&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;t_max&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;100&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;dt&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1e-2&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;seq&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t_max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Increasing &lt;code&gt;t_max&lt;/code&gt; creates a longer path, while decreasing &lt;code&gt;dt&lt;/code&gt; creates a smoother path.
Now simulate the random increments and take their cumulative sum:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;dW&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rnorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sd&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sqrt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;W&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dW&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here are three sample paths generated by this procedure:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/wiener-paths-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;We can use &lt;code&gt;\(\{W(t)\}_{t\ge0}\)&lt;/code&gt; to construct an &lt;a href=&#34;https://en.wikipedia.org/wiki/Ornstein%E2%80%93Uhlenbeck_process&#34;&gt;Ornstein-Uhlenbeck process&lt;/a&gt; &lt;code&gt;\(\{X(t)\}_{t\ge0}\)&lt;/code&gt;.
This process has instantaneous increments
&lt;code&gt;$$\der X(t)=-\theta X(t)\der t+\der W(t),$$&lt;/code&gt;
where &lt;code&gt;\(\theta\ge0\)&lt;/code&gt; controls the process&amp;rsquo; tendency to &lt;a href=&#34;https://en.wikipedia.org/wiki/Regression_toward_the_mean&#34;&gt;mean-revert&lt;/a&gt;.
We can compute its values &lt;code&gt;\(X(t)\)&lt;/code&gt; by iterating over &lt;code&gt;dW&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;theta&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dW&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;while &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dW&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;X[i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X[i]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;theta&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X[i]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dt&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dW[i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The chart below compares the sample paths obtained using different &lt;code&gt;\(\theta\)&lt;/code&gt; values.
Each path uses the same realization of the underlying Wiener process &lt;code&gt;\(\{W(t)\}_{t\ge0}\)&lt;/code&gt;.
If &lt;code&gt;\(\theta=0\)&lt;/code&gt; then &lt;code&gt;\(X(t)=W(t)\)&lt;/code&gt; for all &lt;code&gt;\(t\ge0\)&lt;/code&gt;.
The mean magnitude of &lt;code&gt;\(X(t)\)&lt;/code&gt; falls as &lt;code&gt;\(\theta\)&lt;/code&gt; rises because this makes the process more mean-reverting.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/orstein-uhlenbeck-paths-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Inverting matrices of pairwise minima</title>
      <link>https://bldavies.com/blog/inverting-matrices-pairwise-minima/</link>
      <pubDate>Sun, 20 Aug 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/inverting-matrices-pairwise-minima/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(0&amp;lt;x_1&amp;lt;x_2&amp;lt;\ldots&amp;lt;x_n\)&lt;/code&gt; and let &lt;code&gt;\(A\)&lt;/code&gt; be the symmetric &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix with &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(A_{ij}=\min\{x_i,x_j\}\)&lt;/code&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
This matrix has linearly independent columns and so is invertible.
Its inverse &lt;code&gt;\(A^{-1}\)&lt;/code&gt; is symmetric, &lt;a href=&#34;https://en.wikipedia.org/wiki/Tridiagonal_matrix&#34;&gt;tridiagonal&lt;/a&gt;, and has &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry
&lt;code&gt;$$[A^{-1}]_{ij}=\begin{cases} \frac{1}{x_1}+\frac{1}{x_2-x_1} &amp;amp; \text{if}\ i=j=1 \\ \frac{1}{x_i-x_{i-1}}+\frac{1}{x_{i+1}-x_i} &amp;amp; \text{if}\ 1&amp;lt;i=j&amp;lt;n \\ \frac{1}{x_n-x_{n-1}} &amp;amp; \text{if}\ i=j=n \\ -\frac{1}{x_j-x_i} &amp;amp; \text{if}\ i=j-1 \\ -\frac{1}{x_i-x_j} &amp;amp; \text{if}\ i=j+1 \\ 0 &amp;amp; \text{otherwise}. \end{cases}$$&lt;/code&gt;
For example, if &lt;code&gt;\(x_i=2^{i-1}\)&lt;/code&gt; for each &lt;code&gt;\(i\le n=5\)&lt;/code&gt; then
&lt;code&gt;$$A=\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 2 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 4 &amp;amp; 4 &amp;amp; 4 \\ 1 &amp;amp; 2 &amp;amp; 4 &amp;amp; 8 &amp;amp; 8 \\ 1 &amp;amp; 2 &amp;amp; 4 &amp;amp; 8 &amp;amp; 16 \\ \end{bmatrix}$$&lt;/code&gt;
and
&lt;code&gt;$$A^{-1}=\begin{bmatrix} 2 &amp;amp; -1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ -1 &amp;amp; 1.5 &amp;amp; -0.5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; -0.5 &amp;amp; 0.75 &amp;amp; -0.25 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -0.25 &amp;amp; 0.375 &amp;amp; -0.125 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; -0.125 &amp;amp; 0.125 \\ \end{bmatrix}$$&lt;/code&gt;
You may wonder: why is this useful?
Suppose I observe data &lt;code&gt;\(\{(x_i,y_i)\}_{i=1}^n\)&lt;/code&gt;, where the function &lt;code&gt;\(f:[0,\infty)\to\mathbb{R}\)&lt;/code&gt; mapping regressors &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; to outcomes &lt;code&gt;\(y_i=f(x_i)\)&lt;/code&gt; is the realization of a &lt;a href=&#34;https://en.wikipedia.org/wiki/Wiener_process&#34;&gt;Wiener process&lt;/a&gt;.
I use these data to estimate some value &lt;code&gt;\(f(x)\)&lt;/code&gt; via &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayesian_linear_regression&#34;&gt;Bayesian regression&lt;/a&gt;.
My estimate depends on the inverse of the covariance matrix for the outcome vector &lt;code&gt;\(y=(y_1,y_2,\ldots,y_n)\)&lt;/code&gt;.
This matrix has &lt;code&gt;\({ij}^\text{th}\)&lt;/code&gt; entry &lt;code&gt;\(\min\{x_i,x_j\}\)&lt;/code&gt;, so I can compute its inverse using the expression above.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://mathoverflow.net/questions/453045/is-there-a-name-for-this-family-of-matrices&#34;&gt;Let me know&lt;/a&gt; if the family of such matrices has a name! &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Correlation and concordance</title>
      <link>https://bldavies.com/blog/correlation-concordance/</link>
      <pubDate>Thu, 03 Aug 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/correlation-concordance/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(X=(X_1,X_2)\)&lt;/code&gt; be a random vector in &lt;code&gt;\(\mathbb{R}^2\)&lt;/code&gt;.
Two realizations &lt;code&gt;\(x\)&lt;/code&gt; and &lt;code&gt;\(x&#39;\)&lt;/code&gt; of &lt;code&gt;\(X\)&lt;/code&gt; form a &lt;a href=&#34;https://en.wikipedia.org/wiki/Concordant_pair&#34;&gt;concordant pair&lt;/a&gt; if &lt;code&gt;\((x_2&#39;-x_2)\)&lt;/code&gt; and &lt;code&gt;\((x_1&#39;-x_1)\)&lt;/code&gt; have the same sign.
What&amp;rsquo;s the probability of sampling a concordant pair when &lt;code&gt;\(X\)&lt;/code&gt; is bivariate normal?&lt;/p&gt;
&lt;p&gt;For example, suppose &lt;code&gt;\(X_1\)&lt;/code&gt; and &lt;code&gt;\(X_2\)&lt;/code&gt; have zero means, unit variances, and a correlation of &lt;code&gt;\(\rho\)&lt;/code&gt;.
The scatter plots below show 100 realizations of &lt;code&gt;\((X_1,X_2)\)&lt;/code&gt; when &lt;code&gt;\(\rho\in\{-0.5,0,0.5\}\)&lt;/code&gt;.
These realizations contain
&lt;code&gt;$$\binom{100}{2}=4,\!950$$&lt;/code&gt;
pairs, of which 36% are concordant when &lt;code&gt;\(\rho=-0.5\)&lt;/code&gt;.
This percentage rises to 48% when &lt;code&gt;\(\rho=0\)&lt;/code&gt; and to 71% when &lt;code&gt;\(\rho=0.5\)&lt;/code&gt;.
Increasing &lt;code&gt;\(\rho\)&lt;/code&gt; makes concordance more likely because it makes &lt;code&gt;\((X_2-X_1)\)&lt;/code&gt; larger and less noisy.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/scatter-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Different samples give different concordance rates due to sampling variation.
We can remove this variation by deriving the concordance rate analytically.
To begin, suppose &lt;code&gt;\(X\)&lt;/code&gt; has mean &lt;code&gt;\(\mathrm{E}[X]=(\mu_1,\mu_2)\)&lt;/code&gt; and covariance matrix
&lt;code&gt;$$\mathrm{Var}(X)=\begin{bmatrix} \sigma_1^2 &amp;amp; \rho\sigma_1\sigma_2 \\ \rho\sigma_1\sigma_2 &amp;amp; \sigma_2^2 \end{bmatrix}.$$&lt;/code&gt;
Then &lt;code&gt;\(X_2\mid X_1\)&lt;/code&gt; is normal with mean
&lt;code&gt;$$\mathrm{E}[X_2\mid X_1]=\mu_2+\frac{\rho\sigma_2}{\sigma_1}(X_1-\mu_1)$$&lt;/code&gt;
and variance
&lt;code&gt;$$\mathrm{Var}(X_2\mid X_1)=(1-\rho^2)\sigma_2^2.$$&lt;/code&gt;
So for any two realizations &lt;code&gt;\(x\)&lt;/code&gt; and &lt;code&gt;\(x&#39;\)&lt;/code&gt; of &lt;code&gt;\(X\)&lt;/code&gt; we can write
&lt;code&gt;$$\renewcommand{\epsilon}{\varepsilon} x&#39;_2-x_2=\frac{\rho\sigma_2}{\sigma_1}\left(x&#39;_1-x_1\right)+\epsilon$$&lt;/code&gt;
with &lt;code&gt;\(\epsilon\sim N(0,2(1-\rho^2)\sigma_2^2)\)&lt;/code&gt;.
Now &lt;code&gt;\(x&#39;_1-x_1\sim N(0,2\sigma_1^2)\)&lt;/code&gt; is normal, and so
&lt;code&gt;$$z\equiv \frac{x&#39;_1-x_1}{\sigma_1\sqrt{2}}$$&lt;/code&gt;
is standard normal and exceeds zero if and only if &lt;code&gt;\(x&#39;_1&amp;gt;x_1\)&lt;/code&gt;.
Letting &lt;code&gt;\(f\)&lt;/code&gt; and &lt;code&gt;\(\phi\)&lt;/code&gt; be the density functions for &lt;code&gt;\(\epsilon\)&lt;/code&gt; and &lt;code&gt;\(z\)&lt;/code&gt; then gives
&lt;code&gt;$$\newcommand{\der}{\mathrm{d}} \begin{align} \Pr(x&#39;_2&amp;gt;x_2\ \text{and}\ x&#39;_1&amp;gt;x_1) &amp;amp;= \Pr(\sqrt{2}\rho\sigma_2 z+\epsilon&amp;gt;0\ \text{and}\ z&amp;gt;0) \\ &amp;amp;= \int_0^\infty\left(\int_{-\sqrt{2}\rho\sigma_2 z}^\infty f(\epsilon)\,\der \epsilon\right)\phi(z)\,\der z \\ &amp;amp;\overset{\star}{=} \int_0^\infty\left(\int_{\frac{-\rho z}{\sqrt{1-\rho^2}}}^\infty \phi(w)\,\der w\right)\phi(z)\,\der z \\ &amp;amp;= \int_0^\infty\left(1-\Phi\left(\frac{-\rho z}{\sqrt{1-\rho^2}}\right)\right)\phi(z)\,\der z \\ &amp;amp;\overset{\star\star}{=} \frac{1}{2}-\int_0^\infty\Phi\left(\frac{-\rho z}{\sqrt{1-\rho^2}}\right)\phi(z)\,\der z, \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\Phi\)&lt;/code&gt; is the standard normal CDF, where &lt;code&gt;\(\star\)&lt;/code&gt; uses the change of variables
&lt;code&gt;$$w\equiv \frac{\epsilon}{\sigma_2\sqrt{2(1-\rho^2)}},$$&lt;/code&gt;
and where &lt;code&gt;\(\star\star\)&lt;/code&gt; uses the symmetry of &lt;code&gt;\(\phi\)&lt;/code&gt; about &lt;code&gt;\(z=0\)&lt;/code&gt;.
But &lt;code&gt;\(f\)&lt;/code&gt; is symmetric about &lt;code&gt;\(\epsilon=0\)&lt;/code&gt;, which implies
&lt;code&gt;$$\Pr(x&#39;_2&amp;gt;x_2\ \text{and}\ x&#39;_1&amp;gt;x_1)=\Pr(x&#39;_2&amp;lt;x_1\ \text{and}\ x&#39;_1&amp;lt;x_1),$$&lt;/code&gt;
and therefore
&lt;code&gt;$$\begin{align} C(\rho) &amp;amp;\equiv \Pr(x\ \text{and}\ x&#39;\ \text{are concordant}) \\ &amp;amp;= \Pr(x&#39;_2&amp;gt;x_2\ \text{and}\ x&#39;_1&amp;gt;x_1)+\Pr(x&#39;_2&amp;lt;x_1\ \text{and}\ x&#39;_1&amp;lt;x_1) \\ &amp;amp;= 1-2\int_0^\infty\Phi\left(\frac{-\rho z}{\sqrt{1-\rho^2}}\right)\phi(z)\,\der z. \end{align}$$&lt;/code&gt;
The concordance rate &lt;code&gt;\(C(\rho)\)&lt;/code&gt; depends on the correlation &lt;code&gt;\(\rho\)&lt;/code&gt; of &lt;code&gt;\(X_1\)&lt;/code&gt; and &lt;code&gt;\(X_2\)&lt;/code&gt;, but not their means or variances.
It has value &lt;code&gt;\(C(0)=0.5\)&lt;/code&gt; when &lt;code&gt;\(\rho=0\)&lt;/code&gt; because &lt;code&gt;\(\Phi(0)=0.5\)&lt;/code&gt; is constant.
Intuitively, if &lt;code&gt;\(X_1\)&lt;/code&gt; and &lt;code&gt;\(X_2\)&lt;/code&gt; are uncorrelated then we can&amp;rsquo;t use &lt;code&gt;\((x&#39;_1-x_1)\)&lt;/code&gt; to predict &lt;code&gt;\((x&#39;_2-x_2)\)&lt;/code&gt;, which is equally likely to be positive or negative.
Whereas if &lt;code&gt;\(\lvert\rho\rvert=1\)&lt;/code&gt; then &lt;code&gt;\((x&#39;_1-x_1)\)&lt;/code&gt; predicts &lt;code&gt;\((x&#39;_2-x_2)\)&lt;/code&gt; perfectly, and so
&lt;code&gt;$$\lim_{\rho\to1}C(\rho)=1$$&lt;/code&gt;
and
&lt;code&gt;$$\lim_{\rho\to-1}C(\rho)=0.$$&lt;/code&gt;
The chart below verifies that the concordance rate &lt;code&gt;\(C(\rho)\)&lt;/code&gt; grows with &lt;code&gt;\(\rho\)&lt;/code&gt;.
It also shows that
&lt;code&gt;$$C(\rho)+C(1-\rho)=1.$$&lt;/code&gt;
Thus, for example, we have &lt;code&gt;\(C(-0.5)=1/3\)&lt;/code&gt; and &lt;code&gt;\(C(0.5)=2/3\)&lt;/code&gt;.
These values remove the sampling error from the estimates 0.36 and 0.71 obtained using the 100 realizations above.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/integral-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>The option value of waiting</title>
      <link>https://bldavies.com/blog/option-value-waiting/</link>
      <pubDate>Sun, 16 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/option-value-waiting/</guid>
      <description>&lt;p&gt;This post is about waiting for information before taking an action.
It uses a simple model to explain when and why waiting is valuable.
It formalizes some ideas discussed in my posts on &lt;a href=&#34;https://bldavies.com/blog/climate-change-transport-planning/&#34;&gt;climate change&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/policymaking-under-uncertainty/&#34;&gt;pandemic&lt;/a&gt; policy.&lt;/p&gt;
&lt;p&gt;Suppose it costs &lt;code&gt;\(c&amp;gt;0\)&lt;/code&gt; to take an action that pays &lt;code&gt;\(b&amp;gt;c\)&lt;/code&gt; if it is beneficial (&lt;code&gt;\(\omega=1\)&lt;/code&gt;) and zero otherwise (&lt;code&gt;\(\omega=0\)&lt;/code&gt;).
I take the action if its expected net benefit
&lt;code&gt;$$\newcommand{\E}{\mathrm{E}} \E[\omega b-c]=pb-c$$&lt;/code&gt;
exceeds zero, where &lt;code&gt;\(p=\Pr(\omega=1)\)&lt;/code&gt; is my prior belief about &lt;code&gt;\(\omega\)&lt;/code&gt;.
Thus, my decision rule is to take the action whenever &lt;code&gt;\(p\)&lt;/code&gt; exceeds the cost-benefit ratio &lt;code&gt;\(c/b\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now suppose I can wait for a &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signal&lt;/a&gt; &lt;code&gt;\(s\in\{0,1\}\)&lt;/code&gt; with error rate
&lt;code&gt;$$\renewcommand{\epsilon}{\varepsilon} \Pr(s\not=\omega\mid \omega)=\epsilon\in[0,0.5].$$&lt;/code&gt;
I use my prior, the signal, and Bayes&amp;rsquo; rule to form a posterior belief
&lt;code&gt;$$\begin{align} q_s &amp;amp;\equiv \Pr(\omega=1\mid s) \\ &amp;amp;= \begin{cases} \frac{\epsilon p}{(1-\epsilon)(1-p)+\epsilon p} &amp;amp; \text{if}\ s=0 \\ \frac{(1-\epsilon)p}{\epsilon(1-p)+(1-\epsilon)p} &amp;amp; \text{if}\ s=1 \end{cases} \end{align}$$&lt;/code&gt;
about &lt;code&gt;\(\omega\)&lt;/code&gt;.
Then I take the action if its expected net benefit
&lt;code&gt;$$\begin{align} \E[\omega b-c\mid s] &amp;amp;= q_sb-c \end{align}$$&lt;/code&gt;
given &lt;code&gt;\(s\)&lt;/code&gt; exceeds zero.
This happens with probability
&lt;code&gt;$$\Pr(q_sb-c\ge0)=\begin{cases} 1 &amp;amp; \text{if}\ c/b\le q_0 \\ \Pr(s=1) &amp;amp; \text{if}\ q_0&amp;lt;c/b\le q_1 \\ 0 &amp;amp; \text{if}\ q_1&amp;lt;c/b, \end{cases}$$&lt;/code&gt;
where the probability
&lt;code&gt;$$\Pr(s=1)=\epsilon(1-p)+(1-\epsilon)p$$&lt;/code&gt;
of receiving a positive signal depends on my prior &lt;code&gt;\(p\)&lt;/code&gt; and the error rate &lt;code&gt;\(\epsilon\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;\(c/b\le q_0\)&lt;/code&gt; or &lt;code&gt;\(q_1&amp;lt;c/b\)&lt;/code&gt; then the signal doesn&amp;rsquo;t affect whether I take the action, so I don&amp;rsquo;t need to wait.
But if &lt;code&gt;\(q_0&amp;lt;c/b\le q_1\)&lt;/code&gt; then waiting gives me a &lt;a href=&#34;https://en.wikipedia.org/wiki/Real_options_valuation&#34;&gt;real option&lt;/a&gt; not to take the action if I learn it isn&amp;rsquo;t beneficial.
So the expected benefit of waiting equals
&lt;code&gt;$$\begin{align} W &amp;amp;\equiv \delta\,\E\left[\E[\max\{0,q_sb-c\}\mid s]\right] \\ &amp;amp;= \begin{cases} \delta(pb-c) &amp;amp; \text{if}\ c/b\le q_0 \\ \delta(q_1b-c)\Pr(s=1) &amp;amp; \text{if}\ q_0&amp;lt;c/b\le q_1 \\ 0 &amp;amp; \text{if}\ q_1&amp;lt;c/b, \end{cases} \end{align}$$&lt;/code&gt;
where the discount factor &lt;code&gt;\(\delta\in[0,1]\)&lt;/code&gt; captures
(i) my patience and
(ii) my confidence that the action will still be available if I wait.&lt;/p&gt;
&lt;p&gt;I should take the action &lt;em&gt;before&lt;/em&gt; receiving &lt;code&gt;\(s\)&lt;/code&gt; if and only if the expected net benefit &lt;code&gt;\((pb-c)\)&lt;/code&gt; under my prior exceeds &lt;code&gt;\(W\)&lt;/code&gt;.
This happens precisely when my prior exceeds
&lt;code&gt;$$p^*\equiv\frac{(1-\delta\epsilon)c}{b-\delta((1-\epsilon)b-(1-2\epsilon)c)}.$$&lt;/code&gt;
The following chart plots &lt;code&gt;\(p^*\)&lt;/code&gt; against &lt;code&gt;\(\delta\)&lt;/code&gt; when &lt;code&gt;\(c/b\in\{0.1,0.3,0.5\}\)&lt;/code&gt; and &lt;code&gt;\(\epsilon\in\{0,0.25,0.5\}\)&lt;/code&gt;.
Increasing the discount factor &lt;code&gt;\(\delta\)&lt;/code&gt; or the cost-benefit ratio &lt;code&gt;\(c/b\)&lt;/code&gt; raises the option value of waiting, which raises the threshold prior &lt;code&gt;\(p^*\)&lt;/code&gt; above which I should take the action.
Increasing the error rate &lt;code&gt;\(\epsilon\)&lt;/code&gt; makes the signal less informative, which &lt;em&gt;lowers&lt;/em&gt; the option value of waiting and, hence, lowers &lt;code&gt;\(p^*\)&lt;/code&gt;.
If &lt;code&gt;\(\epsilon=0.5\)&lt;/code&gt; then the signal is uninformative and so &lt;code&gt;\(p^*=c/b\)&lt;/code&gt; independently of &lt;code&gt;\(\delta\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/thresholds-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learning in continuous time</title>
      <link>https://bldavies.com/blog/learning-continuous-time/</link>
      <pubDate>Sat, 08 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-continuous-time/</guid>
      <description>&lt;p&gt;This post describes a continuous-time model of Bayesian learning about a binary state.
It complements the discrete-time models discussed in previous posts (see, e.g., &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;here&lt;/a&gt; or &lt;a href=&#34;https://bldavies.com/blog/binary-signals-posterior-variances/&#34;&gt;here&lt;/a&gt;).
I present &lt;a href=&#34;#model&#34;&gt;the model&lt;/a&gt;, discuss its &lt;a href=&#34;#learning-dynamics&#34;&gt;learning dynamics&lt;/a&gt;, and &lt;a href=&#34;#deriving-the-belief-increments&#34;&gt;derive these dynamics&lt;/a&gt; analytically.&lt;/p&gt;
&lt;p&gt;The model has been used to study decision times (&lt;a href=&#34;https://doi.org/10.1257/aer.20150742&#34;&gt;Fudenberg et al., 2018&lt;/a&gt;), experimentation (&lt;a href=&#34;https://doi.org/10.1111/1468-0262.00022&#34;&gt;Bolton and Harris, 1999&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1111/1468-0262.00259&#34;&gt;Moscarini and Smith, 2001&lt;/a&gt;), information acquisition (&lt;a href=&#34;https://doi.org/10.2139/ssrn.2991567&#34;&gt;Morris and Strack, 2019&lt;/a&gt;), and persuasion (&lt;a href=&#34;https://doi.org/10.1016/j.jmateco.2021.102534&#34;&gt;Liao, 2021&lt;/a&gt;).
It also underlies the &lt;a href=&#34;https://en.wikipedia.org/wiki/Two-alternative_forced_choice#Drift-diffusion_model&#34;&gt;drift-diffusion model&lt;/a&gt; of reaction times used by psychologists&amp;mdash;see &lt;a href=&#34;https://doi.org/10.1037/0033-295X.85.2.59&#34;&gt;Ratcliff (1978)&lt;/a&gt; for an early example, and &lt;a href=&#34;https://doi.org/10.1016/j.jet.2023.105612&#34;&gt;Hébert and Woodford (2023)&lt;/a&gt; or &lt;a href=&#34;https://doi.org/10.1006/jmps.1999.1260&#34;&gt;Smith (2000)&lt;/a&gt; for related discussions.&lt;/p&gt;
&lt;h2 id=&#34;model&#34;&gt;Model&lt;/h2&gt;
&lt;p&gt;Suppose I want to learn about a state &lt;code&gt;\(\mu\)&lt;/code&gt; that may be high (equal to &lt;code&gt;\(H\)&lt;/code&gt;) or low (equal to &lt;code&gt;\(L&amp;lt;H\)&lt;/code&gt;).
I observe a continuous sample path &lt;code&gt;\((X_t)_{t\ge0}\)&lt;/code&gt; with random, instantaneous increments
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \newcommand{\der}{\mathrm{d}} \newcommand{\R}{\mathbb{R}} \der X_t=\mu\der t+\sigma \der W_t,$$&lt;/code&gt;
where &lt;code&gt;\(\sigma&amp;gt;0\)&lt;/code&gt; amplifies the noise generated by the standard &lt;a href=&#34;https://en.wikipedia.org/wiki/Wiener_process&#34;&gt;Wiener process&lt;/a&gt; &lt;code&gt;\((W_t)_{t\ge0}\)&lt;/code&gt;.
These increments provide &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signals&lt;/a&gt; of the state &lt;code&gt;\(\mu\)&lt;/code&gt;.
I use these signals, my prior belief &lt;code&gt;\(p_0=\Pr(\mu=H)\)&lt;/code&gt;, and Bayes&amp;rsquo; rule to form a posterior belief
&lt;code&gt;$$p_t\equiv \Pr\left(\mu=H\mid (X_s)_{s&amp;lt;t}\right)$$&lt;/code&gt;
about &lt;code&gt;\(\mu\)&lt;/code&gt; given the sample path observed up to time &lt;code&gt;\(t\)&lt;/code&gt;.
As &lt;a href=&#34;#deriving-the-belief-increments&#34;&gt;shown below&lt;/a&gt;, this posterior belief has increments
&lt;code&gt;$$\der p_t=p_t(1-p_t)\frac{(H-L)}{\sigma}\der Z_t,$$&lt;/code&gt;
where &lt;code&gt;\((Z_t)_{t\ge0}\)&lt;/code&gt; is a Wiener process with respect to my information at time &lt;code&gt;\(t\)&lt;/code&gt;.
Its increments
&lt;code&gt;$$\der Z_t=\frac{1}{\sigma}\left(\der X_t-\hat\mu_t\der t\right)$$&lt;/code&gt;
exceed zero precisely when the corresponding increments &lt;code&gt;\(\der X_t\)&lt;/code&gt; in the sample path exceed my posterior estimates
&lt;code&gt;$$\begin{align} \hat\mu_t &amp;amp;\equiv \E\left[\mu\mid (X_s)_{s&amp;lt;t}\right] \\ &amp;amp;= p_tH+(1-p_t)L. \end{align}$$&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;learning-dynamics&#34;&gt;Learning dynamics&lt;/h2&gt;
&lt;p&gt;My belief increments &lt;code&gt;\(\der p_t\)&lt;/code&gt; get smaller as &lt;code&gt;\(p_t\)&lt;/code&gt; approaches zero or one.
The ratio &lt;code&gt;\((H-L)/\sigma\)&lt;/code&gt; controls how quickly this happens.
Intuitively, if &lt;code&gt;\((H-L)\)&lt;/code&gt; is large then the high and low states are easy to tell apart from the trends in &lt;code&gt;\((X_t)_{t\ge0}\)&lt;/code&gt; they imply.
But if &lt;code&gt;\(\sigma\)&lt;/code&gt; is large then these trends are blurred by the random fluctuations &lt;code&gt;\(\sigma\der W_t\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I illustrate these dynamics in the chart below.
It shows the sample paths &lt;code&gt;\((X_t)_{t\ge0}\)&lt;/code&gt; and corresponding beliefs &lt;code&gt;\((p_t)_{t\ge0}\)&lt;/code&gt; when &lt;code&gt;\((H,L,\mu,p_0)=(1,0,H,0.5)\)&lt;/code&gt; and &lt;code&gt;\(\sigma\in\{1,2\}\)&lt;/code&gt;.
I use the same realization of the underlying Wiener process &lt;code&gt;\((W_t)_{t\ge0}\)&lt;/code&gt; for each value of &lt;code&gt;\(\sigma\)&lt;/code&gt;.
Increasing this value slows my convergence to the correct belief &lt;code&gt;\(p_t=1\)&lt;/code&gt; because it makes the signals &lt;code&gt;\(\der X_t\)&lt;/code&gt; less informative about &lt;code&gt;\(\mu=H\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;deriving-the-belief-increments&#34;&gt;Deriving the belief increments&lt;/h2&gt;
&lt;p&gt;The increments &lt;code&gt;\(\der W_t\)&lt;/code&gt; of the Wiener process &lt;code&gt;\((W_t)_{t\ge0}\)&lt;/code&gt; are iid normally distributed with mean zero and variance &lt;code&gt;\(\der t\)&lt;/code&gt;:
&lt;code&gt;$$\der W_t\sim N(0,\der t).$$&lt;/code&gt;
Thus, given &lt;code&gt;\(\mu\)&lt;/code&gt;, the increments &lt;code&gt;\(\der X_t\)&lt;/code&gt; of the sample path &lt;code&gt;\((X_t)_{t\ge0}\)&lt;/code&gt; are iid normal with mean &lt;code&gt;\(\mu\der t\)&lt;/code&gt; and variance &lt;code&gt;\(\sigma^2\der t\)&lt;/code&gt;:
&lt;code&gt;$$\der X_t\mid\mu\sim N(\mu\der t,\sigma^2\der t).$$&lt;/code&gt;
So these increments have conditional PDF
&lt;code&gt;$$\begin{align} f_\mu(\der X_t) &amp;amp;= \frac{1}{\sigma\sqrt{2\pi\der t}}\exp\left(-\frac{(\der X_t-\mu\der t)^2}{2\sigma^2\der t}\right) \\ &amp;amp;= \frac{1}{\sigma\sqrt{2\pi\der t}}\exp\left(-\frac{(\der X_t)^2}{2\sigma^2\der t}\right)\exp\left(\frac{\mu\der X_t}{\sigma^2}-\frac{\mu^2\der t}{2\sigma^2}\right). \end{align}$$&lt;/code&gt;
But the rules of &lt;a href=&#34;https://en.wikipedia.org/wiki/It%C3%B4_calculus&#34;&gt;Itô calculus&lt;/a&gt; imply &lt;code&gt;\((\der X_t)^2=\sigma^2\der t\)&lt;/code&gt; and
&lt;code&gt;$$\begin{align} \exp\left(\frac{\der X_t\mu}{\sigma^2}-\frac{\mu^2\der t}{2\sigma^2}\right) &amp;amp;= \sum_{k\ge0}\frac{1}{k!}\left(\frac{\mu\der X_t}{\sigma^2}-\frac{\mu^2\der t}{2\sigma^2}\right)^k \\ &amp;amp;= 1+\frac{\mu\der X_t}{\sigma^2} \end{align}$$&lt;/code&gt;
because these rules treat terms of order &lt;code&gt;\((\der t)^2\)&lt;/code&gt; or smaller as equal to zero.
Thus
&lt;code&gt;$$f_\mu(\der X_t)=\frac{1}{\sigma^3\sqrt{2\pi\der t}}\exp\left(-\frac{1}{2}\right)\left(\mu\der X_t+\sigma^2\right)$$&lt;/code&gt;
for each &lt;code&gt;\(\mu\in\{H,L\}\)&lt;/code&gt;.
Applying &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayes&amp;rsquo; rule&lt;/a&gt; then gives
&lt;code&gt;$$\begin{align} p_{t+\der t} &amp;amp;= \frac{p_tf_H(\der X_t)}{p_tf_H(\der X_t)+(1-p_t)f_L(\der X_t)} \\ &amp;amp;= \frac{p_t\left(H\der X_t+\sigma^2\right)}{\hat\mu_t\der X_t+\sigma^2}, \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\hat\mu_t=\E[\mu\mid (X_s)_{s&amp;lt;t}]\)&lt;/code&gt; is my posterior estimate of &lt;code&gt;\(\mu\)&lt;/code&gt;.
So the belief process &lt;code&gt;\((p_t)_{t\ge0}\)&lt;/code&gt; has increments
&lt;code&gt;$$\begin{align} \der p_t &amp;amp;\equiv p_{t+\der t}-p_t \\ &amp;amp;= \frac{p_t(1-p_t)(H-L)\der X_t}{\hat\mu_t\der X_t+\sigma^2}. \end{align}$$&lt;/code&gt;
Finally, taking a Maclaurin series expansion and applying the rules of Itô calculus gives
&lt;code&gt;$$\begin{align} \frac{\der X_t}{\hat\mu_t\der X_t+\sigma^2} &amp;amp;= \der X_t\sum_{k\ge0}\frac{(-1)^kk!}{(\sigma^2)^{k+1}}(\der X_t)^k \\ &amp;amp;= \der X_t\left(\frac{1}{\sigma^2}-\frac{1}{\sigma^4}\der X_t\right) \\ &amp;amp;= \frac{1}{\sigma^2}\left(\der X_t-\hat\mu_t\der t\right), \end{align}$$&lt;/code&gt;
from which we obtain the expressions for &lt;code&gt;\(\der p_t\)&lt;/code&gt; and &lt;code&gt;\(\der Z_t\)&lt;/code&gt; provided above.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Paying for precision</title>
      <link>https://bldavies.com/blog/paying-precision/</link>
      <pubDate>Tue, 04 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/paying-precision/</guid>
      <description>&lt;p&gt;Suppose my payoff &lt;code&gt;\(u(a,\mu)\equiv-(a-\mu)^2\)&lt;/code&gt; from taking an action &lt;code&gt;\(a\in\mathbb{R}\)&lt;/code&gt; depends on an unknown state &lt;code&gt;\(\mu\in\mathbb{R}\)&lt;/code&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
I can learn about &lt;code&gt;\(\mu\)&lt;/code&gt; by collecting data &lt;code&gt;\(X=\{x_1,x_2,\ldots,x_n\}\)&lt;/code&gt;, where the observations &lt;code&gt;\(x_i\)&lt;/code&gt; are iid normally distributed with mean &lt;code&gt;\(\mu\)&lt;/code&gt; and variance &lt;code&gt;\(\sigma^2\)&lt;/code&gt;:&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$x_i\mid \mu\sim N(\mu,\sigma^2).$$&lt;/code&gt;
I use these data, my prior belief
&lt;code&gt;$$\mu\sim N(\mu_0,\sigma_0^2),$$&lt;/code&gt;
and Bayes&amp;rsquo; rule to form a posterior belief
&lt;code&gt;$$\mu\mid X\sim N\left(\frac{\tau_0}{\tau_0+n\tau}\mu_0+\frac{n\tau}{\tau_0+n\tau}\bar{x},\frac{1}{\tau_0+n\tau}\right),$$&lt;/code&gt;
where &lt;code&gt;\(\tau_0\equiv1/\sigma_0^2\)&lt;/code&gt; is the precision of my prior, &lt;code&gt;\(\tau\equiv1/\sigma^2\)&lt;/code&gt; is the precision of the &lt;code&gt;\(x_i\)&lt;/code&gt;, and
&lt;code&gt;$$\bar{x}\equiv\frac{1}{n}\sum_{i=1}^nx_i$$&lt;/code&gt;
is their arithmetic mean.
Then my expected payoff from taking action &lt;code&gt;\(a\)&lt;/code&gt; equals
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \E[u(a,\mu)\mid X]=-(a-\E[\mu\mid X])^2-\Var(\mu\mid X).$$&lt;/code&gt;
I maximize this payoff by choosing &lt;code&gt;\(a^*\equiv\E[\mu\mid X]\)&lt;/code&gt;.
This yields expected payoff
&lt;code&gt;$$\E[u(a^*,\mu)\mid X_n]=-\frac{1}{\tau_0+n\tau},$$&lt;/code&gt;
which is increasing in &lt;code&gt;\(n\)&lt;/code&gt;.
Intuitively, collecting more data makes me more informed and makes my optimal action more likely to be &amp;ldquo;correct.&amp;rdquo;
But data are costly: I have to pay &lt;code&gt;\(\kappa n\tau\)&lt;/code&gt; to collect &lt;code&gt;\(n\)&lt;/code&gt; observations, where &lt;code&gt;\(\kappa&amp;gt;0\)&lt;/code&gt; captures the marginal cost of information.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
I choose &lt;code&gt;\(n\)&lt;/code&gt; to maximize my total payoff
&lt;code&gt;$$\begin{align*} U(n) &amp;amp;\equiv \E[u(a^*,\mu)\mid X]-\kappa n\tau, \end{align*}$$&lt;/code&gt;
which has maximizer
&lt;code&gt;$$n^*=\max\left\{0,\frac{1}{\tau}\left(\frac{1}{\sqrt\kappa}-\tau_0\right)\right\}.$$&lt;/code&gt;
If &lt;code&gt;\(1\le\sqrt\kappa\tau_0\)&lt;/code&gt; then &lt;code&gt;\(n^*=0\)&lt;/code&gt; because the cost of collecting &lt;em&gt;any&lt;/em&gt; data isn&amp;rsquo;t worth the variance reduction they deliver.
Whereas if &lt;code&gt;\(1&amp;gt;\sqrt\kappa\tau_0\)&lt;/code&gt; then &lt;code&gt;\(n^*\)&lt;/code&gt; is strictly positive and gives me total payoff
&lt;code&gt;$$U(n^*)=-2\sqrt\kappa+\kappa\tau_0.$$&lt;/code&gt;
Both &lt;code&gt;\(n^*\)&lt;/code&gt; and &lt;code&gt;\(U(n^*)\)&lt;/code&gt; are decreasing in &lt;code&gt;\(\kappa\)&lt;/code&gt;.
Intuitively, making the data more expensive makes me want to collect less, leaving me less informed and worse off.
In contrast, making my prior more precise (i.e., increasing &lt;code&gt;\(\tau_0\)&lt;/code&gt;) makes me want to collect less data but leaves me &lt;em&gt;better&lt;/em&gt; off.
This is because being well-informed means I can pay for less data and still be well-informed.&lt;/p&gt;
&lt;p&gt;Curiously, making the &lt;code&gt;\(x_i\)&lt;/code&gt; more precise (i.e., increasing &lt;code&gt;\(\tau\)&lt;/code&gt;) makes me want to collect more data but does not change my welfare.
This is because the cost &lt;code&gt;\(\kappa\tau\)&lt;/code&gt; of each observation &lt;code&gt;\(x_i\)&lt;/code&gt; scales with its precision.
This cost exactly offsets the value of the information gained, leaving my total payoff &lt;code&gt;\(U(n^*)\)&lt;/code&gt; unchanged.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://bldavies.com/blog/paying-truth/&#34;&gt;here&lt;/a&gt; for my discussion of the case when the state and data are binary. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This is the same as letting &lt;code&gt;\(x_i=\mu+\varepsilon_i\)&lt;/code&gt; with iid errors &lt;code&gt;\(\varepsilon_i\sim N(0,\sigma^2)\)&lt;/code&gt;. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1257/aer.20190185&#34;&gt;Pomatto et al. (2023)&lt;/a&gt; show that this cost function (uniquely) satisfies some attractive properties.
Linear cost functions also appear in many sequential sampling problems (see, e.g., &lt;a href=&#34;https://doi.org/10.1214/aoms/1177731118&#34;&gt;Wald&amp;rsquo;s (1945)&lt;/a&gt; classic model or &lt;a href=&#34;https://dx.doi.org/10.2139/ssrn.2991567&#34;&gt;Morris and Strack&amp;rsquo;s (2019)&lt;/a&gt; discussion of it) and their continuous-time analogues (see, e.g.,  &lt;a href=&#34;https://doi.org/10.1257/aer.20150742&#34;&gt;Fudenberg et al. (2018)&lt;/a&gt; or &lt;a href=&#34;https://doi.org/10.3982/ECTA18324&#34;&gt;Liang et al. (2022)&lt;/a&gt;). &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Binary signals and posterior variances</title>
      <link>https://bldavies.com/blog/binary-signals-posterior-variances/</link>
      <pubDate>Sun, 02 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/binary-signals-posterior-variances/</guid>
      <description>&lt;p&gt;Suppose I receive a &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signal&lt;/a&gt; &lt;code&gt;\(s\in\{0,1\}\)&lt;/code&gt; about an unknown state &lt;code&gt;\(\omega\in\{0,1\}\)&lt;/code&gt;.
The signal has false positive rate
&lt;code&gt;$$\renewcommand{\epsilon}{\varepsilon} \Pr(s=1\mid\omega=0)=\alpha$$&lt;/code&gt;
and false negative rate
&lt;code&gt;$$\Pr(s=0\mid\omega=1)=\beta$$&lt;/code&gt;
with &lt;code&gt;\(\alpha,\beta\in[0,0.5]\)&lt;/code&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
I use these rates, my prior belief &lt;code&gt;\(p=\Pr(\omega=1)\)&lt;/code&gt;, and &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayes&amp;rsquo; rule&lt;/a&gt; to form a posterior belief
&lt;code&gt;$$\begin{align} q_s &amp;amp;\equiv \Pr(\omega=1\mid s) \\ &amp;amp;= \frac{\Pr(s\mid\omega=1)\Pr(\omega=1)}{\Pr(s)} \\ &amp;amp;= \begin{cases} \frac{\beta p}{(1-\alpha)(1-p)+\beta p} &amp;amp; \text{if}\ s=0 \\ \frac{(1-\beta)p}{\alpha(1-p)+(1-\beta)p} &amp;amp; \text{if}\ s=1 \end{cases} \end{align}$$&lt;/code&gt;
that depends on the signal I receive.&lt;/p&gt;
&lt;p&gt;Now suppose I take an action &lt;code&gt;\(a\in[0,1]\)&lt;/code&gt; with cost &lt;code&gt;\(c(a,\omega)\equiv(a-\omega)^2\)&lt;/code&gt;.
I want to minimize my expected cost
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \begin{align} \E[c(a,\omega)\mid s] &amp;amp;= (1-q_s)c(a,0)+q_sc(a,1) \\ &amp;amp;= (1-q_s)a^2+q_s(a-1)^2 \end{align}$$&lt;/code&gt;
given &lt;code&gt;\(s\)&lt;/code&gt;, which leads me to choose &lt;code&gt;\(a=q_s\)&lt;/code&gt;.
Then my minimized expected cost
&lt;code&gt;$$\begin{align} \E[c(q_s,\omega)\mid s] &amp;amp;= q_s(1-q_s) \\ &amp;amp;= p(1-p)\times\begin{cases} \frac{(1-\alpha)\beta}{\left((1-\alpha)(1-p)+\beta p\right)^2} &amp;amp; \text{if}\ s=0 \\ \frac{\alpha(1-\beta)}{\left(\alpha(1-p)+(1-\beta)p\right)^2} &amp;amp; \text{if}\ s=1 \end{cases} \end{align}$$&lt;/code&gt;
equals the posterior variance in my belief about &lt;code&gt;\(\omega\)&lt;/code&gt; after receiving &lt;code&gt;\(s\)&lt;/code&gt;.
The expected value of this variance &lt;em&gt;before&lt;/em&gt; receiving &lt;code&gt;\(s\)&lt;/code&gt; equals
&lt;code&gt;$$\begin{align} V(p,\alpha,\beta) &amp;amp;\equiv q_0(1-q_0)\Pr(s=0)+q_1(1-q_1)\Pr(s=1) \\ &amp;amp;= p(1-p)\times\frac{\alpha(1-\alpha)(1-p)+\beta(1-\beta)p}{\left((1-\alpha)(1-p)+\beta p\right)\left(\alpha(1-p)+(1-\beta)p\right)}, \end{align}$$&lt;/code&gt;
which depends on my prior &lt;code&gt;\(p\)&lt;/code&gt; as well as the error rates &lt;code&gt;\(\alpha\)&lt;/code&gt; and &lt;code&gt;\(\beta\)&lt;/code&gt;.
For example, the chart below plots
&lt;code&gt;$$V(p,\epsilon,\epsilon)=p(1-p)\times\frac{\epsilon(1-\epsilon)}{p(1-p)+\epsilon(1-\epsilon)(1-2p)^2}$$&lt;/code&gt;
against &lt;code&gt;\(\epsilon\)&lt;/code&gt; when &lt;code&gt;\(p\in\{0.5,0.7,0.9\}\)&lt;/code&gt;.
If &lt;code&gt;\(\epsilon=0\)&lt;/code&gt; then the signal is fully informative because it always matches the state &lt;code&gt;\(\omega\)&lt;/code&gt;.
Larger values of &lt;code&gt;\(\epsilon\le0.5\)&lt;/code&gt; lead to less precise posterior beliefs.
Indeed if &lt;code&gt;\(\epsilon=0.5\)&lt;/code&gt; then the signal is uninformative because &lt;code&gt;\(\Pr(s=1)=0.5\)&lt;/code&gt; (and, hence, &lt;code&gt;\(q_0=q_1=p\)&lt;/code&gt;) independently of &lt;code&gt;\(\omega\)&lt;/code&gt;.
The slope &lt;code&gt;\(\partial V(p,\epsilon,\epsilon)/\partial\epsilon\)&lt;/code&gt; falls as my prior &lt;code&gt;\(p\)&lt;/code&gt; moves away from &lt;code&gt;\(0.5\)&lt;/code&gt; because having a more precise prior makes my beliefs less sensitive to the signal.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/convexity-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The next chart shows the contours of &lt;code&gt;\(V(p,\alpha,\beta)\)&lt;/code&gt; in the &lt;code&gt;\(\alpha\beta\)&lt;/code&gt;-plane.
These contours are symmetric across the diagonal line &lt;code&gt;\(\alpha=\beta\)&lt;/code&gt; when my prior &lt;code&gt;\(p\)&lt;/code&gt; equals &lt;code&gt;\(0.5\)&lt;/code&gt; but asymmetric when &lt;code&gt;\(p\not=0.5\)&lt;/code&gt;.
Intuitively, if I have a strong prior that &lt;code&gt;\(\omega=1\)&lt;/code&gt; then positive signals &lt;code&gt;\(s=1\)&lt;/code&gt; are less surprising, and shift my belief less, than negative signals &lt;code&gt;\(s=0\)&lt;/code&gt;.
So if &lt;code&gt;\(p&amp;gt;0.5\)&lt;/code&gt; then I need to increase the false positive rate &lt;code&gt;\(\alpha\)&lt;/code&gt; by more than I decrease the false negative rate &lt;code&gt;\(\beta\)&lt;/code&gt; to keep &lt;code&gt;\(V(p,\alpha,\beta)\)&lt;/code&gt; constant.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/contours-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;One consequence of this asymmetry is that the constrained minimization problem
&lt;code&gt;$$\min_{\alpha,\beta}V(p,\alpha,\beta)\ \text{subject to}\ 0\le\alpha,\beta\le0.5\ \text{and}\ \alpha+\beta\ge B$$&lt;/code&gt;
has a corner solution
&lt;code&gt;$$(\alpha^*,\beta^*)=\begin{cases} (0,B) &amp;amp; \text{if}\ p\le1/2 \\ (B,0) &amp;amp; \text{if}\ p&amp;gt;1/2 \end{cases}$$&lt;/code&gt;
for all lower bounds &lt;code&gt;\(B\in[0,0.5]\)&lt;/code&gt; on the sum of the error rates.
Intuitively, if I can limit my exposure to false positives and negatives then I should prevent whichever occur in the state that&amp;rsquo;s most likely under my prior.
For example, if &lt;code&gt;\(p&amp;gt;0.5\)&lt;/code&gt; then I&amp;rsquo;m best off allowing some false positives but preventing any false negatives.
This makes negative signals fully informative because they only occur when &lt;code&gt;\(\omega=0\)&lt;/code&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;There is no loss in generality from assuming &lt;code&gt;\(\alpha,\beta\le0.5\)&lt;/code&gt; because observing &lt;code&gt;\(s\)&lt;/code&gt; is the same as observing &lt;code&gt;\((1-s)\)&lt;/code&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Comparing equal- and value-weighted portfolios</title>
      <link>https://bldavies.com/blog/comparing-equal-value-weighted-portfolios/</link>
      <pubDate>Mon, 22 May 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/comparing-equal-value-weighted-portfolios/</guid>
      <description>&lt;p&gt;Imagine two portfolios of S&amp;amp;P 500 companies.
One portfolio weights all companies equally; the other weights companies by their market capitalization (hereafter &amp;ldquo;value&amp;rdquo;).
Which portfolio is the better investment?&lt;/p&gt;
&lt;p&gt;One way to answer this question is to look at historical data.
For example, the Center for Research in Security Prices (CRSP) &lt;a href=&#34;https://www.crsp.org/products/documentation/crsp-indexes-sp-500%C2%AE-universe-0&#34;&gt;provides&lt;/a&gt; monthly returns on each portfolio between January 1926 and December 2022.
I summarize these returns in the table below.
They had overall means of 1.13% and 0.94%, standard deviations of 6.72% and 5.42%, and a Pearson correlation of 0.96.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Portfolio&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Mean&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Std. dev.&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Min&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Median&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Max&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Equal-weighted&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.13&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.72&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-31.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.36&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;68.04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Value-weighted&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.94&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5.42&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-28.75&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.30&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;41.43&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Suppose past and future returns have the same distribution.
Then I expect the returns on the equal-weighted portfolio to be larger but riskier.
So my preference over portfolios depends on my risk tolerance.
I demonstrate this dependence in the chart below.
It shows the certainty-equivalent (CE) return on each portfolio for a range of &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_aversion#Relative_risk_aversion&#34;&gt;relative risk aversion&lt;/a&gt; (RRA) coefficients.
The CE return equals the mean return when my RRA coefficient equals zero.
It falls when my RRA coefficient rises because I demand a larger risk premium.
The rate at which the CE return falls depends on portfolio&amp;rsquo;s return distribution.
Based on the distributions summarized above, I prefer the equal-weighted portfolio whenever my RRA coefficient is less than 2.76.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/certainty-equivalents-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Another way to compare the two portfolios is to look at their long-term growth rates.
I do that in the chart below.
It shows the capital gain I would have realized if I bought each portfolio in the past, reinvested my dividends, and sold my holdings at the end of 2022.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
I make these gains comparable across holding periods by presenting them as mean monthly returns.
For example, investing in the equal-weighted portfolio in December 2002 would have led to the same capital gain as investing in an asset that returned 0.90% every month for the next 20 years.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/gains-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;If I invested in either portfolio before September 2010, then I would have earned more on the equal-weighted portfolio.
Its dominance over the value-weighted portfolio peaked in early 2000, when the &lt;a href=&#34;https://en.wikipedia.org/wiki/Dot-com_bubble&#34;&gt;dot-com crash&lt;/a&gt; saw lots of large companies lose lots of value.&lt;/p&gt;
&lt;p&gt;Of course, past and future returns can differ.
The equal-weighted portfolio may have been the better investment 20 years ago but could be a worse investment today.
So what does the theory say?&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1057/s41260-016-0033-4&#34;&gt;Malladi and Fabozzi (2017)&lt;/a&gt; argue that the equal-weighted portfolio offers higher returns because it is regularly &lt;a href=&#34;https://en.wikipedia.org/wiki/Rebalancing_investments&#34;&gt;rebalanced&lt;/a&gt;.
For example, if I start with equal shares in two companies, but one doubles in value and the other halves, then my portfolio will end with a 80/20 split.
So if I want to maintain equal weights then I need to sell companies that grow a lot and buy companies that don&amp;rsquo;t.
This &lt;a href=&#34;https://en.wikipedia.org/wiki/Contrarian_investing&#34;&gt;contrarian&lt;/a&gt; strategy takes advantage of &lt;a href=&#34;https://en.wikipedia.org/wiki/Mean_reversion_(finance)&#34;&gt;mean reversion&lt;/a&gt;.
Indeed &lt;a href=&#34;https://doi.org/10.1007/978-3-030-66691-0_9&#34;&gt;Plyakha et al (2021)&lt;/a&gt; argue that maintaining &lt;em&gt;unequal&lt;/em&gt; weights would also lead to higher mean returns.
These arguments agree with empirical evidence that few, if any, investing strategies consistently outperform weighting stocks equally (e.g., &lt;a href=&#34;https://doi.org/10.1093/rfs/hhm075&#34;&gt;DeMiguel et al, 2009&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1016/j.jbankfin.2018.09.021&#34;&gt;Hsu et al, 2018&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1007/s11156-021-01008-w&#34;&gt;Qin and Singal, 2022&lt;/a&gt;).&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://profiles.stanford.edu/john-shoven&#34;&gt;John Shoven&lt;/a&gt; for inspiring this post.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;For reference, most macro/finance research uses coefficients between one and three. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I focus on investments made before January 2020 to suppress the noise from (i) the COVID-19 pandemic and (ii) having few observations with which to compute means. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Models of the AI apocalypse</title>
      <link>https://bldavies.com/blog/models-ai-apocalypse/</link>
      <pubDate>Mon, 15 May 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/models-ai-apocalypse/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://www.econtalk.org/tyler-cowen-on-the-risks-and-impact-of-artificial-intelligence/&#34;&gt;this week&amp;rsquo;s episode of &lt;em&gt;EconTalk&lt;/em&gt;&lt;/a&gt;, Tyler Cowen asks:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Is there any actual mathematical model of this process of how the world is supposed to end?
&amp;hellip;
If you look, say, at COVID or climate change fears, in both cases, there are many models you can look at.
&amp;hellip;
I&amp;rsquo;m not saying you have to like those models.
But the point is: there&amp;rsquo;s something you look at and then you make up your mind whether or not you like those models; and then they&amp;rsquo;re tested against data.
So, when it comes to AGI and existential risk, it turns out as best I can ascertain, in the 20 years or so we&amp;rsquo;ve been talking about this seriously, there isn&amp;rsquo;t a single model done.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;He goes on:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;I don&amp;rsquo;t think any idea should be dismissed.
I&amp;rsquo;ve just been inviting [AI doomsayers] to actually join the discourse of science.
&amp;lsquo;Show us your models.
Let us see their assumptions and let&amp;rsquo;s talk about those.&amp;rsquo;
The practice, instead, is to write these very long pieces online, which just stack arguments vertically and raise the level of anxiety.
&amp;hellip;
Their mental model is so much: &amp;lsquo;We&amp;rsquo;re the insiders, we&amp;rsquo;re the experts.&amp;rsquo;
&amp;hellip;
My mental model is: There&amp;rsquo;s a thing, science.
Try to publish this stuff in journals.
Try to model it.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&#34;https://bldavies.com/blog/judging-economic-models&#34;&gt;Good models&lt;/a&gt; don&amp;rsquo;t need to be complete descriptions of reality.
But they &lt;em&gt;do&lt;/em&gt; need to be logically consistent.
Their purpose is to make explicit the assumptions and premises underlying our intuitions.
Then we can subject those intuitions to formal scrutiny.&lt;/p&gt;
&lt;p&gt;For example, suppose I think people should do X.
I write down a model of the process by which they decide what to do.
My model comprises a set of assumptions that imply X.
Now I ask:
Are my assumptions reasonable?
Do I believe them?
If not, then either
(i) people shouldn&amp;rsquo;t do X or
(ii) they don&amp;rsquo;t make decisions according to the process I&amp;rsquo;ve written down.
Both cases teach me something: my intuition is wrong!&lt;/p&gt;
&lt;p&gt;Tyler wants AI doomsayers to go on similar intellectual journeys.
He wants to know: exactly what assumptions do they make when they say humanity is doomed?
What are the logical foundations of that claim?
Only by exposing those foundations can we test and revise them.
That&amp;rsquo;s how science works.
We tell each other &lt;em&gt;how&lt;/em&gt; we think so that we can debate &lt;em&gt;what&lt;/em&gt; we think.
Models help us frame the debate.
Sure, &lt;a href=&#34;https://en.wikipedia.org/wiki/All_models_are_wrong&#34;&gt;all models are wrong&lt;/a&gt;.
But you can&amp;rsquo;t beat a model by waffling!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Who reads *Marginal Revolution*?</title>
      <link>https://bldavies.com/blog/who-reads-marginal-revolution/</link>
      <pubDate>Mon, 08 May 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/who-reads-marginal-revolution/</guid>
      <description>&lt;p&gt;Here&amp;rsquo;s a summary of my website&amp;rsquo;s traffic since the start of 2023:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/daily-visitors-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Notice the spike on April 9, when Tyler Cowen &lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2023/04/sunday-assorted-links-413.html&#34;&gt;linked&lt;/a&gt; to &lt;a href=&#34;https://bldavies.com/blog/marginal-revolution-metadata&#34;&gt;my post of &lt;em&gt;Marginal Revolution&lt;/em&gt; metadata&lt;/a&gt;.
That post is now my second most-viewed ever (just behind my post on &lt;a href=&#34;https://bldavies.com/blog/applying-economics-phd-programs&#34;&gt;applying to economics PhD programs&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Where in the world did those views come from?
Here&amp;rsquo;s a summary:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/sources-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Most visitors came from the US.
This makes sense: &lt;em&gt;Marginal Revolution&lt;/em&gt; is run by American authors who tend to focus on American issues.
About a third of my US-based visitors came from California, New York, or Massachusetts.
Bigger states tended to bring more visitors, but the relationship was not perfect.
For example, Californians comprise about 11.7% of the US population but 15.2% of my visitors.
These percentages differ due to selection effects: &lt;em&gt;Marginal Revolution&lt;/em&gt; caters to educated readers who share the authors&amp;rsquo; interests.
Indeed, all my visitors saw the word &amp;ldquo;metadata&amp;rdquo; and thought &amp;ldquo;I want to know more.&amp;rdquo;
I doubt the typical American would react similarly!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Loan repayments</title>
      <link>https://bldavies.com/blog/loan-repayments/</link>
      <pubDate>Tue, 18 Apr 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/loan-repayments/</guid>
      <description>&lt;p&gt;Suppose I take out a loan.
It gains interest at rate &lt;code&gt;\(r\)&lt;/code&gt;, compounded continuously.
I repay the loan by making constant, continuous payments until time &lt;code&gt;\(T\)&lt;/code&gt;.
How does the repaid share of my loan vary over time?
And how does it depend on &lt;code&gt;\(r\)&lt;/code&gt; and &lt;code&gt;\(T\)&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(P_0\)&lt;/code&gt; be the initial value of my loan: the &amp;ldquo;principal.&amp;rdquo;
Then my continuous payments &lt;code&gt;\(C\)&lt;/code&gt; must satisfy
&lt;code&gt;$$\begin{align} P_0 &amp;amp;= \int_0^TCe^{-r\tau}\,\mathrm{d}\tau \\ &amp;amp;= \frac{C}{r}\left(1-e^{-rT}\right) \end{align}$$&lt;/code&gt;
and so the value of my remaining payments at time &lt;code&gt;\(t\in[0,T]\)&lt;/code&gt; equals
&lt;code&gt;$$\begin{align} P_t &amp;amp;\equiv \int_t^TCe^{-r(\tau-t)}\,\mathrm{d}\tau \\ &amp;amp;= \frac{C}{r}\left(1-e^{-r(T-t)}\right) \\ &amp;amp;= P_0\left(\frac{e^{-rt}-e^{-rT}}{1-e^{-rT}}\right)e^{rt}. \end{align}$$&lt;/code&gt;
If I don&amp;rsquo;t make any payments before time &lt;code&gt;\(t\)&lt;/code&gt; then the principal grows to &lt;code&gt;\(P_0e^{rt}\)&lt;/code&gt;.
Therefore, the value of my repayments up to time &lt;code&gt;\(t\)&lt;/code&gt; equals the difference &lt;code&gt;\((P_0e^{rt}-P_t)\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now let &lt;code&gt;\(x\equiv t/T\in[0,1]\)&lt;/code&gt; be share of payments I&amp;rsquo;ve made up to time &lt;code&gt;\(t\)&lt;/code&gt;.
The chart below plots the corresponding share
&lt;code&gt;$$\frac{P_0e^{rt}-P_t}{P_0e^{rt}}\bigg\rvert_{t=xT}=\frac{1-e^{-xrT}}{1-e^{-rT}}$$&lt;/code&gt;
of the loan that I&amp;rsquo;ve repaid.
This share grows with &lt;code&gt;\(x\)&lt;/code&gt; at a decreasing rate.
Intuitively, my repayment &amp;ldquo;slows down&amp;rdquo; because the interest on the principal and payments grows larger than the payments themselves.
This slowing effect is stronger when the interest rate &lt;code&gt;\(r\)&lt;/code&gt; is larger and time horizon &lt;code&gt;\(T\)&lt;/code&gt; is longer.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>*Marginal Revolution* metadata</title>
      <link>https://bldavies.com/blog/marginal-revolution-metadata/</link>
      <pubDate>Fri, 07 Apr 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/marginal-revolution-metadata/</guid>
      <description>&lt;p&gt;Today I released the R package &lt;a href=&#34;https://github.com/bldavies/MRposts&#34;&gt;MRposts&lt;/a&gt;.
It contains data on &lt;a href=&#34;https://marginalrevolution.com&#34;&gt;&lt;em&gt;Marginal Revolution&lt;/em&gt;&lt;/a&gt; blog posts: their &lt;a href=&#34;#authors&#34;&gt;authors&lt;/a&gt;, &lt;a href=&#34;#titles&#34;&gt;titles&lt;/a&gt;, &lt;a href=&#34;#publication-times&#34;&gt;publication times&lt;/a&gt;, &lt;a href=&#34;#categories&#34;&gt;categories&lt;/a&gt;, and &lt;a href=&#34;#comments&#34;&gt;comment counts&lt;/a&gt;.
I describe these data below.
They cover all 34,189 posts published between August 2003 and March 2023.&lt;/p&gt;
&lt;h2 id=&#34;authors&#34;&gt;Authors&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Marginal Revolution&lt;/em&gt; is run by &lt;a href=&#34;https://en.wikipedia.org/wiki/Tyler_Cowen&#34;&gt;Tyler Cowen&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Alex_Tabarrok&#34;&gt;Alex Tabarrok&lt;/a&gt;.
They wrote 86% and 13% of the posts in MRposts.
The rest were written by several guest bloggers.
I count posts by author in the table below.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Author&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Posts&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Tyler Cowen&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29,373&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Alex Tabarrok&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4,564&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Fabio Rojas&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;63&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Justin Wolfers&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Steven Landsburg&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Robin Hanson&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Tim Harford&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Craig Newmark&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Ed Lopez&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Bryan Caplan&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Eric Helland&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Angus Grier&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;12 others, each with fewer than ten posts&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Tyler wrote &lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2003/08/the_lunar_men&#34;&gt;the first &lt;em&gt;Marginal Revolution&lt;/em&gt; post&lt;/a&gt; on August 21, 2003, and posted every day thereafter.
His monthly output grew during the late 2000s and early 2010s.
Alex&amp;rsquo;s monthly output was lower but relatively constant:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/monthly-output-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;titles&#34;&gt;Titles&lt;/h2&gt;
&lt;p&gt;My next chart compares the words used in Tyler and Alex&amp;rsquo;s posts&amp;rsquo; titles.
Their posts often contained &amp;ldquo;assorted links&amp;rdquo; or &amp;ldquo;facts of the day,&amp;rdquo; or explained how there are &amp;ldquo;markets in everything.&amp;rdquo;
Tyler also had many posts on &amp;ldquo;sentences to ponder&amp;rdquo; and &amp;ldquo;what [he&amp;rsquo;d] been reading.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/titular-words-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The longest title contained 21 words (&amp;ldquo;The Icelandic Stock Exchange fell by 76% in early trading as it re-opened after closing for two days last week.&amp;quot;).
Tyler&amp;rsquo;s titles had a median of five words while Alex&amp;rsquo;s had a median of four.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h2 id=&#34;publication-times&#34;&gt;Publication times&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Marginal Revolution&lt;/em&gt; posts tended to appear in early mornings and afternoons.
Tyler posted at all hours of the day, albeit seldom at night.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
Alex&amp;rsquo;s posting schedule was more regular.
His posts usually appeared between 7am and 9am:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/publication-times-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;categories&#34;&gt;Categories&lt;/h2&gt;
&lt;p&gt;MRposts matches posts with their &lt;a href=&#34;https://marginalrevolution.com/categories&#34;&gt;categories&lt;/a&gt;.
The most common categories were Economics (12,757 posts), Current Affairs (5,648 posts), and Law (3,706 posts).
About 52% of posts had two or more categories, while 16% had none.&lt;/p&gt;
&lt;p&gt;The following chart compares the categories of Tyler and Alex&amp;rsquo;s posts.
I count posts &amp;ldquo;fractionally&amp;rdquo; so that, e.g., posts with two categories contribute half a post to each category.
Tyler wrote proportionally more non-Economics posts than Alex.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/categories-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;p&gt;The median post in MRposts had 26 comments.
Tyler&amp;rsquo;s median post had 27 comments while Alex&amp;rsquo;s had 25.
About 11% of posts had more than 100 comments, while 26% had fewer than ten and 11% had none.
I list the most-commented-on posts in the table below.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Post&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Year&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Comments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2008/08/sarah-palin&#34;&gt;Sarah Palin&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2008&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;947&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2015/10/the-case-for-getting-rid-of-borders-completely&#34;&gt;The Case for Getting Rid of Borders-Completely&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2015&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;711&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2022/06/if-you-wish-to-debate-scotus-on-roe-v-wade&#34;&gt;If you wish to debate SCOTUS on Roe v. Wade&amp;hellip;&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2022&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;577&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2022/10/classical-liberalism-vs-the-new-right&#34;&gt;Classical liberalism vs. The New Right&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2022&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;567&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2016/05/what-in-the-hell-is-going-on&#34;&gt;What the hell is going on?&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2016&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;562&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2016/11/upward-mobility-discrimination-asians-african-americans&#34;&gt;Upward Mobility and Discrimination: Asians and African Americans&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2016&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;548&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2022/12/cwt-bleg&#34;&gt;CWT bleg&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2022&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;534&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2014/08/ferguson-and-the-debtors-prison&#34;&gt;Ferguson and the Modern Debtor&amp;rsquo;s Prison&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2014&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;525&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2016/11/trump-winning-rises-falls-status&#34;&gt;Trump winning: who rises and falls in status?&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2016&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;520&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://marginalrevolution.com/marginalrevolution/2016/06/what-is-neo-reaction&#34;&gt;What is neo-reaction?&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2016&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;519&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Three of the ten most-commented-on posts were published in the last year.
Indeed, the mean number of comments per post grew over time:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/comments-growth-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Post engagement grew slowly during the late 2010s.
It increased sharply in early 2011, when Tyler was &lt;a href=&#34;https://www.economist.com/free-exchange/2011/02/01/economics-most-influential-people&#34;&gt;listed among the most influential economists&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;content&#34;&gt;Content&lt;/h2&gt;
&lt;p&gt;I could update MRposts to include data on posts&amp;rsquo; content.
This would allow users to mine the text of Tyler and Alex&amp;rsquo;s posts.
For example, many commenters have decried Tyler&amp;rsquo;s recent focus on ChatGPT and other large language models.
I document that focus in the chart below.
It shows the share of Tyler&amp;rsquo;s posts containing the string &amp;ldquo;chat&amp;rdquo;, &amp;ldquo;GPT&amp;rdquo;, &amp;ldquo;LLM&amp;rdquo;, or &amp;ldquo;language model&amp;rdquo; in each of the past 24 months.
The majority of those posts contained none of those strings!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/focus-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Mark Nagelberg &lt;a href=&#34;https://www.marknagelberg.com/lets-scrape-a-blog-part-1/&#34;&gt;compares&lt;/a&gt; the mean lengths of all authors&amp;rsquo; titles. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Hamilton Noel &lt;a href=&#34;https://hamiltonnoel.substack.com/p/does-tyler-cowen-sleep&#34;&gt;looks closer&lt;/a&gt; at Tyler&amp;rsquo;s blogging habits. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Five years of blogging</title>
      <link>https://bldavies.com/blog/five-years-blogging/</link>
      <pubDate>Wed, 01 Mar 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/five-years-blogging/</guid>
      <description>&lt;p&gt;Today marks five years since &lt;a href=&#34;https://bldavies.com/blog/habitat-choices-first-generation-pokemon/&#34;&gt;my first blog post&lt;/a&gt;.
This post is my 100th.
It summarizes the &lt;a href=&#34;#words-used&#34;&gt;words I&amp;rsquo;ve used&lt;/a&gt; and &lt;a href=&#34;#traffic&#34;&gt;traffic I&amp;rsquo;ve received&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;words-used&#34;&gt;Words used&lt;/h2&gt;
&lt;p&gt;My first 99 posts contained more than 56 thousand words:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/growth-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I wrote 11 posts in March and April 2020, when the pandemic forced me to &amp;ldquo;work&amp;rdquo; from home.
I&amp;rsquo;ve written 56 posts&amp;mdash;about once every 16 days&amp;mdash;since &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;starting my PhD&lt;/a&gt; in September 2020.&lt;/p&gt;
&lt;p&gt;My &lt;a href=&#34;https://bldavies.com/blog/applying-economics-phd-programs&#34;&gt;longest post&lt;/a&gt; had 2,128 words and my &lt;a href=&#34;https://bldavies.com/blog/transitivity-positive-correlations&#34;&gt;shortest&lt;/a&gt; had 123.
The most common (non-&lt;a href=&#34;https://en.wikipedia.org/wiki/Stop_word&#34;&gt;stop&lt;/a&gt;) word was &amp;ldquo;network,&amp;rdquo; used 269 times across 34 distinct posts.
The chart below shows the six most common words overall and among posts on my most common topics.
It includes &amp;ldquo;datum&amp;rdquo; rather than &amp;ldquo;data&amp;rdquo; because I &lt;a href=&#34;https://en.wikipedia.org/wiki/Lemmatisation&#34;&gt;lemmatize&lt;/a&gt; words before counting them.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/common-words-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;So far I&amp;rsquo;ve written 34 posts on &lt;a href=&#34;https://bldavies.com/topics/economics&#34;&gt;economics&lt;/a&gt; and 31 on &lt;a href=&#34;https://bldavies.com/topics/networks&#34;&gt;networks&lt;/a&gt;.
Most posts had multiple topics.
The most commonly paired topics were networks and &lt;a href=&#34;https://bldavies.com/topics/research&#34;&gt;research&lt;/a&gt; (eight posts), research and &lt;a href=&#34;https://bldavies.com/topics/software&#34;&gt;software&lt;/a&gt; (six posts), and networks and &lt;a href=&#34;https://bldavies.com/topics/statistics&#34;&gt;statistics&lt;/a&gt; (six posts).&lt;/p&gt;
&lt;h2 id=&#34;traffic&#34;&gt;Traffic&lt;/h2&gt;
&lt;p&gt;Since March 2020 I&amp;rsquo;ve used &lt;a href=&#34;https://www.goatcounter.com&#34;&gt;GoatCounter&lt;/a&gt; to count page views and visitors.
I had lots in late 2022, when I shared my &lt;a href=&#34;https://bldavies.com/blog/reflections-grad-school-years-1-2&#34;&gt;reflections on graduate school&lt;/a&gt; and people started &lt;a href=&#34;https://bldavies.com/blog/applying-economics-phd-programs&#34;&gt;applying to economics PhD programs&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/goatcounts-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;My most popular three posts benefit from being in the top few Google search results.
They account for about half of my (non-bot) page views:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Post&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Views&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/applying-economics-phd-programs&#34;&gt;Applying to economics PhD programs&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4,174&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/accessing-strava-api&#34;&gt;Accessing the Strava API with R&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,831&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/greedy-pig-strategies&#34;&gt;Greedy Pig strategies&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,189&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/reflections-grad-school-years-1-2&#34;&gt;Reflections on grad school: Years 1 and 2&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;411&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/stanford&#34;&gt;Stanford&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;387&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/degroot-learning-social-networks&#34;&gt;DeGroot learning in social networks&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;341&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/ordinary-total-least-squares&#34;&gt;Ordinary and total least squares&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;336&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/female-representation-collaboration-nber&#34;&gt;Female representation and collaboration at the NBER&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;318&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/living-america&#34;&gt;What&amp;rsquo;s it like living in America?&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;296&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;&lt;a href=&#34;https://bldavies.com/blog/how-central-grand-central-terminal&#34;&gt;How central is Grand Central Terminal?&lt;/a&gt;&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;280&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Other&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4,747&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Total&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14,310&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Most of my visitors were from the USA (usually California or Massachusetts):&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Country&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Visitors&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;United States&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6,216&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;United Kingdom&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;770&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Australia&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;642&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;New Zealand&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;561&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;India&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;294&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Other/unknown&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3,856&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Total&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12,339&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description>
    </item>
    
    <item>
      <title>Selection bias and fixed effects</title>
      <link>https://bldavies.com/blog/selection-bias-fixed-effects/</link>
      <pubDate>Wed, 25 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/selection-bias-fixed-effects/</guid>
      <description>&lt;p&gt;Economists often use &lt;a href=&#34;https://en.wikipedia.org/wiki/Fixed_effects_model&#34;&gt;fixed effects&lt;/a&gt; to correct for &lt;a href=&#34;https://bldavies.com/blog/understanding-selection-bias&#34;&gt;selection bias&lt;/a&gt;.
Intuitively, these effects &amp;ldquo;partial out&amp;rdquo; the reasons why our data include some observations but not others.
But this intuition relies on the selection criteria being linear functions of the dependent variable.&lt;/p&gt;
&lt;p&gt;For example, suppose I have panel data on 100 individuals &lt;code&gt;\(i\)&lt;/code&gt; at ten dates &lt;code&gt;\(t\)&lt;/code&gt;.
These data include pairs &lt;code&gt;\((y_{it},x_{it})\)&lt;/code&gt; generated by the process
&lt;code&gt;$$y_{it}=x_{it}+u_i+\epsilon_{it},$$&lt;/code&gt;
where &lt;code&gt;\(u_i\)&lt;/code&gt; is a fixed effect and &lt;code&gt;\(\epsilon_{it}\)&lt;/code&gt; is an error term.
The &lt;code&gt;\(x_{it}\)&lt;/code&gt;, &lt;code&gt;\(u_i\)&lt;/code&gt;, and &lt;code&gt;\(\epsilon_{it}\)&lt;/code&gt; are iid normal with zero mean and unit variance.
They all vary across individuals.
The &lt;code&gt;\(x_{it}\)&lt;/code&gt; and &lt;code&gt;\(\epsilon_{it}\)&lt;/code&gt; also vary over time, but the &lt;code&gt;\(u_i\)&lt;/code&gt; do not.&lt;/p&gt;
&lt;p&gt;The chart below plots &lt;code&gt;\(y_{it}\)&lt;/code&gt; against &lt;code&gt;\(x_{it}\)&lt;/code&gt; overall and within two subsets of my data:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Observations for the 50 individuals &lt;code&gt;\(i\)&lt;/code&gt; whose outcomes &lt;code&gt;\(y_{it}\)&lt;/code&gt; have the largest mean;&lt;/li&gt;
&lt;li&gt;Observations for the 50 individuals &lt;code&gt;\(i\)&lt;/code&gt; whose &lt;em&gt;squared&lt;/em&gt; outcomes &lt;code&gt;\(y_{it}^2\)&lt;/code&gt; have the largest mean.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It also shows the OLS regression line fitted to my data and its subsets.
The intercept and slope of this line depend on the selection criterion.
Individuals with larger mean outcomes tend to have larger fixed effects and narrower error distributions.
This leads OLS to estimate a higher intercept but shallower slope than in the full data.
In contrast, individuals with larger mean squared outcomes have similar fixed effects to other individuals but wider error distributions.
This leads OLS to estimate the same intercept but steeper slope than in the full data.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/binscatter-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;What if I include fixed effects in my regression?
The box plots below summarize the slopes I estimate when I simulate my data 100 times and apply my selection criteria.
Including fixed effects removes the bias from selecting on mean outcomes.
This is because the fixed effects &lt;em&gt;are&lt;/em&gt; the variables I select on.
Partialing them out removes the selection bias by definition.
In contrast, including fixed effects does not remove the bias from selecting on mean squared outcomes.
This is because the fixed effects are uncorrelated with the variables I select on.
Partialing them out removes noise but not bias.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/boxplot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learning and persuasion</title>
      <link>https://bldavies.com/blog/learning-persuasion/</link>
      <pubDate>Sun, 08 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-persuasion/</guid>
      <description>&lt;p&gt;People talk for many reasons.
One is to learn: to collect information that helps us make better choices.
Another is to &lt;a href=&#34;https://bldavies.com/blog/persuading-anecdotes&#34;&gt;persuade&lt;/a&gt;: to convince others to make choices we think are best.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1016/j.geb.2021.01.001&#34;&gt;Meng (2021)&lt;/a&gt; shows how wanting to learn and persuade can lead to &lt;a href=&#34;https://en.wikipedia.org/wiki/Homophily&#34;&gt;homophily&lt;/a&gt;.
He presents a model in which people choose conversation partners before taking actions.
Everyone wants these actions to match an unknown binary state.
But people have different prior beliefs about the state.
They update their beliefs after receiving (i) a &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signal&lt;/a&gt; from nature and (ii) a message from their partner.
Priors are public, signals are private, and messages are &lt;a href=&#34;https://doi.org/10.1257/aer.101.6.2590&#34;&gt;designed to be persuasive&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Meng studies the &lt;a href=&#34;https://bldavies.com/blog/stable-matchings/&#34;&gt;matchings&lt;/a&gt; that arise in this setting.
A matching is &amp;ldquo;stable&amp;rdquo; if it has no &amp;ldquo;blocking pairs:&amp;rdquo; people who want to be partners but aren&amp;rsquo;t.
It is &amp;ldquo;&lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortative&lt;/a&gt;&amp;rdquo; if all partners are &amp;ldquo;like-minded:&amp;rdquo; their priors are both close to zero or both close to one.&lt;/p&gt;
&lt;p&gt;Every assortative matching is stable.
To see why, suppose Alice and Bob are not like-minded.
Alice will only partner with Bob if it&amp;rsquo;s easier to persuade him than be persuaded by him.
But Bob will only partner with Alice if it&amp;rsquo;s easier to persuade her than be persuaded by her.
These two conditions can&amp;rsquo;t hold at the same time, so Alice and Bob can&amp;rsquo;t form a blocking pair.&lt;/p&gt;
&lt;p&gt;Likewise, in Meng&amp;rsquo;s model, every stable matching is assortative.
This is especially true if people care more about learning than persuading.
Like-minded partners send truthful messages because they don&amp;rsquo;t need to persuade each other.
But non-like-minded partners send distorted messages hoping to persuade each other.
These distortions make at least one person worse off than they would be if they had a like-minded partner who told them the truth.&lt;/p&gt;
&lt;p&gt;Meng then considers a social planner who can choose matchings but not messages.
This planner wants to maximize the sum of everyone&amp;rsquo;s expected payoffs under their priors.
They choose an assortative matching only when the distribution of priors is symmetric.
Otherwise, they choose a matching in which people with extreme priors have non-like-minded partners with moderate priors.
This is because extremists gain more than moderates lose.
It suggests that sorting is socially bad.&lt;/p&gt;
&lt;p&gt;Finally, Meng extends his model to allow stable matchings that are &lt;em&gt;not&lt;/em&gt; assortative.
This can happen when signals or actions are not binary.
He leaves open the extension to settings in which people have more than one partner.
&lt;a href=&#34;https://bldavies.com/blog/echo-chambers-useful/&#34;&gt;Jann and Schottmüller (2021)&lt;/a&gt; consider a version of that setting.
But they reach a different normative conclusion than Meng: sorting can be good because it stops people from sending distorted messages.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Protecting Planet Xiddler</title>
      <link>https://bldavies.com/blog/protecting-planet-xiddler/</link>
      <pubDate>Sat, 07 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/protecting-planet-xiddler/</guid>
      <description>&lt;p&gt;This week&amp;rsquo;s &lt;a href=&#34;https://fivethirtyeight.com/features/can-you-fend-off-the-alien-armada/&#34;&gt;Riddler Classic&lt;/a&gt; asks us to fend off an alien invasion:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The astronomers of Planet Xiddler are back in action!
Unfortunately, this time they have used their telescopes to spot an armada of hostile alien warships on a direct course for Xiddler.
The armada will be arriving in exactly 100 days.
(Recall that, like Earth, there are 24 hours in a Xiddler day.)&lt;/p&gt;
&lt;p&gt;Fortunately, Xiddler&amp;rsquo;s engineers have just completed construction of the planet&amp;rsquo;s first assembler, which is capable of producing any object.
An assembler can be used to build a space fighter to defend the planet, which takes one hour to produce.
An assembler can also be used to build another assembler (which, in turn, can build other space fighters or assemblers).
However, building an assembler is more time-consuming, requiring six whole days.
Also, you cannot use multiple assemblers to build one space fighter or assembler in a shorter period of time.&lt;/p&gt;
&lt;p&gt;What is the greatest number of space fighters the Xiddlerian fleet can have when the alien armada arrives?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can solve this problem via &lt;a href=&#34;https://en.wikipedia.org/wiki/Dynamic_programming&#34;&gt;dynamic programming&lt;/a&gt;.
First, let &lt;code&gt;\(N(t)\)&lt;/code&gt; be the maximum number of fighters an assembler can make in &lt;code&gt;\(t\)&lt;/code&gt; days.
The aliens invade in 100 days, so our goal is to compute &lt;code&gt;\(N(100)\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An assembler can either&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;spend a day building fighters, or&lt;/li&gt;
&lt;li&gt;spend six days duplicating itself.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first option gives us 24 fighters plus however many an assembler can make in &lt;code&gt;\((t-1)\)&lt;/code&gt; days.
The second option gives us however many &lt;em&gt;two&lt;/em&gt; assemblers can make in &lt;code&gt;\((t-6)\)&lt;/code&gt; days.
Thus &lt;code&gt;\(N(t)\)&lt;/code&gt; satisfies the &lt;a href=&#34;https://en.wikipedia.org/wiki/Bellman_equation&#34;&gt;Bellman equation&lt;/a&gt;
&lt;code&gt;$$N(t)=\max\{24+N(t-1),2N(t-6)\},$$&lt;/code&gt;
where &lt;code&gt;\(N(t)=0\)&lt;/code&gt; for all &lt;code&gt;\(t\le0\)&lt;/code&gt;.
Solving this equation recursively gives
&lt;code&gt;$$N(100)=7,\!864,\!320.$$&lt;/code&gt;
The chart below shows how &lt;code&gt;\(N(t)\)&lt;/code&gt; grows with &lt;code&gt;\(t\)&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/growth-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Fighter production begins with a 90-day &amp;ldquo;duplicate&amp;rdquo; phase in which the number of assemblers doubles 15 times: once every six days.
This gives us
&lt;code&gt;$$2^{15}=32,\!768$$&lt;/code&gt;
assemblers to use during a 10-day &amp;ldquo;build&amp;rdquo; phase in which each builds 24 fighters per day, giving us
&lt;code&gt;$$2^{15}\times10\times24=7,\!864,\!320$$&lt;/code&gt;
fighters in total.&lt;/p&gt;
&lt;p&gt;The length of the build phase depends on how quickly an assembler can build fighters or duplicate itself.
For example, if it takes only three days to duplicate then the build phase lasts only four days.
This is because the opportunity cost of duplicating (not building now) falls relative to the benefit of duplicating (building twice as fast later).
The opposite is true if it takes more than six days to duplicate or if assemblers can build more than 24 fighters per day.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learning from opinions</title>
      <link>https://bldavies.com/blog/learning-opinions/</link>
      <pubDate>Fri, 06 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-opinions/</guid>
      <description>&lt;p&gt;We often use others&amp;rsquo; opinions to guide our choices.
For example, we use movie and Yelp reviews to decide what to watch and where to eat.
But opinions can be hard to interpret because they depend on objective facts (e.g., movie/food quality) and subjective perspectives (e.g., reviewers&amp;rsquo; tastes).
So, when seeking opinions, we face a trade-off between&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;well-informed&amp;rdquo; sources who know a lot and&lt;/li&gt;
&lt;li&gt;&amp;ldquo;well-understood&amp;rdquo; sources with known perspectives.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.3982/ECTA13320&#34;&gt;Sethi and Yildiz (2016)&lt;/a&gt; study this trade-off and its consequences.
They consider a group of people who receive &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signals&lt;/a&gt; about a sequence of states.
These people form posterior beliefs (&amp;ldquo;opinions&amp;rdquo;) about each state based on their signal precisions (&amp;ldquo;expertise&amp;rdquo;) and prior beliefs (&amp;ldquo;perspectives&amp;rdquo;).
Expertise is public, and varies across people and states.
Perspectives are private, and vary across people but not states.
Everyone observes their own opinion and the opinion of a chosen &amp;ldquo;target.&amp;rdquo;
They always choose the target whose opinion reveals the most information about the current state.&lt;/p&gt;
&lt;p&gt;Initially, no-one knows anyone else&amp;rsquo;s perspective, so everyone chooses the target with the most expertise (i.e., the most precise signal).
But people learn others&amp;rsquo; perspectives over time by comparing the signals they receive to the opinions they observe.
Eventually, everyone attaches to a set of &amp;ldquo;long-run experts&amp;rdquo; and never considers opinions outside that set, even if those opinions are better informed.&lt;/p&gt;
&lt;p&gt;This set of long-run experts can vary across people.
To see why, suppose Alice and Bob observe Charlie&amp;rsquo;s opinion about a given state.
Alice and Charlie receive precise signals about that state, but Bob doesn&amp;rsquo;t.
Alice knows that her opinion can only differ from Charlie&amp;rsquo;s if they have different perspectives.
In contrast, Bob can&amp;rsquo;t tell if his opinion differs from Charlie&amp;rsquo;s because they have different perspectives or because Bob&amp;rsquo;s signal is imprecise.
So Alice learns more about Charlie&amp;rsquo;s perspective than Bob does.
She&amp;rsquo;s more likely to include Charlie in her set of long-run experts.&lt;/p&gt;
&lt;p&gt;Sethi and Yildiz&amp;rsquo;s model explains why people gravitate to like-minded opinion sources.
We learn more about the perspectives of people who know about the same things, making us more likely to attach to them.
This contrasts with the &lt;a href=&#34;https://bldavies.com/blog/ideological-bias-trust-information-sources/&#34;&gt;trust&lt;/a&gt;- and &lt;a href=&#34;https://bldavies.com/blog/persuading-anecdotes/&#34;&gt;persuasion&lt;/a&gt;-based explanations discussed in previous posts.
It leads people to ask experts for opinions on topics beyond their expertise.
It may also lead people to &lt;a href=&#34;https://bldavies.com/blog/truth-seekers-ideologues/&#34;&gt;befriend fellow ideologues&lt;/a&gt; who see the world the same (possibly incorrect) way.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>stravadata demo</title>
      <link>https://bldavies.com/blog/stravadata-demo/</link>
      <pubDate>Sun, 01 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/stravadata-demo/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/bldavies/stravadata&#34;&gt;stravadata&lt;/a&gt; is an R package I use to organize and analyze my &lt;a href=&#34;https://www.strava.com/&#34;&gt;Strava&lt;/a&gt; activity data.
This post offers some example analyses:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#computing-annual-totals&#34;&gt;Computing annual totals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#making-activity-heat-maps&#34;&gt;Making activity heat maps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#counting-efforts&#34;&gt;Counting efforts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#making-training-calendars&#34;&gt;Making training calendars&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#tracking-personal-records&#34;&gt;Tracking personal records&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My examples use data on my running activities from the last five years:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lubridate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;stravadata&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;activities&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Run&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;start_time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
         &lt;span class=&#34;n&#34;&gt;date&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;start_time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%in%&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2018&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2022&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;computing-annual-totals&#34;&gt;Computing annual totals&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;runs&lt;/code&gt; contains activity-level features like distance traveled and time spent moving.
I sum these features by year, then use &lt;code&gt;knitr::kable&lt;/code&gt; to display these sums in a table:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;knitr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;summarise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Runs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt;
            &lt;span class=&#34;nf&#34;&gt;`Distance &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;km&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;` = sum(distance) / 1e3,
&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;            `&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Time &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hours&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;time_moving&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3600&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate_at&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;round&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;big.mark&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;kable&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;align&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;crrr&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Year&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Runs&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Distance (km)&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Time (hours)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2018&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;68&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;544&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;52&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2019&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;152&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,085&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;92&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2020&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;224&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2,026&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;172&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2021&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;207&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2,149&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;173&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2022&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;145&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,517&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;120&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;making-activity-heat-maps&#34;&gt;Making activity heat maps&lt;/h2&gt;
&lt;p&gt;I record my runs with a watch that tracks my GPS coordinates.
stravadata stores these coordinates in &lt;code&gt;streams&lt;/code&gt;.
For example, here&amp;rsquo;s the course for last year&amp;rsquo;s &lt;a href=&#34;https://www.paloaltoonline.com/moonlight_run/&#34;&gt;Moonlight Run&lt;/a&gt; in Palo Alto:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ggplot2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Moonlight Run&amp;#39;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2022&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;left_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;streams&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;plot_nicely&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Add text and formatting&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/moonlight-run-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Combining the GPS coordinates from many runs yields a local map.
For example, suppose I want to map my runs near &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;Stanford&lt;/a&gt;.
I first make a table of GPS paths near a local landmark:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;coords&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;-122.16&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;37.44&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Trader Joe&amp;#39;s&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;tol&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.08&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;stanford_paths&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;streams&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;semi_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;step&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;row_number&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;sqrt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;coords[1]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;^&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;coords[2]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;^&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tol&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove pauses&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new_path&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;row_number&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;step&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new_path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I increment &lt;code&gt;path&lt;/code&gt; every time I start a new run, unpause a previous run, or re-enter the area defined by &lt;code&gt;coords&lt;/code&gt; and &lt;code&gt;tol&lt;/code&gt;.
I use &lt;code&gt;path&lt;/code&gt; as a grouping variable so that &lt;code&gt;ggplot2::ggplot&lt;/code&gt; knows to draw each path separately.
I then use the &lt;code&gt;alpha&lt;/code&gt; argument of &lt;code&gt;ggplot2::geom_path&lt;/code&gt; to create a &amp;ldquo;heat map&amp;rdquo; of paths I run most often:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stanford_paths&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;plot_nicely&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/stanford-1.jpeg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;counting-efforts&#34;&gt;Counting efforts&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;best_efforts&lt;/code&gt; stores my fastest times running a range of distances (that Strava calls &amp;ldquo;efforts&amp;rdquo;) within each activity:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;best_efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 6 × 4
##           id effort   start_index end_index
##        &amp;lt;dbl&amp;gt; &amp;lt;chr&amp;gt;          &amp;lt;int&amp;gt;     &amp;lt;int&amp;gt;
## 1 1253004287 1 mile            15       447
## 2 1253004287 1/2 mile          11       232
## 3 1253004287 1k                12       284
## 4 1253004287 2 mile            11       876
## 5 1253004287 400m              11       120
## 6 1253004287 5k                11      1342
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;id&lt;/code&gt; column stores activity IDs and the &lt;code&gt;effort&lt;/code&gt; column stores effort descriptions.
I focus on 5k, 10k, and half marathon efforts:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;focal_efforts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;5k&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;10k&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Half-Marathon&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;efforts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;left_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;best_efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%in%&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;focal_efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;factor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;focal_efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;start_index&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;end_index&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;efforts&lt;/code&gt; inherits the &lt;code&gt;year&lt;/code&gt; variable from &lt;code&gt;runs&lt;/code&gt;.
I use this variable to count efforts within each year.
I then use &lt;code&gt;tidyr::spread&lt;/code&gt; and &lt;code&gt;knitr::kable&lt;/code&gt; to display these counts in a table:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;efforts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;spread&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;fill&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;kable&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;align&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Year&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;5k&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;10k&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Half-Marathon&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2018&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;64&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;24&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2019&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;136&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;34&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2020&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;191&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2021&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;200&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;90&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2022&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;131&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;85&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;making-training-calendars&#34;&gt;Making training calendars&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;efforts&lt;/code&gt; also inherits the &lt;code&gt;date&lt;/code&gt; variable from &lt;code&gt;runs&lt;/code&gt;.
I use this variable to create &lt;a href=&#34;https://github.blog/2013-01-07-introducing-contributions/#contributions-calendar&#34;&gt;GitHub-esque&lt;/a&gt; training calendars.
For example, here&amp;rsquo;s my running calendar for 2021:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;efforts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2021&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;slice_max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;distinct&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# I ran twice on some days&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Week&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;floor_date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;weeks&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;week_start&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
         &lt;span class=&#34;n&#34;&gt;Weekday&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;wday&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;label&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;week_start&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Week&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Weekday&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_tile&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;col&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;white&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;linewidth&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;plot_nicely&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/calendar-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I use &lt;code&gt;lubridate::floor_date&lt;/code&gt; to identify weeks and &lt;code&gt;lubridate::wday&lt;/code&gt; to identify weekdays.
The &lt;code&gt;col&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt; arguments of &lt;code&gt;ggplot2::geom_tile&lt;/code&gt; add space between tiles.&lt;/p&gt;
&lt;h2 id=&#34;tracking-personal-records&#34;&gt;Tracking personal records&lt;/h2&gt;
&lt;p&gt;I combine &lt;code&gt;runs&lt;/code&gt;, &lt;code&gt;streams&lt;/code&gt;, and &lt;code&gt;efforts&lt;/code&gt; to track my record running paces over time.
I follow a three-step process:&lt;/p&gt;
&lt;p&gt;First, I compute the mean pace for each effort.
I do this using the &lt;code&gt;start_index&lt;/code&gt; and &lt;code&gt;end_index&lt;/code&gt; columns that &lt;code&gt;efforts&lt;/code&gt; inherits from &lt;code&gt;best_efforts&lt;/code&gt;.
These columns tell me where each effort occurs in the corresponding activity&amp;rsquo;s stream:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;effort_paces&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;streams&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%in%&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runs&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Create indices&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;index&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;row_number&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Extract stream segment for each effort&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;inner_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;index&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;start_index&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;index&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;end_index&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Compute mean paces&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;summarise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;distance&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;distance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;min&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;distance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;time&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;min&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;time&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;60&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;distance&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1e3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort_paces&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 6 × 6
##           id date       effort distance  time  pace
##        &amp;lt;dbl&amp;gt; &amp;lt;date&amp;gt;     &amp;lt;fct&amp;gt;     &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1 1335437333 2018-01-01 5k        5002.  1442  4.81
## 2 1338123783 2018-01-03 5k        5000.  1605  5.35
## 3 1344338907 2018-01-07 5k        5000.  1455  4.85
## 4 1347622521 2018-01-09 5k        5000   1493  4.98
## 5 1353889714 2018-01-13 5k        5001.  1622  5.41
## 6 1353889714 2018-01-13 10k      10001.  3380  5.63
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The values in the &lt;code&gt;distance&lt;/code&gt; column differ slightly from the descriptions in the &lt;code&gt;effort&lt;/code&gt; column.
This is because the stream segment doesn&amp;rsquo;t always cover the described distance exactly.
But the multiplicative errors in &lt;code&gt;distance&lt;/code&gt; and &lt;code&gt;time&lt;/code&gt; should be equal on average, making &lt;code&gt;pace&lt;/code&gt; is an unbiased estimate of my true mean pace.
I measure this pace in minutes per kilometer.&lt;/p&gt;
&lt;p&gt;Next, I extract my record paces by deleting efforts slower than my previous best:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;record_paces&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort_paces&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;arrange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cummin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, I &amp;ldquo;fill in the gaps&amp;rdquo; by adding days on which I &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; set a new record.
I do this using &lt;code&gt;tidyr::crossing&lt;/code&gt; and &lt;code&gt;tidyr::fill&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;date_range&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;seq&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;2018-01-01&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;2022-12-31&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;day&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;record_paces_filled&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;crossing&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;date_range&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;focal_efforts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;left_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;record_paces&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;fill&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;record_paces&lt;/code&gt; and &lt;code&gt;record_paces_filled&lt;/code&gt; differ in that the latter includes date-effort pairs with no new records.
This makes &lt;code&gt;record_paces_filled&lt;/code&gt; produce horizontal lines when I plot its data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;record_paces_filled&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;effort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_line&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;plot_nicely&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/record-paces-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Social networks in rural India</title>
      <link>https://bldavies.com/blog/social-networks-rural-india/</link>
      <pubDate>Sat, 24 Dec 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/social-networks-rural-india/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/bldavies/IndianVillages&#34;&gt;IndianVillages&lt;/a&gt; is a new R package containing data on social networks in rural India.
I derived these data from &lt;a href=&#34;https://doi.org/10.1126/science.1236498&#34;&gt;Banerjee et al.&amp;lsquo;s (2013)&lt;/a&gt; surveys of households across 75 &lt;a href=&#34;https://en.wikipedia.org/wiki/Karnataka&#34;&gt;Karnatakan&lt;/a&gt; villages.
This post describes the derived data and the networks they define.
I also show that the networks are &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortatively mixed&lt;/a&gt; with respect to &lt;a href=&#34;https://en.wikipedia.org/wiki/Caste_system_in_India&#34;&gt;caste&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;data-description&#34;&gt;Data description&lt;/h2&gt;
&lt;p&gt;IndianVillages provides two tables.
The first, &lt;code&gt;households&lt;/code&gt;, links each household to its village and caste:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;IndianVillages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;households&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 6 × 3
##    hhid village caste
##   &amp;lt;dbl&amp;gt;   &amp;lt;dbl&amp;gt; &amp;lt;chr&amp;gt;
## 1  1001       1 &amp;lt;NA&amp;gt; 
## 2  1002       1 &amp;lt;NA&amp;gt; 
## 3  1003       1 &amp;lt;NA&amp;gt; 
## 4  1004       1 &amp;lt;NA&amp;gt; 
## 5  1005       1 &amp;lt;NA&amp;gt; 
## 6  1006       1 &amp;lt;NA&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;hhid&lt;/code&gt; and &lt;code&gt;village&lt;/code&gt; columns store household and village IDs.
The &lt;code&gt;caste&lt;/code&gt; column stores caste memberships:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;households&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;caste&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 6 × 2
##   caste               n
##   &amp;lt;chr&amp;gt;           &amp;lt;int&amp;gt;
## 1 OBC              5517
## 2 &amp;lt;NA&amp;gt;             4455
## 3 Scheduled Caste  2584
## 4 General          1371
## 5 Scheduled Tribe   618
## 6 Minority          359
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Some &lt;code&gt;caste&lt;/code&gt; values are missing because the surveys were changed during their collection.
About 53% of the households with known castes are in the &lt;a href=&#34;https://en.wikipedia.org/wiki/Other_Backward_Class&#34;&gt;Other Backward Class&lt;/a&gt; (&amp;ldquo;OBC&amp;rdquo;).
This exceeds the (disputed) share of OBCs in India&amp;rsquo;s general population during the survey period.&lt;/p&gt;
&lt;p&gt;The second table, &lt;code&gt;household_relationships&lt;/code&gt;, contains information on inter-household relationships:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;household_relationships&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 6 × 4
##   hhid.x hhid.y village type                        
##    &amp;lt;dbl&amp;gt;  &amp;lt;dbl&amp;gt;   &amp;lt;dbl&amp;gt; &amp;lt;fct&amp;gt;                       
## 1   1001   1002       1 Help with a decision        
## 2   1001   1002       1 Borrow kerosene or rice from
## 3   1001   1002       1 Lend kerosene or rice to    
## 4   1001   1002       1 Are related to              
## 5   1001   1002       1 Invite to one&#39;s home        
## 6   1001   1002       1 Visit in another&#39;s home
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;hhid.x&lt;/code&gt; and &lt;code&gt;hhid.y&lt;/code&gt; columns store ego and alter household IDs.
The &lt;code&gt;type&lt;/code&gt; column stores relationship types:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;household_relationships&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 12 × 2
##    type                             n
##    &amp;lt;fct&amp;gt;                        &amp;lt;int&amp;gt;
##  1 Visit in another&#39;s home      33629
##  2 Invite to one&#39;s home         32652
##  3 Engage socially with         30939
##  4 Borrow money from            25514
##  5 Lend kerosene or rice to     23993
##  6 Borrow kerosene or rice from 23743
##  7 Lend money to                23558
##  8 Obtain medical advice from   22310
##  9 Help with a decision         17228
## 10 Are related to               16037
## 11 Give advice to               15613
## 12 Go to temple with             2700
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These types correspond to questions asked in Banerjee et al.&amp;lsquo;s surveys.&lt;/p&gt;
&lt;h2 id=&#34;inter-household-networks&#34;&gt;Inter-household networks&lt;/h2&gt;
&lt;p&gt;We can use &lt;code&gt;households&lt;/code&gt; and &lt;code&gt;household_relationships&lt;/code&gt; to define social networks among the households in each village.
First, use the &lt;code&gt;graph_from_data_frame&lt;/code&gt; function from &lt;a href=&#34;https://igraph.org/&#34;&gt;igraph&lt;/a&gt; to create the network among all households:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph_from_data_frame&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;distinct&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;household_relationships&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;hhid.x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;hhid.y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;directed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;vertices&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;households&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;net&lt;/code&gt; contains 66,862 edges: one for each pair of households with at least one social relationship.
There are no between-village relationships in the data, so we can partition &lt;code&gt;net&lt;/code&gt; into village-specific networks without deleting any edges:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;purrr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;villages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sort&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;unique&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;households&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;village&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;village_nets&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;map&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;villages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;subgraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;V&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;village&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;sum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;map_dbl&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;village_nets&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Same as gsize(net)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 66862
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The networks in &lt;code&gt;village_nets&lt;/code&gt; are too large to describe visually.
Instead, let&amp;rsquo;s compute some of their properties:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;village_nets_properties&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;map_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;village_nets&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;comp&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;components&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;giant&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;subgraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;comp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;membership&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;which.max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;comp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;csize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;Households&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;`Mean degree`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;degree&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;`% of households in giant`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;100&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;giant&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.)&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;`Mean distance in giant`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean_distance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;giant&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I summarize these properties in the table below.
The number of households in each village ranges from 77 to 356.
The mean degree of the households in each village ranges from 6.11 to 13.44.
Most households are in the giant component for their village, and are connected to others in that component via paths of length two or three.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Property&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Mean&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Std. dev.&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Min.&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Median&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Max.&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Households&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;198.72&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;59.29&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;77.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;190.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;356.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mean degree&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8.90&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.61&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.11&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8.72&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13.44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;% of households in giant&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;95.10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.71&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;84.62&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;95.54&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;99.42&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mean distance in giant&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.75&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.21&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.30&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.72&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.32&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;inter-caste-mixing&#34;&gt;Inter-caste mixing&lt;/h2&gt;
&lt;p&gt;We can use &lt;code&gt;net&lt;/code&gt; to study the extent of &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortative mixing&lt;/a&gt; with respect to caste membership.
First, delete the 4,455 households with missing &lt;code&gt;caste&lt;/code&gt; values:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;subnet&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;subgraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;V&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;caste&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;subnet&lt;/code&gt; contains 10,449 households with a mean degree of 9.08.
This is similar to the mean degree in &lt;code&gt;net&lt;/code&gt;.
The two networks also have similar mean distances between connected households: 2.85 in &lt;code&gt;subnet&lt;/code&gt;, versus 2.81 in &lt;code&gt;net&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Next, compute &lt;code&gt;subnet&lt;/code&gt;&#39;s mixing matrix:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bldr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# https://github.com/bldavies/bldr&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_mixing_matrix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subnet&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;caste&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I define &lt;code&gt;get_mixing_matrix&lt;/code&gt; &lt;a href=&#34;https://github.com/bldavies/bldr/blob/master/R/get_mixing_matrix.R&#34;&gt;here&lt;/a&gt;.
It returns a matrix in which rows and columns correspond to castes, and entries equal the share of edges joining households in each caste pair.
Multiplying these entries by the sum of degrees&amp;mdash;which, by the &lt;a href=&#34;https://en.wikipedia.org/wiki/Handshaking_lemma&#34;&gt;degree sum formula&lt;/a&gt;, equals twice the number of edges&amp;mdash;yields a table of inter-caste edge counts:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subnet&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##             
##              General Minority   OBC Sch. Caste Sch. Tribe
##   General       8680       79  3118        932        521
##   Minority        79     1860   381        156         84
##   OBC           3118      381 40058       4325       2241
##   Sch. Caste     932      156  4325      16074        910
##   Sch. Tribe     521       84  2241        910       2722
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example, &lt;code&gt;subnet&lt;/code&gt; contains 3,118 edges between households in general castes and households in OBC castes.&lt;/p&gt;
&lt;p&gt;We can measure the extent of assortative mixing by comparing &lt;code&gt;mix_mat&lt;/code&gt; to the matrix we&amp;rsquo;d expect if edges were independent of caste.
This matrix equals the outer product of the row and column sums of &lt;code&gt;mix_mat&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;mix_mat_indep&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rowSums&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%*%&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;colSums&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Comparing the traces of &lt;code&gt;mix_mat&lt;/code&gt; and &lt;code&gt;mix_mat_indep&lt;/code&gt; allows us to measure mixing overall:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;tr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;diag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;tr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mix_mat_indep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 0.7313254 0.3598672
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So &lt;code&gt;subnet&lt;/code&gt; contains about twice as many within-caste edges than we&amp;rsquo;d expect if edges were independent of caste.&lt;/p&gt;
&lt;p&gt;We can also compare &lt;code&gt;mix_mat&lt;/code&gt; and &lt;code&gt;mix_mat_indep&lt;/code&gt; element-wise to assess which inter-caste relationships are most over-represented:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;round&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mix_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mix_mat_indep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##             
##              General Minority   OBC Sch. Caste Sch. Tribe
##   General       4.64     0.22  0.44       0.30       0.57
##   Minority      0.22    26.93  0.28       0.26       0.48
##   OBC           0.44     0.28  1.51       0.37       0.65
##   Sch. Caste    0.30     0.26  0.37       3.04       0.60
##   Sch. Tribe    0.57     0.48  0.65       0.60       6.15
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So, for example, there are about 51% more OBC-OBC edges than we&amp;rsquo;d expect if edges were independent of caste, but less than half as many general-OBC edges.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Optimal pacing with random energy costs</title>
      <link>https://bldavies.com/blog/optimal-pacing-random-energy-costs/</link>
      <pubDate>Mon, 12 Dec 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/optimal-pacing-random-energy-costs/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-varying-energy-costs/&#34;&gt;My previous post&lt;/a&gt; discussed how I should pace myself in a running race.
I allowed the cost of running fast to vary during the race, and I showed how the costs I faced determined my optimal speeds and finish time.
I assumed that I knew the costs in advance&amp;mdash;for example, that I knew which parts of the race had the steepest hills and the strongest headwinds.&lt;/p&gt;
&lt;p&gt;But sometimes I &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; know the costs of running fast in advance.
For example, I might not know the terrain or how the weather will turn out.
This uncertainty prevents me from committing to a pacing strategy before the race begins.
Instead, I must adapt my strategy to the costs I encounter during the race.&lt;/p&gt;
&lt;p&gt;This post discusses my optimal pacing strategy when I face random energy costs.
I assume these costs follow a &lt;a href=&#34;https://en.wikipedia.org/wiki/Markov_chain&#34;&gt;Markov chain&lt;/a&gt;.
This allows me to &lt;a href=&#34;#solving-the-problem&#34;&gt;solve&lt;/a&gt; for my optimal speeds and finish times numerically.
I show that my &lt;a href=&#34;#ex-ante-expected-times&#34;&gt;&lt;em&gt;ex ante&lt;/em&gt; expected time&lt;/a&gt; falls when my costs become more variable and less persistent.
I also show that my &lt;a href=&#34;#realized-times&#34;&gt;realized time&lt;/a&gt; depends on the number and timing of high cost realizations.&lt;/p&gt;
&lt;h2 id=&#34;allowing-for-random-costs&#34;&gt;Allowing for random costs&lt;/h2&gt;
&lt;p&gt;The setup is similar to &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-varying-energy-costs/&#34;&gt;my previous post&lt;/a&gt;:
I have &lt;code&gt;\(k&amp;gt;0\)&lt;/code&gt; units of energy to allocate across &lt;code&gt;\(N\)&lt;/code&gt; laps &lt;code&gt;\(n\in\{1,2,\ldots,N\}\)&lt;/code&gt;.
It costs &lt;code&gt;\(c_ns_n\)&lt;/code&gt; units to run at speed &lt;code&gt;\(s_n\)&lt;/code&gt; in lap &lt;code&gt;\(n\)&lt;/code&gt;, where the per-unit cost &lt;code&gt;\(c_n&amp;gt;0\)&lt;/code&gt; varies with &lt;code&gt;\(n\)&lt;/code&gt;.
I want to minimize my total time
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \renewcommand{\epsilon}{\varepsilon} T\equiv\sum_{n=1}^N\frac{1}{s_n}$$&lt;/code&gt;
subject to the dynamic energy constraint
&lt;code&gt;$$k_{n+1}=k_n-c_ns_n,$$&lt;/code&gt;
boundary conditions &lt;code&gt;\(k_1=k\)&lt;/code&gt; and &lt;code&gt;\(k_{N+1}=0\)&lt;/code&gt;, and non-negativity constraint &lt;code&gt;\(s_n\ge0\)&lt;/code&gt;.
But now the costs &lt;code&gt;\(c_n\)&lt;/code&gt; are random.
So I can&amp;rsquo;t choose the entire speed sequence &lt;code&gt;\((s_n)_{n=1}^N\)&lt;/code&gt; before the race begins.
Instead, I choose each term &lt;code&gt;\(s_n\)&lt;/code&gt; after observing the cost history &lt;code&gt;\(c_1,c_2,\ldots,c_n\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For simplicity, I assume &lt;code&gt;\(c_n\in\{1-\epsilon,1+\epsilon\}\)&lt;/code&gt; for some &lt;code&gt;\(\epsilon\in[0,1)\)&lt;/code&gt;, and that &lt;code&gt;\(\Pr(c_1=1+\epsilon)=0.5\)&lt;/code&gt; and &lt;code&gt;\(\Pr(c_{n+1}=c_n)=p\)&lt;/code&gt; for each &lt;code&gt;\(n\)&lt;/code&gt;.
The probability &lt;code&gt;\(p\)&lt;/code&gt; controls costs&amp;rsquo; persistence: if &lt;code&gt;\(p=1\)&lt;/code&gt; then they never change, whereas if &lt;code&gt;\(p=0\)&lt;/code&gt; then they change every lap.
The cost in lap &lt;code&gt;\(n+1\le N\)&lt;/code&gt; has conditional mean
&lt;code&gt;$$\begin{align} \E_n[c_{n+1}] &amp;amp;\equiv \E[c_{n+1}\mid c_1,c_2,\ldots,c_n] \\ &amp;amp;= \begin{cases} 1+(2p-1)\epsilon &amp;amp; \text{if}\ c_n=1+\epsilon \\ 1-(2p-1)\epsilon &amp;amp; \text{if}\ c_n=1-\epsilon \end{cases} \end{align}$$&lt;/code&gt;
and variance
&lt;code&gt;$$\begin{align} \Var_n(c_{n+1}) &amp;amp;= \E_n[c_{n+1}^2]-\E_n[c_{n+1}]^2 \\ &amp;amp;= 4p(1-p)\epsilon^2, \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\E_n\)&lt;/code&gt; takes expectations given the first &lt;code&gt;\(n\)&lt;/code&gt; cost realizations, and where &lt;code&gt;\(\epsilon\)&lt;/code&gt; controls the variance of &lt;code&gt;\(c_{n+1}\)&lt;/code&gt;.
For example, if &lt;code&gt;\(p=0.5\)&lt;/code&gt; then costs are independent across laps, and so &lt;code&gt;\(\E_n[c_{n+1}]=1\)&lt;/code&gt; and &lt;code&gt;\(\Var_n(c_{n+1})=\epsilon^2\)&lt;/code&gt; for each &lt;code&gt;\(n\)&lt;/code&gt;.
But as &lt;code&gt;\(p\)&lt;/code&gt; moves away from 0.5, knowing the cost history &lt;code&gt;\(c_1,c_2,\ldots,c_n\)&lt;/code&gt; gives me more information about &lt;code&gt;\(c_{n+1}\)&lt;/code&gt;, thereby decreasing &lt;code&gt;\(\Var_n(c_{n+1})\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;solving-the-problem&#34;&gt;Solving the problem&lt;/h2&gt;
&lt;p&gt;Facing random costs forces me to solve my pacing problem sequentially: to choose each speed &lt;code&gt;\(s_n\)&lt;/code&gt; based on the observed cost history &lt;code&gt;\(c_1,c_2,\ldots,c_n\)&lt;/code&gt; and distribution of future costs &lt;code&gt;\(c_{n+1},c_{n+2},\ldots,c_N\)&lt;/code&gt;.
This is equivalent to choosing the amount of energy &lt;code&gt;\(k_{n+1}\)&lt;/code&gt; to carry into the next lap.
I make this choice via the &lt;a href=&#34;https://en.wikipedia.org/wiki/Bellman_equation&#34;&gt;Bellman equation&lt;/a&gt;
&lt;code&gt;$$V_n=\min_{k_{n+1}}\left\{\frac{c_n}{k_n-k_{n+1}}+\E_n[V_{n+1}]\right\},$$&lt;/code&gt;
where
&lt;code&gt;$$V_n\equiv\sum_{m=n}^N\frac{1}{s_m}$$&lt;/code&gt;
is the time taken to run laps &lt;code&gt;\(n\)&lt;/code&gt; through &lt;code&gt;\(N\)&lt;/code&gt;.
It turns out that
&lt;code&gt;$$V_n=\frac{a_n}{k_n}$$&lt;/code&gt;
for each &lt;code&gt;\(n\in\{1,2,\ldots,N+1\}\)&lt;/code&gt;, where the coefficients &lt;code&gt;\(a_1,a_2,\ldots,a_{N+1}\)&lt;/code&gt; are defined recursively by
&lt;code&gt;$$\begin{align} a_{N+1} &amp;amp;= 0 \\ a_n &amp;amp;= \left(\sqrt{c_n}+\sqrt{\E_n[a_{n+1}]}\right)^2. \end{align}$$&lt;/code&gt;
If the costs &lt;code&gt;\(c_n\)&lt;/code&gt; are non-random then the coefficients &lt;code&gt;\(a_n\)&lt;/code&gt; are also non-random, and we obtain the solution described in &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-varying-energy-costs/&#34;&gt;my previous post&lt;/a&gt;.
But if the costs are random then so are the &lt;code&gt;\(a_n\)&lt;/code&gt;, and calculating them involves a case-wise analysis that grows exponentially with &lt;code&gt;\(N\)&lt;/code&gt;.
Instead, I proceed numerically: by computing &lt;code&gt;\(a_n\)&lt;/code&gt; in each cost state &lt;code&gt;\(c_n\)&lt;/code&gt; given the implied distribution of future states.
This is possible because the cost sequence is a Markov chain, which means that &lt;code&gt;\(c_n\)&lt;/code&gt; is a &lt;a href=&#34;https://en.wikipedia.org/wiki/Sufficient_statistic&#34;&gt;sufficient statistic&lt;/a&gt; for the future costs &lt;code&gt;\(c_{n+1},c_{n+2},\ldots,c_N\)&lt;/code&gt;.
I use this property to compute the optimal speeds
&lt;code&gt;$$s_n=\frac{k_n}{c_n+\sqrt{c_n\E_n[a_{n+1}]}}$$&lt;/code&gt;
and finish time &lt;code&gt;\(T\)&lt;/code&gt; associated with each cost sequence realization.&lt;/p&gt;
&lt;h2 id=&#34;ex-ante-expected-times&#34;&gt;&lt;em&gt;Ex ante&lt;/em&gt; expected times&lt;/h2&gt;
&lt;p&gt;Consider the case with full cost persistence: &lt;code&gt;\(p=1\)&lt;/code&gt;.
Then &lt;code&gt;\(c_n=c_1\)&lt;/code&gt; for each &lt;code&gt;\(n\)&lt;/code&gt;, from which it follows that &lt;code&gt;\(T=N^2c_1/k\)&lt;/code&gt;.
But &lt;code&gt;\(c_1\)&lt;/code&gt; has mean &lt;code&gt;\(\E[c_1]=1\)&lt;/code&gt;, so my &lt;em&gt;ex ante&lt;/em&gt; expected time with &lt;code&gt;\(p=1\)&lt;/code&gt; equals
&lt;code&gt;$$\E[T\mid p=1]=\frac{N^2}{k}.$$&lt;/code&gt;
This is the finish time I expect if I know costs are constant but don&amp;rsquo;t know if they&amp;rsquo;re high or low.
Conversely, if I know costs always alternate (i.e., that &lt;code&gt;\(p=0\)&lt;/code&gt;), then my &lt;em&gt;ex ante&lt;/em&gt; expected time equals
&lt;code&gt;$$\E[T\mid p=0]=\frac{N^2\E[\sqrt{c_1}]^2}{k}+\begin{cases} 0 &amp;amp; \text{if}\ N\ \text{is even} \\ \Var(\sqrt{c_1})/k &amp;amp; \text{if}\ N\ \text{is odd}. \end{cases}$$&lt;/code&gt;
The additional &lt;code&gt;\(\Var(\sqrt{c_1})\)&lt;/code&gt; term when &lt;code&gt;\(N\)&lt;/code&gt; is odd comes from the cost sequence being imbalanced: it has &lt;code&gt;\((N-1)/2+1\)&lt;/code&gt; copies of &lt;code&gt;\(c_1\)&lt;/code&gt; but only &lt;code&gt;\((N-1)/2\)&lt;/code&gt; copies of the other cost value.
This imbalance becomes inconsequential as &lt;code&gt;\(N\)&lt;/code&gt; becomes large.
Thus
&lt;code&gt;$$\begin{align} \E[T\mid p=1]-\E[T\mid p=0] &amp;amp;\approx \frac{N^2}{k}\left(1-\E[\sqrt{c_1}]^2\right) \\ &amp;amp;= \frac{N^2}{2k}\left(1-\sqrt{1-\epsilon^2}\right), \end{align}$$&lt;/code&gt;
which grows with &lt;code&gt;\(\epsilon\)&lt;/code&gt;.
We can understand this growth via the following chart.
It shows how my expected time increases from &lt;code&gt;\(\E[T\mid p=0]\)&lt;/code&gt; to &lt;code&gt;\(\E[T\mid p=1]\)&lt;/code&gt; as &lt;code&gt;\(p\)&lt;/code&gt; increases from zero to one.
Intuitively, if &lt;code&gt;\(p\)&lt;/code&gt; is large then I could face persistently high costs that slow me down.
But if &lt;code&gt;\(p\)&lt;/code&gt; is small then high costs are likely to be &amp;ldquo;cancelled out&amp;rdquo; by low costs, improving my optimal time.
The benefit of this canceling grows as the difference &lt;code&gt;\(2\epsilon\)&lt;/code&gt; between high and low costs grows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/expected-times-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;realized-times&#34;&gt;Realized times&lt;/h2&gt;
&lt;p&gt;The relationship between my actual and expected times depends on the realized cost sequence.
I demonstrate this dependence in the table below.
It shows the mean (standard deviation) of my actual and expected times across 100 simulated 100-lap races with 25, 50, and 75 high-cost laps.
It also shows the &amp;ldquo;oracle&amp;rdquo; time I would obtain if I knew the cost sequence in advance.
This time depends only on the number of high-cost laps, whereas my actual time depends on both the number and order of such laps.
Likewise, my expected time depends only on my parameter choices: &lt;code&gt;\(N=100\)&lt;/code&gt;, &lt;code&gt;\(k=100\)&lt;/code&gt;, &lt;code&gt;\(\epsilon=0.5\)&lt;/code&gt;, and &lt;code&gt;\(p=0.5\)&lt;/code&gt;.
These parameters are constant across simulated races, so my expected time is also constant.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;High-cost laps&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Actual time&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Expected time&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Oracle time&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;71.38 (0.37)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.65&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;69.98&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;50&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.50 (0.14)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.65&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;75&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;122.00 (0.58)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.65&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;119.98&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I finish faster than expected when I face 25 high-cost laps, which is unexpectedly few.
Whereas I finish slower than expected when I face 75 high-cost laps, which is unexpectedly many.
I always finish slower than the oracle time because I have to optimize my speeds sequentially, whereas the oracle has the option to optimize them all at once.&lt;/p&gt;
&lt;p&gt;The difference between my actual and oracle times depends on the order in which I encounter high- and low-cost laps.
For example, consider the following four orderings:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;50 high-cost laps followed by 50 low-cost laps;&lt;/li&gt;
&lt;li&gt;50 low-cost laps followed by 50 high-cost laps;&lt;/li&gt;
&lt;li&gt;25 low-cost laps followed by 25 high-cost laps, repeated twice;&lt;/li&gt;
&lt;li&gt;10 low-cost laps followed by 10 high-cost laps, repeated five times.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I assume the same parameters &lt;code&gt;\((N,k,\epsilon,p)\)&lt;/code&gt; as in the simulations above, so my &lt;em&gt;ex ante&lt;/em&gt; expected time equals 93.65 in all four orderings.
Likewise, my oracle time equals 93.30 in all orderings because they all contain 50 high-cost laps and 50 low-cost laps.
This oracle time comes from choosing speeds before each race begins, whereas my actual time comes from choosing speeds when I start each lap.
I compare these choices in the chart below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/realized-times-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Consider the first ordering, with 50 high-cost laps followed by 50 low-cost laps.
I start at about the same speed as the oracle.
But I slow down in laps two through 50 to preserve my energy, which is unexpectedly expensive.
I speed up in lap 51 when energy becomes cheap, then keep speeding up as energy keeps being unexpectedly cheap.
I sprint the last few laps to use the excess energy I saved from running slow earlier.
Whereas the oracle never has excess energy: it always uses the optimal amount, maintaining a constant speed in each block of constant-cost laps.
This makes the oracle time 3.6% faster than my actual time.&lt;/p&gt;
&lt;p&gt;Now consider the second ordering, with 50 low-cost laps followed by 50 high-cost laps.
Again, I start at about the same speed as the oracle.
But now I &lt;em&gt;speed up&lt;/em&gt; in laps two through 50 because energy is unexpectedly &lt;em&gt;cheap&lt;/em&gt;.
I slow down in lap 51 when energy becomes expensive, then keep slowing down as energy keeps being unexpectedly expensive.
I &lt;a href=&#34;https://en.wikipedia.org/wiki/Hitting_the_wall&#34;&gt;bonk&lt;/a&gt; in the last few laps, having used too much energy by running too fast in the first half.
Whereas the oracle never bonks.
It finishes 4.3% faster than me.&lt;/p&gt;
&lt;p&gt;Having shorter blocks of constant-cost laps narrows the gap between my actual and oracle times.
This is because short blocks prevent me from straying too far from the oracle&amp;rsquo;s energy consumption path.
Intuitively, the more frequently I encounter different costs, the more these costs meet my expectations, and so the less I respond to costs being unexpectedly expensive or cheap.
Indeed, my actual time approaches the oracle time as the blocks of constant-cost laps approach one-lap lengths.
This echoes &lt;a href=&#34;#ex-ante-expected-times&#34;&gt;my earlier discussion&lt;/a&gt; of &lt;em&gt;ex ante&lt;/em&gt; expected times: I finish faster when costs are less persistent.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Optimal pacing with varying energy costs</title>
      <link>https://bldavies.com/blog/optimal-pacing-varying-energy-costs/</link>
      <pubDate>Sun, 11 Dec 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/optimal-pacing-varying-energy-costs/</guid>
      <description>&lt;p&gt;Suppose I&amp;rsquo;m running a race.
I have a fixed amount of energy to &amp;ldquo;spend&amp;rdquo; on running fast.
But the energy cost of running fast varies during the race (e.g., it&amp;rsquo;s high on hills and low on flats).
How should I pace myself to minimize my race time?&lt;/p&gt;
&lt;p&gt;This post discusses my optimal pacing problem.
I describe it mathematically, derive its solution in &lt;a href=&#34;#solving-the-two-lap-case&#34;&gt;simple&lt;/a&gt; and &lt;a href=&#34;#solving-the-general-case&#34;&gt;general&lt;/a&gt; settings, and analyze these solutions&amp;rsquo; &lt;a href=&#34;#solution-properties&#34;&gt;properties&lt;/a&gt;.
I assume energy costs are deterministic, whereas &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-random-energy-costs/&#34;&gt;my next post&lt;/a&gt; allows them to be random.&lt;/p&gt;
&lt;h2 id=&#34;the-optimal-pacing-problem&#34;&gt;The optimal pacing problem&lt;/h2&gt;
&lt;p&gt;My race consists of &lt;code&gt;\(N\)&lt;/code&gt; &amp;ldquo;laps&amp;rdquo; &lt;code&gt;\(n\in\{1,2,\ldots,N\}\)&lt;/code&gt; with equal lengths.
I start with &lt;code&gt;\(k_1=k&amp;gt;0\)&lt;/code&gt; units of energy and finish the race with none.
Running lap &lt;code&gt;\(n\)&lt;/code&gt; at speed &lt;code&gt;\(s_n\)&lt;/code&gt; costs &lt;code&gt;\(c_ns_n\)&lt;/code&gt; units of energy, where &lt;code&gt;\(c_n&amp;gt;0\)&lt;/code&gt; varies with &lt;code&gt;\(n\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My goal is to find the speed sequence &lt;code&gt;\((s_n)_{n=1}^N\)&lt;/code&gt; that minimizes my total time&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \newcommand{\der}{\mathrm{d}} \newcommand{\parfrac}[2]{\frac{\partial #1}{\partial #2}} T\equiv\sum_{n=1}^N\frac{1}{s_n}$$&lt;/code&gt;
subject to the dynamic energy constraint
&lt;code&gt;$$k_{n+1}=k_n-c_ns_n,$$&lt;/code&gt;
boundary conditions &lt;code&gt;\(k_1=k\)&lt;/code&gt; and &lt;code&gt;\(k_{N+1}=0\)&lt;/code&gt;, and non-negativity constraint &lt;code&gt;\(s_n\ge0\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;solving-the-two-lap-case&#34;&gt;Solving the two-lap case&lt;/h2&gt;
&lt;p&gt;We can build intuition by solving the case with &lt;code&gt;\(N=2\)&lt;/code&gt;.
Then the dynamic constraint and boundary conditions imply
&lt;code&gt;$$T=\frac{c_1}{k-k_2}+\frac{c_2}{k_2},$$&lt;/code&gt;
where &lt;code&gt;\(k_2\)&lt;/code&gt; is the energy I choose to leave for the second lap.
It satisfies the first-order condition &lt;code&gt;\(\partial T/\partial k_2=0\)&lt;/code&gt;, which we can write as
&lt;code&gt;$$\frac{c_1}{(k-k_2)^2}=\frac{c_2}{k_2^2}.$$&lt;/code&gt;
The left-hand side is the marginal cost (in units of total time) of using less energy in the first lap.
The right-hand side is the marginal benefit of using more energy in the second lap.
The first-order condition balances this marginal cost and benefit.
It determines how I should &lt;a href=&#34;https://en.wikipedia.org/wiki/Consumption_smoothing&#34;&gt;smooth my energy consumption&lt;/a&gt; across laps.&lt;/p&gt;
&lt;p&gt;Rearranging the first-order condition for &lt;code&gt;\(k_2\)&lt;/code&gt; gives
&lt;code&gt;$$k_2=\frac{\sqrt{c_2}}{\sqrt{c_1}+\sqrt{c_2}}k.$$&lt;/code&gt;
So I should spend my energy proportionally to the square roots of the costs I face.
For example, if &lt;code&gt;\(c_1=4c_2\)&lt;/code&gt; then I should spend a third of my energy on the first lap and two thirds on the second.
This leads me to run twice as fast on the second lap and makes my total time equal &lt;code&gt;\(9c_2/k\)&lt;/code&gt;.
In contrast, if I spent energy proportionally to costs then I would spend a fifth on the first lap and four fifths on the second.
I would run at a constant speed and my total time would equal &lt;code&gt;\(10c_2/k\)&lt;/code&gt;.
That strategy would be optimal if the costs were constant at their mean &lt;code&gt;\(5c_2/2\)&lt;/code&gt;.
But they &lt;em&gt;aren&amp;rsquo;t&lt;/em&gt; constant: they vary by a factor of four.
Square-root scaling takes advantage of this variation.
It makes me run slow when it&amp;rsquo;s expensive to run fast.&lt;/p&gt;
&lt;h2 id=&#34;solving-the-general-case&#34;&gt;Solving the general case&lt;/h2&gt;
&lt;p&gt;The results and intuitions from the case with &lt;code&gt;\(N=2\)&lt;/code&gt; generalize to cases with &lt;code&gt;\(N&amp;gt;2\)&lt;/code&gt;.
But those cases require more powerful solution methods.
I explain two: using the &lt;a href=&#34;https://en.wikipedia.org/wiki/Hamiltonian_%28control_theory%29&#34;&gt;Hamiltonian&lt;/a&gt; and using the &lt;a href=&#34;https://en.wikipedia.org/wiki/Bellman_equation&#34;&gt;Bellman equation&lt;/a&gt;.
The first is faster, but the second is more intuitive and extends naturally to a setting with &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-random-energy-costs/&#34;&gt;random costs&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;using-the-hamiltonian&#34;&gt;Using the Hamiltonian&lt;/h3&gt;
&lt;p&gt;The Hamiltonian for my optimal pacing problem is
&lt;code&gt;$$H\equiv-\frac{1}{s_n}-\lambda_{n+1}c_ns_n,$$&lt;/code&gt;
where &lt;code&gt;\(\lambda_{n+1}\)&lt;/code&gt; is a costate that satisfies
&lt;code&gt;$$\lambda_{n+1}-\lambda_n=-\parfrac{H}{k_n}$$&lt;/code&gt;
for each &lt;code&gt;\(n\)&lt;/code&gt;.
But &lt;code&gt;\(\partial H/\partial k_n=0\)&lt;/code&gt; and so &lt;code&gt;\(\lambda_{n+1}=\lambda\)&lt;/code&gt; is constant.
Substituting it into the first-order condition &lt;code&gt;\(\partial H/\partial s_n=0\)&lt;/code&gt; gives
&lt;code&gt;$$s_n=\frac{1}{\sqrt{\lambda c_n}}.$$&lt;/code&gt;
Now the dynamic constraint and boundary conditions imply
&lt;code&gt;$$\sum_{n=1}^Nc_ns_n=k,$$&lt;/code&gt;
from which it follows that
&lt;code&gt;$$\sqrt\lambda=\frac{1}{k}\sum_{n=1}^N\sqrt{c_n}$$&lt;/code&gt;
and therefore
&lt;code&gt;$$s_n=\frac{k}{\sqrt{c_n}\sum_{m=1}^N\sqrt{c_m}}$$&lt;/code&gt;
for each &lt;code&gt;\(n\)&lt;/code&gt;.
Then my total time equals
&lt;code&gt;$$T=\frac{1}{k}\left(\sum_{n=1}^N\sqrt{c_n}\right)^2.$$&lt;/code&gt;
For example, letting &lt;code&gt;\(N=2\)&lt;/code&gt; and &lt;code&gt;\(c_1=4c_2\)&lt;/code&gt; yields the optimal time &lt;code&gt;\(T=9c_2/k\)&lt;/code&gt; &lt;a href=&#34;#solving-the-two-lap-case&#34;&gt;described above&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;using-the-bellman-equation&#34;&gt;Using the Bellman equation&lt;/h3&gt;
&lt;p&gt;The dynamic constraint implies
&lt;code&gt;$$s_n=\frac{k_n-k_{n+1}}{c_n}$$&lt;/code&gt;
for each &lt;code&gt;\(n.\)&lt;/code&gt;
Consequently, the cost sequence &lt;code&gt;\((c_n)_{n=1}^N\)&lt;/code&gt; and &amp;ldquo;remaining energy&amp;rdquo; sequence &lt;code&gt;\((k_{n+1})_{n=0}^N\)&lt;/code&gt; uniquely determine the speed sequence &lt;code&gt;\((s_n)_{n=1}^N\)&lt;/code&gt;.
So if
&lt;code&gt;$$V_n\equiv\sum_{m=n}^N\frac{1}{s_n}$$&lt;/code&gt;
denotes the time spent running laps &lt;code&gt;\(n\)&lt;/code&gt; through &lt;code&gt;\(N\)&lt;/code&gt; when I pace myself optimally, then &lt;code&gt;\(V_n\)&lt;/code&gt; must satisfy the Bellman equation
&lt;code&gt;$$V_n=\min_{k_{n+1}}\left\{\frac{c_n}{k_n-k_{n+1}}+V_{n+1}\right\}.$$&lt;/code&gt;
This equation echoes my objective in &lt;a href=&#34;#solving-the-two-lap-case&#34;&gt;the two-lap case&lt;/a&gt;.
Intuitively, my optimal speeds in the &lt;code&gt;\(N\)&lt;/code&gt;-lap case solve a sequence of two-lap problems, where the second &amp;ldquo;lap&amp;rdquo; is the remainder of my race.&lt;/p&gt;
&lt;p&gt;We can solve the Bellman equation using the &lt;a href=&#34;https://en.wikipedia.org/wiki/Method_of_undetermined_coefficients&#34;&gt;method of undetermined coefficients&lt;/a&gt;.
Suppose &lt;code&gt;\(V_{n+1}=a_{n+1}/k_{n+1}\)&lt;/code&gt; for some &lt;code&gt;\(a_{n+1}\ge0\)&lt;/code&gt;.
Then, under optimal pacing, we have
&lt;code&gt;$$\begin{align} 0 &amp;amp;= \parfrac{}{k_{n+1}}\left(\frac{c_n}{k_n-k_{n+1}}+V_{n+1}\right) \\ &amp;amp;= \frac{c_n}{(k_n-k_{n+1})^2}-\frac{a_{n+1}}{k_{n+1}} \end{align}$$&lt;/code&gt;
and therefore
&lt;code&gt;$$k_{n+1}=\frac{\sqrt{a_{n+1}}}{\sqrt{a_{n+1}}+\sqrt{c_n}}k_n.$$&lt;/code&gt;
Substituting this recurrence into the Bellman equation gives &lt;code&gt;\(V_n=a_n/k_n\)&lt;/code&gt;, where
&lt;code&gt;$$a_n\equiv\left(\sqrt{a_{n+1}}+\sqrt{c_n}\right)^2$$&lt;/code&gt;
and &lt;code&gt;\(a_{N+1}=0\)&lt;/code&gt;.
Solving recursively gives
&lt;code&gt;$$\sqrt{a_n}=\sum_{m=n}^N\sqrt{c_m}$$&lt;/code&gt;
for each &lt;code&gt;\(n\)&lt;/code&gt;, from which it follows that
&lt;code&gt;$$k_{n+1}=\frac{\sum_{m=n+1}^N\sqrt{c_m}}{\sum_{m=1}^N\sqrt{c_m}}k$$&lt;/code&gt;
and
&lt;code&gt;$$s_n=\frac{k}{\sqrt{c_n}\sum_{m=1}^N\sqrt{c_m}}.$$&lt;/code&gt;
So we get the same optimal speed sequence and total time as obtained &lt;a href=&#34;#using-the-hamiltonian&#34;&gt;using the Hamiltonian&lt;/a&gt;.
We also see the square-root scaling from the two-lap case generalize to the &lt;code&gt;\(N\)&lt;/code&gt;-lap case.
For example, if the costs I face in the first half of the race are four times the costs I face in the second, then I should run half as fast in the first half than I run in the second.&lt;/p&gt;
&lt;h2 id=&#34;solution-properties&#34;&gt;Solution properties&lt;/h2&gt;
&lt;p&gt;As explained above, each speed term &lt;code&gt;\(s_n\)&lt;/code&gt; scales with the inverse square-root of the corresponding cost term &lt;code&gt;\(c_n\)&lt;/code&gt;.
This scaling takes advantage of the variation in costs faced during my race.
But scaling &lt;em&gt;all&lt;/em&gt; of the cost terms has a linear effect: doubling each &lt;code&gt;\(c_n\)&lt;/code&gt; halves each &lt;code&gt;\(s_n\)&lt;/code&gt; and so doubles my total time &lt;code&gt;\(T\)&lt;/code&gt;.
Likewise, doubling my initial energy &lt;code&gt;\(k\)&lt;/code&gt; doubles each &lt;code&gt;\(s_n\)&lt;/code&gt; and so halves &lt;code&gt;\(T\)&lt;/code&gt;.
These linearities come from the linearity of the dynamic constraint &lt;code&gt;\(k_{n+1}=k_n-c_ns_n\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Rearranging the cost sequence &lt;code&gt;\((c_n)_{n=1}^N\)&lt;/code&gt; leads to the same rearrangement of the optimal speed sequence &lt;code&gt;\((s_n)_{n=1}^N\)&lt;/code&gt;.
This is because the sequences satisfy
&lt;code&gt;$$\sqrt{c_n}s_n=\frac{k}{\sum_{m=1}^N\sqrt{c_m}},$$&lt;/code&gt;
the right-hand side of which doesn&amp;rsquo;t change if I rearrange the &lt;code&gt;\(c_n\)&lt;/code&gt;.
Nor does my minimized time &lt;code&gt;\(T\)&lt;/code&gt; change.
Intuitively, swapping the laps on which I run slow and fast doesn&amp;rsquo;t change my average pace.&lt;/p&gt;
&lt;p&gt;Whereas variation in costs &lt;em&gt;improves&lt;/em&gt; my average pace.
To see how, let
&lt;code&gt;$$\E[c_n]\equiv\frac{1}{N}\sum_{n=1}^Nc_n$$&lt;/code&gt;
be the empirical mean cost of energy during my race and let
&lt;code&gt;$$\overline{T}\equiv\frac{\E[c_n]N}{k}$$&lt;/code&gt;
be my optimal time when &lt;code&gt;\(c_n=\E[c_n]\)&lt;/code&gt; for each &lt;code&gt;\(n\)&lt;/code&gt;.
Then
&lt;code&gt;$$\begin{align} \overline{T}-T &amp;amp;= \frac{N}{k}\left(\E[c_n]-\frac{1}{N^2}\left(\sum_{n=1}^N\sqrt{c_n}\right)^2\right) \\ &amp;amp;= \frac{N}{k}\left(\E[\sqrt{c_n}^2]-\E[\sqrt{c_n}]^2\right) \end{align}$$&lt;/code&gt;
and therefore
&lt;code&gt;$$T=\overline{T}-\frac{N}{k}\Var(\sqrt{c_n}),$$&lt;/code&gt;
where &lt;code&gt;\(\Var(\sqrt{c_n})=\E[\sqrt{c_n}^2]-\E[\sqrt{c_n}]^2\)&lt;/code&gt; is the empirical variance of the &lt;code&gt;\(\sqrt{c_n}\)&lt;/code&gt;.
So applying a &lt;a href=&#34;https://en.wikipedia.org/wiki/Mean-preserving_spread&#34;&gt;mean-preserving spread&lt;/a&gt; to the distribution of &lt;code&gt;\(\sqrt{c_n}\)&lt;/code&gt; values lowers my optimal time &lt;code&gt;\(T\)&lt;/code&gt;.
But this is not the same as increasing the variance in &lt;code&gt;\(c_n\)&lt;/code&gt;.
For example, consider the cost sequences &lt;code&gt;\((c_n)_{n=1}^{100}\)&lt;/code&gt; and &lt;code&gt;\((c_n&#39;)_{n=1}^{100}\)&lt;/code&gt; defined by
&lt;code&gt;$$c_n=\begin{cases} 145 &amp;amp; \text{if}\ n\le 50 \\ 55 &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
and
&lt;code&gt;$$c_n&#39;=\begin{cases} 200 &amp;amp; \text{if}\ n\le 20 \\ 75 &amp;amp; \text{otherwise}. \end{cases}$$&lt;/code&gt;
Then &lt;code&gt;\(\E[c_n]=\E[c_n&#39;]=100\)&lt;/code&gt;, while &lt;code&gt;\(\Var(c_n)=2025\)&lt;/code&gt; and &lt;code&gt;\(\Var(c_n&#39;)=2500\)&lt;/code&gt;.
So the &lt;code&gt;\(c_n\)&lt;/code&gt; have lower variance than the &lt;code&gt;\(c_n&#39;\)&lt;/code&gt;.
But &lt;code&gt;\(\Var(\sqrt{c_n})\approx5.3\)&lt;/code&gt; is larger than &lt;code&gt;\(\Var(\sqrt{c_n&#39;})\approx4.8\)&lt;/code&gt;, which means my optimal time is &lt;em&gt;smaller&lt;/em&gt; under &lt;code&gt;\((c_n)_{n=1}^{100}\)&lt;/code&gt; than under &lt;code&gt;\((c_n&#39;)_{n=1}^{100}\)&lt;/code&gt;.
Intuitively, I &lt;a href=&#34;https://bldavies.com/blog/binary-distributions-risky-gambles&#34;&gt;prefer&lt;/a&gt; cost sequences with a mix of highs and lows to sequences with a few sharp highs and lots of mild lows.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Replacing &lt;code&gt;\(T\)&lt;/code&gt; with &lt;code&gt;\(T/N\)&lt;/code&gt;, and letting &lt;code&gt;\(x=n/N\)&lt;/code&gt; and &lt;code&gt;\(N\to\infty\)&lt;/code&gt;, yields a special (linear) case of the problem discussed in &lt;a href=&#34;https://bldavies.com/blog/rationalizing-negative-splits/&#34;&gt;my post on negative splits&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Correlation and concatenation</title>
      <link>https://bldavies.com/blog/correlation-concatenation/</link>
      <pubDate>Thu, 17 Nov 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/correlation-concatenation/</guid>
      <description>&lt;p&gt;Suppose I have data &lt;code&gt;\((a_i,b_i)_{i=1}^n\)&lt;/code&gt; on two random variables &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt;.
I store my data as vectors &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, and compute their correlation using the &lt;code&gt;cor&lt;/code&gt; function in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 0.4326075
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now suppose I append a mirrored version of my data by defining the vectors&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;beta&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;so that &lt;code&gt;alpha&lt;/code&gt; is a concatenation of the &lt;code&gt;\(a_i\)&lt;/code&gt; and &lt;code&gt;\(b_i\)&lt;/code&gt; values, and &lt;code&gt;beta&lt;/code&gt; is a concatenation of the &lt;code&gt;\(b_i\)&lt;/code&gt; and &lt;code&gt;\(a_i\)&lt;/code&gt; values.
I compute the correlation of &lt;code&gt;alpha&lt;/code&gt; and &lt;code&gt;before&lt;/code&gt; as before:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;beta&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 0.4288428
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice that &lt;code&gt;cor(a, b)&lt;/code&gt; and &lt;code&gt;cor(alpha, beta)&lt;/code&gt; are not equal.
This surprised me.
How can appending a copy of &lt;em&gt;the same data&lt;/em&gt; change the correlation within those data?&lt;/p&gt;
&lt;p&gt;The answer is that the concatenated data &lt;code&gt;\((\alpha_i,\beta_i)_{i=1}^{2n}\)&lt;/code&gt; have different marginal distributions than the original data &lt;code&gt;\((a_i,b_i)_{i=1}^n\)&lt;/code&gt;.
Indeed one can show that
&lt;code&gt;$$\DeclareMathOperator{\Cor}{Cor} \DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \begin{align} \E[\alpha]=\E[\beta]=\frac{\E[a]+\E[b]}{2} \end{align}$$&lt;/code&gt;
and
&lt;code&gt;$$\begin{align} \E[\alpha^2]=\E[\beta^2]=\frac{\E[a^2]+\E[b^2]}{2}, \end{align}$$&lt;/code&gt;
where
&lt;code&gt;$$\E[\alpha]\equiv\frac{1}{2n}\sum_{i=1}^n\alpha_i$$&lt;/code&gt;
is the empirical mean of the &lt;code&gt;\(\alpha_i\)&lt;/code&gt; values, and where &lt;code&gt;\(\E[\beta]\)&lt;/code&gt;, &lt;code&gt;\(\E[a]\)&lt;/code&gt;, and &lt;code&gt;\(\E[b]\)&lt;/code&gt; are defined similarly.
It turns out that &lt;code&gt;\(\E[\alpha\beta]=\E[ab]\)&lt;/code&gt;, but since the marginal distributions are different the empirical correlations are different.
In fact
&lt;code&gt;$$\Cor(\alpha,\beta)=\frac{\Cov(a,b)-0.25\left(\E[a]+\E[b]\right)^2}{0.5\Var(a)+0.5\Var(b)+0.25\left(\E[a]-\E[b]\right)^2},$$&lt;/code&gt;
where &lt;code&gt;\(\Cor\)&lt;/code&gt;, &lt;code&gt;\(\Cov\)&lt;/code&gt;, and &lt;code&gt;\(\Var\)&lt;/code&gt; are the empirical correlation, covariance, and variance operators.
This expression implies that &lt;code&gt;cor(alpha, beta)&lt;/code&gt; and &lt;code&gt;cor(a, b)&lt;/code&gt; will be equal if the &lt;code&gt;\(a_i\)&lt;/code&gt; and &lt;code&gt;\(b_i\)&lt;/code&gt; values have the same means and variances.
We can achieve this by scaling &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; before computing their correlation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 0.4326075
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;scale&lt;/code&gt; function de-means its argument and scales it to have unit variance.
These operations don&amp;rsquo;t change the correlation of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;.
But they &lt;em&gt;do&lt;/em&gt; change the correlation of &lt;code&gt;alpha&lt;/code&gt; and &lt;code&gt;beta&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;beta&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;beta&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 0.4326075
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the two correlations agree!&lt;/p&gt;
&lt;p&gt;I came across this phenomenon while writing &lt;a href=&#34;https://bldavies.com/blog/friendship-paradox/&#34;&gt;my previous post&lt;/a&gt;, in which I discuss the degree &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortativity&lt;/a&gt; among nodes in &lt;a href=&#34;https://en.wikipedia.org/wiki/Zachary&#39;s_karate_club&#34;&gt;Zachary&amp;rsquo;s (1977) karate club network&lt;/a&gt;.
One way to measure this assortativity is to use the &lt;code&gt;degree_assortativity&lt;/code&gt; function in &lt;a href=&#34;https://igraph.org/&#34;&gt;igraph&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph.famous&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;Zachary&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;assortativity_degree&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] -0.4756131
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This function returns the correlation of the degrees of adjacent nodes in &lt;code&gt;G&lt;/code&gt;.
Another way to compute this correlation is to&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;construct a matrix &lt;code&gt;el&lt;/code&gt; in which rows correspond to edges and columns list incident nodes;&lt;/li&gt;
&lt;li&gt;define the vectors &lt;code&gt;d1&lt;/code&gt; and &lt;code&gt;d2&lt;/code&gt; of degrees among the nodes listed in &lt;code&gt;el&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;compute the correlation of &lt;code&gt;d1&lt;/code&gt; and &lt;code&gt;d2&lt;/code&gt; using &lt;code&gt;cor&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here&amp;rsquo;s what I get when I take those three steps:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;el&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as_edgelist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;d&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;degree&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d[el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Ego degrees&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d[el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Alter degrees&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] -0.4769563
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice that &lt;code&gt;cor(d1, d2)&lt;/code&gt; disagrees with the value of &lt;code&gt;assortativity_degree(G)&lt;/code&gt; computed above.
This is because the vectors &lt;code&gt;d1&lt;/code&gt; and &lt;code&gt;d2&lt;/code&gt; have different means and variances:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 7.487179 8.051282
&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 25.94139 32.23110
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These differences come from &lt;code&gt;el&lt;/code&gt; listing each edge only once: it includes a row &lt;code&gt;c(i, j)&lt;/code&gt; for the edge between nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\not=i\)&lt;/code&gt;, but not a row &lt;code&gt;c(j, i)&lt;/code&gt;.
Whereas &lt;code&gt;assortativity_degree&lt;/code&gt; accounts for edges being undirected by adding the row &lt;code&gt;c(j, i)&lt;/code&gt; before computing the correlation.
This is analogous to the &amp;ldquo;append the mirrored data&amp;rdquo; step I took to create &lt;code&gt;\((\alpha_i,\beta_i)_{i=1}^{2n}\)&lt;/code&gt; above.
Appending the mirror of &lt;code&gt;el&lt;/code&gt; to itself before computing &lt;code&gt;cor(d1, d2)&lt;/code&gt; returns the same value as &lt;code&gt;assortativity_degree(G)&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;el&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rbind&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;el&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ncol&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# el&amp;#39;s mirror&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d[el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d[el[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;assortativity_degree&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] -0.4756131 -0.4756131
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>The friendship paradox</title>
      <link>https://bldavies.com/blog/friendship-paradox/</link>
      <pubDate>Wed, 16 Nov 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/friendship-paradox/</guid>
      <description>&lt;p&gt;People tend to be less popular than their friends.
This &lt;a href=&#34;https://en.wikipedia.org/wiki/Friendship_paradox&#34;&gt;paradox&lt;/a&gt;, first observed by &lt;a href=&#34;https://doi.org/10.1086/229693&#34;&gt;Feld (1991)&lt;/a&gt;, is due to popular people appearing on many friend lists.&lt;/p&gt;
&lt;p&gt;For example, consider the social network among members of a karate club studied by &lt;a href=&#34;https://doi.org/10.1086/jar.33.4.3629752&#34;&gt;Zachary (1977)&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/zachary-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The network contains &lt;code&gt;\(n=34\)&lt;/code&gt; nodes with mean degree
&lt;code&gt;$$\DeclareMathOperator{\Corr}{Corr} \DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \E[d_i]\equiv\frac{1}{n}\sum_{i=1}^nd_i=4.59,$$&lt;/code&gt;
where &lt;code&gt;\(\E\)&lt;/code&gt; takes expected values across nodes and &lt;code&gt;\(d_i\)&lt;/code&gt; is the degree of node &lt;code&gt;\(i\)&lt;/code&gt;.
If &lt;code&gt;\(N_i\)&lt;/code&gt; denotes the set of &lt;code&gt;\(i\)&lt;/code&gt;&#39;s neighbors, then the mean degree among those neighbors equals
&lt;code&gt;$$f_i\equiv \frac{1}{d_i}\sum_{j\in N_i}d_j.$$&lt;/code&gt;
The friendship paradox states that &lt;code&gt;\(\E[d_i]\le\E[f_i]\)&lt;/code&gt; in &lt;em&gt;any&lt;/em&gt; network.
In Zachary&amp;rsquo;s network we have &lt;code&gt;\(\E[f_i]=9.61\)&lt;/code&gt;, about twice the mean degree.&lt;/p&gt;
&lt;p&gt;We can approximate &lt;code&gt;\(\E[f_i]\)&lt;/code&gt; using the following procedure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose a stub (i.e., the endpoint of an edge) uniformly at random.&lt;/li&gt;
&lt;li&gt;Record the degree of the chosen stub.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Repeating these steps many times yields a degree distribution that over-samples from high-degree nodes.
The mean of this distribution answers the following question: &amp;ldquo;How many friends does a typical friend have?&amp;rdquo;
The probability of choosing node &lt;code&gt;\(i\)&lt;/code&gt; in the first step equals
&lt;code&gt;$$p_i\equiv \frac{d_i}{\sum_{j=1}^nd_j},$$&lt;/code&gt;
the proportion of stubs that &lt;code&gt;\(i\)&lt;/code&gt; adds to the network.
Using the probabilities &lt;code&gt;\(p_i\)&lt;/code&gt; to compute the expected value of the degrees &lt;code&gt;\(d_i\)&lt;/code&gt; yields an approximation
&lt;code&gt;$$\begin{align} \widehat{\E[f_i]} &amp;amp;= \sum_{i=1}^np_id_i \\ &amp;amp;= \sum_{i=1}^n\left(\frac{d_i}{\sum_{j=1}^nd_j}\right)d_i \\ &amp;amp;= \frac{\sum_{i=1}^nd_i^2}{\sum_{j=1}^nd_j} \\ &amp;amp;= \frac{\E[d_i^2]}{\E[d_i]} \\ &amp;amp;= \E[d_i]+\frac{\Var(d_i)}{\E[d_i]} \end{align}$$&lt;/code&gt;
of &lt;code&gt;\(\E[f_i]\)&lt;/code&gt;.
Notice that if &lt;code&gt;\(\Var(d_i)=0\)&lt;/code&gt; then &lt;code&gt;\(\widehat{\E[f_i]}=\E[d_i]\)&lt;/code&gt;; in that case, everyone has the same degree as their friends, and so there is no friendship paradox.
The difference between the mean degree &lt;code&gt;\(\E[d_i]\)&lt;/code&gt; and the typical friend&amp;rsquo;s degree &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; grows as the variance in degrees grows.&lt;/p&gt;
&lt;p&gt;The approximation &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; is closest to &lt;code&gt;\(\E[f_i]\)&lt;/code&gt; when there is no &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortative mixing&lt;/a&gt; with respect to degree.
Then the &lt;code&gt;\(d_i\)&lt;/code&gt; are uncorrelated with the &lt;code&gt;\(f_i\)&lt;/code&gt;.
But this isn&amp;rsquo;t true in Zachary&amp;rsquo;s network:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/zachary-degrees-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Indeed, in Zachary&amp;rsquo;s network we have &lt;code&gt;\(\widehat{\E[f_i]}=7.77\)&lt;/code&gt;, which is smaller than the true value &lt;code&gt;\(\E[f_i]=9.61\)&lt;/code&gt;.
To see why, notice that
&lt;code&gt;$$\begin{align} \E[d_if_i] &amp;amp;= \frac{1}{n}\sum_{i=1}^nd_if_i \\ &amp;amp;= \frac{1}{n}\sum_{i=1}^n\sum_{j\in N_i}d_j \\ &amp;amp;\overset{\star}{=}\frac{1}{n}\sum_{j=1}^nd_j^2 \\ &amp;amp;= \E[d_j^2], \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\star\)&lt;/code&gt; holds because &lt;code&gt;\(j\)&lt;/code&gt; appears in &lt;code&gt;\(d_j\)&lt;/code&gt; neighborhoods &lt;code&gt;\(N_i\)&lt;/code&gt;.
But
&lt;code&gt;$$\E[d_if_i]=\E[d_if_i]+\Cov(d_i,f_i)$$&lt;/code&gt;
by the definition of covariance, from which it follows that
&lt;code&gt;$$\widehat{\E[f_i]}=\E[f_i]+\frac{\Cov(d_i,f_i)}{\E[d_i]}.$$&lt;/code&gt;
Thus &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; under-estimates &lt;code&gt;\(\E[f_i]\)&lt;/code&gt; in Zachary&amp;rsquo;s network because &lt;code&gt;\(\Cov(d_i,f_i)=-8.45\)&lt;/code&gt; is negative.&lt;/p&gt;
&lt;p&gt;The value of &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; depends only on the mean and variance of degrees, and not the correlation of degrees across adjacent nodes.
Thus &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; is invariant to &lt;a href=&#34;https://bldavies.com/blog/degree-preserving-randomisation/&#34;&gt;degree-preserving randomizations&lt;/a&gt; (DPRs).
But &lt;code&gt;\(\E[f_i]\)&lt;/code&gt; can vary under DPRs because they can change the correlation of adjacent nodes&amp;rsquo; degrees.
For example, consider the three networks shown below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/dpr-example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The networks &lt;code&gt;\(G_1\)&lt;/code&gt;, &lt;code&gt;\(G_2\)&lt;/code&gt;, and &lt;code&gt;\(G_3\)&lt;/code&gt; have the same degree distributions.
As a result, they have the same mean degrees &lt;code&gt;\(\E[d_i]\)&lt;/code&gt; and approximations &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; of &lt;code&gt;\(\E[f_i]\)&lt;/code&gt;.
But the true values of &lt;code&gt;\(\E[f_i]\)&lt;/code&gt; differ because the correlations &lt;code&gt;\(\Corr(d_i,f_i)\)&lt;/code&gt; differ:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Network&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\E[d_i]\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\E[f_i]\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\Corr(d_i,f_i)\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(G_1\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.43&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.43&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(G_2\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.43&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.57&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(G_3\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.43&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.71&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;-0.91&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The network &lt;code&gt;\(G_1\)&lt;/code&gt; is perfectly assortative with respect to degree, so &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; over-estimates &lt;code&gt;\(\E[f_i]\)&lt;/code&gt;.
Whereas &lt;code&gt;\(G_3\)&lt;/code&gt; is dis-assortative with respect to degree, so &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; under-estimates &lt;code&gt;\(\E[f_i]\)&lt;/code&gt;.
The network &lt;code&gt;\(G_2\)&lt;/code&gt; is relatively unsorted, so &lt;code&gt;\(\widehat{\E[f_i]}\)&lt;/code&gt; is close to &lt;code&gt;\(\E[f_i]\)&lt;/code&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Binary distributions and risky gambles</title>
      <link>https://bldavies.com/blog/binary-distributions-risky-gambles/</link>
      <pubDate>Sun, 13 Nov 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/binary-distributions-risky-gambles/</guid>
      <description>&lt;p&gt;This post shows how binary random variables can be defined by their mean, variance, and skewness.
I use this fact to explain why variance does not (always) measure &amp;ldquo;riskiness.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Suppose I&amp;rsquo;m defining a random variable &lt;code&gt;\(X\)&lt;/code&gt;.
It takes value &lt;code&gt;\(H\)&lt;/code&gt; or &lt;code&gt;\(L&amp;lt;H\)&lt;/code&gt;, with &lt;code&gt;\(\Pr(X=H)=p\)&lt;/code&gt;.
I want &lt;code&gt;\(X\)&lt;/code&gt; to have mean &lt;code&gt;\(\mu\)&lt;/code&gt;, variance &lt;code&gt;\(\sigma^2\)&lt;/code&gt;, and &lt;a href=&#34;https://en.wikipedia.org/wiki/Skewness#Fisher&#39;s_moment_coefficient_of_skewness&#34;&gt;skewness coefficient&lt;/a&gt;
&lt;code&gt;$$\DeclareMathOperator{\E}{E} s\equiv\E\left[\left(\frac{X-\mu}{\sigma}\right)^3\right].$$&lt;/code&gt;
The target parameters &lt;code&gt;\((\mu,\sigma,s)\)&lt;/code&gt; uniquely determine &lt;code&gt;\((H,L,p)\)&lt;/code&gt; via
&lt;code&gt;$$\begin{align} H &amp;amp;= \mu+\frac{s+\sqrt{s^2+4}}{2}\sigma \\ L &amp;amp;= \mu+\frac{s-\sqrt{s^2+4}}{2}\sigma \\ p &amp;amp;= \frac{2}{4+s\left(s+\sqrt{s^2+4}\right)}. \end{align}$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For example, if I want &lt;code&gt;\(X\)&lt;/code&gt; to be symmetric (i.e., to have &lt;code&gt;\(s=0\)&lt;/code&gt;) then I have to choose &lt;code&gt;\((H,L,p)=(\mu+\sigma,\mu-\sigma,0.5)\)&lt;/code&gt;.
Increasing the target skewness &lt;code&gt;\(s\)&lt;/code&gt; makes the upside &lt;code&gt;\((H-\mu)\)&lt;/code&gt; larger but less likely, and the downside &lt;code&gt;\((\mu-L)\)&lt;/code&gt; smaller but more likely:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/required-values-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;This mapping between &lt;code&gt;\((\mu,\sigma,s)\)&lt;/code&gt; and &lt;code&gt;\((H,L,p)\)&lt;/code&gt; is useful for generating examples of &amp;ldquo;risky&amp;rdquo; gambles.
Intuition suggests that a gamble is less risky if its payoffs have lower variance.
But &lt;a href=&#34;https://doi.org/10.1016/0022-0531%2870%2990038-4&#34;&gt;Rothschild and Stiglitz (1970)&lt;/a&gt; define a gamble &lt;code&gt;\(A\)&lt;/code&gt; to be less risky than gamble &lt;code&gt;\(B\)&lt;/code&gt; if every &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_aversion&#34;&gt;risk averse&lt;/a&gt; decision-maker (DM) prefers &lt;code&gt;\(A\)&lt;/code&gt; to &lt;code&gt;\(B\)&lt;/code&gt;.
These two definitions of &amp;ldquo;risky&amp;rdquo; agree when&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;payoffs are normally distributed, or&lt;/li&gt;
&lt;li&gt;DMs have quadratic utility functions.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Under those conditions, DMs&amp;rsquo; expected utility depends only on the payoffs&amp;rsquo; mean and variance.
But if neither condition holds then DMs also care about payoffs&amp;rsquo; skewness.
We can demonstrate this using binary gambles.
Consider these three:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Gamble &lt;code&gt;\(A\)&lt;/code&gt;&#39;s payoffs have mean &lt;code&gt;\(\mu_A=10\)&lt;/code&gt;, variance &lt;code&gt;\(\sigma_A^2=36\)&lt;/code&gt;, and skewness &lt;code&gt;\(s_A=0\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Gamble &lt;code&gt;\(B\)&lt;/code&gt;&#39;s payoffs have mean &lt;code&gt;\(\mu_B=10\)&lt;/code&gt;, variance &lt;code&gt;\(\sigma_B^2=144\)&lt;/code&gt;, and skewness &lt;code&gt;\(s_B=5\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Gamble &lt;code&gt;\(C\)&lt;/code&gt;&#39;s payoffs have mean &lt;code&gt;\(\mu_C=10\)&lt;/code&gt;, variance &lt;code&gt;\(\sigma_C^2=9\)&lt;/code&gt;, and skewness &lt;code&gt;\(s_C=-3\)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The means are the same but the distributions are different.
Gamble &lt;code&gt;\(i\in\{A,B,C\}\)&lt;/code&gt; gives me a random payoff &lt;code&gt;\(X_i\)&lt;/code&gt;, which equals &lt;code&gt;\(H_i\)&lt;/code&gt; with probability &lt;code&gt;\(p_i\)&lt;/code&gt; and &lt;code&gt;\(L_i\)&lt;/code&gt; otherwise.
We can compute the &lt;code&gt;\((H_i,L_i,p_i)\)&lt;/code&gt; using the target parameters &lt;code&gt;\((\mu_i,\sigma_i,s_i)\)&lt;/code&gt; and the formulas above:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Gamble &lt;code&gt;\(i\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(H_i\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(L_i\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(p_i\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(A\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16.00&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4.00&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(B\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;72.31&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7.69&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(C\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10.91&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.09&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.92&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Gamble &lt;code&gt;\(A\)&lt;/code&gt; offers a symmetric payoff: its upside &lt;code&gt;\((H_A-\mu_A)\)&lt;/code&gt; and downside &lt;code&gt;\((\mu_A-L_A)\)&lt;/code&gt; are equally large and equally likely.
Gamble &lt;code&gt;\(B\)&lt;/code&gt; offers a positively skewed payoff: a large but unlikely upside, and a small but likely downside.
Gamble &lt;code&gt;\(C\)&lt;/code&gt; offers a negatively skewed payoff: a small but likely upside, and a large but unlikely downside.&lt;/p&gt;
&lt;p&gt;These upsides and downsides affect my preferences over gambles.
Suppose I get utility &lt;code&gt;\(u(x)\equiv\log(x)\)&lt;/code&gt; from receiving payoff &lt;code&gt;\(x\)&lt;/code&gt;.
Then gamble &lt;code&gt;\(A\)&lt;/code&gt; gives me expected utility
&lt;code&gt;$$\begin{align} \E[u(X_A)] &amp;amp;\equiv p_Au(H_A)+(1-p_A)u(L_A) \\ &amp;amp;= 0.5\log(16)+(1-0.5)\log(4) \\ &amp;amp;= 2.08, \end{align}$$&lt;/code&gt;
while &lt;code&gt;\(B\)&lt;/code&gt; gives me &lt;code&gt;\(\E[u(X_B)]=2.12\)&lt;/code&gt; and &lt;code&gt;\(C\)&lt;/code&gt; gives me &lt;code&gt;\(\E[u(X_C)]=1.99\)&lt;/code&gt;.
So I prefer gamble &lt;code&gt;\(B\)&lt;/code&gt; to &lt;code&gt;\(A\)&lt;/code&gt;, even though &lt;code&gt;\(B\)&lt;/code&gt;&#39;s payoffs have four times the variance of &lt;code&gt;\(A\)&lt;/code&gt;&#39;s.
I also prefer &lt;code&gt;\(B\)&lt;/code&gt; to &lt;code&gt;\(C\)&lt;/code&gt;, even though &lt;code&gt;\(B\)&lt;/code&gt;&#39;s payoffs have &lt;em&gt;sixteen&lt;/em&gt; times the variance of &lt;code&gt;\(C\)&lt;/code&gt;&#39;s.
How can I be risk averse&amp;mdash;that is, have a concave utility function&amp;mdash;but prefer gambles with higher variance?
The answer is that I also care about skewness: I prefer gambles with large upsides and small downsides.
These &amp;ldquo;sides&amp;rdquo; of risk are not captured by variance.&lt;/p&gt;
&lt;p&gt;So is gamble &lt;code&gt;\(C\)&lt;/code&gt; &amp;ldquo;riskier&amp;rdquo; than gambles &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt;?
Rothschild and Stiglitz wouldn&amp;rsquo;t say so.
To see why, suppose my friend has utility function &lt;code&gt;\(v(x)=\sqrt{x}\)&lt;/code&gt;.
Then gamble &lt;code&gt;\(A\)&lt;/code&gt; gives him expected utility &lt;code&gt;\(\E[v(X_A)]=3\)&lt;/code&gt;, while &lt;code&gt;\(B\)&lt;/code&gt; gives him &lt;code&gt;\(\E[v(X_B)]=2.98\)&lt;/code&gt; and &lt;code&gt;\(C\)&lt;/code&gt; gives him &lt;code&gt;\(\E[v(X_C)]=3.05\)&lt;/code&gt;.
My friend and I have &lt;em&gt;opposite&lt;/em&gt; preferences: he prefers &lt;code&gt;\(C\)&lt;/code&gt; to &lt;code&gt;\(A\)&lt;/code&gt; to &lt;code&gt;\(B\)&lt;/code&gt;, whereas I prefer &lt;code&gt;\(B\)&lt;/code&gt; to &lt;code&gt;\(A\)&lt;/code&gt; to &lt;code&gt;\(C\)&lt;/code&gt;.
But we&amp;rsquo;re both risk averse: our utility functions are both concave!
Thus, it isn&amp;rsquo;t true that &lt;em&gt;every&lt;/em&gt; risk-averse decision-maker prefers &lt;code&gt;\(A\)&lt;/code&gt; or &lt;code&gt;\(B\)&lt;/code&gt; to &lt;code&gt;\(C\)&lt;/code&gt;.
Different risk-averse DMs have different preference rankings.
This makes the three gambles incomparable under Rothschild and Stiglitz&amp;rsquo;s definition of &amp;ldquo;risky.&amp;rdquo;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Estimating treatment effects with OLS</title>
      <link>https://bldavies.com/blog/estimating-treatment-effects-ols/</link>
      <pubDate>Sat, 12 Nov 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/estimating-treatment-effects-ols/</guid>
      <description>&lt;p&gt;A crop farmer wonders if he should use a new fertilizer.
He asks his peers what fertilizer they use and what are their annual yields.
He notices that some have different soil.
&amp;ldquo;That&amp;rsquo;s annoying,&amp;rdquo; the farmer thinks.
&amp;ldquo;If we all had the same soil, then I could estimate the benefit of using the new fertilizer by comparing the mean yields among farmers who do and don&amp;rsquo;t use it.
But now I have to control for soil too!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Thankfully the farmer learned about &lt;a href=&#34;https://en.wikipedia.org/wiki/Ordinary_least_squares&#34;&gt;ordinary least squares&lt;/a&gt; in his youth.
He remembers that he can control for variables by including them in a regression equation.
He posits a linear model
&lt;code&gt;$$\text{yield}=\beta_1\text{fert}+\beta_2\text{soil}+\epsilon,$$&lt;/code&gt;
where&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\(\text{fert}\)&lt;/code&gt; indicates using the new fertilizer,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(\text{soil}\)&lt;/code&gt; indicates having a different soil,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\beta_2\)&lt;/code&gt; are the average marginal effects of changing fertilizers and soils, and&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(\epsilon\)&lt;/code&gt; is an iid random error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The farmer estimates &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\beta_2\)&lt;/code&gt; using OLS, and gets the following results:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Coefficient&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Estimate&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Std. error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(\beta_1\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.787&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.210&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(\beta_2\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.013&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.211&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The farmer&amp;rsquo;s daughter enters his office.
She looks at his estimates and asks, &amp;ldquo;why don&amp;rsquo;t you just compare the mean yields among farmers with the same soil as you?
That seems less complicated than OLS.&amp;rdquo;
The farmer agrees.
He computes the conditional means
&lt;code&gt;$$\mu_{10}\equiv\mathrm{E}[\text{yield}\mid\text{fert}=1\ \text{and}\ \text{soil}=0]$$&lt;/code&gt;
and
&lt;code&gt;$$\mu_{00}\equiv\mathrm{E}[\text{yield}\mid\text{fert}=0\ \text{and}\ \text{soil}=0]$$&lt;/code&gt;
in his data, and finds that &lt;code&gt;\(\mu_{10}-\mu_{00}=0.965\)&lt;/code&gt;.
This surprises the farmer:
&amp;ldquo;I thought OLS controlled for variation in soil.
I expected it to give me the same result as computing the difference in conditional means.
But it doesn&amp;rsquo;t.
Why not?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The farmer has an idea:
&amp;ldquo;What if I include an interaction term?&amp;rdquo;
He posits an extended model
&lt;code&gt;$$\text{yield}=\gamma_1\text{fert}+\gamma_2\text{soil}+\gamma_3(\text{fert}\cdot\text{soil})+\epsilon,$$&lt;/code&gt;
estimates it via OLS, and gets the following results:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Coefficient&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Estimate&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Std. error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(\gamma_1\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.965&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.290&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(\gamma_2\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.208&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.303&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;\(\gamma_3\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;-0.377&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.422&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;ldquo;Interesting,&amp;rdquo; he thinks.
&amp;ldquo;OLS gives me the difference in conditional means if I include an interaction term, but not if I don&amp;rsquo;t.
I wonder what&amp;rsquo;s going on?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s going on is that &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\gamma_1\)&lt;/code&gt; measure different things.
The latter measures the average effect of using the new fertilizer &lt;em&gt;without changing&lt;/em&gt; soils.
Thus &lt;code&gt;\(\gamma_1=\mu_{10}-\mu_{00}\)&lt;/code&gt; by definition.
Whereas &lt;code&gt;\(\beta_1\)&lt;/code&gt; measures the average effect of using the new fertilizer &lt;em&gt;across all&lt;/em&gt; soils.
Thus
&lt;code&gt;$$\beta_1=(1-p)\left(\mu_{10}-\mu_{00}\right)+p\left(\mu_{11}-\mu_{01}\right),$$&lt;/code&gt;
where &lt;code&gt;\(p=\Pr(\text{soil}=1)\)&lt;/code&gt; is the share of the farmer&amp;rsquo;s peers who have a different soil, and
&lt;code&gt;$$\mu_{fs}\equiv\mathrm{E}[\text{yield}\mid\text{fert}=f\ \text{and}\ \text{soil}=s]$$&lt;/code&gt;
is the mean yield among peers with &lt;code&gt;\(\text{fert}=f\in\{0,1\}\)&lt;/code&gt; and &lt;code&gt;\(\text{soil}=s\in\{0,1\}\)&lt;/code&gt;.
The farmer&amp;rsquo;s data has &lt;code&gt;\(p=0.47\)&lt;/code&gt; and &lt;code&gt;\(\mu_{11}-\mu_{01}=0.587\)&lt;/code&gt;, giving
&lt;code&gt;$$\beta_1=(1-0.47)\times0.965+0.47\times0.587=0.787$$&lt;/code&gt;
as in the first table above.&lt;/p&gt;
&lt;p&gt;The OLS estimates of &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\gamma_1\)&lt;/code&gt; differ whenever the effect of using the new fertilizer varies across soils; that is, whenever &lt;code&gt;\(\gamma_3\not=0\)&lt;/code&gt; in the true model.
But they can also differ when &lt;code&gt;\(\gamma_3=0\)&lt;/code&gt; due to sampling variation.
For example, suppose the true model is
&lt;code&gt;$$\text{yield}=\text{fert}+\text{soil}+\epsilon,$$&lt;/code&gt;
where &lt;code&gt;\(\text{fert}\)&lt;/code&gt; and &lt;code&gt;\(\text{soil}\)&lt;/code&gt; are independent, and where &lt;code&gt;\(\epsilon\)&lt;/code&gt; is iid normally distributed.
The differences &lt;code&gt;\((\mu_{10}-\mu_{00})\)&lt;/code&gt; and &lt;code&gt;\((\mu_{11}-\mu_{01})\)&lt;/code&gt; in conditional means can differ in small samples because &lt;code&gt;\(\text{soil}\)&lt;/code&gt; and &lt;code&gt;\(\epsilon\)&lt;/code&gt; can be correlated by chance.
But this &lt;a href=&#34;https://en.wikipedia.org/wiki/Spurious_relationship&#34;&gt;spurious correlation&lt;/a&gt; disappears as the sample grows, making &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\gamma_1\)&lt;/code&gt; converge.
I demonstrate this convergence in the table below.
It shows the mean absolute difference between &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\gamma_1\)&lt;/code&gt; across many samples of increasing size &lt;code&gt;\(n\)&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(n\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\mathrm{E}\left[\lvert\beta_1-\gamma_1\rvert\right]\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;100&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.160&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1,000&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.050&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;10,000&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.014&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://sites.google.com/view/anirudh-sankar&#34;&gt;Anirudh Sankar&lt;/a&gt; for reading a draft version of this post.
It came from discussions that led to &lt;a href=&#34;https://bldavies.com/blog/value-conceptual-knowledge&#34;&gt;this paper&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Why do experts give simple advice?</title>
      <link>https://bldavies.com/blog/why-experts-give-simple-advice/</link>
      <pubDate>Sun, 25 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/why-experts-give-simple-advice/</guid>
      <description>&lt;p&gt;One of the requirements for &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;my PhD program&lt;/a&gt; is to write a &amp;ldquo;second-year paper.&amp;rdquo;
You can read mine &lt;a href=&#34;https://arxiv.org/abs/2209.11710v1&#34;&gt;here&lt;/a&gt;.
It discusses how career concerns impact the type of advice that experts provide.
I consider two types of advice:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Simple&amp;rdquo; advice of the form &amp;ldquo;take this action;&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Complex&amp;rdquo; advice of the form &amp;ldquo;take this action under these conditions.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Including conditions makes the expert seem more confident his advice is correct.
This hurts his reputation if his advice turns out to be &lt;em&gt;incorrect&lt;/em&gt;.
Then the advisee &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;infers&lt;/a&gt; that the expert is incompetent.
She says, &amp;ldquo;most wrong experts are incompetent.
You&amp;rsquo;re wrong, so you&amp;rsquo;re probably incompetent.
You&amp;rsquo;re fired!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The expert can avoid this fate by &amp;ldquo;simplifying&amp;rdquo; his advice: by excluding relevant conditions.
This makes the advice worse but prevents the advisee from learning about the expert&amp;rsquo;s competence.
It insures him against the risk of losing his job.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://arxiv.org/abs/2209.11710v1&#34;&gt;The paper&lt;/a&gt; formalizes this argument.
It explores how the expert&amp;rsquo;s choice between simple and complex advice depends on his incentives.
It explains my answer to the titular question: experts give simple advice to avoid being &amp;ldquo;confidently wrong.&amp;rdquo;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Dollar cost averaging</title>
      <link>https://bldavies.com/blog/dollar-cost-averaging/</link>
      <pubDate>Sat, 17 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/dollar-cost-averaging/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Dollar_cost_averaging&#34;&gt;Dollar cost averaging&lt;/a&gt; (DCA) is a way to split a lump sum investment into many smaller investments.
It involves regular purchases of a fixed &lt;em&gt;value&lt;/em&gt; (rather than &lt;em&gt;quantity&lt;/em&gt;) of shares.
This leads to buying more shares when their price is low and fewer when their price is high.
DCA is less risky than investing the lump sum because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it reduces the chance of buying lots of shares before their price rises or falls;&lt;/li&gt;
&lt;li&gt;it reduces the time that invested cash spends earning capital gains and losses.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But DCA is also less rewarding if prices trend upward because uninvested cash does not earn capital gains.
In that case, choosing between DCA and lump sum investment requires trading off risks and rewards.&lt;/p&gt;
&lt;p&gt;For example, suppose I have some cash to invest in a market index: the &lt;a href=&#34;https://en.wikipedia.org/wiki/S%26P_500&#34;&gt;S&amp;amp;P 500&lt;/a&gt;.
Here&amp;rsquo;s how that index evolved over the past five years (based on week-closing values from &lt;a href=&#34;https://fred.stlouisfed.org/series/SP500&#34;&gt;FRED&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/sp500-series-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The index grew overall, with a sharp drop at the start of the pandemic and slower drop at the start of this year.
The weekly return fluctuated around a mean of 0.2%:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/sp500-returns-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s assume future weekly returns will follow this distribution.
Should I invest all my cash now (the &amp;ldquo;lump sum&amp;rdquo; strategy) or split it into equal weekly investments (the &amp;ldquo;weekly DCA&amp;rdquo; strategy)?
How about equal monthly investments (the &amp;ldquo;monthly DCA&amp;rdquo; strategy)?&lt;/p&gt;
&lt;p&gt;We can answer these questions via simulation:&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sample 52 values from the S&amp;amp;P 500&amp;rsquo;s weekly return distribution.&lt;/li&gt;
&lt;li&gt;Take the cumulative product of those returns to get a simulated price path.&lt;/li&gt;
&lt;li&gt;Divide the cash invested each week by the simulated price for that week to get the number of shares bought that week.&lt;/li&gt;
&lt;li&gt;Multiply the total number of shares bought by the price in the 52nd week to get the investments&amp;rsquo; final value.&lt;/li&gt;
&lt;li&gt;Divide the final value by the amount of cash invested to get the annual return.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Repeating these five steps many times yields a distribution of annual returns offered by each strategy.
I compare those distributions in the table below, based on 1,000 simulated price paths.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Strategy&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Mean&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Std. dev.&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Min.&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Max.&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Lump sum&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.8%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22.2%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-46.1%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;95.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Weekly DCA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5.6%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.9%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-26.1%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Monthly DCA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.0%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12.5%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-27.0%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;57.3%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The return on the lump sum strategy has the highest mean and variance.
Investing all my cash in the first week gives me more time &amp;ldquo;in the market&amp;rdquo; earning capital gains, but exposes me to lots of random gains and losses.
Investing in smaller chunks limits my exposure to gains and losses, narrowing the distribution of annual returns.&lt;/p&gt;
&lt;p&gt;So, should I dollar cost average or not?
The answer depends on my risk tolerance.
If I don&amp;rsquo;t care about risk then I should choose the strategy with the highest mean return.
But if I&amp;rsquo;m risk averse then I need to paid a &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_premium&#34;&gt;risk premium&lt;/a&gt;.
The more risk averse I am and the riskier the strategy, the higher the risk premium.
I should choose the strategy with the highest return net of its risk premium.
This net, &amp;ldquo;certainty-equivalent&amp;rdquo; (CE) return equals the return on a riskless strategy that makes me indifferent between using it and using the risky strategy.&lt;/p&gt;
&lt;p&gt;For example, the chart below plots the CE return on each strategy when I have &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_aversion#Relative_risk_aversion&#34;&gt;constant relative risk aversion&lt;/a&gt;.
When my risk aversion is low, I prefer investing the lump sum.
But when my risk aversion is high, I prefer investing in smaller chunks.
Weekly and monthly chunks appear to deliver similar CE returns in my simulations.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/sp500-ce-returns-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The risk aversion level that makes me prefer DCA depends on the asset I invest in.
For example, suppose I&amp;rsquo;d rather invest in &lt;a href=&#34;https://en.wikipedia.org/wiki/Bitcoin&#34;&gt;bitcoin&lt;/a&gt;.
Its recent prices were much more volatile than the S&amp;amp;P 500 (according to week-closing values from &lt;a href=&#34;https://finance.yahoo.com/quote/BTC-USD/history?p=BTC-USD&#34;&gt;Yahoo Finance&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/bitcoin-series-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Investing in bitcoin offered a mean weekly return of 1.3% in the past five years, six times that of the S&amp;amp;P 500.
But bitcoin&amp;rsquo;s returns were riskier: they had a standard deviation of 11.0%, whereas the S&amp;amp;P 500&amp;rsquo;s returns had a standard deviation of 2.8%.&lt;/p&gt;
&lt;p&gt;The chart below compares the lump-sum, weekly DCA, and monthly DCA strategies for investing in bitcoin.
It shows the certainty-equivalent return on each strategy, based on 1,000 price paths simulated using the five steps described above.
My decision rule is the same as when investing in the S&amp;amp;P 500: use DCA if I&amp;rsquo;m sufficiently risk averse.
But the &amp;ldquo;sufficient&amp;rdquo; level of risk aversion for bitcoin is lower than for the S&amp;amp;P 500.
This is because bitcoin is riskier: its risk premium is a larger share of its mean return.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/bitcoin-ce-returns-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;One benefit of DCA that my simulations don&amp;rsquo;t capture is its simplicity: I don&amp;rsquo;t have to think about &lt;em&gt;when&lt;/em&gt; to invest the lump sum.
Indeed DCA removes the temptation to &lt;a href=&#34;https://en.wikipedia.org/wiki/Market_timing&#34;&gt;time the market&lt;/a&gt; that leads many investors astray.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: I am not a financial advisor and this post is not financial advice.
Do you own research on the investments that feel right to you.
Don&amp;rsquo;t invest money you can&amp;rsquo;t afford to lose.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I assume my uninvested cash earns interest at the inflation rate.
This means I can treat the simulated prices as real.
I also assume there are no transaction costs or brokerage fees. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Homophily and the strength of moderate ties</title>
      <link>https://bldavies.com/blog/homophily-strength-moderate-ties/</link>
      <pubDate>Fri, 16 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/homophily-strength-moderate-ties/</guid>
      <description>&lt;p&gt;Yesterday &lt;em&gt;Science&lt;/em&gt; published &lt;a href=&#34;https://doi.org/10.1126/science.abl4476&#34;&gt;a study&lt;/a&gt; on social networks and job mobility.
It suggests that there&amp;rsquo;s a causal, &amp;ldquo;inverted U-shaped&amp;rdquo; relationship between&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;the number of mutual friends you share with someone and&lt;/li&gt;
&lt;li&gt;the probability that befriending them leads you to change jobs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The authors call for a theory to explain this relationship.
In fact it has a simple explanation: &lt;a href=&#34;https://en.wikipedia.org/wiki/Homophily&#34;&gt;homophily&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;People tend to have friends with similar interests.
Those interests influence the jobs we want and hear about.
If you and I have lots of mutual friends, then I probably hear about lots of job opportunities that interest you.
But you probably hear about those opportunities too because you &lt;a href=&#34;https://bldavies.com/blog/echo-chambers-useful/&#34;&gt;talk to the same people&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/ideological-bias-trust-information-sources/&#34;&gt;follow the same news sources&lt;/a&gt;.
So befriending me is unlikely to impact your job mobility because the information I could give you is redundant.&lt;/p&gt;
&lt;p&gt;The opposite is true if we have few mutual friends.
Then we probably hear about different job opportunities because we talk to different people and follow different news sources.
But few of the opportunities I hear about will interest you.
So befriending me is unlikely to impact your job mobility because the information I could give you is irrelevant.&lt;/p&gt;
&lt;p&gt;Thus, homophily creates a trade-off between relevance and redundancy.
Befriending &amp;ldquo;strong ties&amp;rdquo; (i.e., people with lots of mutual connections) provides information that is relevant but redundant.
Befriending &amp;ldquo;weak ties&amp;rdquo; (i.e., people with few or no mutual connections) provides information that is irrelevant but novel.
Befriending &amp;ldquo;moderate&amp;rdquo; ties balances relevance and redundancy.
It lets you hear about opportunities you find interesting and wouldn&amp;rsquo;t hear otherwise.&lt;/p&gt;
&lt;p&gt;If everyone acts on those opportunities, then we should see the relationship suggested by the &lt;em&gt;Science&lt;/em&gt; study.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Reflections on grad school: Years 1 and 2</title>
      <link>https://bldavies.com/blog/reflections-grad-school-years-1-2/</link>
      <pubDate>Tue, 06 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/reflections-grad-school-years-1-2/</guid>
      <description>&lt;p&gt;This post summarizes the first two years of &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;my PhD program&lt;/a&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
I discuss my &lt;a href=&#34;#first-year-courses&#34;&gt;first&lt;/a&gt;- and &lt;a href=&#34;#second-year-courses&#34;&gt;second&lt;/a&gt;-year coursework, and my &lt;a href=&#34;#quality-of-life&#34;&gt;quality of life&lt;/a&gt; as a grad student.&lt;/p&gt;
&lt;h2 id=&#34;first-year-courses&#34;&gt;First-year courses&lt;/h2&gt;
&lt;p&gt;I spent the first year taking the &amp;ldquo;core&amp;rdquo; micro, macro, and econometrics courses.
Most of their content was familiar from undergrad.
Some of my classmates waived out of courses they&amp;rsquo;d taken before.
I didn&amp;rsquo;t because I hadn&amp;rsquo;t.
I also wanted to be &amp;ldquo;in sync&amp;rdquo; with my classmates: working on the same problems, facing the same stresses, and celebrating the same milestones.&lt;/p&gt;
&lt;p&gt;I found macro the most rewarding and metrics the least.
In macro I learned how to solve dynamic optimization problems.
I used that skill in a &lt;a href=&#34;https://bldavies.com/blog/rationalizing-negative-splits/&#34;&gt;blog post&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/research/D2.pdf&#34;&gt;term paper&lt;/a&gt; on non-macro topics.
In contrast, I&amp;rsquo;m about as good at econometrics as I was before starting my PhD.
I know more ways to compute standard errors, but I&amp;rsquo;ve still never run a diff-in-diff.&lt;/p&gt;
&lt;p&gt;Most of our assessment was via problem sets.
They tended to focus on technical minutiae rather than fundamental insights.
I seldom found them educational.
Working in groups made them &lt;em&gt;less&lt;/em&gt; educational.
In theory, group-work involved discussions that helped everyone learn.
In practice, it involved &amp;ldquo;dividing and conquering:&amp;rdquo; splitting problems among group members to work on alone.&lt;/p&gt;
&lt;p&gt;We had no qualifying or in-person exams.
Some courses had final assignments, but we did them at home.
So I saw no reason to study.
Instead I waited until we got our assignments and learned only what I needed.
I didn&amp;rsquo;t want to waste time studying topics I didn&amp;rsquo;t care about.
And I never forgot what the department chair said on our first day:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Grades don&amp;rsquo;t matter.
What matters is whether you do good research.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;One consequence of not studying was ending the year feeling like I knew &lt;em&gt;less&lt;/em&gt; economics.
I gained more awareness than knowledge, so my ratio of &amp;ldquo;known knowns&amp;rdquo; to &amp;ldquo;known unknowns&amp;rdquo; fell.
But awareness is still useful: I know what keywords to search if I need to learn something in the future.&lt;/p&gt;
&lt;h2 id=&#34;second-year-courses&#34;&gt;Second-year courses&lt;/h2&gt;
&lt;p&gt;I kept taking courses in my second year.
But I got to choose my courses based on the fields I chose to specialize in.
I chose micro theory and behavioral economics.
Some of my reasons were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I like studying simple models of how people behave and interact;&lt;/li&gt;
&lt;li&gt;I&amp;rsquo;d rather argue about &lt;a href=&#34;https://bldavies.com/blog/judging-economic-models/&#34;&gt;modeling assumptions&lt;/a&gt; than external validity;&lt;/li&gt;
&lt;li&gt;Theory and (especially) behavioral courses had the fewest assessments.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I was scared about my career: the job market for theorists, especially behavioral theorists, is notoriously awful.
But I was &lt;em&gt;more&lt;/em&gt; scared of doing research I didn&amp;rsquo;t enjoy.
That said, I viewed field choices as administrative only.
They didn&amp;rsquo;t have to confine my research.
Indeed I &lt;a href=&#34;https://bldavies.com/blog/gender-sorting-economists/&#34;&gt;published a paper&lt;/a&gt; in my second year that was neither theoretical nor behavioral.&lt;/p&gt;
&lt;p&gt;I also had to take &amp;ldquo;distribution&amp;rdquo; courses outside my chosen fields.
Mine were on market design, political economy, and economic history.
I attended some sociology classes because I wanted to meet non-economists who shared my interests.
I met some non-economists (including some who were anti-economists), but none shared my interests.
They also had very different definitions of &amp;ldquo;theory.&amp;rdquo;
But I enjoyed hearing their perspectives.&lt;/p&gt;
&lt;p&gt;The purpose of the second year was to help us transition from being research consumers to producers.
Our assessments reflected that purpose.
They included referee reports, research proposals, and term papers.
Proposals were helpful for organizing and clarifying my ideas.
They weren&amp;rsquo;t helpful for prompting feedback: I submitted six proposals and got comments once.
Instead I got feedback from discussions with professors and classmates.
Those discussions made going to class worthwhile.&lt;/p&gt;
&lt;p&gt;The best discussions were with people who challenged me to think harder.
For example, some professors were known to ask hard questions when students shared their ideas.
At first those professors seemed &amp;ldquo;scary.&amp;rdquo;
Eventually I realized that what made them scary was that they assumed I was intelligent.
They wouldn&amp;rsquo;t let me make hand-wavy arguments or think lazily.
I learned to admire those professors and gravitated to them.
Sometimes they told me my ideas were shallow or wrong.
But I&amp;rsquo;d rather be wrong in class than in print.&lt;/p&gt;
&lt;h2 id=&#34;quality-of-life&#34;&gt;Quality of life&lt;/h2&gt;
&lt;p&gt;People warned me that grad students have no free time.
That has not been my experience.
I&amp;rsquo;ve had plenty of time to exercise, blog, and be unproductive.
I had that time because I chose to minimize my coursework.
I made that choice because (i) grades don&amp;rsquo;t matter (see above), and (ii) I saw coursework as a barrier to doing research and enjoying my life.&lt;/p&gt;
&lt;p&gt;People also warned me that grad students live in poverty.
Again, that has not been my experience.
Stanford pays enough that I can dine out occasionally (even at Palo Alto prices), and can eat more than beans and rice at home.
I can replace my running shoes and socks when they wear out.
I don&amp;rsquo;t have to worry about &lt;a href=&#34;https://bldavies.com/blog/living-america/#healthcare&#34;&gt;hospital bills&lt;/a&gt;.
I feel &lt;em&gt;privileged&lt;/em&gt; rather than poor.
Campus housing is expensive, but Stanford deducts rent from my stipend so I don&amp;rsquo;t notice they&amp;rsquo;re ripping me off.&lt;/p&gt;
&lt;p&gt;In hindsight, I under-appreciated local amenities when I &lt;a href=&#34;https://bldavies.com/blog/applying-economics-phd-programs/&#34;&gt;applied to PhD programs&lt;/a&gt;.
My other options were in Boston, Chicago, and New York.
Stanford definitely wins on the weather front: it&amp;rsquo;s always warm and dry here.
We don&amp;rsquo;t have Chicago&amp;rsquo;s bitter winters or the east coast&amp;rsquo;s humid summers.
I can go outside to unwind whenever I like.
If I couldn&amp;rsquo;t then I&amp;rsquo;d go insane.&lt;/p&gt;
&lt;p&gt;But Stanford loses on the &amp;ldquo;fun place to live&amp;rdquo; front.
&lt;a href=&#34;https://bldavies.com/blog/living-america/#its-always-sunny-in-palo-alto&#34;&gt;Palo Alto is small and suburban&lt;/a&gt;.
It lacks the energy and excitement found in big cities.
San Francisco is an hour away by train, which is fine for days out but a hassle for nights out.
I prefer running to drinking, so I&amp;rsquo;m willing to sacrifice bars for sun.
But that preference is endogenous.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://bldavies.com/blog/reflections-grad-school-years-3-4&#34;&gt;here&lt;/a&gt; for reflections on my third and fourth years. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Paying for the truth</title>
      <link>https://bldavies.com/blog/paying-truth/</link>
      <pubDate>Thu, 01 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/paying-truth/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://bldavies.com/blog/truth-seekers-ideologues/&#34;&gt;previous post&lt;/a&gt;, I showed that if the truth doesn&amp;rsquo;t matter then I&amp;rsquo;m better off being an ideologue with ideological friends.
I discussed the trade-off between (i) experiencing reality and (ii) experiencing what my friends experience.
Truth-seeking made sense only when the benefit of (i) exceeded the cost of forgoing (ii).
This post discusses another cost of truth-seeking: having to pay&amp;mdash;financially, cognitively, or emotionally&amp;mdash;for information.&lt;/p&gt;
&lt;p&gt;One way to model that cost is as follows.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Suppose the truth is determined by a random variable &lt;code&gt;\(\theta\in\{0,1\}\)&lt;/code&gt;.
I learn about &lt;code&gt;\(\theta\)&lt;/code&gt; by observing a signal &lt;code&gt;\(s(x)\in\{0,1\}\)&lt;/code&gt; with precision
&lt;code&gt;$$\Pr(s(x)=\theta)=\frac{1+x}{2}.$$&lt;/code&gt;
The parameter &lt;code&gt;\(x\in[0,1]\)&lt;/code&gt; determines the signal&amp;rsquo;s quality.
If &lt;code&gt;\(x=1\)&lt;/code&gt; then the signal is fully informative; if &lt;code&gt;\(x=0\)&lt;/code&gt; then it is uninformative.&lt;/p&gt;
&lt;p&gt;My prior estimate &lt;code&gt;\(\theta_0\in[0.5,1]\)&lt;/code&gt; of &lt;code&gt;\(\theta\)&lt;/code&gt; is based on no information; it reflects my ideology.
I use the realization of &lt;code&gt;\(s(x)\)&lt;/code&gt; and my prior &lt;code&gt;\(\theta_0\)&lt;/code&gt; to form a posterior estimate
&lt;code&gt;$$\hat\theta(s(x))=\Pr\left(\theta=1\,\vert\,s(x)\right)$$&lt;/code&gt;
via &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;Bayes&amp;rsquo; rule&lt;/a&gt;.
I care about the &lt;a href=&#34;https://en.wikipedia.org/wiki/Mean_squared_error&#34;&gt;mean squared error&lt;/a&gt;
&lt;code&gt;$$\newcommand{\E}{\mathrm{E}} \newcommand{\MSE}{\mathrm{MSE}} \MSE(x)=\E\left[\left(\theta-\hat\theta(s(x))\right)^2\right]$$&lt;/code&gt;
of my posterior estimate, where &lt;code&gt;\(\E\)&lt;/code&gt; is the expectation operator taken with respect to the joint distribution of &lt;code&gt;\(\theta\)&lt;/code&gt; and &lt;code&gt;\(s(x)\)&lt;/code&gt; given my prior &lt;code&gt;\(\theta_0\)&lt;/code&gt;.
But I also care about the cost &lt;code&gt;\(cx\)&lt;/code&gt; I endure from observing a signal of quality &lt;code&gt;\(x\)&lt;/code&gt;.
This cost reflects the resources I use to seek the information and process it (e.g., money, time, and mental energy).
I choose the quality &lt;code&gt;\(x^*\)&lt;/code&gt; that minimizes
&lt;code&gt;$$f(x)=\MSE(x)+cx.$$&lt;/code&gt;
The chart below plots my objective &lt;code&gt;\(f(x)\)&lt;/code&gt; against &lt;code&gt;\(x\)&lt;/code&gt; when I have prior &lt;code&gt;\(\theta_0\in\{0.5,0.7,0.9\}\)&lt;/code&gt; and face marginal cost &lt;code&gt;\(c\in\{0,0.1,0.2,0.3\}\)&lt;/code&gt;.
Since &lt;code&gt;\(f\)&lt;/code&gt; is concave in &lt;code&gt;\(x\)&lt;/code&gt;, it has (constrained) local minima at &lt;code&gt;\(x=0\)&lt;/code&gt; and &lt;code&gt;\(x=1\)&lt;/code&gt;.
My choice between these minima depends on the value of &lt;code&gt;\(c\)&lt;/code&gt;.
If it&amp;rsquo;s small then information is cheap and I &amp;ldquo;buy&amp;rdquo; as much as I can.
If it&amp;rsquo;s large then information is expensive and I don&amp;rsquo;t buy any.
But there&amp;rsquo;s no middle ground: I seek &lt;em&gt;all&lt;/em&gt; the truth or none of it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/objectives-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(c^*\)&lt;/code&gt; be the threshold value of &lt;code&gt;\(c\)&lt;/code&gt; at which I stop paying for information: the &amp;ldquo;choke price&amp;rdquo; of truth.
How does &lt;code&gt;\(c^*\)&lt;/code&gt; depend on my prior &lt;code&gt;\(\theta_0\)&lt;/code&gt;?
Intuitively, increasing &lt;code&gt;\(\theta_0\)&lt;/code&gt; has two competing effects:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it increases the error in my posterior estimate when &lt;code&gt;\(\theta=0\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;it increases my confidence that &lt;code&gt;\(\theta=1\)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first effect makes me &lt;em&gt;want more&lt;/em&gt; information, increasing &lt;code&gt;\(c^*\)&lt;/code&gt;.
The second effect makes me think I &lt;em&gt;need less&lt;/em&gt; information, decreasing &lt;code&gt;\(c^*\)&lt;/code&gt;.
The chart below shows that the second effect dominates.
The more ideological I am about the value of &lt;code&gt;\(\theta\)&lt;/code&gt;, the cheaper the truth must be for me to seek it.
If I&amp;rsquo;m a pure ideologue (i.e., &lt;code&gt;\(\theta_0=1\)&lt;/code&gt;) then I won&amp;rsquo;t seek the truth even if it&amp;rsquo;s free.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/choke-prices-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;One reason the first effect might dominate is if I care about errors when &lt;code&gt;\(\theta=0\)&lt;/code&gt; more than when &lt;code&gt;\(\theta=1\)&lt;/code&gt;.
For example, if &lt;code&gt;\(\theta\)&lt;/code&gt; indicates whether it will be sunny then I&amp;rsquo;d rather bring an umbrella I don&amp;rsquo;t use than be caught wearing flip-flops in the rain.
I can capture that asymmetry by replacing the MSE component of my objective with a weighted version
&lt;code&gt;$$\newcommand{\WMSE}{\mathrm{WMSE}} \WMSE(x)=\E\left[W(\theta)\cdot\left(\theta-\hat\theta(s(x))\right)^2\right],$$&lt;/code&gt;
where the weighting function
&lt;code&gt;$$W(\theta)=\begin{cases} 1 &amp;amp; \text{if}\ \theta=1 \\ w &amp;amp; \text{if}\ \theta=0 \end{cases}$$&lt;/code&gt;
has &lt;code&gt;\(w\ge1\)&lt;/code&gt;.
Increasing &lt;code&gt;\(w\)&lt;/code&gt; nudges my optimal posterior estimate towards zero because I want to avoid being &amp;ldquo;confidently wrong&amp;rdquo; when &lt;code&gt;\(\theta=0\)&lt;/code&gt;.
Since &lt;code&gt;\(\WMSE(x)\)&lt;/code&gt; is concave in &lt;code&gt;\(x\)&lt;/code&gt;, I still optimally pay for all the truth or none of it.
But now the choke price &lt;code&gt;\(c^*\)&lt;/code&gt; at which I stop paying for the truth depends on my prior &lt;code&gt;\(\theta_0\)&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; the error weight &lt;code&gt;\(w\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The chart below shows that &lt;code&gt;\(c^*\)&lt;/code&gt; is non-monotonic in &lt;code&gt;\(\theta_0\)&lt;/code&gt; when &lt;code&gt;\(w\)&lt;/code&gt; is large.
This is due to the two competing effects described above.
The first effect dominates when &lt;code&gt;\(w\)&lt;/code&gt; is large and my prior is low.
In that case, it&amp;rsquo;s really bad to be wrong and I&amp;rsquo;m not confident I&amp;rsquo;ll be right.
Whereas the second effect dominates when &lt;code&gt;\(w\)&lt;/code&gt; is large and my prior is high.
In that case, I&amp;rsquo;m so confident I&amp;rsquo;ll be right that I don&amp;rsquo;t care what happens if I&amp;rsquo;m wrong.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/choke-prices-weighted-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;This example raises a philosophical question: what does it mean for the estimate to be &amp;ldquo;wrong?&amp;rdquo;
For example, suppose I thought there was a 30% chance of rain.
If it rained, was I wrong?
What if I thought there was a 5% chance?
A 95% chance?
Where should I draw the line?
On those questions, I recommend Michael Lewis&amp;rsquo; discussion with Nate Silver about 17 minutes into &lt;a href=&#34;https://www.pushkin.fm/podcasts/against-the-rules/respect-the-polygon&#34;&gt;this podcast episode&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://bldavies.com/blog/paying-precision&#34;&gt;here&lt;/a&gt; for my discussion of the case when &lt;code&gt;\(\theta\)&lt;/code&gt; and &lt;code&gt;\(s\)&lt;/code&gt; are normally distributed. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Why should academics blog?</title>
      <link>https://bldavies.com/blog/academics-blog/</link>
      <pubDate>Sun, 31 Jul 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/academics-blog/</guid>
      <description>&lt;p&gt;I published &lt;a href=&#34;https://bldavies.com/blog/habitat-choices-first-generation-pokemon/&#34;&gt;my first blog post&lt;/a&gt; in March 2018.
Since then I&amp;rsquo;ve spent countless hours planning, drafting, and editing other posts.
Academics might think those hours were wasted:
&amp;ldquo;Why write blog posts when you could write research papers?
Blogging won&amp;rsquo;t get you citations or tenure!&amp;rdquo;
But I disagree with that criticism.
Blogging &lt;em&gt;complements&lt;/em&gt; my research rather than substitutes for it.
Here are seven reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging can lead to papers&lt;/strong&gt;.
&lt;a href=&#34;https://bldavies.com/blog/policymaking-under-uncertainty/&#34;&gt;My post on policymaking under uncertainty&lt;/a&gt; inspired &lt;a href=&#34;https://bldavies.com/blog/covid-19-lockdown-two-sided-uncertainty/&#34;&gt;Arthur Grimes and my paper on COVID-19 lockdowns&lt;/a&gt;.
Blogging about &lt;a href=&#34;https://github.com/bldavies/nberwp/&#34;&gt;nberwp&lt;/a&gt; meant I understood the data and context enough to write &lt;a href=&#34;https://bldavies.com/blog/gender-sorting-economists/&#34;&gt;my paper on gender sorting among economists&lt;/a&gt;.
Discussing the idea for a post with Adam Jaffe led to &lt;a href=&#34;https://bldavies.com/blog/research-funding-collaboration/&#34;&gt;our paper on research funding and collaboration&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging increases my idea turnover&lt;/strong&gt;.
I have lots of research ideas.
Some are worth pursuing and some are &lt;a href=&#34;https://bldavies.com/blog/dead-ends/&#34;&gt;dead ends&lt;/a&gt;.
I sort ideas by &amp;ldquo;testing&amp;rdquo; them: writing down toy models or exploring relevant data.
Blogging lets me run those tests quickly and casually.
It also lets me share my tests with readers.
They can avoid dead ends I&amp;rsquo;ve reached, or salvage ideas I&amp;rsquo;ve abandoned if they see opportunities I don&amp;rsquo;t.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging promotes a creator mindset&lt;/strong&gt;.
When I encounter a new idea, one of my first thoughts is &amp;ldquo;how could I make that a blog post?&amp;rdquo;
Blogging nudges me to think like a creator; to view ideas as opportunities to write something &lt;a href=&#34;https://youtu.be/vtIzMaLkCaM?t=823&#34;&gt;valuable&lt;/a&gt;.
It also nudges me to focus on &lt;em&gt;output&lt;/em&gt; as the source of value.
No matter how long I spend writing posts, no one can read and benefit from them if they&amp;rsquo;re still on my computer.
The goal is to publish.
Academics have a similar goal.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging improves my writing&lt;/strong&gt;.
It gives me practice refining my ideas, (re)structuring arguments, and thinking about my audience.
Writing papers gives me similar practice, but blogging yields the benefits faster because I can write blog posts faster.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging helps me learn&lt;/strong&gt;.
Most of my posts come from wanting to understand something.
Sometimes it&amp;rsquo;s a problem encountered in my research (e.g., &lt;a href=&#34;https://bldavies.com/blog/dyadic-dependence&#34;&gt;dyadic dependence&lt;/a&gt; or &lt;a href=&#34;https://bldavies.com/blog/understanding-selection-bias/&#34;&gt;selection bias&lt;/a&gt;).
Sometimes it&amp;rsquo;s a result from others&amp;rsquo; research (e.g., on &lt;a href=&#34;https://bldavies.com/blog/information-gerrymandering/&#34;&gt;information gerrymandering&lt;/a&gt; or &lt;a href=&#34;https://bldavies.com/blog/improving-human-predictions/&#34;&gt;modeling human predictions&lt;/a&gt;).
Sometimes it&amp;rsquo;s a technical paper (e.g., on &lt;a href=&#34;https://bldavies.com/blog/communicating-science/&#34;&gt;communicating science&lt;/a&gt; or &lt;a href=&#34;https://bldavies.com/blog/research-incentives-evolution-knowledge/&#34;&gt;research incentives&lt;/a&gt;).
Writing blog posts makes me engage with ideas and explain them in my own words.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging helps me connect ideas&lt;/strong&gt;.
Many of my posts build on previous posts.
Sometimes this is clear in advance (as with, e.g., my posts on &lt;a href=&#34;https://bldavies.com/blog/stable-matchings/&#34;&gt;stable matchings&lt;/a&gt; with &lt;a href=&#34;https://bldavies.com/blog/stable-matchings-noisy-preferences/&#34;&gt;noisy&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/stable-matchings-correlated-preferences/&#34;&gt;correlated&lt;/a&gt; preferences).
Sometimes I realize the connection between posts while writing them.
I love discovering how ideas are connected&amp;mdash;indeed I&amp;rsquo;ve blogged about that &lt;a href=&#34;https://bldavies.com/blog/college-degrees-similarity-measures/&#34;&gt;here&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/estimating-research-field-similarities/&#34;&gt;here&lt;/a&gt;&amp;mdash;and view it as an essential research skill.
Blogging helps me practice that skill.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Blogging is fun&lt;/strong&gt;.
(Yes, academics can have fun!)
I enjoy thinking and writing.
Blogging is a way to think and write.
Most important, I can think and write about whatever I like&amp;mdash;I don&amp;rsquo;t have to focus on topics that academics care about.
I can blog about &lt;a href=&#34;https://bldavies.com/blog/birds-voting-russian-interference/&#34;&gt;birds&lt;/a&gt;, &lt;a href=&#34;https://bldavies.com/blog/white-elephant-gift-exchanges/&#34;&gt;gift exchanges&lt;/a&gt;, and &lt;a href=&#34;https://bldavies.com/blog/rationalizing-negative-splits/&#34;&gt;running negative splits&lt;/a&gt;.
I can even blog about &lt;a href=&#34;https://bldavies.com/blog/habitat-choices-first-generation-pokemon&#34;&gt;Pokémon&lt;/a&gt;!
And I get the benefits of thinking and writing without the pressure of academic evaluation.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
</description>
    </item>
    
    <item>
      <title>What&#39;s it like living in America?</title>
      <link>https://bldavies.com/blog/living-america/</link>
      <pubDate>Tue, 26 Jul 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/living-america/</guid>
      <description>&lt;p&gt;Last month I visited New Zealand for the first time since &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;moving to the USA&lt;/a&gt;.
Lots of people asked what living in the USA is like.
Here&amp;rsquo;s what I told them:&lt;/p&gt;
&lt;h2 id=&#34;its-always-sunny-in-palo-alto&#34;&gt;It&amp;rsquo;s always sunny in Palo Alto&lt;/h2&gt;
&lt;p&gt;I live in &lt;a href=&#34;https://en.wikipedia.org/wiki/Palo_Alto%2C_California&#34;&gt;Palo Alto, California&lt;/a&gt;.
It&amp;rsquo;s near San Francisco and part of Silicon Valley.
Palo Alto is officially a &amp;ldquo;city,&amp;rdquo; but it feels suburban: the streets are clean, there are trees everywhere, and most buildings are one or two stories.&lt;/p&gt;
&lt;p&gt;Palo Alto has two main attractions.
One is the weather: the air is warm and dry, it seldom rains, and it never snows.
I don&amp;rsquo;t feel guilty about spending a nice day inside because &lt;em&gt;every&lt;/em&gt; day is a nice day.
(In fact I have the opposite problem: I spend too much time outside running and cycling, and too little inside being productive.)&lt;/p&gt;
&lt;p&gt;The other attraction is &lt;a href=&#34;https://www.stanford.edu&#34;&gt;Stanford University&lt;/a&gt;, where I study.
Most of my interactions are with students and professors.
Yet Palo Alto doesn&amp;rsquo;t feel like a university town: it&amp;rsquo;s easier to find ice cream than beer, and everything is expensive.
The rent on my studio apartment here is more than what I paid for a two-bedroom apartment in the middle of &lt;a href=&#34;https://en.wikipedia.org/wiki/Wellington&#34;&gt;Wellington&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Palo Alto is culturally diverse.
I hear foreign languages daily.
Most of my friends here are from South America or Europe.
Despite being used to hearing different accents, people have trouble with mine: they often think I&amp;rsquo;m named &amp;ldquo;Bin.&amp;rdquo;
(We all feel embarrassed when I have to spell my name, one of the simplest in the English language.)&lt;/p&gt;
&lt;p&gt;In contrast, Palo Altoans seem politically homogeneous.
The Americans I know all vote Democrat; the non-Americans would if they could.
But people signal their politics in different ways.
Some decorate their lawns with &amp;ldquo;climate change is real&amp;rdquo; and &amp;ldquo;black lives matter&amp;rdquo; signs.
Others wear masks while walking alone outside or cycling without a helmet.&lt;/p&gt;
&lt;p&gt;People here seem aware of, and concerned about, social issues plaguing the USA.
But they&amp;rsquo;re also insulated from such issues.
There are no riots.
There are few homeless and no (visible) guns.
No one looks obese.&lt;/p&gt;
&lt;p&gt;Clearly Palo Alto is not representative of the USA.
Other areas have skyscrapers, snow, cheap drinks, Republicans, climate change deniers, and openly carried guns.
I&amp;rsquo;ve visited some cities on the east and west coasts, but nowhere in the south and almost nowhere rural.
So my perspective on living here is biased because my experience is biased.&lt;/p&gt;
&lt;p&gt;But I don&amp;rsquo;t think &lt;em&gt;anywhere&lt;/em&gt; is representative of the USA.
There&amp;rsquo;s so much variety in where people live, how they behave, and what they believe.
I didn&amp;rsquo;t appreciate that variety until moving here.
I thought of the USA similarly to New Zealand: I thought everyone was basically the same, with minor differences in wealth and lifestyle.
I thought wrong.&lt;/p&gt;
&lt;h2 id=&#34;hows-it-different&#34;&gt;How&amp;rsquo;s it different?&lt;/h2&gt;
&lt;p&gt;New Zealand and the USA differ in many ways.
Here are some of my observations:&lt;/p&gt;
&lt;h3 id=&#34;dining-out&#34;&gt;Dining out&lt;/h3&gt;
&lt;p&gt;When I read a restaurant menu in New Zealand, the price I see is the price I pay.
When I read one here, the price I see is about 80% of what I pay.
The last 20% comprises taxes and tips.
Taxes vary by product, store, and state.
Tips vary by (perceived) service quality and social norms.&lt;/p&gt;
&lt;p&gt;The norm in Palo Alto is to tip 18% of the pre-tax price.
I&amp;rsquo;m not sure why the fee for shipping items from kitchen to table depends on the price of the cargo.
&lt;a href=&#34;https://calave.com&#34;&gt;One local menu&lt;/a&gt; reads:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We are a no tipping establishment.
20% service charge will be added to your bill to ensure a better living wage to our staff.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;They could just raise their pre-tax prices by 20%, but then they wouldn&amp;rsquo;t get to virtue signal.
At least they prompt people to multiply by 1.2 before choosing what to order.&lt;/p&gt;
&lt;h3 id=&#34;paying-taxes&#34;&gt;Paying taxes&lt;/h3&gt;
&lt;p&gt;I pay income tax to the state and federal governments.
I use third-party software to avoid the risk of committing fraud by mistake.
That risk exists because both governments already know my taxable income.
They could, like New Zealand&amp;rsquo;s tax office, just fill out my return and have me spend two minutes confirming it.
But then I wouldn&amp;rsquo;t be intimidated into paying an intermediary to organize my financial data.
I&amp;rsquo;m fortunate in that Stanford pays on my behalf.
Others in the USA are less fortunate.&lt;/p&gt;
&lt;h3 id=&#34;healthcare&#34;&gt;Healthcare&lt;/h3&gt;
&lt;p&gt;Stanford also pays for my health insurance.
I&amp;rsquo;d hate to be uninsured:
I broke my wrist last year, and my hospital and surgery fees totalled just under 100,000 USD (currently about 160,000 NZD).
But I had surgery just three days after my accident; in New Zealand I&amp;rsquo;d have paid almost nothing but waited weeks.
Sometimes you get what you pay for.&lt;/p&gt;
&lt;p&gt;(As an aside:
My surgeon prescribed oxycodone, a pain-relieving opiate.
I paid 1.25 USD for 20 days&amp;rsquo; worth.
That payment helped me understand why the USA has an &lt;a href=&#34;https://en.wikipedia.org/wiki/Opioid_epidemic_in_the_United_States&#34;&gt;opioid epidemic&lt;/a&gt;.)&lt;/p&gt;
&lt;h3 id=&#34;talking-to-strangers&#34;&gt;Talking to strangers&lt;/h3&gt;
&lt;p&gt;In New Zealand it is (mostly) socially acceptable to talk to strangers.
People trust each other.
If you&amp;rsquo;re approached by someone you don&amp;rsquo;t know, they probably don&amp;rsquo;t want anything from you (other than, say, directions).
They usually just want to chat.&lt;/p&gt;
&lt;p&gt;In the USA, it seems (mostly) socially &lt;em&gt;unacceptable&lt;/em&gt; to talk to strangers.
People &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; trust each other.
If you&amp;rsquo;re approached by someone you don&amp;rsquo;t know, they probably want something from you.
They might want to chat, but only to build rapport before advancing their agenda.&lt;/p&gt;
&lt;h3 id=&#34;talking-generally&#34;&gt;Talking generally&lt;/h3&gt;
&lt;p&gt;Americans (and other non-New Zealanders) use &amp;ldquo;how are you&amp;rdquo; as a greeting rather than a question.
They don&amp;rsquo;t actually want to know; they just want you to say &amp;ldquo;good&amp;rdquo; or &amp;ldquo;fine,&amp;rdquo; and move on.
Replying &amp;ldquo;bad&amp;rdquo; would make the greeter&amp;rsquo;s day worse.
I hear &amp;ldquo;how are you&amp;rdquo; most often when walking past people I know.
They usually don&amp;rsquo;t stop and wait for an answer.
I&amp;rsquo;m still learning not to take offense.&lt;/p&gt;
&lt;p&gt;Likewise I&amp;rsquo;m still adjusting to how Americans receive thanks.
New Zealanders always reply &amp;ldquo;you&amp;rsquo;re welcome.&amp;rdquo;
Americans always reply &amp;ldquo;sure&amp;rdquo; or &amp;ldquo;of course.&amp;rdquo;
I find those responses dismissive and rude.
They suggest my thanks were unnecessary and I&amp;rsquo;ve wasted my time offering them.
Whereas I think Americans want to avoid a sense of reliance: they don&amp;rsquo;t want me to think I owe them anything in return.&lt;/p&gt;
&lt;h3 id=&#34;scenery&#34;&gt;Scenery&lt;/h3&gt;
&lt;p&gt;Most people I&amp;rsquo;ve met know New Zealand is scenic and beautiful.
Scenery in the USA&amp;mdash;at least, the scenery I&amp;rsquo;ve seen&amp;mdash;is not as beautiful.
But the USA has something New Zealand doesn&amp;rsquo;t: &lt;em&gt;scale&lt;/em&gt;.
&lt;a href=&#34;https://en.wikipedia.org/wiki/Sequoioideae&#34;&gt;Redwoods&lt;/a&gt; are huge.
Big Sur is huge.
New York City&amp;rsquo;s skyline is huge.
New Zealand&amp;rsquo;s main scenic attractions&amp;mdash;glaciers, lakes, and national parks&amp;mdash;are not as huge.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Research incentives and the evolution of knowledge</title>
      <link>https://bldavies.com/blog/research-incentives-evolution-knowledge/</link>
      <pubDate>Fri, 22 Jul 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/research-incentives-evolution-knowledge/</guid>
      <description>&lt;p&gt;Research is a cumulative process.
New discoveries build on previous discoveries: researchers &amp;ldquo;stand on the shoulders of giants.&amp;rdquo;
&lt;a href=&#34;https://arxiv.org/abs/2102.13434&#34;&gt;Carnehl and Schneider (2022)&lt;/a&gt; embed this idea in a model of how knowledge evolves.
In their model, knowledge is the set of questions with known answers and research is the process of finding answers.
The model has three main features:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Existing knowledge determines the benefits and costs of research.&lt;/li&gt;
&lt;li&gt;Answering a question sheds light on related questions.&lt;/li&gt;
&lt;li&gt;Researchers are free to choose which questions to ask and how intensely to seek answers.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The authors first discuss the social benefit of research.
They think of society as an agent who makes policy choices.
These choices appear as questions:
How much should we tax companies?
How much should we subsidize healthcare?
Society knows the answer to some questions but is uncertain about the answer to others.
This uncertainty means society has to guess which policies are best.
Research is beneficial insofar as it leads to better guesses.
It does so through two channels:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It reveals the answer to the researched questions.&lt;/li&gt;
&lt;li&gt;It lowers the uncertainty around answers to other questions.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Society is more certain about answers to questions that are &amp;ldquo;closer&amp;rdquo; to existing knowledge.
Intuitively, knowing how much to tax companies tells you more about taxing households than about building rockets.
Research removes more uncertainty for questions closer to those researched.
Carnehl and Schneider measure the benefit of research as the total amount of uncertainty it removes.&lt;/p&gt;
&lt;p&gt;Next, the authors compare the benefits of research that &amp;ldquo;deepens&amp;rdquo; and &amp;ldquo;expands&amp;rdquo; knowledge.
They model questions as points on the real line and the &amp;ldquo;frontier&amp;rdquo; as the extremal points of existing knowledge.
Research on questions between these extremal points deepens knowledge; research on questions beyond the frontier expands knowledge.
The relative benefits of deepening and expanding depend on the gaps in existing knowledge.
Deepening is more beneficial when gaps are large.
This is because larger gaps leave more uncertainty to remove.
Splitting a large gap into smaller gaps removes more uncertainty than creating a new gap at the frontier.&lt;/p&gt;
&lt;p&gt;Carnehl and Schneider then consider researchers&amp;rsquo; choices:
What questions do they ask?
How intensely do they seek answers?
These choices depend on the private benefits and costs of research.
The authors assume private benefits equal social benefits.
They also assume private costs rise with search intensity and existing uncertainty.
More intense searches are more likely to succeed.
But, for a given likelihood, more uncertain answers need wider searches.
Carnehl and Schneider characterize researchers&amp;rsquo; optimal choices in two dimensions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Novelty:&amp;rdquo; how far is the chosen question from existing knowledge?&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Output:&amp;rdquo; how likely is the research to succeed?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The relationship between novelty and output depends on whether the research expands or deepens knowledge.
If it expands knowledge, then novelty and output are substitutes: more novel research is always riskier.
If it deepens knowledge, then whether novelty and output are substitutes depends on the size of the gap being filled.
This dependence is intricate&amp;mdash;see &lt;a href=&#34;https://arxiv.org/abs/2102.13434&#34;&gt;the paper&lt;/a&gt; for details.&lt;/p&gt;
&lt;p&gt;Finally, the authors use their model to study how researchers&amp;rsquo; choices affect how knowledge evolves.
Carnehl and Schneider&amp;rsquo;s key insight is that short- and long-run choices differ.
Short-lived researchers choose questions that maximize private benefits less private costs.
But they don&amp;rsquo;t consider the impact their choices have on future researchers&amp;rsquo; choices.
This impact arises from lowering the uncertainty for some questions but not others.
Long-lived researchers internalize the impact their choices today have on choices tomorrow.
The authors show that rewarding &amp;ldquo;moonshots&amp;rdquo;&amp;mdash;research on questions more novel than myopically optimal&amp;mdash;can raise the present value of future knowledge.&lt;/p&gt;
&lt;p&gt;Overall, the paper is impressive.
Its introduction gives a clear summary of the main results.
The model is creative and crisp.
Like all &lt;a href=&#34;https://bldavies.com/blog/judging-economic-models/&#34;&gt;good models&lt;/a&gt;, it focuses on one issue&amp;mdash;the cumulative nature of research&amp;mdash;and abstracts from others&amp;mdash;e.g., the &lt;a href=&#34;https://en.wikipedia.org/wiki/Scientific_priority&#34;&gt;priority system&lt;/a&gt; and career concerns.
The paper is also a rare theoretical contribution to the (mostly empirical) literature on the economics of science.&lt;/p&gt;
&lt;p&gt;Carnehl and Schneider&amp;rsquo;s model could be extended to acknowledge the &lt;a href=&#34;https://en.wikipedia.org/wiki/Replication_crisis&#34;&gt;replication crisis&lt;/a&gt;.
Their model assumes all research findings are certain and true.
But the crisis exists because some findings are &lt;em&gt;false&lt;/em&gt;.
We discover false findings via replication studies.
These studies have &lt;em&gt;zero&lt;/em&gt; novelty, but can still be beneficial: they remove uncertainty around findings we think are true.&lt;/p&gt;
&lt;p&gt;Allowing for uncertain findings would then help us think about replication incentives.
Some economists argue they need to be stronger&amp;mdash;see, e.g., &lt;a href=&#34;https://doi.org/10.20955/wp.2015.016&#34;&gt;Zimmerman (2015)&lt;/a&gt;.
But whether to incentivize replication studies depends on the benefits they offer relative to original research.
If society is confident a finding is true, then replicating it may be less beneficial than producing novel findings.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Truth-seekers and ideologues</title>
      <link>https://bldavies.com/blog/truth-seekers-ideologues/</link>
      <pubDate>Mon, 18 Jul 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/truth-seekers-ideologues/</guid>
      <description>&lt;p&gt;People learn socially: they get information from their friends.
Research on social learning takes as given that people want to learn the truth.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
This assumption motivates worries about online misinformation: if your friends see something wrong and share it with you, then you might believe it and be wrong too.&lt;/p&gt;
&lt;p&gt;But people share for more reasons than learning.
Sometimes we share to feel connected: to let each other know we&amp;rsquo;re not alone in what we see.
We enjoy having &lt;a href=&#34;https://bldavies.com/blog/polarized-beliefs-social-networks/&#34;&gt;like-minded friends&lt;/a&gt; who have relatable experiences and validate ours.
But if we &lt;em&gt;only&lt;/em&gt; talk to like-minded friends then it&amp;rsquo;s hard to learn the truth because no one challenges our subjective experiences of objective reality.&lt;/p&gt;
&lt;p&gt;Thus, when forming social networks, we face a trade-off.
We want friends with similar experiences because they help us feel connected.
But we also want friends with &lt;em&gt;different&lt;/em&gt; experiences because they help us learn the truth.
How we resolve this trade-off depends on how much we care about the truth.
If we care a lot then we should choose friends with unbiased experiences;
if we don&amp;rsquo;t care at all then we should choose friends who share our biases.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a basic model to illustrate.
Imagine reality is chosen by a coin toss: Heads or Tails, each with probability 0.5.
There are two types of people:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Truth-seekers&amp;rdquo; try to see the world for what it is.
But they do so noisily: their experience matches reality with probability &lt;code&gt;\(a&amp;gt;0.5\)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Ideologues&amp;rdquo; always see the world the same way: they always experience Heads.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These types represent two extremes:
truth-seekers have unbiased but noisy experiences, whereas ideologues have biased but precise experiences.
I choose a friend to help me win one of two games:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &amp;ldquo;learning&amp;rdquo; game, I win if my friend&amp;rsquo;s experience matches reality.&lt;/li&gt;
&lt;li&gt;In the &amp;ldquo;connecting&amp;rdquo; game, I win if my friend shares my experience.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I want to maximize my chance of winning the game we play.
But I don&amp;rsquo;t know &lt;em&gt;which&lt;/em&gt; we&amp;rsquo;ll play until I&amp;rsquo;ve chosen my friend.
Which type should I choose?&lt;/p&gt;
&lt;p&gt;If I&amp;rsquo;m a truth-seeker then I&amp;rsquo;m better off choosing a truth-seeking friend.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
They&amp;rsquo;re better in the learning game because they&amp;rsquo;re more likely than ideologues to experience reality.
They&amp;rsquo;re &lt;em&gt;also&lt;/em&gt; better in the connecting game because we &lt;em&gt;both&lt;/em&gt; tend to experience reality.
Our pursuit for truth makes our experiences correlated.
In contrast, ideologues&amp;rsquo; indifference to the truth makes their experience &lt;em&gt;uncorrelated&lt;/em&gt; with mine.&lt;/p&gt;
&lt;p&gt;Things are different if I&amp;rsquo;m an ideologue.
Then my best choice depends on how likely I am to play each game.
Let &lt;code&gt;\(p\)&lt;/code&gt; be the probability I play the learning game.
I&amp;rsquo;m better off choosing a truth-seeking friend if and only if &lt;code&gt;\(p\)&lt;/code&gt; exceeds&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$\overline{p}\equiv \frac{1}{2a}.$$&lt;/code&gt;
Intuitively, I face a trade-off:
Truth-seekers are better in the learning game for the same reason as above.
But now &lt;em&gt;ideologues&lt;/em&gt; are better in the connecting game because they always share my ideological experience.
This trade-off tilts in favor of truth-seekers as their accuracy &lt;code&gt;\(a\)&lt;/code&gt; rises, lowering the threshold probability &lt;code&gt;\(\overline{p}\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now suppose I can choose my &lt;em&gt;own&lt;/em&gt; type.
Should I be a truth-seeker or an ideologue?
Again, my choice depends on the probability &lt;code&gt;\(p\)&lt;/code&gt; that I play the learning game.
It turns out I&amp;rsquo;m better off seeking truth if and only if &lt;code&gt;\(p\)&lt;/code&gt; exceeds another threshold &lt;code&gt;\(\underline{p}\)&lt;/code&gt; that depends on &lt;code&gt;\(a\)&lt;/code&gt;.&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;
This threshold has two interesting properties:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It&amp;rsquo;s positive, so if &lt;code&gt;\(p\)&lt;/code&gt; is small enough then I&amp;rsquo;m better off being an ideologue.&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s smaller than &lt;code&gt;\(\overline{p}\)&lt;/code&gt;, so &lt;em&gt;if&lt;/em&gt; I&amp;rsquo;m better off being an ideologue then I&amp;rsquo;m &lt;em&gt;also&lt;/em&gt; better off choosing an ideologue as my friend.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Intuitively, if the truth doesn&amp;rsquo;t matter then there&amp;rsquo;s no point seeking it.
I might as well be an ideologue and choose ideological friends who always share my experience.&lt;/p&gt;
&lt;p&gt;One can extend this model to choosing many friends with a range of accuracies and biases.
Some people might be more truth-seeking than others.
Some people might have correlated experiences because they get information from the same &lt;a href=&#34;https://bldavies.com/blog/ideological-bias-trust-information-sources/&#34;&gt;like-minded sources&lt;/a&gt;.
These correlations determine the &amp;ldquo;experience portfolio&amp;rdquo; my friends can provide.
But the goal of this portfolio&amp;mdash;whether I want it to provide truth or connection&amp;mdash;still depends on how much I care about learning the truth.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Indeed this assumption motivates the extensive literature on social learning &amp;ldquo;failures.&amp;rdquo;
These failures arise from, e.g.,
unequal influence (&lt;a href=&#34;https://doi.org/10.1093/restud/rdr004&#34;&gt;Acemoglu et al., 2011&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1257/mic.2.1.112&#34;&gt;Golub and Jackson, 2010&lt;/a&gt;),
network structure (&lt;a href=&#34;https://doi.org/10.3982/ECTA14407&#34;&gt;Chandrasekhar et al., 2020&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1145/3505156.3505163&#34;&gt;Dasaratha and He, 2021&lt;/a&gt;),
herding (&lt;a href=&#34;https://doi.org/10.2307/2118364&#34;&gt;Banerjee, 1992&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1086/261849&#34;&gt;Bikhchandani et al., 1992&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1111/1468-0262.00113&#34;&gt;Smith and Sørensen, 2000&lt;/a&gt;),
conformity (&lt;a href=&#34;https://doi.org/10.1007/s10670-019-00167-6&#34;&gt;Mohseni and Williams, 2021&lt;/a&gt;),
misinformation (&lt;a href=&#34;https://doi.org/10.1287/mnsc.2022.4340&#34;&gt;Mostagir and Siderius, 2022&lt;/a&gt;),
and misinterpretation (&lt;a href=&#34;https://doi.org/10.3982/ECTA16981&#34;&gt;Frick et al., 2020&lt;/a&gt;). &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Choosing another truth-seeker makes me win the learning game with probability &lt;code&gt;\(a\)&lt;/code&gt; and the connecting game with probability &lt;code&gt;\(a^2+(1-a)^2\)&lt;/code&gt;.
Both of these probabilities exceed 0.5, the probability of winning either game if I choose an ideologue. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;If I&amp;rsquo;m an ideologue, then my &lt;em&gt;ex ante&lt;/em&gt; chance of winning is &lt;code&gt;\(pa+0.5(1-p)\)&lt;/code&gt; if I choose a truth-seeking friend and &lt;code&gt;\(0.5p+(1-p)\)&lt;/code&gt; if I choose another ideologue. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The exact probability is
&lt;code&gt;$$\underline{p}\equiv \frac{4a(1-a)}{2a-1+4a(1-a)}.$$&lt;/code&gt;
It comes from comparing the truth-seeker&amp;rsquo;s indirect objective
&lt;code&gt;$$pa+(1-p)(a^2+(1-a)^2)$$&lt;/code&gt;
and the ideologue&amp;rsquo;s indirect objective
&lt;code&gt;$$\begin{cases}pa+0.5(1-p)&amp;amp;\text{if}\ p\ge\overline{p}\\0.5p+(1-p)&amp;amp;\text{otherwise}.\end{cases}$$&lt;/code&gt;
These functions coincide when &lt;code&gt;\(p\in\{\underline{p},1\}\)&lt;/code&gt;. &lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Gender sorting among economists</title>
      <link>https://bldavies.com/blog/gender-sorting-economists/</link>
      <pubDate>Fri, 03 Jun 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/gender-sorting-economists/</guid>
      <description>&lt;p&gt;I have a &lt;a href=&#34;https://doi.org/10.1016/j.econlet.2022.110640&#34;&gt;new paper&lt;/a&gt; on gender sorting in economic research teams.
Here&amp;rsquo;s the abstract:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I compare the co-authorship patterns of male and female economists, using historical data on National Bureau of Economic Research working papers.
Men tended to work in smaller teams than women, but co-authored more papers and so had more co-authors overall.
Both men and women had more same-gender co-authors than we would expect if co-authorships were random.
This was especially true for men in Macro/Finance.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I show that the NBER co-authorship network is &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortatively mixed&lt;/a&gt; with respect to gender, and has been since the late 1980s.
This could reflect explicit choices to work in same-gender teams.
But it could also be a consequence of other choices (e.g., which topics to research) that lead to gender sorting.
I leave this distinction open for future research.&lt;/p&gt;
&lt;p&gt;The paper uses data from &lt;a href=&#34;https://github.com/bldavies/nberwp/&#34;&gt;nberwp&lt;/a&gt;, an R package I&amp;rsquo;ve been working on since 2019.
I&amp;rsquo;ve described and used the package in several blog posts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/introducing-nberwp/&#34;&gt;Introducing nberwp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/nber-co-authorships/&#34;&gt;NBER (co-)authorships&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/triadic-closure-nber/&#34;&gt;Triadic closure at the NBER&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/female-representation-collaboration-nber/&#34;&gt;Female representation and collaboration at the NBER&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/nberwp-cran/&#34;&gt;nberwp is now on CRAN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/nberwp-1-1-0/&#34;&gt;nberwp 1.1.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/publication-outcomes-nber-working-papers&#34;&gt;Publication outcomes of NBER working papers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bldavies.com/blog/gender-differences-publication-rates-nber-programs/&#34;&gt;Gender differences in publication rates within NBER programs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The paper is in &lt;a href=&#34;https://www.sciencedirect.com/journal/economics-letters&#34;&gt;&lt;em&gt;Economics Letters&lt;/em&gt;&lt;/a&gt;, which publishes concise papers at most 2,000 words long.
This seemed appropriate for my paper: it&amp;rsquo;s longer than a blog post but shorter than an &lt;a href=&#34;https://www.aeaweb.org/journals/aer&#34;&gt;&lt;em&gt;AER&lt;/em&gt;&lt;/a&gt; epic.
The few words mask the many hours spent collecting and cleaning the data (e.g., manually identifying about 2,500 authors&amp;rsquo; genders).
Such is the nature of publishing empirical work.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Gender differences in publication rates within NBER programs</title>
      <link>https://bldavies.com/blog/gender-differences-publication-rates-nber-programs/</link>
      <pubDate>Sat, 28 May 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/gender-differences-publication-rates-nber-programs/</guid>
      <description>&lt;p&gt;My &lt;a href=&#34;https://bldavies.com/blog/publication-outcomes-nber-working-papers/&#34;&gt;previous post&lt;/a&gt; showed that NBER research programs with higher female representation tend to have fewer papers published in the &amp;ldquo;Top Five&amp;rdquo; economics journals.
A reader suggested comparing Top Five publication rates among men and women &lt;em&gt;within&lt;/em&gt; each program.
This comparison reveals whether men and women publish at different rates despite writing about similar topics.
Here&amp;rsquo;s the chart:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/top-fives-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Most points lie below the dashed diagonal line.
Such points represent programs in which male-authored papers are more likely to be in Top Fives than female-authored papers.
This &amp;ldquo;male premium&amp;rdquo; in Top Five publication rates doesn&amp;rsquo;t appear to differ between programs in the &amp;ldquo;Micro&amp;rdquo; and &amp;ldquo;Macro/Finance&amp;rdquo; subfields defined in &lt;a href=&#34;https://doi.org/10.31235/osf.io/zeb7a&#34;&gt;Davies (2022)&lt;/a&gt;.
The premium is largest for the Corporate Finance (CF) program and most negative for the Development of the American Economy (DAE) program.&lt;/p&gt;
&lt;p&gt;How do these patterns compare to publication rates across &lt;em&gt;all&lt;/em&gt; journals?
Here&amp;rsquo;s the corresponding chart:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/all-journals-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Looking at all journals, rather than only Top Fives, lowers the &amp;ldquo;male premium&amp;rdquo; in publication rates.
It also reveals differences between subfields: some Micro programs have negative premia, but all Macro/Finance programs have positive premia.&lt;/p&gt;
&lt;p&gt;What explains these patterns?
Here are two theories:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Women submit papers to Top Fives less often.
This would be consistent with evidence that women shy away from competition relative to equally competent men (see, e.g., &lt;a href=&#34;https://doi.org/10.1146/annurev-economics-111809-125122&#34;&gt;Niederle and Vesterlund, 2011&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Top Five referees and editors discriminate against women.
This would be consistent with evidence that women are held to higher editorial standards (&lt;a href=&#34;https://doi.org/10.1093/qje/qjz035&#34;&gt;Card et al., 2020&lt;/a&gt;; &lt;a href=&#34;https://ideas.repec.org/p/cam/camdae/1753.html&#34;&gt;Hengel, 2017&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Unfortunately I can&amp;rsquo;t test these theories with my data.
I observe publication outcomes, but not journal submissions or referee/editor biases.
And the two theories aren&amp;rsquo;t mutually exclusive: women may submit less often &lt;em&gt;because&lt;/em&gt; they anticipate discrimination.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Publication outcomes of NBER working papers</title>
      <link>https://bldavies.com/blog/publication-outcomes-nber-working-papers/</link>
      <pubDate>Tue, 17 May 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/publication-outcomes-nber-working-papers/</guid>
      <description>&lt;p&gt;The latest version of &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;nberwp&lt;/a&gt; (1.2.0) contains information on where NBER working papers are published:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Outlet&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Papers&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Share (%)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Top Five journals&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3,832&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Other journals&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14,792&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;49.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Book/chapters&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3,096&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Unpublished&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8,363&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;27.8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;About 62% of working papers are published or forthcoming in peer-reviewed journals.
One in five of these papers are in the &amp;ldquo;Top Five:&amp;rdquo; the &lt;a href=&#34;https://www.aeaweb.org/journals/aer&#34;&gt;&lt;em&gt;American Economic Review&lt;/em&gt;&lt;/a&gt;, &lt;a href=&#34;https://www.econometricsociety.org/publications/econometrica/browse&#34;&gt;&lt;em&gt;Econometrica&lt;/em&gt;&lt;/a&gt;, the &lt;a href=&#34;https://www.journals.uchicago.edu/loi/jpe&#34;&gt;&lt;em&gt;Journal of Political Economy&lt;/em&gt;&lt;/a&gt;, the &lt;a href=&#34;https://academic.oup.com/qje/issue&#34;&gt;&lt;em&gt;Quarterly Journal of Economics&lt;/em&gt;&lt;/a&gt;, and the &lt;a href=&#34;https://academic.oup.com/restud/issue&#34;&gt;&lt;em&gt;Review of Economic Studies&lt;/em&gt;&lt;/a&gt;.
These journals are the tallest peaks in the world of economic research.
Publishing in them &lt;a href=&#34;https://www.aeaweb.org/research/charts/publishing-promotion-economics-top-five&#34;&gt;can be vital for career progression&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The chart below counts papers by decade and publication outcome.
As the number of NBER working papers grew, so did the number appearing in journals and the Top Five.
Yet the space available in Top Fives was relatively constant between the 1970s and 2010s (&lt;a href=&#34;https://doi.org/10.1257/jel.51.1.144&#34;&gt;Card and DellaVigna, 2013&lt;/a&gt;).
NBER working papers occupied an increasing share of that space.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/decade-counts-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Why are so many NBER working papers in the Top Five?
Here are four possible reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The NBER working paper series is among &lt;a href=&#34;https://logec.repec.org/scripts/seriesstat.pf&#34;&gt;the most read series&lt;/a&gt; in economics.
More readers means more feedback, which helps authors improve their papers and make them Top Five-worthy.&lt;/li&gt;
&lt;li&gt;Each paper has an NBER-affiliated author.
&amp;ldquo;Affiliates are selected through a rigorous and competitive process&amp;rdquo; (see &lt;a href=&#34;https://www.nber.org/affiliated-scholars&#34;&gt;here&lt;/a&gt;).
This process may select authors more willing and able to pursue Top Five publications.&lt;/li&gt;
&lt;li&gt;NBER working papers tend to apply cutting-edge methods to policy-relevant issues.
This makes papers attractive to Top Five editors, who want to publish frontier, impactful research.&lt;/li&gt;
&lt;li&gt;Top Five editors tend to be NBER affiliates.
Club co-membership might help authors during peer-review.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;gender-differences&#34;&gt;Gender differences&lt;/h2&gt;
&lt;p&gt;nberwp contains information on author genders, so we can compare the representation of women among papers with different publication outcomes.
Here&amp;rsquo;s one approach:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Compute the fraction of authors on each paper who were women.&lt;/li&gt;
&lt;li&gt;Sum these fractions across all papers.&lt;/li&gt;
&lt;li&gt;Divide by the number of papers.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These three steps deliver an estimate of the share of papers written by women.
This estimate equals 16.5% across all NBER working papers.
The chart below separates by decade and publication outcome.
Female representation grew over time, both overall and among papers published in journals.
But the growth was slower among papers published in the Top Five.
Women were consistently less represented among papers published in the Top Five than among other papers.
Overall, only 12.5% of NBER working papers in the Top Five were written by women.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/female-representation-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;What explains the relative gender gap for papers in the Top Five?
Perhaps it reflects what men and women write about.
One way to explore this is to compare female representation and Top Five publication rates across the NBER&amp;rsquo;s &lt;a href=&#34;https://www.nber.org/programs-projects/programs-working-groups&#34;&gt;research programs&lt;/a&gt;, which &amp;ldquo;correspond loosely to traditional field[s] of study within economics.&amp;rdquo;
I present that comparison in the chart below.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
The horizontal axis measures female representation using the estimator defined above; the vertical axis measures the share of papers in each program published in the Top Five.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/programs-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Programs with lower female representation tend to have proportionally more papers in the Top Five.
The Monetary Economics (ME) program, which has the lowest female representation, has more papers in the Top Five than the program on Children (CH), which has the highest female representation.
Papers in the Economic Fluctuations and Growth (EFG) program tend to focus on &amp;ldquo;big picture&amp;rdquo; questions and often land in Top Fives.
Papers in the Health Economics (HE) program tend to focus on more specific questions, and often land in field or medical journals.
But papers in the HE program are about three times as likely to be written by women than are papers in the EFG program.
This difference in likelihoods contributes to lower female representation among NBER working papers published in the Top Five.&lt;/p&gt;
&lt;p&gt;But &lt;em&gt;why&lt;/em&gt; are the likelihoods different?
Why do proportionally fewer women write papers on growth than on children?
Perhaps this reflects what men and women enjoy researching.
But, again, publishing in the Top Five can be vital for career progression.
So, at the margin, I&amp;rsquo;d expect researchers to choose topics more likely to land in Top Five journals.
These choices do not appear in my data.
I&amp;rsquo;m interested to learn more&amp;mdash;&lt;a href=&#34;mailto:bldavies@stanford.edu&#34;&gt;reach out&lt;/a&gt; if you are too.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I compare publication rates among men and women &lt;em&gt;within&lt;/em&gt; each program &lt;a href=&#34;https://bldavies.com/blog/gender-differences-publication-rates-nber-programs&#34;&gt;here&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Judging economic models</title>
      <link>https://bldavies.com/blog/judging-economic-models/</link>
      <pubDate>Mon, 16 May 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/judging-economic-models/</guid>
      <description>&lt;p&gt;Lots of people criticize &lt;a href=&#34;https://bldavies.com/blog/what-economic-model&#34;&gt;economic models&lt;/a&gt; for being unrealistic.
&amp;ldquo;Humans are irrational,&amp;rdquo; they cry; &amp;ldquo;financial markets are inefficient.&amp;rdquo;
These criticisms are valid, but they miss the point.
Models aren&amp;rsquo;t &lt;em&gt;meant&lt;/em&gt; to be realistic.
They&amp;rsquo;re meant to simplify reality: to focus our attention on what&amp;rsquo;s relevant and abstract from what isn&amp;rsquo;t.
&lt;a href=&#34;https://en.wikipedia.org/wiki/All_models_are_wrong&#34;&gt;All models are wrong&lt;/a&gt;&amp;mdash;we shouldn&amp;rsquo;t judge them for their realism.&lt;/p&gt;
&lt;p&gt;How &lt;em&gt;should&lt;/em&gt; we judge a model?
Here are two criteria:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it makes predictions that agree with data;&lt;/li&gt;
&lt;li&gt;it helps us think clearly about how the world works.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Economists use models to generate predictions, such as &amp;ldquo;people buy less when prices rise.&amp;rdquo;
We test these predictions using data from the real world.
When the predictions and data disagree, we reject the model and search for something better.
This search leads to new models with new predictions.
Under the first criterion, &amp;ldquo;better&amp;rdquo; models make more true predictions.&lt;/p&gt;
&lt;p&gt;Model predictions come in different forms.
&amp;ldquo;Within-sample&amp;rdquo; predictions tell us about data we&amp;rsquo;ve seen; &amp;ldquo;out-of-sample&amp;rdquo; predictions tell us what to expect in data we &lt;em&gt;haven&amp;rsquo;t&lt;/em&gt; seen.&lt;/p&gt;
&lt;p&gt;We test within-sample predictions by asking if the model &amp;ldquo;fits&amp;rdquo; the data it was designed to explain.
Bad models fail this test.
But useless models can pass it.
For example, suppose I have a list of quantity-price pairs.
I use the list as my &amp;ldquo;model&amp;rdquo; of demand.
My model fits the data because the data fit the data.
But my model says nothing about &lt;em&gt;why&lt;/em&gt; people buy a given quantity at a given price.
It also says nothing about how much people buy at &lt;em&gt;other&lt;/em&gt; prices.&lt;/p&gt;
&lt;p&gt;Hence, we also test out-of-sample predictions.
We ask if the model fits relevant data it &lt;em&gt;wasn&amp;rsquo;t&lt;/em&gt; designed to explain.
This helps us learn whether the model captures general principles rather than contextual quirks.
It also helps us be logically consistent.
For example, suppose I want to explain some pattern Y.
I write down a model in which I assume behavior X, which implies Y.
But X &lt;em&gt;also&lt;/em&gt; implies pattern Z.
Do I think Z is reasonable?
Do I observe it empirically?
If not, then I should revise my model and not assume X.
Writing down the model makes my assumptions explicit and easier to correct.&lt;/p&gt;
&lt;p&gt;The second criterion makes room for some models with false predictions.
The &lt;a href=&#34;https://en.wikipedia.org/wiki/Efficient-market_hypothesis&#34;&gt;efficient market hypothesis&lt;/a&gt; is a good example.
It predicts that you can&amp;rsquo;t use public information to &amp;ldquo;beat the market.&amp;rdquo;
This prediction is false&amp;mdash;&lt;a href=&#34;https://en.wikipedia.org/wiki/Renaissance_Technologies&#34;&gt;RenTech&lt;/a&gt; offers one counter-example.
But the EMH helps us organize our thoughts about how, when, and why prices incorporate information.
It guides our intuitions.
It also provides a benchmark against which to compare models of &lt;em&gt;in&lt;/em&gt;efficient markets.&lt;/p&gt;
&lt;p&gt;Another benchmark model is that of &lt;a href=&#34;https://bldavies.com/blog/degroot-learning-social-networks/&#34;&gt;DeGroot learning&lt;/a&gt;.
Its main prediction&amp;mdash;&amp;ldquo;under some conditions, society reaches a consensus eventually&amp;rdquo;&amp;mdash;is hard to test because &amp;ldquo;eventually&amp;rdquo; never arrives.
But the model offers a tractable (and &lt;a href=&#34;https://doi.org/10.3982/ECTA14407&#34;&gt;surprisingly realistic&lt;/a&gt;) way to study how people learn.
We can enrich the model by adding &lt;a href=&#34;https://doi.org/10.1093/qje/qjs021&#34;&gt;homophily&lt;/a&gt; or &lt;a href=&#34;https://doi.org/10.1287/mnsc.2022.4340&#34;&gt;misinformation&lt;/a&gt;.
These additions make the model more realistic but more complex.
Having a benchmark helps us assess whether the extra realism is &amp;ldquo;worth&amp;rdquo; the extra complexity (e.g., by adding explanatory power).&lt;/p&gt;
&lt;p&gt;Sometimes the realism &lt;em&gt;is&lt;/em&gt; worth the complexity.
This is especially true when we use models to help us design new systems.
As &lt;a href=&#34;https://doi.org/10.1007/978-3-030-18050-8_72&#34;&gt;Jackson (2019)&lt;/a&gt; notes,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;One would never design a large airliner without carefully modeling its aeronautic properties, and testing it thoroughly via simulations and test flights of prototypes, before loading it with passengers.
Why should designing a market for health insurance be any different?
Models have the virtue of offering us insight in to what should we expect in scenarios that have never been tried before.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Models give us prototypes to test.
They let us run theoretical experiments when &amp;ldquo;real&amp;rdquo; experiments are expensive or infeasible.
They guide our search for better designs.
The &amp;ldquo;best&amp;rdquo; design might be complicated because reality is complicated.
Ignoring some complications in the model may lead us astray.
But we don&amp;rsquo;t need &lt;em&gt;all&lt;/em&gt; the complications: health insurance markets don&amp;rsquo;t depend critically on whether I buy blue jeans or black.&lt;/p&gt;
&lt;p&gt;Moreover, when designing new systems, the object of interest is the design rather than the model of it.
The model is just a tool.
We use it to focus on relevant factors and abstract from irrelevant factors.
Different models arise from making different choices about which factors are relevant.
Our job as economic modelers is to make those choices well.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Echo chambers can be useful</title>
      <link>https://bldavies.com/blog/echo-chambers-useful/</link>
      <pubDate>Fri, 08 Apr 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/echo-chambers-useful/</guid>
      <description>&lt;p&gt;Talking to lots of people who know different things helps us learn.
Yet many of us sort into &lt;a href=&#34;https://en.wikipedia.org/wiki/Echo_chamber_%28media%29&#34;&gt;echo chambers&lt;/a&gt;, only talking to a few like-minded people.
Doesn&amp;rsquo;t this hinder learning?&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://scholar.google.com/scholar?cluster=15025907096771476263&#34;&gt;Jann and Schottmüller (2021)&lt;/a&gt; answer: &amp;ldquo;not always.&amp;rdquo;
Different people know &lt;em&gt;and want&lt;/em&gt; different things.
These differences give us &lt;a href=&#34;https://bldavies.com/blog/persuading-anecdotes&#34;&gt;persuasion temptations&lt;/a&gt;: we tell selective stories to influence others&amp;rsquo; behavior.
We don&amp;rsquo;t share everything we know.
Sorting into echo chambers removes our persuasion temptations.
This leads to more sharing and learning.&lt;/p&gt;
&lt;p&gt;The authors formalize this idea as follows:
Each agent has a binary &lt;a href=&#34;https://en.wikipedia.org/wiki/Bit&#34;&gt;bit&lt;/a&gt; of information.
Summing these bits gives the &amp;ldquo;state.&amp;rdquo;
Agents take actions based on (i) their individual biases and (ii) their beliefs about the state.
They want other agents to take similar actions.
Biases are &lt;a href=&#34;https://en.wikipedia.org/wiki/Common_knowledge_%28logic%29&#34;&gt;common knowledge&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Agents learn about the state by talking to each other.
But before they talk, agents sort into &amp;ldquo;rooms.&amp;rdquo;
Agents only talk to people in their room.
They choose what to say based on how it influences their roommates&amp;rsquo; actions.
They either&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;share their bit (i.e., tell the truth),&lt;/li&gt;
&lt;li&gt;share one minus their bit (i.e., lie), or&lt;/li&gt;
&lt;li&gt;share a zero or one randomly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Agents can &amp;ldquo;babble&amp;rdquo; by sharing a zero or one independently of their bit.
For example, they could flip a coin and share a one if it lands on heads.
Babbling is uninformative.&lt;/p&gt;
&lt;p&gt;Jann and Schottmüller first study the &lt;a href=&#34;https://en.wikipedia.org/wiki/Cheap_talk#Theorem&#34;&gt;most informative equilibrium&lt;/a&gt; of the bit-sharing game played in each room.
In this equilibrium, everyone tells the truth or babbles.
Agents close to the mean bias among their roommates tell the truth.
Agents far from that mean babble.&lt;/p&gt;
&lt;p&gt;The authors then study how agents choose rooms.
These choices anticipate how agents talk in each room.
In equilibrium, no agent wants to change rooms on their own.
This equilibrium is &amp;ldquo;welfare-optimal&amp;rdquo; if it leads to more truth-telling than any other equilibrium.&lt;/p&gt;
&lt;p&gt;Whether the equilibrium room choices are welfare-optimal depends on agents&amp;rsquo; biases.
For example, suppose agents are polarized: their biases take one of two values with equal probability.
The difference between these values captures the level of polarization.
The authors show that&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;full segregation is welfare-optimal if polarization is &lt;em&gt;high&lt;/em&gt; enough, and&lt;/li&gt;
&lt;li&gt;full integration is welfare-optimal if polarization is &lt;em&gt;low&lt;/em&gt; enough.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If polarization is high enough then having opposite-minded agents in the same room creates persuasion temptations.
These temptations lead to babbling in the most informative equilibrium.
Full segregation prevents babbling.
On the other hand, if polarization is &lt;em&gt;low&lt;/em&gt; enough then no-one has persuasion temptations and so no-one babbles.
Then having everyone in the same room is welfare-optimal.&lt;/p&gt;
&lt;p&gt;More polarization leads to less bit sharing in equilibrium.
This is because polarization creates persuasion temptations.
Segregation actually &lt;em&gt;removes&lt;/em&gt; some of these temptations.
But it can&amp;rsquo;t restore communication between agents who moved to different rooms.
Thus, polarization lowers welfare &lt;em&gt;despite&lt;/em&gt; segregation, rather than &lt;em&gt;because&lt;/em&gt; of it.
The authors summarize this point nicely:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;One could think of echo chambers as society&amp;rsquo;s (decentralized) defense mechanism against polarization.
Like fever in a human body, segregation occurs as the effect of an underlying problem, and its presence hence indicates that polarization is at problematic levels.
Echo chambers, and segregation more generally, are hence a symptom of polarization.
And just like artificially lowering fever, treating the symptom without addressing the cause can in fact exacerbate the situation.
Reducing polarization will weakly improve welfare; reducing segregation may not.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The authors go on to study extensions of their model.
For example, they show that adding public information can &lt;a href=&#34;https://en.wikipedia.org/wiki/Crowding_out_%28economics%29&#34;&gt;crowd out&lt;/a&gt; incentives to tell the truth.
They also show that their model agrees with data from Twitter.
The authors suggest that social media platforms do more than connect people: they provide infrastructure for efficient segregation.&lt;/p&gt;
&lt;p&gt;Jann and Schottmüller close by calling for more nuanced discussion of echo chambers:
Yes, they limit the diversity of whom we meet and talk to.
But&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;there is simply no use in meeting people with a very diverse set of opinions and very useful information, if there is no way to get that information out of them.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
</description>
    </item>
    
    <item>
      <title>Tolerance and compromise in social networks</title>
      <link>https://bldavies.com/blog/tolerance-compromise-social-networks/</link>
      <pubDate>Fri, 01 Apr 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/tolerance-compromise-social-networks/</guid>
      <description>&lt;p&gt;Everyone has beliefs about how they should behave.
But people differ in their beliefs.
They also differ in their tolerance of &lt;em&gt;others&amp;rsquo;&lt;/em&gt; beliefs.
These differences affect who become friends.
Some people &amp;ldquo;stick to their guns&amp;rdquo; and befriend only those who agree.
Others are more tolerant and befriend others who disagree.
Such people are more willing to compromise, changing their behavior to accommodate friends&amp;rsquo; beliefs.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1086/717041&#34;&gt;Genicot (2022)&lt;/a&gt; studies tolerance and compromise in social networks.
She describes a finite population of agents with different &amp;ldquo;ideal&amp;rdquo; actions.
Agents prefer taking their ideal actions.
They also prefer friends who take their ideal actions.
An agent&amp;rsquo;s &amp;ldquo;tolerance&amp;rdquo; is the largest deviation from their ideal they can accept in a friend&amp;rsquo;s action.&lt;/p&gt;
&lt;p&gt;Agents take actions before making friends.
An agent &amp;ldquo;compromises&amp;rdquo; if they take an action different than their ideal.
Compromise is costly but may lead to beneficial friendships.
Agents weigh these costs and benefits when taking actions.
Genicot studies the equilibrium in which no-one wants to change their action.&lt;/p&gt;
&lt;p&gt;If everyone has the same tolerance then no-one compromises.
The reason is as follows:
No-one wants to compromise more than is necessary for their friends&amp;rsquo; acceptance.
Thus, anyone who compromises must do so &amp;ldquo;minimally&amp;rdquo; for at least one friend.
This friend must also compromise because tolerances are equal.
In fact, they must compromise &lt;em&gt;more&lt;/em&gt; to make the friendship net beneficial.
But then &lt;em&gt;they&lt;/em&gt; must have another friend who compromises &lt;em&gt;even more&lt;/em&gt;.
We can keep applying this argument to find agents who compromise more and more, which is impossible because the population is finite.&lt;/p&gt;
&lt;p&gt;Compromise thus depends on differences in tolerance.
Agents compromise by deviating from their ideals towards the ideals of relatively intolerant friends.
Some compromises are one-sided, where the intolerant friend stands their ground.
Other compromises are two-sided.
Two-sided compromises rely on intolerant &amp;ldquo;bridge&amp;rdquo; agents, who bring their tolerant friends&amp;rsquo; actions close enough together to be mutually acceptable.&lt;/p&gt;
&lt;p&gt;Compromise also depends on how tolerances and ideals covary.
If agents with &amp;ldquo;extreme&amp;rdquo; ideals are less tolerant then two-sided compromise is impossible.
This is because agents compromise towards intolerant extremists.
Consequently, actions tend to be more polarized than ideals.
In contrast, if extremists are more tolerant then agents compromise towards the median.
This makes the population more connected.&lt;/p&gt;
&lt;p&gt;Genicot interprets these results in light of recent political trends.
She cites evidence of intolerance among liberals and conservatives, and of rising polarization in the United States.
These patterns are consistent with Genicot&amp;rsquo;s model.
If people want to make friends, but making friends requires compromise towards extremes, then people will behave more extremely.&lt;/p&gt;
&lt;p&gt;Genicot closes with guidance on finding tolerant people:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Looking at the identity of the members of a person&amp;rsquo;s social network may overestimate the tolerance exhibited by the person.
The distance between a person&amp;rsquo;s identity and her friends&amp;rsquo; behaviors would likely tell us more about her tolerance.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Tolerance isn&amp;rsquo;t about having diverse friends; it&amp;rsquo;s about &lt;em&gt;not forcing friends to accommodate your beliefs&lt;/em&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Persuading with anecdotes</title>
      <link>https://bldavies.com/blog/persuading-anecdotes/</link>
      <pubDate>Fri, 18 Mar 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/persuading-anecdotes/</guid>
      <description>&lt;p&gt;My &lt;a href=&#34;https://bldavies.com/blog/ideological-bias-trust-information-sources/&#34;&gt;previous post&lt;/a&gt; explained why rational people can prefer like-minded information sources.
This preference leads media outlets to compete by targeting biased audiences.
Such targeting can take (at least) two forms:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;presenting content in a way some people like and others don&amp;rsquo;t;&lt;/li&gt;
&lt;li&gt;only sharing content that some people like and others don&amp;rsquo;t.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&#34;https://www.nber.org/papers/w28661&#34;&gt;Haghtalab et al. (2021)&lt;/a&gt; study the second form.
They consider a pair of Bayesian agents called Sender (he) and Receiver (she).
Both agents take actions (e.g., get vaccinated) based on their beliefs about an unknown state (e.g., whether vaccines are effective) and their &amp;ldquo;moral stance.&amp;rdquo;
Sender observes some noisy signals about the state before taking his action.
He sends one of those signals to Receiver before she takes her action.
Sender&amp;rsquo;s &amp;ldquo;communication scheme&amp;rdquo; determines which signal he sends.
He chooses this scheme knowing his and Receiver&amp;rsquo;s moral stances, but before observing any signals.&lt;/p&gt;
&lt;p&gt;Sender wants Receiver to take the same action as him.
He chooses the scheme that minimizes the mean distance (across signal realizations) between his and Receiver&amp;rsquo;s actions.
This distance has three components:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &amp;ldquo;signalling loss&amp;rdquo; from sending one signal rather than many;&lt;/li&gt;
&lt;li&gt;A &amp;ldquo;persuasion temptation&amp;rdquo; from wanting Receiver to take the same action;&lt;/li&gt;
&lt;li&gt;An unavoidable loss from differences in moral stances.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If Receiver knows the communication scheme then Sender just minimizes the signalling loss.
This is because Receiver can &amp;ldquo;undo&amp;rdquo; any bias in the scheme, so persuasion is impossible.
But if Receiver &lt;em&gt;doesn&amp;rsquo;t&lt;/em&gt; know the scheme then Sender trades off the signalling loss and the persuasion temptation.
This makes both agents worse off because the signal sent is less informative.&lt;/p&gt;
&lt;p&gt;Suppose the signal distribution is &amp;ldquo;well-behaved&amp;rdquo; (e.g., single-peaked) and Receiver knows the communication scheme.
If Sender observes enough signals then he always prefers unbiased schemes.
Intuitively, Sender wants to send all the signals he observes but can only send one.
He sends the &amp;ldquo;most representative&amp;rdquo; signal: the one closest to the mean.
But this logic breaks down when Sender observes too few signals.
In that case, the mean signal is noisy and extreme signals can be more informative.
This can make Receiver prefer biased schemes.&lt;/p&gt;
&lt;p&gt;Now suppose Receiver &lt;em&gt;doesn&amp;rsquo;t&lt;/em&gt; know the communication scheme.
Then Sender chooses more biased schemes when he observes more signals.
He does so because of his persuasion temptation.
Again, this makes both agents worse off.
So Receiver prefers when Sender shares her moral stance because then their incentives are aligned.&lt;/p&gt;
&lt;p&gt;This preference for like-mindedness also depends on the number and distribution of signals Sender observes.
For example, suppose Receiver chooses between&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;an expert with many signals but a different moral stance, and&lt;/li&gt;
&lt;li&gt;a layperson with one signal but the same moral stance.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Receiver prefers the layperson when the signal distribution is &lt;a href=&#34;https://en.wikipedia.org/wiki/Fat-tailed_distribution&#34;&gt;thick-tailed&lt;/a&gt;.
This is because the expert observes more signals &amp;ldquo;in the tail,&amp;rdquo; so they send a more extreme (and, thus, less informative) signal due to their persuasion temptation.&lt;/p&gt;
&lt;p&gt;It may seem restrictive that Sender shares a raw signal rather than, say, his posterior estimate of the state.
But such sharing reflects how real people talk to each other.
Real people don&amp;rsquo;t trade summary statistics on vaccination outcomes.
Instead, they trade anecdotes like &amp;ldquo;I felt tired and achy after my booster shot.&amp;rdquo;
News outlets do the same: they typically report on individual events rather than aggregate patterns.
(When was the last time you saw a &lt;a href=&#34;https://en.wikipedia.org/wiki/Base_rate&#34;&gt;base rate&lt;/a&gt; in the news?)
These anecdotes in conversation and events in the news correspond to signals in the authors&amp;rsquo; model.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ideological bias and trust in information sources</title>
      <link>https://bldavies.com/blog/ideological-bias-trust-information-sources/</link>
      <pubDate>Wed, 09 Mar 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/ideological-bias-trust-information-sources/</guid>
      <description>&lt;p&gt;If people were &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayesian_inference&#34;&gt;Bayesian&lt;/a&gt;, then giving them more information would help them learn the truth and reach consensus.
But most people &lt;em&gt;aren&amp;rsquo;t&lt;/em&gt; Bayesian.
They can have, e.g., &lt;a href=&#34;https://en.wikipedia.org/wiki/Confirmation_bias&#34;&gt;confirmation bias&lt;/a&gt; or limited memory.
These cognitive &amp;ldquo;errors&amp;rdquo; can lead people with access to lots of information to disagree.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://web.stanford.edu/~gentzkow/research/trust.pdf&#34;&gt;Gentzkow, Wong and Zhang (2021)&lt;/a&gt; show that such errors are not necessary for disagreement.
The authors consider Bayesian agents with access to some information sources.
Agents don&amp;rsquo;t know which sources they can trust.
They learn to trust sources that are consistent with their personal experiences.
Variation in experiences can lead agents to disagree, even as the number of sources grows.&lt;/p&gt;
&lt;p&gt;In Gentzkow et al.&amp;lsquo;s model, sources send &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals&#34;&gt;noisy signals&lt;/a&gt; about many &amp;ldquo;states.&amp;rdquo;
States represent objective facts about different issues, such as mask effectiveness or the extent of global warming.
States vary in their &amp;ldquo;ideological valence:&amp;rdquo; how favorable they are to liberals or conservatives.
Sources vary in their accuracy (i.e., signals&amp;rsquo; correlation with states) and ideological bias (i.e., signals&amp;rsquo; correlation with ideological valences).
Agents want to learn sources&amp;rsquo; accuracies and biases, which are constant across issues.&lt;/p&gt;
&lt;p&gt;Agents learn by comparing signals to their personal experience, such as friends&amp;rsquo; disease outcomes or local weather events.
Experiences, like sources, vary in their accuracy and ideological bias (due to, e.g., &lt;a href=&#34;https://bldavies.com/blog/polarized-beliefs-social-networks/&#34;&gt;choosing like-minded friends&lt;/a&gt;).
However, agents believe their experience is &lt;em&gt;unbiased&lt;/em&gt;.
This belief gives each agent a baseline against which to compare signals.
Different agents have different baselines, leading to different inferences from the signals they receive.&lt;/p&gt;
&lt;p&gt;The authors show that biased agents prefer like-minded sources.
When comparing sources with the same accuracy but opposite biases, agents think the source sharing their bias is more accurate.
Agents also under-estimate the bias of like-minded sources and think unbiased sources are opposite-minded.
These patterns stem from agents&amp;rsquo; dogmatic beliefs that their experiences are unbiased.
Agents learn the truth if and only if their experiences &lt;em&gt;really are&lt;/em&gt; unbiased.&lt;/p&gt;
&lt;p&gt;The authors also show that biases in experiences can lead to disagreements about states.
Suppose the bias in two agents&amp;rsquo; experiences have equal magnitudes but opposite signs.
As the magnitude grows, the agents become more likely to disagree.
Having more sources doesn&amp;rsquo;t always help.
It can actually lead to &lt;em&gt;more&lt;/em&gt; disagreement because agents can combine sources to construct a maximally like-minded composite.&lt;/p&gt;
&lt;p&gt;This demand for like-minded sources affects media market outcomes.
People devote their attention to media outlets they trust.
Outlets profit from capturing peoples&amp;rsquo; attention.
The authors show that monopolists maximize profit by offering accurate and unbiased information, whereas competing outlets &lt;a href=&#34;https://en.wikipedia.org/wiki/Product_differentiation&#34;&gt;differentiate&lt;/a&gt; by targeting biased audiences.&lt;/p&gt;
&lt;p&gt;All of these results rely on some technical assumptions.
For example, agents only see normally distributed data.
This makes the math (relatively) easy but limits generality.
I don&amp;rsquo;t mind those assumptions because they lead to clear, testable hypotheses about why people disagree.
What remains is to test them.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Pre-screening evidence</title>
      <link>https://bldavies.com/blog/pre-screening-evidence/</link>
      <pubDate>Wed, 02 Mar 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/pre-screening-evidence/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1016/j.jet.2021.105401&#34;&gt;Cheng and Hsiaw (2022)&lt;/a&gt; study an agent who wants to learn about a binary state (e.g., whether a vaccine is safe).
An information source (e.g., Fauci or a Twitter thread) sends &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;noisy signals&lt;/a&gt; about the state.
But the agent doesn&amp;rsquo;t know whether the source is &amp;ldquo;credible.&amp;rdquo;
They have to infer credibility from the signals received.&lt;/p&gt;
&lt;p&gt;The authors compare two types of agents: Bayesians and &amp;ldquo;pre-screeners.&amp;rdquo;
Both types respond to new evidence in two steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Update beliefs about whether the source is credible.&lt;/li&gt;
&lt;li&gt;Update beliefs about the state, weighing the evidence by its credibility.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The two types differ in the second step.
Whereas Bayesians use their &lt;em&gt;prior&lt;/em&gt; beliefs about credibility, pre-screeners use their &lt;em&gt;updated&lt;/em&gt; beliefs.
Pre-screeners &amp;ldquo;double-dip&amp;rdquo; the evidence: once to evaluate its credibility, and again to evaluate its likelihood &lt;em&gt;given&lt;/em&gt; its credibility.
Bayesians never double-dip: they evaluate credibility and likelihood independently.&lt;/p&gt;
&lt;p&gt;Bayesians and pre-screeners can have different responses to the same evidence.
For example, suppose an agent thinks (i) they have COVID-19 and (ii) their testing procedure is accurate (i.e., credible).
The procedure  &lt;em&gt;is&lt;/em&gt; accurate, but they actually &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; have the virus.
They take a test; it returns &amp;ldquo;negative.&amp;rdquo;
Surprised, they take another test; &amp;ldquo;negative.&amp;rdquo;
They keep taking tests; the tests keep returning &amp;ldquo;negative.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Suppose the agent is Bayesian.
The first result makes them think the testing procedure is inaccurate.
But they evaluate the first result using their &lt;em&gt;prior&lt;/em&gt; belief about accuracy, which is that the procedure &lt;em&gt;is&lt;/em&gt; accurate.
Consequently, they weaken their belief in having the virus.
This makes the second result less surprising than the first.
That result weakens the agent&amp;rsquo;s belief further.
Eventually, the agent stops being surprised: they gradually learn the procedure is accurate and they don&amp;rsquo;t have the virus.&lt;/p&gt;
&lt;p&gt;Now suppose the agent pre-screens.
The first result makes them think the testing procedure is inaccurate.
They evaluate the first result using their &lt;em&gt;updated&lt;/em&gt; belief about accuracy.
Consequently, they &lt;em&gt;strengthen&lt;/em&gt; their belief in having the virus.
This makes the second result less surprising than the first: the agent expects an inaccurate result and, from their perspective, gets one.
They strengthen their belief further.
Eventually, the agent wonders, &amp;ldquo;if the procedure was inaccurate then it wouldn&amp;rsquo;t keep returning the same result.
Perhaps it &lt;em&gt;is&lt;/em&gt; accurate after all?&amp;rdquo;
The agent then evaluates &lt;em&gt;all&lt;/em&gt; the results as though the procedure is accurate, weakening their belief in having the virus sharply.
Suddenly, the agent learns the procedure is accurate and they don&amp;rsquo;t have the virus.&lt;/p&gt;
&lt;p&gt;The Bayesian and pre-screener reach the same conclusion in different ways.
The Bayesian learns gradually because they evaluate each result independently.
The pre-screener learns suddenly because they evaluate &lt;em&gt;the entire history of results&lt;/em&gt; as though they knew the testing procedure was accurate all along.
Cheng and Hsiaw show generally that, so long as signals tend to agree with the state, pre-screeners learn the truth eventually if Bayesians do too.&lt;/p&gt;
&lt;p&gt;But &amp;ldquo;eventually&amp;rdquo; can mean &amp;ldquo;after an unhelpfully long time.&amp;rdquo;
In the meantime, pre-screeners and Bayesians can disagree about the state.
They do so because they disagree about credibility.
Pre-screeners either &amp;ldquo;over-trust&amp;rdquo; or &amp;ldquo;under-trust&amp;rdquo; the source relative to Bayesians.
Over-trust leads pre-screeners to think the state favored by the evidence is more likely than Bayesians think.
Under-trust has the opposite effect.&lt;/p&gt;
&lt;p&gt;Cheng and Hsiaw call this pattern &amp;ldquo;correlated disagreement:&amp;rdquo; pre-screeners&amp;rsquo; beliefs tend to agree with whether they think sources supporting those beliefs are credible.
For example, imagine collecting peoples&amp;rsquo; opinions on (i) whether vaccines are safe and (ii) the credibility of sources saying vaccines are safe.
If people pre-screen then their opinions on (i) and (ii) should be positively correlated.&lt;/p&gt;
&lt;p&gt;Correlated disagreement is one testable prediction of Cheng and Hsiaw&amp;rsquo;s model.
Another prediction is &amp;ldquo;first impression bias:&amp;rdquo; pre-screeners are more likely to think a source is credible if its first few signals agree with each other.
Bayesians have no such bias because their final beliefs don&amp;rsquo;t depend on which signals they see first.&lt;/p&gt;
&lt;p&gt;A third prediction concerns how pre-screeners react to new evidence.
They over-react if the evidence confirms their priors and think the source is credible.
They under-react if the evidence contradicts their priors &lt;em&gt;or&lt;/em&gt; think the source is &lt;em&gt;not&lt;/em&gt; credible.&lt;/p&gt;
&lt;p&gt;Cheng and Hsiaw also discuss how such reactions influence asset prices.
Disagreements over credibility (e.g., of financial reports) lead to disagreements over fundamental values.
These disagreements lead to speculation: people buy assets hoping to cash-in on others&amp;rsquo; over-confidence.
Speculation raises asset prices.
Eventually, disagreements over credibility disappear, investors wise up, and prices come crashing down.&lt;/p&gt;
&lt;p&gt;Cheng and Hsiaw argue that disagreement comes from people not being Bayesian.
In contrast, &lt;a href=&#34;https://web.stanford.edu/~gentzkow/research/trust.pdf&#34;&gt;Gentzkow, Wong and Zhang (2021)&lt;/a&gt; argue that disagreement can arise even if people &lt;em&gt;are&lt;/em&gt; Bayesian.
I summarize their argument &lt;a href=&#34;https://bldavies.com/blog/ideological-bias-trust-information-sources&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Communicating science</title>
      <link>https://bldavies.com/blog/communicating-science/</link>
      <pubDate>Wed, 23 Feb 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/communicating-science/</guid>
      <description>&lt;p&gt;Science is hard, and communicating it to a broad audience is even harder.
I don&amp;rsquo;t envy Anthony Fauci or his colleagues, who must summarize the science on vaccines to a range of parties with a range of prior beliefs.&lt;/p&gt;
&lt;p&gt;What does it mean to communicate science &amp;ldquo;optimally?&amp;rdquo;
&lt;a href=&#34;https://doi.org/10.3982/ECTA18155&#34;&gt;Andrews and Shapiro (2021)&lt;/a&gt; offer some guidance.
They consider an analyst who sends an audience a report about some data.
Audience members vary in their beliefs and objectives, and so vary in their reactions to a given report.
The analyst chooses a report that maximizes audience members&amp;rsquo; welfare given their reactions.&lt;/p&gt;
&lt;p&gt;Andrews and Shapiro compare two models:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &amp;ldquo;communication model,&amp;rdquo; the analyst provides information and lets audience members take their preferred decision &lt;em&gt;given&lt;/em&gt; that information.&lt;/li&gt;
&lt;li&gt;In the &amp;ldquo;decision model,&amp;rdquo; the analyst takes a decision on audience members&amp;rsquo; behalf.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These two models generally have different optimal reporting rules.
For example, suppose the analyst has experimental data on a new drug.
Their audience is a range of governments, who want to subsidize the drug if its effect is positive and tax it if its effect is negative.
Everyone knows the true effect is non-negative, so taxing is never optimal.
But the analyst may estimate a negative effect due to sampling error in the experiment.
Under the decision model, the analyst optimally censors negative estimates because imposing a tax is worse than doing nothing.
Conversely, under the communication model, censoring is &lt;em&gt;never&lt;/em&gt; optimal because it throws away information about effect size.&lt;/p&gt;
&lt;p&gt;In this example, the analyst optimally reports a &lt;a href=&#34;https://en.wikipedia.org/wiki/Sufficient_statistic&#34;&gt;sufficient statistic&lt;/a&gt; for the effect size (e.g., the mean outcomes within the experiment&amp;rsquo;s treatment and control groups).
In fact, reporting a sufficient statistic is &lt;em&gt;always&lt;/em&gt; optimal under the communication model.&lt;/p&gt;
&lt;p&gt;The communication and decision models can even have different &lt;a href=&#34;https://en.wikipedia.org/wiki/Admissible_decision_rule&#34;&gt;admissible&lt;/a&gt; reporting rules.
For example, suppose the analyst has data on (true) treatment effects for many drugs.
Their audience is a range of physicians, who want to give the best drug to their patients.
Every physician believes that any drug is better than none (e.g., because patients can&amp;rsquo;t self-prescribe).
The analyst considers two reporting rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose randomly among the drugs with the largest effect.&lt;/li&gt;
&lt;li&gt;If all drugs have the same effect then do nothing; otherwise, use rule 1.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Every physician prefers &lt;em&gt;some&lt;/em&gt; drug to none, so doing nothing is never optimal.
Consequently, the first rule always dominates the second under the decision model.
But physicians can reconstruct the first rule from the second, so the second rule is (weakly) more informative.
Consequently, it always dominates the first rule under the communication model.&lt;/p&gt;
&lt;p&gt;Andrews and Shapiro discuss more features of the two models, such as what happens when the analyst puts different weights on different audience members&amp;rsquo; welfare.
The authors also discuss implications of their analysis for research practice, such as for reporting estimates of structural economic models.&lt;/p&gt;
&lt;p&gt;One thing Andrews and Shapiro &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; discuss is what happens when the audience is &lt;a href=&#34;https://en.wikipedia.org/wiki/Bounded_rationality&#34;&gt;boundedly rational&lt;/a&gt;.
Audience members may find it hard to process information&amp;mdash;hence getting the analyst to process it for them&amp;mdash;due to cognitive or emotional costs.
Such costs make the audience &lt;a href=&#34;https://en.wikipedia.org/wiki/Rational_inattention&#34;&gt;rationally inattentive&lt;/a&gt;.
&lt;a href=&#34;https://scholar.google.com/scholar?cluster=10141712202393797072&#34;&gt;Bloedel and Segal (2021)&lt;/a&gt; study optimal communication to a rationally inattentive audience, but use the language of Bayesian persuasion (&lt;a href=&#34;https://doi.org/10.1257/aer.101.6.2590&#34;&gt;Kamenica and Gentzkow, 2011&lt;/a&gt;) rather than statistical decision theory.&lt;/p&gt;
&lt;p&gt;Another missing discussion is what happens when the audience don&amp;rsquo;t trust the analyst.
Suppose some audience members believe the analyst lies or suppresses truths for conspiratorial reasons.
How should the analyst respond to this belief?
How should they trade off the cognitive costs induced by providing information with the conspiracy theories induced by suppressing it?
This trade-off is both deliciously complicated and faced by real-world science communicators.
Again, I do not envy them!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Assortativity and correlation coefficients</title>
      <link>https://bldavies.com/blog/assortativity-correlation-coefficients/</link>
      <pubDate>Thu, 17 Feb 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/assortativity-correlation-coefficients/</guid>
      <description>&lt;p&gt;This is a technical follow-up to a previous post on &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortative mixing in networks&lt;/a&gt;.
In a &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/#fn:1&#34;&gt;footnote&lt;/a&gt;, I claimed that &lt;a href=&#34;https://doi.org/10.1103/PhysRevE.67.026126&#34;&gt;Newman&amp;rsquo;s (2003)&lt;/a&gt; assortativity coefficient equals the Pearson correlation coefficient when there are two possible node types.
This post proves that claim.&lt;/p&gt;
&lt;h2 id=&#34;notation&#34;&gt;Notation&lt;/h2&gt;
&lt;p&gt;Consider an undirected network &lt;code&gt;\(N\)&lt;/code&gt; in which each node has a type belonging to a (finite) set &lt;code&gt;\(T\)&lt;/code&gt;.
The assortativity coefficient is defined as
&lt;code&gt;$$r=\frac{\sum_{t\in T}x_{tt}-\sum_{t\in T}y_t^2}{1-\sum_{t\in T}y_t^2},$$&lt;/code&gt;
where &lt;code&gt;\(x_{st}\)&lt;/code&gt; is the proportion of edges joining nodes of type &lt;code&gt;\(s\)&lt;/code&gt; to nodes of type &lt;code&gt;\(t\)&lt;/code&gt;, and where
&lt;code&gt;$$y_t=\sum_{s\in T}x_{st}$$&lt;/code&gt;
is the proportion of edges incident with nodes of type &lt;code&gt;\(t\)&lt;/code&gt;.
The Pearson correlation of adjacent nodes&amp;rsquo; types is given by
&lt;code&gt;$$\DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\Var}{Var} \rho=\frac{\Cov(t_i,t_j)}{\sqrt{\Var(t_i)\Var(t_j)}},$$&lt;/code&gt;
where &lt;code&gt;\(t_i\in T\)&lt;/code&gt; and &lt;code&gt;\(t_j\in T\)&lt;/code&gt; are the types of nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\)&lt;/code&gt;, and where (co)variances are computed with respect to the frequency at which nodes of type &lt;code&gt;\(t_i\)&lt;/code&gt; and &lt;code&gt;\(t_j\)&lt;/code&gt; are adjacent in &lt;code&gt;\(N\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;proof&#34;&gt;Proof&lt;/h2&gt;
&lt;p&gt;Let &lt;code&gt;\(T=\{a,b\}\subset\mathbb{R}\)&lt;/code&gt; with &lt;code&gt;\(a\not=b\)&lt;/code&gt;.
I show that the correlation coefficient &lt;code&gt;\(\rho\)&lt;/code&gt; and assortativity coefficient &lt;code&gt;\(r\)&lt;/code&gt; can be expressed as the same function of &lt;code&gt;\(y_a\)&lt;/code&gt; and &lt;code&gt;\(x_{ab}\)&lt;/code&gt;, implying &lt;code&gt;\(\rho=r\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Consider &lt;code&gt;\(\rho\)&lt;/code&gt;.
It can be understood by presenting the &lt;a href=&#34;#appendix-constructing-the-mixing-matrix&#34;&gt;mixing matrix&lt;/a&gt; &lt;code&gt;\(X=(x_{st})\)&lt;/code&gt; in tabular form:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;code&gt;\(t_i\)&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;\(t_j\)&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;\(x_{t_it_j}\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\(a\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(a\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(x_{aa}\)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\(a\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(b\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(x_{ab}\)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\(b\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(a\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(x_{ba}\)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\(b\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(b\)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\(x_{bb}\)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The first two columns enumerate the possible type pairs &lt;code&gt;\((t_i,t_j)\)&lt;/code&gt; and the third column stores the proportion of adjacent node pairs &lt;code&gt;\((i,j)\)&lt;/code&gt; with each type pair.
This third column defines the joint distribution of types across adjacent nodes.
Thus &lt;code&gt;\(\rho\)&lt;/code&gt; equals the correlation of the first two columns, weighted by the third column.
(Here &lt;code&gt;\(x_{ab}=x_{ba}\)&lt;/code&gt; since &lt;code&gt;\(N\)&lt;/code&gt; is undirected.)
Now &lt;code&gt;\(t_i\)&lt;/code&gt; has mean
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \begin{aligned} \E[t_i] &amp;amp;= x_{aa}a+x_{ab}a+x_{ba}b+x_{bb}b \\ &amp;amp;= y_aa+y_bb \end{aligned}$$&lt;/code&gt;
and second moment
&lt;code&gt;$$\begin{aligned} \E[t_i^2] &amp;amp;= x_{aa}a^2+x_{ab}a^2+x_{ba}b^2+x_{bb}b^2 \\ &amp;amp;= y_aa^2+y_bb^2, \end{aligned}$$&lt;/code&gt;
and similar calculations reveal &lt;code&gt;\(\E[t_j]=\E[t_i]\)&lt;/code&gt; and &lt;code&gt;\(\E[t_j^2]=\E[t_i^2]\)&lt;/code&gt;.
Thus &lt;code&gt;\(t_i\)&lt;/code&gt; has variance
&lt;code&gt;$$\begin{aligned} \Var(t_i) &amp;amp;= \E[t_i^2]-\E[t_i]^2 \\ &amp;amp;= y_aa^2+y_bb^2-(y_aa+y_bb)^2 \\ &amp;amp;= y_a(1-y_a)a^2+y_b(1-y_b)b^2-2y_ay_bab \end{aligned}$$&lt;/code&gt;
and similarly &lt;code&gt;\(\Var(t_j)=\Var(t_i)\)&lt;/code&gt;.
We can simplify this expression for the variance by noticing that
&lt;code&gt;$$x_{aa}+x_{ab}+x_{ba}+x_{bb}=1,$$&lt;/code&gt;
which implies
&lt;code&gt;$$\begin{aligned} y_b &amp;amp;= x_{ab}+x_{bb} \\ &amp;amp;= 1-x_{aa}-x_{ba} \\ &amp;amp;= 1-y_a \end{aligned}$$&lt;/code&gt;
and therefore
&lt;code&gt;$$\begin{aligned} \Var(t_i) &amp;amp;= y_a(1-y_a)a^2+(1-y_a)y_ab^2-2y_a(1-y_a)ab \\ &amp;amp;= y_a(1-y_a)(a-b)^2. \end{aligned}$$&lt;/code&gt;
We next express the covariance &lt;code&gt;\(\Cov(t_i,t_j)=\E[t_it_j]-\E[t_i]\E[t_j]\)&lt;/code&gt; in terms of &lt;code&gt;\(y_a\)&lt;/code&gt; and &lt;code&gt;\(x_{ab}\)&lt;/code&gt;.
Now
&lt;code&gt;$$\begin{aligned} \E[t_it_j] &amp;amp;= x_{aa}a^2+x_{ab}ab+x_{ba}ab+x_{bb}b^2 \\ &amp;amp;= (y_a-x_{ab})a^2+2x_{ab}ab+(y_b-x_{ab})b^2 \\ &amp;amp;= y_aa^2+y_bb^2-x_{ab}(a-b)^2 \end{aligned}$$&lt;/code&gt;
because &lt;code&gt;\(x_{ab}=x_{ba}\)&lt;/code&gt;.
It follows that
&lt;code&gt;$$\begin{aligned} \Cov(t_i,t_j) &amp;amp;= y_aa^2+y_bb^2-x_{ab}(a-b)^2-(y_aa+y_bb)^2 \\ &amp;amp;= y_a(1-y_a)a^2+y_b(1-y_b)b^2-2y_ay_bab-x_{ab}(a-b)^2 \\ &amp;amp;= y_a(1-y_a)(a-b)^2-x_{ab}(a-b)^2, \end{aligned}$$&lt;/code&gt;
where the last line uses the fact that &lt;code&gt;\(y_b=1-y_a\)&lt;/code&gt;.
Putting everything together, we have
&lt;code&gt;$$\begin{aligned} \rho &amp;amp;= \frac{\Cov(t_i,t_j)}{\sqrt{\Var(t_i)\Var(t_j)}} \\ &amp;amp;= \frac{y_a(1-y_a)-x_{ab}}{y_a(1-y_a)}, \end{aligned}$$&lt;/code&gt;
a function of &lt;code&gt;\(y_a\)&lt;/code&gt; and &lt;code&gt;\(x_{ab}\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now consider &lt;code&gt;\(r\)&lt;/code&gt;.
Its numerator equals
&lt;code&gt;$$\begin{aligned} \sum_{t\in T}x_{tt}-\sum_{t\in T}y_t^2 &amp;amp;= x_{aa}+x_{bb}-y_a^2-y_b^2 \\ &amp;amp;= (y_a-x_{ab})+(y_b-x_{ab})-y_a^2-y_b^2 \\ &amp;amp;= y_a(1-y_a)+y_b(1-y_b)-2x_{ab} \\ &amp;amp;\overset{\star}{=} 2y_a(1-y_a)-2x_{ab} \end{aligned}$$&lt;/code&gt;
and its denominator equals
&lt;code&gt;$$\begin{aligned} 1-\sum_{t\in T}y_t^2 &amp;amp;= 1-y_a^2-y_b^2 \\ &amp;amp;\overset{\star\star}{=} 1-y_a^2-(1-y_a)^2 \\ &amp;amp;= 2y_a(1-y_a), \end{aligned}$$&lt;/code&gt;
where &lt;code&gt;\(\star\)&lt;/code&gt; and &lt;code&gt;\(\star\star\)&lt;/code&gt; both use the fact that &lt;code&gt;\(y_b=1-y_a\)&lt;/code&gt;.
Thus
&lt;code&gt;$$r=\frac{y_a(1-y_a)-x_{ab}}{y_a(1-y_a)},$$&lt;/code&gt;
the same function of &lt;code&gt;\(y_a\)&lt;/code&gt; and &lt;code&gt;\(x_{ab}\)&lt;/code&gt;, and so &lt;code&gt;\(\rho=r\)&lt;/code&gt; as claimed.&lt;/p&gt;
&lt;p&gt;Writing &lt;code&gt;\(\rho=r\)&lt;/code&gt; in terms of &lt;code&gt;\(y_a\)&lt;/code&gt; and &lt;code&gt;\(x_{ab}\)&lt;/code&gt; makes it easy to check the boundary cases:
if there are no within-type edges then &lt;code&gt;\(y_a=x_{ab}=1/2\)&lt;/code&gt; and so &lt;code&gt;\(\rho=r=-1\)&lt;/code&gt;;
if there are no between-type edges then &lt;code&gt;\(x_{ab}=0\)&lt;/code&gt; and so &lt;code&gt;\(\rho=r=1\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;appendix-constructing-the-mixing-matrix&#34;&gt;Appendix: Constructing the mixing matrix&lt;/h2&gt;
&lt;p&gt;The proof relies on noticing that &lt;code&gt;\(x_{ab}=x_{ba}\)&lt;/code&gt;, which comes from undirectedness of the network &lt;code&gt;\(N\)&lt;/code&gt; and from how the mixing matrix &lt;code&gt;\(X\)&lt;/code&gt; is constructed.
I often forget this construction, so here&amp;rsquo;s a simple algorithm:
Consider some type pair &lt;code&gt;\((s,t)\)&lt;/code&gt;.
Look at the edges beginning at type &lt;code&gt;\(s\)&lt;/code&gt; nodes and count how many end at type &lt;code&gt;\(t\)&lt;/code&gt; nodes.
Call this count &lt;code&gt;\(m_{st}\)&lt;/code&gt;.
Do the same for all type pairs to obtain a matrix &lt;code&gt;\(M=(m_{st})\)&lt;/code&gt; of edge counts.
Divide the entries in &lt;code&gt;\(M\)&lt;/code&gt; by their sum to obtain &lt;code&gt;\(X\)&lt;/code&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>nberwp 1.1.0</title>
      <link>https://bldavies.com/blog/nberwp-1-1-0/</link>
      <pubDate>Fri, 21 Jan 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/nberwp-1-1-0/</guid>
      <description>&lt;p&gt;A new version of &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;nberwp&lt;/a&gt;, an R package containing data on &lt;a href=&#34;https://www.nber.org/papers&#34;&gt;NBER working papers&lt;/a&gt;, is &lt;a href=&#34;https://cran.r-project.org/package=nberwp&#34;&gt;available on CRAN&lt;/a&gt;.
This version adds information about (i) papers published in July&amp;ndash;December 2021 and (ii) author sexes.&lt;/p&gt;
&lt;h2 id=&#34;papers-from-late-2021&#34;&gt;Papers from late 2021&lt;/h2&gt;
&lt;p&gt;The second half of 2021 saw 649 new NBER working papers by 1,663 unique authors, 503 of whom had not published in the series previously.
Those counts were down (from 858, 2,094, and 683, respectively) from the second half of 2020, but roughly in-line with pre-pandemic trends:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/monthly-papers-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;nberwp 1.1.0 also corrects some &lt;a href=&#34;https://bldavies.com/blog/nber-co-authorships/&#34;&gt;false merges and splits&lt;/a&gt; among authors who published &lt;em&gt;before&lt;/em&gt; July 2021.
These corrections lowered the number of such authors from 15,437 in version 1.0.0 to 15,430 in version 1.1.0.&lt;/p&gt;
&lt;h2 id=&#34;author-sexes&#34;&gt;Author sexes&lt;/h2&gt;
&lt;p&gt;nberwp 1.1.0 adds information about author sexes, allowing one to, e.g., visualize the growing &lt;a href=&#34;https://bldavies.com/blog/female-representation-collaboration-nber/&#34;&gt;female representation&lt;/a&gt; among NBER working paper authors:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/female-representation-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I obtain sex information by matching authors&amp;rsquo; names with baby name and Facebook data, and through manual identification.
I document my matching and manual procedures in &amp;ldquo;&lt;a href=&#34;https://doi.org/10.31235/osf.io/zeb7a&#34;&gt;Sex-based sorting among economists: Evidence from the NBER&lt;/a&gt;,&amp;rdquo; a new paper comparing males&amp;rsquo; and females&amp;rsquo; co-authorship patterns.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Hypothesis tests and Bayesian reasoning</title>
      <link>https://bldavies.com/blog/hypothesis-tests-bayesian-reasoning/</link>
      <pubDate>Thu, 06 Jan 2022 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/hypothesis-tests-bayesian-reasoning/</guid>
      <description>&lt;p&gt;Most empirical research relies on &lt;a href=&#34;https://en.wikipedia.org/wiki/Statistical_hypothesis_testing&#34;&gt;hypothesis testing&lt;/a&gt;.
We form null and alternative hypotheses (e.g., a regression coefficient equals zero or doesn&amp;rsquo;t), collect some data, and reject the null if it implies those data are rare enough.
How rare is &amp;ldquo;enough&amp;rdquo; depends on the context, but a common rule is to reject the null if the &lt;a href=&#34;https://en.wikipedia.org/wiki/P-value&#34;&gt;p-value&lt;/a&gt;&amp;mdash;that is, the probability of observing the same or rarer data &lt;em&gt;given the null is true&lt;/em&gt;&amp;mdash;is smaller than 0.05.
However, this rule can lead to very different conclusions than &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayesian&lt;/a&gt; reasoning.&lt;/p&gt;
&lt;p&gt;For example, suppose I&amp;rsquo;m the government trying to collect taxes.
I know 1% of taxpayers cheat (e.g., by under-reporting their income), so I hire an auditor to detect cheating.
The auditor makes occasional mistakes: they incorrectly detect cheating among 2% of non-cheaters.
But the auditor never fails to detect cheating when it happens.&lt;/p&gt;
&lt;p&gt;Suppose the auditor tells me Joe cheated on his taxes.
Should I prosecute him for fraud?
Letting &amp;ldquo;Joe is innocent&amp;rdquo; be the null hypothesis and &amp;ldquo;Joe is guilty&amp;rdquo; be the alternative, the p-value of the auditor&amp;rsquo;s message is simply their &lt;a href=&#34;https://en.wikipedia.org/wiki/False_positives_and_false_negatives&#34;&gt;false positive&lt;/a&gt; rate: 0.02.
This p-value is smaller than the 0.05 &amp;ldquo;critical value&amp;rdquo; below which I reject nulls, so I take the auditor&amp;rsquo;s message as strong evidence of guilt.&lt;/p&gt;
&lt;p&gt;Now consider a random sample of a thousand taxpayers.
The auditor accuses all ten cheaters in this sample of cheating.
But the auditor also accuses 20 of the 990 &lt;em&gt;non-cheaters&lt;/em&gt; of cheating.
So only one in three accusees actually cheated&amp;mdash;if I thought everyone like Joe was guilty, I would be wrong two thirds of the time!
That&amp;rsquo;s hardly evidence of guilt &amp;ldquo;beyond reasonable doubt.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s going on?
Why does the hypothesis test suggest Joe is guilty, when simply counting true and false accusations suggests he&amp;rsquo;s innocent?&lt;/p&gt;
&lt;p&gt;The suggestions differ because they are based on different probabilities.
The hypothesis test uses the probability that the auditor detects Joe cheating &lt;em&gt;given he is innocent&lt;/em&gt;: 0.02.
But the counting argument uses the probability that Joe is innocent &lt;em&gt;given the auditor detects him cheating&lt;/em&gt;: 0.66.
(Notice the swap in what comes before and after &amp;ldquo;given.&amp;quot;)&lt;/p&gt;
&lt;p&gt;But which probability should I use?
Should I follow my hypothesis test and prosecute Joe, or should I follow my counting argument and let him walk free?&lt;/p&gt;
&lt;p&gt;One problem with the hypothesis test is that it ignores the &lt;a href=&#34;https://en.wikipedia.org/wiki/Base_rate&#34;&gt;base rate&lt;/a&gt;: most taxpayers are innocent.
Sure, false accusations are rare, but there are lots of non-cheaters to falsely accuse!
These false accusations crowd out the true accusations, which are relatively rare because cheating is rare.&lt;/p&gt;
&lt;p&gt;In contrast, counting accusees effectively takes the base rate as a &lt;a href=&#34;https://en.wikipedia.org/wiki/Prior_probability&#34;&gt;prior belief&lt;/a&gt; in Joe&amp;rsquo;s innocence and updates this belief in response to the evidence provided by the auditor.
My belief updates a lot&amp;mdash;from 0.99 to 0.66&amp;mdash;but not enough to indict Joe beyond reasonable doubt.
The auditor&amp;rsquo;s &lt;a href=&#34;https://bldavies.com/blog/learning-noisy-signals/&#34;&gt;signal is too noisy&lt;/a&gt; to establish guilt on its own.
(One way to combat this noise is to hire a &lt;em&gt;second&lt;/em&gt; auditor, identical to but independent of the first.
If &lt;em&gt;both&lt;/em&gt; auditors told me Joe cheated then my belief in his innocence would fall to 0.04, which would be much stronger grounds for prosecution.)&lt;/p&gt;
&lt;p&gt;However, things can change if my prior belief is incorrect.
For example, suppose I think 10% of taxpayers cheat, ten times as many as &lt;em&gt;actually&lt;/em&gt; cheat.
When the auditor tells me Joe cheated, &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayes&amp;rsquo; formula&lt;/a&gt; tells me to update my belief in Joe&amp;rsquo;s innocence from 0.9 to 0.15, which is plausible grounds for prosecution.
Now accusee-counting &lt;em&gt;agrees&lt;/em&gt; with my hypothesis test, even though my evidence didn&amp;rsquo;t change.
This sensitivity to prior beliefs&amp;mdash;which may be incorrect, or may not even exist&amp;mdash;is a common criticism of &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayesian_inference&#34;&gt;Bayesian inference&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But I like the Bayesian approach.
It forces me to remember that data are noisy: the auditor makes mistakes, as do the tools I use to observe and catch data in the wild.
This noisiness affects how I should interpret data as evidence of how the world works.
Bayesian reasoning also forces me to specify my priors&amp;mdash;&lt;a href=&#34;https://bldavies.com/blog/lessons-dave-mare/#have-weak-priors-and-strong-nulls&#34;&gt;they&amp;rsquo;re probably wrong&lt;/a&gt;, but specifying them encourages me to think about &lt;em&gt;why&lt;/em&gt; they&amp;rsquo;re wrong (and, hopefully, work to make them &lt;em&gt;less&lt;/em&gt; wrong).&lt;/p&gt;
&lt;p&gt;I won&amp;rsquo;t go decrying hypothesis tests any time soon: they&amp;rsquo;re well-established as the dominant tool in empirical economics, not least because they&amp;rsquo;re easier to describe and interpret than Bayesian arguments.
But I&amp;rsquo;ll try to &amp;ldquo;be more Bayesian&amp;rdquo; generally: to think more carefully about my beliefs, about evidence, and how my beliefs respond to evidence.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://sites.google.com/view/anirudh-sankar&#34;&gt;Anirudh Sankar&lt;/a&gt; for reading a draft version of this post.
It was inspired by the tenth chapter of Jordan Ellenberg&amp;rsquo;s &amp;ldquo;&lt;a href=&#34;http://www.jordanellenberg.com/book/how-not-to-be-wrong/&#34;&gt;How Not to Be Wrong&lt;/a&gt;.&amp;quot;&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Stable matchings with correlated preferences</title>
      <link>https://bldavies.com/blog/stable-matchings-correlated-preferences/</link>
      <pubDate>Fri, 19 Nov 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/stable-matchings-correlated-preferences/</guid>
      <description>&lt;p&gt;Suppose I use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm&#34;&gt;Gale-Shapley (GS) algorithm&lt;/a&gt; to find a &lt;a href=&#34;https://bldavies.com/blog/stable-matchings/&#34;&gt;stable matching&lt;/a&gt; between two sets &lt;code&gt;\(P\)&lt;/code&gt; and &lt;code&gt;\(R\)&lt;/code&gt; of size &lt;code&gt;\(n\)&lt;/code&gt;.
Proposer &lt;code&gt;\(p\in P\)&lt;/code&gt; gets utility
&lt;code&gt;$$u_{rp}=\alpha w_r+(1-\alpha)x_{rp}$$&lt;/code&gt;
from being matched with reviewer &lt;code&gt;\(r\in R\)&lt;/code&gt;, where &lt;code&gt;\(w_r\)&lt;/code&gt; is common to all proposers, &lt;code&gt;\(x_{rp}\)&lt;/code&gt; is specific to proposer &lt;code&gt;\(p\)&lt;/code&gt;, and &lt;code&gt;\(\alpha\in[0,1]\)&lt;/code&gt; controls the correlation in utilities across proposers.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Likewise, reviewer &lt;code&gt;\(r\)&lt;/code&gt; gets utility
&lt;code&gt;$$v_{pr}=\beta y_p+(1-\beta)z_{pr}$$&lt;/code&gt;
from being matched with proposer &lt;code&gt;\(p\)&lt;/code&gt;, where &lt;code&gt;\(y_p\)&lt;/code&gt; is common to all reviewers, &lt;code&gt;\(z_{pr}\)&lt;/code&gt; is specific to reviewer &lt;code&gt;\(r\)&lt;/code&gt;, and &lt;code&gt;\(\beta\in[0,1]\)&lt;/code&gt; controls the correlation in utilities across reviewers.
The &lt;code&gt;\(w_r\)&lt;/code&gt;, &lt;code&gt;\(x_{rp}\)&lt;/code&gt;, &lt;code&gt;\(y_p\)&lt;/code&gt;, and &lt;code&gt;\(z_{pr}\)&lt;/code&gt; are iid standard normal.
I run the GS algorithm 200 times, each time (i) simulating new utility realizations and (ii) computing the means
&lt;code&gt;$$U\equiv\frac{1}{n}\sum_{p\in P}u_{rp}$$&lt;/code&gt;
and
&lt;code&gt;$$V\equiv\frac{1}{n}\sum_{r\in R}v_{pr}$$&lt;/code&gt;
of utilities under the resulting matching.
I then compute the &lt;a href=&#34;https://en.wikipedia.org/wiki/Grand_mean&#34;&gt;grand means&lt;/a&gt; of &lt;code&gt;\(U\)&lt;/code&gt; and &lt;code&gt;\(V\)&lt;/code&gt; across all 200 simulations.
The chart below shows how these grand means vary with &lt;code&gt;\(\alpha\)&lt;/code&gt; and &lt;code&gt;\(\beta\)&lt;/code&gt; when &lt;code&gt;\(n=50\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Proposers and reviewers tend to be better off when (i) utilities on their side of the market are &lt;em&gt;less&lt;/em&gt; correlated and (ii) utilities on the &lt;em&gt;other&lt;/em&gt; side of the market are &lt;em&gt;more&lt;/em&gt; correlated.
Intuitively, same-side correlations induce competition that makes the most desirable people on that side better off but the rest much worse off.
This competition benefits the other side of the market because it gives people on that side more power to choose &amp;ldquo;winners&amp;rdquo; according to their preferences.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;If &lt;code&gt;\(\mathrm{Var}(w_r)=\sigma_w^2\)&lt;/code&gt; and &lt;code&gt;\(\mathrm{Var}(x_{rp})=\sigma_x^2\)&lt;/code&gt; then &lt;code&gt;\(\mathrm{Corr}(u_{rp},u_{rq})=[1+(1-\alpha)^2\sigma_x^2/\alpha^2\sigma_w^2]^{-1}\)&lt;/code&gt; increases with &lt;code&gt;\(\alpha\)&lt;/code&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Learning from noisy signals</title>
      <link>https://bldavies.com/blog/learning-noisy-signals/</link>
      <pubDate>Sat, 23 Oct 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/learning-noisy-signals/</guid>
      <description>&lt;p&gt;Suppose I want to learn the value of &lt;code&gt;\(\omega\in\{0,1\}\)&lt;/code&gt;.
I observe a sequence of iid signals &lt;code&gt;\((s_n)_{n\ge1}\)&lt;/code&gt; with
&lt;code&gt;$$\Pr(s_n=0\,\vert\,\omega=0)=1-\alpha$$&lt;/code&gt;
and
&lt;code&gt;$$\Pr(s_n=1\,\vert\,\omega=1)=1-\beta,$$&lt;/code&gt;
where &lt;code&gt;\(\alpha\)&lt;/code&gt; and &lt;code&gt;\(\beta\)&lt;/code&gt; are &lt;a href=&#34;https://en.wikipedia.org/wiki/Type_I_and_type_II_errors&#34;&gt;false positive and false negative rates&lt;/a&gt;.
I let &lt;code&gt;\(\pi_n\)&lt;/code&gt; denote my belief that &lt;code&gt;\(\omega=1\)&lt;/code&gt; after observing &lt;code&gt;\(n\)&lt;/code&gt; signals, and update this belief sequentially via &lt;a href=&#34;https://en.wikipedia.org/wiki/Bayes%27_theorem&#34;&gt;Bayes&amp;rsquo; formula&lt;/a&gt;:
&lt;code&gt;$$\pi_{n}(s)=\frac{\Pr(s_n=s\,\vert\,\omega=1)\pi_{n-1}}{\Pr(s_n=s)}.$$&lt;/code&gt;
In particular, if I observe &lt;code&gt;\(s_n=0\)&lt;/code&gt; then I update my belief to
&lt;code&gt;$$\pi_n(0)=\frac{\beta\pi_{n-1}}{\beta\pi_{n-1}+(1-\alpha)(1-\pi_{n-1})},$$&lt;/code&gt;
whereas if I observe &lt;code&gt;\(s_n=1\)&lt;/code&gt; then I update my belief to
&lt;code&gt;$$\pi_n(1)=\frac{(1-\beta)\pi_{n-1}}{(1-\beta)\pi_{n-1}+\alpha(1-\pi_{n-1})}.$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The chart below shows how my belief &lt;code&gt;\(\pi_n\)&lt;/code&gt; changes with &lt;code&gt;\(n\)&lt;/code&gt;.
Each path in the chart corresponds to the sequence of beliefs &lt;code&gt;\((\pi_0,\pi_1,\ldots,\pi_{100})\)&lt;/code&gt; obtained by updating my initial belief &lt;code&gt;\(\pi_0=0.5\)&lt;/code&gt; in response to a signal sequence &lt;code&gt;\((s_1,s_2,\ldots,s_{100})\)&lt;/code&gt;.
I simulate 10 such sequences, fixing &lt;code&gt;\(\omega=1\)&lt;/code&gt; and &lt;code&gt;\(\alpha=0.4\)&lt;/code&gt; but varying &lt;code&gt;\(\beta\in\{0.2,0.4,0.6,0.8\}\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/paths-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;\(\beta\not=0.6\)&lt;/code&gt; then my belief converges to &lt;code&gt;\(\pi_n=1\)&lt;/code&gt; as &lt;code&gt;\(n\)&lt;/code&gt; grows.
However, if &lt;code&gt;\(\beta=0.6\)&lt;/code&gt; then &lt;code&gt;\(\pi_n=\pi_0\)&lt;/code&gt; for each &lt;code&gt;\(n\)&lt;/code&gt;; that is, I never update my beliefs regardless of the signals I observe.
This is because if &lt;code&gt;\(\alpha+\beta=1\)&lt;/code&gt; then &lt;code&gt;\(\Pr(s_n=s\cap\omega=1)=\Pr(s_n=s)\)&lt;/code&gt; for each &lt;code&gt;\(s\in\{0,1\}\)&lt;/code&gt;, and so signals are uninformative because they are independent of &lt;code&gt;\(\omega\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The chart below plots the mean of my beliefs &lt;code&gt;\(\pi_n\)&lt;/code&gt; across 1,000 realizations of the signals simulated above.
Again, I fix &lt;code&gt;\(\omega=1\)&lt;/code&gt; and the false positive rate &lt;code&gt;\(\alpha=0.4\)&lt;/code&gt; but vary the false negative rate &lt;code&gt;\(\beta\in\{0.2,0.4,0.6,0.8\}\)&lt;/code&gt;.
Higher values of &lt;code&gt;\(\beta\)&lt;/code&gt; are not always worse: my belief converges to the truth faster when &lt;code&gt;\(\beta=0.8\)&lt;/code&gt; than when &lt;code&gt;\(\beta=0.4\)&lt;/code&gt;.
Intuitively, if I know the false negative rate is close to 100% then observing a signal &lt;code&gt;\(s_n=0\)&lt;/code&gt; gives me strong evidence that &lt;code&gt;\(\omega=1\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/means-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>A competition model of corruption</title>
      <link>https://bldavies.com/blog/competition-model-corruption/</link>
      <pubDate>Tue, 12 Oct 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/competition-model-corruption/</guid>
      <description>&lt;p&gt;This post presents a simple model of corruption in two-party elections.
The model is similar to one of &lt;a href=&#34;https://en.wikipedia.org/wiki/Cournot_competition&#34;&gt;Cournot competition&lt;/a&gt;: parties choose quantities of corruption in response to implicit &amp;ldquo;price&amp;rdquo; schedules determined by voter preferences.
I describe the &lt;a href=&#34;#model&#34;&gt;model&lt;/a&gt;, &lt;a href=&#34;#equilibrium&#34;&gt;derive&lt;/a&gt; and &lt;a href=&#34;#comparative-statics&#34;&gt;analyze&lt;/a&gt; its equilibrium, provide a &lt;a href=&#34;#numerical-example&#34;&gt;numerical example&lt;/a&gt;, and discuss some &lt;a href=&#34;#alternative-models&#34;&gt;alternatives&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;model&#34;&gt;Model&lt;/h2&gt;
&lt;p&gt;Two parties &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; compete for votes in an electoral system with &lt;a href=&#34;https://en.wikipedia.org/wiki/Proportional_representation&#34;&gt;proportional representation&lt;/a&gt;.
Each party &lt;code&gt;\(k\)&lt;/code&gt; chooses its corruption level &lt;code&gt;\(c_k\)&lt;/code&gt; to maximize &lt;code&gt;\(c_ks_k(c_A,c_B)\)&lt;/code&gt;, where party &lt;code&gt;\(k\)&lt;/code&gt;&#39;s vote share &lt;code&gt;\(s_k(c_A,c_B)\)&lt;/code&gt; depends on both parties&amp;rsquo; chosen corruptions.
This objective captures how parties benefit from engaging in corrupt activities, but only insofar as voters give them power to do so.&lt;/p&gt;
&lt;p&gt;Voters don&amp;rsquo;t like corruption: voter &lt;code&gt;\(i\)&lt;/code&gt;&#39;s payoff from voting for &lt;code&gt;\(A\)&lt;/code&gt; is &lt;code&gt;\((1-c_A+\epsilon_i)\)&lt;/code&gt; and their payoff from voting for &lt;code&gt;\(B\)&lt;/code&gt; is &lt;code&gt;\((1-c_B)\)&lt;/code&gt;.
The &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; are iid uniformly distributed on &lt;code&gt;\([b-w,b+w]\)&lt;/code&gt;, where &lt;code&gt;\(b\)&lt;/code&gt; is the mean bias in favor of party &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(w&amp;gt;0\)&lt;/code&gt; controls the noise in voter preferences.
Thus, party &lt;code&gt;\(A\)&lt;/code&gt;&#39;s vote share is
&lt;code&gt;$$\begin{aligned} s_A(c_A,c_B) &amp;amp;= \Pr(1-c_A+\epsilon_i\ge1-c_B) \\ &amp;amp;= \Pr(\epsilon_i\ge c_A-c_B) \\ &amp;amp;= \frac{b+w-(c_A-c_B)}{(b+w)-(b-w)} \\ &amp;amp;= \frac{1}{2}+\frac{b-(c_A-c_B)}{2w} \end{aligned}$$&lt;/code&gt;
while party &lt;code&gt;\(B\)&lt;/code&gt;&#39;s vote share is
&lt;code&gt;$$\begin{aligned} s_B &amp;amp;= 1-s_A(c_A,c_B) \\ &amp;amp;= \frac{1}{2}-\frac{b-(c_A-c_B)}{2w}. \end{aligned}$$&lt;/code&gt;
Parties &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; engage in a form of Cournot competition: they choose corruptions &lt;code&gt;\(c_k\)&lt;/code&gt; independently and simultaneously, with full knowledge of the (inverse) demand curves &lt;code&gt;\(s_k(c_A,c_B)\)&lt;/code&gt;.
These curves are downward-sloping: the &amp;ldquo;price&amp;rdquo; &lt;code&gt;\(s_k\)&lt;/code&gt;, reflecting voters&amp;rsquo; willingness to spend their votes on party &lt;code&gt;\(k\)&lt;/code&gt;, falls with the chosen &amp;ldquo;quantity&amp;rdquo; &lt;code&gt;\(c_k\)&lt;/code&gt;.
Corruptions &lt;code&gt;\(c_A\)&lt;/code&gt; and &lt;code&gt;\(c_B\)&lt;/code&gt; are substitutes in the sense that, e.g., the price &lt;code&gt;\(s_A\)&lt;/code&gt; rises with &lt;code&gt;\(c_B\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;equilibrium&#34;&gt;Equilibrium&lt;/h2&gt;
&lt;p&gt;The competition over corruption levels resolves at a &lt;a href=&#34;https://en.wikipedia.org/wiki/Nash_equilibrium&#34;&gt;Nash equilibrium&lt;/a&gt; in which each party chooses optimally given the other party&amp;rsquo;s choice.
For party &lt;code&gt;\(A\)&lt;/code&gt;, this means choosing &lt;code&gt;\(c_A^*\)&lt;/code&gt; to satisfy the first-order condition
&lt;code&gt;$$\newcommand{\parfrac}[2]{\frac{\partial\,#1}{\partial\,#2}} \begin{aligned} 0 &amp;amp;= \parfrac{}{c_A^*}\left(c_A^*\,s_A(c_A^*,c_B)\right) \\ &amp;amp;= \frac{1}{2}+\frac{b-2c_A^*+c_B}{2w}, \end{aligned}$$&lt;/code&gt;
which can be rewritten as
&lt;code&gt;$$2c_A^*-c_B=w+b.$$&lt;/code&gt;
Similarly, the first-order condition for party &lt;code&gt;\(B\)&lt;/code&gt;&#39;s optimal choice &lt;code&gt;\(c_B^*\)&lt;/code&gt; can be written as
&lt;code&gt;$$-c_A+2c_B^*=w-b.$$&lt;/code&gt;
Therefore, the Nash equilibrium &lt;code&gt;\((c_A^*,c_B^*)\)&lt;/code&gt; levels of corruption satisfy the linear system
&lt;code&gt;$$\begin{bmatrix}2&amp;amp;-1\\-1&amp;amp;2\end{bmatrix}\begin{bmatrix}c_A^*\\c_B^*\end{bmatrix}=\begin{bmatrix}w+b\\w-b\end{bmatrix},$$&lt;/code&gt;
which has unique solution
&lt;code&gt;$$\begin{bmatrix}c_A^*\\c_B^*\end{bmatrix}=\frac{1}{3}\begin{bmatrix}3w+b\\3w-b\end{bmatrix}.$$&lt;/code&gt;
Party &lt;code&gt;\(A\)&lt;/code&gt;&#39;s vote share in this equilibrium is
&lt;code&gt;$$s_A(c_A^*,c_B^*)=\frac{1}{2}\left(1-\frac{b}{3w}\right),$$&lt;/code&gt;
which exceeds 50% if and only if &lt;code&gt;\(b\)&lt;/code&gt; is &lt;em&gt;negative&lt;/em&gt;; that is, when voters are biased &lt;em&gt;against&lt;/em&gt; party &lt;code&gt;\(A\)&lt;/code&gt;.
In that case, party &lt;code&gt;\(A\)&lt;/code&gt; can&amp;rsquo;t &amp;ldquo;sell&amp;rdquo; as much corruption as party &lt;code&gt;\(B\)&lt;/code&gt; because voters aren&amp;rsquo;t as tolerant of &lt;code&gt;\(A\)&lt;/code&gt;&#39;s corruption as &lt;code&gt;\(B\)&lt;/code&gt;&#39;s.
But the price elasticity of corruption is party-invariant, so selling less corruption &lt;code&gt;\(c_A^*\)&lt;/code&gt; allows party &lt;code&gt;\(A\)&lt;/code&gt; to obtain a higher price &lt;code&gt;\(s_A(c_A^*,c_B^*)\)&lt;/code&gt; than party &lt;code&gt;\(B\)&lt;/code&gt;.
Nonetheless, both parties obtain the same &amp;ldquo;corruption revenue&amp;rdquo; in equilibrium:
&lt;code&gt;$$c_k^*s_k(c_A^*,c_B^*)=\frac{w}{2}-\frac{b^2}{18w}.$$&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;comparative-statics&#34;&gt;Comparative statics&lt;/h2&gt;
&lt;p&gt;Differentiating the Nash equilibrium corruption levels &lt;code&gt;\(c_A^*\)&lt;/code&gt; and &lt;code&gt;\(c_B^*\)&lt;/code&gt; with respect to the mean bias &lt;code&gt;\(b\)&lt;/code&gt; gives
&lt;code&gt;$$\parfrac{c_A^*}{b}=\frac{1}{3}=-\parfrac{c_B^*}{b},$$&lt;/code&gt;
implying that if &lt;code&gt;\(b\)&lt;/code&gt; increases then party &lt;code&gt;\(A\)&lt;/code&gt; becomes more corrupt by exactly the amount that party &lt;code&gt;\(B\)&lt;/code&gt; becomes less corrupt.
Indeed, aggregate corruption &lt;code&gt;\(c_A^*+c_B^*=2w\)&lt;/code&gt; is constant in &lt;code&gt;\(b\)&lt;/code&gt; but increases with &lt;code&gt;\(w\)&lt;/code&gt;.
Both parties become more corrupt (in equilibrium) when &lt;code&gt;\(w\)&lt;/code&gt; rises:
&lt;code&gt;$$\parfrac{c_A^*}{w}=1=\parfrac{c_B^*}{w}.$$&lt;/code&gt;
Intuitively, if &lt;code&gt;\(w\)&lt;/code&gt; rises then voters become less sensitive to corruption because their preferences become noisier.
Both parties exploit this fall in sensitivity by becoming more corrupt, which makes them better off because
&lt;code&gt;$$\parfrac{}{w}\left(c_k^*\,s_k(c_A^*,c_B^*)\right)=\frac{1}{2}+\frac{b^2}{18w^2}$$&lt;/code&gt;
is strictly positive.
On the other hand, if &lt;code&gt;\(b\)&lt;/code&gt; rises then voters become more willing to tolerate party &lt;code&gt;\(A\)&lt;/code&gt;&#39;s corruption and less willing to tolerate party &lt;code&gt;\(B\)&lt;/code&gt;&#39;s.
Party &lt;code&gt;\(A\)&lt;/code&gt; responds to this shift in relative tolerance by selling more corruption, albeit at a lower price &lt;code&gt;\(s_A(c_A^*,c_B^*)\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;numerical-example&#34;&gt;Numerical example&lt;/h2&gt;
&lt;p&gt;The Nash equilibrium corruption levels lie at the intersection of party &lt;code&gt;\(A\)&lt;/code&gt;&#39;s best response curve
&lt;code&gt;$$c_A^*=\frac{c_B+w+b}{2}$$&lt;/code&gt;
and party &lt;code&gt;\(B\)&lt;/code&gt;&#39;s best response curve
&lt;code&gt;$$c_B^*=2c_A+w-b,$$&lt;/code&gt;
obtained by rearranging the first-order conditions for &lt;code&gt;\(c_A^*\)&lt;/code&gt; and &lt;code&gt;\(c_B^*\)&lt;/code&gt;.
The chart below plots these curves when &lt;code&gt;\(b=3\)&lt;/code&gt; and &lt;code&gt;\(w=5\)&lt;/code&gt;.
The curves intersect at &lt;code&gt;\((c_A^*,c_B^*)=(6,4)\)&lt;/code&gt;, where party &lt;code&gt;\(A\)&lt;/code&gt; wins a vote share of &lt;code&gt;\(s_A(c_A^*,c_B^*)=40\%\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/nash-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Now suppose the mean bias in favor of party &lt;code&gt;\(A\)&lt;/code&gt; rises to &lt;code&gt;\(b=9\)&lt;/code&gt;.
The chart below shows how this rise shifts parties&amp;rsquo; best response curves in the &lt;code&gt;\(c_Ac_B\)&lt;/code&gt; plane.
These shifts move the Nash equilibrium rightward to &lt;code&gt;\((c_A^*,c_B^*)=(8,2)\)&lt;/code&gt;.
Party &lt;code&gt;\(A\)&lt;/code&gt;&#39;s vote share falls to &lt;code&gt;\(s_A(c_A^*,c_B^*)=20\%\)&lt;/code&gt;, and both parties&amp;rsquo; corruption revenues &lt;code&gt;\(c_k^*s_k(c_A^*,c_B^*)\)&lt;/code&gt; fall from &lt;code&gt;\(2.4\)&lt;/code&gt; to &lt;code&gt;\(1.6\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/nash-shift-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;alternative-models&#34;&gt;Alternative models&lt;/h2&gt;
&lt;p&gt;With proportional representation, every vote for party &lt;code&gt;\(k\)&lt;/code&gt; gives that party more power to engage in corrupt activities.
Consequently, the party trades off its corruption level &lt;code&gt;\(c_k\)&lt;/code&gt; with its vote share &lt;code&gt;\(s_k(c_A,c_B)\)&lt;/code&gt; continuously.
In contrast, if only the party with a majority vote share gains power then corruption revenues become discontinuous in vote shares.
This discontinuity changes the equilibrium choices of &lt;code&gt;\(c_A\)&lt;/code&gt; and &lt;code&gt;\(c_B\)&lt;/code&gt;.
For example, if electoral ties are resolved with a coin toss then the unique equilibrium gives each party a 50% vote share independently of &lt;code&gt;\(b\)&lt;/code&gt; and &lt;code&gt;\(w\)&lt;/code&gt;, and the corruption levels satisfy &lt;code&gt;\(c_A^*=c_B^*+b\)&lt;/code&gt; (as opposed to &lt;code&gt;\(c_A^*=c_B^*+2b/3\)&lt;/code&gt; under proportional representation).&lt;/p&gt;
&lt;p&gt;One way to generalize the model with proportional representation is to introduce voting blocs: groups of voters with group-specific mean biases &lt;code&gt;\(b_j\)&lt;/code&gt; and radii &lt;code&gt;\(w_j\)&lt;/code&gt;.
Then the equilibrium corruption levels become
&lt;code&gt;$$c_A^*=\frac{3+\sum_jb_j\theta_j/w_j}{3\sum_j\theta_j/w_j}$$&lt;/code&gt;
and
&lt;code&gt;$$c_B^*=\frac{3-\sum_jb_j\theta_j/w_j}{3\sum_j\theta_j/w_j},$$&lt;/code&gt;
where &lt;code&gt;\(\theta_j\)&lt;/code&gt; is group &lt;code&gt;\(j\)&lt;/code&gt;&#39;s share of the population.
Intuitively, the equilibrium depends on the aggregate bias and precision of voters&amp;rsquo; preferences, but these aggregates depend on the group-specific biases &lt;code&gt;\(b_j\)&lt;/code&gt; and precisions &lt;code&gt;\(1/w_j\)&lt;/code&gt; as well as the relative group sizes &lt;code&gt;\(\theta_j\)&lt;/code&gt;.
Introducing voting blocs makes the comparative statics more intricate but preserves the underlying intuitions.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Snowball sampling bias in program evaluation</title>
      <link>https://bldavies.com/blog/snowball-sampling-bias-program-evaluation/</link>
      <pubDate>Sat, 04 Sep 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/snowball-sampling-bias-program-evaluation/</guid>
      <description>&lt;p&gt;Suppose I want to run a pilot study of a mental health support program before rolling it out at scale.
The program has heterogeneous treatment effects, but tends to be more effective for people who have fewer social connections.
Such people tend to have lower mental health (&lt;a href=&#34;https://doi.org/10.1093/jurban/78.3.458&#34;&gt;Kawachi and Berkman, 2001&lt;/a&gt;) and so have more to gain from participating in the program.&lt;/p&gt;
&lt;p&gt;I recruit people to my study via &lt;a href=&#34;https://en.wikipedia.org/wiki/Snowball_sampling&#34;&gt;snowball sampling&lt;/a&gt;: I advertise it to a few initial seeds, who share the ads with their friends, who share the ads with their friends, and so on.
Everyone who sees an ad participates.
But some people are more likely to see ads than others: in particular, people with more friends have more chances to be sent an ad.
Consequently, I will tend to under-estimate the average treatment effect (ATE) of the program because people with more social connections, for whom the program is less effective, are more likely to appear in my pilot sample.
Such under-estimation may lead me to abandon the program even if its mental health benefits actually outweigh its implementation costs.&lt;/p&gt;
&lt;h2 id=&#34;demonstration&#34;&gt;Demonstration&lt;/h2&gt;
&lt;p&gt;As a concrete example, suppose each individual &lt;code&gt;\(i\)&lt;/code&gt; has degree &lt;code&gt;\(d_i\)&lt;/code&gt; in the social network from which I recruit my sample.
The treatment effect of the program on individual &lt;code&gt;\(i\)&lt;/code&gt; is
&lt;code&gt;$$\beta_i=1-r\bar{d}_i+(1-r)z_i,$$&lt;/code&gt;
where &lt;code&gt;\(\bar{d}_i\)&lt;/code&gt; is a normalization of &lt;code&gt;\(d_i\)&lt;/code&gt; with zero mean and unit variance across the network, the &lt;code&gt;\(z_i\)&lt;/code&gt; are iid standard normal, and &lt;code&gt;\(r\)&lt;/code&gt; is a parameter controlling the (negative) correlation between the &lt;code&gt;\(\beta_i\)&lt;/code&gt; and &lt;code&gt;\(d_i\)&lt;/code&gt;.
The treatment effects &lt;code&gt;\(\beta_i\)&lt;/code&gt; give rise to individual-level outcomes
&lt;code&gt;$$y_i=\beta_it_i+\epsilon_i,$$&lt;/code&gt;
where the &lt;code&gt;\(t_i\)&lt;/code&gt; are binary treatment indicators and the &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; are iid standard normal errors.
The sample delivers an estimate
&lt;code&gt;$$\hat\beta=\frac{\sum_iy_it_i}{\sum_it_i}-\frac{\sum_iy_i(1-t_i)}{\sum_i(1-t_i)}$$&lt;/code&gt;
of the program&amp;rsquo;s ATE: the difference in mean outcomes between treated and untreated members of the pilot sample.
Treatments are assigned to sample members randomly.
But the sample is recruited non-randomly: individual &lt;code&gt;\(i\)&lt;/code&gt; is recruited with probability proportional to their degree &lt;code&gt;\(d_i\)&lt;/code&gt;.
This non-random recruitment leads to sampling bias when the &lt;code&gt;\(\beta_i\)&lt;/code&gt; and &lt;code&gt;\(d_i\)&lt;/code&gt; are correlated.&lt;/p&gt;
&lt;p&gt;The chart below summarizes the distribution of ATE estimates across 500 snowball samples of 250 people from a random social network.
This network contains 1,000 bilateral friendships among 1,000 people.
Network degrees vary between zero and seven, producing variation in the probability of being sampled.
I randomize the treatment effects &lt;code&gt;\(\beta_i\)&lt;/code&gt; and assignments &lt;code&gt;\(t_i\)&lt;/code&gt; in each simulation run.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The ATE estimate is unbiased when treatment effects are uncorrelated with network degrees.
However, the estimate becomes more biased as the correlation becomes stronger.
Intuitively, the more the program&amp;rsquo;s effectiveness is concentrated among low-degree individuals, the worse the program looks in pilot samples excluding those individuals (independently of how treatments are assigned).&lt;/p&gt;
&lt;h2 id=&#34;potential-solutions&#34;&gt;Potential solutions&lt;/h2&gt;
&lt;p&gt;How can we mitigate snowball sampling bias?
One approach is to collect information about sample members&amp;rsquo; degrees in the social network, and use this information to obtain weighted ATE estimates.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
The difference-in-means estimator &lt;code&gt;\(\hat\beta\)&lt;/code&gt; equals the OLS estimator of &lt;code&gt;\(\beta\)&lt;/code&gt; in the linear model
&lt;code&gt;$$y_i=\beta t_i+\varepsilon_i$$&lt;/code&gt;
relating outcomes to treatment assignments.
Using &lt;a href=&#34;https://en.wikipedia.org/wiki/Weighted_least_squares&#34;&gt;weighted least squares&lt;/a&gt; (WLS) with weights &lt;code&gt;\(w_i=1/\sqrt{d_i}\)&lt;/code&gt; may deliver less biased estimates by accounting for the probability of sampling each individual &lt;code&gt;\(i\)&lt;/code&gt;.
Intuitively, individuals with lower degrees provide relatively more information about the true ATE because they are less likely to be sampled, and so giving these individuals higher weights in the estimation procedure leads to more informed estimates.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
However, the distribution of degrees &lt;code&gt;\(d_i\)&lt;/code&gt; in the sample is different than the distribution of degrees in the full network, and so weighting by the (observed) &lt;code&gt;\(d_i\)&lt;/code&gt; may still deliver different (and thus incorrect) estimates than weighting by the (unobserved) sampling probabilities.&lt;/p&gt;
&lt;p&gt;Another approach, suggested by &lt;a href=&#34;https://dx.doi.org/10.2139/ssrn.3522256&#34;&gt;Jackson et al. (2020)&lt;/a&gt;, is to model sample recruitment explicitly using game theory.
The authors describe a game wherein each individual&amp;rsquo;s recruitment payoff depends on whether their peers are recruited.
The equilibrium of this game determines each individual&amp;rsquo;s recruitment probability conditional on the network structure (and other covariates).
Jackson et al. embed this game in an estimation procedure based on &lt;a href=&#34;https://en.wikipedia.org/wiki/Propensity_score_matching&#34;&gt;propensity score matching&lt;/a&gt;, and show theoretically and empirically that this procedure leads to better ATE estimates.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://twitter.com/RyanBrennanEcon&#34;&gt;Ryan Brennan&lt;/a&gt; for discussing the ideas presented in this post.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This approach is conceptually similar to the &amp;ldquo;respondent-driven sampling&amp;rdquo; technique described by &lt;a href=&#34;https://doi.org/10.1111/j.0081-1750.2004.00152.x&#34;&gt;Salganik and Heckathorn (2004)&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Taking square roots recognizes that the objective of WLS is to minimize the weighted sum of &lt;em&gt;squared&lt;/em&gt; residuals. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Improving human predictions</title>
      <link>https://bldavies.com/blog/improving-human-predictions/</link>
      <pubDate>Tue, 17 Aug 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/improving-human-predictions/</guid>
      <description>&lt;p&gt;Chapter 9 of &lt;a href=&#34;https://readnoise.com&#34;&gt;Kahneman et al. (2021)&lt;/a&gt; discusses how predictions made by humans can be less accurate than predictions made using statistical models.
Part of the chapter describes research by &lt;a href=&#34;https://doi.org/10.1037/h0029230&#34;&gt;Goldberg (1970)&lt;/a&gt; and subsequent authors showing that models of human predictions can out-perform the humans on which those models are based.&lt;/p&gt;
&lt;p&gt;For example, suppose I&amp;rsquo;m asked to make predictions in a range of contexts &lt;code&gt;\(i\in\{1,2,\ldots,n\}\)&lt;/code&gt;.
My goal is to use some contextual data &lt;code&gt;\(x_i\in\mathbb{R}^k\)&lt;/code&gt; to predict the value of a context-specific outcome &lt;code&gt;\(y_i\)&lt;/code&gt;.
I generate predictions
&lt;code&gt;$$\newcommand{\abs}[1]{\lvert#1\rvert} \bar{y}_i=y_i+u_i,$$&lt;/code&gt;
where the &lt;code&gt;\(u_i\)&lt;/code&gt; are context-specific errors.
The accuracy of my predictions can be measured via their &lt;a href=&#34;https://en.wikipedia.org/wiki/Mean_squared_error&#34;&gt;mean squared error&lt;/a&gt; (MSE)
&lt;code&gt;$$\frac{1}{n}\sum_{i=1}^n(\bar{y}_i-y_i)^2=\frac{1}{n}\sum_{i=1}^nu_i^2,$$&lt;/code&gt;
where a lower MSE implies higher accuracy.
Another way to generate predictions could be to posit a linear model
&lt;code&gt;$$y_i=\theta x_i+\epsilon_i,$$&lt;/code&gt;
where &lt;code&gt;\(\theta\)&lt;/code&gt; is a row vector of coefficients and the &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; are random errors.
But I don&amp;rsquo;t know the true outcomes &lt;code&gt;\(y_i\)&lt;/code&gt;&amp;mdash;hence needing to predict them&amp;mdash;and so I can&amp;rsquo;t just use ordinary least squares (OLS) to estimate &lt;code&gt;\(\theta\)&lt;/code&gt;.
Instead, Goldberg (1970) suggests replacing this linear model with
&lt;code&gt;$$\bar{y}_i=\beta x_i+\varepsilon_i,$$&lt;/code&gt;
where &lt;code&gt;\(\beta\)&lt;/code&gt; is a (possibly different) vector of coefficients and the &lt;code&gt;\(\varepsilon_i\)&lt;/code&gt; are (possibly different) random errors.
This second model describes the linearized relationship between my (possibly incorrect) predictions &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; and the data &lt;code&gt;\(x_i\)&lt;/code&gt; on which those predictions are based.
Since I know my predictions &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt;, I can use OLS to obtain an estimate &lt;code&gt;\(\hat\beta\)&lt;/code&gt; of &lt;code&gt;\(\beta\)&lt;/code&gt; and produce a set of &amp;ldquo;modeled predictions&amp;rdquo;
&lt;code&gt;$$\hat{y}_i=\hat\beta x_i.$$&lt;/code&gt;
The difference between the &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; and &lt;code&gt;\(\hat{y}_i\)&lt;/code&gt; is that the latter ignore the non-linearities in my method for generating predictions.
Intuitively, the &lt;code&gt;\(\hat{y}_i\)&lt;/code&gt; represent what I would predict using a simple, linear formula; my predictions &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; may be generated using a formula that is much more complex, or may not be generated using a formula at all.&lt;/p&gt;
&lt;p&gt;So, how do my raw predictions &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; and their modeled counterparts &lt;code&gt;\(\hat{y}_i\)&lt;/code&gt; compare?
The chart below plots the &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; and &lt;code&gt;\(\hat{y}_i\)&lt;/code&gt; against the true values &lt;code&gt;\(y_i\)&lt;/code&gt; when&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt; are iid standard normal, and&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(y_i=(x_i+z_i)/2\)&lt;/code&gt; with &lt;code&gt;\(z_i\)&lt;/code&gt; iid standard normal.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The modeled predictions are far more accurate: they have an MSE of 0.22, whereas my raw predictions have an MSE of 0.76.
In this case, the true relationship between the &lt;code&gt;\(y_i\)&lt;/code&gt; and &lt;code&gt;\(x_i\)&lt;/code&gt; is linear, and so a linear model of my predictions is well-placed to out-perform those predictions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;However, modeling predictions does not always improve their accuracy.
For example, suppose the contextual data &lt;code&gt;\(x_i\)&lt;/code&gt; are scalars, and the &lt;code&gt;\(x_i\)&lt;/code&gt;, &lt;code&gt;\(y_i\)&lt;/code&gt;, and &lt;code&gt;\(u_i\)&lt;/code&gt; have zero means.
Then the MSE of the modeled predictions turns out to be
&lt;code&gt;$$\frac{1}{n}\sum_{i=1}^n(\hat{y}_i-y_i)^2=\sigma_y^2+\rho_{ux}^2\sigma_u^2-\rho_{xy}^2\sigma_y^2,$$&lt;/code&gt;
where &lt;code&gt;\(\sigma_y^2\)&lt;/code&gt; and &lt;code&gt;\(\sigma_u^2\)&lt;/code&gt; are the variances of the &lt;code&gt;\(y_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt;, where &lt;code&gt;\(\rho_{ux}\)&lt;/code&gt; is the correlation of the &lt;code&gt;\(u_i\)&lt;/code&gt; and &lt;code&gt;\(x_i\)&lt;/code&gt;, and where &lt;code&gt;\(\rho_{xy}\)&lt;/code&gt; is the correlation of the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(y_i\)&lt;/code&gt;.
Consequently, replacing my raw predictions &lt;code&gt;\(\bar{y}_i\)&lt;/code&gt; with their modeled counterparts &lt;code&gt;\(\hat{y}_i\)&lt;/code&gt; leads to an accuracy improvement if and only if
&lt;code&gt;$$\sigma_y^2(1-\rho_{xy}^2)&amp;lt;\sigma_u^2(1-\rho_{ux}^2).$$&lt;/code&gt;
This condition holds in the example plotted above: both &lt;code&gt;\(\sigma_u^2\)&lt;/code&gt; and &lt;code&gt;\(\sigma_y^2\)&lt;/code&gt; equal unity, but &lt;code&gt;\(\rho_{xy}=0.69\)&lt;/code&gt; is much larger in absolute value than &lt;code&gt;\(\rho_{ux}=-0.09\)&lt;/code&gt;.
In general, the condition is most likely to hold when&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;\(\sigma_u^2\)&lt;/code&gt; is larger than &lt;code&gt;\(\sigma_y^2\)&lt;/code&gt; (i.e., my raw predictions are relatively noisy);&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(\abs{\rho_{xy}}\)&lt;/code&gt; is large (i.e., the relationship between the &lt;code&gt;\(y_i\)&lt;/code&gt; and &lt;code&gt;\(x_i\)&lt;/code&gt; is approximately linear and deterministic); and&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(\abs{\rho_{ux}}\)&lt;/code&gt; is small (i.e., the errors &lt;code&gt;\(u_i\)&lt;/code&gt; in my raw predictions are relatively uncorrelated with the &lt;code&gt;\(x_i\)&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Intuitively, if the outcomes &lt;code&gt;\(y_i\)&lt;/code&gt; are a linear function of the &lt;code&gt;\(x_i\)&lt;/code&gt; (i.e., if &lt;code&gt;\(\abs{\rho_{xy}}=1\)&lt;/code&gt;) then linearizing my predictions improves their accuracy by removing non-linear errors.
On the other hand, if &lt;em&gt;my prediction errors&lt;/em&gt; &lt;code&gt;\(u_i\)&lt;/code&gt; are a linear function of the &lt;code&gt;\(x_i\)&lt;/code&gt; (i.e., if &lt;code&gt;\(\abs{\rho_{ux}}=1\)&lt;/code&gt;) then linearizing my predictions cannot improve their accuracy because there are no non-linear errors to remove.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Dead ends</title>
      <link>https://bldavies.com/blog/dead-ends/</link>
      <pubDate>Wed, 28 Jul 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/dead-ends/</guid>
      <description>&lt;p&gt;We can think of research as having two phases:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a &amp;ldquo;creative phase,&amp;rdquo; during which researchers search for new ideas, and&lt;/li&gt;
&lt;li&gt;a &amp;ldquo;working phase,&amp;rdquo; during which researchers exert effort on an idea.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1016/j.jet.2020.105167&#34;&gt;Sadler (2021)&lt;/a&gt; views these phases as complementary productive inputs, and analyzes how and why the optimal input mix changes when features of the research environment change.
For example, if creativity becomes more expensive then researchers spend more time working on each idea and, in Sadler&amp;rsquo;s model, tend to work on lower quality ideas.
Policymakers can use subsidies and taxes to change the relative costs of creativity and work, thereby influencing how researchers allocate their time.&lt;/p&gt;
&lt;p&gt;The core features of Sadler&amp;rsquo;s model are as follows.
A researcher wants to maximize the (sum of discounted) payoffs from their life&amp;rsquo;s work on research ideas.
Different ideas have different qualities, and the researcher knows an idea&amp;rsquo;s quality when they find it.
What they don&amp;rsquo;t know is whether each idea is feasible: some ideas are &amp;ldquo;dead ends&amp;rdquo; in the sense that they cannot generate payoffs, no matter their quality or how long the researcher works on them.
The longer the researcher works on an idea without it paying off, the more they start to believe the idea is a dead end.
The researcher can act on this belief at any time by abandoning an idea and searching for a new one.&lt;/p&gt;
&lt;p&gt;In Sadler&amp;rsquo;s model, the researcher continues working on an idea if and only if the expected payoff exceeds the sum of two costs: (i) the effort required to work on the idea and (ii) the opportunity cost of not searching for another idea.
This opportunity cost depends on the researcher&amp;rsquo;s discount rate for future payoffs because new ideas take time to find.
The expected payoff from working on an idea falls over time, implying that there is a unique amount of time that the researcher spends on each idea before abandoning it.
This amount of time is larger for ideas with higher quality.&lt;/p&gt;
&lt;p&gt;If effort becomes more costly then the researcher spends less time working on each idea and focuses their effort on higher quality ideas.
Intuitively, this rise in effort costs makes the creative phase relatively cheaper, so the researcher substitutes towards it.
On the other hand, if the researcher&amp;rsquo;s discount rate rises (i.e., they become less patient) then they spend &lt;em&gt;more&lt;/em&gt; time in the working phase and allow themselves to work on &lt;em&gt;lower&lt;/em&gt; quality ideas.
This is because the discounted payoff from continuing to work on an idea falls by less than the discounted opportunity cost of searching for a new idea.&lt;/p&gt;
&lt;p&gt;Sadler&amp;rsquo;s model helps explain why organizations with a shorter-term focus (i.e., a higher discount rate) tend to be less innovative: they spend too much time working on low quality ideas, and not enough time searching for high quality ideas.
In contrast, organizations that use longer-term incentives, such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Employee_stock_option&#34;&gt;stock options&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Golden_parachute&#34;&gt;golden parachutes&lt;/a&gt;, tend to be more innovative (&lt;a href=&#34;https://doi.org/10.1162/rest.89.4.634&#34;&gt;Lerner and Wulf, 2007&lt;/a&gt;; &lt;a href=&#34;https://dx.doi.org/10.2139/ssrn.1953947&#34;&gt;Francis et al., 2011&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Sadler&amp;rsquo;s model also demonstrates how subsidies and taxes can influence how researchers allocate their time.
Subsidizing effort during the working phase lowers the relative cost of that phase, and so researchers spend more time working but tend to work on lower quality ideas.
Taxing payoffs raises the quality threshold for abandoning an idea, and so researchers spend &lt;em&gt;less&lt;/em&gt; time in the working phase but tend to work on &lt;em&gt;higher&lt;/em&gt; quality ideas.
The optimal policy depends on the social value of research: the more convex is that value in idea quality, the more society wants researchers to focus on fewer but higher quality ideas, and so the more attractive are taxes relative to subsidies.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>nberwp is now on CRAN</title>
      <link>https://bldavies.com/blog/nberwp-cran/</link>
      <pubDate>Wed, 21 Jul 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/nberwp-cran/</guid>
      <description>&lt;p&gt;nberwp, an R package providing information on &lt;a href=&#34;https://www.nber.org/papers&#34;&gt;NBER working papers&lt;/a&gt; and their authors, is now &lt;a href=&#34;https://cran.r-project.org/package=nberwp&#34;&gt;available on CRAN&lt;/a&gt;.
The current version (1.0.0) covers 29,434 papers published between June 1973 and June 2021.
It can be installed via&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;nberwp&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;nberwp has evolved since &lt;a href=&#34;https://bldavies.com/blog/introducing-nberwp/&#34;&gt;its initial release&lt;/a&gt; on GitHub nearly two years ago.
This post describes some of the main changes.&lt;/p&gt;
&lt;h2 id=&#34;more-papers&#34;&gt;More papers&lt;/h2&gt;
&lt;p&gt;The first version of nberwp covered papers published between June 1973 and December 2018.
The updated version adds papers published between January 2019 and June 2021, allowing one to visualize the spike in publications when COVID-19 emerged:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ggplot2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;nberwp&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;papers&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Quarter&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;ceiling&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;month&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;New papers&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Quarter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;`New papers`&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_line&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;labs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;title&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;COVID-19 induced a spike in NBER publications&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
       &lt;span class=&#34;n&#34;&gt;subtitle&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;New NBER working papers, by quarter&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/covid-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;nberwp now also includes papers published in the historical and technical working paper series.
The historical series contains 136 papers focused on (American) economic history, and the technical series contains 337 papers focused on analytical and empirical methods.&lt;/p&gt;
&lt;p&gt;The working paper data exclude duplicates (e.g., papers published in multiple series) but include revisions, which capture continued development of (and collaboration on) research ideas that I believe should be acknowledged.&lt;/p&gt;
&lt;h2 id=&#34;program-affiliations&#34;&gt;Program affiliations&lt;/h2&gt;
&lt;p&gt;The NBER organizes its research into &lt;a href=&#34;https://www.nber.org/programs-projects/programs-working-groups&#34;&gt;programs&lt;/a&gt;, each of which &amp;ldquo;corresponds loosely to a traditional field of study within economics.&amp;rdquo;
nberwp now provides a table of paper-program correspondences&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;paper_programs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 53,996 x 2
##    paper program
##    &amp;lt;chr&amp;gt; &amp;lt;chr&amp;gt;  
##  1 w0074 EFG    
##  2 w0087 IFM    
##  3 w0087 ITI    
##  4 w0107 PE     
##  5 w0116 PE     
##  6 w0117 LS     
##  7 w0129 HE     
##  8 w0131 IFM    
##  9 w0131 ITI    
## 10 w0134 HE     
## # … with 53,986 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;as well as a table of program descriptions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;programs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 21 x 3
##    program program_desc                        program_category   
##    &amp;lt;chr&amp;gt;   &amp;lt;chr&amp;gt;                               &amp;lt;chr&amp;gt;              
##  1 AG      Economics of Aging                  Micro              
##  2 AP      Asset Pricing                       Finance            
##  3 CF      Corporate Finance                   Finance            
##  4 CH      Children                            Micro              
##  5 DAE     Development of the American Economy Micro              
##  6 DEV     Development Economics               Micro              
##  7 ED      Economics of Education              Micro              
##  8 EEE     Environment and Energy Economics    Micro              
##  9 EFG     Economic Fluctuations and Growth    Macro/International
## 10 HC      Health Care                         Micro              
## # … with 11 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;program_category&lt;/code&gt; column categorizes programs similarly to &lt;a href=&#34;https://www.nber.org/papers/w23953&#34;&gt;Chari and Goldsmith-Pinkham (2017)&lt;/a&gt;.
On average, each paper is affiliated with 1.83 programs and each program has 2,571 affiliated papers.&lt;/p&gt;
&lt;p&gt;One use of the paper-program correspondences is to analyze the intellectual overlaps among programs.
For example, the table below presents the six pairs of programs with the most-overlapping sets of affiliated papers, with overlap sizes measured by &lt;a href=&#34;https://en.wikipedia.org/wiki/Jaccard_index&#34;&gt;Jaccard indices&lt;/a&gt;.
The top index of 0.29 means that about 29% of the papers affiliated with the Children or Economics of Education programs are affiliated with both.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Program 1&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;Program 2&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Jaccard index&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Children&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Economics of Education&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Health Care&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Health Economics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;International Finance and Macroeconomics&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;International Trade and Investment&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.26&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economic Fluctuations and Growth&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Monetary Economics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Asset Pricing&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Corporate Finance&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Labor Studies&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Public Economics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;authorships&#34;&gt;Authorships&lt;/h2&gt;
&lt;p&gt;nberwp now contains information about working papers&amp;rsquo; (co-)authors:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;authors&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 15,437 x 4
##    author  name             user_nber        user_repec
##    &amp;lt;chr&amp;gt;   &amp;lt;chr&amp;gt;            &amp;lt;chr&amp;gt;            &amp;lt;chr&amp;gt;     
##  1 w0001.1 Finis Welch      finis_welch      &amp;lt;NA&amp;gt;      
##  2 w0002.1 Barry R Chiswick barry_chiswick   pch425    
##  3 w0003.1 Swarnjit S Arora swarnjit_arora   &amp;lt;NA&amp;gt;      
##  4 w0004.1 Lee A Lillard    &amp;lt;NA&amp;gt;             pli669    
##  5 w0005.1 James P Smith    james_smith      psm28     
##  6 w0006.1 Victor Zarnowitz victor_zarnowitz &amp;lt;NA&amp;gt;      
##  7 w0007.1 Lewis C Solmon   &amp;lt;NA&amp;gt;             &amp;lt;NA&amp;gt;      
##  8 w0008.1 Merle Yahr Weiss &amp;lt;NA&amp;gt;             &amp;lt;NA&amp;gt;      
##  9 w0008.2 Robert E Lipsey  robert_lipsey    pli259    
## 10 w0010.1 Paul W Holland   &amp;lt;NA&amp;gt;             &amp;lt;NA&amp;gt;      
## # … with 15,427 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;author&lt;/code&gt; column contains unique author identifiers, constructed by concatenating each author&amp;rsquo;s debut paper and their position on that paper&amp;rsquo;s (alphabetized) byline.
This construction ensures that &lt;code&gt;author&lt;/code&gt; values do not change when I add newly published papers to the data.
The &lt;code&gt;user_nber&lt;/code&gt; column contains authors&amp;rsquo; usernames on the NBER website; the &lt;code&gt;user_repec&lt;/code&gt; column contains authors&amp;rsquo; &lt;a href=&#34;https://ideas.repec.org&#34;&gt;RePEc&lt;/a&gt; IDs.
Some authors do not have an NBER username or RePEc ID, indicated by &lt;code&gt;NA&lt;/code&gt; values in the appropriate column.&lt;/p&gt;
&lt;p&gt;nberwp also provides a table of paper-author correspondences:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;paper_authors&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 67,090 x 2
##    paper author 
##    &amp;lt;chr&amp;gt; &amp;lt;chr&amp;gt;  
##  1 w0001 w0001.1
##  2 w0002 w0002.1
##  3 w0003 w0003.1
##  4 w0004 w0004.1
##  5 w0005 w0005.1
##  6 w0006 w0006.1
##  7 w0007 w0007.1
##  8 w0008 w0008.1
##  9 w0008 w0008.2
## 10 w0009 w0004.1
## # … with 67,080 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This table can be used to construct a co-authorship network among the 15,437 authors identified in nberwp.
This network currently contains 38,968 edges, implying that 0.03% of pairs co-authored at least one working paper during the period covered by the data.
Authors in the network have a mean degree of 5.05.&lt;/p&gt;
&lt;p&gt;I used previous versions of nberwp in blog posts on &lt;a href=&#34;https://bldavies.com/blog/triadic-closure-nber/&#34;&gt;triadic closure&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/female-representation-collaboration-nber/&#34;&gt;female representation&lt;/a&gt;.
These posts assumed that authors were uniquely identified by their full names.
This assumption was problematic: different authors could share the same name, or a single author could publish under many names (e.g., before and after marriage).
The updated version of nberwp builds on &lt;a href=&#34;https://bldavies.com/blog/nber-co-authorships/&#34;&gt;previous efforts to disambiguate authors&amp;rsquo; names&lt;/a&gt;&amp;mdash;namely cross-referencing against NBER usernames, RePEc IDs, common co-authorships, and name edit distances&amp;mdash;in three ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;using paper-program correspondences to identify authors who have similar names and published papers in similar programs, and so are likely to be the same person;&lt;/li&gt;
&lt;li&gt;manually merging (or splitting) authors whom I determine to be the same (or distinct) based on their personal or academic websites;&lt;/li&gt;
&lt;li&gt;including an author ID variable (&lt;code&gt;author&lt;/code&gt;) rather than relying on names for unique identification.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These enhancements support cleaner analyses of (co-)authorship behavior.
Nonetheless the data may still contain errors&amp;mdash;if you find any, let me know by adding an issue on &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Coefficients of correlated regressors</title>
      <link>https://bldavies.com/blog/coefficients-correlated-regressors/</link>
      <pubDate>Wed, 07 Jul 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/coefficients-correlated-regressors/</guid>
      <description>&lt;p&gt;Linear models cannot be estimated &lt;a href=&#34;https://en.wikipedia.org/wiki/Multicollinearity&#34;&gt;when regressors are perfectly correlated&lt;/a&gt;, and their coefficients have large variances when regressors are almost-perfectly correlated.
But how does coefficients&amp;rsquo; correlation depend on regressors&amp;rsquo; correlation?&lt;/p&gt;
&lt;p&gt;To answer this question, suppose I have data &lt;code&gt;\((y_i,x_i,z_i)_{i=1}^n\)&lt;/code&gt; generated by the process
&lt;code&gt;$$\newcommand{\abs}[1]{\lvert#1\rvert} \DeclareMathOperator{\Cor}{Cor} \DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\Var}{Var} \renewcommand{\epsilon}{\varepsilon} y_i=\beta_1x_i+\beta_2z_i+\epsilon_i,$$&lt;/code&gt;
where the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; are normalized to have zero mean and unit variance, and where the &lt;code&gt;\(\epsilon_i\)&lt;/code&gt; are iid with zero mean and zero correlation with the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt;.
If the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; are not perfectly correlated then the OLS estimator &lt;code&gt;\(\hat\beta\)&lt;/code&gt; of the coefficient vector &lt;code&gt;\((\beta_1,\beta_2)\)&lt;/code&gt; has variance
&lt;code&gt;$$\DeclareMathOperator{\Var}{Var} \Var(\hat\beta)=\frac{\sigma^2}{n(1-\rho^2)}\begin{bmatrix}1&amp;amp;-\rho\\-\rho&amp;amp;1\end{bmatrix},$$&lt;/code&gt;
where &lt;code&gt;\(\sigma^2\)&lt;/code&gt; is the variance of the &lt;code&gt;\(\epsilon_i\)&lt;/code&gt;, and where &lt;code&gt;\(\rho\)&lt;/code&gt; is the (empirical) correlation of the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt;.
It follows that
&lt;code&gt;$$\Cor(\hat\beta_1,\hat\beta_2)=-\Cor(x_i,z_i)$$&lt;/code&gt;
whenever the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; are not perfectly correlated.
As their correlation grows, the mean slope of the data in the directions spanned by the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; approaches &lt;code&gt;\((\beta_1+\beta_2)\)&lt;/code&gt;, and so the OLS estimates &lt;code&gt;\(\hat\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\hat\beta_2\)&lt;/code&gt; increasingly &amp;ldquo;compete&amp;rdquo; for contributions to their sum: if sampling error leads to one coefficient being over-estimated then the other coefficient must be under-estimated to preserve the sum.
This competition drives the decreasing correlation of &lt;code&gt;\(\hat\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\hat\beta_2\)&lt;/code&gt; as the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; become more correlated.&lt;/p&gt;
&lt;p&gt;The correlation of the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; also determines the precision with which &lt;code&gt;\((\beta_1\pm\beta_2)\)&lt;/code&gt; can be estimated.
In particular, the expression for &lt;code&gt;\(\Var(\hat\beta)\)&lt;/code&gt; above implies
&lt;code&gt;$$\Var(\hat\beta_1\pm\hat\beta_2)=\frac{2\sigma^2}{n(1\pm\rho)}$$&lt;/code&gt;
for &lt;code&gt;\(\abs{\rho}&amp;lt;1\)&lt;/code&gt;.
As the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; become more correlated (i.e., &lt;code&gt;\(\rho\)&lt;/code&gt; rises), over-estimates of &lt;code&gt;\(\beta_1\)&lt;/code&gt; must increasingly coincide with under-estimates of &lt;code&gt;\(\beta_2\)&lt;/code&gt;, and so the estimate of &lt;code&gt;\((\beta_1+\beta_2)\)&lt;/code&gt; becomes more precise because the errors cancel out.
Conversely, the estimate of &lt;code&gt;\((\beta_1-\beta_2)\)&lt;/code&gt; becomes &lt;em&gt;less&lt;/em&gt; precise as &lt;code&gt;\(\rho\)&lt;/code&gt; rises because the errors in &lt;code&gt;\(\hat\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\hat\beta_2\)&lt;/code&gt; amplify each other.&lt;/p&gt;
&lt;p&gt;One application of this relationship between &lt;code&gt;\(\Var(\hat\beta_1\pm\hat\beta_2)\)&lt;/code&gt; and &lt;code&gt;\(\rho\)&lt;/code&gt; is to experimental design.
Suppose I want to estimate the effect of receiving two treatments&amp;mdash;say, doses of a single vaccine&amp;mdash;on some outcome of interest.
The &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(z_i\)&lt;/code&gt; indicate whether individual &lt;code&gt;\(i\)&lt;/code&gt; receives each dose, the coefficients &lt;code&gt;\(\beta_1\)&lt;/code&gt; and &lt;code&gt;\(\beta_2\)&lt;/code&gt; are the average treatment effects (ATEs) of receiving each dose, and the sum &lt;code&gt;\((\beta_1+\beta_2)\)&lt;/code&gt; is the ATE of receiving both doses.
The most precise estimate of &lt;code&gt;\((\beta_1+\beta_2)\)&lt;/code&gt; obtains when the treatments are perfectly positively correlated: that is, when people receive either zero or two doses, but no-one receives only one.
Intuitively, I learn more about the effect of receiving two doses from people who receive both than from people who receive only one, so the most informative experiment cannot have anyone who receives a single dose.&lt;/p&gt;
&lt;p&gt;On the other hand, suppose I want to compare the effect of two distinct treatments&amp;mdash;say, doses of different vaccines&amp;mdash;on my outcome of interest.
Then I want to estimate &lt;code&gt;\((\beta_1-\beta_2)\)&lt;/code&gt;, which I can do most precisely when the treatments are perfectly &lt;em&gt;negatively&lt;/em&gt; correlated: that is, when people receive one type of vaccine or the other, but no-one receives both.
Intuitively, I learn more about the vaccines&amp;rsquo; relative effects from people who receive one type than from people who receive both types because the two vaccines may have confounding effects.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://lautarochittaro.github.io&#34;&gt;Lautaro Chittaro&lt;/a&gt; for inspiring this post and commenting on a draft.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Rationalizing negative splits</title>
      <link>https://bldavies.com/blog/rationalizing-negative-splits/</link>
      <pubDate>Tue, 18 May 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/rationalizing-negative-splits/</guid>
      <description>&lt;p&gt;Many competitive runners aim for &lt;a href=&#34;https://en.wikipedia.org/wiki/Negative_split&#34;&gt;negative splits&lt;/a&gt;: running the second half of a race faster than the first.
A more general goal is to speed up as the race progresses.
This post analyzes the conditions under which that goal makes sense.
I derive these conditions mathematically, demonstrate them with &lt;a href=&#34;#a-simple-example&#34;&gt;an example&lt;/a&gt;, and discuss some possible &lt;a href=&#34;#extensions&#34;&gt;extensions&lt;/a&gt; to my analysis.&lt;/p&gt;
&lt;h2 id=&#34;when-is-speeding-up-optimal&#34;&gt;When is speeding up optimal?&lt;/h2&gt;
&lt;p&gt;Suppose I want to run a unit distance as fast as possible.
I choose a speed function &lt;code&gt;\(s:[0,1]\to(0,\infty)\)&lt;/code&gt; that minimizes my total running time
&lt;code&gt;$$\newcommand{\der}{\mathrm{d}} \newcommand{\derfrac}[2]{\frac{\der #1}{\der #2}} \newcommand{\parfrac}[2]{\frac{\partial #1}{\partial #2}} T[s]:=\int_0^1\frac{1}{s(x)}\,\der x,$$&lt;/code&gt;
where &lt;code&gt;\(x\)&lt;/code&gt; indexes distance.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
However, running uses energy, of which I have a limited supply &lt;code&gt;\(e(0)=1\)&lt;/code&gt; at the start of my run and which evolves according to
&lt;code&gt;$$\parfrac{e(x)}{x}=-r(x,s(x),e(x)),$$&lt;/code&gt;
where &lt;code&gt;\(r\)&lt;/code&gt; determines the rate of energy consumption based on the instantaneous values of &lt;code&gt;\(x\)&lt;/code&gt;, &lt;code&gt;\(s(x)\)&lt;/code&gt;, and &lt;code&gt;\(e(x)\)&lt;/code&gt;.
I assume that running faster uses more energy (i.e., &lt;code&gt;\(r\)&lt;/code&gt; is increasing in &lt;code&gt;\(s(x)\)&lt;/code&gt;) and that I use all of my energy (i.e, &lt;code&gt;\(e(1)=0\)&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;My interest is in how the shape of &lt;code&gt;\(s\)&lt;/code&gt; depends on the shape of &lt;code&gt;\(r\)&lt;/code&gt;.
In particular, I want to know what conditions I have to put on &lt;code&gt;\(r\)&lt;/code&gt; to make &lt;code&gt;\(s\)&lt;/code&gt; an increasing function of &lt;code&gt;\(x\)&lt;/code&gt;.
I determine these conditions as follows.
First, I define the &lt;a href=&#34;https://en.wikipedia.org/wiki/Hamiltonian_%28control_theory%29&#34;&gt;Hamiltonian&lt;/a&gt;
&lt;code&gt;$$H(x,s(x),e(x),\lambda(x))\equiv-\frac{1}{s(x)}-\lambda(x)r(x,s(x),e(x)),$$&lt;/code&gt;
where &lt;code&gt;\(\lambda\)&lt;/code&gt; is a co-state function.
Under some regularity conditions, I can choose the optimizing functions point-wise, so for convenience I let &lt;code&gt;\(x\in[0,1]\)&lt;/code&gt; be arbitrary and suppress functions&amp;rsquo; arguments.
Then &lt;code&gt;\(s\)&lt;/code&gt; and &lt;code&gt;\(\lambda\)&lt;/code&gt; satisfy the first-order conditions (FOCs)
&lt;code&gt;$$\begin{aligned} 0&amp;amp;=H_s=\frac{1}{s^2}-\lambda r_s \\ -\lambda_x&amp;amp;=H_e=-\lambda r_e, \end{aligned}$$&lt;/code&gt;
where subscripts denote (partial) differentiation.
Differentiating the first FOC with respect to &lt;code&gt;\(x\)&lt;/code&gt; gives
&lt;code&gt;$$\frac{2s_x}{s^3}=-\lambda_xr_s-\lambda r_{sx},$$&lt;/code&gt;
which, after substituting back in the two FOCs and dividing by &lt;code&gt;\(2\lambda r_s\)&lt;/code&gt;, becomes
&lt;code&gt;$$\frac{s_x}{s}=-\frac{1}{2}\left(r_e+\frac{r_{sx}}{r_s}\right).$$&lt;/code&gt;
Thus, if &lt;code&gt;\(s_x&amp;gt;0\)&lt;/code&gt; then at least one of two conditions on &lt;code&gt;\(r\)&lt;/code&gt; must hold:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;\(r_e&amp;lt;0\)&lt;/code&gt;, which means that I use energy faster when I have less of it;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\(r_{sx}/r_s&amp;lt;0\)&lt;/code&gt;, which, coupled with the assumption that &lt;code&gt;\(r_s&amp;gt;0\)&lt;/code&gt;, means that the energy cost of running fast falls as I cover more distance.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The intuition for the first condition is as follows:
energy falls with distance, and if it starts falling faster then I have to start running faster to avoid running out of energy before the finish line.
The second condition amplifies this motive to speed up by lowering the cost of running fast as the finish line approaches.
I don&amp;rsquo;t know enough about physiology to know which condition is more plausible, but from experience I&amp;rsquo;m sympathetic to the second: I&amp;rsquo;m much less likely to &lt;a href=&#34;https://en.wikipedia.org/wiki/Hitting_the_wall&#34;&gt;bonk&lt;/a&gt; while running if I warm up slowly than if I sprint out of the gate.&lt;/p&gt;
&lt;h2 id=&#34;a-simple-example&#34;&gt;A simple example&lt;/h2&gt;
&lt;p&gt;Suppose I consume energy at the rate
&lt;code&gt;$$r(x,s(x),e(x))=(1-ax)s(x)$$&lt;/code&gt;
for some parameter &lt;code&gt;\(a\in(0,1)\)&lt;/code&gt;, which determines how the energy cost of running fast changes during my run.
That cost is approximately constant when &lt;code&gt;\(a\approx0\)&lt;/code&gt; and becomes more decreasing in &lt;code&gt;\(x\)&lt;/code&gt; as &lt;code&gt;\(a\)&lt;/code&gt; approaches unity.
Given this definition of &lt;code&gt;\(r\)&lt;/code&gt;, and given the boundary conditions &lt;code&gt;\(e(0)=1\)&lt;/code&gt; and &lt;code&gt;\(e(1)=0\)&lt;/code&gt;, the time-minimizing speed and energy profiles are
&lt;code&gt;$$s(x)=\frac{2\left(1-(1-a)^{3/2}\right)}{3a\sqrt{1-ax}}$$&lt;/code&gt;
and
&lt;code&gt;$$e(x)=1-\frac{1-(1-ax)^{3/2}}{1-(1-a)^{3/2}}.$$&lt;/code&gt;
Then &lt;code&gt;\(s\)&lt;/code&gt; is an increasing function of &lt;code&gt;\(x\)&lt;/code&gt; and becomes more convex as &lt;code&gt;\(a\)&lt;/code&gt; rises.
It turns out that &lt;code&gt;\(T[s]=1\)&lt;/code&gt; for all &lt;code&gt;\(a\in(0,1)\)&lt;/code&gt;, so varying &lt;code&gt;\(a\)&lt;/code&gt; preserves the mean speed &lt;code&gt;\(1/T[s]=1\)&lt;/code&gt; but varies the curvature of &lt;code&gt;\(s\)&lt;/code&gt; around that mean.
More generally, the time
&lt;code&gt;$$t(x)\equiv\int_0^x\frac{1}{s(y)}\,\der y$$&lt;/code&gt;
taken to run distance &lt;code&gt;\(x\in[0,1]\)&lt;/code&gt; satisfies &lt;code&gt;\(t(x)=1-e(x)\)&lt;/code&gt;; that is, the proportion of time elapsed always equals the proportion of energy consumed.&lt;/p&gt;
&lt;p&gt;The chart below plots &lt;code&gt;\(s(x)\)&lt;/code&gt; and &lt;code&gt;\(t(x)\)&lt;/code&gt; when &lt;code&gt;\(r=(1-ax)s(x)\)&lt;/code&gt;.
When &lt;code&gt;\(a\approx0\)&lt;/code&gt;, the energy cost of running fast is approximately constant with respect to distance and so the optimal speed profile is approximately flat.
As &lt;code&gt;\(a\)&lt;/code&gt; increases, the cost of running fast increasingly falls with distance and so the optimal speed increasingly rises with distance.
Consequently, the percentage of time and energy spent on the first half of the run increases with &lt;code&gt;\(a\)&lt;/code&gt;, starting at 50% when &lt;code&gt;\(a\approx0\)&lt;/code&gt; and rising to 65% as &lt;code&gt;\(a\)&lt;/code&gt; approaches unity.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;extensions&#34;&gt;Extensions&lt;/h2&gt;
&lt;p&gt;One way to extend my analysis could be to &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-random-energy-costs/&#34;&gt;make the energy consumption rate stochastic&lt;/a&gt;.
For example, if I run on unfamiliar terrain then I face uncertainty about upcoming obstacles (e.g., steep hills) and the energy cost of overcoming those obstacles.
This uncertainty would encourage me to start my run slowly as a form of &lt;a href=&#34;https://en.wikipedia.org/wiki/Precautionary_savings&#34;&gt;precautionary saving&lt;/a&gt;, resulting in negative splits.&lt;/p&gt;
&lt;p&gt;Another extension could be to model the different energy systems used when running at different speeds.
For example, short sprints use the anaerobic system, which burns carbohydrates for fuel, while long slow runs use the aerobic system, which also burns fat for fuel.
Adding more energy systems would allow for richer, more realistic dynamics, but would require more domain knowledge than I possess to set up the inter-dependencies correctly.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to Logan Donald and Florian Fiaux for commenting on a draft version of this post.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I formalize my pacing problem as a &amp;ldquo;continuous-time&amp;rdquo; &lt;a href=&#34;https://en.wikipedia.org/wiki/Optimal_control&#34;&gt;optimal control problem&lt;/a&gt;.
I consider a discrete-time version of this problem &lt;a href=&#34;https://bldavies.com/blog/optimal-pacing-varying-energy-costs/&#34;&gt;here&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Stable matchings with noisy preferences</title>
      <link>https://bldavies.com/blog/stable-matchings-noisy-preferences/</link>
      <pubDate>Sun, 02 May 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/stable-matchings-noisy-preferences/</guid>
      <description>&lt;p&gt;My &lt;a href=&#34;https://bldavies.com/blog/stable-matchings/&#34;&gt;previous post&lt;/a&gt; described &lt;a href=&#34;https://doi.org/10.2307/2312726&#34;&gt;Gale and Shapley&amp;rsquo;s (1962)&lt;/a&gt; algorithm for solving &lt;a href=&#34;https://en.wikipedia.org/wiki/Stable_marriage_problem&#34;&gt;the stable matching problem&lt;/a&gt;.
The algorithm delivers a matching between two sets &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; of &lt;code&gt;\(n\)&lt;/code&gt; people with preferences over matches in the other set.&lt;/p&gt;
&lt;p&gt;The Gale-Shapley (GS) algorithm works by letting people in &lt;code&gt;\(A\)&lt;/code&gt; make proposals to people in &lt;code&gt;\(B\)&lt;/code&gt;, who &amp;ldquo;tentatively accept&amp;rdquo; or reject proposals until the matching market clears.
Consequently, if one side of the market is more informed about match qualities than the other side then the algorithm could generate different levels of welfare depending on which side makes proposals.&lt;/p&gt;
&lt;p&gt;For example, suppose &lt;code&gt;\(a\in A\)&lt;/code&gt; and &lt;code&gt;\(b\in B\)&lt;/code&gt; generate surplus &lt;code&gt;\(S_{ab}\)&lt;/code&gt; from being matched.
This surplus has a monetary value (representing, e.g., the price &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(b\)&lt;/code&gt; would pay to be matched) so can be aggregated across pairs meaningfully.
Both &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(b\)&lt;/code&gt; want the match that gives them the greatest surplus.
However, they perceive match surpluses noisily: person &lt;code&gt;\(a\)&lt;/code&gt; thinks their surplus from matching with &lt;code&gt;\(b\)&lt;/code&gt; is
&lt;code&gt;$$S_{ab}^A=S_{ab}+\epsilon_{ab}^A,$$&lt;/code&gt;
while &lt;code&gt;\(b\)&lt;/code&gt; thinks their surplus from matching with &lt;code&gt;\(a\)&lt;/code&gt; is
&lt;code&gt;$$S_{ab}^B=S_{ab}+\epsilon_{ab}^B.$$&lt;/code&gt;
The &lt;code&gt;\(S_{ab}\)&lt;/code&gt; are iid standard normal, the &lt;code&gt;\(\epsilon_{ab}^A\)&lt;/code&gt; are iid normal with mean zero and variance &lt;code&gt;\(\sigma_A^2\)&lt;/code&gt;, and the &lt;code&gt;\(\epsilon_{ab}^B\)&lt;/code&gt; are iid normal with mean zero and variance &lt;code&gt;\(\sigma_B^2\)&lt;/code&gt;.
Increasing &lt;code&gt;\(\sigma_A\)&lt;/code&gt; and &lt;code&gt;\(\sigma_B\)&lt;/code&gt; increases the errors in perceived surpluses.
These errors disappear when the matching is made and the &amp;ldquo;true&amp;rdquo; surpluses &lt;code&gt;\(S_{ab}\)&lt;/code&gt; (representing peoples&amp;rsquo; true preferences) are realized.&lt;/p&gt;
&lt;p&gt;I compare the distribution of mean match surpluses delivered by four matching procedures:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;MBM&lt;/em&gt;: the &lt;a href=&#34;https://en.wikipedia.org/wiki/Maximum_weight_matching&#34;&gt;maximum-weight bipartite matching&lt;/a&gt; based on the true match surpluses &lt;code&gt;\(S_{ab}\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;GS-A&lt;/em&gt;: the GS algorithm with people in &lt;code&gt;\(A\)&lt;/code&gt; proposing based on their perceived match surpluses &lt;code&gt;\(S_{ab}^A\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;GS-B&lt;/em&gt;: the GS algorithm with people in &lt;code&gt;\(B\)&lt;/code&gt; proposing based on their perceived match surpluses &lt;code&gt;\(S_{ab}^B\)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Feasible MBM&lt;/em&gt;: the maximum-weight bipartite matching based on the precision-weighted mean perceived match surpluses
&lt;code&gt;$$\hat{S}_{ab}=\begin{cases} S_{ab} &amp;amp; \text{if}\ \sigma_A=0\ \text{or}\ \sigma_B=0 \\ \lambda S_{ab}^A+(1-\lambda)S_{ab}^B &amp;amp; \text{otherwise}, \end{cases}$$&lt;/code&gt;
where
&lt;code&gt;$$\lambda=\frac{1/\sigma_A^2}{1/\sigma_A^2+1/\sigma_B^2}$$&lt;/code&gt;
is the relative precision of &lt;code&gt;\(A\)&lt;/code&gt; members&amp;rsquo; perceptions when &lt;code&gt;\(\min\{\sigma_A,\sigma_B\}&amp;gt;0\)&lt;/code&gt;.
&lt;em&gt;Feasible MBM&lt;/em&gt; replicates &lt;em&gt;MBM&lt;/em&gt; when &lt;code&gt;\(\min\{\sigma_A,\sigma_B\}=0\)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The &lt;em&gt;MBM&lt;/em&gt; procedure maximizes the sum of true match surpluses, while the &lt;em&gt;Feasible MBM&lt;/em&gt; procedure maximizes the sum of the best match surplus estimates that people in &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; could obtain by communicating.
The &lt;em&gt;GS-A&lt;/em&gt; and &lt;em&gt;GS-B&lt;/em&gt; procedures do not allow such communication, but guarantee that the ultimate matching is stable.
I run all four procedures 1,000 times for &lt;code&gt;\(\sigma_A\in\{0,1,5\}\)&lt;/code&gt; and &lt;code&gt;\(\sigma_B\in\{0,1,5\}\)&lt;/code&gt;, and summarize my results in the figure below.
All four procedures deliver mean match surpluses greater than zero, implying that people tend to do better by following the procedures than by forming matches randomly.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/summary-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The mean match surpluses delivered by the &lt;em&gt;GS-A&lt;/em&gt;, &lt;em&gt;GS-B&lt;/em&gt;, and &lt;em&gt;Feasible MBM&lt;/em&gt; procedures fall as &lt;code&gt;\(\sigma_A\)&lt;/code&gt; and &lt;code&gt;\(\sigma_B\)&lt;/code&gt; rise.
Intuitively, these three procedures rely on preferences reported by the people in &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt;, and if those preferences become noisier then the procedures become worse at finding good matches.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Feasible MBM&lt;/em&gt; tends to outperform &lt;em&gt;GS-A&lt;/em&gt; and &lt;em&gt;GS-B&lt;/em&gt; when &lt;code&gt;\(\sigma_A\)&lt;/code&gt; or &lt;code&gt;\(\sigma_B\)&lt;/code&gt; are small.
However, the performance gain is neglible when &lt;code&gt;\(\sigma_A\)&lt;/code&gt; and &lt;code&gt;\(\sigma_B\)&lt;/code&gt; are large.
Intuitively, if perceived match surpluses are mostly noise then sharing that noise doesn&amp;rsquo;t help with finding better matches.&lt;/p&gt;
&lt;p&gt;The GS algorithm tends to find better matches when the people making proposals are the ones with less noisy preferences.
Both sides of the matching market provide information that determines the ultimate matching: the proposing side provides information &lt;em&gt;actively&lt;/em&gt; through proposals, whereas the non-proposing side provides information &lt;em&gt;passively&lt;/em&gt; through proposal acceptances and rejections.
Letting the more-informed side make proposals allows more information to feed into the matching process, leading to better matches on average.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://www.spantoja.com&#34;&gt;Spencer Pantoja&lt;/a&gt; for inspiring this post and to &lt;a href=&#34;https://web.stanford.edu/~alroth/&#34;&gt;Al Roth&lt;/a&gt; for his comments.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Stable matchings</title>
      <link>https://bldavies.com/blog/stable-matchings/</link>
      <pubDate>Mon, 19 Apr 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/stable-matchings/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; be sets of &lt;code&gt;\(n\)&lt;/code&gt; people.
A &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Matching_%28graph_theory%29&#34;&gt;matching&lt;/a&gt;&amp;rdquo; is a collection of pairs &lt;code&gt;\((a,b)\)&lt;/code&gt; with &lt;code&gt;\(a\in A\)&lt;/code&gt; and &lt;code&gt;\(b\in B\)&lt;/code&gt; such that everyone in &lt;code&gt;\(A\cup B\)&lt;/code&gt; belongs to exactly one pair.
For example, if &lt;code&gt;\(A\)&lt;/code&gt; and &lt;code&gt;\(B\)&lt;/code&gt; are sets of men and women then a matching could define a collection of monogamous, heterosexual marriages.&lt;/p&gt;
&lt;p&gt;Suppose the people in each set have (complete, strict) preferences over potential matches in the other set.
A matching is &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Stable_marriage_problem&#34;&gt;stable&lt;/a&gt;&amp;rdquo; if there are no unmatched pairs who prefer each other to their match.
&lt;a href=&#34;https://doi.org/10.2307/2312726&#34;&gt;Gale and Shapley (1962)&lt;/a&gt; show that a stable matching always exists and describe an &lt;a href=&#34;https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm&#34;&gt;algorithm&lt;/a&gt; for finding it:
Let each person &lt;code&gt;\(a\in A\)&lt;/code&gt; without a match &amp;ldquo;propose&amp;rdquo; to their most preferred person in &lt;code&gt;\(b\in B\)&lt;/code&gt; to whom they haven&amp;rsquo;t already proposed.
If &lt;code&gt;\(b\)&lt;/code&gt; is unmatched then they tentatively accept the proposal;
if &lt;code&gt;\(b\)&lt;/code&gt; is matched to &lt;code&gt;\(a&#39;\)&lt;/code&gt; but prefers &lt;code&gt;\(a\)&lt;/code&gt; then they tentatively accept the proposal and reject &lt;code&gt;\(a&#39;\)&lt;/code&gt;;
otherwise, &lt;code&gt;\(b\)&lt;/code&gt; rejects the proposal.
Repeat this process until everyone is matched.&lt;/p&gt;
&lt;h2 id=&#34;optimality-and-strategy-proofness&#34;&gt;Optimality and strategy-proofness&lt;/h2&gt;
&lt;p&gt;The Gale-Shapley (GS) algorithm always delivers a stable matching that is best for everyone in &lt;code&gt;\(A\)&lt;/code&gt; among all stable matchings.
To see why, suppose &lt;code&gt;\(a\in A\)&lt;/code&gt; is matched to &lt;code&gt;\(b\in B\)&lt;/code&gt; but prefers &lt;code&gt;\(b&#39;\in B\setminus\{b\}\)&lt;/code&gt;.
Then &lt;code&gt;\(b&#39;\)&lt;/code&gt; must have received a proposal from some &lt;code&gt;\(a&#39;\in A\setminus\{a\}\)&lt;/code&gt; whom they prefer to &lt;code&gt;\(a\)&lt;/code&gt;.
Consequently, &lt;code&gt;\(a\)&lt;/code&gt; cannot form a &amp;ldquo;blocking pair&amp;rdquo; with &lt;code&gt;\(b&#39;\)&lt;/code&gt; (and thereby break the stable matching) because &lt;code&gt;\(b&#39;\)&lt;/code&gt; would rather be matched to &lt;code&gt;\(a&#39;\)&lt;/code&gt;.
Thus &lt;code&gt;\(b\)&lt;/code&gt; is the best match &lt;code&gt;\(a\)&lt;/code&gt; can get if the matching is stable.&lt;/p&gt;
&lt;p&gt;On the other hand, the GS algorithm always delivers a stable matching that is &lt;em&gt;worst&lt;/em&gt; for everyone in &lt;code&gt;\(B\)&lt;/code&gt; among all stable matchings.
To see why, suppose &lt;code&gt;\(b\in B\)&lt;/code&gt; is matched to &lt;code&gt;\(a\in A\)&lt;/code&gt; in some matching &lt;code&gt;\(\mathcal{M}\)&lt;/code&gt; obtained using the GS algorithm.
Suppose further that &lt;code&gt;\(b\)&lt;/code&gt; prefers &lt;code&gt;\(a\)&lt;/code&gt; to some &lt;code&gt;\(a&#39;\in A\setminus\{a\}\)&lt;/code&gt; and assume towards a contradiction that there is a stable matching &lt;code&gt;\(\mathcal{M}&#39;\)&lt;/code&gt; in which &lt;code&gt;\(b\)&lt;/code&gt; is matched to &lt;code&gt;\(a&#39;\)&lt;/code&gt;.
Then &lt;code&gt;\(a\)&lt;/code&gt; is matched to some &lt;code&gt;\(b&#39;\in B\setminus\{b\}\)&lt;/code&gt; in &lt;code&gt;\(\mathcal{M}&#39;\)&lt;/code&gt;.
Now &lt;code&gt;\(\mathcal{M}\)&lt;/code&gt; was obtained using the GS algorithm, so it gives &lt;code&gt;\(a\)&lt;/code&gt; their top preference among all stable matchings.
Consequently, &lt;code&gt;\(a\)&lt;/code&gt; must prefer &lt;code&gt;\(b\)&lt;/code&gt; to &lt;code&gt;\(b&#39;\)&lt;/code&gt;.
But then &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(b\)&lt;/code&gt; form a blocking pair in &lt;code&gt;\(\mathcal{M}&#39;\)&lt;/code&gt;, contradicting its stability.
Thus &lt;code&gt;\(a&#39;\)&lt;/code&gt; cannot exist; that is, &lt;code&gt;\(a\)&lt;/code&gt; is the worst match &lt;code&gt;\(b\)&lt;/code&gt; can get among all stable matchings.&lt;/p&gt;
&lt;p&gt;The GS algorithm is &lt;a href=&#34;https://en.wikipedia.org/wiki/Strategyproofness&#34;&gt;strategy-proof&lt;/a&gt; for everyone in &lt;code&gt;\(A\)&lt;/code&gt;: no-one in &lt;code&gt;\(A\)&lt;/code&gt; can do better by misreporting their preferences (&lt;a href=&#34;https://doi.org/10.1287/moor.7.4.617&#34;&gt;Roth, 1982&lt;/a&gt;), nor can any subset of &lt;code&gt;\(A\)&lt;/code&gt; coordinate to do (strictly) better (&lt;a href=&#34;https://doi.org/10.2307/2321753&#34;&gt;Dubins and Freedman, 1981&lt;/a&gt;).
However, people in &lt;code&gt;\(B\)&lt;/code&gt; may be able to do better.
For example, suppose the preferences among people in &lt;code&gt;\(A=\{a_1,a_2,a_3\}\)&lt;/code&gt; and &lt;code&gt;\(B=\{b_1,b_2,b_3\}\)&lt;/code&gt; are given by
&lt;code&gt;$$\begin{align*} b_2&amp;amp;\succ_{a_1}b_1\succ_{a_1}b_3 \\ b_1&amp;amp;\succ_{a_2}b_2\succ_{a_2}b_3 \\ b_1&amp;amp;\succ_{a_3}b_2\succ_{a_3}b_3 \\ a_1&amp;amp;\succ_{b_1}a_3\succ_{b_1}a_2 \\ a_3&amp;amp;\succ_{b_2}a_1\succ_{b_2}a_2 \\ a_1&amp;amp;\succ_{b_3}a_2\succ_{b_3}a_3, \end{align*}$$&lt;/code&gt;
where &lt;code&gt;\(j\succ_ik\)&lt;/code&gt; means that &lt;code&gt;\(i\)&lt;/code&gt; prefers &lt;code&gt;\(j\)&lt;/code&gt; to &lt;code&gt;\(k\)&lt;/code&gt;.
Applying the GS algorithm to these preferences delivers the stable matching &lt;code&gt;\(\{(a_1,b_2),(a_2,b_3),(a_3,b_1)\}\)&lt;/code&gt;.
But if &lt;code&gt;\(b_1\)&lt;/code&gt; misreported their preferences as &lt;code&gt;\(a_1\succ_{b_1}a_2\succ_{b_1}a_3\)&lt;/code&gt; then the algorithm would deliver &lt;code&gt;\(\{(a_1,b_1),(a_2,b_3),(a_3,b_2)\}\)&lt;/code&gt;, which &lt;code&gt;\(b_1\)&lt;/code&gt; prefers.&lt;/p&gt;
&lt;h2 id=&#34;convergence&#34;&gt;Convergence&lt;/h2&gt;
&lt;p&gt;Since everyone in &lt;code&gt;\(A\)&lt;/code&gt; proposes to everyone in &lt;code&gt;\(B\)&lt;/code&gt; at most once, the GS algorithm never requires more than &lt;code&gt;\(n^2\)&lt;/code&gt; proposals.
However, the algorithm typically requires fewer proposals.
For example, suppose the utility &lt;code&gt;\(a\in A\)&lt;/code&gt; derives from being matched to &lt;code&gt;\(b\in B\)&lt;/code&gt; is
&lt;code&gt;$$U_{ab}=\rho W_b+(1-\rho)X_{ab},$$&lt;/code&gt;
where &lt;code&gt;\(W_b\)&lt;/code&gt; and &lt;code&gt;\(X_{ab}\)&lt;/code&gt; are iid uniformly distributed on the unit interval &lt;code&gt;\([0,1]\)&lt;/code&gt;, and where &lt;code&gt;\(\rho\)&lt;/code&gt; indexes the correlation of match utilities.
Similarly, suppose the utility &lt;code&gt;\(b\)&lt;/code&gt; derives from being matched to &lt;code&gt;\(a\)&lt;/code&gt; is
&lt;code&gt;$$V_{ba}=\rho Y_a+(1-\rho)Z_{ba},$$&lt;/code&gt;
where &lt;code&gt;\(Y_a\)&lt;/code&gt; and &lt;code&gt;\(Z_{ba}\)&lt;/code&gt; are also iid uniform on &lt;code&gt;\([0,1]\)&lt;/code&gt;.
The utilities &lt;code&gt;\(U_{ab}\)&lt;/code&gt; and &lt;code&gt;\(V_{ba}\)&lt;/code&gt; determine peoples&amp;rsquo; preferences over matches, and increasing &lt;code&gt;\(\rho\)&lt;/code&gt; makes those preferences more homogeneous.
The chart below shows how the number of proposals required by the GS algorithm covaries with &lt;code&gt;\(\rho\)&lt;/code&gt; when &lt;code&gt;\(n=20\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;On average, more proposals are required when preferences are more homogeneous.
Intuitively, increasing &lt;code&gt;\(\rho\)&lt;/code&gt; makes it more likely that an early tentative acceptance will become a rejection, forcing the rejected person to make another proposal.
If &lt;code&gt;\(\rho=1\)&lt;/code&gt; then the GS algorithm always requires
&lt;code&gt;$$\sum_{x=1}^nx=\frac{n(n+1)}{2}$$&lt;/code&gt;
proposals.
To see why, notice that if &lt;code&gt;\(\rho=1\)&lt;/code&gt; then everyone in &lt;code&gt;\(A\)&lt;/code&gt; has the same preferences over everyone in &lt;code&gt;\(B\)&lt;/code&gt; and vice versa.
Consequently, the person in &lt;code&gt;\(A\)&lt;/code&gt; most preferred by the people in &lt;code&gt;\(B\)&lt;/code&gt; always gets their first choice, the person in &lt;code&gt;\(A\)&lt;/code&gt; second-most preferred by the people in &lt;code&gt;\(B\)&lt;/code&gt; always gets their second choice, and so on.
But since everyone in &lt;code&gt;\(A\)&lt;/code&gt; has the same preferences, each has to make as many proposals as is their position on the (common) preference ordering among the people in &lt;code&gt;\(B\)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;One limitation of the GS algorithm is that it assumes everyone has strict, complete preferences over potential matches.
This assumption may not hold in practice: &lt;code&gt;\(a\in A\)&lt;/code&gt; could be indifferent between &lt;code&gt;\(b\in B\)&lt;/code&gt; and &lt;code&gt;\(b&#39;\in B\)&lt;/code&gt;, or &lt;code&gt;\(a\)&lt;/code&gt; may not even know who is in &lt;code&gt;\(B\)&lt;/code&gt; let alone the utilities derived from being matched to them.
&lt;a href=&#34;https://doi.org/10.1016/0166-218X%2892%2900179-P&#34;&gt;Irving (1994)&lt;/a&gt; generalizes the GS algorithm to handle situations with indifferences, while &lt;a href=&#34;https://doi.org/10.1016/S0304-3975%2801%2900206-7&#34;&gt;Manlove et al. (2002)&lt;/a&gt; describe the computational complexity generated by allowing for incomplete preferences.&lt;/p&gt;
&lt;p&gt;Another limitation of the GS algorithm is that it always delivers a stable matching that is best for people in &lt;code&gt;\(A\)&lt;/code&gt; and worst for people in &lt;code&gt;\(B\)&lt;/code&gt;.
This &amp;ldquo;extremal&amp;rdquo; property of the algorithm&amp;rsquo;s output motivates alternative algorithms (e.g., those by &lt;a href=&#34;https://doi.org/10.2307/2938326&#34;&gt;Roth and Vande Vate (1990)&lt;/a&gt; and &lt;a href=&#34;https://doi.org/10.1007/s11238-005-6846-0&#34;&gt;Romero-Medina (2005)&lt;/a&gt;, and more recently &lt;a href=&#34;https://doi.org/10.1287/opre.2020.2042&#34;&gt;Dworczak (2021)&lt;/a&gt; and &lt;a href=&#34;https://ideas.repec.org/p/cte/werepe/31711.html&#34;&gt;Kuvalekar and Romero-Medina (2021)&lt;/a&gt;) that deliver &lt;em&gt;ex ante&lt;/em&gt; fairer matchings by randomizing whose preferences (i.e., people in &lt;code&gt;\(A\)&lt;/code&gt; or people in &lt;code&gt;\(B\)&lt;/code&gt;) are used to form matches.&lt;/p&gt;
&lt;p&gt;A third limitation is that the GS algorithm assumes match utilities do not depend on the sequence of proposals.
In particular, the algorithm assumes that &lt;code&gt;\(a\in A\)&lt;/code&gt; derives the same utility from being matched to &lt;code&gt;\(b\in B\)&lt;/code&gt; regardless of how much &lt;code&gt;\(b\)&lt;/code&gt; wants to be matched to &lt;code&gt;\(a\)&lt;/code&gt;.
This assumption seems unrealistic: if I proposed to someone but later learned I was &lt;em&gt;the last person&lt;/em&gt; they wanted to marry then that lesson would surely affect my comfort with the proposal.
One way to resolve this issue could be to run the algorithm many times, allowing people to revise their preferences at each run based on the matching obtained in the previous run.
However, this approach could be expensive&amp;mdash;computationally, cognitively, and emotionally&amp;mdash;and might not converge if peoples&amp;rsquo; preference revisions aren&amp;rsquo;t well-behaved.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Female representation and collaboration at the NBER</title>
      <link>https://bldavies.com/blog/female-representation-collaboration-nber/</link>
      <pubDate>Mon, 29 Mar 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/female-representation-collaboration-nber/</guid>
      <description>&lt;p&gt;This post analyzes the &lt;a href=&#34;#representation-across-research-programs&#34;&gt;representation&lt;/a&gt; of, and &lt;a href=&#34;#co-authorship-patterns&#34;&gt;collaboration&lt;/a&gt; among, female authors of &lt;a href=&#34;https://www.nber.org/papers&#34;&gt;NBER working papers&lt;/a&gt; over the last four decades.
My analysis uses paper-author correspondences provided by the R package &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;nberwp&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;estimating-sexes&#34;&gt;Estimating sexes&lt;/h2&gt;
&lt;p&gt;I estimate authors&amp;rsquo; sexes using the R package &lt;a href=&#34;https://cran.r-project.org/package=gender&#34;&gt;gender&lt;/a&gt;, which provides access to historical baby name data from the US Social Security Administration.
I focus on baby names between 1940 and 1995 because these roughly correspond to (what I expect are) the birth years of authors who published NBER working papers during the 1980s through 2010s.&lt;/p&gt;
&lt;p&gt;Comparing authors&amp;rsquo; first names to the frequency of female and male baby names allows me to estimate the probability that each author is female.
For example, 3% of babies named Alex between 1940 and 1995 were female, so the estimated probability that an author named Alex is female is 0.03.
Rounding each probability to the nearest integer estimates the binary indicator variable for whether each author is female.&lt;/p&gt;
&lt;p&gt;The table below reports the number of NBER working papers and authors during the 1980s, 1990s, 2000s, and 2010s.
It also reports the percentage of those authors whom I estimate to be female, as well as the percentage of authors whose sexes I can estimate.
The number of authors roughly doubled each decade, and the percentage of those authors whom I estimate to be female almost doubled between the 1980s and 2010s.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Decade&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Papers&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Authors&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;% authors female&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;% authors with estimable sex&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1980s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2,820&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;972&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;14.1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;93.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1990s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4,213&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2,211&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;19.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2000s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8,188&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5,118&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;24.0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;85.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2010s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10,970&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9,519&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;27.0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;84.1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The percentage of authors with estimable sex is less than 100% because some authors (i) never listed their first names on their papers&amp;rsquo; bylines (e.g., always published as &amp;ldquo;J. Smith&amp;rdquo;) or (ii) have first names that do not appear in the baby name data.
Throughout this post, I assume that conditions (i) and (ii) occur at the same rate for both sexes.
Almost all (99.9%) of the authors satisfying either condition satisfy (ii) because they have foreign names.
The decrease in sex estimability over time reflects the increase in (co-)authorship of NBER working papers by researchers born outside the United States.&lt;/p&gt;
&lt;h2 id=&#34;representation-across-research-programs&#34;&gt;Representation across research programs&lt;/h2&gt;
&lt;p&gt;The NBER organizes its research into &lt;a href=&#34;https://www.nber.org/programs-projects/programs-working-groups&#34;&gt;programs&lt;/a&gt;, each of which &amp;ldquo;corresponds loosely to a traditional field of study within economics.&amp;rdquo;
I count the papers associated with each program in &lt;a href=&#34;#appendix&#34;&gt;the appendix below&lt;/a&gt;.
The largest programs are Labor Studies, Economic Fluctuations and Growth, and Public Economics, reflecting the NBER&amp;rsquo;s focus on policy-relevant economic research.&lt;/p&gt;
&lt;p&gt;The table below reports the percentage of authors whom I estimate to be female in each of the NBER&amp;rsquo;s ten largest research programs.
I pool the remaining eleven programs into an &amp;ldquo;Other&amp;rdquo; program and report separate percentages for each decade.
The percentage of female authors grew over time, both overall and within each of the tabulated programs, and was larger in programs that are relatively focused on individual-level outcomes (e.g., Labor Studies and Health Economics).
I omit the percentages for Asset Pricing and Corporate Finance in the 1980s because there was only one paper associated with those programs during that decade.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Program&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;1980s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;1990s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;2000s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;2010s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Labor Studies (LS)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;27.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economic Fluctuations and Growth (EFG)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;17.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;18.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Public Economics (PE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;21.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;International Finance and Macroeconomics (IFM)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;International Trade and Investment (ITI)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Monetary Economics (ME)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5.3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;17.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Asset Pricing (AP)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;18.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Productivity, Innovation, and Entrepreneurship (PR)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Corporate Finance (CF)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;-&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Health Economics (HE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Other&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;All&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;27.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Another way to analyze female representation is to compare the density of female-authored working papers across programs.
I present this comparison in the chart below, focusing on papers published during the 2010s.
The horizontal axis measures the percentage of working papers published by female authors in each program.
I compute these percentages by counting papers &amp;ldquo;fractionally&amp;rdquo; so that, for example, papers with two authors and three associated programs contribute a sixth of a paper to the count for each author-program pair.
This method avoids double-counting papers across programs and sexes.
Aggregating fractional counts by program and sex allows me to estimate the percentage of working papers published in each program by female authors.
I order programs by percentage of female authorship and color them according to a categorization based on that used by &lt;a href=&#34;https://www.nber.org/papers/w23953&#34;&gt;Chari and Goldsmith-Pinkham (2017)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/female-authorships-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Overall, females wrote about 21% of the working papers published during the 2010s.
These papers were relatively concentrated among programs focused on applied microeconomics rather than on macroeconomics or finance.
These patterns echo those presented by Chari and Goldsmith-Pinkham (2017), and could reflect differences in academic culture between different branches of economics (see, e.g., &lt;a href=&#34;https://www.nber.org/papers/w28494&#34;&gt;Dupas et al., 2021&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&#34;co-authorship-patterns&#34;&gt;Co-authorship patterns&lt;/h2&gt;
&lt;p&gt;I infer the collaboration patterns among NBER authors from the working paper co-authorship network for each decade.
In each network, nodes correspond to authors who published at least one working paper during that decade, and edges join authors who co-authored at least one working paper during that decade.
The table below summarizes each network.
The networks grew larger and less dense over time, while the rise in mean degree&amp;mdash;that is, the mean number of co-authors&amp;mdash;reflects the rise in co-authorship among economists documented in other studies (e.g., &lt;a href=&#34;https://doi.org/10.1080/13504851.2015.1119783&#34;&gt;Rath and Wohlrabe, 2017&lt;/a&gt;).&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Decade&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Nodes&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Edges&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Edge density (%)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Mean degree&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1980s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;972&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1,197&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.46&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1990s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2,211&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3,062&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.13&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.77&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2000s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5,118&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8,890&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.07&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.47&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2010s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9,519&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;21,455&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.05&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4.51&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The figure below compares the co-authorship network degree distributions for each sex.
Females tended to have fewer co-authors than males, but the mean difference was small and fell over time (from 0.78 during the 1980s to 0.66 during the 2010s).&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/degree-distributions-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The next three tables describe structural properties of each decade&amp;rsquo;s co-authorship network based on authors&amp;rsquo; estimated sexes.
These properties may be sensitive to estimation errors.
Therefore, rather than report point estimates for each property, I report 95% confidence intervals obtained using the following bootstrap procedure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Randomly assign each author to be female according to the probabilities obtained from the baby name data.&lt;/li&gt;
&lt;li&gt;Compute each structural property under the randomized assignment.&lt;/li&gt;
&lt;li&gt;Repeat the preceding two steps 1,000 times to obtain bootstrap distributions of each property.&lt;/li&gt;
&lt;li&gt;Use the 2.5% and 97.5% quantiles of the bootstrap distributions as the lower and upper confidence bounds.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first property I examine is the &lt;a href=&#34;https://en.wikipedia.org/wiki/Clustering_coefficient&#34;&gt;clustering coefficient&lt;/a&gt;: the probability that two authors were co-authors given that they shared a common co-author.
The table below compares the clustering coefficient of the full co-authorship network in each decade with the clustering coefficient of the sub-networks &lt;a href=&#34;https://en.wikipedia.org/wiki/Induced_subgraph&#34;&gt;induced&lt;/a&gt; by the sets of authors whom I estimate to be female and male.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Clustering coefficient&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;1980s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;1990s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;2000s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;2010s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Overall&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.17&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.18&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.21&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Among females (95% CI)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.39, 0.50)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.41, 0.50)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.30, 0.35)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.32, 0.35)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Among males (95% CI)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.16, 0.17)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.17, 0.17)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.20, 0.21)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.23, 0.23)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The female sub-networks were much more clustered than the full and male networks.
Such clustering suggests a stronger tendency among females to &lt;a href=&#34;https://bldavies.com/blog/triadic-closure-nber&#34;&gt;close triads&lt;/a&gt; by collaborating with other females with whom they share a common (female) co-author.
The decline in clustering among females over time could reflect the rise in between-sex co-authorship: the percentage of co-authored papers with at least one author of each sex was about 16% in the 1980s, and rose to 25%, 35%, and 42% in the subsequent three decades.&lt;/p&gt;
&lt;p&gt;The next property I examine is the &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing&#34;&gt;assortativity coefficient&lt;/a&gt;, which measures the extent to which authors tended to co-author with members of the same sex.
The coefficient equals 1 when there is perfect sorting (i.e., no between-sex edges), −1 when there is perfect dis-sorting (i.e., no within-sex edges), and 0 when there is no sorting (i.e., the network is &amp;ldquo;as random&amp;rdquo;).
The table below shows that each network&amp;rsquo;s assortativity coefficient was positive, implying that within-sex co-authorship was more common than we would expect if co-authorships were random.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Decade&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Assort. coeff. (95% CI)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1980s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.05, 0.09)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1990s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.08, 0.11)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2000s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.07, 0.09)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2010s&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.08, 0.10)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Computing assortativity coefficients across all programs may mask program-specific patterns.
I explore these patterns in my final table below, which reports 95% confidence intervals for the assortativity coefficient of the co-authorship network within each of the NBER&amp;rsquo;s ten largest research programs.
I label programs by their abbreviations so that the table is not too wide.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Program&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;1980s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;1990s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;2000s&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;2010s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;LS&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.16, 0.27)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.13, 0.19)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.05, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.09, 0.11)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;EFG&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.07, 0.08)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.07, 0.01)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.02, 0.02)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.02, 0.06)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;PE&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.04, 0.14)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.01, 0.05)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.03, 0.07)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.05, 0.07)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;IFM&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.05, 0.04)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.01, 0.08)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.01, 0.05)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.03, 0.08)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;ITI&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.06, 0.04)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.01, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.00, 0.07)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.05, 0.10)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;ME&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.07, 0.04)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.03, 0.06)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.10, -0.03)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.03, 0.09)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;AP&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;-&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.06, 0.07)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.01, 0.05)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.00, 0.05)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;PR&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.15, -0.01)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.12, 0.22)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.02, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.07, 0.11)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;CF&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;-&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.04, 0.07)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.03, 0.04)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.03, 0.09)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;HE&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(-0.14, -0.01)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.01, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.01, 0.05)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.07, 0.10)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;All&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.05, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.08, 0.11)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.07, 0.09)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;(0.08, 0.10)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The network among authors in the Labor Studies (LS) program became less sorted over time, whereas the network among authors in the Health Economics (HE) program became more sorted over time.
But the representation of women in both of those programs grew over time, suggesting that the mechanisms promoting female representation were different than the mechanisms promoting female collaboration.
It would be interesting to explore these mechanisms further, but I&amp;rsquo;ll leave that for a future post.&lt;/p&gt;
&lt;h2 id=&#34;acknowledgements&#34;&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;Thanks to &lt;a href=&#34;https://adhami.people.stanford.edu&#34;&gt;Mohamad Adhami&lt;/a&gt;, &lt;a href=&#34;https://www.florenciahnilo.com&#34;&gt;Florencia Hnilo&lt;/a&gt; and &lt;a href=&#34;https://www.akhilakovvuri.com&#34;&gt;Akhila Kovvuri&lt;/a&gt; for reading draft versions of this post.&lt;/p&gt;
&lt;h2 id=&#34;appendix&#34;&gt;Appendix&lt;/h2&gt;
&lt;p&gt;The table below (fractionally) counts working papers by program and decade.
I present programs in decreasing order of associated papers across all four decades.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Program&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;1980s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;1990s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;2000s&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;2010s&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Labor Studies (LS)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;454&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;635&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;868&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,081&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economic Fluctuations and Growth (EFG)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;458&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;471&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;921&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1,083&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Public Economics (PE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;445&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;557&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;827&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;993&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;International Finance and Macroeconomics (IFM)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;374&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;466&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;731&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;662&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;International Trade and Investment (ITI)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;370&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;517&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;631&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;525&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Monetary Economics (ME)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;418&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;327&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;389&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;514&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Asset Pricing (AP)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;221&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;610&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;627&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Productivity, Innovation, and Entrepreneurship (PR)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;96&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;231&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;371&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;563&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Corporate Finance (CF)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;131&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;436&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;560&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Health Economics (HE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;82&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;115&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;355&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;497&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Development of the American Economy (DAE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;45&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;78&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;311&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;379&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Industrial Organization (IO)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;82&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;300&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;432&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economics of Aging (AG)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;126&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;237&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;340&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Health Care (HC)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;248&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;316&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Environment and Energy Economics (EEE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;138&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;483&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economics of Education (ED)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;209&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;411&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Children (CH)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;35&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;246&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;297&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Political Economics (POL)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;141&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;415&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Law and Economics (LE)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;57&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;188&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;231&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Development Economics (DEV)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;462&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Technical Working Papers (TWP)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;None&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;58&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Total&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2,820&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4,213&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8,188&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10,970&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description>
    </item>
    
    <item>
      <title>Monopoly equilibrium in insurance markets</title>
      <link>https://bldavies.com/blog/monopoly-equilibrium-insurance-markets/</link>
      <pubDate>Fri, 19 Feb 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/monopoly-equilibrium-insurance-markets/</guid>
      <description>&lt;p&gt;This post shows how monopoly insurance pricing can lead to inefficient risk sharing.
I describe &lt;a href=&#34;#model&#34;&gt;a mathematical model&lt;/a&gt; of the monopoly equilibrium, present &lt;a href=&#34;#numerical-example&#34;&gt;a numerical example&lt;/a&gt;, and discuss &lt;a href=&#34;#limitations&#34;&gt;some limitations&lt;/a&gt; of my analysis.&lt;/p&gt;
&lt;h2 id=&#34;model&#34;&gt;Model&lt;/h2&gt;
&lt;p&gt;Suppose I have initial wealth &lt;code&gt;\(w_0\)&lt;/code&gt; and suffer a loss of size &lt;code&gt;\(L\)&lt;/code&gt; with probability &lt;code&gt;\(p\)&lt;/code&gt;.
I can buy &lt;code&gt;\(c\in[0,L]\)&lt;/code&gt; units of insurance coverage at per-unit price &lt;code&gt;\(\lambda p\)&lt;/code&gt;, where &lt;code&gt;\(\lambda\ge1\)&lt;/code&gt; is a loading factor set by my insurer.
I choose the amount of coverage &lt;code&gt;\(c^*\)&lt;/code&gt; that maximizes my expected utility
&lt;code&gt;$$EU(c)\equiv(1-p)u(w_0-\lambda p c)+pu(w_0-\lambda pc-L+c),$$&lt;/code&gt;
where
&lt;code&gt;$$u(w)\equiv-\frac{1}{a}\exp(-aw)$$&lt;/code&gt;
is my utility function and &lt;code&gt;\(a&amp;gt;0\)&lt;/code&gt; is my &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_aversion#Absolute_risk_aversion&#34;&gt;coefficient of absolute risk aversion&lt;/a&gt;.
Solving the first-order condition for &lt;code&gt;\(c^*\)&lt;/code&gt; gives
&lt;code&gt;$$c^*=L-\frac{1}{a}\log\left(\frac{\lambda(1-p)}{1-\lambda p}\right),$$&lt;/code&gt;
which equals &lt;code&gt;\(L\)&lt;/code&gt; when &lt;code&gt;\(\lambda=1\)&lt;/code&gt; (i.e, the premium is actuarially fair) and equals zero when &lt;code&gt;\(\lambda\)&lt;/code&gt; equals
&lt;code&gt;$$\lambda_{\text{max}}=\frac{1}{p+(1-p)\exp(-aL)}.$$&lt;/code&gt;
This limiting value of &lt;code&gt;\(\lambda\)&lt;/code&gt; approaches one as &lt;code&gt;\(aL\)&lt;/code&gt; approaches zero&amp;mdash;I won&amp;rsquo;t buy insurance if I am risk neutral or face no risk&amp;mdash;and is always less than &lt;code&gt;\(1/p\)&lt;/code&gt;.
For &lt;code&gt;\(\lambda\in(1,\lambda_{\text{max}})\)&lt;/code&gt;, the slope
&lt;code&gt;$$\newcommand{\parfrac}[2]{\frac{\partial #1}{\partial #2}} \parfrac{c^*}{\lambda}=-\frac{1}{a\lambda(1-\lambda p)}$$&lt;/code&gt;
of my inverse demand curve is strictly decreasing, implying that I view insurance as an ordinary good.&lt;/p&gt;
&lt;p&gt;Now suppose my insurer knows my demand for coverage &lt;code&gt;\(c^*\equiv C(\lambda)\)&lt;/code&gt; given the loading factor &lt;code&gt;\(\lambda\)&lt;/code&gt;, as well as the other parameters in my choice environment.
Then they can choose &lt;code&gt;\(\lambda\)&lt;/code&gt; to maximize their expected profit
&lt;code&gt;$$\pi(\lambda)\equiv(\lambda-1)pC(\lambda),$$&lt;/code&gt;
which equals the premium I pay minus the expected cost of indemnifying me.
If &lt;code&gt;\(L&amp;gt;0\)&lt;/code&gt; then the profit-maximizing loading factor &lt;code&gt;\(\lambda^*\)&lt;/code&gt; is strictly between one and &lt;code&gt;\(\lambda_{\text{max}}\)&lt;/code&gt;, and setting &lt;code&gt;\(\lambda=\lambda^*\)&lt;/code&gt; gives my insurer positive expected profit.
But then I demand partial coverage &lt;code&gt;\(C(\lambda^*)&amp;lt;L\)&lt;/code&gt;, which is allocatively inefficient because I am risk averse but my insurer is risk neutral: having the insurer bear more of my risk would make me better off but my insurer no worse off.
Consequently, we suffer a deadweight loss relative to the equilibrium in which my insurer sets &lt;code&gt;\(\lambda=1\)&lt;/code&gt;, I demand full coverage, and my insurer bears all of my risk.&lt;/p&gt;
&lt;h2 id=&#34;numerical-example&#34;&gt;Numerical example&lt;/h2&gt;
&lt;p&gt;The figure below describes the monopoly equilibrium when &lt;code&gt;\(w_0=100\)&lt;/code&gt;, &lt;code&gt;\(L=20\)&lt;/code&gt;, &lt;code&gt;\(p=0.2\)&lt;/code&gt;, and &lt;code&gt;\(a=0.2\)&lt;/code&gt;.
My insurer best-responds to my demand schedule (the downward-sloping curve) by setting the loading factor equal to &lt;code&gt;\(\lambda^*=3.26\)&lt;/code&gt;, which earns them expected profit &lt;code&gt;\(\pi=4.49\)&lt;/code&gt;.
At the price &lt;code&gt;\(\lambda^* p=0.65\)&lt;/code&gt;, I buy &lt;code&gt;\(c^*=9.94\)&lt;/code&gt; units of coverage and enjoy
&lt;code&gt;$$p\int_{\lambda^*}^{\lambda_{\text{max}}}C(\lambda)\,\mathrm{d}\lambda=1.68$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;units of consumer surplus.
In contrast, at the actuarially fair price &lt;code&gt;\(p\)&lt;/code&gt; I would have bought full coverage, and although my insurer would have made zero expected profit we would have avoided the deadweight loss of 2.14 generated by our inefficient risk-sharing arrangement at the monopoly equilibrium.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;One way to make sense of these numbers is to compute the certainty-equivalent wealth
&lt;code&gt;$$CE(\lambda)=u^{-1}(EU(C(\lambda)))$$&lt;/code&gt;
that, if held with certainty, would give me as much utility as I expect to enjoy if I buy &lt;code&gt;\(C(\lambda)\)&lt;/code&gt; units of coverage at per-unit price &lt;code&gt;\(\lambda p\)&lt;/code&gt;.
Buying insurance at the monopoly equilibrium price raises my certainty equivalent wealth by &lt;code&gt;\(CE(\lambda^*)-CE(\lambda_{\text{max}})=1.68\)&lt;/code&gt;, the consumer surplus I enjoy at that equilibrium.
Making the premium actuarially fair would further raise my certainty-equivalent wealth by &lt;code&gt;\(CE(1)-CE(\lambda^*)=6.63\)&lt;/code&gt; but lower my insurer&amp;rsquo;s expected profit by &lt;code&gt;\(\pi(\lambda^*)=4.49\)&lt;/code&gt;; the sum of our surpluses would rise by &lt;code&gt;\(6.63-4.49=2.14\)&lt;/code&gt;, the deadweight loss at the monopoly equilibrium.&lt;/p&gt;
&lt;p&gt;The chart below presents some comparative statics of the monopoly equilibrium.
I maintain the parameters &lt;code&gt;\(w_0=100\)&lt;/code&gt; and &lt;code&gt;\(L=20\)&lt;/code&gt; from above, but vary my risk aversion coefficient &lt;code&gt;\(a\)&lt;/code&gt; and the probability &lt;code&gt;\(p\)&lt;/code&gt; with which I incur the loss.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/equilibria-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;My insurer sets a higher loading factor and earns more profit when my risk aversion rises.
This is because the mixed partial derivative
&lt;code&gt;$$\parfrac{^2c^*}{\lambda\partial a}=\frac{1}{a^2\lambda(1-\lambda p)}$$&lt;/code&gt;
is strictly positive, which means that my demand is less sensitive to price changes when &lt;code&gt;\(a\)&lt;/code&gt; is high.
My insurer exploits this lower sensitivity by charging me higher prices.
When &lt;code&gt;\(a\)&lt;/code&gt; is small, this exploitation moves us away from the actuarially fair equilibrium and so raises the deadweight loss; when &lt;code&gt;\(a\)&lt;/code&gt; is large, I want to buy a lot of insurance despite its high price, and so the deadweight loss is small because having the insurer bear my risk is allocatively efficient.&lt;/p&gt;
&lt;p&gt;On the other hand, my insurer sets a lower loading factor when the probability of loss rises.
This is because the mixed partial derivative
&lt;code&gt;$$\parfrac{^2c^*}{\lambda\partial p}=-\frac{\lambda}{\alpha(1-\lambda p)^2}$$&lt;/code&gt;
is strictly negative, which means that my demand is more sensitive to price changes when &lt;code&gt;\(p\)&lt;/code&gt; is high.
My insurer responds to this sensitivity by forfeiting some of its monopoly power, moving us closer to the actuarially fair equilibrium and lowering the deadweight loss.&lt;/p&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;One issue with my analysis is the assumption that I have exponential utility, which implies that my tolerance for, and demand for insurance against, additive risks does not depend on how rich I am.
Under this assumption, I am equally willing to pay for insurance to avoid a $10 loss when I have $10 as I am when I have $10 million, which seems implausible.
I could instead assume that I have &lt;a href=&#34;https://en.wikipedia.org/wiki/Isoelastic_utility&#34;&gt;isoelastic utility&lt;/a&gt;
&lt;code&gt;$$u(w)\equiv\frac{w^{1-r}-1}{1-r}$$&lt;/code&gt;
for some &lt;code&gt;\(r&amp;gt;0\)&lt;/code&gt;, which would imply that my willingness to pay for insurance falls as I become richer.
However, replacing exponential with isoelastic utility in the plots above delivers qualitatively identical patterns.&lt;/p&gt;
&lt;p&gt;Another issue is the supposition that the insurer knows my demand schedule.
In reality, my insurer would have imperfect information about my utility function and the parameters of my choice environment, and so would not know my inverse demand function &lt;code&gt;\(C(\lambda)\)&lt;/code&gt;.
But they could estimate &lt;code&gt;\(C(\lambda)\)&lt;/code&gt; by, for example, asking how much insurance I would buy at a range of prices.
They would have to be clever to prevent me from over-reporting my price-sensitivity in an attempt to get cheaper coverage, but I&amp;rsquo;m sure real-world insurers have solved this problem (at least approximately) given their financial incentives.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Dyadic dependence</title>
      <link>https://bldavies.com/blog/dyadic-dependence/</link>
      <pubDate>Wed, 10 Feb 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/dyadic-dependence/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\([n]\equiv\{1,2,\ldots,n\}\)&lt;/code&gt; be a set of individuals.
Suppose I have data &lt;code&gt;\(\{(y_{ij},x_{ij}):i,j\in[n]\ \text{with}\ i&amp;lt;j\}\)&lt;/code&gt; on pairs in &lt;code&gt;\([n]\)&lt;/code&gt; generated by the process
&lt;code&gt;$$\renewcommand{\epsilon}{\varepsilon} y_{ij}=x_{ij}\beta+\epsilon_{ij},$$&lt;/code&gt;
where &lt;code&gt;\(x_{ij}\)&lt;/code&gt; is a row vector of pair &lt;code&gt;\(\{i,j\}\)&lt;/code&gt;&#39;s characteristics, &lt;code&gt;\(\beta\)&lt;/code&gt; is a vector of coefficients to be estimated, and &lt;code&gt;\(\epsilon_{ij}\)&lt;/code&gt; is a random error term with zero mean and zero correlation with the &lt;code&gt;\(x_{ij}\)&lt;/code&gt;.
For example, &lt;code&gt;\([n]\)&lt;/code&gt; could be the nodes in a network, &lt;code&gt;\(x_{ij}\)&lt;/code&gt; the dimensions along which nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\)&lt;/code&gt; interact, and &lt;code&gt;\(y_{ij}\)&lt;/code&gt; the outcome of such interaction.&lt;/p&gt;
&lt;p&gt;We can rewrite the data-generating process (DGP) in matrix form as
&lt;code&gt;$$y=X\beta+\epsilon,$$&lt;/code&gt;
where &lt;code&gt;\(y\)&lt;/code&gt; is the vector of outcomes, &lt;code&gt;\(X\)&lt;/code&gt; is the design matrix, and &lt;code&gt;\(\epsilon\)&lt;/code&gt; is the vector of errors.
Here &lt;code&gt;\(X\)&lt;/code&gt; has
&lt;code&gt;$$N\equiv\frac{n(n-1)}{2}$$&lt;/code&gt;
rows, each corresponding to a(n unordered) pair of individuals in &lt;code&gt;\([n]\)&lt;/code&gt;.
Since the &lt;code&gt;\(x_{ij}\)&lt;/code&gt; and &lt;code&gt;\(\epsilon_{ij}\)&lt;/code&gt; are uncorrelated, the ordinary least squares estimator
&lt;code&gt;$$\hat\beta=(X^T\!X)^{-1}X^T\!y$$&lt;/code&gt;
of &lt;code&gt;\(\beta\)&lt;/code&gt; is unbiased.
However, &lt;code&gt;\(\hat\beta\)&lt;/code&gt; may not be &lt;a href=&#34;https://en.wikipedia.org/wiki/Gauss%E2%80%93Markov_theorem&#34;&gt;efficient&lt;/a&gt; because the errors &lt;code&gt;\(\epsilon_{ij}\)&lt;/code&gt; may be correlated.
For example, if
&lt;code&gt;$$\epsilon_{ij}=u_i+u_j+v_{ij}$$&lt;/code&gt;
with &lt;code&gt;\(u_i\)&lt;/code&gt;, &lt;code&gt;\(u_j\)&lt;/code&gt;, and &lt;code&gt;\(v_{ij}\)&lt;/code&gt; independent then
&lt;code&gt;$$\DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\Var}{Var} \Cov(\epsilon_{ij},\epsilon_{jk})=\Var(u_j).$$&lt;/code&gt;
Intuitively, the pairs &lt;code&gt;\(\{i,j\}\)&lt;/code&gt; and &lt;code&gt;\(\{j,k\}\)&lt;/code&gt; are linked through individual &lt;code&gt;\(j\)&lt;/code&gt;, and so any errors specific to that individual affect the errors for both pairs.
Consequently, the &lt;a href=&#34;https://en.wikipedia.org/wiki/Homoscedasticity&#34;&gt;homoskedastic&lt;/a&gt; estimator
&lt;code&gt;$$\widehat{\Var}_{\text{Hom.}}(\hat\beta)=\hat\sigma^2(X^T\!X)^{-1}$$&lt;/code&gt;
with
&lt;code&gt;$$\hat\sigma^2=\frac{1}{N}\sum_{ij}\hat\epsilon_{ij}^2$$&lt;/code&gt;
and
&lt;code&gt;$$\hat\epsilon_{ij}=y_{ij}-x_{ij}\hat\beta$$&lt;/code&gt;
will typically under-estimate the variance in &lt;code&gt;\(\hat\beta\)&lt;/code&gt; by failing to account for linked pairs having dependent errors.&lt;/p&gt;
&lt;p&gt;So, how can we account for such dependence?
Consider the &amp;ldquo;sandwich&amp;rdquo; form
&lt;code&gt;$$\Var(\hat\beta)=BMB$$&lt;/code&gt;
of the (co)variance matrix for &lt;code&gt;\(\hat\beta\)&lt;/code&gt;, where &lt;code&gt;\(B=(X^T\!X)^{-1}\)&lt;/code&gt; is the &amp;ldquo;bread&amp;rdquo; matrix and &lt;code&gt;\(M=X^T\!VX\)&lt;/code&gt; is the &amp;ldquo;meat&amp;rdquo; matrix with &lt;code&gt;\(V=\Var(\epsilon)\)&lt;/code&gt; the error (co)variance matrix.
We need to estimate &lt;code&gt;\(M\)&lt;/code&gt; because we don&amp;rsquo;t observe the &lt;code&gt;\(\epsilon_{ij}\)&lt;/code&gt;.
Indexing pairs by &lt;code&gt;\(p\)&lt;/code&gt;, the homoskedastic estimator defined above uses
&lt;code&gt;$$\begin{align} \hat{M}_{\text{Hom.}} &amp;amp;= \hat\sigma^2X^T\!X \\ &amp;amp;= \hat\sigma^2\sum_{p=1}^Nx_p^T\!x_p, \end{align}$$&lt;/code&gt;
which assumes all errors have equal variance.
In contrast, &lt;a href=&#34;https://doi.org/10.2307/1912934&#34;&gt;White (1980)&lt;/a&gt; suggests using
&lt;code&gt;$$\begin{align} \hat{M}_{\text{White}} &amp;amp;= X^T\!\mathrm{diag}\left(\hat\epsilon_p^2\right)X \\ &amp;amp;= \sum_{p=1}^N\hat\epsilon_p^2x_p^T\!x_p, \end{align}$$&lt;/code&gt;
which allows for unequal error variances (&lt;a href=&#34;https://en.wikipedia.org/wiki/Heteroscedasticity&#34;&gt;heteroskedasticity&lt;/a&gt;).
But neither &lt;code&gt;\(\hat{M}_{\text{Hom.}}\)&lt;/code&gt; nor &lt;code&gt;\(\hat{M}_{\text{White}}\)&lt;/code&gt; allow for dyadic dependence among the errors.
To that end, &lt;a href=&#34;https://doi.org/10.1093/pan/mpv018&#34;&gt;Aronow et al. (2017)&lt;/a&gt; suggest augmenting White&amp;rsquo;s estimator via
&lt;code&gt;$$\begin{align} \hat{M}_{\text{Aronow}} &amp;amp;= \hat{M}_{\text{White}}+\sum_{p=1}^N\sum_{q\in\mathcal{D}(p)}\hat\epsilon_p\hat\epsilon_qx_p^T\!x_q, \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\mathcal{D}(p)\)&lt;/code&gt; is the set of pairs &lt;code&gt;\(q\not=p\)&lt;/code&gt; linked to &lt;code&gt;\(p\)&lt;/code&gt; by a shared individual.
We can express &lt;code&gt;\(\hat{M}_{\text{Aronow}}\)&lt;/code&gt; in matrix form as
&lt;code&gt;$$\hat{M}_{\text{Aronow}}=X^T\!\left(D\odot\hat\epsilon\hat\epsilon^T\!\right)X,$$&lt;/code&gt;
where &lt;code&gt;\(D=(d_{pq})\)&lt;/code&gt; is the dyadic dependence matrix with
&lt;code&gt;$$d_{pq}=\begin{cases} 1 &amp;amp; \text{if pairs}\ p\ \text{and}\ q\ \text{are linked}\\ 0 &amp;amp; \text{otherwise}, \end{cases}$$&lt;/code&gt;
and where &lt;code&gt;\(\odot\)&lt;/code&gt; denotes element-wise multiplication.
Aronow et al. show that, under mild conditions, &lt;code&gt;\(B\hat{M}_{\text{Aronow}}B\)&lt;/code&gt; is a consistent estimator for &lt;code&gt;\(\Var(\hat\beta)\)&lt;/code&gt; when the data exhibit dyadic dependence.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;To see Aronow et al.&amp;lsquo;s estimator in action, suppose the DGP is given by the system
&lt;code&gt;$$\begin{align} y_{ij} &amp;amp;= \beta x_{ij}+\epsilon_{ij} \\ x_{ij} &amp;amp;= z_i+z_j \\ \epsilon_{ij} &amp;amp;= u_i+u_j+v_{ij}, \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(z_i\)&lt;/code&gt;, &lt;code&gt;\(z_j\)&lt;/code&gt;, &lt;code&gt;\(u_i\)&lt;/code&gt;, &lt;code&gt;\(u_j\)&lt;/code&gt; and &lt;code&gt;\(v_{ij}\)&lt;/code&gt; are iid standard normal, and &lt;code&gt;\(\beta=1\)&lt;/code&gt; is the (scalar) coefficient to be estimated.
Both the &lt;code&gt;\(x_{ij}\)&lt;/code&gt; and the &lt;code&gt;\(\epsilon_{ij}\)&lt;/code&gt; exhibit dyadic dependence, so we expect the homoskedastic and White estimators to under-estimate the true variance in &lt;code&gt;\(\hat\beta\)&lt;/code&gt;.
Indeed, the box plots below show that Aronow et al.&amp;lsquo;s estimator is less biased than the homoskedastic and White estimators, and gets more accurate as the number of individuals &lt;code&gt;\(n\)&lt;/code&gt; grows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Aronow et al.&amp;lsquo;s estimator can also be applied to generalized linear models.
For example, suppose
&lt;code&gt;$$y_{ij}=\begin{cases} 1 &amp;amp; \text{if nodes}\ i\ \text{and}\ j\ \text{are adjacent} \\ 0 &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
is an indicator for the event in which nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\)&lt;/code&gt; are adjacent in a network.
We can model the link formation process as
&lt;code&gt;$$\Pr(y_{ij}=1)=\Lambda^{-1}(x_{ij}\beta+\epsilon_{ij}),$$&lt;/code&gt;
where &lt;code&gt;\(\Lambda(x)\equiv\log(x/(1-x))\)&lt;/code&gt; is the logit link function.
The &lt;a href=&#34;https://en.wikipedia.org/wiki/Logistic_regression&#34;&gt;logistic regression&lt;/a&gt; estimate &lt;code&gt;\(\hat\beta\)&lt;/code&gt; of &lt;code&gt;\(\beta\)&lt;/code&gt; reveals how the observable characteristics &lt;code&gt;\(x_{ij}\)&lt;/code&gt; of nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\)&lt;/code&gt; determine their probability of being adjacent.
We can estimate the variance of &lt;code&gt;\(\hat\beta\)&lt;/code&gt; consistently by letting &lt;code&gt;\(\hat{P}_{ij}=\Lambda^{-1}(x_{ij}\hat\beta)\)&lt;/code&gt; be the predicted probability for pair &lt;code&gt;\(\{i,j\}\)&lt;/code&gt;, replacing the bread matrix &lt;code&gt;\(B=(X^T\!X)^{-1}\)&lt;/code&gt; with
&lt;code&gt;$$\hat{B}=\left(X^T\mathrm{diag}\left(\hat{P}_{ij}\left(1-\hat{P}_{ij}\right)\right)X\right)^{-1},$$&lt;/code&gt;
and computing &lt;code&gt;\(\hat{B}\hat{M}_{\text{Aronow}}\hat{B}\)&lt;/code&gt;.
My co-authors and I use this approach in &amp;ldquo;&lt;a href=&#34;https://bldavies.com/blog/research-funding-collaboration&#34;&gt;Research Funding and Collaboration&lt;/a&gt;:&amp;rdquo; we estimate how grant proposal outcomes determine the probability with which pairs of researchers co-author, and we compare &lt;code&gt;\(\hat\sigma^2\hat{B}\)&lt;/code&gt; and &lt;code&gt;\(\hat{B}\hat{M}_{\text{Aronow}}\hat{B}\)&lt;/code&gt; to show that our inferences are robust to dyadic dependence.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1016/j.jdeveco.2006.05.005&#34;&gt;Fafchamps and Gubert (2007)&lt;/a&gt; describe a similar variance estimator to Aronow et al. but do not establish its consistency. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Assortative mixing</title>
      <link>https://bldavies.com/blog/assortative-mixing/</link>
      <pubDate>Tue, 02 Feb 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/assortative-mixing/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(N\)&lt;/code&gt; be a network with &lt;code&gt;\(n\)&lt;/code&gt; nodes, each of which has a &amp;ldquo;type&amp;rdquo; belonging to some set &lt;code&gt;\(T\)&lt;/code&gt;.
We say that &lt;code&gt;\(N\)&lt;/code&gt; is &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Assortative_mixing&#34;&gt;assortatively mixed&lt;/a&gt;&amp;rdquo; if nodes tend to have the same types as their neighbors.
For example, if &lt;code&gt;\(N\)&lt;/code&gt; is a social network and &lt;code&gt;\(T\)&lt;/code&gt; is a set of interests, then assortative mixing could arise because friends tend to share interests.&lt;/p&gt;
&lt;p&gt;How can we measure the extent of assortative mixing in &lt;code&gt;\(N\)&lt;/code&gt;?
&lt;a href=&#34;https://doi.org/10.1103/PhysRevE.67.026126&#34;&gt;Newman (2003)&lt;/a&gt; suggests the &amp;ldquo;assortativity coefficient&amp;rdquo;
&lt;code&gt;$$r=\frac{\sum_{t\in T}x_{tt}-\sum_{t\in T}y_t^2}{1-\sum_{t\in T}y_t^2},$$&lt;/code&gt;
where &lt;code&gt;\(x_{st}\)&lt;/code&gt; is the proportion of edges joining nodes of type &lt;code&gt;\(s\)&lt;/code&gt; to nodes of type &lt;code&gt;\(t\)&lt;/code&gt;, and where
&lt;code&gt;$$y_t=\sum_{s\in T}x_{st}$$&lt;/code&gt;
is the proportion of edges incident with nodes of type &lt;code&gt;\(t\)&lt;/code&gt;.
The coefficient &lt;code&gt;\(r\)&lt;/code&gt; varies between -1 and 1, and takes larger values when &lt;code&gt;\(N\)&lt;/code&gt; is more assortatively mixed.
We say that &lt;code&gt;\(N\)&lt;/code&gt; is &amp;ldquo;positively sorted&amp;rdquo; if &lt;code&gt;\(r&amp;gt;0\)&lt;/code&gt; and &amp;ldquo;negatively sorted&amp;rdquo; if &lt;code&gt;\(r&amp;lt;0\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can interpret &lt;code&gt;\(r\)&lt;/code&gt; by thinking about the &amp;ldquo;mixing matrix&amp;rdquo; &lt;code&gt;\(X=(x_{st})\)&lt;/code&gt;.
The numerator of &lt;code&gt;\(r\)&lt;/code&gt; equals the sum of diagonal entries of &lt;code&gt;\(X\)&lt;/code&gt; minus what that sum would be if the distributions of entries across rows and columns were independent.
The denominator of &lt;code&gt;\(r\)&lt;/code&gt; is a normalizing constant ensuring &lt;code&gt;\(\lvert r\rvert\le1\)&lt;/code&gt;.
Thus &lt;code&gt;\(r\)&lt;/code&gt; indexes the frequency of within-type edges in &lt;code&gt;\(N\)&lt;/code&gt; relative to the frequency we would expect in a random network with the same proportion of edges incident with each type.&lt;/p&gt;
&lt;p&gt;As an example, suppose &lt;code&gt;\(N\)&lt;/code&gt; is a realization of the &lt;a href=&#34;https://bldavies.com/blog/generating-random-graphs-communities/&#34;&gt;planted partition model&lt;/a&gt; with &lt;code&gt;\(n_1\)&lt;/code&gt; nodes of type 1, &lt;code&gt;\(n_2=n-n_1\)&lt;/code&gt; nodes of type 2, and some proportion
&lt;code&gt;$$p_{st}=\begin{cases} p &amp;amp; \text{if}\ s=t \\ q &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
of edges joining nodes of type &lt;code&gt;\(s\)&lt;/code&gt; to nodes of type &lt;code&gt;\(t\)&lt;/code&gt;.
Then &lt;code&gt;\(N\)&lt;/code&gt; has assortativity coefficient
&lt;code&gt;$$r=\frac{p^2(n_1-1)(n_2-1)-q^2n_1n_2}{p^2(n_1-1)(n_2-1)+pq(n_1(n_1-1)+n_2(n_2-1))+q^2n_1n_2},$$&lt;/code&gt;
which equals -1 if &lt;code&gt;\(p=0\)&lt;/code&gt; and &lt;code&gt;\(q&amp;gt;0\)&lt;/code&gt; (i.e., there are no within-type edges), and equals 1 if &lt;code&gt;\(p&amp;gt;0\)&lt;/code&gt; and &lt;code&gt;\(q=0\)&lt;/code&gt; (i.e., there are no between-type edges).
If &lt;code&gt;\(p=q\)&lt;/code&gt; then
&lt;code&gt;$$r=-\frac{1}{n-1},$$&lt;/code&gt;
which converges to zero from below as &lt;code&gt;\(n\)&lt;/code&gt; becomes large.
Intuitively, if &lt;code&gt;\(p=q\)&lt;/code&gt; then within-type and between-type edges occur at the same rate, but the network is slightly negatively sorted because there are slightly fewer potential within-type edges than potential between-type edges.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;\(n_1=n_2\)&lt;/code&gt; then
&lt;code&gt;$$r=\frac{p^2(n-2)-q^2n}{p^2(n-2)+q^2n},$$&lt;/code&gt;
which converges to &lt;code&gt;\((p^2-q^2)/(p^2+q^2)\)&lt;/code&gt; as &lt;code&gt;\(n\)&lt;/code&gt; becomes large.
The figure below demonstrates this case with &lt;code&gt;\(n_1=n_2=25\)&lt;/code&gt;.
The network on the left has edge frequencies &lt;code&gt;\((p,q)=(0.15,0.02)\)&lt;/code&gt; and assortativity coefficient &lt;code&gt;\(r=0.75\)&lt;/code&gt;; the network on the right has edge frequencies &lt;code&gt;\((p,q)=(0.02,0.15)\)&lt;/code&gt; and assortativity coefficient &lt;code&gt;\(r=-0.79\)&lt;/code&gt;.
Both networks are drawn so that adjacent nodes are closer together.
Nodes in the positively sorted network tend to have neighbors with the same type, while nodes in the negatively sorted network tend to have neighbors with a different type.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The assortativity coefficient &lt;code&gt;\(r\)&lt;/code&gt; can be used when &lt;code&gt;\(T\)&lt;/code&gt; is a set of categorical types.
In contrast, if &lt;code&gt;\(T\)&lt;/code&gt; is set of scalar quantities then we can measure the extent of assortative mixing via the Pearson correlation coefficient
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \DeclareMathOperator{\Var}{Var} \DeclareMathOperator{\Cov}{Cov} \rho=\frac{\Cov(t_i,t_j)}{\sqrt{\Var(t_i)\Var(t_j)}},$$&lt;/code&gt;
where &lt;code&gt;\(t_i\in T\)&lt;/code&gt; and &lt;code&gt;\(t_j\in T\)&lt;/code&gt; are the &amp;ldquo;types&amp;rdquo; of nodes &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(j\)&lt;/code&gt;, and where (co)variances are computed with respect to the frequency at which nodes of type &lt;code&gt;\(t_i\)&lt;/code&gt; and &lt;code&gt;\(t_j\)&lt;/code&gt; are adjacent in the network.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
To see how this works, let &lt;code&gt;\(A=(a_{ij})\)&lt;/code&gt; be the &lt;code&gt;\(n\times n\)&lt;/code&gt; adjacency matrix for &lt;code&gt;\(N\)&lt;/code&gt; and let &lt;code&gt;\(W=(w_{ij})\)&lt;/code&gt; be the &lt;code&gt;\(n\times n\)&lt;/code&gt; &amp;ldquo;weighting matrix&amp;rdquo; with entries
&lt;code&gt;$$w_{ij}=\frac{a_{ij}}{\lvert\rvert A\rvert\rvert},$$&lt;/code&gt;
where &lt;code&gt;\(\lvert\rvert A\rvert\rvert\)&lt;/code&gt; denotes the sum of elements in &lt;code&gt;\(A\)&lt;/code&gt;.
Then the vector &lt;code&gt;\(t=(t_1,t_2,\ldots,t_n)\)&lt;/code&gt; of node types has mean
&lt;code&gt;$$\E[t]=s^Tt,$$&lt;/code&gt;
where &lt;code&gt;\(s=(s_1,s_2,\ldots,s_n)\)&lt;/code&gt; is the vector of row sums
&lt;code&gt;$$s_i=\sum_{j=1}^nw_{ij}.$$&lt;/code&gt;
Intuitively, &lt;code&gt;\(s\)&lt;/code&gt; describes the probability mass function for the (marginal) distribution of node types.
Treating &lt;code&gt;\(t_i\)&lt;/code&gt; and &lt;code&gt;\(t_j\)&lt;/code&gt; as draws from this distribution, we have
&lt;code&gt;$$\begin{align*} \Cov(t_i,t_j) &amp;amp;= \E[t_it_j]-\E[t_i]\E[t_j] \\ &amp;amp;= \sum_{i=1}^n\sum_{j=1}^nw_{ij}t_it_j-(s^Tt)(s^Tt) \\ &amp;amp;= t^TWt-(s^Tt)^2 \end{align*}$$&lt;/code&gt;
and similarly
&lt;code&gt;$$\begin{align*} \Var(t_i) &amp;amp;= \E[t_i^2]-\E[t_i]^2 \\ &amp;amp;= \sum_{i=1}^ns_it_i^2-(s^Tt)^2 \\ &amp;amp;= t^TSt-(s^Tt)^2, \end{align*}$$&lt;/code&gt;
where &lt;code&gt;\(S\)&lt;/code&gt; is the &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix with principal diagonal equal to &lt;code&gt;\(s\)&lt;/code&gt; and off-diagonal entries equal to zero.
Then
&lt;code&gt;$$\rho=\frac{t^TWt-(s^Tt)^2}{t^TSt-(s^Tt)^2}.$$&lt;/code&gt;
For example, if the nodes in &lt;code&gt;\(N\)&lt;/code&gt; are arranged such that
&lt;code&gt;$$a_{ij}=\begin{cases}1 &amp;amp; \text{if}\ t_i=t_j \\ 0 &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
then
&lt;code&gt;$$\begin{align*} t^TWt &amp;amp;= \sum_{i=1}^n\sum_{j=1}^nw_{ij}t_it_j \\ &amp;amp;= \sum_{i=1}^nt_i^2\sum_{j=1}^nw_{ij} \\ &amp;amp;= \sum_{i=1}^nt_i^2s_i \\ &amp;amp;= t^TSt \end{align*}$$&lt;/code&gt;
and so &lt;code&gt;\(\rho=1\)&lt;/code&gt;&amp;mdash;that is, if all adjacent nodes have the same scalar type then the coefficient &lt;code&gt;\(\rho\)&lt;/code&gt; obtains its maximum value of unity.&lt;/p&gt;
&lt;p&gt;One common use of the correlation coefficient &lt;code&gt;\(\rho\)&lt;/code&gt; is to measure assortativity with respect to nodes&amp;rsquo; degrees (see, e.g., &lt;a href=&#34;https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.89.208701&#34;&gt;Newman, 2002&lt;/a&gt;).
For example, the left-hand network in the figure above has &lt;code&gt;\(\rho=0.03\)&lt;/code&gt;: although nodes are sorted strongly by color, they are approximately unsorted by degree because the planted partition model from which the network is generated has no mechanism for connecting high-degree nodes.
Performing a &lt;a href=&#34;https://bldavies.com/blog/degree-preserving-randomisation/&#34;&gt;degree-preserving randomization&lt;/a&gt; of the network changes its assortativity with respect to nodes&amp;rsquo; degrees by changing the joint distribution of those degrees across node pairs:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/dpr-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Numerical experimentation suggests &lt;code&gt;\(r=\rho\)&lt;/code&gt; whenever &lt;code&gt;\(\lvert T\rvert=2\)&lt;/code&gt;, which I prove &lt;a href=&#34;https://bldavies.com/blog/assortativity-correlation-coefficients/&#34;&gt;here&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Ordinary and total least squares</title>
      <link>https://bldavies.com/blog/ordinary-total-least-squares/</link>
      <pubDate>Mon, 11 Jan 2021 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/ordinary-total-least-squares/</guid>
      <description>&lt;p&gt;Suppose &lt;code&gt;\(X\)&lt;/code&gt; and &lt;code&gt;\(Y\)&lt;/code&gt; are random variables with
&lt;code&gt;$$\DeclareMathOperator{\E}{E} \DeclareMathOperator{\Cov}{Cov} \DeclareMathOperator{\Var}{Var} \newcommand{\abs}[1]{\lvert#1\rvert} Y=\beta X+u,$$&lt;/code&gt;
where &lt;code&gt;\(u\)&lt;/code&gt; has zero mean and zero correlation with &lt;code&gt;\(X\)&lt;/code&gt;.
The coefficient &lt;code&gt;\(\beta\)&lt;/code&gt; can be estimated by collecting data &lt;code&gt;\((Y_i,X_i)_{i=1}^n\)&lt;/code&gt; and regressing the &lt;code&gt;\(Y_i\)&lt;/code&gt; on the &lt;code&gt;\(X_i\)&lt;/code&gt;.
Now suppose our data collection procedure is flawed: instead of observing &lt;code&gt;\(X_i\)&lt;/code&gt;, we observe &lt;code&gt;\(Z_i=X_i+v_i\)&lt;/code&gt;, where the &lt;code&gt;\(v_i\)&lt;/code&gt; are iid with zero mean and zero correlation with the &lt;code&gt;\(X_i\)&lt;/code&gt;.
Then the ordinary least squares (OLS) estimate &lt;code&gt;\(\hat\beta_{\text{OLS}}\)&lt;/code&gt; of &lt;code&gt;\(\beta\)&lt;/code&gt; obtained by regressing the &lt;code&gt;\(Y_i\)&lt;/code&gt; on the &lt;code&gt;\(Z_i\)&lt;/code&gt; suffers from &lt;a href=&#34;https://en.wikipedia.org/wiki/Regression_dilution&#34;&gt;attenuation bias&lt;/a&gt;:
&lt;code&gt;$$\begin{align*} \DeclareMathOperator*{\plim}{plim} \plim_{n\to\infty}\hat\beta_{\text{OLS}} &amp;amp;=\frac{\Cov(Y,Z)}{\Var(Z)} \\ &amp;amp;=\frac{\Cov(\beta X+u,X+v)}{\Var(X+v)} \\ &amp;amp;= \frac{\beta\Var(X)}{\Var(X)+\Var(v)} \\ &amp;amp;= \frac{\beta}{1+\Var(v)/\Var(X)} \end{align*}$$&lt;/code&gt;
and so &lt;code&gt;\(\abs{\hat\beta_{\text{OLS}}}&amp;lt;\abs{\beta}\)&lt;/code&gt; asympotically whenever &lt;code&gt;\(\Var(v)&amp;gt;0\)&lt;/code&gt;.
Intuitively, the measurement errors &lt;code&gt;\(v_i\)&lt;/code&gt; spread out the independent variable, flattening the fitted regression line.&lt;/p&gt;
&lt;p&gt;One way to reduce attenuation bias is to replace OLS with total least squares (TLS), which accounts for noise in the dependent &lt;em&gt;and&lt;/em&gt; independent variables.
As a demonstration, the chart below compares the OLS and TLS lines of best fit through some randomly generated data &lt;code&gt;\((Y_i,Z_i)_{i=1}^n\)&lt;/code&gt; with &lt;code&gt;\(\beta=1\)&lt;/code&gt;.
The OLS estimate &lt;code&gt;\(\hat\beta_{\text{OLS}}=0.43\)&lt;/code&gt; minimizes the sum of squared &lt;em&gt;vertical&lt;/em&gt; deviations of the data from the fitted line.
In contrast, the TLS estimate &lt;code&gt;\(\hat\beta_{\text{TLS}}=0.95\)&lt;/code&gt; minimizes the sum of squared &lt;em&gt;perpendicular&lt;/em&gt; deviations of the data from the fitted line.
For these data, the TLS estimate is unbiased because &lt;code&gt;\(u\)&lt;/code&gt; and &lt;code&gt;\(v\)&lt;/code&gt; have the same variance.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;However, if &lt;code&gt;\(u\)&lt;/code&gt; and &lt;code&gt;\(v\)&lt;/code&gt; have different variances then the TLS estimate of &lt;code&gt;\(\beta\)&lt;/code&gt; is biased.
I demonstrate this phenomenon in the chart below, which compares the OLS and TLS estimates of &lt;code&gt;\(\beta=1\)&lt;/code&gt; for varying &lt;code&gt;\(\Var(u)\)&lt;/code&gt; and &lt;code&gt;\(\Var(v)\)&lt;/code&gt; when &lt;code&gt;\(X\)&lt;/code&gt; is standard normal.
I plot the bias &lt;code&gt;\(\E[\hat\beta-\beta]\)&lt;/code&gt; and mean squared error &lt;code&gt;\(\E[(\hat\beta-\beta)^2]\)&lt;/code&gt; of each estimate &lt;code&gt;\(\hat\beta\in\{\hat\beta_{\text{OLS}},\hat\beta_{\text{TLS}}\}\)&lt;/code&gt;, obtained by simulating the data-generating process 100 times for each &lt;code&gt;\((\Var(u),\Var(v))\)&lt;/code&gt; pair.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/comparison-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;\(\Var(u)&amp;gt;\Var(v)\)&lt;/code&gt; then the TLS estimate &lt;code&gt;\(\hat\beta_{\text{TLS}}\)&lt;/code&gt; is biased upward because the data are relatively stretched vertically; if &lt;code&gt;\(\Var(u)&amp;lt;\Var(v)\)&lt;/code&gt; then &lt;code&gt;\(\hat\beta_{\text{TLS}}\)&lt;/code&gt; is biased downward because the data are relatively stretched horizontally.
The OLS estimate is biased downward whenever &lt;code&gt;\(\Var(u)&amp;gt;0\)&lt;/code&gt; due to attenuation.
The TLS estimate is less biased and has smaller mean squared error than the OLS estimate when &lt;code&gt;\(\Var(u)&amp;lt;\Var(v)\)&lt;/code&gt;, suggesting that TLS generates &amp;ldquo;better&amp;rdquo; estimates than OLS when the measurement errors &lt;code&gt;\(v_i\)&lt;/code&gt; are relatively large.&lt;/p&gt;
&lt;p&gt;One problem with TLS estimates is that they depend on the units in which variables are measured.
For example, suppose &lt;code&gt;\(Y_i\)&lt;/code&gt; is person &lt;code&gt;\(i\)&lt;/code&gt;&#39;s weight and &lt;code&gt;\(Z_i\)&lt;/code&gt; is their height.
If I measure &lt;code&gt;\(Y_i\)&lt;/code&gt; in pounds, generate a TLS estimate &lt;code&gt;\(\hat\beta_{\text{TLS}}\)&lt;/code&gt;, use this estimate to predict the weight in pounds of someone six feet tall, and then convert my prediction to kilograms, I get a different result than if I had measured &lt;code&gt;\(Y_i\)&lt;/code&gt; in kilograms initially.
This unit-dependence arises because rescaling the dependent variable affects each perpendicular deviation differently.&lt;/p&gt;
&lt;p&gt;In contrast, OLS-based predictions do not depend on the units in which I measure &lt;code&gt;\(Y_i\)&lt;/code&gt;.
Rescaling the dependent variable multiplies each vertical deviation by the same constant, leaving the squared deviation-minimizing coefficient unchanged.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Auctioning vaccines</title>
      <link>https://bldavies.com/blog/auctioning-vaccines/</link>
      <pubDate>Thu, 17 Dec 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/auctioning-vaccines/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3746231&#34;&gt;Pancs (2020)&lt;/a&gt; proposes an auction for vaccines in which people can bid on others&amp;rsquo; behalf.
This format allows people to internalize the externalities they enjoy from their peers being vaccinated.&lt;/p&gt;
&lt;p&gt;For example, suppose there are two vaccines to be allocated among agents A&amp;ndash;H, who are connected socially via the network shown below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/network-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Everyone submits bids totaling $60, spread evenly among themselves and their peers.
For example, agent A bids $30 towards vaccinating themself and agent B, while agent B bids $15 towards vaccinating themself and agents A, C, and D.
Intuitively, agent A values vaccinating B highly because it protects A fully from viruses transmitted among agents C&amp;ndash;H.
In contrast, B has more peers and so values vaccinating any one of those peers less because it doesn&amp;rsquo;t protect B fully from the rest of the network.&lt;/p&gt;
&lt;p&gt;The &amp;ldquo;aggregate bid&amp;rdquo; for each agent equals the sum of bids submitted towards that agent&amp;rsquo;s vaccination.
The agents with the highest aggregate bids receive the vaccines.
In this example, agents B and F receive the vaccine, with aggregate bids equal to $94 and $87.&lt;/p&gt;
&lt;p&gt;Each agent receives surplus equal to their subjective valuation of the vaccine allocation minus their payment towards that allocation&amp;rsquo;s provision.
This payment equals the increase in aggregate surplus that other agents would receive if the agent&amp;rsquo;s bids were ignored.
Thus, the vaccine auction is a type of &lt;a href=&#34;https://en.wikipedia.org/wiki/Vickrey%E2%80%93Clarke%E2%80%93Groves_auction&#34;&gt;Vickrey-Clarke-Groves (VCG) auction&lt;/a&gt; in which each agent pays the harm they inflict on other agents.
Consequently, the vaccine auction inherits the properties of VCG auctions; in particular, bids equal subjective valuations.
This property makes it easy to compute pre-payment surpluses: simply sum each agent&amp;rsquo;s bids towards vaccinated agents.&lt;/p&gt;
&lt;p&gt;The table below presents the aggregate bid for, payment made by, and surplus delivered to each agent under the optimal vaccine allocation.
Agents B and F don&amp;rsquo;t have to pay for the vaccines they receive because others are willing to pay on their behalf.
Agent A pays $15 because their bid towards vaccinating B shifts the optimal allocation away from E, which lowers F&amp;rsquo;s surplus by $15.
Likewise, agents G and H pay because their preference to vaccinate F, rather than E, makes B&amp;ndash;D worse off.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Agent&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Aggregate bid ($)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Payment ($)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Surplus ($)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;A&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;42&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;15&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;B&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;94&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;C&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;44&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;D&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;44&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;E&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;79&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;F&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;87&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;G&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;45&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;22&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;H&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;45&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;22&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This example departs from reality in two important ways.
First, I assume each agent&amp;rsquo;s bids sum to a constant ($60).
This assumption is obviously unrealistic: wealth inequality means some people can afford to submit higher bids than others, which may lead to inequitible vaccine allocations.
Moreover, people may vary in their willingness to pay for vaccines independently of the variation in their wealths.&lt;/p&gt;
&lt;p&gt;Second, I assume every agent wants to be vaccinated.
This common desire may not hold in reality: some people may prefer not to be vaccinated because they fear potential side-effects.
Such people may refuse to participate in the auction, reducing social welfare by preventing some externalities from being internalized.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Gift exchange mechanisms</title>
      <link>https://bldavies.com/blog/gift-exchange-mechanisms/</link>
      <pubDate>Sun, 13 Dec 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/gift-exchange-mechanisms/</guid>
      <description>&lt;p&gt;Last December &lt;a href=&#34;https://bldavies.com/blog/white-elephant-gift-exchanges/&#34;&gt;I compared strategies for playing white elephant&lt;/a&gt;, a game in which people take turns either unwrapping a gift or stealing a previously unwrapped gift.
It turned out that players&amp;rsquo; best strategy was to be &amp;ldquo;greedy&amp;rdquo; by stealing the most subjectively valuable unwrapped gift.
Intuitively, this strategy helps players obtain the gift they want most, provided no other players also want that gift and steal it later in the game.&lt;/p&gt;
&lt;p&gt;White elephant exchanges are a fun, but not necessarily optimal, way to match people with gifts.
Another way is to use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Top_trading_cycle&#34;&gt;top trading cycle&lt;/a&gt; (TTC) algorithm:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Give everyone a random unwrapped gift.&lt;/li&gt;
&lt;li&gt;Ask everyone to point at the most subjectively valuable gift (which may be their own).&lt;/li&gt;
&lt;li&gt;If there is a closed cycle of people pointing at each others&amp;rsquo; gifts, give everyone in that cycle the gift at which they&amp;rsquo;re pointing, and remove those people and gifts from consideration.&lt;/li&gt;
&lt;li&gt;If there are no gifts remaining then stop. Otherwise, return to step 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The allocation delivered by this algorithm has several desirable properties.
First, it is &lt;a href=&#34;https://en.wikipedia.org/wiki/Pareto_efficiency&#34;&gt;Pareto efficient&lt;/a&gt;: every cycle identifies a mutually beneficial exchange, and the algorithm stops when no such exchanges remain.
Second, it is &lt;a href=&#34;https://en.wikipedia.org/wiki/Strategyproofness&#34;&gt;strategy-proof&lt;/a&gt;: people cannot get better gifts by lying about their preferences (see &lt;a href=&#34;https://doi.org/10.1016/0165-1765%2882%2990003-9&#34;&gt;Roth, 1982&lt;/a&gt;).
Third, it is &lt;a href=&#34;https://en.wikipedia.org/wiki/Core_%28game_theory%29&#34;&gt;core-stable&lt;/a&gt;: no group of people can cooperate to improve their allocations, for otherwise they would have formed a cycle before the algorithm stopped.&lt;/p&gt;
&lt;p&gt;However, the TTC algorithm may not deliver the allocation that maximizes the sum of gifts&amp;rsquo; subjective values.
This allocation corresponds to a &lt;a href=&#34;https://en.wikipedia.org/wiki/Maximum_weight_matching&#34;&gt;maximum-weight matching&lt;/a&gt; in the bipartite graph connecting people to gifts, with each edge&amp;rsquo;s weight equal to the incident player&amp;rsquo;s subjective value of the incident gift.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;The chart below compares the mean subjective value of the gifts allocated using a game of white elephant, using the TTC algorithm, and by finding a maximum-weight matching.
I compute these allocations as follows.
First, I define person &lt;code&gt;\(i\)&lt;/code&gt;&#39;s subjective value of gift &lt;code&gt;\(j\)&lt;/code&gt; as
&lt;code&gt;$$V_{ij}=\rho X_j+(1-\rho)Y_{ij},$$&lt;/code&gt;
where &lt;code&gt;\(X_i\)&lt;/code&gt; and &lt;code&gt;\(Y_{ij}\)&lt;/code&gt; are iid uniformly distributed on the unit interval.
The parameter &lt;code&gt;\(\rho\)&lt;/code&gt; determines the correlation of gifts&amp;rsquo; subjective values across people: if &lt;code&gt;\(\rho=0\)&lt;/code&gt; then everyone&amp;rsquo;s valuations are independent, whereas if &lt;code&gt;\(\rho=1\)&lt;/code&gt; then everyone has the same valuation of each gift.
For a range of &lt;code&gt;\(\rho\)&lt;/code&gt; values, I simulate 100 valuation sets &lt;code&gt;\(\{V_{ij}:i,j\in\{1,2,\ldots,30\}\}\)&lt;/code&gt;, and apply each gift exchange mechanism to each set.
In the white elephant games, I assume all players adopt the greedy strategy described above unless the best unwrapped gift has subjective value less than &lt;code&gt;\(\mathrm{E}[V_{ij}]=0.5\)&lt;/code&gt;, in which case players unwrap a new gift.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/means-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;All three gift exchange mechanisms get worse as gifts&amp;rsquo; subjective values become more correlated.
Intuitively, as the correlation increases, there are fewer Pareto-improving trades and so people get stuck with their random endowments.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
The allocations delivered via white elephant games and the TTC algorithm have similar allocative efficiencies, even though white elephant players can&amp;rsquo;t assign subjective values to gifts until they are unwrapped.&lt;/p&gt;
&lt;p&gt;Yet white elephant games are much more popular at Christmas parties than the TTC algorithm.
One explanation could be that the algorithm tends to reveal a lot of information about peoples&amp;rsquo; preferences and, in particular, may make people more upset about contributing a gift no-one wants.
I justify this claim in the following chart, which plots the number of times someone rejects each gift for another in my simulated exchanges.
For example, I add one to gift A&amp;rsquo;s rejection count if&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a white elephant player could steal gift A but instead steals gift B, or&lt;/li&gt;
&lt;li&gt;I&amp;rsquo;m running the TTC algorithm and someone could point at gift A but instead points at gift B.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Intuitively, these rejection events reveal that gift A has subjectively lower value than other gifts, and the more often this happens the more likely is the person who contributed gift A to feel bad about their contribution.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/rejections-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Most Christmas parties set a target amount to be spent on each gift, so&amp;mdash;to the extent that cost correlates positively with value&amp;mdash;the empirically relevant region of the chart is where the correlation of subjective values is high.
In this region, running the TTC algorithm tends to generate many more rejection events than running a game of white elephant.
Intuitively, if the correlation of subjective values is high then people will tend to all point at the same gifts, there will be fewer cycles, more iterations will be required before the TTC algorithm stops, and hence the algorithm will force people to reveal more about their preferences as the market slowly clears.
On the other hand, the unobservability of wrapped gifts&amp;rsquo; subjective values means that white elephant players have fewer opportunities to reveal their preferences, regardless of whether those preferences are shared by other players.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&#34;https://adhami.people.stanford.edu&#34;&gt;Mohamad Adhami&lt;/a&gt;, &lt;a href=&#34;https://nickcao.com/&#34;&gt;Nick Cao&lt;/a&gt;, and &lt;a href=&#34;https://www.spantoja.com&#34;&gt;Spencer Pantoja&lt;/a&gt; for commenting on a draft version of this post.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The maximum-weight matching is hard to find in practice because it requires complete information about peoples&amp;rsquo; preferences. In contrast, white elephant games and the TTC algorithm elicit peoples&amp;rsquo; preferences by asking them to choose explicitly which gifts they want. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;In white elephant games, the randomness comes from the order in which people take their turns choosing whether to unwrap or steal. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Aggregating preferences: Bird of the Year edition</title>
      <link>https://bldavies.com/blog/aggregating-preferences-bird-year-edition/</link>
      <pubDate>Sun, 29 Nov 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/aggregating-preferences-bird-year-edition/</guid>
      <description>&lt;p&gt;Earlier this month the &lt;a href=&#34;https://www.birdoftheyear.org.nz/kakapo&#34;&gt;kākāpō&lt;/a&gt; was elected &lt;a href=&#34;https://www.birdoftheyear.org.nz&#34;&gt;Bird of the Year&lt;/a&gt; for 2020.
The news prompted me to review the results of &lt;a href=&#34;https://bldavies.com/blog/birds-voting-russian-interference/&#34;&gt;last year&amp;rsquo;s election&lt;/a&gt;, in which the kākāpō lost narrowly to the yellow-eyed penguin.
In particular, I wanted to determine whether the 2019 results were sensitive to the method used to aggregate voters&amp;rsquo; preferences.
This post summarises my findings: different methods deliver (slightly) different outcomes, and at least one method would have crowned the kākāpō.&lt;/p&gt;
&lt;p&gt;Bird of the Year elections run as follows.
Each voter selects up to five birds, ranks their selections in order of preference, and submits their ranking on the election website.
These submissions determine the winning bird via the &lt;a href=&#34;https://en.wikipedia.org/wiki/Instant-runoff_voting&#34;&gt;instant-runoff&lt;/a&gt; (IR) method:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Count the ballots on which each bird is ranked first.&lt;/li&gt;
&lt;li&gt;If one bird is ranked first on a majority of ballots then elect it.
Otherwise, eliminate the bird ranked first on the fewest ballots and return to step 1.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Using the IR method, rather than a &lt;a href=&#34;https://en.wikipedia.org/wiki/Plurality_voting&#34;&gt;plurality vote&lt;/a&gt; (in which the bird listed first on the most ballots wins), mitigates &lt;a href=&#34;https://en.wikipedia.org/wiki/Vote_splitting&#34;&gt;vote-splitting&lt;/a&gt; because voters can list multiple birds on their ballots.
However, the IR method violates the &lt;a href=&#34;https://en.wikipedia.org/wiki/Condorcet_criterion&#34;&gt;Condorcet criterion&lt;/a&gt;: a bird may lose the election even if it would beat every other bird in a head-to-head plurality vote.
One way to satisfy this criterion is to use &lt;a href=&#34;https://en.wikipedia.org/wiki/Copeland%27s_method&#34;&gt;Copeland&amp;rsquo;s method&lt;/a&gt;, which ranks birds by the number of pairwise plurality votes they win minus the number of such votes they lose.&lt;/p&gt;
&lt;p&gt;The IR method and Copeland&amp;rsquo;s method both rely on noiseless within-ballot rankings.
I suspect this property does not hold for Bird of the Year elections.
After selecting up to five birds, voters are asked to rearrange their selections from most to least preferred before submitting their ballots.
It seems likely that this rearrangement does not occur, either because voters can&amp;rsquo;t be bothered or because they are approximately indifferent among their selections.
In either case, voters&amp;rsquo; preferences might be better aggregated using an &lt;a href=&#34;https://en.wikipedia.org/wiki/Approval_voting&#34;&gt;approval&lt;/a&gt;-based system: each bird earns one point for each ballot appearance, and the bird with the most points wins.&lt;/p&gt;
&lt;p&gt;One obvious problem with the approval-based system is that voters may approve of more than five birds, but cannot signal such approval because the &amp;ldquo;up to five&amp;rdquo; constraint binds.
On the other hand, some voters may feel obliged to list five birds on their ballots even if they approve of only four birds or fewer.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
The most defensible way to deal with these possibilities seems (to me) to be to use a plurality vote, which assumes the minimal completeness of voters&amp;rsquo; individual preferences by treating only their first choices as informative.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;The table below presents the top-placing birds in the 2019 election using the IR method, and those birds&amp;rsquo; places under the other preference aggregation methods described above.
The kākāpō was actually the Condorcet winner; it would have beaten every other bird in a head-to-head plurality vote.
Nevertheless the IR method crowned the yellow-eyed penguin, as would have the approval-based system and a simple plurality vote.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Bird&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;IR place&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Copeland place&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Approval place&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Plurality place&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Yellow-eyed penguin&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Kākāpō&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Black Robin&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Banded Dotterel&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Fantail&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;12&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;New Zealand Falcon&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Kererū&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Blue Duck&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Kea&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Kākā&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The figure below compares all candidate birds&amp;rsquo; places using the IR method to their places obtained using the alternative methods.
The IR method delivers results most similar to a plurality vote and least similar to Copeland&amp;rsquo;s method, as shown by the relative deviations of points from the 45-degree line.
These patterns suggest that voters&amp;rsquo; second through fifth choices for Bird of the Year didn&amp;rsquo;t affect the 2019 election outcome materially.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/comparison-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Of the 43,460 ballots cast in last year&amp;rsquo;s election, 91.3% listed five birds, 1.4% listed four birds, 1.2% listed three birds, 0.8% listed two birds, and 5.2% listed one bird. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Nominating a &amp;ldquo;first choice&amp;rdquo; requires only that a voter can identify at least one bird that they prefer to at least one other bird. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Polarized beliefs in social networks</title>
      <link>https://bldavies.com/blog/polarized-beliefs-social-networks/</link>
      <pubDate>Thu, 29 Oct 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/polarized-beliefs-social-networks/</guid>
      <description>&lt;p&gt;Suppose 50 people each have four friends.
Everyone believes that some proposition&amp;mdash;say, &amp;ldquo;corporate tax rates should be higher&amp;rdquo;&amp;mdash;is either true or false, with equal probability and independently of everyone else.
Consequently, the social network among the 50 people is unsorted with respect to peoples&amp;rsquo; beliefs.
However, the network&amp;rsquo;s structure changes over time, in discrete time steps, according to two rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;everyone updates their belief to match the majority within their friend group (comprised of themselves and their neighbours in the network), defaulting to their previous belief to break ties;&lt;/li&gt;
&lt;li&gt;edges appear between people who hold the same belief and disappear between people who hold different beliefs, both with probability 0.01.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first rule describes a &amp;ldquo;social learning&amp;rdquo; process: people update their beliefs to match the majority among their friends.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
The second rule describes a &amp;ldquo;peer selection&amp;rdquo; process: people choose friends who share the same beliefs.
These two processes can lead to polarized beliefs, even if there is no polarization before the processes begin.
I demonstrate this phenomenon in the figure below, which plots the beliefs and connections in a simulated network after zero, 10, 20, and 30 time steps.
The figure shows how people grow increasingly connected to others with the same belief and decreasingly connected to others with the opposing belief.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/networks-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The social learning and peer selection processes can lead to polarization both together and separately.
I justify this claim in the figure below.
The left-hand panel plots the network&amp;rsquo;s &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortativity coefficient&lt;/a&gt;, which measures the overall correlation among friends&amp;rsquo; beliefs.
This coefficient equals one when all neighbours share the same beliefs (complete polarization) and equals zero when edges are &amp;ldquo;as random.&amp;rdquo;
The right-hand panel plots the proportion of people in the network who update their belief at each time step.
Both panels present means and 95% confidence intervals across 30 simulated networks, each with randomized initial beliefs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/network-attributes-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The social learning process leads to positive sorting because, by construction, people increasingly share the same beliefs as their friends.
The peer selection process leads to positive sorting because, by construction, edges increasingly connect people with common beliefs only.
The two processes work together to isolate the subnetworks of people who believe the proposition is true and false.
Interestingly, most belief updates occur very early: after about five time steps, most of the structural changes in the social network result from edge creations and deletions rather than from belief updates.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://bldavies.com/blog/degroot-learning-social-networks/&#34;&gt;my blog post on DeGroot learning&lt;/a&gt; for more discussion of social learning processes. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Estimating sensitive parameters</title>
      <link>https://bldavies.com/blog/estimating-sensitive-parameters/</link>
      <pubDate>Wed, 21 Oct 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/estimating-sensitive-parameters/</guid>
      <description>&lt;p&gt;Suppose some proportion &lt;code&gt;\(\theta\)&lt;/code&gt; of the population engages in a socially undesirable activity&amp;mdash;say, evading taxes.
We want to estimate &lt;code&gt;\(\theta\)&lt;/code&gt;, but can&amp;rsquo;t ask people directly because they may fear penalities from incriminating themselves.&lt;/p&gt;
&lt;p&gt;One solution to this problem is as follows.
Choose another characteristic that people don&amp;rsquo;t mind reporting and for which we know the population prevalence&amp;mdash;say, whether they are right-handed.
Let &lt;code&gt;\(\alpha\)&lt;/code&gt; be the (assumedly known) proportion of the population with this characteristic.
Sample &lt;code&gt;\(n\)&lt;/code&gt; people, and give them the following instructions:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Flip a fair coin, but &lt;em&gt;don&amp;rsquo;t tell me what you get&lt;/em&gt;.
If you get heads, answer the question &amp;ldquo;do you evade taxes?&amp;rdquo;
If you get tails, answer the question &amp;ldquo;are you right-handed?&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The coin toss outcome&amp;rsquo;s unobservability shields respondents&amp;rsquo; revelation of tax evasion&amp;mdash;they could be responding &amp;ldquo;Yes&amp;rdquo; to the question of whether they are right-handed.
This shield, hopefully, elicits truthful reporting.
Then, by the &lt;a href=&#34;https://en.wikipedia.org/wiki/Law_of_total_probability&#34;&gt;Law of Total Probability&lt;/a&gt;, the probability that someone responds &amp;ldquo;Yes&amp;rdquo; is
&lt;code&gt;$$p=\frac{\theta+\alpha}{2}.$$&lt;/code&gt;
Let &lt;code&gt;\(X\)&lt;/code&gt; be the number of people who respond &amp;ldquo;Yes.&amp;rdquo;
Then &lt;code&gt;\(X\)&lt;/code&gt; is Binomially distributed with &lt;code&gt;\(n\)&lt;/code&gt; trials and success rate &lt;code&gt;\(p\)&lt;/code&gt;, and so has mean &lt;code&gt;\(\mathrm{E}[X]=np\)&lt;/code&gt; and variance &lt;code&gt;\(\mathrm{Var}(X)=np(1-p)\)&lt;/code&gt;.
Consequently, the estimator
&lt;code&gt;$$\hat\theta_n=2\frac{X}{n}-\alpha$$&lt;/code&gt;
of &lt;code&gt;\(\theta\)&lt;/code&gt; has mean &lt;code&gt;\(\mathrm{E}[\hat\theta_n]=\theta\)&lt;/code&gt; and variance
&lt;code&gt;$$\begin{align*} \mathrm{Var}(\hat\theta_n) &amp;amp;= \frac{4}{n^2}\mathrm{Var}(X) \\ &amp;amp;= \frac{4p(1-p)}{n} \\ &amp;amp;\le \frac{1}{n} \end{align*}$$&lt;/code&gt;
since &lt;code&gt;\(4p(1-p)\le1\)&lt;/code&gt; for any &lt;code&gt;\(p\in[0,1]\)&lt;/code&gt;.
Thus, &lt;code&gt;\(\hat\theta_n\)&lt;/code&gt; is an unbiased estimator of &lt;code&gt;\(\theta\)&lt;/code&gt; and becomes more precise as the sample size &lt;code&gt;\(n\)&lt;/code&gt; grows.
We can quantify this precision using &lt;a href=&#34;https://en.wikipedia.org/wiki/Chebyshev%27s_inequality&#34;&gt;Chebyshev&amp;rsquo;s inequality&lt;/a&gt;: for any &lt;code&gt;\(\varepsilon&amp;gt;0\)&lt;/code&gt;, we have
&lt;code&gt;$$\Pr(\lvert\hat\theta_n-\theta\rvert\ge\varepsilon)\le\frac{\mathrm{Var}(\hat\theta_n)}{\varepsilon^2}$$&lt;/code&gt;
and therefore
&lt;code&gt;$$\Pr(\lvert\hat\theta_n-\theta\rvert&amp;lt;\varepsilon)\ge1-\frac{1}{n\varepsilon^2}.$$&lt;/code&gt;
Thus, for example, choosing &lt;code&gt;\(n\ge4000\)&lt;/code&gt; guarantees that &lt;code&gt;\(\hat\theta_n\)&lt;/code&gt; differs from &lt;code&gt;\(\theta\)&lt;/code&gt; by no more than &lt;code&gt;\(\varepsilon=0.05\)&lt;/code&gt; with probability 0.9.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Research funding and collaboration</title>
      <link>https://bldavies.com/blog/research-funding-collaboration/</link>
      <pubDate>Mon, 12 Oct 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/research-funding-collaboration/</guid>
      <description>&lt;p&gt;Research is increasingly conducted by teams.
Consequently, there is growing interest in the mechanisms underlying research team formation.
In &lt;a href=&#34;https://www.nber.org/papers/w27916&#34;&gt;a new NBER working paper&lt;/a&gt;, my co-authors and I explore one potential mechanism: participation in research funding contests.
Such contests may promote collaboration for several reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;They require proposal team members to invest resources in planning collaborative projects;&lt;/li&gt;
&lt;li&gt;They may help researchers screen for productive collaborators;&lt;/li&gt;
&lt;li&gt;If better ideas are more likely to win funding then success signals that researchers&amp;rsquo; shared ideas are worth pursuing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These arguments suggest that the members of more successful proposal teams are more likely to become co-authors.
We test this hypothesis empirically, using data from New Zealand.
Our data include Scopus publication records on New Zealand researchers and their international co-authors.
We link these records to data on applications to the &lt;a href=&#34;https://www.royalsociety.org.nz/what-we-do/funds-and-opportunities/marsden&#34;&gt;Marsden Fund&lt;/a&gt;, the premier source of funding for basic research in New Zealand.&lt;/p&gt;
&lt;p&gt;In our data, researchers with more successful Marsden Fund applications tended to have more co-authors.
However, this tendency may be driven by confounding factors, such as researchers&amp;rsquo; ability to generate publishable research.
We control for such factors by analysing co-authorship dynamics econometrically.
Specifically, we use &lt;a href=&#34;https://doi.org/10.1016/B978-0-12-811771-2.00008-0&#34;&gt;dyadic regression&lt;/a&gt; to estimate how the probability that pairs of researchers co-author in a given year varies with their observable characteristics.
Pairs were more likely to co-author in a given year if&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;they had co-authored with each other recently,&lt;/li&gt;
&lt;li&gt;they co-authored with others often,&lt;/li&gt;
&lt;li&gt;they published in similar fields,&lt;/li&gt;
&lt;li&gt;their prior publications attracted more citations, or&lt;/li&gt;
&lt;li&gt;their prior citation histories differed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The fifth bullet implies negative &lt;a href=&#34;https://bldavies.com/blog/assortative-mixing/&#34;&gt;assortative mixing&lt;/a&gt; among the researchers in our data, which we suspect arises due to inter-generational collaboration (e.g., professors working with graduate students and post-docs).&lt;/p&gt;
&lt;p&gt;On average, pairs were 13.8 percentage points more likely to co-author in a given year if they co-submitted Marsden Fund proposals during the previous ten years than if they did not.
This co-authorship rate was not significantly larger among pairs who received funding.
However, increasing the lag between our outcome and explanatory variables delivers the opposite result: funding receipt, rather than proposal submission, promotes co-authorship.
As discussed in &lt;a href=&#34;https://www.nber.org/papers/w27916&#34;&gt;our paper&lt;/a&gt;, these patterns suggest that the &amp;ldquo;treatment effect&amp;rdquo; of research funding contest participation on co-authorship is limited to successful participants only.&lt;/p&gt;
&lt;p&gt;Our analysis has both technical and policy implications.
On the technical side, we discuss some empirical problems that arise when analysing co-authorship networks, offer solutions to these problems, and discuss how these solutions affect our inferences.
On the policy side, we show how science funding schemes can influence how researchers choose collaborators, which may have long-term effects on how science and innovation systems evolve.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Relatedness, complexity and local growth redux</title>
      <link>https://bldavies.com/blog/relatedness-complexity-local-growth-redux/</link>
      <pubDate>Thu, 10 Sep 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/relatedness-complexity-local-growth-redux/</guid>
      <description>&lt;p&gt;&amp;ldquo;Relatedness, Complexity and Local Growth,&amp;rdquo; co-authored with &lt;a href=&#34;https://motu.nz/about-us/people/dave-mare/&#34;&gt;Dave Maré&lt;/a&gt; while I worked at &lt;a href=&#34;https://motu.nz&#34;&gt;Motu&lt;/a&gt;, has undergone peer review.
A revised version was &lt;a href=&#34;https://doi.org/10.1080/00343404.2020.1802418&#34;&gt;published online&lt;/a&gt; today and will appear in a future issue of &lt;em&gt;Regional Studies&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Dave and I present a measure of the relatedness between economic activities that is more robust to noisy employment data than measures used in previous studies (e.g., &lt;a href=&#34;https://doi.org/10.1080/00343404.2018.1437900&#34;&gt;Balland et al., 2019&lt;/a&gt;; &lt;a href=&#34;https://doi.org/10.1126/science.1144581&#34;&gt;Hidalgo et al., 2007&lt;/a&gt;; &lt;a href=&#34;http://econ.geo.uu.nl/peeg/peeg1931.pdf&#34;&gt;Rigby et al., 2019&lt;/a&gt;).
We demonstrate this robustness using historical census data from New Zealand.
We also demonstrate that relatedness patterns do not significantly influence the employment dynamics described by those data.&lt;/p&gt;
&lt;p&gt;Our analysis suggests that the &lt;a href=&#34;https://doi.org/10.1007/978-3-319-96661-8_46&#34;&gt;principle of relatedness&lt;/a&gt; applies in large geographic areas only.
In our New Zealand data, the &lt;a href=&#34;https://en.wikipedia.org/wiki/Economies_of_agglomeration&#34;&gt;benefits of proximity&lt;/a&gt; are more apparent in larger cities, where workers engaged in related activities interact more frequently.
Our paper highlights some of the challenges with operationalising place-based regional growth and innovation policies, such as the &lt;a href=&#34;https://s3platform.jrc.ec.europa.eu/what-is-smart-specialisation-&#34;&gt;&amp;ldquo;smart specialisation&amp;rdquo; policies&lt;/a&gt; adopted in the European Union.&lt;/p&gt;
&lt;p&gt;Read &lt;a href=&#34;https://doi.org/10.1080/00343404.2020.1802418&#34;&gt;the published article&lt;/a&gt; (available under Open Access) for more details.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>COVID-19, lockdown and two-sided uncertainty</title>
      <link>https://bldavies.com/blog/covid-19-lockdown-two-sided-uncertainty/</link>
      <pubDate>Fri, 21 Aug 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/covid-19-lockdown-two-sided-uncertainty/</guid>
      <description>&lt;p&gt;When the COVID-19 pandemic began, the New Zealand government faced uncertainty around the virus&amp;rsquo; health and economic consequences.
Amid this uncertainty, the government had two choices: enter lockdown immediately or delay its decision.
Delaying preserved the option to enter lockdown if its necessity became clearer.
However, a delayed lockdown would be less effective if many people caught the virus while the government waited for clarifying information.&lt;/p&gt;
&lt;p&gt;We know now that the government chose to enter lockdown early.
Was this the best choice given information available at the time?
To help answer this question, &lt;a href=&#34;https://motu.nz/about-us/people/arthur-grimes/&#34;&gt;Arthur Grimes&lt;/a&gt; and I analyse the government&amp;rsquo;s decision in &lt;a href=&#34;https://doi.org/10.1080/00779954.2020.1806340&#34;&gt;an article&lt;/a&gt; published last week in the &lt;em&gt;New Zealand Economic Papers&lt;/em&gt;.
Our analysis formalises, and builds on, ideas discussed in &lt;a href=&#34;https://bldavies.com/blog/policymaking-under-uncertainty/&#34;&gt;my blog post on policymaking under uncertainty&lt;/a&gt; and &lt;a href=&#34;https://www.newsroom.co.nz/pro/was-lockdown-the-right-choice&#34;&gt;Arthur&amp;rsquo;s commentary on the lockdown at &lt;em&gt;Newsroom&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Arthur and I present a two-period model of the government&amp;rsquo;s choice problem.
In the first period, the government decides whether to enter lockdown given random future health and economic outcomes.
These outcomes are realised in the second period, at which time the government decides whether to maintain or reverse its initial decision.
That initial decision influences the joint probability distribution of health and economic outcomes, and the payoffs associated with each choice in the second period.
The government&amp;rsquo;s decision rule in the first period is to choose the policy that generates the greatest net expected payoff, given the dynamic consequences of the policy chosen.&lt;/p&gt;
&lt;p&gt;We allow payoffs to vary with a parameter capturing the government&amp;rsquo;s aversion to health risks vis-à-vis economic risks.
The chart below shows how this parameter affects the payoff from each choice available in the first period.
As health risk aversion rises, the government increasingly prefers policies that insure against bad health outcomes.
Consequently, the value of entering lockdown rises while the value of delaying falls.
The non-linearity in the payoff curves reflects the non-linearity of health and economic costs under each policy choice: delaying lockdown suppresses economic costs but exposes the government to potentially exponential health costs if the virus spreads rampantly.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;See Arthur and my article, &amp;ldquo;&lt;a href=&#34;https://doi.org/10.1080/00779954.2020.1806340&#34;&gt;COVID-19, lockdown and two-sided uncertainty&lt;/a&gt;,&amp;rdquo; for further discussion.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Lessons from Dave Maré</title>
      <link>https://bldavies.com/blog/lessons-dave-mare/</link>
      <pubDate>Sun, 16 Aug 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/lessons-dave-mare/</guid>
      <description>&lt;p&gt;Last week I finished up at &lt;a href=&#34;https://motu.nz&#34;&gt;Motu&lt;/a&gt;, an economic research institute where I worked for two and half years.
During that time I learned a lot from &lt;a href=&#34;https://motu.nz/about-us/people/dave-mare/&#34;&gt;Dave Maré&lt;/a&gt;, who taught me several techniques for conducting rigorous, intellectually honest empirical research.
This post describes three such techniques:
&lt;a href=&#34;#state-your-predictions&#34;&gt;stating your predictions&lt;/a&gt;,
&lt;a href=&#34;#have-weak-priors-and-strong-nulls&#34;&gt;having weak priors and strong nulls&lt;/a&gt;,
and &lt;a href=&#34;#kill-off-the-variation&#34;&gt;killing off the variation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;state-your-predictions&#34;&gt;State your predictions&lt;/h2&gt;
&lt;p&gt;The scientific method involves stating hypotheses &lt;em&gt;before&lt;/em&gt; testing them.
Dave encourages this practice at a smaller scale: before plotting figures or printing regression tables, write down what you expect to see.&lt;/p&gt;
&lt;p&gt;Stating your predictions forces you to think about how and why variables might be related.
For example, if I regressed workers&amp;rsquo; wages on their years of education, I would expect to estimate a positive coefficient because education provides knowledge and skills that make people more employable.
Likewise, if I could control for natural ability then I would expect the coefficient on education to decrease because I would remove some endogeneity bias.
Forming these expectations (and their justifications) in advance makes my &lt;a href=&#34;#have-weak-priors-and-strong-nulls&#34;&gt;priors&lt;/a&gt; explicit, making them easier to revise when confronted with new evidence.
It also insures against &lt;em&gt;ex post&lt;/em&gt; rationalisations of the empirical patterns.&lt;/p&gt;
&lt;p&gt;Stating your predictions also means you have two independent data sources&amp;mdash;your predictions and your figures/tables&amp;mdash;that you can compare to identify and correct mistakes.
For example, if I estimated a negative relationship between education and wages, I would want to make sure the disagreement between my intuition and my estimate was not due to errant definitions of the variables in my data.&lt;/p&gt;
&lt;h2 id=&#34;have-weak-priors-and-strong-nulls&#34;&gt;Have weak priors and strong nulls&lt;/h2&gt;
&lt;p&gt;Priors are beliefs held before gathering new evidence.
In empirical research, we usually derive priors from intuitive or logical reasoning (e.g., &amp;ldquo;education provides knowledge and skills that make people more employable&amp;rdquo;).
However, the world is more complicated than can be described by intuition and logic; people behave in unexpected and unpredictable ways.
Consequently, our priors can be incorrect or incomplete.
To have &amp;ldquo;weak priors&amp;rdquo; is to acknowledge such ignorance and to let your beliefs be guided by empirical evidence rather than by fallible reasoning.&lt;/p&gt;
&lt;p&gt;However, empirical evidence comes in varying strengths.
To have &amp;ldquo;strong nulls&amp;rdquo; is to graduate from &amp;ldquo;ignorant&amp;rdquo; to &amp;ldquo;informed&amp;rdquo; only when supplied with strong evidence.
For example, if significant relationships persist after controlling for potentially confounding factors then those relationships are likely to reflect the true data-generating process.&lt;/p&gt;
&lt;h2 id=&#34;kill-off-the-variation&#34;&gt;Kill off the variation&lt;/h2&gt;
&lt;p&gt;Empirical models describe relationships between variables.
These relationships may not be first-order: the mechanisms that we think operate, and that our models aim to capture, may not be central to the stories playing out in our data.
To determine the centrality of our hypothesised mechanisms, Dave suggests trying to &amp;ldquo;kill off the variation:&amp;rdquo; add explanatory variables until the coefficients on our covariates of interest become insignificant.&lt;/p&gt;
&lt;p&gt;For example, in &amp;ldquo;&lt;a href=&#34;https://doi.org/10.1080/00343404.2020.1802418&#34;&gt;Relatedness, Complexity and Local Growth&lt;/a&gt;,&amp;rdquo; Dave and I analyse the relationship between local activity growth rates and several covariates that capture the prevalence of local employee interactions.
In theory, such interactions foster the growth of &amp;ldquo;complex&amp;rdquo; activities that build on existing local strengths.
However, in our data, most of the variation in local activity growth is explained by the growth experienced by the city and activity as a whole, and our chosen covariates provide no additional explanatory power.
Thus, while employee interactions may influence employment dynamics at the margin, such interactions are not central to the story of how New Zealand cities evolved during our period of study.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Product-maximising partitions</title>
      <link>https://bldavies.com/blog/product-maximising-partitions/</link>
      <pubDate>Wed, 08 Jul 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/product-maximising-partitions/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(\newcommand{\N}{\mathbb{N}}\N=\{1,2,\ldots\}\)&lt;/code&gt; be the set of positive integers.
A &lt;em&gt;partition&lt;/em&gt; of &lt;code&gt;\(n\in\N\)&lt;/code&gt; is a way of writing &lt;code&gt;\(n\)&lt;/code&gt; as a sum of positive integers, called &lt;em&gt;parts&lt;/em&gt;.
For example, &lt;code&gt;\(1+2+3\)&lt;/code&gt; is a partition of &lt;code&gt;\(6\)&lt;/code&gt;, with parts &lt;code&gt;\(1\)&lt;/code&gt;, &lt;code&gt;\(2\)&lt;/code&gt;, and &lt;code&gt;\(3\)&lt;/code&gt;.
Partitions are unique up to rearrangement: &lt;code&gt;\(1+2+3\)&lt;/code&gt; and &lt;code&gt;\(3+2+1\)&lt;/code&gt; are the same partition, but &lt;code&gt;\(1+2+3\)&lt;/code&gt; and &lt;code&gt;\(3+3\)&lt;/code&gt; are different partitions.&lt;/p&gt;
&lt;p&gt;This post discusses the following problem:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Let &lt;code&gt;\(n\ge2\)&lt;/code&gt; be a positive integer.
Find a partition of &lt;code&gt;\(n\)&lt;/code&gt; whose parts have maximum product.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For example, the parts in &lt;code&gt;\(1+2+3\)&lt;/code&gt; have product &lt;code&gt;\(1\times2\times3=6\)&lt;/code&gt;, while the parts in &lt;code&gt;\(3+3\)&lt;/code&gt; have product &lt;code&gt;\(3\times3=9\)&lt;/code&gt;.
Our goal is to find a product-maximising partition for arbitrary &lt;code&gt;\(n\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(x_1+x_2+\cdots+x_k\)&lt;/code&gt; be a partition of &lt;code&gt;\(n\)&lt;/code&gt;.
If &lt;code&gt;\(x_1=1\)&lt;/code&gt; then &lt;code&gt;\(k\ge2\)&lt;/code&gt; (since &lt;code&gt;\(n\ge2\)&lt;/code&gt;) and
&lt;code&gt;$$\begin{align} \prod_{i=1}^kx_i &amp;amp;= 1\times x_2\times\prod_{i=3}^kx_i \\ &amp;amp;&amp;lt; (1+x_2)\times\prod_{i=3}^kx_i \end{align}$$&lt;/code&gt;
because the &lt;code&gt;\(x_i\)&lt;/code&gt; are strictly positive.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Thus, replacing the partition &lt;code&gt;\(x_1+x_2+\cdots+x_k\)&lt;/code&gt; with &lt;code&gt;\((1+x_2)+x_3+\cdots+x_k\)&lt;/code&gt; delivers a greater product.
Since the &lt;code&gt;\(x_i\)&lt;/code&gt; can be rearranged arbitrarily, it follows that product-maximising partitions contain no parts equal to one.
Similarly, if &lt;code&gt;\(x_1&amp;gt;4\)&lt;/code&gt; then
&lt;code&gt;$$\begin{align} \prod_{i=1}^kx_i &amp;amp;= x_1\times\prod_{i=2}^kx_i \\ &amp;amp;&amp;lt; 3(x_1-3)\times\prod_{i=2}^kx_i, \end{align}$$&lt;/code&gt;
so we can obtain a greater product by replacing &lt;code&gt;\(x_1+x_2+\cdots+x_k\)&lt;/code&gt; with &lt;code&gt;\(3+(x_1-3)+x_2+\cdots+x_k\)&lt;/code&gt;.
It follows that product-maximising partitions contain no parts greater than four.
But &lt;code&gt;\(2\times2=4\)&lt;/code&gt; and &lt;code&gt;\(2+2=4\)&lt;/code&gt;, so we can replace each four with two twos without reducing the parts&amp;rsquo; product.
Thus, we can obtain a product-maximising partition using only twos and threes.
Finally, if a partition contains three twos then we should replace them with two threes, since &lt;code&gt;\(2+2+2=3+3\)&lt;/code&gt; but &lt;code&gt;\(2^3=8&amp;lt;9=3^2\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To summarise, we can obtain a product-maximising partition using only twos and threes, with as many threes as possible.
Letting &lt;code&gt;\(n=3q+r\)&lt;/code&gt; for some &lt;code&gt;\(q\in\N\cup\{0\}\)&lt;/code&gt; and &lt;code&gt;\(r\in\{0,1,2\}\)&lt;/code&gt;, the maximum product we can obtain is
&lt;code&gt;$$P(n)=\begin{cases}3^q&amp;amp;\text{if}\ r=0\\ 2^2\times3^{q-1}&amp;amp;\text{if}\ r=1\\ 2\times3^q&amp;amp;\text{if}\ r=2.\end{cases}$$&lt;/code&gt;
We can approximate this solution by &lt;a href=&#34;https://en.wikipedia.org/wiki/Relaxation_%28approximation%29&#34;&gt;relaxing&lt;/a&gt; the integrality constraint on the &lt;code&gt;\(x_i\)&lt;/code&gt;.
For any given &lt;code&gt;\(k\)&lt;/code&gt;, we can find the vector &lt;code&gt;\(x^*\)&lt;/code&gt; that solves
&lt;code&gt;$$\newcommand{\R}{\mathbb{R}}\max_{x\in\R_+^k}\prod_{i=1}^kx_i\ \text{subject to}\ \sum_{i=1}^kx_i=n \tag{1},$$&lt;/code&gt;
where &lt;code&gt;\(\R_+\)&lt;/code&gt; is the set of positive real numbers.
This vector has &lt;code&gt;\(x_i^*=n/k\)&lt;/code&gt; for each &lt;code&gt;\(i\in\{1,2,\ldots,k\}\)&lt;/code&gt;, so that &lt;code&gt;\(\prod_{i=1}^kx_i^*=(n/k)^k\)&lt;/code&gt;.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
If there was no integrality constraint on &lt;code&gt;\(k\)&lt;/code&gt; then we could maximise &lt;code&gt;\((n/k)^k\)&lt;/code&gt; by choosing &lt;code&gt;\(k=n/e\)&lt;/code&gt;, where &lt;code&gt;\(e\approx2.718\)&lt;/code&gt; is Euler&amp;rsquo;s constant.
But &lt;code&gt;\(k\)&lt;/code&gt; must be an integer, so we should round it to the nearest integer in whatever direction delivers the greatest value of &lt;code&gt;\((n/k)^k\)&lt;/code&gt;.
Doing so delivers an estimate
&lt;code&gt;$$\hat{P}(n)=\max\left\{\left(\frac{n}{\lfloor n/e\rfloor}\right)^{\lfloor n/e\rfloor},\left(\frac{n}{\lceil n/e\rceil}\right)^{\lceil n/e\rceil}\right\}$$&lt;/code&gt;
of &lt;code&gt;\(P(n)\)&lt;/code&gt;, where &lt;code&gt;\(x\mapsto\lfloor x\rfloor\)&lt;/code&gt; and &lt;code&gt;\(x\mapsto\lceil x\rceil\)&lt;/code&gt; are the floor (&amp;ldquo;round down&amp;rdquo;) and ceiling (&amp;ldquo;round up&amp;rdquo;) functions.&lt;/p&gt;
&lt;p&gt;The table below compares &lt;code&gt;\(P(n)\)&lt;/code&gt; and &lt;code&gt;\(\hat{P}(n)\)&lt;/code&gt; for various &lt;code&gt;\(n\)&lt;/code&gt;.
Since &lt;code&gt;\(\{2,3\}\subset\mathbb{R}_+\)&lt;/code&gt;, the partition of &lt;code&gt;\(n\)&lt;/code&gt; using twos and as many threes as possible is a feasible, but not necessarily optimal, solution to &lt;code&gt;\((1)\)&lt;/code&gt;.
Thus &lt;code&gt;\(P(n)\le\hat{P}(n)\)&lt;/code&gt; for each &lt;code&gt;\(n\ge2\)&lt;/code&gt;.
The multiplicative error &lt;code&gt;\(\hat{P}(n)/P(n)\)&lt;/code&gt; grows exponentially with &lt;code&gt;\(n\)&lt;/code&gt; because the exponent &lt;code&gt;\(k\in\{\lfloor n/e\rfloor,\lceil n/e\rceil\}\)&lt;/code&gt; of &lt;code&gt;\((n/k)^k\)&lt;/code&gt; grows (increasingly linearly) with &lt;code&gt;\(n\)&lt;/code&gt;, amplifying the error in the approximation &lt;code&gt;\(n/k\sim e\)&lt;/code&gt; to each part in the partition underlying &lt;code&gt;\(P(n)\)&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(n\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(P(n)\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\hat{P}(n)\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\hat{P}(n)/P(n)\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6.25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;36&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;39.06&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.09&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;50&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8.61×10&lt;sup&gt;7&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9.70×10&lt;sup&gt;7&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;100&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7.41×10&lt;sup&gt;15&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9.47×10&lt;sup&gt;15&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;500&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.19×10&lt;sup&gt;79&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7.66×10&lt;sup&gt;79&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1,000&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.01×10&lt;sup&gt;159&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5.86×10&lt;sup&gt;159&lt;/sup&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5.78&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;If &lt;code&gt;\(j&amp;gt;k\)&lt;/code&gt; then &lt;code&gt;\(\prod_{i=j}^kx_i=1\)&lt;/code&gt; &lt;a href=&#34;https://en.wikipedia.org/wiki/Empty_product&#34;&gt;by convention&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;One can derive &lt;code&gt;\(x_i^*=n/k\)&lt;/code&gt; using the &lt;a href=&#34;https://en.wikipedia.org/wiki/Lagrange_multiplier&#34;&gt;method of Lagrange multipliers&lt;/a&gt;. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Understanding selection bias</title>
      <link>https://bldavies.com/blog/understanding-selection-bias/</link>
      <pubDate>Fri, 03 Jul 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/understanding-selection-bias/</guid>
      <description>&lt;p&gt;Suppose we have data &lt;code&gt;\(\{(x_i,y_i):i\in\{1,2,\ldots,n\}\}\)&lt;/code&gt; generated by the process
&lt;code&gt;$$y_i=\beta x_i+u_i,$$&lt;/code&gt;
where the &lt;code&gt;\(u_i\)&lt;/code&gt; are random errors with zero means, equal variances, and zero correlations with the &lt;code&gt;\(x_i\)&lt;/code&gt;.
This data generating process (DGP) satisfies the &lt;a href=&#34;https://en.wikipedia.org/wiki/Gauss%E2%80%93Markov_theorem&#34;&gt;Gauss-Markov&lt;/a&gt; assumptions, so we can obtain an unbiased estimate &lt;code&gt;\(\hat\beta\)&lt;/code&gt; of the coefficient &lt;code&gt;\(\beta\)&lt;/code&gt; using ordinary least squares (OLS).&lt;/p&gt;
&lt;p&gt;Now suppose we restrict our data to observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; or &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;.
How will these restrictions change &lt;code&gt;\(\hat\beta\)&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;To investigate, let&amp;rsquo;s create some toy data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;100&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rnorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;u&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rnorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;u&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt; are standard normal random variables, and &lt;code&gt;\(y_i=x_i+u_i\)&lt;/code&gt; for each observation &lt;code&gt;\(i\in\{1,2,\ldots,100\}\)&lt;/code&gt;.
Thus &lt;code&gt;\(\beta=1\)&lt;/code&gt;.
The OLS estimate of &lt;code&gt;\(\beta\)&lt;/code&gt; is
&lt;code&gt;$$\DeclareMathOperator{\Cov}{Cov}\DeclareMathOperator{\Var}{Var}\hat\beta=\frac{\Cov(x,y)}{\Var(x)},$$&lt;/code&gt;
where &lt;code&gt;\(x=(x_1,x_2,\ldots,x_{100})\)&lt;/code&gt; and &lt;code&gt;\(y=(y_1,y_2,\ldots,y_{100})\)&lt;/code&gt; are data vectors, &lt;code&gt;\(\Cov\)&lt;/code&gt; is the covariance operator, and &lt;code&gt;\(\Var\)&lt;/code&gt; is the variance operator.
For these data, we have&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;cov&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 1.138795
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;as our estimate with no selection.&lt;/p&gt;
&lt;p&gt;Next, let&amp;rsquo;s introduce our selection criteria:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;crossing&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;criterion&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;x &amp;gt;= 0&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;y &amp;gt;= 0&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;rowwise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# eval is annoying to vectorise&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;selected&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;eval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;parse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;criterion&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 200 x 5
##        x       u      y criterion selected
##    &amp;lt;dbl&amp;gt;   &amp;lt;dbl&amp;gt;  &amp;lt;dbl&amp;gt; &amp;lt;chr&amp;gt;     &amp;lt;lgl&amp;gt;   
##  1 -2.22 -0.0125 -2.24  x &amp;gt;= 0    FALSE   
##  2 -2.22 -0.0125 -2.24  y &amp;gt;= 0    FALSE   
##  3 -1.56 -1.12   -2.68  x &amp;gt;= 0    FALSE   
##  4 -1.56 -1.12   -2.68  y &amp;gt;= 0    FALSE   
##  5 -1.54  0.577  -0.963 x &amp;gt;= 0    FALSE   
##  6 -1.54  0.577  -0.963 y &amp;gt;= 0    FALSE   
##  7 -1.44 -1.39   -2.83  x &amp;gt;= 0    FALSE   
##  8 -1.44 -1.39   -2.83  y &amp;gt;= 0    FALSE   
##  9 -1.43 -0.543  -1.97  x &amp;gt;= 0    FALSE   
## 10 -1.43 -0.543  -1.97  y &amp;gt;= 0    FALSE   
## # … with 190 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now &lt;code&gt;df&lt;/code&gt; contains two copies of each observation&amp;mdash;one for each selection criterion&amp;mdash;and an indicator for whether the observation is selected by each criterion.
We can use &lt;code&gt;df&lt;/code&gt; to estimate OLS coefficients and their standard errors among observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; and &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;selected&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;criterion&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;summarise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;estimate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cov&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;std.error&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sd&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;estimate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sqrt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 2 x 4
##   criterion     n estimate std.error
##   &amp;lt;chr&amp;gt;     &amp;lt;int&amp;gt;    &amp;lt;dbl&amp;gt;     &amp;lt;dbl&amp;gt;
## 1 x &amp;gt;= 0       48    1.02      0.136
## 2 y &amp;gt;= 0       47    0.356     0.110
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The OLS estimate among observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; approximates the true value &lt;code&gt;\(\beta=1\)&lt;/code&gt; well.
However, the estimate among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt; is much smaller than one.
We can confirm this visually:
&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s going on?
Why do we get biased OLS estimates of &lt;code&gt;\(\beta\)&lt;/code&gt; among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt; but not among observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;The key is to think about the errors &lt;code&gt;\(u_i\)&lt;/code&gt; in each case.
Since the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt; are independent, selecting observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; leaves the distributions of the &lt;code&gt;\(u_i\)&lt;/code&gt; unchanged&amp;mdash;they still have zero means, equal variances, and zero correlations with the &lt;code&gt;\(x_i\)&lt;/code&gt;.
Thus, the Gauss-Markov assumptions still hold and we still obtain unbiased OLS estimates of &lt;code&gt;\(\beta\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In contrast, the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt; are negatively correlated among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;.
To see why, notice that if &lt;code&gt;\(y_i=x_i+u_i\)&lt;/code&gt; then &lt;code&gt;\(y_i\ge0\)&lt;/code&gt; if and only if &lt;code&gt;\(x_i\ge-u_i\)&lt;/code&gt;.
So if &lt;code&gt;\(x_i\)&lt;/code&gt; is low then &lt;code&gt;\(u_i\)&lt;/code&gt; must be high (and vice versa) for the observation to be selected.
Thus, among selected observations, we have
&lt;code&gt;$$u_i=\rho x_i+\varepsilon_i,$$&lt;/code&gt;
where &lt;code&gt;\(\rho&amp;lt;0\)&lt;/code&gt; indexes (and, in this case, equals) the correlation between the &lt;code&gt;\(x_i\)&lt;/code&gt; and &lt;code&gt;\(u_i\)&lt;/code&gt;, and where the residuals &lt;code&gt;\(\varepsilon_i\)&lt;/code&gt; are uncorrelated with the &lt;code&gt;\(x_i\)&lt;/code&gt;.
Our DGP then becomes
&lt;code&gt;$$y_i=(\beta+\rho)x_i+\varepsilon_i.$$&lt;/code&gt;
The &lt;code&gt;\(\varepsilon_i\)&lt;/code&gt; have equal variances (equal to &lt;code&gt;\(1+\rho^2\)&lt;/code&gt; in this case) and, again, are uncorrelated with the &lt;code&gt;\(x_i\)&lt;/code&gt;.
Therefore, the OLS estimate
&lt;code&gt;$$\hat\rho=\frac{\Cov(u,x)}{\Var(x)}$$&lt;/code&gt;
of &lt;code&gt;\(\rho\)&lt;/code&gt; is unbiased&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;, and for our toy data equals &lt;code&gt;\(\hat\rho\approx-0.644\)&lt;/code&gt; among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;.
Subtracting &lt;code&gt;\(\hat\rho\)&lt;/code&gt; from &lt;code&gt;\(\hat\beta\)&lt;/code&gt; then gives
&lt;code&gt;$$\begin{align} \hat\beta-\hat\rho &amp;amp;\approx 0.356 - (-0.644) \\ &amp;amp;= 1, \end{align}$$&lt;/code&gt;
recovering the true value &lt;code&gt;\(\beta=1\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The table below reports 95% confidence intervals for &lt;code&gt;\(\hat\beta\)&lt;/code&gt;, &lt;code&gt;\(\hat\rho\)&lt;/code&gt;, and &lt;code&gt;\((\hat\beta-\hat\rho)\)&lt;/code&gt;, estimated by simulating the DGP &lt;code&gt;\(y_i=x_i+u_i\)&lt;/code&gt; described above 100 times.
The table confirms that the OLS estimate &lt;code&gt;\(\hat\beta\)&lt;/code&gt; of &lt;code&gt;\(\beta=1\)&lt;/code&gt; is unbiased among observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; but biased negatively among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Observations&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\hat\beta\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\hat\rho\)&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;\(\hat\beta-\hat\rho\)&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;All&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.005 ± 0.002&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.005 ± 0.002&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.000 ± 0.000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;With &lt;code&gt;\(x_i\ge0\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.001 ± 0.004&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.001 ± 0.004&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.000 ± 0.000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;With &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.547 ± 0.003&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;-0.453 ± 0.003&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.000 ± 0.000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The estimate &lt;code&gt;\(\hat\beta\)&lt;/code&gt; always differs from &lt;code&gt;\(\beta\)&lt;/code&gt; by &lt;code&gt;\(\hat\rho\)&lt;/code&gt;, which is significantly non-zero among observations with &lt;code&gt;\(y_i\ge0\)&lt;/code&gt;.
However, this pattern is not useful empirically because we generally don&amp;rsquo;t observe the &lt;code&gt;\(u_i\)&lt;/code&gt; and so can&amp;rsquo;t estimate &lt;code&gt;\(\hat\rho\)&lt;/code&gt; to back out the true value of &lt;code&gt;\(\beta=\hat\beta-\hat\rho\)&lt;/code&gt;.
Instead, we may use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Heckman_correction&#34;&gt;Heckman correction&lt;/a&gt; to adjust for the bias introduced through non-random selection.&lt;/p&gt;
&lt;p&gt;In empirical settings, selecting observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; may lead to biased estimates when (i) there is heterogeneity in the relationship between &lt;code&gt;\(y_i\)&lt;/code&gt; and &lt;code&gt;\(x_i\)&lt;/code&gt; across observations &lt;code&gt;\(i\)&lt;/code&gt;, and (ii) OLS is used to estimate an &lt;a href=&#34;https://en.wikipedia.org/wiki/Average_treatment_effect&#34;&gt;average treatment effect&lt;/a&gt;.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
In particular, if the &lt;code&gt;\(x_i\)&lt;/code&gt; are correlated with the observation-specific treatment effects then restricting to observations with &lt;code&gt;\(x_i\ge0\)&lt;/code&gt; changes the distribution, and hence the mean, of those effects non-randomly.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;We can rewrite &lt;code&gt;\(\varepsilon_i=\alpha+(\varepsilon_i-\alpha)\)&lt;/code&gt;, where &lt;code&gt;\(\alpha\)&lt;/code&gt; is the mean of the &lt;code&gt;\(\varepsilon_i\)&lt;/code&gt;, and where the &lt;code&gt;\((\varepsilon_i-\alpha)\)&lt;/code&gt; have zero means, equal variances, and zero correlations with the &lt;code&gt;\(x_i\)&lt;/code&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Thanks to &lt;a href=&#34;http://shakkednoy.com&#34;&gt;Shakked&lt;/a&gt; for pointing this out. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Modelling bacterial extinction</title>
      <link>https://bldavies.com/blog/modelling-bacterial-extinction/</link>
      <pubDate>Sun, 14 Jun 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/modelling-bacterial-extinction/</guid>
      <description>&lt;p&gt;This week&amp;rsquo;s &lt;a href=&#34;https://fivethirtyeight.com/features/how-long-will-the-bacterial-colony-last/&#34;&gt;Riddler Classic&lt;/a&gt; poses a question about bacteria (paraphrased for brevity):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Each bacterium in a colony splits into two copies with probability &lt;code&gt;\(p\)&lt;/code&gt; and dies with probability &lt;code&gt;\((1-p)\)&lt;/code&gt;.
If the colony starts with one bacterium, what is the probability that the colony survives forever?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can model the colony&amp;rsquo;s size as a &lt;a href=&#34;https://en.wikipedia.org/wiki/Galton%E2%80%93Watson_process&#34;&gt;Galton-Watson process&lt;/a&gt;.
Let &lt;code&gt;\(X_t\)&lt;/code&gt; be the colony&amp;rsquo;s size in generation &lt;code&gt;\(t\in\{1,2,\ldots\}\)&lt;/code&gt; and let &lt;code&gt;\(Y_{it}\)&lt;/code&gt; be the number of offspring generated by bacterium &lt;code&gt;\(i\in\{1,2,\ldots,X_t\}\)&lt;/code&gt;.
The &lt;code&gt;\(Y_{it}\)&lt;/code&gt; are independently and identically distributed, with
&lt;code&gt;$$\Pr(Y_{it}=y)=\begin{cases} p &amp;amp; \text{if}\ y=2 \\ 1-p &amp;amp; \text{if}\ y=0 \\ 0 &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
for each &lt;code&gt;\(i\)&lt;/code&gt; and &lt;code&gt;\(t\)&lt;/code&gt;.
The colony&amp;rsquo;s size grows according to
&lt;code&gt;$$X_{t+1}=\sum_{i=1}^{X_t}Y_{it}$$&lt;/code&gt;
with &lt;code&gt;\(X_1=1\)&lt;/code&gt;.
Our goal is to compute
&lt;code&gt;$$\lim_{t\to\infty}\Pr(X_t&amp;gt;0)=1-\lim_{t\to\infty}q_t,$$&lt;/code&gt;
where &lt;code&gt;\(q_t\equiv\Pr(X_t=0)\)&lt;/code&gt; is the probability that the colony is extinct by generation &lt;code&gt;\(t\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can compute &lt;code&gt;\(q_t\)&lt;/code&gt; by conditioning on &lt;code&gt;\(Y_{11}\)&lt;/code&gt;, the number of offspring generated by the first bacterium.
If &lt;code&gt;\(Y_{11}=0\)&lt;/code&gt; then the colony is extinct from the second generation onwards.
However, if &lt;code&gt;\(Y_{11}=2\)&lt;/code&gt; then there are two sub-colonies in the second generation that must be extinct in &lt;code&gt;\((t-1)\)&lt;/code&gt; generations if the whole colony is extinct by generation &lt;code&gt;\(t\)&lt;/code&gt;.
These sub-colonies grow independently, so the probability that both are extinct in &lt;code&gt;\((t-1)\)&lt;/code&gt; generations is &lt;code&gt;\(q_{t-1}^2\)&lt;/code&gt;.
Thus, by the &lt;a href=&#34;https://en.wikipedia.org/wiki/Law_of_total_probability&#34;&gt;law of total probability&lt;/a&gt;, we have
&lt;code&gt;$$\begin{align} q_t &amp;amp;= \Pr(X_t=0\,\vert\,Y_{11}=0)\Pr(Y_{11}=0)+\Pr(X_t=0\,\vert\,Y_{11}=2)\Pr(Y_{11}=2) \\ &amp;amp;= 1\times(1-p)+q_{t-1}^2\times p \\ &amp;amp;= 1-p+pq_{t-1}^2 \end{align}$$&lt;/code&gt;
for &lt;code&gt;\(t\ge2\)&lt;/code&gt;.
Defining &lt;code&gt;\(q\equiv\lim_{t\to\infty}q_t\)&lt;/code&gt; and taking limits as &lt;code&gt;\(t\to\infty\)&lt;/code&gt; gives&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$q=1-p+pq^2,$$&lt;/code&gt;
which has solutions
&lt;code&gt;$$\begin{align} \newcommand{\abs}[1]{\lvert#1\rvert} q &amp;amp;= \frac{1\pm\sqrt{1-4p(1-p)}}{2p} \\ &amp;amp;= \frac{1\pm\sqrt{(2p-1)^2}}{2p} \\ &amp;amp;= \frac{1\pm\abs{2p-1}}{2p}. \end{align}$$&lt;/code&gt;
The larger solution exceeds unity when &lt;code&gt;\(p&amp;lt;0.5\)&lt;/code&gt;, which we cannot have because &lt;code&gt;\(q\)&lt;/code&gt; is a probability.
Thus
&lt;code&gt;$$\lim_{t\to\infty}\Pr(X_t&amp;gt;0)=1-\frac{1-\abs{2p-1}}{2p}.$$&lt;/code&gt;
For example, if &lt;code&gt;\(p=0.8\)&lt;/code&gt; then the colony survives forever with probability
&lt;code&gt;$$1-\frac{1-\abs{2\times0.8-1}}{2\times0.8}=0.75.$$&lt;/code&gt;
If &lt;code&gt;\(p&amp;lt;0.5\)&lt;/code&gt; then extinction is guaranteed because each bacterium generates fewer than one offspring on average.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The function &lt;code&gt;\(x\mapsto x^2\)&lt;/code&gt; is continuous and so preserves limits. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Applying to economics PhD programs</title>
      <link>https://bldavies.com/blog/applying-economics-phd-programs/</link>
      <pubDate>Sat, 13 Jun 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/applying-economics-phd-programs/</guid>
      <description>&lt;p&gt;Last year I applied to several economics PhD programs at elite universities and business schools.
I applied to twelve programs (nine in economics and three in business), was accepted by three, and &lt;a href=&#34;https://bldavies.com/blog/stanford/&#34;&gt;chose to study at Stanford&lt;/a&gt;.
This post describes my experience with the application process and offers some advice to future applicants.&lt;/p&gt;
&lt;h2 id=&#34;contents&#34;&gt;Contents&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#before-applying&#34;&gt;Before applying&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#earning-a-degree&#34;&gt;Earning a degree&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#gaining-research-experience&#34;&gt;Gaining research experience&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#completing-the-gre&#34;&gt;Completing the GRE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#choosing-where-to-apply&#34;&gt;Choosing where to apply&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#application-materials&#34;&gt;Application materials&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#transcripts&#34;&gt;Transcripts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#gre-score-reports&#34;&gt;GRE score reports&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#recommendation-letters&#34;&gt;Recommendation letters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#statements-of-purpose&#34;&gt;Statements of purpose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#writing-samples&#34;&gt;Writing samples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#diversity-statements&#34;&gt;Diversity statements&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#after-applying&#34;&gt;After applying&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#waiting-for-responses&#34;&gt;Waiting for responses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#interviews&#34;&gt;Interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#admissions-decisions&#34;&gt;Admissions decisions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-reading&#34;&gt;Further reading&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;before-applying&#34;&gt;Before applying&lt;/h2&gt;
&lt;p&gt;The programs I applied to accepted applications between late September and early December.
However, these applications depended on tasks completed earlier: &lt;a href=&#34;#earning-a-degree&#34;&gt;earning a degree&lt;/a&gt;, &lt;a href=&#34;#gaining-research-experience&#34;&gt;gaining research experience&lt;/a&gt;, &lt;a href=&#34;#completing-the-gre&#34;&gt;completing the Graduate Record Exam (GRE)&lt;/a&gt;, and &lt;a href=&#34;#choosing-where-to-apply&#34;&gt;choosing where to apply&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;earning-a-degree&#34;&gt;Earning a degree&lt;/h3&gt;
&lt;p&gt;Every program required that I held the equivalent of a four-year bachelor&amp;rsquo;s degree or higher.
Most stated explicitly that a master&amp;rsquo;s was not necessary.
Some stated explicitly that applicants need not have a major in economics, but some prior coursework (e.g., intermediate microeconomics) helps to signal interest and familiarity.
Most stated explicitly that applicants should be comfortable with undergraduate-level calculus, linear algebra, and probability and statistics.&lt;/p&gt;
&lt;h3 id=&#34;gaining-research-experience&#34;&gt;Gaining research experience&lt;/h3&gt;
&lt;p&gt;While not required explicitly, my impression is that most successful applicants to top programs have some research experience.
Such experience helps demonstrate that you know what research is and can conduct it successfully.
Moreover, everyone applying to top programs has stellar grades, so having research experience helps you stand out.&lt;/p&gt;
&lt;p&gt;Thankfully, there are many ways to gain research experience.
I have four recommendations.&lt;/p&gt;
&lt;p&gt;First, write an honours or master&amp;rsquo;s thesis.
Doing so provides early evidence that you&amp;rsquo;re interested in research and can work independently.&lt;/p&gt;
&lt;p&gt;Second, work with professors while studying.
The University of Canterbury (UC), where I completed my bachelor&amp;rsquo;s degree, &lt;a href=&#34;https://www.canterbury.ac.nz/get-started/summer-school/summer-scholarships/&#34;&gt;offers scholarships&lt;/a&gt; to work with professors during summer breaks.
I won one to work with Richard Watt on a theoretical project related to insurance pricing.
Completing the project gave me experience to discuss in my &lt;a href=&#34;#statements-of-purpose&#34;&gt;statement of purpose&lt;/a&gt; and gave Richard something to discuss in his &lt;a href=&#34;#recommendation-letters&#34;&gt;recommendation letter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Third, work at a research-oriented organisation after finishing your bachelor&amp;rsquo;s or master&amp;rsquo;s.
In New Zealand, the best place is &lt;a href=&#34;https://motu.nz&#34;&gt;Motu&lt;/a&gt; or &lt;a href=&#34;https://www.rbnz.govt.nz&#34;&gt;the Reserve Bank&lt;/a&gt;, depending on whether you&amp;rsquo;re more interested in microeconomics or macroeconomics.
Working at Motu has improved my technical and research skills, and given me experience working with respected economists on substantive research projects.
It has also helped clarify what a &amp;ldquo;research career&amp;rdquo; looks like and whether it&amp;rsquo;s something I want to pursue.&lt;/p&gt;
&lt;p&gt;Finally, consider completing a pre-doctoral fellowship at an elite university.
These fellowships typically last one or two years, and involve assisting professors with their research.
Pre-doctoral fellowships deliver similar benefits to working at places like Motu.
However, some fellowships (e.g., those offered by &lt;a href=&#34;https://opportunityinsights.org/joinourteam/&#34;&gt;Opportunity Insights&lt;/a&gt; at Harvard and &lt;a href=&#34;https://siepr.stanford.edu/research/student-opportunities/predoctoral-fellowship&#34;&gt;SIEPR&lt;/a&gt; at Stanford) allow you to take graduate courses while working, further strengthening your profile.
Moreover, working with well-known economists at elite universities (and impressing them) helps you gain strong recommendation letters.&lt;/p&gt;
&lt;h3 id=&#34;completing-the-gre&#34;&gt;Completing the GRE&lt;/h3&gt;
&lt;p&gt;All programs required official scores from &lt;a href=&#34;https://en.wikipedia.org/wiki/Graduate_Record_Examinations&#34;&gt;the (general) GRE&lt;/a&gt;, a standardised test comprising three sections: quantitative reasoning, verbal reasoning, and analytical writing.
The test can be attempted multiple times.
Programs consider only your highest score on each section.&lt;/p&gt;
&lt;p&gt;I sat the GRE once, in 2018.
The test took about four hours.
The quantitative and verbal reasoning sections each comprised two sets of 20 multi-choice questions.
The quantitative section was mostly high school-level mathematics.
(New Zealanders: think NCEA Level 1 or 2.)
The verbal section tested reading comprehension and vocabulary.
The analytical writing section comprised two short, typed essay responses to prompts given during the test.
I think anyone who recently earned a bachelor&amp;rsquo;s degree in economics could do well on the test with 2&amp;ndash;4 weeks of study.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1080/00220485.2020.1731385&#34;&gt;Jones et al. (2020)&lt;/a&gt; survey graduate admissions coordinators, who report placing more emphasis on quantitative reasoning scores than verbal reasoning scores when evaluating applicants.
Both scores are less important at higher ranked programs because applicants to such programs tend to have higher scores, leaving less variation for identifying applicants&amp;rsquo; relative abilities.
For example, Harvard&amp;rsquo;s economics department &lt;a href=&#34;https://economics.harvard.edu/pages/admissions&#34;&gt;states&lt;/a&gt; that admitted candidates&amp;rsquo; quantitative scores range &amp;ldquo;in the 97th percentile.&amp;rdquo;
I scored in the 94th percentile and would have resat the test if I had scored any lower.&lt;/p&gt;
&lt;h3 id=&#34;choosing-where-to-apply&#34;&gt;Choosing where to apply&lt;/h3&gt;
&lt;p&gt;I applied to most programs in the &amp;ldquo;top 10,&amp;rdquo; and a few more specialised programs that matched my interests and geographic preferences.
I figured that if I was going to move overseas, away from my family and friends, then I better go somewhere excellent.
If I had a weaker technical background or less research experience then I might have aimed lower.&lt;/p&gt;
&lt;p&gt;Beyond this &amp;ldquo;aim high&amp;rdquo; strategy, I have two recommendations.&lt;/p&gt;
&lt;p&gt;First, apply to as many programs as you can afford and would attend.
The marginal effort cost of applying to each program falls quickly after preparing your first set of application materials.
Moreover, although the application fees can sting, they are small compared to the expected gain in life satisfaction from being admitted.&lt;/p&gt;
&lt;p&gt;Second, apply to programs at business schools as well as economic departments.
Chicago, Harvard, Northwestern, NYU, and Stanford&amp;rsquo;s business schools all offer excellent economics-focused PhD programs.
They provide similar technical training and faculty access to &amp;ldquo;traditional&amp;rdquo; programs.
However, business schools tend to offer larger stipends and require less teaching than economics departments.
Business schools tend to make fewer offers, but they also tend to receive fewer applications.&lt;/p&gt;
&lt;h2 id=&#34;application-materials&#34;&gt;Application materials&lt;/h2&gt;
&lt;p&gt;All of the programs I applied to required the following materials:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An application form, submitted online;&lt;/li&gt;
&lt;li&gt;Copies of my academic &lt;a href=&#34;#transcripts&#34;&gt;transcripts&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;Official &lt;a href=&#34;#gre-score-reports&#34;&gt;GRE score reports&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#recommendation-letters&#34;&gt;Recommendation letters&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;A CV;&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;#statements-of-purpose&#34;&gt;statement of purpose&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most programs required a &lt;a href=&#34;#writing-samples&#34;&gt;writing sample&lt;/a&gt;.
Some required a (short) &lt;a href=&#34;#diversity-statements&#34;&gt;diversity statement&lt;/a&gt;.
All required payment of a 75&amp;ndash;125 USD application fee.&lt;/p&gt;
&lt;p&gt;Overall, it took about a month to prepare my application materials and about a day to tailor them to each program.
To track my progress and help manage my time, I maintained a checklist of form sections to complete and materials to upload.&lt;/p&gt;
&lt;h3 id=&#34;transcripts&#34;&gt;Transcripts&lt;/h3&gt;
&lt;p&gt;Stanford asked for official copies of my academic transcripts.
All other programs accepted &amp;ldquo;unofficial&amp;rdquo; copies.
I ordered a digital copy from UC, which set up a &lt;a href=&#34;https://www.myequals.ac.nz&#34;&gt;My eQuals&lt;/a&gt; account with my transcript uploaded as a PDF and certified by the UC registrar.
I shared this certified version with Stanford, saving me about 190 USD worth of third-party certification fees.
I downloaded the PDF version from My eQuals and used it as the unofficial copy for my other applications.&lt;/p&gt;
&lt;p&gt;In addition to transcripts, some schools asked for more information about my prior coursework.
Harvard and MIT asked for comprehensive lists of course codes and titles, dates completed, grades obtained, and textbooks used.
Other programs asked for similar information but only for the handful of &amp;ldquo;most advanced&amp;rdquo; courses I&amp;rsquo;d taken in economics, mathematics, and statistics.
Stanford asked me to match the courses I&amp;rsquo;d taken with courses offered at Stanford.
The matching took a while because the courses I took at UC often matched Stanford courses in different subject areas and at different degree levels.&lt;/p&gt;
&lt;p&gt;New Zealand universities use a nine-point GPA system, whereas the universities I applied to use a four-point system.
Some programs asked me to report my GPA on its original scale, some asked me to convert it to the four-point scale, and some asked me to leave the GPA field blank.
Overall, the difference in systems didn&amp;rsquo;t seem to be problematic.&lt;/p&gt;
&lt;h3 id=&#34;gre-score-reports&#34;&gt;GRE score reports&lt;/h3&gt;
&lt;p&gt;All programs asked for official GRE score reports.
The testing fee (205 USD) covers the cost of sending scores to up to four institutions, nominated on test day.
Sending scores to additional institutions costs 27 USD per institution.
I didn&amp;rsquo;t nominate any schools on test day because I wasn&amp;rsquo;t sure whether I would need to resit the test, or whether sending low scores would hurt my admissions chances even if I resat the test and performed better.
Once I sent my score reports, most programs confirmed receipt after about a week.&lt;/p&gt;
&lt;h3 id=&#34;recommendation-letters&#34;&gt;Recommendation letters&lt;/h3&gt;
&lt;p&gt;All programs asked me to nominate three recommendation letter writers.
I arranged my recommenders about two months in advance.
I gave each a list of programs I was applying to, a description of each program, and the due date for their letters.
I also provided copies of my CV, transcript, and draft statements of purpose.&lt;/p&gt;
&lt;p&gt;Whenever I nominated a recommender, I was asked whether I wanted to waive my &lt;a href=&#34;https://www2.ed.gov/ferpa/&#34;&gt;FERPA&lt;/a&gt; right to view their letter upon admission.
I always waived.
I wasn&amp;rsquo;t concerned that my recommenders would change what they wrote if they knew I could read their letters.
Instead, I was concerned that admissions committees would observe that I chose not to waive access, assume that my recommenders responded by providing stronger-than-truthful recommendations, and subsequently discount the quality of those recommendations.&lt;/p&gt;
&lt;h3 id=&#34;statements-of-purpose&#34;&gt;Statements of purpose&lt;/h3&gt;
&lt;p&gt;All programs asked for a statement describing my preparation for graduate study, my research experience and interests, and my career goals.
&lt;a href=&#34;statement.pdf&#34;&gt;The statement I submitted to Stanford&lt;/a&gt; contained&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a brief introduction,&lt;/li&gt;
&lt;li&gt;a paragraph describing my educational background,&lt;/li&gt;
&lt;li&gt;five paragraphs describing my research experience,&lt;/li&gt;
&lt;li&gt;a paragraph stating my research interests, and&lt;/li&gt;
&lt;li&gt;a paragraph stating my career goals.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I focused on my research experience because I felt that it was my comparative advantage over other applicants, whom I assumed were well-trained technically and had more prestigious alma maters.&lt;/p&gt;
&lt;h3 id=&#34;writing-samples&#34;&gt;Writing samples&lt;/h3&gt;
&lt;p&gt;Most programs asked for a writing sample.
Some programs required at least 15 pages; some required at most 10 pages.
In both cases, I used an excerpt from my most recent journal submission.
For long samples, I excluded figures and tables, which happened to leave 15 pages.
For short samples, I included only the first eight pages, which contained the introduction, literature review, method, and data sections.
I always included a cover page describing the excerpt and stating the full paper&amp;rsquo;s abstract.&lt;/p&gt;
&lt;p&gt;I could have submitted my honours thesis, which analysed a theoretical model of insurance and saving.
However, I felt that my academic transcript signalled my technical skills adequately.
Instead, I wanted my writing sample to demonstrate skills not demonstrated by other application materials: identifying interesting and important research questions, and synthesising literature.&lt;/p&gt;
&lt;h3 id=&#34;diversity-statements&#34;&gt;Diversity statements&lt;/h3&gt;
&lt;p&gt;Stanford and Yale asked me to explain how I would contribute to diversity on campus.
My response to Stanford read as follows:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I grew up in Wakefield, a small rural town in New Zealand.
I have been fortunate to attend university, to discover my passion for research, and to collaborate on research projects with economists from Europe and North America.
These projects have benefited from the diverse ideas and experiences of my collaborators, which have increased the quality of our work.&lt;/p&gt;
&lt;p&gt;I am excited to continue engaging with ideas in an inclusive research environment as a graduate student at Stanford.
I am also excited to share my cultural experiences in New Zealand with my Stanford classmates, and to learn about their experiences in other countries.
Doing so will increase our understanding of how different cultural values shape economic and social outcomes.
This understanding will enhance our ability to conduct globally relevant economic research that considers a range of perspectives.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;after-applying&#34;&gt;After applying&lt;/h2&gt;
&lt;p&gt;Clicking &amp;ldquo;submit&amp;rdquo; on the online application forms began the long&amp;mdash;about three month&amp;mdash;&lt;a href=&#34;#waiting-for-responses&#34;&gt;wait for responses&lt;/a&gt;.
In two cases, those responses were invitations for &lt;a href=&#34;#interviews&#34;&gt;interviews&lt;/a&gt;; in most cases, they were &lt;a href=&#34;#admissions-decisions&#34;&gt;admissions decisions&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;waiting-for-responses&#34;&gt;Waiting for responses&lt;/h3&gt;
&lt;p&gt;On waiting for responses, I offer three pieces of advice.&lt;/p&gt;
&lt;p&gt;First, &lt;em&gt;take a break&lt;/em&gt;.
Applying to PhD programs takes many years of effort earning a degree, gaining research experience, building relationships with recommendation letter writers, completing the GRE, and preparing your applications.
Make time to acknowledge and celebrate that effort.&lt;/p&gt;
&lt;p&gt;Second, realise that there is nothing you can do (except, if invited, prepare for interviews) to change your admissions decisions.
Worrying is futile.
Instead, try to find fun and engaging ways to spend your time that take your mind off your applications.
I ran a lot and worked on some blog posts.&lt;/p&gt;
&lt;p&gt;Third, try to stay off &lt;a href=&#34;https://www.urch.com/forums/phd-economics/&#34;&gt;Urch&lt;/a&gt; and &lt;a href=&#34;https://www.thegradcafe.com&#34;&gt;TheGradCafe&lt;/a&gt;.
In late January, people will start using those fora to share their anxiety and admissions results.
You will, after months of waiting, be hungry for news.
However, if you&amp;rsquo;re going to get good news then you will receive it from the program first.
Programs generally send all acceptances at the same time (or, at least, on the same day).
Thus, online fora can only deliver bad news: others received acceptance notifications but you did not.&lt;/p&gt;
&lt;h3 id=&#34;interviews&#34;&gt;Interviews&lt;/h3&gt;
&lt;p&gt;As far as I know, only business schools conduct interviews.
I interviewed for the business programs at Harvard and MIT, in late January and early February.
Both interviews comprised discussing my research experience and interests, and why those interests are best pursued at a business school.
The interviews lasted about fifteen minutes each and took place over Zoom.&lt;/p&gt;
&lt;h3 id=&#34;admissions-decisions&#34;&gt;Admissions decisions&lt;/h3&gt;
&lt;p&gt;Most programs sent admissions decisions in late February or early March.
They were either acceptances, rejections, or being placed on a wait list.
The program for which I was wait-listed was weaker than my best offer at the time, so I declined them promptly to help the market clear.&lt;/p&gt;
&lt;h2 id=&#34;further-reading&#34;&gt;Further reading&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;https://www.reddit.com/r/Economics/wiki/career_undergrad_links&#34;&gt;here&lt;/a&gt; for more resources on economics PhD admissions.
I found Susan Athey&amp;rsquo;s &lt;a href=&#34;https://athey.people.stanford.edu/professional-advice&#34;&gt;professional advice&lt;/a&gt;, Chris Blattman&amp;rsquo;s &lt;a href=&#34;https://chrisblattman.com/about/contact/gradschool/&#34;&gt;FAQs on PhD applications&lt;/a&gt;, and Abhishek Nagaraj&amp;rsquo;s &lt;a href=&#34;http://abhishekn.com/files/phdguide.pdf&#34;&gt;guide to business PhD applications&lt;/a&gt; particularly helpful.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Estimating research field similarities</title>
      <link>https://bldavies.com/blog/estimating-research-field-similarities/</link>
      <pubDate>Sat, 30 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/estimating-research-field-similarities/</guid>
      <description>&lt;p&gt;Research often draws on multiple fields, each contributing field-specific ideas and techniques to the production of new knowledge.
The more similar are two fields, the easier it is to combine their ideas and techniques, the more frequently such combination occurs, and the more demand there is for ways to publish the consequent research.
Likewise, the more similar are two fields, the easier it is to attract (subscription fee-paying) readers to journals covering those fields, and so the more willing publishers are to supply such journals.
Thus, in equilibrium, the frequency with which journals cover pairs of research fields rises with the similarity between those fields.&lt;/p&gt;
&lt;p&gt;This argument suggests that we can estimate research field similarities from data on journals and the fields they cover.
One source of such data is the &lt;a href=&#34;https://www.scopus.com/home.uri&#34;&gt;Scopus&lt;/a&gt; source list, which matches journals to fields within Scopus&amp;rsquo; &lt;a href=&#34;https://service.elsevier.com/app/answers/detail/a_id/15181/supporthub/scopus/&#34;&gt;All Science Journal Classification (ASJC)&lt;/a&gt; system.
The Scopus source list covers 24,039 active journals, each assigned to one or more of 26 ASJC fields.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Each of these fields belongs to one of four subject areas: Health, Life, Physical, and Social Sciences.
The bar chart below presents the distribution of journals across fields, with bars coloured by subject area.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/counts-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I estimate the similarity between ASJC fields as follows.
First, I count the number of journals assigned to each pair of fields.
I then divide these co-assignment counts by the number of journals assigned to at least one of the paired fields.
This normalisation delivers the &lt;a href=&#34;https://en.wikipedia.org/wiki/Jaccard_index&#34;&gt;Jaccard similarities&lt;/a&gt; between the sets of journals assigned to each field.&lt;/p&gt;
&lt;p&gt;On average, each ASJC field pair shares 62.43 co-assignments and a Jaccard similarity of 0.02.
About 83% of pairs share at least one journal co-assignment.
The table below presents the ten field pairs with the greatest Jaccard similarities.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Field 1&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Field 2&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Co-assignments&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Jaccard similarity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Arts and Humanities&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Social Sciences&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2,247&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Materials Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Physics and Astronomy&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;403&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Chemical Engineering&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Chemistry&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;222&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.19&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Engineering&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Materials Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;564&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Business, Management and Accounting&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Economics, Econometrics and Finance&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;359&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Agricultural and Biological Sciences&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Environmental Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;459&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Computer Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Mathematics&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;395&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Chemistry&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Materials Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;252&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Computer Science&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Engineering&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;492&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Engineering&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Physics and Astronomy&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;383&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.12&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;We can visualise the similarities between ASJC fields by constructing a network in which (i) nodes represent fields and (ii) edges have weights proportional to incident nodes&amp;rsquo; similarities.
I present this network below, restricting my visualisation to the sub-network induced by the 50 edges of largest weight.
To improve readability, I label some nodes using the field abbreviations given in parentheses in the bar chart above.
I draw fields with greater similarities closer together.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/map-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Overall, fields tend to be most similar to other fields in the same subject area.
The proximities among nodes, reflecting fields&amp;rsquo; pairwise similarities, seem intuitive:
Chemistry (Chem) and Chemical Engineering (ChemEng) are obviously similar, the biological sciences are clustered together, and Astronomy researchers probably don&amp;rsquo;t read many Nursing journals&amp;mdash;indeed, there are no journal co-assignments between Physics and Astronomy (PhysAstr) and Nursing.&lt;/p&gt;
&lt;p&gt;The paths between fields also make sense.
For example, Social Science (SocSci) relies on Neuroscience (Neur) to the extent it helps explain how people think and behave, which suggests the fields should be connected via Psychology (Psyc).
Likewise, Business, Management and Accounting (BusMgtAcc) rely on Mathematics (Math) to the extent that it helps model how people make decisions, which suggests that the fields should be connected via Decision Science (DscnSci).&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I exclude the 27th field, &amp;ldquo;Multidisciplinary,&amp;rdquo; from my analysis. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I count journals &amp;ldquo;fractionally&amp;rdquo; so that, for example, journals assigned to four fields contribute a quarter to each field&amp;rsquo;s count. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Policymaking under uncertainty</title>
      <link>https://bldavies.com/blog/policymaking-under-uncertainty/</link>
      <pubDate>Sun, 17 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/policymaking-under-uncertainty/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/COVID-19_pandemic&#34;&gt;The COVID-19 pandemic&lt;/a&gt; exposes policymakers to several sources of uncertainty:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How dangerous is the virus?&lt;/li&gt;
&lt;li&gt;What will be the consequences of policies introduced to combat the virus?&lt;/li&gt;
&lt;li&gt;How willing and able are people to tolerate those consequences?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Under this uncertainty, policymakers must determine which policies to introduce and &lt;a href=&#34;https://bldavies.com/blog/covid-19-lockdown-two-sided-uncertainty/&#34;&gt;when to introduce them&lt;/a&gt;.
On the one hand, acting early may prevent the virus from spreading uncontrollably; on the other, delaying action allows policymakers to collect more information about the virus and the policies best suited to combat it.&lt;/p&gt;
&lt;p&gt;This post compares two approaches to policymaking under uncertainty: &amp;ldquo;commit early,&amp;rdquo; and &amp;ldquo;wait and learn.&amp;rdquo;
These approaches highlight the trade-off between acting decisively and &lt;a href=&#34;https://bldavies.com/blog/option-value-waiting/&#34;&gt;waiting for more information&lt;/a&gt;.
I discuss this trade-off in the context of the New Zealand (NZ) government&amp;rsquo;s response to COVID-19.
However, my discussion also applies in other (non-NZ and non-pandemic) contexts.&lt;/p&gt;
&lt;p&gt;To frame my discussion, consider a policymaker (PM) in a world with three time periods.
Each period, the world moves into one of many &amp;ldquo;states&amp;rdquo; that partition the set of possible futures (e.g., &amp;ldquo;recession&amp;rdquo; and &amp;ldquo;no recession&amp;rdquo;).
Moving between the first and second periods provides more, but not complete, information about the probability distribution of period three states.
The PM can influence this distribution by implementing policies in the first or second period.&lt;/p&gt;
&lt;p&gt;Under the &amp;ldquo;commit early&amp;rdquo; approach, the PM implements policies in the first period based solely on information available in that period.
To the extent that these policies are expensive and irreversible, their implementation signals the PM&amp;rsquo;s confidence in the policies&amp;rsquo; necessity and efficacy.
This signal can help prevent public dissent.
For example, NZ&amp;rsquo;s relatively early transition to &lt;a href=&#34;https://covid19.govt.nz/alert-system/covid-19-alert-system/&#34;&gt;COVID-19 Alert Level&lt;/a&gt; 4 signalled our government&amp;rsquo;s strong belief that the cost of letting the virus spread outweighed the cost of entering a nationwide lockdown.
This signal probably made New Zealanders more willing to tolerate the consequences of staying home&amp;mdash;they were told, in no uncertain terms, that doing so would &amp;ldquo;save lives.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Committing early also provides information about future conditions to households and firms, who may be less informed than the PM about the distribution of future states.
For example, one of the NZ government&amp;rsquo;s earliest actions during the COVID-19 pandemic was to implement a &lt;a href=&#34;https://www.employment.govt.nz/leave-and-holidays/other-types-of-leave/coronavirus-workplace/wage-subsidy/&#34;&gt;wage subsidy scheme&lt;/a&gt; that provided 12 weeks of financial support to firms and their employees.
The scheme signalled that our government expected the economic downturn caused by the virus to last at least 12 weeks.
This signal allowed households and firms to calibrate their expectations about, and adjust their behaviour to prepare for, the future.&lt;/p&gt;
&lt;p&gt;One problem with the &amp;ldquo;commit early&amp;rdquo; approach is that the PM may commit to policies that appear optimal &lt;em&gt;ex ante&lt;/em&gt; but turn out to be sub-optimal &lt;em&gt;ex post&lt;/em&gt;.
As time passes, the PM gains more information about the distribution of future states and about which policies are most likely to deliver favourable states.
Consequently, the PM may end up regretting committing to, and paying for, policies they wouldn&amp;rsquo;t have chosen if they had waited for more information.&lt;/p&gt;
&lt;p&gt;This regret can be avoided by adopting a &amp;ldquo;wait and learn&amp;rdquo; approach.
Under this approach, the PM delays implementing policies until more information about their relative merits arrives in the second period.
This delay allows the PM to preserve the &lt;a href=&#34;https://en.wikipedia.org/wiki/Real_options_valuation&#34;&gt;real options&lt;/a&gt; that would otherwise be destroyed by implementing irreversible policies in the first period.
For example, delaying wage subsidy payouts until the economic impacts of COVID-19 were clearer may have allowed the NZ government to avoid &lt;a href=&#34;https://www.stuff.co.nz/business/121254612/coronavirus-business-owner-pockets-150000-from-government-wage-subsidy-and-hes-not-paying-it-back&#34;&gt;giving money to businesses that didn&amp;rsquo;t need it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, delaying policy decisions may also delay decisions made by households and firms, who rely on policies as coordination devices.
For example, delaying the decision to allow inter-regional transport may delay freight companies&amp;rsquo; decisions to schedule inter-regional shipments, which, in turn, delays production decisions by firms with inter-regional supply chains.
These supply-side delays may induce undesirable demand-side responses, such as &lt;a href=&#34;https://www.rnz.co.nz/news/national/412425/supermarkets-urge-people-to-stop-panic-buying&#34;&gt;&amp;ldquo;panic buying&amp;rdquo; food and homeware&lt;/a&gt;.
The more peoples&amp;rsquo; decisions depend on others&amp;rsquo; decisions, the more the PM&amp;rsquo;s initial delay spreads throughout the economy and the more disruptive that delay becomes.&lt;/p&gt;
&lt;p&gt;Delaying policy decisions also allows the costs of indecision (e.g., deaths from uncontrolled exposure to COVID-19) to accumulate.
The PM must trade these costs off with the benefits of waiting for more information.
These benefits may appear large &lt;em&gt;ex ante&lt;/em&gt; but turn out to be small &lt;em&gt;ex post&lt;/em&gt;.
Moving into the second period may not change the PM&amp;rsquo;s preferences over policy options if the new information merely confirms what was already known in the first period.
This confirmation may make the PM believe that they accrued the costs of delaying action unnecessarily.
Thus, whereas the &amp;ldquo;commit early&amp;rdquo; approach induces regret when initial estimates turn out to be wrong, the &amp;ldquo;wait and learn&amp;rdquo; approach induces regret when initial estimates turn out to be right.&lt;/p&gt;
&lt;p&gt;Although committing early destroys some real options, it may create other real options in their place.
For example, NZ&amp;rsquo;s early lockdown likely prevented the virus from overburdening our healthcare providers, giving them time to plan and prepare for a range of future COVID-19 scenarios.
Similarly, our government&amp;rsquo;s &lt;a href=&#34;https://www.beehive.govt.nz/release/govt-backs-rbnz-move-support-economy-lower-interest-rates&#34;&gt;agreement to let the Reserve Bank buy government bonds&lt;/a&gt; gave the Bank more flexibility to provide monetary stimulus if the need arises.
In both cases, taking early, decisive action opened paths that may have been unavailable if our government had chosen to wait and learn.&lt;/p&gt;
&lt;p&gt;Ultimately, the PM should adopt the &amp;ldquo;commit early&amp;rdquo; approach whenever the net benefits of acting early exceed the net benefits of waiting.
However, valuing these net benefits requires&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;estimating the likelihood and quality of future states,&lt;/li&gt;
&lt;li&gt;choosing a (politically defensible) rate at which to discount future payoffs, and&lt;/li&gt;
&lt;li&gt;valuing changes in net optionality.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These three requirements raise the complexity of the PM&amp;rsquo;s choice problem and the cognitive cost of finding its solution.
Such &lt;a href=&#34;https://en.wikipedia.org/wiki/Bounded_rationality&#34;&gt;bounds&lt;/a&gt; on the PM&amp;rsquo;s rationality may lead to sub-optimal policy decisions, both &lt;em&gt;ex ante&lt;/em&gt; and &lt;em&gt;ex post&lt;/em&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Thanks to my dad for inspiring this post and to &lt;a href=&#34;https://motu.nz/about-us/people/arthur-grimes/&#34;&gt;Arthur Grimes&lt;/a&gt; for his comments.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Transitivity in positive correlations</title>
      <link>https://bldavies.com/blog/transitivity-positive-correlations/</link>
      <pubDate>Fri, 24 Apr 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/transitivity-positive-correlations/</guid>
      <description>&lt;p&gt;Let &lt;code&gt;\(X\)&lt;/code&gt;, &lt;code&gt;\(Y\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt; be random variables.
Suppose that both &lt;code&gt;\(X\)&lt;/code&gt; and &lt;code&gt;\(Y\)&lt;/code&gt; are positively correlated with &lt;code&gt;\(Z\)&lt;/code&gt;.
Are &lt;code&gt;\(X\)&lt;/code&gt; and &lt;code&gt;\(Y\)&lt;/code&gt; positively correlated?&lt;/p&gt;
&lt;p&gt;The answer to this question is &amp;ldquo;not necessarily.&amp;rdquo;
To see why, let &lt;code&gt;\(\rho\in[-1,1]\)&lt;/code&gt; be a constant, and define the random variables
&lt;code&gt;$$X=\rho Z+W \tag{1}$$&lt;/code&gt;
and
&lt;code&gt;$$Y=\rho Z-W \tag{2}$$&lt;/code&gt;
with &lt;code&gt;\(Z\sim N(0,1)\)&lt;/code&gt; and &lt;code&gt;\(W\sim N(0,1-\rho^2)\)&lt;/code&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Then &lt;code&gt;\(W\)&lt;/code&gt;, &lt;code&gt;\(X\)&lt;/code&gt;, &lt;code&gt;\(Y\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt; have zero means, while &lt;code&gt;\(X\)&lt;/code&gt;, &lt;code&gt;\(Y\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt; have unit variances.
It follows that
&lt;code&gt;$$\begin{align} \newcommand{\E}{\mathrm{E}} \newcommand{\Corr}{\mathrm{Corr}} \newcommand{\Cov}{\mathrm{Cov}} \newcommand{\Var}{\mathrm{Var}} \Corr(X,Y) &amp;amp;= \frac{\Cov(X,Y)}{\sqrt{\Var(X)}\sqrt{\Var(Y)}} \\ &amp;amp;= \Cov(X,Y) \\ &amp;amp;= \E[XY]-\E[X]\E[Y] \\ &amp;amp;= \E[XY], \end{align}$$&lt;/code&gt;
and similarly &lt;code&gt;\(\Corr(X,Z)=\E[XZ]\)&lt;/code&gt; and &lt;code&gt;\(\Corr(Y,Z)=\E[YZ]\)&lt;/code&gt;.
Now
&lt;code&gt;$$\begin{align} \E[XZ] &amp;amp;= \E[(\rho Z+W)Z] \\ &amp;amp;= \rho\E[Z^2]+\E[WZ] \\ &amp;amp;= \rho\Var(Z)+\rho\E[Z]^2+\Cov(W,Z)+\E[W]\E[Y] \\ &amp;amp;= \rho \end{align}$$&lt;/code&gt;
because &lt;code&gt;\(W\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt; are independent.
A similar argument yields &lt;code&gt;\(\E[YZ]=\rho\)&lt;/code&gt;.
Finally, substituting &lt;code&gt;\((1)\)&lt;/code&gt; into &lt;code&gt;\((2)\)&lt;/code&gt; so as to eliminate &lt;code&gt;\(W\)&lt;/code&gt; gives
&lt;code&gt;$$Y=2\rho Z-X,$$&lt;/code&gt;
from which we obtain
&lt;code&gt;$$\begin{align} \Corr(X,Y) &amp;amp;= \E[XY] \\ &amp;amp;= \E[X(2\rho Z-X)] \\ &amp;amp;= 2\rho\E[XZ]-\E[X^2] \\ &amp;amp;= 2\rho\E[XZ]-\Var(X)+\E[X]^2 \\ &amp;amp;= 2\rho^2-1. \end{align}$$&lt;/code&gt;
Thus, if &lt;code&gt;\(\rho\in(0,1/\sqrt{2})\)&lt;/code&gt; then &lt;code&gt;\(X\)&lt;/code&gt; and &lt;code&gt;\(Y\)&lt;/code&gt; share a negative correlation even though both are correlated positively with &lt;code&gt;\(Z\)&lt;/code&gt;.
Intuitively, if &lt;code&gt;\(\rho\)&lt;/code&gt; is sufficiently small then the negative correlation between the error terms &lt;code&gt;\(W\)&lt;/code&gt; and &lt;code&gt;\(-W\)&lt;/code&gt; dominates the positive correlations between &lt;code&gt;\(X\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt;, and &lt;code&gt;\(Y\)&lt;/code&gt; and &lt;code&gt;\(Z\)&lt;/code&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Here &lt;code&gt;\(N(\mu,\sigma^2)\)&lt;/code&gt; denotes the normal distribution with mean &lt;code&gt;\(\mu\)&lt;/code&gt; and variance &lt;code&gt;\(\sigma^2\)&lt;/code&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Greedy Pig strategies</title>
      <link>https://bldavies.com/blog/greedy-pig-strategies/</link>
      <pubDate>Sat, 18 Apr 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/greedy-pig-strategies/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://nzmaths.co.nz/resource/greedy-pig-1&#34;&gt;Greedy Pig&lt;/a&gt; is a game used to teach probability and statistics to primary school students.
The game comprises a set of rounds in which players roll a fair six-sided die until they choose to stop, in which case their score for that round is equal to the sum of rolled values, or they roll a one, in which case their score for that round is zero.
The player with the highest total score across all rounds wins.&lt;/p&gt;
&lt;p&gt;Since the scores obtained in each round are independent, players can maximise their total score across all rounds by maximising their score in each round independently.
One strategy is to commit to rolling the die &lt;code&gt;\(n\)&lt;/code&gt; times in each round, where &lt;code&gt;\(n\)&lt;/code&gt; is chosen to maximise the expected resulting score.
We can make this choice as follows.
First, let &lt;code&gt;\(X_k\)&lt;/code&gt; be the outcome of the &lt;code&gt;\(k^\text{th}\)&lt;/code&gt; die roll.
This outcome has probability distribution
&lt;code&gt;$$\Pr(X_k=x)=\begin{cases}1/6&amp;amp;\text{if}\ x\in\{1,2,3,4,5,6\}\\ 0&amp;amp;\text{otherwise}.\end{cases}$$&lt;/code&gt;
Next, let &lt;code&gt;\(1_{X_k&amp;gt;1}\)&lt;/code&gt; be the indicator variable for the event in which &lt;code&gt;\(X_k&amp;gt;1\)&lt;/code&gt;.
Then the score after &lt;code&gt;\(n\)&lt;/code&gt; rolls is given by
&lt;code&gt;$$S_n=\sum_{k=1}^nX_k\pi_n,$$&lt;/code&gt;
where
&lt;code&gt;$$\pi_n=\prod_{k=1}^n1_{X_k&amp;gt;1}$$&lt;/code&gt;
is the indicator variable for the event in which all of the first &lt;code&gt;\(n\)&lt;/code&gt; rolls exceed unity.
Now, by the linearity of the expectation operator and the &lt;a href=&#34;https://en.wikipedia.org/wiki/Law_of_total_expectation&#34;&gt;law of total expectation&lt;/a&gt;, the score &lt;code&gt;\(S_n\)&lt;/code&gt; has expected value
&lt;code&gt;$$\begin{align} \mathrm{E}[S_n] &amp;amp;= \sum_{k=1}^n\mathrm{E}[X_k\pi_n] \\ &amp;amp;= \sum_{k=1}^n\left(\mathrm{E}[X_k\pi_n\,\vert\,\pi_n=1]\Pr(\pi_n=1)+\mathrm{E}[X_k\pi_n\,\vert\,\pi_n=0]\Pr(\pi_n=0)\right) \\ &amp;amp;= \sum_{k=1}^n\mathrm{E}[X_k\,\vert\,\pi_n=1]\Pr(\pi_n=1). \end{align}$$&lt;/code&gt;
Since &lt;code&gt;\(\pi_n=1\)&lt;/code&gt; if and only if &lt;code&gt;\(X_k&amp;gt;1\)&lt;/code&gt; for each &lt;code&gt;\(k\in\{1,2,\ldots,n\}\)&lt;/code&gt;, and since die rolls are independent, we have
&lt;code&gt;$$\begin{align} \mathrm{E}[X_k\,\vert\,\pi_n=1] &amp;amp;= \mathrm{E}[X_k\,\vert\,X_k&amp;gt;1] \\ &amp;amp;= \frac{2+3+4+5+6}{5} \\ &amp;amp;= 4 \end{align}$$&lt;/code&gt;
and
&lt;code&gt;$$\Pr(\pi_n=1)=\left(\frac{5}{6}\right)^n.$$&lt;/code&gt;
Hence
&lt;code&gt;$$\mathrm{E}[S_n]=4n\left(\frac{5}{6}\right)^n$$&lt;/code&gt;
for each &lt;code&gt;\(n\)&lt;/code&gt;, which obtains its maximum value of 8.04 when &lt;code&gt;\(n\in\{5,6\}\)&lt;/code&gt;.
Therefore, players who commit to a fixed number of rolls should commit to five or six rolls in each round to maximise their expected score.&lt;/p&gt;
&lt;p&gt;Another strategy is to continue rolling until reaching some target score &lt;code&gt;\(S^*\)&lt;/code&gt;.
This strategy allows players to respond to their realised sequence of rolls.
Intuitively, players who realise a run of high-value rolls have more to lose by rolling again and so may be less willing to do so.
To determine the value of &lt;code&gt;\(S^*\)&lt;/code&gt;, let &lt;code&gt;\(Y_k\)&lt;/code&gt; denote the payoff from the &lt;code&gt;\(k^\text{th}\)&lt;/code&gt; roll and notice that this payoff has expected value
&lt;code&gt;$$\begin{align} \mathrm{E}[Y_k] &amp;amp;= \mathrm{E}[X_k\,\vert\,X_k&amp;gt;1]\Pr(X_k&amp;gt;1)-S_{k-1}\Pr(X_k=1) \\ &amp;amp;= \frac{20-S_{k-1}}{6}. \end{align}$$&lt;/code&gt;
Thus, rolling again delivers a positive expected payoff if and only if &lt;code&gt;\(S_{k-1}&amp;lt;20\)&lt;/code&gt;, and so players seeking to maximise their expected score should stop rolling when their score reaches &lt;code&gt;\(S^*=20\)&lt;/code&gt;.
This argument also clarifies why both &lt;code&gt;\(n=5\)&lt;/code&gt; and &lt;code&gt;\(n=6\)&lt;/code&gt; maximise &lt;code&gt;\(\mathrm{E}[S_n]\)&lt;/code&gt;: players with a non-zero score after five rolls have a conditional expected score of &lt;code&gt;\(\mathrm{E}[S_5\,\vert\,\pi_5=1]=20\)&lt;/code&gt;, so the expected gain in score for such players from a sixth roll is zero.&lt;/p&gt;
&lt;p&gt;We can compare the &amp;ldquo;roll five times&amp;rdquo; and &amp;ldquo;stop at 20&amp;rdquo; strategies via simulation.
First, define a function &lt;code&gt;simulate_strategy&lt;/code&gt; that takes as arguments either a fixed number of rolls &lt;code&gt;n&lt;/code&gt; or a target score &lt;code&gt;t&lt;/code&gt;, and simulates the player&amp;rsquo;s score from adopting their chosen strategy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;simulate_strategy&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;NULL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;NULL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;if &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;is.null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;stop&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;`n` or `t` must be non-NULL&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;done&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;F&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;while &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;done&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sample&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;if &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;done&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;done&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;ifelse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;score&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next, define two wrapper functions for simulating each strategy separately:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;simulate_n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;simulate_strategy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;simulate_t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;simulate_strategy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we can simulate 10,000 games using each strategy and store the realised scores:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;scores_n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sapply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1e4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;simulate_n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;scores_t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sapply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1e4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;simulate_t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &amp;ldquo;stop at 20&amp;rdquo; strategy delivers a mean score of 8.13, which is 1.69% higher than the mean score delivered by the &amp;ldquo;roll five times&amp;rdquo; strategy.
However, the &amp;ldquo;stop at 20&amp;rdquo; strategy is also 4.12% more likely to deliver a score of zero than the &amp;ldquo;roll five times&amp;rdquo; strategy.
We can see this by plotting the distributions of simulated scores delivered by the two strategies:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ggplot2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;`Roll five times`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scores_n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;`Stop at 20`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scores_t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;gather&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Strategy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Score&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Strategy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Score&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggplot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Score&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1e4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_col&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fill&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Strategy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.75&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;position&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;dodge&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;labs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Relative frequency&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
       &lt;span class=&#34;n&#34;&gt;title&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Comparing Greedy Pig strategies&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
       &lt;span class=&#34;n&#34;&gt;subtitle&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Distribution of scores across 10,000 simulated games&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/distributions-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The distribution of non-zero scores under the &amp;ldquo;stop at 20&amp;rdquo; strategy is asymmetric about its conditional mean of 21.69, and is bounded below by 20 and above by 25.
In contrast, the distribution of non-zero scores under the &amp;ldquo;roll five times&amp;rdquo; strategy is symmetric about its conditional mean of 20, and is bounded below by 10 and above by 30.&lt;/p&gt;
&lt;p&gt;The &amp;ldquo;roll five times&amp;rdquo; and &amp;ldquo;stop at 20&amp;rdquo; strategies are heuristics for maximising players&amp;rsquo; scores in each round.
These heuristics may be sub-optimal in some situations.
For example, if one player remains in the last round and has accumulated enough total score to win the game then they should always stop rolling.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Generating random graphs with communities</title>
      <link>https://bldavies.com/blog/generating-random-graphs-communities/</link>
      <pubDate>Tue, 07 Apr 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/generating-random-graphs-communities/</guid>
      <description>&lt;p&gt;Suppose I want to generate some random graphs that exhibit &lt;a href=&#34;https://en.wikipedia.org/wiki/Community_structure&#34;&gt;community structure&lt;/a&gt;.
For example, I might be interested in simulating how information or diseases spread in social networks, and I suspect&amp;mdash;but lack data to confirm&amp;mdash;that people sort into communities based on their personal and professional interests.&lt;/p&gt;
&lt;p&gt;One approach is to use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Stochastic_block_model&#34;&gt;stochastic block model&lt;/a&gt;.
In this model, each vertex belongs to one of &lt;code&gt;\(r\)&lt;/code&gt; disjoint communities &lt;code&gt;\(C_1,C_2,\ldots,C_r\)&lt;/code&gt;, and vertices &lt;code&gt;\(u\in C_i\)&lt;/code&gt; and &lt;code&gt;\(v\in C_j\)&lt;/code&gt; are adjacent with probability &lt;code&gt;\(p_{ij}\)&lt;/code&gt;.
Varying &lt;code&gt;\(p_{ij}\)&lt;/code&gt; across &lt;code&gt;\((i,j)\)&lt;/code&gt; pairs varies the level of connectivity within and between communities.
For example, choosing
&lt;code&gt;$$p_{ij}=\begin{cases} p &amp;amp; \text{if}\ i=j \\ q &amp;amp; \text{otherwise} \end{cases}$$&lt;/code&gt;
for some probabilities &lt;code&gt;\(p\)&lt;/code&gt; and &lt;code&gt;\(q&amp;lt;p\)&lt;/code&gt; delivers random graphs that tend to contain more edges within communities than between communities.
We can simulate this special case&amp;mdash;known as the &amp;ldquo;planted partition model&amp;rdquo; (PPM)&amp;mdash;in R using the &lt;code&gt;sample_ppm&lt;/code&gt; function defined below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;sample_ppm&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;memb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;combn&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;seq_along&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;memb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;prob&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;[1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;memb[mat[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;memb[mat[&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;el&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mat&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;[which&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;runif&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;nrow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;prob&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;graph_from_edgelist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;el&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;FALSE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;sample_ppm&lt;/code&gt; takes as arguments a vector &lt;code&gt;memb&lt;/code&gt; of community memberships, and the edge probabilities &lt;code&gt;\(p\)&lt;/code&gt; and &lt;code&gt;\(q\)&lt;/code&gt;.
The function constructs a matrix &lt;code&gt;mat&lt;/code&gt; of vertex pairs, determines the probabilities that these pairs are adjacent, and uses these probabilities to create a random edge list &lt;code&gt;el&lt;/code&gt; and corresponding random graph.&lt;/p&gt;
&lt;p&gt;For example, let&amp;rsquo;s simulate a PPM random graph with 50 vertices and four communities, and with edge probabilities &lt;code&gt;\(p=1/3\)&lt;/code&gt; and &lt;code&gt;\(q=0.01\)&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;memb&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sample&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;50&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;replace&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sample_ppm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;memb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.01&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can visualise &lt;code&gt;G&lt;/code&gt; using &lt;a href=&#34;https://cran.r-project.org/package=ggraph&#34;&gt;ggraph&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ggraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ggraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_edge_link0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;colour&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;grey75&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;geom_node_point&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;aes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;col&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;factor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;memb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;show.legend&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;FALSE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;scale_colour_brewer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;palette&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Set1&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;theme_void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;figures/network-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The communities in &lt;code&gt;G&lt;/code&gt;&amp;mdash;identified by vertices&amp;rsquo; colours&amp;mdash;contain many internal edges but few external edges.
Thus, if informed or infected vertices spread information or disease among their neighbours with equal probabilities, then we would expect faster diffusion within communities than between communities.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Insurance and saving</title>
      <link>https://bldavies.com/blog/insurance-saving/</link>
      <pubDate>Fri, 03 Apr 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/insurance-saving/</guid>
      <description>&lt;p&gt;The seminal model of insurance demand (&lt;a href=&#34;https://www.jstor.org/stable/1812044&#34;&gt;Arrow, 1963&lt;/a&gt;; &lt;a href=&#34;https://www.jstor.org/stable/1830049&#34;&gt;Mossin, 1968&lt;/a&gt;) describes a consumer who chooses the level of coverage &lt;code&gt;\(I^*\)&lt;/code&gt; that maximises their expected utility
&lt;code&gt;$$\phi(I)=(1-p)u(Y-\pi I)+pu(Y-\pi I-L+I),$$&lt;/code&gt;
where
&lt;code&gt;\(p\)&lt;/code&gt; is the probability of suffering a binary loss of fixed size &lt;code&gt;\(L\)&lt;/code&gt;,
&lt;code&gt;\(Y\)&lt;/code&gt; is the consumer&amp;rsquo;s riskless income,
&lt;code&gt;\(u\)&lt;/code&gt; is their increasing and concave utility function,
and &lt;code&gt;\(\pi\)&lt;/code&gt; is the per-unit price of insurance.
In this model, the consumer buys full insurance (i.e., chooses &lt;code&gt;\(I^*=L\)&lt;/code&gt;) if and only if the premium is actuarially fair (i.e., if &lt;code&gt;\(\pi=p\)&lt;/code&gt;), and their demand for insurance decreases with income if their &lt;a href=&#34;https://en.wikipedia.org/wiki/Risk_aversion#Absolute_risk_aversion&#34;&gt;absolute risk aversion&lt;/a&gt; decreases with wealth.&lt;/p&gt;
&lt;p&gt;A more realistic model would contain at least two periods:
one in which the consumer buys insurance and
one in which they might suffer an insurable loss.
However, in a two-period model, the consumer suffers a form of &lt;a href=&#34;https://en.wikipedia.org/wiki/Incomplete_markets&#34;&gt;market incompleteness&lt;/a&gt;:
they can buy insurance to shift income into the future, but they cannot do the opposite nor vary their net income in the future no-loss state.&lt;/p&gt;
&lt;p&gt;This market incompleteness can be resolved by allowing the consumer to save or borrow at the riskless interest rate.
Then they can save or borrow to smooth income across time, and buy insurance to smooth income across future states of nature.
In particular, they can choose the level of coverage &lt;code&gt;\(I^*\)&lt;/code&gt; and savings commitment &lt;code&gt;\(S^*\)&lt;/code&gt; that maximise their expected utility
&lt;code&gt;$$\begin{align} \psi(I,S) &amp;amp;= u(Y_1-\pi I-S) \\ &amp;amp;\quad+\delta[(1-p)u(Y_2+(1+R)S)+pu(Y_2+(1+R)S-L+I)], \end{align}$$&lt;/code&gt;
where
&lt;code&gt;\(Y_1\)&lt;/code&gt; and &lt;code&gt;\(Y_2\)&lt;/code&gt; are the consumer&amp;rsquo;s riskless incomes in the first and second periods,
&lt;code&gt;\(\delta\in(0,1]\)&lt;/code&gt; is their intertemporal discount factor, and
&lt;code&gt;\(R\)&lt;/code&gt; is the riskless interest rate.
In this two-period model, the consumer buys full insurance if and only if
&lt;code&gt;$$\pi=\frac{p}{1+R},$$&lt;/code&gt;
which is the two-period equivalent of the actuarially fair premium rate.
One can also show that
if the consumer cannot save then &lt;code&gt;\(I^*\)&lt;/code&gt; is increasing in &lt;code&gt;\(Y_1\)&lt;/code&gt; and decreasing in &lt;code&gt;\(Y_2\)&lt;/code&gt;, but
if they can save then increases in &lt;code&gt;\(Y_1\)&lt;/code&gt; and &lt;code&gt;\(Y_2\)&lt;/code&gt; shift &lt;code&gt;\(I^*\)&lt;/code&gt; in the same direction as they shift the consumer&amp;rsquo;s absolute risk aversion.
Intuitively, if the consumer cannot save and they want to shift income into the future then the only way to do so is to buy more insurance.
In contrast, if the consumer can save then they can use their savings commitment to smooth increases in income across time, and adjust their insurance demand according to whether such increases make them more or less absolute risk averse.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Optimal training loads</title>
      <link>https://bldavies.com/blog/optimal-training-loads/</link>
      <pubDate>Mon, 30 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/optimal-training-loads/</guid>
      <description>&lt;p&gt;Suppose I&amp;rsquo;m training for an upcoming race.
I want to choose the training load that maximises my expected performance on race day.
The harder I train, the better my performance will be but the more likely I am to injure myself.
How should I balance this trade-off between better performance and greater risk of injury?&lt;/p&gt;
&lt;p&gt;We can model this choice problem as follows.
Let &lt;code&gt;\(t\in[0,1]\)&lt;/code&gt; represent my training load and &lt;code&gt;\(a\in\mathbb{R}\)&lt;/code&gt; my natural ability.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
My performance on race day is some function &lt;code&gt;\(f(t,a)\)&lt;/code&gt; of &lt;code&gt;\(t\)&lt;/code&gt; and &lt;code&gt;\(a\)&lt;/code&gt;.
I assume that this function is increasing and concave in &lt;code&gt;\(t\)&lt;/code&gt; (so that there are positive but diminishing returns to training), and increasing in &lt;code&gt;\(a\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I can&amp;rsquo;t compete if I get injured, which occurs with some probability &lt;code&gt;\(p(t,r)\)&lt;/code&gt; that depends on my training load and my natural resistance to injury &lt;code&gt;\(r\in\mathbb{R}\)&lt;/code&gt;.
I assume that &lt;code&gt;\(p\)&lt;/code&gt; is increasing and convex in &lt;code&gt;\(t\)&lt;/code&gt; (so that training increases my likelihood of injury at an increasing rate), and decreasing in &lt;code&gt;\(r\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My objective is to choose the training load &lt;code&gt;\(t^*\)&lt;/code&gt; that maximises my expected performance&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
&lt;code&gt;$$\psi(t)=(1-p(t,r))\,f(t,a).$$&lt;/code&gt;
My assumptions on the shapes of &lt;code&gt;\(f\)&lt;/code&gt; and &lt;code&gt;\(p\)&lt;/code&gt; imply that &lt;code&gt;\(\psi\)&lt;/code&gt; is concave in &lt;code&gt;\(t\)&lt;/code&gt;.
Therefore, the unique optimal training load &lt;code&gt;\(t^*\)&lt;/code&gt; satisfies the first-order condition (FOC)
&lt;code&gt;$$\begin{align} 0 &amp;amp;= \psi&#39;(t^*) \\ &amp;amp;= -p_t(t^*,r)\,f(t^*,a)+(1-p(t^*,r))\,f_t(t^*,a), \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\psi&#39;\)&lt;/code&gt; denotes the derivative of &lt;code&gt;\(\psi\)&lt;/code&gt; with respect to &lt;code&gt;\(t\)&lt;/code&gt;, and
where &lt;code&gt;\(p_t\)&lt;/code&gt; and &lt;code&gt;\(f_t\)&lt;/code&gt; denote the partial derivatives of &lt;code&gt;\(p\)&lt;/code&gt; and &lt;code&gt;\(f\)&lt;/code&gt; with respect to &lt;code&gt;\(t\)&lt;/code&gt;.
The FOC can be rewritten as
&lt;code&gt;$$(1-p(t^*,r))\,f_t(t^*,a)=p_t(t^*,r)f(t^*,a),$$&lt;/code&gt;
which shows that I should keep training until the marginal benefit of improved performance (the left-hand side) equals the marginal cost of injury becoming more probable (the right-hand side).&lt;/p&gt;
&lt;p&gt;I can&amp;rsquo;t determine the value of &lt;code&gt;\(t^*\)&lt;/code&gt; without further assumptions on &lt;code&gt;\(f\)&lt;/code&gt; and &lt;code&gt;\(p\)&lt;/code&gt;.
However, I can determine the relationship between &lt;code&gt;\(t^*\)&lt;/code&gt; and the parameters &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(r\)&lt;/code&gt;.
Since &lt;code&gt;\(\psi&#39;&#39;(t)&amp;lt;0\)&lt;/code&gt; for all feasible &lt;code&gt;\(t\)&lt;/code&gt;, the &lt;a href=&#34;https://en.wikipedia.org/wiki/Implicit_function_theorem&#34;&gt;implicit function theorem&lt;/a&gt; (IFT) implies that
&lt;code&gt;$$\mathrm{sign}\frac{\partial t^*}{\partial \theta}=\mathrm{sign}\frac{\partial \psi&#39;(t^*)}{\partial \theta}$$&lt;/code&gt;
for each element &lt;code&gt;\(\theta\)&lt;/code&gt; of the symbol set &lt;code&gt;\(\{a,r\}\)&lt;/code&gt;.
Now
&lt;code&gt;$$\frac{\partial \psi&#39;(t^*)}{\partial a}=-p_t(t^*,r)\,f_a(t^*,a)+(1-p(t^*,r))\,f_{ta}(t^*,a),$$&lt;/code&gt;
where &lt;code&gt;\(f_a\)&lt;/code&gt; and &lt;code&gt;\(f_{ta}\)&lt;/code&gt; denote the partial derivatives of &lt;code&gt;\(f\)&lt;/code&gt; and &lt;code&gt;\(f_t\)&lt;/code&gt; with respect to &lt;code&gt;\(a\)&lt;/code&gt;, and
&lt;code&gt;$$\frac{\partial \psi&#39;(t^*)}{\partial r}=-p_{tr}(t^*,r)\,f(t^*,a)-p_r(t^*,r)\,f_t(t^*,a),$$&lt;/code&gt;
where &lt;code&gt;\(p_{tr}\)&lt;/code&gt; and &lt;code&gt;\(p_r\)&lt;/code&gt; denote the partial derivatives of &lt;code&gt;\(p_t\)&lt;/code&gt; and &lt;code&gt;\(p\)&lt;/code&gt; with respect to &lt;code&gt;\(r\)&lt;/code&gt;.
By &lt;a href=&#34;https://en.wikipedia.org/wiki/Symmetry_of_second_derivatives&#34;&gt;Young&amp;rsquo;s theorem&lt;/a&gt;, the mixed partials &lt;code&gt;\(f_{ta}\)&lt;/code&gt; and &lt;code&gt;\(p_{tr}\)&lt;/code&gt; satisfy
&lt;code&gt;$$f_{ta}(t,a)=\frac{\partial}{\partial t}\left(\frac{\partial f(t,a)}{\partial a}\right)$$&lt;/code&gt;
and
&lt;code&gt;$$p_{tr}(t,r)=\frac{\partial}{\partial t}\left(\frac{\partial p(t,r)}{\partial r}\right)$$&lt;/code&gt;
for all feasible &lt;code&gt;\(t\)&lt;/code&gt;, &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(r\)&lt;/code&gt;.
Thus, it seems reasonable to assume that &lt;code&gt;\(f_{ta}(t,a)\le0\)&lt;/code&gt; and &lt;code&gt;\(p_{tr}(t,r)\le0\)&lt;/code&gt;, which mean that training washes out the benefits of natural ability and resistance to injury.
These assumptions, together with the IFT, imply that &lt;code&gt;\(t^*\)&lt;/code&gt; is decreasing in &lt;code&gt;\(a\)&lt;/code&gt; and increasing in &lt;code&gt;\(r\)&lt;/code&gt;&amp;mdash;that is, I should train harder if I become less naturally able or more resistant to injury.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;For example, &lt;code&gt;\(t\)&lt;/code&gt; could represent the proportion of time before the race that I spend training. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I assume that &lt;code&gt;\(f\)&lt;/code&gt; and &lt;code&gt;\(p\)&lt;/code&gt; are twice continuously differentiable so that &lt;code&gt;\(\psi\)&lt;/code&gt; is too. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Voting along party lines</title>
      <link>https://bldavies.com/blog/voting-along-party-lines/</link>
      <pubDate>Thu, 26 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/voting-along-party-lines/</guid>
      <description>&lt;p&gt;Later this year, New Zealanders will vote in a referendum on whether to legalise voluntary euthanasia under the conditions specified in the &lt;a href=&#34;http://www.legislation.govt.nz/bill/member/2017/0269/latest/DLM7285905.html&#34;&gt;End of Life Choice Bill&lt;/a&gt; (hereafter &amp;ldquo;the Bill&amp;rdquo;).
Members of Parliament (MPs) read the Bill three times, each time holding a &lt;a href=&#34;https://en.wikipedia.org/wiki/Conscience_vote&#34;&gt;conscience vote&lt;/a&gt; on whether to progress the Bill towards becoming legislation.
The table below presents the percentage and fraction of MPs who voted in favour of the Bill, separated by political party and reading.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Party&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;First reading&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Second reading&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Third reading&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Act&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Green&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (8/8)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (8/8)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (8/8)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Independent&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (1/1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Labour&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;80% (37/46)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;72% (33/46)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;72% (33/46)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;National&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;36% (20/55)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;33% (18/55)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;29% (16/55)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;NZ First&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (9/9)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (9/9)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;100% (9/9)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Most MPs in the coalition government voted in favour, including all MPs from the Green Party and NZ First.
In the Bill&amp;rsquo;s final reading, 72% of Labour MPs followed party leader Jacinda Ardern&amp;rsquo;s vote in favour, while 71% of National MPs followed party leader Simon Bridges&amp;rsquo; vote to oppose.
Overall, about a third of Labour and National MPs voted against their party lines.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;New Zealand uses a &lt;a href=&#34;https://en.wikipedia.org/wiki/Mixed-member_proportional_representation&#34;&gt;mixed member proportional&lt;/a&gt; electoral system:
voters submit votes for a political party and for a representative of their local constituency.
Consequently, some &amp;ldquo;list&amp;rdquo; MPs enter parliament because they are ranked highly within a party that received many votes rather than because they were the preferred candidate among their local constituents.
The table below shows that Labour and National list MPs were more likely to vote along party lines than non-list MPs in the Bill&amp;rsquo;s third reading.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Party&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;List MP adherence&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Non-list MP adherence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Labour&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88% (15/17)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;62% (18/29)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;National&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;80% (12/15)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;68% (27/40)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The difference in list and non-list MPs&amp;rsquo; adherence to party lines has at least two explanations.
First, non-list MPs have non-party reasons to be in government&amp;mdash;namely, to serve their local constituents&amp;mdash;and so may accept weaker idealogical matches than list MPs when self-selecting into party affiliations.
This weaker matching would reduce the idealogical polarisation and inertia among non-list MPs relative to list MPs.
Indeed, all of the MPs who changed their votes between the Bill&amp;rsquo;s first and third readings were non-list MPs.&lt;/p&gt;
&lt;p&gt;Second, list MPs have stronger incentives to signal loyalty to their party because they cannot rely on support from local constituents to get elected.
If list MPs consistently oppose their leaders then they may be demoted within their parties and, consequently, become less likely to re-enter parliament at the next election.
Thus, to the extent that MPs want to maximise their chances of re-election, list MPs may be more willing than non-list MPs to ignore their conscience and vote along party lines.&lt;/p&gt;
&lt;p&gt;It would be interesting to separate the idealogical sorting and signalling motives that drive greater adherence among list MPs.
One strategy could be to track individual MPs across votes and governments, and analyse whether their propensity to vote along party lines is greater when they are list MPs than when they are non-list MPs.
However, I can&amp;rsquo;t find any up-to-date vote data online and don&amp;rsquo;t particularly want to create them by trawling through decades worth of &lt;a href=&#34;https://www.parliament.nz/en/pb/hansard-debates/&#34;&gt;Hansard&lt;/a&gt; documents.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
Perhaps one of my readers is up for the challenge?&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The data used in this post are available &lt;a href=&#34;https://github.com/bldavies/eolc-bill/&#34;&gt;here&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This overlap in preferences among Labour and National MPs reflects the idealogical overlap between the two parties at the centre of the political spectrum. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;There was an &lt;a href=&#34;https://web.archive.org/web/20190911021215/http://votes.wotfun.com/&#34;&gt;online database&lt;/a&gt; of conscience votes among New Zealand MPs, but the database was shut down in late 2019 and hadn&amp;rsquo;t been updated since 2012. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Matching runners</title>
      <link>https://bldavies.com/blog/matching-runners/</link>
      <pubDate>Sat, 21 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/matching-runners/</guid>
      <description>&lt;p&gt;Running in pairs (and, more generally, in groups) can be more rewarding than running alone.
Running buddies can motivate each other, share the mental load of maintaining pace, and provide competition and accountability.&lt;/p&gt;
&lt;p&gt;The main problem with running buddies is that they can be hard to find.
Not everyone is a runner, and runners vary in their abilities and training goals.
Moreover, these abilities and goals are mostly unobservable by other runners searching for a buddy.
This unobservable variation creates &amp;ldquo;matching frictions&amp;rdquo; that prevent runners from sorting into &amp;ldquo;optimal&amp;rdquo; pairs.&lt;/p&gt;
&lt;p&gt;If prospective running buddies could observe each others&amp;rsquo; abilities and training goals then they could form preferences over whom they want to be paired with.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Runners could rank potential buddies from most to least prefered, and submit these rankings to a central match-maker (e.g., a team coach) whose task would be to partition the (assumedly even-sized) set of &lt;code&gt;\(2n\)&lt;/code&gt; runners into &lt;code&gt;\(n\)&lt;/code&gt; pairs.
The socially optimal partition &lt;code&gt;\(\mathcal{P}^*\)&lt;/code&gt; would minimise the sum
&lt;code&gt;$$S(\mathcal{P})=\sum_{\{i,j\}\in\mathcal{P}}(x_{ij}+x_{ji}),$$&lt;/code&gt;
where &lt;code&gt;\(x_{ij}\)&lt;/code&gt; is the rank that runner &lt;code&gt;\(i\)&lt;/code&gt; assigns to potential buddy &lt;code&gt;\(j\)&lt;/code&gt;.
Minimising &lt;code&gt;\(S(\mathcal{P})\)&lt;/code&gt; would ensure that, on average, runners are paired with their most preferred buddies.&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(X=(x_{ij})\)&lt;/code&gt; be the matrix of preference rankings and let &lt;code&gt;\(Y=X+X^T\)&lt;/code&gt;.
One way to find &lt;code&gt;\(\mathcal{P^*}\)&lt;/code&gt; would be to choose &lt;code&gt;\(2n\)&lt;/code&gt; entries of &lt;code&gt;\(Y\)&lt;/code&gt; such that
(a) the sum of the chosen entries is minimised, and
(b) each row and column of &lt;code&gt;\(Y\)&lt;/code&gt; contains exactly one chosen entry.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
This choice problem is equivalent to the (balanced) &lt;a href=&#34;https://en.wikipedia.org/wiki/Assignment_problem&#34;&gt;assignment problem&lt;/a&gt;, and can be solved using the &lt;a href=&#34;https://en.wikipedia.org/wiki/Hungarian_algorithm&#34;&gt;Hungarian algorithm&lt;/a&gt; or via linear programming.&lt;/p&gt;
&lt;p&gt;The socially optimal partition &lt;code&gt;\(\mathcal{P^*}\)&lt;/code&gt; of the set of runners into pairs may be &amp;ldquo;unstable:&amp;rdquo; there may exist two runners who would rather run with each other than with their assigned buddies.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
For example, suppose there is a set &lt;code&gt;\(\{a, b, c, d\}\)&lt;/code&gt; of four runners with preference rankings captured by the matrix
&lt;code&gt;$$X=\begin{bmatrix} &amp;amp; 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; &amp;amp; 1 &amp;amp; 3 \\ 1 &amp;amp; 2 &amp;amp; &amp;amp; 3 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; \end{bmatrix}.$$&lt;/code&gt;
The corresponding matrix &lt;code&gt;\(Y=X+X^T\)&lt;/code&gt; of bidirectional sums is
&lt;code&gt;$$Y=\begin{bmatrix} &amp;amp; 3 &amp;amp; 3 &amp;amp; \underline{4} \\ 3 &amp;amp; &amp;amp; \underline{3} &amp;amp; 5 \\ 3 &amp;amp; \underline{3} &amp;amp; &amp;amp; 6 \\ \underline{4} &amp;amp; 5 &amp;amp; 6 &amp;amp; \end{bmatrix},$$&lt;/code&gt;
where the underlined entries correspond to the socially optimal partition &lt;code&gt;\(\mathcal{P}^*=\{\{a,d\},\{b,c\}\}\)&lt;/code&gt; with &lt;code&gt;\(S(\mathcal{P}^*)=14\)&lt;/code&gt;.
This partition is unstable because runner &lt;code&gt;\(a\)&lt;/code&gt; would prefer to run with &lt;code&gt;\(c\)&lt;/code&gt; than &lt;code&gt;\(d\)&lt;/code&gt;, and runner &lt;code&gt;\(c\)&lt;/code&gt; is indifferent between runners &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(b\)&lt;/code&gt;.
Runners &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(c\)&lt;/code&gt; would ignore the match-maker and become buddies, resulting in a socially inferior partition &lt;code&gt;\(\mathcal{P}_*=\{\{a,c\},\{b,d\}\}\)&lt;/code&gt; with &lt;code&gt;\(S(\mathcal{P}_*)=16\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If the socially optimal partition of runners into pairs is unstable then the match-maker would need to prevent, or at least discourage, so-called &amp;ldquo;blocking pairs&amp;rdquo; from deviating from the optimum.
For example, the match-maker could restrict runners&amp;rsquo; access to training areas (e.g., running tracks and trails) so that no blocking pairs have concurrent access.
However, such restrictions may be detrimental to runners&amp;rsquo; training and camaraderie, and, consequently, reduce social welfare.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;For example, if I wanted to improve my pace then I might prefer to run with someone slightly faster than me so that I can try to match their speed without them racing ahead of me. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Equivalently, one could choose &lt;code&gt;\(n\)&lt;/code&gt; entries in the upper-right triangle of &lt;code&gt;\(Y\)&lt;/code&gt; that satisfy criteria (a) and (b). This works because &lt;code&gt;\(Y\)&lt;/code&gt; is symmetric. If &lt;code&gt;\(y_{ij}\)&lt;/code&gt; is chosen when minimising sums over &lt;code&gt;\(Y\)&lt;/code&gt; then &lt;code&gt;\(y_{ji}\)&lt;/code&gt; is chosen when minimising sums over &lt;code&gt;\(Y^T\)&lt;/code&gt;. But &lt;code&gt;\(Y=Y^T\)&lt;/code&gt;, so the sets of chosen entries when minimising over &lt;code&gt;\(Y\)&lt;/code&gt; and &lt;code&gt;\(Y^T\)&lt;/code&gt; must be equal. Thus, &lt;code&gt;\(y_{ij}\)&lt;/code&gt; and &lt;code&gt;\(y_{ji}\)&lt;/code&gt; must belong to both sets, and so the lower-left triangle can be ignored. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;On the other hand, I conjecture that every stable partition is socially optimal. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Spotify Premium pricing</title>
      <link>https://bldavies.com/blog/spotify-premium-pricing/</link>
      <pubDate>Tue, 17 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/spotify-premium-pricing/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.spotify.com/&#34;&gt;Spotify&lt;/a&gt; offers two music and podcast streaming services:
a free, online-only service, and
a paid &amp;ldquo;Premium&amp;rdquo; service with extra features like unlimited skips and offline playback.
Spotify earns some revenue from serving ads to free users, but most of its revenue (&lt;a href=&#34;https://investors.spotify.com/financials/default.aspx&#34;&gt;about 88% in 2019Q4&lt;/a&gt;) comes from Premium subscriptions.
This revenue needs to cover Spotify&amp;rsquo;s fixed and variable costs, which include the costs of maintaining its servers and of paying royalties for streaming artists&amp;rsquo; music.&lt;/p&gt;
&lt;p&gt;Spotify&amp;rsquo;s profit function looks something like
&lt;code&gt;$$\pi(p)=n\theta(p)(p-v_1)+n(1-\theta(p))(a-v_2)-f,$$&lt;/code&gt;
where &lt;code&gt;\(p\)&lt;/code&gt; is the price of subscribing to Spotify Premium, &lt;code&gt;\(n\)&lt;/code&gt; is the number of Spotify users, &lt;code&gt;\(\theta(p)\)&lt;/code&gt; is the price-dependent proportion of these users who pay for Premium, &lt;code&gt;\(a\)&lt;/code&gt; is the revenue from serving ads to each free user, &lt;code&gt;\(v_1\)&lt;/code&gt; and &lt;code&gt;\(v_2\)&lt;/code&gt; are Spotify&amp;rsquo;s variable costs per Premium and free user, and &lt;code&gt;\(f\)&lt;/code&gt; is Spotify&amp;rsquo;s fixed costs.
I assume that &lt;code&gt;\(\theta(p)\)&lt;/code&gt; decreases with &lt;code&gt;\(p\)&lt;/code&gt; so that Spotify Premium is an &lt;a href=&#34;https://en.wikipedia.org/wiki/Ordinary_good&#34;&gt;ordinary good&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The profit-maximising price &lt;code&gt;\(p^*\)&lt;/code&gt; satisfies the first-order condition (FOC)
&lt;code&gt;$$\begin{align} 0 &amp;amp;= \pi&#39;(p^*) \\ &amp;amp;= n\theta&#39;(p^*)(p^*-v_1)+n\theta(p^*)-n\theta&#39;(p^*)(a-v_2), \end{align}$$&lt;/code&gt;
where &lt;code&gt;\(\pi&#39;\)&lt;/code&gt; and &lt;code&gt;\(\theta&#39;\)&lt;/code&gt; denote the derivatives of &lt;code&gt;\(\pi\)&lt;/code&gt; and &lt;code&gt;\(\theta\)&lt;/code&gt; with respect to &lt;code&gt;\(p\)&lt;/code&gt;.
If &lt;code&gt;\(a=0\)&lt;/code&gt; and &lt;code&gt;\(v_1=v_2\)&lt;/code&gt; then the FOC can be rewritten as
&lt;code&gt;$$\frac{p^*\theta&#39;(p^*)}{\theta(p^*)}=-1,$$&lt;/code&gt;
which means that, at &lt;code&gt;\(p=p^*\)&lt;/code&gt;, the demand for Spotify Premium is unit elastic with respect to its price.
If free users generate no ad revenue and have the same variable costs per user as Premium subscribers, then Spotify should raise its Premium price until the increased revenue per Premium subscriber exactly offsets the decrease in such subscribers.
In contrast, if &lt;code&gt;\(a&amp;gt;0\)&lt;/code&gt; or if &lt;code&gt;\(v_1&amp;gt;v_2\)&lt;/code&gt; then Spotify must raise &lt;code&gt;\(p^*\)&lt;/code&gt; further to decrease &lt;code&gt;\(\theta(p^*)\)&lt;/code&gt; and avoid the lost ad revenue or increased variable costs from converting too many free users.&lt;/p&gt;
&lt;p&gt;Notice that &lt;code&gt;\(\pi&#39;(p^*)\)&lt;/code&gt; is constant in &lt;code&gt;\(n\)&lt;/code&gt;, so &lt;code&gt;\(p^*\)&lt;/code&gt; does not change when &lt;code&gt;\(n\)&lt;/code&gt; changes.
In contrast, assuming that the second derivative of &lt;code&gt;\(\pi\)&lt;/code&gt; with respect to &lt;code&gt;\(p\)&lt;/code&gt; is negative at &lt;code&gt;\(p^*\)&lt;/code&gt; (so that &lt;code&gt;\(p^*\)&lt;/code&gt; is profit-&lt;em&gt;maximising&lt;/em&gt; rather than profit-&lt;em&gt;minimising&lt;/em&gt;), the &lt;a href=&#34;https://en.wikipedia.org/wiki/Implicit_function_theorem&#34;&gt;implicit function theorem&lt;/a&gt; implies that
&lt;code&gt;$$\frac{\partial p^*}{\partial a}=\frac{\partial p^*}{\partial v_1}&amp;gt;0&amp;gt;\frac{\partial p^*}{\partial v_2}.$$&lt;/code&gt;
In words, the profit-maximising price is increasing in &lt;code&gt;\(a\)&lt;/code&gt; and &lt;code&gt;\(v_1\)&lt;/code&gt;, and decreasing in &lt;code&gt;\(v_2\)&lt;/code&gt;.
Intuitively, if Spotify collects more ad revenue from free users then it can afford to lose some Premium subscribers by raising the Premium price.
Likewise, the greater is the difference between &lt;code&gt;\(v_1\)&lt;/code&gt; and &lt;code&gt;\(v_2\)&lt;/code&gt;, the more expensive it is to serve Premium subscribers relative to free users and so the fewer Premium subscriptions Spotify would prefer to sell.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Stanford</title>
      <link>https://bldavies.com/blog/stanford/</link>
      <pubDate>Fri, 13 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/stanford/</guid>
      <description>&lt;p&gt;I am excited to announce that I will be moving to the United States later this year to pursue a PhD in economics at &lt;a href=&#34;https://www.stanford.edu&#34;&gt;Stanford University&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://economics.stanford.edu/graduate/graduate-degree-programs&#34;&gt;Stanford&amp;rsquo;s economics PhD program&lt;/a&gt; ranks among the best in the world.
It begins with two years of advanced coursework on microeconomics, macroeconomics, econometrics, and field courses relevant to my academic interests.
This coursework will strengthen my technical and research skills, and prepare me for writing a PhD thesis that contributes substantively to the economic research literature.&lt;/p&gt;
&lt;p&gt;One topic that interests me is how people overcome uncertainty when forming teams.
For example, the students in my cohort face uncertainty about who among the Stanford faculty will be the best supervisor(s) for their eventual theses.
Likewise, faculty members face uncertainty about which students will be the best candidates to supervise.
Participating in lectures and seminars will help students and faculty estimate their match qualities, leading to more informed and productive matches.&lt;/p&gt;
&lt;p&gt;Another topic that interests me is how people share information in networks.
For example, my blog posts on &lt;a href=&#34;https://bldavies.com/blog/information-gerrymandering/&#34;&gt;information gerrymandering&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/degroot-learning-social-networks/&#34;&gt;DeGroot learning&lt;/a&gt; use mathematical models to analyse how inter-personal connections influence peoples&amp;rsquo; decisions and beliefs.
I am looking forward to learning more about these and related models, and their application to &amp;ldquo;real-world&amp;rdquo; social and economic systems.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Uniform sums and Euler&#39;s number</title>
      <link>https://bldavies.com/blog/uniform-sums-eulers-number/</link>
      <pubDate>Mon, 09 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/uniform-sums-eulers-number/</guid>
      <description>&lt;p&gt;Suppose I sample values uniformly at random from the unit interval.
How many samples should I expect to take before the sum of my sampled values exceeds unity?&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(N\)&lt;/code&gt; be the (random) number of samples taken when the sum first exceeds unity.
Then &lt;code&gt;\(N\)&lt;/code&gt; has expected value &lt;code&gt;\(E[N]\)&lt;/code&gt; equal to &lt;a href=&#34;https://en.wikipedia.org/wiki/E_%28mathematical_constant%29&#34;&gt;Euler&amp;rsquo;s number&lt;/a&gt; &lt;code&gt;\(e\approx2.718282\)&lt;/code&gt;.
This can be verified approximately via simulation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;simulate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;run&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;tot&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;N&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;while &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tot&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;tot&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tot&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;runif&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;N&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;N&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;N&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;sapply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1e5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;simulate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## [1] 2.7183
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To see why &lt;code&gt;\(E[N]=e\)&lt;/code&gt;, let &lt;code&gt;\((X_i)_{i=1}^\infty\)&lt;/code&gt; be an infinite sequence of random variables with uniform distributions over the unit interval.
Then the probability that &lt;code&gt;\(N\)&lt;/code&gt; exceeds any non-negative integer &lt;code&gt;\(n\)&lt;/code&gt; is
&lt;code&gt;$$\Pr(N&amp;gt;n)=\Pr(X_1+X_2+\cdots+X_n&amp;lt;1).$$&lt;/code&gt;
Consider the unit (hyper)cube in &lt;code&gt;\(\mathbb{R}^n\)&lt;/code&gt;.
Its vertices comprise the origin, the standard basis vectors &lt;code&gt;\(e_1,e_2,\ldots,e_n\)&lt;/code&gt;, and the sums of two or more of these basis vectors.
The convex hull of &lt;code&gt;\(\{0,e_1,e_2,\ldots,e_n\}\)&lt;/code&gt; forms an &lt;code&gt;\(n\)&lt;/code&gt;-simplex with volume &lt;code&gt;\(1/n!\)&lt;/code&gt;.
The interior of this simplex is precisely the set
&lt;code&gt;$$\{X_1,X_2,\ldots,X_n\in[0,1]:X_1+X_2+\cdots+X_n&amp;lt;1\}.$$&lt;/code&gt;
It follows that &lt;code&gt;\(\Pr(X_1+X_2+\cdots+X_n&amp;lt;1)=1/n!\)&lt;/code&gt; and therefore &lt;code&gt;\(\Pr(N&amp;gt;n)=1/n!\)&lt;/code&gt; from above.
Now
&lt;code&gt;$$\Pr(N=n)=\Pr(N&amp;gt;n-1)-\Pr(N&amp;gt;n)$$&lt;/code&gt;
for each &lt;code&gt;\(n\ge1\)&lt;/code&gt;.
Thus, since &lt;code&gt;\(\Pr(N&amp;gt;0)=1\)&lt;/code&gt; (and, by convention, &lt;code&gt;\(0!=1\)&lt;/code&gt;), we have
&lt;code&gt;$$\begin{align} E[N] &amp;amp;= \sum_{n=1}^\infty n\Pr(N=n) \\ &amp;amp;= \sum_{n=1}^\infty n\left(\Pr(N&amp;gt;n-1)-\Pr(N&amp;gt;n)\right) \\ &amp;amp;= \Pr(N&amp;gt;0)+\sum_{n=1}^\infty\Pr(N&amp;gt;n) \\ &amp;amp;= 1+\sum_{n=1}^\infty\frac{1}{n!} \\ &amp;amp;= \sum_{n=0}^\infty\frac{1}{n!} \\ &amp;amp;= e. \end{align}$$&lt;/code&gt;
The final equality comes from evaluating the Maclaurin series expansion of &lt;code&gt;\(e^x\)&lt;/code&gt; at &lt;code&gt;\(x=1\)&lt;/code&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://www.3blue1brown.com&#34;&gt;Grant Sanderson&lt;/a&gt; mentions this problem in &lt;a href=&#34;https://www.youtube.com/watch?v=6_yU9eJ0NxA&amp;amp;t=28m7s&#34;&gt;this Numberphile video&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Triadic closure at the NBER</title>
      <link>https://bldavies.com/blog/triadic-closure-nber/</link>
      <pubDate>Wed, 04 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/triadic-closure-nber/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://academic.oup.com/jeea/article-abstract/8/1/203/2295936&#34;&gt;Fafchamps et al. (2010)&lt;/a&gt; describe a model of team formation in which people learn about potential collaborators via existing collaborators.
These &amp;ldquo;referrals&amp;rdquo; provide information about potential collaborators&amp;rsquo; match qualities, allowing people to &lt;a href=&#34;https://en.wikipedia.org/wiki/Screening_%28economics%29&#34;&gt;screen&lt;/a&gt; each other and sort into more productive teams.
Fafchamps et al. argue, and demonstrate empirically, that this referral mechanism leads to more teams being formed among people who are closer in the collaboration network.&lt;/p&gt;
&lt;p&gt;Fafchamps et al.&amp;lsquo;s referral model implies that triads in collaboration networks should tend to &lt;a href=&#34;https://en.wikipedia.org/wiki/Triadic_closure&#34;&gt;close&lt;/a&gt; over time; that is, people should tend to collaborate with others with whom they share common collaborators.
One way to measure such closure is via the (global) &lt;a href=&#34;https://en.wikipedia.org/wiki/Clustering_coefficient&#34;&gt;clustering coefficient&lt;/a&gt;, which measures the rate at which pairs of nodes with a common neighbour are also adjacent.
For example, in the &lt;a href=&#34;https://bldavies.com/blog/nber-co-authorships/&#34;&gt;NBER working paper co-authorship network&lt;/a&gt;, about 15% of the pairs of authors who share common co-authors are co-authors themselves.
In contrast, we would expect this to happen 0.27% of the time in a &lt;a href=&#34;https://bldavies.com/blog/degree-preserving-randomisation/&#34;&gt;random network with the same degree distribution&lt;/a&gt;, and 0.04% of the time in a random network with the same number of nodes and edges.
Thus, the NBER co-authorship network is much more clustered than would be expected if authors chose co-authors randomly.&lt;/p&gt;
&lt;p&gt;Another way to measure triadic closure is by computing the rate at which pairs of nodes with common neighbours &lt;em&gt;become&lt;/em&gt; adjacent.
This method makes sense whenever the network&amp;rsquo;s density grows over time.
Such growth occurs in the NBER co-authorship network through co-authorships of new working papers.
The network contains 32,034 pairs of eventual co-authors, 1,861 of whom share common co-authors at an earlier stage of the network&amp;rsquo;s evolution.
However, 340,235 of the 342,096 pairs of authors with common co-authors never become co-authors themselves.
Thus, only 0.54% of the unclosed triads in the NBER co-authorship network ever become closed.&lt;/p&gt;
&lt;p&gt;How can we reconcile the NBER co-authorship network&amp;rsquo;s high clustering coefficient with its low triad closure rate?&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
One explanation could be that referrals primarily attract collaborators on current projects rather than potential future projects.
Suppose I&amp;rsquo;m writing a paper with Alice, who suggests that Bob may have some valuable insights on our research, and that Bob and I might work well together.
It turns out that Bob does have valuable insights and that we do work well together, and Alice and I decide to make him a co-author on our paper.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
We publish our research as an NBER working paper, and Alice, Bob and I appear as a closed triad in the NBER co-authorship network (but never as an unclosed triad).&lt;/p&gt;
&lt;p&gt;If intra-project closure is common then we would expect a high clustering coefficient and low triad closure rate in the NBER co-authorship network.
The open triads in the network would be the triads for which successful referrals did not occur during co-authorship, and the factors that prevented such referrals may persist after the paper is published.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Researchers in the NBER co-authorship network may collaborate in ways not captured by the network. For example, working papers published in the NBER series must have at least one NBER-affiliated author, so papers written exclusively by non-affiliates are not observed in my data. If co-author referrals primarily lead non-affiliates to collaborate, and if such collaboration does not culminate in NBER working paper publications, then we would expect to observe a low triad closure rate. However, we would also expect a low (perhaps lower than 0.15) clustering coefficient because the triads containing non-affiliates would remain mostly open. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.2307/1926798&#34;&gt;Barnett et al. (1988)&lt;/a&gt; and &lt;a href=&#34;https://doi.org/10.1257/jel.51.1.162&#34;&gt;Hamermesh (2013)&lt;/a&gt; suggest that co-authorship is increasingly used as compensation for colleagues&amp;rsquo; research assistance. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Degree-preserving randomisation</title>
      <link>https://bldavies.com/blog/degree-preserving-randomisation/</link>
      <pubDate>Mon, 17 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/degree-preserving-randomisation/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://bldavies.com/blog/centrality-rankings-noisy-edge-sets/&#34;&gt;My previous post&lt;/a&gt; used &lt;a href=&#34;https://en.wikipedia.org/wiki/Degree-preserving_randomization&#34;&gt;degree-preserving randomisation&lt;/a&gt; (DPR) to control for network structure when estimating the effect of edge noise on nodes&amp;rsquo; centrality rankings.
The idea was that nodes may be connected in ways that amplify or suppress the effects of noise, and randomising nodes&amp;rsquo; connections helps to balance these effects by averaging over the network&amp;rsquo;s possible structures.&lt;/p&gt;
&lt;p&gt;DPR can also be used to test whether a network&amp;rsquo;s structure is significantly different than would be expected for a random network with the same degree distribution.
For example, comparing a network&amp;rsquo;s clustering coefficient to the mean clustering coefficient among a sample of degree-preserving random networks reveals whether the original network is significantly more or less clustered than it would be, on average, if nodes&amp;rsquo; connections were random.
In contrast to &lt;a href=&#34;https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93R%C3%A9nyi_model&#34;&gt;Erdös-Rényi&lt;/a&gt; randomisation (ERR)&amp;mdash;that is, generating a random network with the same number of nodes and edges&amp;mdash;DPR separates variation in degree distributions from variation in other properties observed across sampled random networks.&lt;/p&gt;
&lt;p&gt;Consider, as an example, the &lt;a href=&#34;https://bldavies.com/blog/coauthorship-networks-motu/&#34;&gt;Motu working paper co-authorship network&lt;/a&gt;.
The table below presents the network&amp;rsquo;s median node degree, global &lt;a href=&#34;https://en.wikipedia.org/wiki/Clustering_coefficient&#34;&gt;clustering coefficient&lt;/a&gt;, and &lt;a href=&#34;https://en.wikipedia.org/wiki/Average_path_length&#34;&gt;mean geodesic distance&lt;/a&gt;.
The table also presents the sample means and standard deviations of these properties across 50 degree-preserving and Erdös-Rényi randomisations of the co-authorship network.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Property&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Actual value&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;DPR sample mean (sd)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;ERR sample mean (sd)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Median degree&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.00&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.00 (0.00)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7.88 (0.33)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Clustering coefficient&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.52&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.16 (0.01)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.04 (0.00)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mean distance&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.72&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.83 (0.03)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.74 (0.01)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;By definition, DPR preserves the degree distribution and, consequently, always delivers the same median degree as the co-authorship network.
In contrast, ERR removes the inequality in node degrees (arising, for example, from &lt;a href=&#34;https://en.wikipedia.org/wiki/Preferential_attachment&#34;&gt;preferential attachment&lt;/a&gt;) and, consequently, delivers median degrees centred on the co-authorship network&amp;rsquo;s mean degree.&lt;/p&gt;
&lt;p&gt;The co-authorship network is about 13 times more clustered than would be expected for an Erdös-Rényi random network with same number of nodes and edges.
Controlling for the degree distribution drops this factor to just over three.
In contrast, the mean distance between nodes in the co-authorship network is closer to what we would expect in a comparable Erdös-Rényi random network than in a degree-preserving random network.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Centrality rankings with noisy edge sets</title>
      <link>https://bldavies.com/blog/centrality-rankings-noisy-edge-sets/</link>
      <pubDate>Fri, 14 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/centrality-rankings-noisy-edge-sets/</guid>
      <description>&lt;p&gt;Suppose I want to rank the centralities of nodes in a network.
The network&amp;rsquo;s node set is correct, but its edge set is &amp;ldquo;noisy&amp;rdquo; in that it includes some false edges and excludes some true edges.
How sensitive to this noise are the rankings of nodes from most to least central?&lt;/p&gt;
&lt;p&gt;One way to answer this question empirically is to perturb an observable &amp;ldquo;true&amp;rdquo; network by adding and deleting edges randomly.
This can be achieved by generating an &lt;a href=&#34;https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93R%C3%A9nyi_model&#34;&gt;Erdös-Rényi (ER) random network&lt;/a&gt; with the same node set as the true network, and defining a &amp;ldquo;noisy&amp;rdquo; network with edge set equal to the symmetric difference of the true and ER networks&amp;rsquo; edge sets.
This method &amp;ldquo;swaps&amp;rdquo; the states (from &amp;ldquo;present&amp;rdquo; to &amp;ldquo;not present&amp;rdquo;, or vice versa) of the true network&amp;rsquo;s edges at random.
Varying the edge creation probablity in the ER network varies the amount of noise in the noisy network&amp;rsquo;s edge set.&lt;/p&gt;
&lt;p&gt;I demonstrate this &amp;ldquo;random edge swapping&amp;rdquo; method by applying it to the &lt;a href=&#34;https://bldavies.com/blog/coauthorship-networks-motu/&#34;&gt;Motu working paper co-authorship network&lt;/a&gt;.
First, I generate 30 ER networks and 30 corresponding noisy networks for a range of edge swap probabilities.
I then compute nodes&amp;rsquo; betweenness, degree and PageRank centralities in the co-authorship networks with and without noise, and calculate the &lt;a href=&#34;https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient&#34;&gt;Spearman rank correlation&lt;/a&gt; between the true and noisy centralities using each of the three measures.
Finally, I compute the sample means and 95% confidence intervals for the measure-specific rank correlations across the simulation runs associated with each edge swap probability.
I present these means and confidence intervals in the left panel of the plot below.
The right panel presents similar information, but with a &lt;a href=&#34;https://bldavies.com/blog/degree-preserving-randomisation/&#34;&gt;degree-preserving randomisation&lt;/a&gt; of the co-authorship network within each simulation run before introducing noise.
This randomisation allows me to control for the effect of the co-authorship network&amp;rsquo;s structure on my rank correlation estimates.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/correlations-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Increasing the edge swap probability decreases the consistency between the true and noisy centrality rankings for each of the three centrality measures I analyse.
Intuitively, the more noise there is in the edge set, the less similar are the true and noisy co-authorship networks, and so the less correlated are the centrality rankings of the nodes in these networks.&lt;/p&gt;
&lt;p&gt;Degree centrality rankings are the least sensitive to edge noise.
Adding or deleting edges moves the incident nodes up or down the degree rank order, but leaves the relative ranks among non-incident nodes intact.
Degree-preserving randomisation, by definition, does not affect nodes&amp;rsquo; degree centrality rankings and so does not change the sensitivity of those rankings to noise.&lt;/p&gt;
&lt;p&gt;PageRank centrality rankings are more sensitive to edge noise.
Since nodes&amp;rsquo; PageRank centralities depend on the PageRank centralities of their neighbours, the effect of adding or deleting edges spills over to some non-incident nodes and, consequently, disrupts the PageRank rank order more than the degree rank order.
Controlling for network structure increases the influence that degree has on PageRank centrality and, consequently, decreases the sensitivity of PageRank centrality rankings to errant edges.&lt;/p&gt;
&lt;p&gt;Betweenness centrality rankings are the most sensitive to edge noise.
Adding or deleting edges can create or destroy short(est) paths between nodes, leading to radical changes in betweenness centrality for nodes on these paths.
Controlling for network structure suppresses these changes by reducing the initial inequality in betweenness centralities.
About 71% of nodes in the true co-authorship network have betweenness centralities equal to zero, whereas 20% of nodes in the randomised networks have betweenness centralities equal to zero.
Consequently, nodes in the randomised networks typically have &amp;ldquo;less betweenness to gain or lose&amp;rdquo; than nodes in the true network, diminishing the effect of errant edges on betweenness centrality rankings.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>motuwp is now an R package</title>
      <link>https://bldavies.com/blog/motuwp-package/</link>
      <pubDate>Sat, 08 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/motuwp-package/</guid>
      <description>&lt;p&gt;My current project at Motu involves analysing co-authorship networks.
It is helpful for me to have a small example network that I can use to, for example, &lt;a href=&#34;https://bldavies.com/blog/sampling-motu-coauthorship-network/&#34;&gt;compare sampling techniques&lt;/a&gt;.
The &lt;a href=&#34;https://bldavies.com/blog/coauthorship-networks-motu/&#34;&gt;Motu working paper co-authorship network&lt;/a&gt; is my go-to.
Since I work mostly in R, I have converted the &lt;a href=&#34;https://github.com/bldavies/motuwp&#34;&gt;repository&lt;/a&gt; containing the underlying authorship data to an R package.
This package can be installed from GitHub via &lt;a href=&#34;https://github.com/r-lib/remotes&#34;&gt;remotes&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;remotes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;install_github&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;bldavies/motuwp&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;motuwp provides two data frames: &lt;code&gt;papers&lt;/code&gt;, containing working paper attributes, and &lt;code&gt;authors&lt;/code&gt;, containing author-paper pairs.
These pairs can be used to construct a co-authorship network as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;motuwp&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Method 1: Project bipartite author-paper network onto author set&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph_from_data_frame&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;authors&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;V&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;V&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%in%&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;authors&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;author&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;bipartite_projection&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;which&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;true&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;multiplicity&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Method 2: use convenience function that returns same network&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;coauthorship_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The co-authorship network &lt;code&gt;net&lt;/code&gt; contains 185 nodes and 729 edges.
These values are larger than the corresponding values of 82 and 218 reported in &lt;a href=&#34;https://bldavies.com/blog/sampling-motu-coauthorship-network/&#34;&gt;my mid-2019 blog post&lt;/a&gt; on the network.
The increases are due to me adding (i) the remaining working papers from 2019, (ii) some papers with missing landing pages, and (iii) authors with no hyperlinked profile page on Motu&amp;rsquo;s website.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>NBER (co-)authorships</title>
      <link>https://bldavies.com/blog/nber-co-authorships/</link>
      <pubDate>Fri, 07 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/nber-co-authorships/</guid>
      <description>&lt;p&gt;I recently updated the R package &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;nberwp&lt;/a&gt; to include data on NBER working paper authorships.
These data describe a bipartite author-paper network containing 13,571 authors and 26,586 papers.
On average, each author has 4.35 papers and each paper has 2.22 authors.&lt;/p&gt;
&lt;p&gt;The co-authorship network among NBER authors&amp;mdash;that is, the &lt;a href=&#34;https://en.wikipedia.org/wiki/Bipartite_network_projection&#34;&gt;bipartite projection&lt;/a&gt; of the author-paper network onto the set of authors&amp;mdash;contains 0.03% of the possible edges among the 13,571 authors in the network.
On average, each author has 4.72 unique co-authors across the working paper series.
About 95% of authors belong to a single connected component of the co-authorship network, while 139 authors have no co-authors.&lt;/p&gt;
&lt;p&gt;One challenge that arises when constructing co-authorship networks is &lt;a href=&#34;https://en.wikipedia.org/wiki/Author_name_disambiguation&#34;&gt;disambiguating authors&amp;rsquo; names&lt;/a&gt;.
Slight misspellings may split a single author into many nodes, while many authors with the same name may be merged into a single node.
These false splits and merges inhibit one&amp;rsquo;s ability to draw robust inferences about collaborative behaviour from the co-authorship network&amp;rsquo;s structure.&lt;/p&gt;
&lt;p&gt;It is easiest to disambiguate author names when they can be cross-referenced against other data.
The &lt;a href=&#34;https://www.nber.org/RePEc/nbr/nberwo/&#34;&gt;NBER RePEc index&lt;/a&gt;, from which I extract the authorship data, links some authors to their &lt;a href=&#34;http://repec.org/&#34;&gt;RePEc&lt;/a&gt; author IDs.
These IDs allow me to merge some authors who publish under varying names.
I also merge authors with (i) sufficiently similar names and (ii) overlapping neighbourhoods in the co-authorship network.
Criterion (i) assumes that authors&amp;rsquo; names tend to vary from their true values by a few characters only, while criterion (ii) assumes that authors tend to write multiple papers with the same set of co-authors.
Combined, these criteria form a computationally feasible heuristic for identifying and resolving false splits.&lt;/p&gt;
&lt;p&gt;In contrast, I do not attempt to identify false merges.
One method could be to look for authors who bridge otherwise distant parts of the co-authorship network.
This method assumes that authors tend to sort into clusters (e.g., by research interest) and that links between clusters are uncommon.
However, this assumption defies the empirical evidence that the co-authorship network among economists has a &lt;a href=&#34;https://en.wikipedia.org/wiki/Small-world_network&#34;&gt;small-world&lt;/a&gt; structure (&lt;a href=&#34;https://doi.org/10.1086/500990&#34;&gt;Goyal et al., 2006&lt;/a&gt;).&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>DeGroot learning in social networks</title>
      <link>https://bldavies.com/blog/degroot-learning-social-networks/</link>
      <pubDate>Mon, 27 Jan 2020 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/degroot-learning-social-networks/</guid>
      <description>&lt;p&gt;The first book on my reading list for 2020 was &lt;a href=&#34;https://web.stanford.edu/~jacksonm/&#34;&gt;Matthew Jackson&lt;/a&gt;&amp;lsquo;s &lt;em&gt;The Human Network&lt;/em&gt;.
Its seventh chapter discusses &lt;a href=&#34;https://en.wikipedia.org/wiki/DeGroot_learning&#34;&gt;DeGroot learning&lt;/a&gt; as a process for building consensus among members of a social network.&lt;/p&gt;
&lt;p&gt;Consider a (strongly) connected social network among &lt;code&gt;\(n\)&lt;/code&gt; people.
These people have private information that they use to form independent initial beliefs &lt;code&gt;\(b_1^{(0)},\ldots,b_n^{(0)}\)&lt;/code&gt; about the value of some parameter &lt;code&gt;\(\theta\)&lt;/code&gt;.
Recognising that their information sets may be incomplete, everyone updates their beliefs in discrete time steps by iteratively adopting the mean belief among their friends.
This process spreads the information available to each individual throughout the network, allowing peoples&amp;rsquo; beliefs to converge to a consensus estimate &lt;code&gt;\(\hat\theta\)&lt;/code&gt; of &lt;code&gt;\(\theta\)&lt;/code&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;The figure below presents an example of this setup.
It shows the social network among eight people after zero, one, two, and three time steps.
Nodes represent people, and are coloured according to the deviation of peoples&amp;rsquo; beliefs above (orange) or below (purple) &lt;code&gt;\(\theta\)&lt;/code&gt;&#39;s true value (white).
Edges represent mutual friendships.
Over time, the information embedded in peoples&amp;rsquo; initial beliefs diffuses throughout the network and the variation in beliefs around &lt;code&gt;\(\hat\theta\)&lt;/code&gt; collapses to zero.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/example-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;People with more friends have more influence on the consensus estimate because they have more avenues through which to spread information.
One can formalise this claim as follows.
Let &lt;code&gt;\(b^{(t)}=(b_1^{(t)},\ldots,b_n^{(t)})\)&lt;/code&gt; be the &lt;code&gt;\(n\times 1\)&lt;/code&gt; vector of time &lt;code&gt;\(t\)&lt;/code&gt; beliefs.
This vector evolves according to
&lt;code&gt;$$b^{(t+1)}=Wb^{(t)},$$&lt;/code&gt;
where &lt;code&gt;\(W=(W_{ij})\)&lt;/code&gt; is a row-stochastic &lt;code&gt;\(n\times n\)&lt;/code&gt; matrix with entries &lt;code&gt;\(W_{ij}\)&lt;/code&gt; equal to the (time-invariant) weight that person &lt;code&gt;\(i\)&lt;/code&gt; assigns to the beliefs of person &lt;code&gt;\(j\)&lt;/code&gt; at each time step.
Notice that &lt;code&gt;\(b^{(t)}=W^tb^{(0)}\)&lt;/code&gt; and so the &lt;code&gt;\(n\times1\)&lt;/code&gt; vector &lt;code&gt;\(b^{(\infty)}=(\hat\theta,\ldots,\hat\theta)\)&lt;/code&gt; of consensus estimates is given by
&lt;code&gt;$$b^{(\infty)}=\lim_{t\to\infty}W^tb^{(0)}.$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In the context of DeGroot learning in social networks, we have
&lt;code&gt;$$W_{ij}=\frac{A_{ij}+I_{ij}}{d_i+1},$$&lt;/code&gt;
where &lt;code&gt;\(A=(A_{ij})\)&lt;/code&gt; is the adjacency matrix for the social network,
&lt;code&gt;\(d_i=\sum_{j=1}^nA_{ij}\)&lt;/code&gt; is person &lt;code&gt;\(i\)&lt;/code&gt;&#39;s degree in that network,
and &lt;code&gt;\(I=(I_{ij})\)&lt;/code&gt; is the &lt;code&gt;\(n\times n\)&lt;/code&gt; identity matrix.
Adding one in the numerator (if &lt;code&gt;\(i=j\)&lt;/code&gt;) and denominator reflects person &lt;code&gt;\(i\)&lt;/code&gt; including their own beliefs when computing the mean among their friends.&lt;/p&gt;
&lt;p&gt;The matrix &lt;code&gt;\(W\)&lt;/code&gt; describes a &lt;a href=&#34;https://en.wikipedia.org/wiki/Markov_chain&#34;&gt;Markov chain&lt;/a&gt; &lt;code&gt;\(\mathcal{M}\)&lt;/code&gt; on the set of &lt;code&gt;\(n\)&lt;/code&gt; people.
Assuming that the social network is (strongly) connected implies that &lt;code&gt;\(\mathcal{M}\)&lt;/code&gt; is irreducible and aperiodic.
It follows from the &lt;a href=&#34;https://en.wikipedia.org/wiki/Perron%E2%80%93Frobenius_theorem&#34;&gt;Perron-Frobenius theorem&lt;/a&gt; that
&lt;code&gt;$$\lim_{t\to\infty}W^t=1_n\pi,$$&lt;/code&gt;
where &lt;code&gt;\(1_n\)&lt;/code&gt; is the &lt;code&gt;\(n\times1\)&lt;/code&gt; vector of ones and &lt;code&gt;\(\pi\)&lt;/code&gt; is a &lt;code&gt;\(1\times n\)&lt;/code&gt; row vector corresponding to the unique stationary distribution of &lt;code&gt;\(\mathcal{M}\)&lt;/code&gt;; that is, &lt;code&gt;\(\pi\)&lt;/code&gt; uniquely solves
&lt;code&gt;$$\pi W=\pi$$&lt;/code&gt;
subject to the constraints that &lt;code&gt;\(\pi_j\ge0\)&lt;/code&gt; for each &lt;code&gt;\(j\)&lt;/code&gt; and &lt;code&gt;\(\sum_{j=1}^n\pi_j=1\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now, let &lt;code&gt;\(v\)&lt;/code&gt; be the &lt;code&gt;\(1\times n\)&lt;/code&gt; row vector with entries &lt;code&gt;\(v_j=(d_j+1)/\sum_{k=1}^n(d_k+1)\)&lt;/code&gt;.
Then &lt;code&gt;\(v_j\ge0\)&lt;/code&gt; for each &lt;code&gt;\(j\)&lt;/code&gt; and &lt;code&gt;\(\sum_{j=1}^nv_j=1\)&lt;/code&gt;.
Moreover, since &lt;code&gt;\(A\)&lt;/code&gt; is symmetric (and so &lt;code&gt;\(d_j=\sum_{i=1}^nA_{ij}\)&lt;/code&gt;),
&lt;code&gt;$$\begin{align} (v W)_j &amp;amp;=\sum_{i=1}^nv_iW_{ij}\\ &amp;amp;=\sum_{i=1}^n\frac{d_i+1}{\sum_{k=1}^n(d_k+1)}\frac{A_{ij}+I_{ij}}{{d_i+1}}\\ &amp;amp;=\frac{d_j+1}{\sum_{k=1}^n(d_k+1)}\\ &amp;amp;=v_j \end{align}$$&lt;/code&gt;
for each &lt;code&gt;\(j\)&lt;/code&gt; so that &lt;code&gt;\(vW=v\)&lt;/code&gt; and therefore &lt;code&gt;\(\pi=v\)&lt;/code&gt; by uniqueness.
Thus, the consensus estimate is given by
&lt;code&gt;$$\hat\theta=\frac{\sum_{k=1}^n(d_k+1)b_k^{(0)}}{\sum_{k=1}^n(d_k+1)}.$$&lt;/code&gt;
Finally, the influence that person &lt;code&gt;\(i\)&lt;/code&gt; has on &lt;code&gt;\(\hat\theta\)&lt;/code&gt; is captured by the partial derivative
&lt;code&gt;$$\frac{\partial\hat\theta}{\partial b_i^{(0)}}=\frac{d_i+1}{\sum_{k=1}^n(d_k+1)},$$&lt;/code&gt;
which is an increasing linear function of person &lt;code&gt;\(i\)&lt;/code&gt;&#39;s degree &lt;code&gt;\(d_i\)&lt;/code&gt; in the social network.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Convergence is guaranteed if the social network is strongly connected &lt;a href=&#34;https://doi.org/10.1257/mic.2.1.112&#34;&gt;(Golub and Jackson, 2005)&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>White elephant gift exchanges</title>
      <link>https://bldavies.com/blog/white-elephant-gift-exchanges/</link>
      <pubDate>Wed, 11 Dec 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/white-elephant-gift-exchanges/</guid>
      <description>&lt;p&gt;Motu&amp;rsquo;s staff Christmas party is this Friday.
We&amp;rsquo;re planning a &lt;a href=&#34;https://en.wikipedia.org/wiki/White_elephant_gift_exchange&#34;&gt;white elephant gift exchange&lt;/a&gt;: everyone contributes a wrapped gift to a common pool and sequentially chooses to either (i) unwrap a gift or (ii) steal a previously unwrapped gift.
&amp;ldquo;Victims&amp;rdquo; of theft make the same choice, but previously stolen gifts cannot be re-stolen until a new gift is unwrapped.
The exchange ends when the last gift is unwrapped.&lt;/p&gt;
&lt;p&gt;Suppose I want to maximise the subjective value of the gift in my possession when the exchange ends.
I must overcome two strategic challenges:
I don&amp;rsquo;t know the subjective values of wrapped gifts, and
I don&amp;rsquo;t know other players&amp;rsquo; subjective values of wrapped &lt;em&gt;or unwrapped&lt;/em&gt; gifts.
Therefore, any strategy I adopt must account for uncertainty both in wrapped gifts&amp;rsquo; subjective values and in the propensity of other players to steal unwrapped gifts I covet.&lt;/p&gt;
&lt;p&gt;One strategy could be to always steal the unwrapped gift with the highest subjective value.
This strategy is risky because my subjective valuations might correlate with those of other players, making it more likely I will become a victim of theft.
I could hedge this risk by instead always stealing the unwrapped gift with the &lt;em&gt;second&lt;/em&gt; highest subjective value (unless I&amp;rsquo;m the last player, in which case I would be better off stealing the most subjectively valuable gift because it can&amp;rsquo;t be re-stolen).
Alternatively, I could play as a pacifist and never steal (unless I&amp;rsquo;m the last player).&lt;/p&gt;
&lt;p&gt;I compare these three strategies&amp;mdash;greediness, hedged greediness, and pacifism&amp;mdash;via simulation.
I assume gifts&amp;rsquo; subjective values are determined as the mean of two &lt;a href=&#34;https://en.wikipedia.org/wiki/Continuous_uniform_distribution#Standard_uniform&#34;&gt;standard uniform&lt;/a&gt; random variables: one describing an underlying value common to all players, and one describing an idiosyncratic component unique to each player.
I simulate 1000 games among 30 players, randomising the strategies adopted by each player in each game.&lt;/p&gt;
&lt;p&gt;For each simulated game, I compute the subjective value of the gift in each player&amp;rsquo;s possession when the exchange ends.
I also compute the allocation that maximises aggregate (i.e., the sum of) subjective values.
I refer to the subjective values in this allocation as &amp;ldquo;efficiency baselines,&amp;rdquo; and use them to compare strategies&amp;rsquo; tendencies to deliver socially optimal allocations.
I summarise my simulation results in the plot below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Across all strategies, players whose turns arrive later in the game tend to be better off.
Such players have more choices of gifts to steal and fewer opportunities to become victims of theft.
Greedier players tend to end up with more subjectively valuable gifts, while pacifists&amp;mdash;who never use victimisation as an opportunity to &amp;ldquo;trade up&amp;rdquo;&amp;mdash;typically possess the least subjectively valuable gifts when the exchange ends.
Only late and/or greedy players tend to do better than under the socially optimal allocation.&lt;/p&gt;
&lt;p&gt;Choosing not to steal is risky because it may result in unwrapping a low-value gift that no other players want to steal.
The first player, who cannot steal, is particularly exposed to this risk.
The game could be made fairer by allowing the first player (and subsequent victims) to unilaterally swap gifts when everyone else has had their turn.
This adjustment shifts the disadvantage to the second player, who, in the game&amp;rsquo;s pre-swap phase, has only two choices: steal from the first player or unwrap a new gift.
Giving more players a second turn could improve the final gift allocation by giving early players a larger choice set.&lt;/p&gt;
&lt;p&gt;The table below shows how the efficiency and equity of the final gift allocation varies with the number of early players given a second turn.
I measure efficiency by the ratio of aggregate subjective values to aggregate efficiency baselines.
I define equity as one minus the &lt;a href=&#34;https://en.wikipedia.org/wiki/Gini_coefficient&#34;&gt;Gini coefficient&lt;/a&gt; for the distribution of subjective values.
The table reports 95% confidence intervals across 1000 simulated games.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Players given second turn&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Efficiency (%)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Equity (%)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;83.9 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;80.3 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.8 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;83.0 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.7 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82.8 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.6 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82.7 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.6 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82.6 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;88.3 ± 0.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82.4 ± 0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Giving the first player a second turn makes the final allocation more efficient and more equitable.
That player gets a chance to improve upon their initial endowment, and subsequent victims get a chance to reconsider their choices with more information about the distribution of gifts&amp;rsquo; subjective values.
However, on average, giving further players a second turn appears to push efficiency and equity back down.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Birds, voting, and Russian interference</title>
      <link>https://bldavies.com/blog/birds-voting-russian-interference/</link>
      <pubDate>Sun, 17 Nov 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/birds-voting-russian-interference/</guid>
      <description>&lt;p&gt;Since 2005, &lt;a href=&#34;https://www.forestandbird.org.nz&#34;&gt;Forest and Bird&lt;/a&gt; has run annual elections for New Zealand&amp;rsquo;s &lt;a href=&#34;https://www.birdoftheyear.org.nz&#34;&gt;Bird of the Year&lt;/a&gt;.
This week Radio New Zealand &lt;a href=&#34;https://www.rnz.co.nz/news/national/402986/bird-of-the-year-2019-hoiho-takes-the-winning-title&#34;&gt;announced&lt;/a&gt; the &lt;a href=&#34;https://en.wikipedia.org/wiki/Yellow-eyed_penguin&#34;&gt;yellow-eyed penguin&lt;/a&gt; as 2019&amp;rsquo;s winner.
A follow-up &lt;a href=&#34;https://twitter.com/Forest_and_Bird/status/1193720097283567616&#34;&gt;tweet&lt;/a&gt; by Forest and Bird &lt;a href=&#34;https://www.rnz.co.nz/news/national/403085/bird-of-the-year-russian-interest-in-contest-piques-suspicions-online&#34;&gt;raised suspicions&lt;/a&gt; about possible Russian interference into the vote&amp;rsquo;s outcome.&lt;/p&gt;
&lt;p&gt;Forest and Bird&amp;rsquo;s tweet includes a world map with countries coloured by voter turnout.
The bar chart below presents the same information in a less exciting format.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/countries-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Russian votes account for 193 of the 15,044 votes with known country of origin.
New Zealand contributed 12,651 such votes.
Fully 28,416 votes had unknown origin and were excluded from the set of votes used to determine the winning bird.&lt;/p&gt;
&lt;p&gt;This year&amp;rsquo;s election used an &lt;a href=&#34;https://en.wikipedia.org/wiki/Instant-runoff_voting&#34;&gt;instant-runoff&lt;/a&gt; system.
Voters reported up to five of their favorite birds, ranked in order of preference.
Beginning with voters&amp;rsquo; first preferences, birds with the least votes were eliminated sequentially and their votes reallocated to voters&amp;rsquo; next favorites.
This process continued until one bird remained.&lt;/p&gt;
&lt;p&gt;The table below reports the last five birds eliminated by the instant-runoff process among the votes cast from anywhere, from known countries, from New Zealand, from Russia, and from known countries excluding Russia.
The bracketed percentages represent the share of voters from each country who preferred the top two candidates in the final round.
For example, 61.6% of New Zealanders with preferences over the yellow-eyed penguin and the kākāpō preferred the former.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Place&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;All countries&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Known countries&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;New Zealand&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Russia&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Known countries ex. Russia&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Yellow-eyed penguin (52.4%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Yellow-eyed penguin (58.7%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Yellow-eyed penguin (61.6%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākāpō (52.0%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Yellow-eyed penguin (59.0%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākāpō (47.6%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākāpō (41.3%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākāpō (38.4%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Black Robin (48.0%)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākāpō (41.0%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Black Robin&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Banded Dotterel&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Banded Dotterel&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Barn Owl&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Banded Dotterel&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Banded Dotterel&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Black Robin&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Black Robin&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Antipodean Albatross&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Black Robin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Fantail&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākā&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Fantail&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Southern Brown Kiwi&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Kākā&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Excluding votes from unknown countries did not affect which bird won.
New Zealand voters got the outcome for which they voted, whereas Russian voters would have crowned the kākāpō.
Removing Russian votes wouldn&amp;rsquo;t have changed the election outcome&amp;mdash;to the extent that Russians did interfere with the vote, their interference was not successful.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The data used in this post are copyright Forest and Bird, and are released under a &lt;a href=&#34;https://creativecommons.org/licenses/by/4.0/&#34;&gt;CC BY 4.0&lt;/a&gt; license. They are available &lt;a href=&#34;https://www.dragonfly.co.nz/news/2019-11-12-boty.html&#34;&gt;here&lt;/a&gt;. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>How central is Grand Central Terminal?</title>
      <link>https://bldavies.com/blog/how-central-grand-central-terminal/</link>
      <pubDate>Thu, 14 Nov 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/how-central-grand-central-terminal/</guid>
      <description>&lt;p&gt;I spent most of October travelling in the United States.
I visited a range of large cities with correspondingly large subway systems.
New York City&amp;rsquo;s is the most extensive, containing &lt;a href=&#34;https://www.citymetric.com/transport/what-largest-metro-system-world-1361&#34;&gt;more stops than any other subway system in the world&lt;/a&gt;.
Its &lt;a href=&#34;http://www.grandcentralterminal.com&#34;&gt;crown jewel&lt;/a&gt;, Grand Central Terminal, provides access to many cultural and commercial attractions in Midtown Manhattan.&lt;/p&gt;
&lt;p&gt;But just how central is Grand Central?&lt;/p&gt;
&lt;p&gt;To help me answer this question, I created an R package &lt;a href=&#34;https://github.com/bldavies/nyctrains&#34;&gt;nyctrains&lt;/a&gt; that provides data on the NYC subway network.
These data include scheduled travel times between subway stops.
I use these times to construct a travel-time-weighted directed network in which stops are adjacent if they occur consecutively along any route.
I exclude stops along the Staten Island Railway, which is disconnected from the rest of the system.
The plot below maps the resulting network, with nodes positioned by latitude/longitude and with edges coloured by route.
(Some routes overlap.)&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/map-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Estimating Grand Central&amp;rsquo;s centrality requires choosing a measure.
One candidate is &lt;a href=&#34;https://en.wikipedia.org/wiki/Betweenness_centrality&#34;&gt;betweenness centrality&lt;/a&gt;.
Stops are more betweennness-central if trains are more likely to pass through them when taking the fastest route between other stops.&lt;/p&gt;
&lt;p&gt;Another candidate measure is &lt;a href=&#34;https://en.wikipedia.org/wiki/Closeness_centrality&#34;&gt;closeness centrality&lt;/a&gt;.
Stops are more (out-)closeness-central if they have shorter mean fastest travel times to all other stops.
In the NYC subway network, some of these times are infinite because the network is not &lt;a href=&#34;https://en.wikipedia.org/wiki/Strongly_connected_component&#34;&gt;strongly connected&lt;/a&gt;.
For example, it is not possible to get from Grand Central to &lt;a href=&#34;https://subwaynut.com/ind/aqueduct_racetracka/index.php&#34;&gt;Aqueduct Racetrack&lt;/a&gt; without exiting the subway system.&lt;/p&gt;
&lt;p&gt;Closeness centrality measures the extent to which stops provide fast access to other stops.
Another way to measure such access is to count the number of stops that can be reached within a specified time.
For example, the chart below shows the number of stops that can be reached from Grand Central and Broadway Junction within an hour.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/reach-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The number of stops reachable from Grand Central dominates the corresponding number from Brooklyn Junction for all but the smallest travel time allowances.
One way to operationalise this fact is to observe that the area below the red curve exceeds the area below blue curve.
In general, the area below the cumulative reach curve is larger for stops that provide access to more stops in less time.
I compute this area for each stop as a measure of what I call &amp;ldquo;reach&amp;rdquo; centrality.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;The table below reports betweenness and reach centralities for the ten most betweenness-central stops in the NYC subway network, excluding stops on Staten Island.
I normalise centralities to have maximum values equal to unity.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Stop&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Borough&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Betweenness rank (value)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Reach rank (value)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Lexington Av / 59 St&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Manhattan&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1 (1.000)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;23 (0.973)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;125 St&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Manhattan&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2 (0.975)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;118 (0.870)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Jay St - MetroTech&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Brooklyn&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3 (0.959)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;46 (0.951)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;86 St&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Manhattan&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4 (0.952)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;81 (0.926)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Atlantic Av-Barclays Ctr&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Brooklyn&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5 (0.851)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;92 (0.914)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;149 St - Grand Concourse&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Bronx&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6 (0.794)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;158 (0.814)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Grand Central - 42 St&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Manhattan&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7 (0.777)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3 (0.991)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;14 St - Union Sq&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Manhattan&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8 (0.774)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1 (1.000)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Court Sq - 23 St&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Queens&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9 (0.763)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;42 (0.953)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Broadway Junction&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Brooklyn&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;10 (0.747)&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;172 (0.802)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Grand Central is the third most reach-central stop but only the seventh most betweeness-central, contributing to 22% fewer shortest paths than Lexington Avenue/59th Street station.
Broadway Junction is less reach-central than Grand Central&amp;mdash;consistent with the chart above&amp;mdash;but almost as betweeness-central.
The figure below shows the distribution of betweenness and reach centrality across the 424 stops in the network.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/comparison-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Betweenness-central nodes belong to many shortest paths, and so tend to congregate along bottlenecks and highways.
For example, seven of the ten most betweenness-central stops in the NYC subway network provide access to the Lexington Avenue Express (routes 4, 5 and 5X), which is the fastest&amp;mdash;but not only&amp;mdash;route between Brooklyn and the Bronx.
In contrast, reach centrality emanates from mid/lower Manhattan, which (i) is geographically dense with mutually nearby subway stops and (ii) contains the fastest inter-borough connections.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This approach could be improved by adjusting for variation in stops&amp;rsquo; access to unique amenities so that some stops are more valuable to reach than others. However, this variation is not observable in my data. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Climate change and transport planning</title>
      <link>https://bldavies.com/blog/climate-change-transport-planning/</link>
      <pubDate>Wed, 06 Nov 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/climate-change-transport-planning/</guid>
      <description>&lt;p&gt;Last year I organised a &lt;a href=&#34;https://motu.nz/resources/dialogue-groups/&#34;&gt;dialogue&lt;/a&gt; on climate change adaptation within New Zealand&amp;rsquo;s transport sector.
The purpose of the dialogue was to facilitate discussions between researchers, stakeholders and government on adaptation issues relevant to the sector.
&lt;a href=&#34;https://motu.nz/our-work/environment-and-resources/climate-change-impacts/climate-change-adaptation-within-new-zealands-transport-system/&#34;&gt;Motu Note #40&lt;/a&gt;, released today, summarises those discussions.&lt;/p&gt;
&lt;p&gt;Climate change has uncertain supply-side impacts on transport because we don&amp;rsquo;t know when, where or how big will be the events (e.g., storms, floods and landslides) that threaten to damage our infrastructure.
These impacts affect other parts of the transport network by diverting flows away from damaged areas and putting pressure on alternative routes.&lt;/p&gt;
&lt;p&gt;Climate change also has uncertain demand-side impacts on transport through impacts on sectors that use the network.
For example, climate change may trigger land use changes by altering the yields of different crops or the attractiveness of different settlement areas.
These changes shift the spatial allocation of human activity and, consequently, shift users&amp;rsquo; derived demand for transport infrastructure.
However, it is unclear how people will vary their land use in response to climate change because such responses involve complex tradeoffs between economic, social and cultural factors.&lt;/p&gt;
&lt;p&gt;The uncertainty around climate change impacts creates challenges for transport planners, who must forecast climate change itself, how people will respond to the change, and how those responses translate into spatial shifts in the derived demand for transport.&lt;/p&gt;
&lt;p&gt;One solution is to apply real options analysis (ROA) to transport planning and investment decisions.
ROA extends traditional cost-benefit analyses by accounting for managerial flexibility in response to the realisation of future uncertainties, such as the time and place of climate change impacts.
For example, ROA provides tools for valuing the ability to abandon roads that get flooded during storms.
These tools help planners identify investments that meet users&amp;rsquo; needs across a range of climate change scenarios.&lt;/p&gt;
&lt;p&gt;However, real options provide an &lt;a href=&#34;https://bldavies.com/blog/option-value-waiting/&#34;&gt;incentive to delay&lt;/a&gt; investments in order to draw more samples from, and thereby learn more about, the temporal and spatial distributions of climate change impacts.
Such delays halt investment decisions made by transport network users, who rely on the network to conduct economic and social activities, and by utility providers, who provide services that co-locate with transport infrastructure.&lt;/p&gt;
&lt;p&gt;My coauthors and I discuss these issues further in &lt;a href=&#34;https://motu.nz/our-work/environment-and-resources/climate-change-impacts/climate-change-adaptation-within-new-zealands-transport-system/&#34;&gt;Motu Note #40&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Computing epicycles</title>
      <link>https://bldavies.com/blog/computing-epicycles/</link>
      <pubDate>Sun, 03 Nov 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/computing-epicycles/</guid>
      <description>&lt;p&gt;Earlier this year Grant Sanderson, creator of the YouTube channel &lt;a href=&#34;https://www.3blue1brown.com&#34;&gt;3blue1brown&lt;/a&gt;, posted a &lt;a href=&#34;https://www.youtube.com/watch?v=r6sGWTCMz2k&#34;&gt;video&lt;/a&gt; explaining how &lt;a href=&#34;http://mathworld.wolfram.com/FourierSeries.html&#34;&gt;Fourier series&lt;/a&gt; approximate periodic functions using sums of sines and cosines.
In the video and its &lt;a href=&#34;https://www.youtube.com/watch?v=-qgreAUpPwM&#34;&gt;companion&lt;/a&gt;, Grant animates sets of vectors that rotate on circular orbits and, when summed together, reproduce a range of images defined by closed curves.&lt;/p&gt;
&lt;p&gt;Consider, for example, the boundary of GitHub&amp;rsquo;s logo:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/plot-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Let &lt;code&gt;\(\gamma:[0,1]\to\mathbb{R}^2\)&lt;/code&gt; be the closed curve in &lt;code&gt;\(\mathbb{R}^2\)&lt;/code&gt; defining the logo&amp;rsquo;s boundary.
Suppose there is an integer &lt;code&gt;\(n\)&lt;/code&gt; such that
&lt;code&gt;$$\gamma(t) = \sum_{k=-n}^n \gamma_k(t)$$&lt;/code&gt;
for some set of circular orbits &lt;code&gt;\(\gamma_{-n},\ldots,\gamma_n:[0,1]\to\mathbb{R}^2\)&lt;/code&gt; and for all times &lt;code&gt;\(t\in[0,1]\)&lt;/code&gt;.
(Negative and positive subscripts correspond to clockwise and anti-clockwise orbits.
Both may be necessary to reconstruct &lt;code&gt;\(\gamma\)&lt;/code&gt;.)
Each orbit &lt;code&gt;\(\gamma_k\)&lt;/code&gt; has time &lt;code&gt;\(t\)&lt;/code&gt; position defined by the vector
&lt;code&gt;$$\gamma_k(t) = \begin{bmatrix} r_k \cos(2\pi k t + \theta_k) \\ r_k \sin(2\pi k t + \theta_k) \end{bmatrix}$$&lt;/code&gt;
for some radius &lt;code&gt;\(r_k\)&lt;/code&gt;, angular speed &lt;code&gt;\(2\pi k\)&lt;/code&gt; rad/s and initial phase &lt;code&gt;\(\theta_k\)&lt;/code&gt;.
Consequently, the curves &lt;code&gt;\(x,y:[0,1]\to\mathbb{R}\)&lt;/code&gt; defining the horizontal and vertical components of &lt;code&gt;\(\gamma\)&lt;/code&gt; must satisfy the system
&lt;code&gt;$$\begin{align} x(t) &amp;amp;= \sum_{k=-n}^n r_k\cos(2\pi k t + \theta_k) \\ y(t) &amp;amp;= \sum_{k=-n}^n r_k\sin(2\pi k t + \theta_k) \end{align}$$&lt;/code&gt;
of identities.
Let &lt;code&gt;\(z:[0,1]\to\mathbb{C}\)&lt;/code&gt; be the curve with &lt;code&gt;\(z(t)=x(t)+iy(t)\)&lt;/code&gt; for all &lt;code&gt;\(t\in[0,1]\)&lt;/code&gt;.
&lt;a href=&#34;http://mathworld.wolfram.com/EulerFormula.html&#34;&gt;Euler&amp;rsquo;s formula&lt;/a&gt; gives
&lt;code&gt;$$\begin{align} z(t) &amp;amp;= \sum_{k=-n}^n r_k(\cos(2\pi k t + \theta_k) + i \sin(2\pi k t + \theta_k)) \\ &amp;amp;= \sum_{k=-n}^n r_k \exp(2\pi i k t + i\theta_k) \\ &amp;amp;= \sum_{k=-n}^n c_k \exp(2\pi i k t), \end{align}$$&lt;/code&gt;
where each Fourier coefficient &lt;code&gt;\(c_k=r_k\exp(i\theta_k)\)&lt;/code&gt; has modulus &lt;code&gt;\(\lvert c_k\rvert=r_k\)&lt;/code&gt; and (principal) argument &lt;code&gt;\(\mathrm{Arg}(c_k)=\theta_k\)&lt;/code&gt;.
Now, notice that
&lt;code&gt;$$\begin{align} \int_0^1 z(t) \exp(-2\pi i k t)\, \mathrm{d}\,t &amp;amp;= \int_0^1\left(\sum_{j=-n}^n c_j \exp(2\pi i j t)\right)\exp(-2\pi i k t)\, \mathrm{d}\,t \\ &amp;amp;= \int_0^1c_k\, \mathrm{d}\,t + \sum_{j\not=k} c_j \int_0^1 \exp(2\pi i (j - k)t)\, \mathrm{d}\,t \\ &amp;amp;= c_k \end{align}$$&lt;/code&gt;
for each &lt;code&gt;\(k\)&lt;/code&gt; because
&lt;code&gt;$$\int_0^1 \exp(2\pi i (j - k)t)\, \mathrm{d}\,t = 0$$&lt;/code&gt;
for all integers &lt;code&gt;\(j\not=k\)&lt;/code&gt; by the &lt;code&gt;\(2\pi i\)&lt;/code&gt;-periodicity of the complex exponential function.
Thus
&lt;code&gt;$$c_k = \int_0^1 z(t) \exp(-2\pi i k t)\, \mathrm{d}\, t,$$&lt;/code&gt;
which can be calculated using Riemann sums given sample points along the component curves &lt;code&gt;\(x\)&lt;/code&gt; and &lt;code&gt;\(y\)&lt;/code&gt;.
Doing this calculation for each &lt;code&gt;\(k\)&lt;/code&gt;, and computing the corresponding moduli &lt;code&gt;\(r_{-n},\ldots,r_n\)&lt;/code&gt; and arguments &lt;code&gt;\(\theta_{-n},\ldots,\theta_n\)&lt;/code&gt;, provides enough information to generate the animation below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/animation-1.gif&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Introducing nberwp</title>
      <link>https://bldavies.com/blog/introducing-nberwp/</link>
      <pubDate>Tue, 24 Sep 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/introducing-nberwp/</guid>
      <description>&lt;p&gt;Today I published &lt;a href=&#34;https://github.com/bldavies/nberwp&#34;&gt;nberwp&lt;/a&gt;, an R package providing data on &lt;a href=&#34;https://www.nber.org&#34;&gt;NBER&lt;/a&gt; working papers published between 1973 and 2018.
It can be installed from GitHub via &lt;a href=&#34;https://github.com/r-lib/remotes&#34;&gt;remotes&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;remotes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;install_github&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;bldavies/nberwp&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;nberwp provides a data frame &lt;code&gt;papers&lt;/code&gt;, each row describing a unique working paper:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;papers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 25,413 x 4
##    number  year month title                                                     
##     &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;chr&amp;gt;                                                     
##  1      1  1973     6 Education, Information, and Efficiency                    
##  2      2  1973     6 Hospital Utilization: An Analysis of SMSA Differences in …
##  3      3  1973     6 Error Components Regression Models and Their Applications 
##  4      4  1973     7 Human Capital Life Cycle of Earnings Models: A Specific S…
##  5      5  1973     7 A Life Cycle Family Model                                 
##  6      6  1973     7 A Review of Cyclical Indicators for the United States: Pr…
##  7      7  1973     8 The Definition and Impact of College Quality              
##  8      8  1973     9 Multinational Firms and the Factor Intensity of Trade     
##  9      9  1973     9 From Age-Earnings Profiles to the Distribution of Earning…
## 10     10  1973     9 Monte Carlo for Robust Regression: The Swindle Unmasked   
## # … with 25,403 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;number&lt;/code&gt; uniquely identifies working papers by their positions in the series, while &lt;code&gt;year&lt;/code&gt; and &lt;code&gt;month&lt;/code&gt; capture papers&amp;rsquo; publication dates.
The chart below uses these dates to show the NBER catalogue&amp;rsquo;s expansion.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/papers-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;title&lt;/code&gt; facilitates simple text mining, such as determining which words are used in working paper titles most frequently:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidytext&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;words&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;papers&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;unnest_tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;anti_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;get_stopwords&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;nchar&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;[a-z.]&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;distinct&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;words&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 11,636 x 2
##    word         n
##    &amp;lt;chr&amp;gt;    &amp;lt;int&amp;gt;
##  1 evidence  2615
##  2 policy    1350
##  3 market    1322
##  4 effects   1193
##  5 trade     1052
##  6 capital    979
##  7 labor      940
##  8 economic   910
##  9 u.s        882
## 10 health     875
## # … with 11,626 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Many papers discuss capital and labour markets, and the effects of public policies.
The word &amp;ldquo;evidence&amp;rdquo; appears in twice as many titles as any other (non-stop) word, which I suspect reflects the growing use of the &amp;ldquo;&amp;lt;Issue&amp;gt;: Evidence from &amp;lt;context&amp;gt;&amp;rdquo; title format:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/evidence-from-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The NBER&amp;rsquo;s &lt;a href=&#34;https://www.nber.org/RePEc/nbr/nberwo/&#34;&gt;RePEc index&lt;/a&gt;, from which I derive &lt;code&gt;papers&lt;/code&gt;, also contains data linking papers to their authors.
I plan to include these data in a future version of nberwp once I&amp;rsquo;ve disambiguated authors&amp;rsquo; names.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Information gerrymandering</title>
      <link>https://bldavies.com/blog/information-gerrymandering/</link>
      <pubDate>Sat, 14 Sep 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/information-gerrymandering/</guid>
      <description>&lt;p&gt;Last week &lt;em&gt;Nature&lt;/em&gt; published &amp;ldquo;&lt;a href=&#34;https://doi.org/10.1038/s41586-019-1507-6&#34;&gt;Information Gerrymandering and Undemocratic Decisions&lt;/a&gt;,&amp;rdquo; an article analysing the effect of peer influences on the outcome of collective decisions.&lt;/p&gt;
&lt;p&gt;Suppose, for example, that a 24-member committee must collectively decide whether to adopt a new policy.
The committee agrees to make the decision by vote, and will action whichever choice&amp;mdash;accept or reject&amp;mdash;wins a two-thirds majority.
One week before the vote, half of the committee members support the policy and half want it rejected.
Fearing stagnation, each member updates their position daily to match the majority among their six most trusted colleagues.
This update process allows committee members to influence each others&amp;rsquo; positions, potentially shifting the split vote to a decisive majority.&lt;/p&gt;
&lt;p&gt;Assuming trust is pairwise mutual, the &amp;ldquo;influence network&amp;rdquo; among committee members can be modelled as a 6-regular graph on 24 vertices, with edges connecting influencers.
The function below uses this regular graph model to simulate the outcome of many votes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;simulate_votes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_votes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_influences&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_days&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  
  &lt;span class=&#34;c1&#34;&gt;# Create regular graph and identify neighbours&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;k.regular.game&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_influences&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;nb&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;neighborhood&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  
  &lt;span class=&#34;c1&#34;&gt;# Define function for simulating one vote&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;simulate_one&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vote&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;double&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_days&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;init_positions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sample&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%/%&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;replace&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;positions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;init_positions&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;for &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;day&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;seq_len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_days&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;positions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;purrr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;map_dbl&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;nb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;positions[.]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;accepts[day]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;positions&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;init_positions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;init_positions&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
  
  &lt;span class=&#34;c1&#34;&gt;# Simulate many votes&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;votes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lapply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;seq_len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_votes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;simulate_one&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  
  &lt;span class=&#34;c1&#34;&gt;# Return results&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;network&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;results&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;votes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;simulate_one&lt;/code&gt; randomises committee members&amp;rsquo; initial positions&amp;mdash;encoding &amp;ldquo;accept&amp;rdquo; as one and &amp;ldquo;reject&amp;rdquo; as zero&amp;mdash;before updating these positions based on neighbouring majorities.
Running &lt;code&gt;simulate_one&lt;/code&gt; many times allows me to simulate the committee&amp;rsquo;s decision for an ensemble of randomly generated influence networks.
The last few lines of &lt;code&gt;simulate_votes&lt;/code&gt; generate this ensemble and output the simulation results.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s simulate the committee&amp;rsquo;s vote 1000 times, including one week of daily position updates, and tabulate the simulated decision frequencies:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Run simulations&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;24&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;votes&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;simulate_votes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Define function for converting vote counts to committee decisions&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;get_decision&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;case_when&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Accept&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;committee_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Reject&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Deadlock&amp;#39;&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Tabulate decision frequencies&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;map&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;votes&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;results&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;tail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;.$accepts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Decision&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_decision&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accepts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Decision&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;Frequency&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;knitr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;kable&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;align&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Decision&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Frequency&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Accept&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;292&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Deadlock&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;429&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Reject&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;279&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Variation in decisions comes from variation in the influence network&amp;rsquo;s structure.
To see how, let &lt;code&gt;\(\Delta_i\)&lt;/code&gt; denote the proportion of committee member &lt;code&gt;\(i\)&lt;/code&gt;&#39;s influencers with the same initial position on the policy as member &lt;code&gt;\(i\)&lt;/code&gt;, and define
&lt;code&gt;$$a_i = \begin{cases} \Delta_i &amp;amp; \text{if}\ \Delta_i\ge 1/2\\ -(1 - \Delta_i) &amp;amp; \text{otherwise}. \end{cases}$$&lt;/code&gt;
The variable &lt;code&gt;\(a_i\)&lt;/code&gt; captures the &amp;ldquo;influence assortment&amp;rdquo; of committee member &lt;code&gt;\(i\)&lt;/code&gt;.
Positive influence assortment means that they mainly agree with their influencers; negative influence assortment means that they mainly disagree.&lt;/p&gt;
&lt;p&gt;Now let &lt;code&gt;\(\mathcal{A}\)&lt;/code&gt; and &lt;code&gt;\(\mathcal{R}\)&lt;/code&gt; be the sets of committee members whose initial positions are to accept and reject the policy, and consider the difference
&lt;code&gt;$$G = \frac{1}{\lvert\mathcal{A}\rvert}\sum_{i\in\mathcal{A}} a_i - \frac{1}{\lvert\mathcal{R}\rvert}\sum_{j\in\mathcal{R}} a_j$$&lt;/code&gt;
in mean influence assortments between these sets.
The &amp;ldquo;influence gap&amp;rdquo; &lt;code&gt;\(G\)&lt;/code&gt; is greater than zero precisely when committee members in &lt;code&gt;\(\mathcal{A}\)&lt;/code&gt; are, on average, more positively influence assorted than committee members in &lt;code&gt;\(\mathcal{R}\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The scatter plot below shows that &lt;code&gt;\(G\)&lt;/code&gt; correlates positively with the probability that the committee accepts the policy.
Intuitively, positive influence gaps characterise influence networks with disproportionately many neighbouring majorities in favour of acceptance, which, consequently, makes voting to accept the policy more likely.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/correlation-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The relationship between influence gaps and vote outcomes creates an incentive to &lt;a href=&#34;https://en.wikipedia.org/wiki/Gerrymandering&#34;&gt;gerrymander&lt;/a&gt; the influence network to make preferred outcomes more likely.
For example, a subset of committee members wanting to accept the policy could cooperate to gain the trust of specific members so as to construct a positive influence gap.
In political and legal contexts (e.g. elections and jury votes), bad actors may act on the incentive to gerrymander voters&amp;rsquo; influences and, in doing so, pervert the democratic process.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;Nature&lt;/em&gt; article extends my model in three ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it generalises to directed influence networks by relaxing the assumption of pairwise mutual trust;&lt;/li&gt;
&lt;li&gt;it uses a more elaborate rule for updating positions;&lt;/li&gt;
&lt;li&gt;it introduces stubborn committee members (&amp;ldquo;zealots&amp;rdquo;) who never change their position.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;However, none of these extensions change the model&amp;rsquo;s prediction: gerrymandering influence networks can lead to undemocratic decision-making by biasing the outcome of otherwise-split votes.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Sampling the Motu coauthorship network</title>
      <link>https://bldavies.com/blog/sampling-motu-coauthorship-network/</link>
      <pubDate>Tue, 30 Jul 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/sampling-motu-coauthorship-network/</guid>
      <description>&lt;p&gt;Suppose I have some data that describe a bipartite author-publication network.
I want to analyse the underlying coauthorship network&amp;mdash;that is, the bipartite projection onto the set of authors&amp;mdash;but I can&amp;rsquo;t compute that network because the data are too large to fit into memory.
Instead, I estimate &lt;a href=&#34;https://en.wikipedia.org/wiki/Graph_property&#34;&gt;properties&lt;/a&gt; of the full coauthorship network by sampling the author-publication incidence data before computing the bipartite projection.&lt;/p&gt;
&lt;p&gt;If the incidence data are stored as a matrix then I can sample its rows or columns, which corresponds to sampling the author or publication sets.
If the incidence data are stored as a list of author-publication pairs then I can sample these pairs, which corresponds to sampling edges in the bipartite network.&lt;/p&gt;
&lt;p&gt;Which of these three methods&amp;mdash;author, publication and edge sampling&amp;mdash;most reliably estimates the full coauthorship network&amp;rsquo;s properties?&lt;/p&gt;
&lt;p&gt;To develop some intuition, I apply each sampling method to &lt;a href=&#34;https://bldavies.com/blog/coauthorship-networks-motu/&#34;&gt;the coauthorship network among Motu researchers&lt;/a&gt;.
The &lt;a href=&#34;https://github.com/bldavies/motuwp&#34;&gt;data&lt;/a&gt; describing this network are small enough that I can compute the true values of various network properties, which I compare with the sampling distributions of such values generated by each sampling method.&lt;/p&gt;
&lt;p&gt;The table below reports the 95% confidence intervals for each property under each method, in all cases sampling (uniformly at random and without replacement) about half of the corresponding entities (i.e., authors, publications or edges) before computing the bipartite projection onto the set of authors.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Property&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;True value&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Author sampling&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Pub. sampling&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Edge sampling&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Order&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;82.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;42.00 ± 0.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;64.40 ± 0.60&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;64.90 ± 0.60&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Size&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;218.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56.10 ± 2.60&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;137.40 ± 3.40&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;81.80 ± 1.40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Density (%)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.56&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.50 ± 0.30&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.70 ± 0.20&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.00 ± 0.10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mean distance&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.52&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.60 ± 0.10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.70 ± 0.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.10 ± 0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Transitivity (%)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;30.91&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;30.80 ± 2.00&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;31.90 ± 1.30&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.80 ± 1.20&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All three methods under-estimate the order and size of the full coauthorship network.
However, this is partly by construction: sampling any proportion of authors will always deliver that proportion of nodes in the coauthorship network, and taking a strict subset of publications or edges will generally omit some inter-author connections.&lt;/p&gt;
&lt;p&gt;Author and publication sampling deliver accurate density and transitivity estimates.
Edge sampling is less accurate: it produces relatively sparse networks in which authors are more distant, and less likely to share common coauthors, than in the full network.&lt;/p&gt;
&lt;p&gt;The chart below plots the sample means and 95% confidence intervals generated by each sampling method for varying sampling rates.
(A sampling rate of p% means that I randomly select p% of the corresponding entities before computing the coauthorship network.)
As the sampling rate rises, the sample means converge to the true value.
I vertically nudge the plotted points to prevent overlaps and make it easier to compare methods at each sampling rate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/convergence-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Publication sampling over-estimates the coauthorship network&amp;rsquo;s density at low sampling rates.
This could be because most working papers are written by authors in the densely connected core of the coauthorship network, so publication sampling is more likely to recover this core than the less connected and less productive periphery.&lt;/p&gt;
&lt;p&gt;Edge sampling appears to generate biased density and transitivity estimates.
Intuitively, pairs of sampled edges are unlikely to be incident with the same publication and thus unlikely to form an edge in the bipartite projection.&lt;/p&gt;
&lt;p&gt;All three methods under-estimate the mean distance between authors at low sampling rates but over-estimate this distance at high sampling rates.
This pattern arises because the distance calculation considers connected nodes only.
At low sampling rates, most connected components are dyads or triads, and so the distances between connected nodes are small.
The number of nodes in each component rises with the sampling rate, which leads to mean distance over-estimates until the number of edges within each component catches up.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Within each sample, I delete authors with no publications and publications with no authors. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Updating motuwp</title>
      <link>https://bldavies.com/blog/updating-motuwp/</link>
      <pubDate>Sun, 28 Jul 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/updating-motuwp/</guid>
      <description>&lt;p&gt;Today I updated the &lt;a href=&#34;https://github.com/bldavies/motuwp&#34;&gt;motuwp&lt;/a&gt; GitHub repository, which stores data on Motu working papers and their authors.
I made three main changes:&lt;/p&gt;
&lt;p&gt;First, I switched from &lt;a href=&#34;https://www.crummy.com/software/BeautifulSoup/&#34;&gt;BeautifulSoup&lt;/a&gt; to &lt;a href=&#34;https://rvest.tidyverse.org&#34;&gt;rvest&lt;/a&gt; for scraping the working paper directory.
My original Python &lt;a href=&#34;https://github.com/bldavies/motuwp/blob/97c9074908367154fcdddb33d377feb45528e4ae/code/urls.py&#34;&gt;script&lt;/a&gt; used a bunch of regex commands to build the list of working paper URLs, despite warnings that &lt;a href=&#34;https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags&#34;&gt;regular expressions and HTML generally don&amp;rsquo;t cooperate&lt;/a&gt;.
I should have just used CSS selectors, which I now do using &lt;a href=&#34;https://github.com/bldavies/motuwp/tree/8f4b1c02e04f8e5e45b4325195bb4f03ac0ee707/code/data.R&#34;&gt;&lt;code&gt;data.R&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Second, I implemented a caching mechanism for passing information between runs of &lt;code&gt;data.R&lt;/code&gt;.
The script queries only papers released since the last run, so adding new papers is faster and requires fewer HTTP requests.&lt;/p&gt;
&lt;p&gt;Third, I added working paper titles to the information collected.
This allows me to, for example, use &lt;a href=&#34;https://bldavies.com/blog/reading-ministerial-diaries/#computing-tf-idf-scores&#34;&gt;tf-idf scores&lt;/a&gt; to characterise research areas:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/tf-idf-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>College degrees in the US: Community detection</title>
      <link>https://bldavies.com/blog/college-degrees-community-detection/</link>
      <pubDate>Sat, 27 Jul 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/college-degrees-community-detection/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://bldavies.com/blog/college-degrees-similarity-measures/&#34;&gt;my last post&lt;/a&gt;, I compared measures of  similarity among college degree fields.
My goal in this post is to partition the set of fields such that each field has greater within-part similarities than between-part similarities.
One approach is to &lt;a href=&#34;https://en.wikipedia.org/wiki/Hierarchical_clustering&#34;&gt;hierarchically cluster&lt;/a&gt; fields based on their similarities, producing a dendrogram that can be cut at different heights to obtain different partitions.
Generating the dendrogram restricts my choice set but, ultimately, I still have to choose which partition is &amp;ldquo;best.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The intellectually honest way forward is to define an objective function on the set of partitions and choose the partition that obtains the function&amp;rsquo;s maximum.
One such function is network &lt;a href=&#34;https://en.wikipedia.org/wiki/Modularity_%28networks%29&#34;&gt;modularity&lt;/a&gt;, which captures the extent to which groups of nodes are intra-connected densely but inter-connected sparsely.
Ranking partitions by modularity removes the need for supervision: rather than making a subjective, potentially biased judgment on which partition is &amp;ldquo;best,&amp;rdquo; I simply choose the partition that maximises modularity.&lt;/p&gt;
&lt;p&gt;Unfortunately, &lt;a href=&#34;https://arxiv.org/abs/physics/0608255&#34;&gt;maximising modularity is hard&lt;/a&gt;.
In most cases, finding the globally optimal partition is infeasible and a heuristic algorithm must be used to find an approximate solution.
&lt;a href=&#34;https://arxiv.org/abs/cond-mat/0408187&#34;&gt;Clauset et al. (2004)&lt;/a&gt; suggest a &lt;a href=&#34;https://en.wikipedia.org/wiki/Greedy_algorithm&#34;&gt;greedy&lt;/a&gt; algorithm:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Assign every node to a unique &amp;ldquo;community.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Find the pair of communities whose union delivers the greatest increase in modularity. Replace these communities with their union.&lt;/li&gt;
&lt;li&gt;Repeat step 2 until the modularity gain is negative or only one community remains.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The term &amp;ldquo;community&amp;rdquo; refers to a set of nodes and stems from the use of network science to probe the &lt;a href=&#34;https://en.wikipedia.org/wiki/Community_structure&#34;&gt;community structure&lt;/a&gt; of social interactions.&lt;/p&gt;
&lt;p&gt;I apply Clauset et al.&amp;lsquo;s algorithm to the networks defined using the co-occurrence, Dice, Jaccard, Ochiai and overlap measures discussed in &lt;a href=&#34;https://bldavies.com/blog/college-degrees-similarity-measures/&#34;&gt;my previous post&lt;/a&gt;, as well as the unweighted network in which fields are adjacent if at least one graduate studied them both.
The table below presents the number and size of communities detected in each network, and the corresponding maximised modularity values.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Network&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Communities&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Fields&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Community sizes (millions of graduates)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Modularity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Co-occurrences&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;19&amp;ndash;51&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6.4&amp;ndash;19.3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.380&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Dice&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&amp;ndash;50&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.7&amp;ndash;16.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.456&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Jaccard&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&amp;ndash;50&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.7&amp;ndash;19.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.457&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Ochiai&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;13&amp;ndash;40&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.4&amp;ndash;15.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.433&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Overlap&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9&amp;ndash;30&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.9&amp;ndash;17.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.423&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Unweighted&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&amp;ndash;84&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.5&amp;ndash;42.2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.118&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Clauset et al.&amp;lsquo;s algorithm detects eight communities in the Dice, Jaccard, Ochiai and overlap similarity networks, with each community containing at least nine fields and at most 50 fields.
The Jaccard measure delivers the greatest maximum modularity.
Ignoring edge weights makes within- and between-part connections harder to separate, leading to few communities being detected.&lt;/p&gt;
&lt;p&gt;I identify the &amp;ldquo;representives&amp;rdquo; of each community as the fields with the largest ratios of mean within- and between-community similarities.
I transform these ratios by taking their natural logarithm in order to rein in the extreme values caused by near-zero divisors.
The following bar chart presents the representatives of each community detected in the Jaccard similarity network.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/jaccard-representatives-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Communities 2, 3, 4, 5, 7 and 8 appear to capture business, engineering, media, education, agriculture and biology-related fields.
Communities 1 and 6 are less clearly classifiable.&lt;/p&gt;
&lt;p&gt;The table below presents the demographic compositions of the eight communities detected in the Jaccard similarity network.
Community 3 contains nearly 30% of degree fields but only about 20% of graduates, and is the most male-dominated among the eight communities detected.
Community 5 is the most female-dominated and has the highest mean age.
Educational attainment is lowest in communities 2 and 4, and highest in community 8.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Community&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Fields&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Total graduates (millions)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Mean graduate age&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;% of graduates female&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;% of graduates with post-graduate degree&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;28&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;19.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;48.4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;64.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;39.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;11&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;14.4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;47.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;41.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;26.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;50&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;14.1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;47.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;28.4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;42.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;9.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;45.1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;60.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;27.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6.5&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;54.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;76.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;49.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;3.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;43.4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;70.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;33.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;17&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2.1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;47.3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;35.4&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;33.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;15&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;1.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;45.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;54.6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;51.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Overall&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;173&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;71.8&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;47.9&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;52.7&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;36.7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description>
    </item>
    
    <item>
      <title>College degrees in the US: Similarity measures</title>
      <link>https://bldavies.com/blog/college-degrees-similarity-measures/</link>
      <pubDate>Sun, 14 Jul 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/college-degrees-similarity-measures/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://bldavies.com/blog/college-degrees-demographics/&#34;&gt;my last post&lt;/a&gt;, I used the &lt;a href=&#34;https://census.gov/programs-surveys/acs/data/pums.html&#34;&gt;2016 ACS PUMS&lt;/a&gt; data to analyse how educational attainment and degree field choices vary between demographic groups.
I commented that the rates at which graduates pair fields together &amp;ldquo;provide insight into the intellectual connections between fields.&amp;rdquo;
This post compares different ways of estimating the strength of such connections.&lt;/p&gt;
&lt;h2 id=&#34;field-pair-co-occurrences&#34;&gt;Field pair co-occurrences&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/bldavies/college-degrees&#34;&gt;repository&lt;/a&gt; for this post contains the files &lt;code&gt;observations.csv&lt;/code&gt; and &lt;code&gt;fields.csv&lt;/code&gt;, which I import as follows.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;readr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;data_url&lt;/span&gt;     &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;https://raw.githubusercontent.com/bldavies/college-degrees/master/data/&amp;#39;&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;observations&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;read_csv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;paste0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data_url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;observations.csv&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;fields&lt;/span&gt;       &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;read_csv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;paste0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data_url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;fields.csv&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;observations&lt;/code&gt; aggregates the sample weights in the PUMS data by age, sex, and degree level and fields.
I use these weights to construct a field pair co-occurrence matrix &lt;code&gt;C&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;observations&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Aggregate sample weights by field pair&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;level&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;field2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;ifelse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;field2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;field1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wt&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Identify weighted field-respondent pairs&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;respondent&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;row_number&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gather&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;key&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;field2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;field&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;respondent&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wt&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Count field pair co-occurrences&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;widyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;pairwise_count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;field&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;respondent&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wt&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;diag&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Cast to matrix&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;reshape2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;acast&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;item1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;item2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;value.var&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;n&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;fill&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The diagonal elements of &lt;code&gt;C&lt;/code&gt; estimate the total number of graduates with degrees in each field, while the off-diagonal elements estimate the number of graduates that chose each degree field pair.
For example, the elements of the leading submatrix&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;C[1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##          1100     1101    1102     1103    1104
## 1100 181555.0    128.0     0.0    163.5     0.0
## 1101    128.0 124979.0   647.5    971.0   196.5
## 1102      0.0    647.5 47352.5    521.5     0.0
## 1103    163.5    971.0   521.5 173097.0   261.5
## 1104      0.0    196.5     0.0    261.5 46670.0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;provide estimates for the degree fields listed in the first five rows of &lt;code&gt;fields&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fields&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 5 x 2
##   field field_desc                           
##   &amp;lt;dbl&amp;gt; &amp;lt;chr&amp;gt;                                
## 1  1100 General Agriculture                  
## 2  1101 Agriculture Production And Management
## 3  1102 Agricultural Economics               
## 4  1103 Animal Sciences                      
## 5  1104 Food Science
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;About 125,000 graduates hold degrees in Agriculture Production And Management, nearly 1,000 of which also hold degrees in Animal Sciences.
Agricultural Economics attracts about as many graduates as Food Science, but no respondents in the PUMS data reported studying both.&lt;/p&gt;
&lt;h2 id=&#34;similarity-measures&#34;&gt;Similarity measures&lt;/h2&gt;
&lt;p&gt;The diagonal elements of &lt;code&gt;C&lt;/code&gt; estimate the &amp;ldquo;size,&amp;rdquo; in units of graduates, of each degree field.
The distribution of field sizes is positively skewed, with the largest field having more than 30 times the size of the smallest 50% of fields:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;summary&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;diag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10696   54731  142088  415163  407828 4275723
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the elements of &lt;code&gt;C&lt;/code&gt; to measure the strength of connections between fields may lead to biased inferences by, for example, making large fields with proportionally few graduates in common appear to have stronger connections than small fields with proportionally many graduates in common.
One way to avoid such bias is to normalise each element &lt;code&gt;\(c_{ij}\)&lt;/code&gt; of &lt;code&gt;C&lt;/code&gt; by the corresponding field sizes &lt;code&gt;\(s_i=c_{ii}\)&lt;/code&gt; and &lt;code&gt;\(s_j=c_{jj}\)&lt;/code&gt;, thereby producing a scale-invariant &amp;ldquo;similarity&amp;rdquo; measure between pairs of degree fields.&lt;/p&gt;
&lt;p&gt;Dividing &lt;code&gt;\(c_{ij}\)&lt;/code&gt; by the arithmetic mean &lt;code&gt;\((s_i+s_j)/2\)&lt;/code&gt; yields the &lt;a href=&#34;https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient&#34;&gt;Dice coefficient&lt;/a&gt;
&lt;code&gt;$$\mathrm{Dice}(i,j) = \frac{2c_{ij}}{s_i+s_j},$$&lt;/code&gt;
while dividing &lt;code&gt;\(c_{ij}\)&lt;/code&gt; by the geometric mean &lt;code&gt;\(\sqrt{s_is_j}\)&lt;/code&gt; yields the &lt;a href=&#34;https://en.wikipedia.org/wiki/Cosine_similarity#Otsuka-Ochiai_coefficient&#34;&gt;Ochiai coefficient&lt;/a&gt;
&lt;code&gt;$$\mathrm{Ochiai}(i,j) = \frac{c_{ij}}{\sqrt{s_i\,s_j}}.$$&lt;/code&gt;
The Dice coefficient can be used to define the &lt;a href=&#34;https://en.wikipedia.org/wiki/Jaccard_index&#34;&gt;Jaccard index&lt;/a&gt;
&lt;code&gt;$$\begin{align} \mathrm{Jaccard}(i,j) &amp;amp;= \frac{c_{ij}}{s_i + s_j - c_{ij}} \\ &amp;amp;= \frac{\mathrm{Dice}(i,j)}{2 - \mathrm{Dice}(i,j)}, \end{align}$$&lt;/code&gt;
which is conceptually related to the &lt;a href=&#34;https://en.wikipedia.org/wiki/Overlap_coefficient&#34;&gt;overlap coefficient&lt;/a&gt;
&lt;code&gt;$$\mathrm{Overlap}(i,j) = \frac{c_{ij}}{\min(s_i, s_j)}$$&lt;/code&gt;
in that both capture the relative size of set intersections.
These four similarity measures take values on the closed unit interval &lt;code&gt;\([0,1]\)&lt;/code&gt;, with more &amp;ldquo;similar&amp;rdquo; fields achieving values closer to unity.
Indeed, one can show that
&lt;code&gt;$$\mathrm{Jaccard}(i,j) \le \mathrm{Dice}(i,j) \le \mathrm{Ochiai}(i,j) \le \mathrm{Overlap}(i,j) \le 1,$$&lt;/code&gt;
with the two inner inequalities holding with equality if and only if &lt;code&gt;\(s_i=s_j\)&lt;/code&gt;, and with all four inequalities holding with equality if and only if &lt;code&gt;\(s_i=s_j=c_{ij}\)&lt;/code&gt;. Thus, two fields have unit similarity precisely when the sets of graduates with degrees in each field coincide.&lt;/p&gt;
&lt;p&gt;I compute matrices of Dice, Jaccard, Ochiai and overlap similarities by defining&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;diag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;nrow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nrow&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;nrow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and exploiting element-wise matrix operations:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;dice_mat&lt;/span&gt;    &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;jaccard_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;ochiai_mat&lt;/span&gt;  &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sqrt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;overlap_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;pmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;S&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;ordinal-properties&#34;&gt;Ordinal properties&lt;/h2&gt;
&lt;p&gt;One way to compare similarity measures is to compare how they rank fields from most to least similar.
I do so using &lt;a href=&#34;https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient&#34;&gt;Kendall&amp;rsquo;s tau coefficient&lt;/a&gt;, which captures the extent to which two rankings agree on the relative positions of ranked entities.
Kendall&amp;rsquo;s tau is defined as
&lt;code&gt;$$\tau(r_1,r_2) = \frac{2\times\text{Number of concordant pairs}}{\text{Number of pairs}} - 1,$$&lt;/code&gt;
where &lt;code&gt;\(r_1\)&lt;/code&gt; and &lt;code&gt;\(r_2\)&lt;/code&gt; are ranking functions, and where a pair &lt;code&gt;\((x,y)\)&lt;/code&gt; of entities is &amp;ldquo;concordant&amp;rdquo; if &lt;code&gt;\((r_1(x)-r_1(y))\)&lt;/code&gt; and &lt;code&gt;\((r_2(x)-r_2(y))\)&lt;/code&gt; share the same sign.
If every pair is corcordant then &lt;code&gt;\(\tau(r_1,r_2)=1\)&lt;/code&gt; and if none are concordant then &lt;code&gt;\(\tau(r_1,r_2)=-1\)&lt;/code&gt;.
The more &lt;code&gt;\(r_1\)&lt;/code&gt; and &lt;code&gt;\(r_2\)&lt;/code&gt; agree on the relative positions of ranked entities, the greater is the number of concordant pairs and hence the larger is &lt;code&gt;\(\tau(r_1,r_2)\)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Rearranging the definition of &lt;code&gt;\(\tau(r_1,r_2)\)&lt;/code&gt; gives
&lt;code&gt;$$\Pr(\text{Pair is concordant}) = \frac{\tau(r_1, r_2) + 1}{2}.$$&lt;/code&gt;
Thus, computing Kendall&amp;rsquo;s tau for the rankings produced by each similarity measure, and mapping the results linearly to the unit interval, allows me to estimate the rates of agreement between different measures.
I compute these rates as follows, excluding zero and unit similarities, and report the results as a matrix.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;similarities&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Dice&lt;/span&gt;      &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dice_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Jaccard&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;jaccard_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Ochiai&lt;/span&gt;    &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ochiai_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Overlap&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;overlap_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;`Co-occ.`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Include for comparison&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;as.vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;upper.tri&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;similarities&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;method&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;kendall&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;{(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;. &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Map to unit interval&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;round&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##          Dice Jaccard Ochiai Overlap Co-occ.
## Dice    1.000   1.000  0.914   0.778   0.778
## Jaccard 1.000   1.000  0.914   0.778   0.778
## Ochiai  0.914   0.914  1.000   0.864   0.798
## Overlap 0.778   0.778  0.864   1.000   0.765
## Co-occ. 0.778   0.778  0.798   0.765   1.000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Dice and Jaccard measures produce identical rankings, and both reach about 91% and 78% agreement with the rankings produced using the Ochiai and overlap measures.
All four measures produce rankings that reach less than 80% agreement with the ranking produced using co-occurrence counts.&lt;/p&gt;
&lt;p&gt;The following table presents the 10 most similar field pairs using the Dice and Jaccard measures, and those pairs&amp;rsquo; ranks using the Ochiai, overlap and co-occurrence measures.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Field 1&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;Field 2&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Dice/Jacc. rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Ochiai rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Overlap rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Co-occ. rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Plant Science And Agronomy&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Soil Science&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;127&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mathematics Teacher Education&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Science And Computer Teacher Education&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;66&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Biochemical Sciences&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Molecular Biology&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Ecology&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Miscellaneous Biology&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;21&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;146&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mathematics&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Physics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Political Science And Government&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;History&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;48&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Journalism&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Mass Media&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;30&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Social Science Or History Teacher Education&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Language And Drama Education&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;43&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;53&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Accounting&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Finance&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;32&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Soil Science&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Geosciences&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;53&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1048&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Plant Science And Agronomy and Soil Science top the rankings for all four similarity measures, despite being only the 127th most common field pair.
Biochemical Sciences and Molecular Biology, and Mathematics and Physics are the only other field pairs that rank in the top 10 most similar across all four measures.
Accounting and Finance, the most common field pair, ranks in the top 10 most similar fields using the Dice and Jaccard measures only.&lt;/p&gt;
&lt;h2 id=&#34;network-properties&#34;&gt;Network properties&lt;/h2&gt;
&lt;p&gt;Another way to compare similarity measures is to compare properties of the networks they define.
Each similarity matrix defines a network in which nodes represent degree fields and in which edges have weight equal to the similarity between incident nodes.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;get_network&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;adj_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;adj_mat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;graph.adjacency&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mode&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;undirected&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weighted&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;simplify&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Ignore self-similarities&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;coocc_net&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;dice_net&lt;/span&gt;    &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dice_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;jaccard_net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;jaccard_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;ochiai_net&lt;/span&gt;  &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ochiai_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;overlap_net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_network&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;overlap_mat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I compare similarity measures by comparing fields&amp;rsquo; &lt;a href=&#34;https://en.wikipedia.org/wiki/Centrality&#34;&gt;centralities&lt;/a&gt; in each network.
I base my analysis on &lt;a href=&#34;https://en.wikipedia.org/wiki/PageRank&#34;&gt;PageRank&lt;/a&gt; centrality for a variety of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Unlike degree-based centrality measures (e.g., degree and strength), PageRank considers the &amp;ldquo;importance&amp;rdquo; of each neighbour as well as neighbourhood size;&lt;/li&gt;
&lt;li&gt;Unlike distance-based centrality measures (e.g., betweenness and closeness), PageRank doesn&amp;rsquo;t require solving a bunch of &lt;a href=&#34;https://en.wikipedia.org/wiki/Shortest_path_problem&#34;&gt;shortest path problems&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;Unlike eigenvector centrality, PageRank doesn&amp;rsquo;t require the underlying network to be strongly connected.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I store degree fields&amp;rsquo; PageRank centralities as a tibble&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;pageranks&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Dice&lt;/span&gt;      &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;page_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dice_net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Jaccard&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;page_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;jaccard_net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Ochiai&lt;/span&gt;    &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;page_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ochiai_net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;Overlap&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;page_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;overlap_net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;`Co-occ.`&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;page_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;coocc_net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and compute the corresponding matrix of Kendall&amp;rsquo;s tau coefficients, each mapped linearly to the unit interval:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;pageranks&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;cor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;method&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;kendall&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;{(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;. &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;round&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;##          Dice Jaccard Ochiai Overlap Co-occ.
## Dice    1.000   0.999  0.949   0.819   0.824
## Jaccard 0.999   1.000  0.949   0.819   0.823
## Ochiai  0.949   0.949  1.000   0.869   0.839
## Overlap 0.819   0.819  0.869   1.000   0.791
## Co-occ. 0.824   0.823  0.839   0.791   1.000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The rankings of fields from most to least PageRank-central under the Dice and Jaccard measures are almost identical, and reach just over 82% agreement with the ranking produced using co-occurrence counts.&lt;/p&gt;
&lt;p&gt;The table below presents the 10 most PageRank-central fields using the Dice measure, and the corresponding ranks using the Jaccard, Ochiai, overlap and co-occurrence measures.
The column &amp;ldquo;Size rank&amp;rdquo; orders each field from largest to smallest.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Field&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Dice rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Jaccard rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Ochiai rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Overlap rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Co-occ. rank&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Size rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;French German Latin And Other Common Foreign Language Studies&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;35&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mathematics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Political Science And Government&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Mass Media&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Molecular Biology&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;53&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;113&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;English Language And Literature&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;History&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Economics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Psychology&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Sociology&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Languages, Mathematics, and Political Science And Government are the most PageRank-central fields under the Dice, Jaccard and Ochiai measures.
The Ochiai and overlap measures rank Mass Media and Molecular Biology relatively low on PageRank centrality, possibly due to those fields&amp;rsquo; relatively small size.
The PageRank centralities produced using co-occurrence counts appear to correlate positively with field size, consistent with my worry that such counts may bias the measurement of intellectual connectedness in favour of larger fields.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Ryan Tibshirani &lt;a href=&#34;http://www.stat.cmu.edu/~ryantibs/datamining/lectures/03-pr.pdf&#34;&gt;provides excellent notes&lt;/a&gt; on how PageRank handles disconnected components and &amp;ldquo;dangling&amp;rdquo; nodes. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>College degrees in the US: Demographics</title>
      <link>https://bldavies.com/blog/college-degrees-demographics/</link>
      <pubDate>Mon, 01 Jul 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/college-degrees-demographics/</guid>
      <description>&lt;p&gt;Each year, the US Census Bureau &lt;a href=&#34;https://www.census.gov/programs-surveys/acs/data/pums.html&#34;&gt;publishes&lt;/a&gt; a set of Public Use Microdata Sample (PUMS) files containing responses to the American Community Survey (ACS).
In this post, I use the 2016 ACS PUMS data to explore the variation in educational attainment and degree field choices between demographic groups.
The source data are available on &lt;a href=&#34;https://github.com/bldavies/college-degrees/&#34;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;educational-attainment&#34;&gt;Educational attainment&lt;/h2&gt;
&lt;p&gt;The table below reports educational attainment rates for each sex, pooled across all ages and degree fields.
Overall, a randomly selected female is more likely to have a college degree than a randomly selected male.
However, fewer females pursue doctoral degrees than males; male graduates are about 1.4 times more likely to have a doctorate than female graduates.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Degree level&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;% of females&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;% of males&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;No college degree&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;76.95&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;78.62&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Bachelor&amp;rsquo;s degree&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14.66&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;13.46&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Professional or Master&amp;rsquo;s degree&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;7.64&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Doctoral degree&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.75&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Pooling across all ages masks variation in educational attainment rates between age groups.
I present this variation in the line chart below, which compares educational attainment by age and sex.
The chart presents mean age group shares over a rolling five-year window, muting some of the noise in attainment rates caused by random fluctuations between consecutive years of age.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/attainment-line-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Young females have higher educational attainment rates than young males, but the decline in such rates with age is steeper among females than males.
Both sexes experience a spike in attainment between the ages of 60 and 70, corresponding to graduation dates during the late 1960s and early 1970s.
This spike could be due to the &lt;a href=&#34;https://en.wikipedia.org/wiki/Higher_Education_Act_of_1965&#34;&gt;Higher Education Act of 1965&lt;/a&gt;, which &amp;ldquo;strengthen[ed] the educational resources of [US] colleges and universities&amp;rdquo; and &amp;ldquo;provide[d] financial assistance for students in post-secondary and higher education.&amp;rdquo;
The spike is most apparent among males.&lt;/p&gt;
&lt;p&gt;Differences in educational attainment could reflect differences in degree field choices.
For example, to the extent that (i) there are more male science graduates than female science graduates, and (ii) science graduates tend to pursue doctoral degrees more often than non-science graduates, we would expect to see more doctorates among males than females.
If field selection is the only source of differences in educational attainment then there should be no difference in the within-field shares of male and female graduates with post-graduate degrees.
I compare such shares in the scatterplots below, in which points correspond to degree fields and have radii proportional to the number of graduates in each field.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/attainment-scatter-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The gap between the OLS fitted lines and 45-degree reference lines imply that, on average, male graduates are more likely to hold post-graduate degrees than female graduates in the same field.
This discrepancy appears to be larger for doctorates than for other post-graduate degrees.&lt;/p&gt;
&lt;h2 id=&#34;degree-fields&#34;&gt;Degree fields&lt;/h2&gt;
&lt;p&gt;The bar chart below plots the eight most common degree fields among male and female graduates.
Both business and accounting rank among the most common fields for graduates of each sex.
Nursing and education are more common among females, while computer science and engineering are more common among males.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/fields-bar-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The frequency at which people graduate with degrees in different fields may vary over time due to changes in social preferences or labour market conditions.
The line chart below plots the shares of graduates who studied electrical engineering or psychology, statified by age and sex.
The chart presents mean age group shares over a rolling five-year window.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/fields-line-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The trough in male electrical engineering graduates and spike in psychology graduates between the ages of 60 and 70 both coincide with the spike in educational attainment following the Higher Education Act of 1965.
The Act may have encouraged males to substitute from electrical engineering (or from not studying) to psychology by changing the relative benefits and costs of becoming qualified in each field.
For example, increasing access to federal loans may have encouraged students to pursue degrees with less certain job prospects by delaying the private burden of paying tuition.&lt;/p&gt;
&lt;p&gt;The PUMS data report up to two degree fields for each respondent, allowing me to estimate the frequency of field pairings within the US population.
For example, the bar chart below shows the fields most frequently paired with economics and mathematics among graduates of each sex.
Males economics graduates appear to make similar pairing choices to female economics graduates.
Males pair mathematics with physics about as often as with computer science, while females do so only about half as often.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/pairs-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Field pair frequencies provide insight into the intellectual connections between fields.
Such connections may reflect fields using similar techniques (e.g., economics and finance) or providing complementary skills (e.g., mathematics and computer science).
I explore those connections &lt;a href=&#34;https://bldavies.com/blog/college-degrees-similarity-measures/&#34;&gt;here&lt;/a&gt; and &lt;a href=&#34;https://bldavies.com/blog/college-degrees-community-detection/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Reading the ministerial diaries</title>
      <link>https://bldavies.com/blog/reading-ministerial-diaries/</link>
      <pubDate>Wed, 12 Jun 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/reading-ministerial-diaries/</guid>
      <description>&lt;p&gt;In December 2018, the New Zealand Government &lt;a href=&#34;https://www.beehive.govt.nz/release/government-proactively-release-ministerial-diaries&#34;&gt;announced&lt;/a&gt; that its ministers &amp;ldquo;will for the first time release details of their internal and external meetings.&amp;rdquo;
The Government has since published these &amp;ldquo;ministerial diaries&amp;rdquo; as &lt;a href=&#34;https://www.beehive.govt.nz/search?f%5B0%5D=content_type_facet%3Aministerial_diary&amp;amp;f%5B1%5D=government_facet%3A6203&amp;amp;f%5B2%5D=ministers%3A6205&#34;&gt;a series of PDFs&lt;/a&gt;.
In this post, I analyse the ministerial diary of &lt;a href=&#34;https://www.beehive.govt.nz/minister/hon-david-parker&#34;&gt;David Parker&lt;/a&gt;, a &lt;a href=&#34;https://www.odt.co.nz/news/election-2017/parker-emerges-pivotal-cabinet-minister&#34;&gt;&amp;ldquo;pivotal cabinet minister&amp;rdquo;&lt;/a&gt; who wears a range of politically and economically significant hats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Attorney-General;&lt;/li&gt;
&lt;li&gt;Minister of Economic Development;&lt;/li&gt;
&lt;li&gt;Minister for the Environment;&lt;/li&gt;
&lt;li&gt;Minister of Trade and Export Growth;&lt;/li&gt;
&lt;li&gt;Associate Minister of Finance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These roles, coupled with his scheduled activities for the 2018 calendar year being available in &lt;a href=&#34;https://www.beehive.govt.nz/sites/default/files/2019-05/October%202017%20-%20December%202018_0.pdf&#34;&gt;a single, consistently formatted table&lt;/a&gt;, make Minister Parker&amp;rsquo;s diary (hereafter &amp;ldquo;the diary&amp;rdquo;) an interesting and relatively painless document to analyse.&lt;/p&gt;
&lt;h2 id=&#34;parsing-the-data&#34;&gt;Parsing the data&lt;/h2&gt;
&lt;p&gt;I read the diary into R using the &lt;code&gt;pdf_data&lt;/code&gt; function from &lt;a href=&#34;https://cran.r-project.org/package=pdftools&#34;&gt;&lt;code&gt;pdftools&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pdftools&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://www.beehive.govt.nz/sites/default/files/2019-05/October%202017%20-%20December%202018_0.pdf&amp;#34;&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;pages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;pdf_data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;pdf_data&lt;/code&gt; scans each page for distinct words, encloses these words in &lt;a href=&#34;https://en.wikipedia.org/wiki/Minimum_bounding_box&#34;&gt;bounding boxes&lt;/a&gt;, and stores the coordinates and content of each box as a list of tibbles.
For example, the diary&amp;rsquo;s first page contains the following data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;pages[[1]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 336 x 6
##    width height     x     y space text    
##    &amp;lt;int&amp;gt;  &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;lgl&amp;gt; &amp;lt;chr&amp;gt;   
##  1    46     20    72    75 TRUE  David   
##  2    52     20   122    75 TRUE  Parker  
##  3    42     20   179    75 TRUE  Diary   
##  4    77     20   226    75 FALSE Summary 
##  5    11     11    72   102 TRUE  26      
##  6    36     11    85   102 TRUE  October 
##  7    22     11   124   102 TRUE  2017    
##  8     3     11   149   102 TRUE  -       
##  9    11     11   155   102 TRUE  31      
## 10    46     11   168   102 TRUE  December
## # … with 326 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; columns provide the horizontal and vertical displacement, in pixels, of each bounding box from the top-left corner of the page.
The left-most boxes sit 72 pixels from the left page boundary, allowing me to identify table rows by the cumulative number of boxes for which &lt;code&gt;x&lt;/code&gt; equals 72.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;pages[[1]]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;arrange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;72&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;72&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Date&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove preamble&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 91 x 7
##    width height     x     y space text         row
##    &amp;lt;int&amp;gt;  &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;lgl&amp;gt; &amp;lt;chr&amp;gt;      &amp;lt;int&amp;gt;
##  1    21     11    72   355 FALSE Date          14
##  2    46     11   149   355 TRUE  Scheduled     14
##  3    22     11   198   355 FALSE Time          14
##  4    37     11   235   355 FALSE Meeting       14
##  5    38     11   390   355 FALSE Location      14
##  6    21     11   504   355 FALSE With          14
##  7    39     11   630   355 FALSE Portfolio     14
##  8    53     11    72   382 FALSE 26/10/2017    15
##  9    25     11   149   382 TRUE  11:00         15
## 10     3     11   177   382 TRUE  -             15
## # … with 81 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;x&lt;/code&gt; values for which &lt;code&gt;row&lt;/code&gt; equals 14 provide the left alignment points for the text in each of the diary&amp;rsquo;s six columns.
These points remain unchanged across all 84 pages, allowing me to identify rows and columns throughout the diary within a single pipe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Define column names and left alignment points&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;left_x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;72&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;149&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;235&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;390&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;504&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;630&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;date&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;scheduled_time&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;meeting&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;location&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;with&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;portfolio&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Identify page numbers&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;for &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pages[[i]]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;page&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;# Process data&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;diary&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;bind_rows&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Identify table rows&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;arrange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;page&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;left_x[1]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;left_x[1]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Date&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;min&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove header row&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Identify table columns&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sapply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;){&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;which&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;left_x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))}),&lt;/span&gt;
         &lt;span class=&#34;n&#34;&gt;column&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name[column]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Concatenate text within table cells&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;summarise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;paste&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;collapse&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Clean data&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;clean_data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Convert to wide format&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;factor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;levels&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;columns&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;spread&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I define the &lt;code&gt;clean_data&lt;/code&gt; function in &lt;a href=&#34;#appendix&#34;&gt;the appendix&lt;/a&gt; below.&lt;/p&gt;
&lt;p&gt;The resulting tibble &lt;code&gt;diary&lt;/code&gt; contains 1,553 rows, each of which describes a unique entry scheduled between October 2017 and December 2018.
I select entries scheduled during the 2018 calendar year:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;diary&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;grepl&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;2018&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 1,347 x 6
##    date    scheduled_time meeting          location    with         portfolio   
##    &amp;lt;chr&amp;gt;   &amp;lt;chr&amp;gt;          &amp;lt;chr&amp;gt;            &amp;lt;chr&amp;gt;       &amp;lt;chr&amp;gt;        &amp;lt;chr&amp;gt;       
##  1 15/01/… 10:00 - 11:00  Meeting with Fi… Beehive     Treasury of… Associate F…
##  2 15/01/… 14:00 - 14:30  Meeting with MF… Beehive     MFAT offici… Trade and E…
##  3 15/01/… 15:00 - 15:30  Meeting with MB… Beehive     MBIE offici… Economic De…
##  4 16/01/… 09:30 - 10:15  Meeting with En… Selwyn      Environment… Environment 
##  5 16/01/… 10:40 - 11:40  Meeting with Ng… Springston  Ngai Tahu r… Environment 
##  6 16/01/… 12:00 - 12:30  Meeting with fa… Canterbury  Farm owners… Environment 
##  7 16/01/… 12:40 - 13:40  Working Lunch w… Canterbury  Te Waihora … Environment 
##  8 16/01/… 13:50 - 14:45  Meeting with fa… Leeston     Farm owners… Environment 
##  9 16/01/… 16:30 - 17:30  Meeting with Sy… Middleton,… Syft Techon… Economic De…
## 10 17/01/… 09:30 - 10:00  Meeting with Ca… Beehive     Cabinet Off… All         
## # … with 1,337 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;According to &lt;a href=&#34;https://www.beehive.govt.nz/ministerial-diaries-full-disclaimer&#34;&gt;the official disclaimer&lt;/a&gt;, the diary excludes personal and party political meetings, along with details published elsewhere such as time spent in the House of Representatives.
Moreover, some details are withheld under various sections of &lt;a href=&#34;http://legislation.govt.nz/act/public/1982/0156/latest/DLM64785.html&#34;&gt;the Official Information Act&lt;/a&gt;.
I assume that the remaining entries provide a representative sample of Minister Parker&amp;rsquo;s ministerial activities.&lt;/p&gt;
&lt;h2 id=&#34;analysing-word-frequencies&#34;&gt;Analysing word frequencies&lt;/h2&gt;
&lt;p&gt;I analyse the frequency of words used in the &lt;code&gt;with&lt;/code&gt; column of &lt;code&gt;data&lt;/code&gt;.
These frequencies provide insight into Minister Parker&amp;rsquo;s interactions with different organisations.
I use the &lt;code&gt;unnest_tokens&lt;/code&gt; function from &lt;a href=&#34;https://cran.r-project.org/package=tidytext&#34;&gt;&lt;code&gt;tidytext&lt;/code&gt;&lt;/a&gt; to identify unique words and the &lt;code&gt;count&lt;/code&gt; function from &lt;code&gt;dplyr&lt;/code&gt; to count word frequencies.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidytext&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;unnest_tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;with&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;anti_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;get_stopwords&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove stop words&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sort&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 674 x 2
##    word          n
##    &amp;lt;chr&amp;gt;     &amp;lt;int&amp;gt;
##  1 attending   290
##  2 officials   272
##  3 minister    198
##  4 ministers   108
##  5 mfe          89
##  6 mbie         82
##  7 jones        76
##  8 sage         58
##  9 twyford      56
## 10 mfat         53
## # … with 664 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The most frequent word, &amp;ldquo;attending,&amp;rdquo; reflects cabinet meetings, media briefings and other general ministerial duties.
The next most frequent word, &amp;ldquo;officials,&amp;rdquo; reflects Minister Parker&amp;rsquo;s meetings with the Ministry for the Environment (MfE), the Ministry of Business, Innovation and Employment (MBIE), and the Ministry of Foreign Affairs and Trade (MFAT), along with other government departments.
Both &amp;ldquo;minister&amp;rdquo; and &amp;ldquo;ministers&amp;rdquo; reflect meetings with Ministers &lt;a href=&#34;https://www.beehive.govt.nz/minister/hon-shane-jones&#34;&gt;Jones&lt;/a&gt;, &lt;a href=&#34;https://www.beehive.govt.nz/minister/hon-eugenie-sage&#34;&gt;Sage&lt;/a&gt;, &lt;a href=&#34;https://www.beehive.govt.nz/minister/hon-phil-twyford&#34;&gt;Twyford&lt;/a&gt; and others.&lt;/p&gt;
&lt;h3 id=&#34;computing-tf-idf-scores&#34;&gt;Computing tf-idf scores&lt;/h3&gt;
&lt;p&gt;Counting word frequencies across all portfolios masks portfolio-specific interactions.
I infer such interactions from the &lt;a href=&#34;https://www.tidytextmining.com/tfidf.html&#34;&gt;&lt;em&gt;term frequency-inverse document frequency&lt;/em&gt;&lt;/a&gt; (tf-idf) scores of word-portfolio pairs.
I identify these pairs as follows.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;word_portfolio_pairs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Disambiguate portfolio names&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Att.*?ral|AG&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Attorney-General&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Split entries with multiple porfolios&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;[^[:alpha:] -]&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;amp;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
         &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;strsplit&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;amp;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;unnest&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;trimws&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# Identify word-portfolio pairs&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;is.na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;unnest_tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;with&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;tf-idf scores measure the &amp;ldquo;importance&amp;rdquo; of words in each document in a corpus.
The &lt;em&gt;term frequency&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$$\mathrm{tf}(w, d)=\frac{\text{Number of occurrences of word}\ w\ \text{in document}\ d}{\text{Number of words in document}\ d}$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;measures the rate at which word &lt;code&gt;\(w\)&lt;/code&gt; occurs in a document &lt;code&gt;\(d\)&lt;/code&gt;, while the &lt;em&gt;inverse document frequency&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$$\mathrm{idf}(w) = -\ln\left(\frac{\text{Number of documents containing word}\ w}{\text{Number of documents}}\right)$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;provides a normalisation factor that penalises ubiquitous words.
The tf-idf score&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$$\text{tf-idf}(w,d) = \mathrm{tf}(w, d) \cdot \mathrm{idf}(w)$$&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;thus measures the prevalence of word &lt;code&gt;\(w\)&lt;/code&gt; in document &lt;code&gt;\(d\)&lt;/code&gt;, normalised by that word&amp;rsquo;s prevalence in other documents.
I interpret the set of entries associated with each portfolio as a document and use the &lt;code&gt;bind_tf_idf&lt;/code&gt; function from &lt;code&gt;tidytext&lt;/code&gt; to compute word-portfolio tf-idf scores:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;word_portfolio_pairs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;bind_tf_idf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;portfolio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;## # A tibble: 1,066 x 6
##    word        portfolio                   n       tf   idf   tf_idf
##    &amp;lt;chr&amp;gt;       &amp;lt;chr&amp;gt;                   &amp;lt;int&amp;gt;    &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;    &amp;lt;dbl&amp;gt;
##  1 a           Associate Finance           1 0.00285  0.693 0.00197 
##  2 a           Environment                 1 0.000739 0.693 0.000512
##  3 a           Trade and Export Growth     2 0.00277  0.693 0.00192 
##  4 accelerator Economic Development        1 0.00137  1.79  0.00245 
##  5 acting      Attorney-General            1 0.00215  1.79  0.00385 
##  6 action      Trade and Export Growth     1 0.00139  1.79  0.00248 
##  7 adrian      Economic Development        1 0.00137  1.79  0.00245 
##  8 advisory    Economic Development        2 0.00273  0.693 0.00189 
##  9 advisory    Environment                 1 0.000739 0.693 0.000512
## 10 advisory    Trade and Export Growth     1 0.00139  0.693 0.000960
## # … with 1,056 more rows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;idf&lt;/code&gt; column identifies both language-specific stop words (e.g., &amp;ldquo;a&amp;rdquo;) and context-specific stop words (e.g., &amp;ldquo;advisory&amp;rdquo;) that are common across portfolios.&lt;/p&gt;
&lt;p&gt;The chart below presents the highest tf-idf words for each portfolio.
These words reveal organisations (e.g., the Parliamentary Counsel Office) and individuals (e.g., &lt;a href=&#34;https://ec.europa.eu/commission/commissioners/2014-2019/malmstrom_en&#34;&gt;Cecilia Malmström&lt;/a&gt;) that are missing from the diary-wide word frequencies computed above.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/highest-tf-idf-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The chart also reveals which interactions correspond to which portfolios.
For example, Minister Parker&amp;rsquo;s frequent interactions with MBIE officials appear to be most associated with the Economic Development portfolio, while his interactions with Minister Sage appear to involve both the Environment and Associate Finance portfolios.
(&lt;a href=&#34;https://www.greens.org.nz/sites/default/files/Eugenie%20Sage%27s%20July-Sept%202018%20Diary.pdf&#34;&gt;Minister Sage&amp;rsquo;s diary&lt;/a&gt; suggests that such cross-portfolio interactions relate to the Overseas Investment Office, for which Ministers Parker and Sage are jointly responsible.)&lt;/p&gt;
&lt;h2 id=&#34;acknowledgements&#34;&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://ropensci.org/technotes/2018/12/14/pdftools-20/&#34;&gt;The pdftools 2.0 release notes&lt;/a&gt; helped me interpret &lt;code&gt;pdf_data&lt;/code&gt;&#39;s output.
&lt;a href=&#34;https://juliasilge.com&#34;&gt;Julia Silge&lt;/a&gt; and &lt;a href=&#34;http://varianceexplained.org&#34;&gt;David Robinson&lt;/a&gt;&amp;lsquo;s book &lt;a href=&#34;https://www.tidytextmining.com&#34;&gt;&lt;em&gt;Text Mining with R&lt;/em&gt;&lt;/a&gt; provided useful background reading, especially &lt;a href=&#34;https://www.tidytextmining.com/tfidf.html&#34;&gt;the chapter on tf-idf scores&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;appendix&#34;&gt;Appendix&lt;/h2&gt;
&lt;h3 id=&#34;source-code-for-clean_data&#34;&gt;Source code for &lt;code&gt;clean_data()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;clean_data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;c1&#34;&gt;# Replace non-ASCII characters with ASCII equivalents&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;iconv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;ASCII&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sub&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;byte&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;c3&amp;gt;&amp;lt;a7&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;c&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;c3&amp;gt;&amp;lt;a9&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;e&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;c3&amp;gt;&amp;lt;b1&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;c4&amp;gt;&amp;lt;81&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;c5&amp;gt;&amp;lt;ab&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;u&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;e2&amp;gt;&amp;lt;80&amp;gt;&amp;lt;93&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;-&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;e2&amp;gt;&amp;lt;80&amp;gt;&amp;lt;99&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#39;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;e2&amp;gt;&amp;lt;80&amp;gt;&amp;lt;9c&amp;gt;|&amp;lt;e2&amp;gt;&amp;lt;80&amp;gt;&amp;lt;9d&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;\&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;c1&#34;&gt;# Fix linebroken data ranges&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;spread&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;split_date&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;is.na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scheduled_time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;grepl&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;-&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;paste&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;row&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;cumsum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;split_date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;split_date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;gather&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;group_by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;row&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;column&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;summarise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;NA&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;paste&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;collapse&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;ungroup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;trimws&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;ifelse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;NA&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#34;c1&#34;&gt;# Fix transcription errors&lt;/span&gt;
    &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsub&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Minster&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Minister&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
           &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;ifelse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;column&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;portfolio&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Minister Little&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Attorney-General&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Relatedness, complexity and local growth</title>
      <link>https://bldavies.com/blog/relatedness-complexity-local-growth/</link>
      <pubDate>Tue, 02 Apr 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/relatedness-complexity-local-growth/</guid>
      <description>&lt;p&gt;I recently wrote an article for &lt;a href=&#34;https://www.nzae.org.nz/blog-page/nzae-newsletters/&#34;&gt;&lt;em&gt;Asymmetric Information&lt;/em&gt;&lt;/a&gt; summarising &lt;a href=&#34;https://motu.nz/our-work/urban-and-regional/regions/relatedness-complexity-and-local-growth/&#34;&gt;my paper with Dave Maré&lt;/a&gt; on the relatedness and complexity of economic activities in New Zealand.
The full text for that article is quoted below.&lt;/p&gt;
&lt;blockquote&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Current European regional policy encourages regions to build on their strengths by diversifying into activities that draw upon existing knowledge bases.
This &amp;ldquo;smart specialisation&amp;rdquo; approach encourages entrepreneurship, innovation and long-term growth by fostering local interactions between workers with complementary knowledge and skills.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://doi.org/10.1080/00343404.2018.1437900&#34;&gt;Balland et al. (2018)&lt;/a&gt; define a framework for analysing smart specialisation using the ideas of relatedness and complexity.
Expanding into activities that are related to existing specialisations carries low growth risk because local workers already possess the knowledge and skills needed to conduct those activities.
Expanding into complex activities delivers the highest expected economic returns because such activities &amp;ldquo;form the basis for long-run competitive advantage.&amp;rdquo;
Balland et al.&amp;lsquo;s framework identifies low-risk, high-return development opportunities as locally under-represented activities with high local relatedness and high complexity.&lt;/p&gt;
&lt;p&gt;We examine the contribution of relatedness and complexity to urban employment growth in New Zealand.
This allows us to evaluate the efficacy of implementing smart specialisation policies in New Zealand by identifying whether the associated mechanisms appear to influence employment dynamics.&lt;/p&gt;
&lt;h2 id=&#34;data-and-methods&#34;&gt;Data and methods&lt;/h2&gt;
&lt;p&gt;Our analysis uses historical New Zealand census data aligned to current industry, occupation and urban area codes.
We select 50 &amp;ldquo;cities&amp;rdquo; (urban areas) and 200 &amp;ldquo;activities&amp;rdquo; (industry-occupation pairs) with persistently high employment in census years 1981, 1991, 2001 and 2013.
Our selected activities span 61 industries and nine occupations.&lt;/p&gt;
&lt;p&gt;We recognise activities as being &amp;ldquo;related&amp;rdquo; if they require similar inputs.
We infer such similarities from employee co-location patterns.
These patterns reveal firms&amp;rsquo; shared preferences for using spatially heterogeneous resources, which encourage firms engaged in related activities to co-locate in order to benefit from agglomeration economies.&lt;/p&gt;
&lt;p&gt;We measure activities&amp;rsquo; relatedness using weighted correlations of local employment shares.
Our approach extends discrete measures used in previous studies by recognising variation in the extent of local specialisation and by adjusting for differences in employment data quality between geographic areas.&lt;/p&gt;
&lt;p&gt;We recognise activities as being &amp;ldquo;complex&amp;rdquo; if they rely on specialised combinations of complementary inputs.
For example, consulting is more complex than lecturing because consultants need local clients while lecturers do not rely as much on other activities being present locally.&lt;/p&gt;
&lt;p&gt;We define activity complexity using the second eigenvector of the row-standardised activity relatedness matrix.
Our approach generalises &lt;a href=&#34;https://doi.org/10.1371/journal.pone.0047278&#34;&gt;Calderelli et al.&amp;lsquo;s (2012)&lt;/a&gt; eigenvector approximation of &lt;a href=&#34;https://doi.org/10.1073/pnas.0900943106&#34;&gt;Hidalgo and Hausmann&amp;rsquo;s (2009)&lt;/a&gt; Method of Reflections.
We use a similar approach, applied to the transpose of the city-activity employment matrix, to estimate city complexity.&lt;/p&gt;
&lt;h2 id=&#34;mapping-relatedness&#34;&gt;Mapping relatedness&lt;/h2&gt;
&lt;p&gt;We define an &amp;ldquo;activity space&amp;rdquo; that captures the network structure of activities based on our relatedness estimates.
We describe activity space by a weighted network in which nodes correspond to activities and in which edges have weight equal to the relatedness between pairs of activities.
The subnetwork induced by the 500 edges of largest weight is shown below, with nodes coloured by occupation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/activity-space.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;At the centre of our map is a tightly connected, nest-shaped cluster of low-skill occupations in the distributive services sector.
To the right of this cluster is a group of medium- to low-skill occupations in the construction, retail and healthcare sectors.
These activities are ubiquitous and appear together as local relative specialisations in smaller, less diverse cities.
In contrast, the lower wing of our network map comprises a cluster of high-skill occupations in the professional and information service sectors, which tend to concentrate in large cities and to have higher levels of complexity.&lt;/p&gt;
&lt;h2 id=&#34;do-relatedness-and-complexity-predict-employment-growth&#34;&gt;Do relatedness and complexity predict employment growth?&lt;/h2&gt;
&lt;p&gt;More complex activities grew faster during our period of study.
On average and holding local relatedness constant at its weighted mean value, a one standard deviation increase in activity complexity is associated with a 0.89 percentage point increase in local employment growth per year.
This effect rises to 0.98 percentage points when we control for city complexity.
More locally related activities experienced slower growth, especially in complex cities.&lt;/p&gt;
&lt;p&gt;Balland et al.&amp;lsquo;s (2018) framework suggests that complex activities with high local relatedness offer the strongest prospects for future growth.
If this were true then we would expect a strong positive coefficient on the interaction of local relatedness and activity complexity.
Our estimates show only a weak and insignificant interaction.&lt;/p&gt;
&lt;p&gt;Relatedness appears to promote growth only in the largest and most complex cities.
This result is consistent with the idea that cities are dense networks of interacting activities: the benefits of such interaction are more apparent in larger cities, where workers and firms engaged in related activities interact more frequently.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Complex activities grew faster during our period of study, especially in complex cities.
However, this growth was not significantly stronger in cities more dense with related activities.
Overall, we do not identify strong effects of relatedness and complexity on growth in local activity employment.
It remains an open question whether the effects do not operate or whether New Zealand cities lack the scale for such operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Further details are available in &lt;a href=&#34;https://motu.nz/our-work/urban-and-regional/regions/relatedness-complexity-and-local-growth/&#34;&gt;Motu Working Paper 19-01&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Accessing the Strava API with R</title>
      <link>https://bldavies.com/blog/accessing-strava-api/</link>
      <pubDate>Sun, 06 Jan 2019 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/accessing-strava-api/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.strava.com/&#34;&gt;Strava&lt;/a&gt; is an online platform for storing and sharing fitness data.
Strava &lt;a href=&#34;https://developers.strava.com&#34;&gt;provides an API&lt;/a&gt; for accessing such data at the activity (e.g., run or cycle) level.
This post explains how I &lt;a href=&#34;#setup-and-authentication&#34;&gt;authenticate&lt;/a&gt; with, and &lt;a href=&#34;#extracting-the-data&#34;&gt;extract data&lt;/a&gt; from, the Strava API using R.
I implement my method in the R package &lt;a href=&#34;https://github.com/bldavies/stravadata&#34;&gt;stravadata&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;setup-and-authentication&#34;&gt;Setup and authentication&lt;/h2&gt;
&lt;p&gt;Strava uses &lt;a href=&#34;https://oauth.net/2/&#34;&gt;OAuth 2.0&lt;/a&gt; to authorise access to the API data.
The first step to becoming authorised is to register for access on &lt;a href=&#34;https://www.strava.com/settings/api/&#34;&gt;Strava&amp;rsquo;s API settings page&lt;/a&gt;.
I put &amp;ldquo;localhost&amp;rdquo; in the &amp;ldquo;Authorization Callback Domain&amp;rdquo; field.
Upon completing the registration form, the page provides two important values: an integer client ID and an alpha-numeric client secret.
I store these values in &lt;code&gt;credentials.yaml&lt;/code&gt;, which I structure as&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;k&#34;&gt;client_id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;xxxxxxxxx&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;secret&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;xxxxxxxxx&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and import into R using the &lt;code&gt;read_yaml&lt;/code&gt; function from the &lt;a href=&#34;https://cran.r-project.org/package=yaml&#34;&gt;&lt;code&gt;yaml&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;p&gt;Next, I create an OAuth application for interacting with the API and an endpoint through which to send authentication requests.
I use the &lt;code&gt;oauth_app&lt;/code&gt; and &lt;code&gt;oauth_endpoint&lt;/code&gt; functions from &lt;a href=&#34;https://cran.r-project.org/package=httr&#34;&gt;&lt;code&gt;httr&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;httr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;app&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;oauth_app&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;strava&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;credentials&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;client_id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;credentials&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;secret&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;endpoint&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;oauth_endpoint&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;request&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;NULL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;authorize&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://www.strava.com/oauth/authorize&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;access&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://www.strava.com/oauth/token&amp;#34;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, I create an OAuth access token to send the authentication request to my Strava account.
This token encapsulates the application and endpoint defined above.
Running&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;token&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;oauth2.0_token&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;endpoint&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;app&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;as_header&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;FALSE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
                        &lt;span class=&#34;n&#34;&gt;scope&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;activity:read_all&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;opens a browser window at a web page for accepting the authentication request.
Doing so redirects me to the callback domain (&amp;ldquo;localhost&amp;rdquo;) and prints a confirmation message:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Authentication complete. Please close this page and return to R.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;extracting-the-data&#34;&gt;Extracting the data&lt;/h2&gt;
&lt;p&gt;After authenticating with Strava, I use HTTP requests to extract activity data from the API.
The API returns multiple pages of data, each containing up to 200 activities.
I use a while loop to iterate over pages, using the &lt;code&gt;fromJSON&lt;/code&gt; function from &lt;a href=&#34;https://cran.r-project.org/package=jsonlite&#34;&gt;&lt;code&gt;jsonlite&lt;/code&gt;&lt;/a&gt; to parse the extracted data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;jsonlite&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;df_list&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;done&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;FALSE&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;while &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;done&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;req&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;GET&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://www.strava.com/api/v3/athlete/activities&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;config&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;token&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;query&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;per_page&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;page&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;df_list[[i]]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;fromJSON&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;content&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;text&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;flatten&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;if &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;length&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;content&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;done&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;TRUE&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, I use the &lt;code&gt;rbind_pages&lt;/code&gt; function from &lt;code&gt;jsonlite&lt;/code&gt; to collate the activity data into a single data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rbind_pages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df_list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Strava&amp;rsquo;s &lt;a href=&#34;https://developers.strava.com/docs/oauth-updates/&#34;&gt;OAuth update&lt;/a&gt; in October 2019 made &lt;code&gt;scope&lt;/code&gt; specification a requirement. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Guest appearances on *The Joe Rogan Experience*</title>
      <link>https://bldavies.com/blog/guest-appearances-joe-rogan-experience/</link>
      <pubDate>Wed, 26 Sep 2018 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/guest-appearances-joe-rogan-experience/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.joerogan.com/#jre-section&#34;&gt;&lt;em&gt;The Joe Rogan Experience&lt;/em&gt;&lt;/a&gt; (&lt;em&gt;JRE&lt;/em&gt;) is a podcast hosted by comedian and mixed martial arts (MMA) commentator Joe Rogan.
In this post, I analyse the relationship between &lt;em&gt;JRE&lt;/em&gt; guest appearances and popularity using data from &lt;a href=&#34;https://trends.google.com/trends&#34;&gt;Google Trends&lt;/a&gt;.
I find that guests typically experience a spike in popularity immediately after appearing on the podcast.&lt;/p&gt;
&lt;p&gt;The data used in my analysis are available &lt;a href=&#34;https://github.com/bldavies/jre-guests&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;collecting-the-data&#34;&gt;Collecting the data&lt;/h2&gt;
&lt;p&gt;I scrape &lt;a href=&#34;http://podcasts.joerogan.net&#34;&gt;the &lt;em&gt;JRE&lt;/em&gt; podcast directory&lt;/a&gt; for a list of episode dates, numbers and titles.
The directory comprises a multi-page table that is dynamically updated using HTTP requests.
I use &lt;a href=&#34;https://stackoverflow.com/a/46311833&#34;&gt;this method&lt;/a&gt; to emulate such requests, allowing me to iterate over table pages and extract the raw episode metadata.
I clean these data by&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;removing non-standard episodes (such as MMA Shows and Fight Companions),&lt;/li&gt;
&lt;li&gt;fixing any missing, incorrect or duplicate episode numbers, and&lt;/li&gt;
&lt;li&gt;removing non-ASCII characters from episode titles.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/bldavies/jre-guests/blob/master/data/episodes.csv&#34;&gt;The resulting file&lt;/a&gt; contains clean metadata for &lt;em&gt;JRE&lt;/em&gt; episodes #1 through #1172.
I use these data to create &lt;a href=&#34;https://github.com/bldavies/jre-guests/blob/master/data/guests.csv&#34;&gt;a list of guests&lt;/a&gt; that appear in each episode, making several manual adjustments that correct for inconsistent or missing guest names.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;The barchart below plots the number of episodes, unique guests and first appearances by year for 2010 through 2018.
On average, the number of &lt;em&gt;JRE&lt;/em&gt; episodes and guests increased each year, although the proportion of guests appearing on the show for the first time appears to be falling.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/annual-counts-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;estimating-popularity&#34;&gt;Estimating popularity&lt;/h2&gt;
&lt;p&gt;I infer guests&amp;rsquo; popularity from Google Trends data on web searches in the United States.
These data index the proportion of total Google search queries attributable to particular keywords.
Google Trends provides data on a 0&amp;ndash;100 scale, where 100 denotes the maximum search interest for the corresponding keyword in a given period and locale.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;I collect Google Trends data for each identified &lt;em&gt;JRE&lt;/em&gt; guest and for Joe himself.
&lt;a href=&#34;https://github.com/bldavies/jre-guests/blob/master/data/popularity.csv&#34;&gt;My data&lt;/a&gt; provide weekly estimates of individuals&amp;rsquo; online popularity for the five years beginning September 2013.
I assume that these data are unbiased estimates of guests&amp;rsquo; actual popularity.&lt;/p&gt;
&lt;p&gt;The chart below plots Joe&amp;rsquo;s estimated popularity during my sample period.
Web search interest for the phrase &amp;ldquo;Joe Rogan&amp;rdquo; more than doubled between September 2013 and September 2018.
The spike during the first week of September 2018 marks &lt;a href=&#34;https://www.youtube.com/watch?v=ycPr5-27vSI&#34;&gt;&lt;em&gt;JRE&lt;/em&gt; episode #1169 with Elon Musk&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/joe-rogan-popularity-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;identifying-popularity-spikes&#34;&gt;Identifying popularity spikes&lt;/h2&gt;
&lt;p&gt;I align &lt;em&gt;JRE&lt;/em&gt; guest appearance dates with my Google Trends data in order to determine whether such appearances coincide with popularity spikes.
I identify spikes as large, sudden deviations in search interest from its mean value.
I allow this mean to change over time by defining a moving average (MA) series, which I subtract from the actual interest series in order to construct a demeaned series that captures the idosyncratic variation in guests&amp;rsquo; popularity.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;For example, the chart below plots the actual, moving average and demeaned search interest series for Dave Rubin&amp;mdash;political commentator and host of &lt;a href=&#34;https://www.rubinreport.com&#34;&gt;&lt;em&gt;The Rubin Report&lt;/em&gt;&lt;/a&gt;&amp;mdash;who appeared on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt; in the three weeks identified by the dashed vertical lines.
Dave&amp;rsquo;s gradual rise in popularity since late 2015 is punctuated by three spikes in search interest that coincide with his &lt;em&gt;JRE&lt;/em&gt; appearances.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/dave-rubin-popularity-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;I construct the demeaned search interest series for each guest who appears on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt; during my sample period.
I standardise each of these series to have zero mean and unit variance across the entire sample period in order to make the series comparable.
The distributions of guests&amp;rsquo; standardised demeanded search interest in the weeks surrounding their appearances are shown below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/densities-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;In the two weeks prior to appearing on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt;, guests&amp;rsquo; popularities are centred about a standard deviation below their MA trend value, reflecting a rise in that value due to an impending upward shock.
Appearances coincide with a shift in probability density towards positive deviations from local means.
Traces of this shift disappear after about three weeks, at which time the distribution of standardised demeaned search interest mimics that observed five weeks prior.
These dynamics suggest that, on average, &lt;em&gt;JRE&lt;/em&gt; guests experience an increase in popularity during the week in which they appear on the podcast.&lt;/p&gt;
&lt;h2 id=&#34;detecting-spikes-in-real-time&#34;&gt;Detecting spikes in real-time&lt;/h2&gt;
&lt;p&gt;I obtain more rigorous results using &lt;a href=&#34;https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data/22640362#22640362&#34;&gt;this real-time spike detection algorithm&lt;/a&gt;.
The algorithm builds a filtering series alongside the actual search interest series, and computes a rolling mean and standard deviation for the filtering series over the previous &lt;code&gt;lag&lt;/code&gt; observations.
Spikes correspond to values in the actual series that deviate from the filtering mean by some &lt;code&gt;threshold&lt;/code&gt; number of standard deviations.
A third parameter &lt;code&gt;influence&lt;/code&gt; controls how sensitive the filtering series is to spikes.&lt;/p&gt;
&lt;p&gt;The real-time algorithm defines a signal series that denotes super-threshold deviations above and below the filtering mean by 1 and -1, respectively, and sub-threshold deviations by 0.
Positive signals identify spikes in search interest relative to recent trends.
The rate at which such signals coincide with &lt;em&gt;JRE&lt;/em&gt; guest appearances offers insight into whether such appearances herald popularity spikes.&lt;/p&gt;
&lt;p&gt;For example, the chart below plots the actual, filtering and signal series for Dave Rubin&amp;rsquo;s estimated popularity during my sample period, along with the dates of his three &lt;em&gt;JRE&lt;/em&gt; appearances.
I compute the filtering means and standard deviations with &lt;code&gt;lag&lt;/code&gt; equal to 12, and set the filtering threshold at two standard deviations from the filtering mean.
Positive signals register when the actual series deviates above the grey band.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/dave-rubin-signal-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The real-time algorithm identifies spikes coincident with each of Dave&amp;rsquo;s appearances on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt;.
However, it also identifies false positives that reflect other sources of sudden popularity booms.&lt;/p&gt;
&lt;p&gt;I compute the empirical probability that the real-time algorithm detects a spike in guests&amp;rsquo; popularity conditional upon their appearing on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt; in the same or previous week.&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;
The table below reports this probability for a range of &lt;code&gt;lag&lt;/code&gt; and &lt;code&gt;threshold&lt;/code&gt; values, and with &lt;code&gt;influence&lt;/code&gt; equal to 0.5.&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Pr(Spike | Appears)&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;lag = 3&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;lag = 6&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;lag = 9&lt;/code&gt;&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;&lt;code&gt;lag = 12&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;strong&gt;&lt;code&gt;threshold = 1&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.940&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.923&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.905&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.892&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;strong&gt;&lt;code&gt;threshold = 2&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.896&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.866&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.845&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.824&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;strong&gt;&lt;code&gt;threshold = 3&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.837&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.808&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.771&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.748&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;strong&gt;&lt;code&gt;threshold = 4&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.791&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.753&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.725&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;0.696&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Increasing &lt;code&gt;lag&lt;/code&gt; or &lt;code&gt;threshold&lt;/code&gt; lowers the detection rate, indicating that the real-time algorithm is more likely to identify guest appearances when it is more adaptive and less picky.
The negative relationship between detection rate and &lt;code&gt;lag&lt;/code&gt; (with &lt;code&gt;threshold&lt;/code&gt; held constant) suggests that, on average, guests&amp;rsquo; popularities are more volatile over longer horizons: the further back you look in search history, the more likely you are to remember shocks and so the larger new shocks must be to seem uncommon.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In general, appearing on the &lt;em&gt;The Joe Rogan Experience&lt;/em&gt; seems to coincide with a spike in popularity as measured by web search interest.
This result is robust to varying the definition of &amp;ldquo;spike,&amp;rdquo; at least along the dimensions of the &lt;code&gt;lag&lt;/code&gt; and &lt;code&gt;threshold&lt;/code&gt; parameters used by the real-time detection algorithm.&lt;/p&gt;
&lt;p&gt;While suggestive, my analysis is not causal because I do not compare my results with the counterfactual scenario in which treatments (i.e., &lt;em&gt;JRE&lt;/em&gt; appearances) do not occur.
The false positives identified by the real-time algorithm are reminders that my results may be driven by other confounding factors.&lt;/p&gt;
&lt;p&gt;It would be useful to compare guests&amp;rsquo; popularity dynamics near &lt;em&gt;JRE&lt;/em&gt; appearances with those near appearances on other fora.
This comparison would help me separate the effect of increased online presense in general from the effect of appearing on &lt;em&gt;The Joe Rogan Experience&lt;/em&gt; in particular, and may thereby provide stronger hints at causality.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I exclude Brian Redban&amp;rsquo;s appearances prior to episode #674, when he returned as a guest for the first time after producing and co-hosting the show until late 2013. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://support.google.com/trends/answer/4365533?hl=en&amp;amp;ref_topic=6248052&#34;&gt;Google Trends&amp;rsquo; FAQ&lt;/a&gt; does not identify how the raw search proportions get mapped to [0, 100]. I assume that the map is linear so that, for example, an increase from 25 to 50 and from 50 to 100 both constitute a doubling in popularity. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I use an MA order of seven. Thus, each observation in the moving average series is equal to the mean value over the two surrounding months in the actual series. This choice seems to optimally suppress the impact of spikes on local means. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Google Trends provides data in weekly intervals with weeks starting on Saturdays. I include lagged weeks in the detection criterion to allow for latency between &lt;em&gt;JRE&lt;/em&gt; episode transmission and audience response. For example, the web search activity attributable to an episode aired on a Friday may not occur until the Saturday that begins the following week. &lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;I obtain similar patterns with &lt;code&gt;influence&lt;/code&gt; equal to 0.3 and 0.7. &lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Coauthorship networks at Motu</title>
      <link>https://bldavies.com/blog/coauthorship-networks-motu/</link>
      <pubDate>Thu, 21 Jun 2018 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/coauthorship-networks-motu/</guid>
      <description>&lt;p&gt;Earlier this year I joined &lt;a href=&#34;https://motu.nz&#34;&gt;Motu&lt;/a&gt;, an economic and public policy research institute based in Wellington, New Zealand.
In this post, I analyse the coauthorship network among Motu researchers based on working paper publications.
The data used in my analysis are available &lt;a href=&#34;https://github.com/bldavies/motuwp/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;collecting-and-preparing-the-data&#34;&gt;Collecting and preparing the data&lt;/h2&gt;
&lt;p&gt;Bibliographic data are notoriously uncooperative.
Changes in author or institution names make it difficult to uniquely identify researchers across time, reducing data consistency and completeness.
Moreover, most bibliographic databases charge an access fee that discourages casual exploration.
Fortunately, &lt;a href=&#34;https://motu.nz/resources/working-papers/&#34;&gt;Motu&amp;rsquo;s working paper directory&lt;/a&gt; is presented in a consistent format that makes it amenable to web scraping free of charge.&lt;/p&gt;
&lt;p&gt;The R script &lt;a href=&#34;https://github.com/bldavies/motuwp/tree/8f4b1c02e04f8e5e45b4325195bb4f03ac0ee707/code/data.R&#34;&gt;&lt;code&gt;data.R&lt;/code&gt;&lt;/a&gt; scrapes the directory for a list of working paper IDs and URLs.
Each URL points to a landing page for the corresponding paper, which I scrape for a list of authors.
I include only those authors with outgoing hyperlinks because&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;the hyperlinked URL provides a unique and persistent author ID, and&lt;/li&gt;
&lt;li&gt;it is much easier to perform a regular expression search for &lt;code&gt;&amp;lt;a href=&amp;quot;(.*?)&amp;quot;&amp;gt;&lt;/code&gt; than to distinguish different uses of commas case-by-case.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The resulting file &lt;a href=&#34;https://github.com/bldavies/motuwp/tree/8f4b1c02e04f8e5e45b4325195bb4f03ac0ee707/data/authors.csv&#34;&gt;&lt;code&gt;authors.csv&lt;/code&gt;&lt;/a&gt; contains each unique author-paper pair.
It excludes the authors of five papers for which either (i) there is no landing page linked from the main directory or (ii) the landing page has no authors with outgoing hyperlinks.&lt;/p&gt;
&lt;p&gt;I read in &lt;code&gt;authors.csv&lt;/code&gt; and two other tables:
&lt;a href=&#34;https://github.com/bldavies/motuwp/tree/8f4b1c02e04f8e5e45b4325195bb4f03ac0ee707/data/areas.csv&#34;&gt;&lt;code&gt;areas.csv&lt;/code&gt;&lt;/a&gt;, which contains the name, ID and ambient colour for each of &lt;a href=&#34;https://motu.nz/our-work/&#34;&gt;Motu&amp;rsquo;s six primary research areas&lt;/a&gt;; and
&lt;a href=&#34;https://github.com/bldavies/motuwp/tree/8f4b1c02e04f8e5e45b4325195bb4f03ac0ee707/data/papers.csv&#34;&gt;&lt;code&gt;papers.csv&lt;/code&gt;&lt;/a&gt;, which links each paper to its research area.
I merge these data into a single tibble &lt;code&gt;data&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;authors&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;left_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;papers&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;left_join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;areas&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;the-authorship-network&#34;&gt;The authorship network&lt;/h2&gt;
&lt;p&gt;I next construct an authorship network by pairing papers with their authors using the information contained in &lt;code&gt;data&lt;/code&gt;.
I achieve this by defining an author-paper incidence matrix&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;incidence&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;table&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;author&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;paper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and using that matrix to create a bipartite network &lt;code&gt;bip&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph.incidence&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;incidence&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The authorship network &lt;code&gt;bip&lt;/code&gt; contains 74 authors who collectively wrote 232 working papers over the 2003&amp;ndash;2018 sample period.
Those papers are distributed across Motu&amp;rsquo;s research areas as shown in the chart below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/area-counts-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The variation in working paper counts reflects the variation in areas&amp;rsquo; tenure within Motu&amp;rsquo;s research portfolio.
Environment and Resources, contributing 67 working papers, has been around since the series began; Human Rights, appearing only once in the series, is a relatively new research area for Motu.&lt;/p&gt;
&lt;p&gt;The authorship network &lt;code&gt;bip&lt;/code&gt; is drawn below using &lt;a href=&#34;https://onlinelibrary.wiley.com/doi/abs/10.1002/spe.4380211102&#34;&gt;Fruchterman and Reingold&amp;rsquo;s (1991)&lt;/a&gt; force-directed algorithm.
Squares denote working papers and are coloured by research area.
Each circle denotes an author and is scaled according to the number of working papers (co)written by that author.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/author-network-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;A striking feature of &lt;code&gt;bip&lt;/code&gt; is the presence of three high-degree vertices, or &lt;em&gt;hubs&lt;/em&gt;, each representing an author of at least 48 working papers.
These hubs are shaded in the map of &lt;code&gt;bip&lt;/code&gt; shown above.
Another feature is the variation in area diversity within authors&amp;rsquo; individual corpuses.
Urban and Regional authors tend to also write papers on Wellbeing and Macroeconomics, while Environment and Resources authors are more specialised.&lt;/p&gt;
&lt;h2 id=&#34;the-coauthorship-network&#34;&gt;The coauthorship network&lt;/h2&gt;
&lt;p&gt;Projecting &lt;code&gt;bip&lt;/code&gt; onto the set of authors yields a coauthorship network in which two authors are adjacent if they have written a paper together.
I define such a projection via&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;bipartite.projection&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;[[1]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I use the &lt;a href=&#34;https://github.com/bldavies/pokenet/blob/master/code/jaccard.R&#34;&gt;&lt;code&gt;jaccard&lt;/code&gt;&lt;/a&gt; function described in my previous post to determine the similarity between two authors from their authorship counts.
According to this measure, maximally similar authors always write together while maximally dissimilar authors never write together.
Again, I use the Fruchterman-Reingold algorithm for distributing vertices in the plane.
The resulting map of &lt;code&gt;net&lt;/code&gt; is shown below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/coauthor-network-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The coauthorship network is sparse, containly only 168 (about 6%) of the 2,701 possible edges between its 74 vertices.
However, the largest connected component (LCC) of &lt;code&gt;net&lt;/code&gt; contains all but six authors, two of whom write exclusively with each other and the remaining four having zero coauthors.
Such connectivity is facilitated by the three shaded hubs identified above.&lt;/p&gt;
&lt;h3 id=&#34;hints-of-small-worldness&#34;&gt;Hints of small-worldness&lt;/h3&gt;
&lt;p&gt;The sparsity of &lt;code&gt;net&lt;/code&gt; implies that most pairs of authors aren&amp;rsquo;t coauthors.
Indeed, the probability that two randomly selected authors are coauthors is given by &lt;code&gt;net&lt;/code&gt;&#39;s edge density: about 0.06.
However, it is not unusual for two randomly selected authors to share a common coauthor; within the LCC of &lt;code&gt;net&lt;/code&gt;, the probability of such an event is about 0.46.
I calculate this probability by examining the distribution of (unweighted) &lt;a href=&#34;https://en.wikipedia.org/wiki/Distance_%28graph_theory%29&#34;&gt;geodesic distances&lt;/a&gt; between the vertices in &lt;code&gt;net&lt;/code&gt; and determining the proportion of vertex pairs that are distance two apart.
The following function performs that calculation for an arbitrary connected graph &lt;code&gt;G&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;common_neighbour_rate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;distances&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weights&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;num_pairs&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;choose&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;rate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;sum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;num_pairs&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Mean within upper right triangle&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;return &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The function &lt;code&gt;common_neighbour_rate&lt;/code&gt; works by computing the geodesic distances between each pair of vertices in &lt;code&gt;G&lt;/code&gt;, defining binary indicator variables (as entries of the matrix &lt;code&gt;B&lt;/code&gt;) for whether each distance is equal to two and taking the average of those variables over all possible vertex pairs.
Its name comes from recognising that &amp;ldquo;coauthor&amp;rdquo; is a context-specific synonym for &amp;ldquo;neighbouring vertex.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Within the LCC of &lt;code&gt;net&lt;/code&gt;, the average distance between any two authors is equal to 2.5 while the maximum such distance&amp;mdash;the &lt;em&gt;diameter&lt;/em&gt; of the LCC&amp;mdash;is equal to five.
These numbers suggest a smallness about the world inhabited by Motu working paper authors: if you ask anyone if they&amp;rsquo;ve written a paper with so-and-so, the answer you&amp;rsquo;ll get is probably, &amp;ldquo;no, but I&amp;rsquo;ve written with someone who has written with someone that has.&amp;rdquo;
It appears that, at least in terms of geodesic distances, Motu researchers are seldom far apart.&lt;/p&gt;
&lt;h3 id=&#34;testing-for-small-worldness&#34;&gt;Testing for small-worldness&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://www.nature.com/articles/30918&#34;&gt;Watts and Strogatz (1998)&lt;/a&gt; formalise the idea of small-worldness.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
They identify small-world networks as those that are&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;highly clustered &amp;hellip; yet have small characteristic path lengths.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The extent to which a network is clustered is determined by its &lt;a href=&#34;https://en.wikipedia.org/wiki/Clustering_coefficient#Global_clustering_coefficient&#34;&gt;clustering coefficient&lt;/a&gt;, while the characteristic path length is simply the mean geodesic distance between pairs of vertices.
Intuitively, a network is small-world if it has local communities whose links are mostly internal but with a few external links that facilitate fast inter-community exchange.
For example, most flights undertaken by New Zealanders comprise travel within our dense domestic network, but a Cantabrian wanting to holiday in Bangkok or Dubai need only make a pitstop in Sydney.
The latter acts as a hub that connects many distant cities in the same way that the three shaded vertices in the map of &lt;code&gt;net&lt;/code&gt; above connect many otherwise distant authors.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0002051&#34;&gt;Humphries and Gurney (2008)&lt;/a&gt; describe a method for determining small-worldness using random graphs.
Their strategy is to compare the clustering coefficient and mean distance between vertices in a network to the expected value of those attributes if edges are randomly distributed.
Concretely, they state that&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A network with &lt;code&gt;n&lt;/code&gt; nodes and &lt;code&gt;m&lt;/code&gt; edges is a small-world network if it has a similar path length but greater clustering of nodes than an equivalent Erdös-Rényi random graph with the same &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;m&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93R%C3%A9nyi_model&#34;&gt;Erdös-Rényi model&lt;/a&gt; is a simple method of generating random graphs with a fixed number of vertices and edges, the latter being placed between vertex pairs with uniform probability and without duplication.
Such graphs tend to have short mean distances because edges are as likely to traverse the network and bridge communities as they are to consolidate an already tight local community.
Likewise, random edge assignment disregards community formation, causing Erdös-Rényi graphs to have small clustering coefficients.&lt;/p&gt;
&lt;p&gt;The function below computes the clustering coefficient (known to &lt;code&gt;igraph&lt;/code&gt; users as &lt;code&gt;transitivity&lt;/code&gt;) and characteristic path length for a sample of Erdös-Rényi random graphs that are equivalent to an arbitrary graph &lt;code&gt;G&lt;/code&gt;.
The sample means of these attributes provide baselines against which to measure the corresponding values observed from &lt;code&gt;G&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;small_world_baselines&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;seed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;set.seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;transitivity_samples&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;mean_distance_samples&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;for &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;er&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;sample_gnm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;transitivity_samples[i]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;transitivity&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;er&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;mean_distance_samples[i]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean_distance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;er&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;FALSE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;return &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transitivity&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transitivity_samples&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
               &lt;span class=&#34;n&#34;&gt;mean_distance&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean_distance_samples&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The coauthorship network &lt;code&gt;net&lt;/code&gt; has clustering coefficient 0.24 and mean distance 2.49, with baseline comparators of 0.06 and 2.96.
Thus, &lt;code&gt;net&lt;/code&gt; is about four times as clustered as is expected for a network with its density and has slightly shorter geodesic distances than would be obtained by allocating edges randomly.
These facts positively indicate small-worldness, and reflect widespread collaboration between authors within and between research areas.&lt;/p&gt;
&lt;p&gt;Humphries and Gurney define a &lt;em&gt;small-world coefficient&lt;/em&gt; by taking the ratio of observed and expected clustering coefficients, and dividing the result by the ratio of observed and expected mean distances.
This quotient is larger than one for small-world networks.
The coauthorship network &lt;code&gt;net&lt;/code&gt; obtains a small-world coefficient of 4.67, thereby passing the Humphries-Gurney small-worldness test.&lt;/p&gt;
&lt;h2 id=&#34;subsampling-by-research-area&#34;&gt;Subsampling by research area&lt;/h2&gt;
&lt;p&gt;Finally, I analyse the coauthorship network within Motu&amp;rsquo;s five largest research areas.
I filter the working papers from &lt;code&gt;data&lt;/code&gt; that correspond to each area and recompute several statistics mentioned earlier using the subsample data.
The first set of statistics is shown in the table below.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Area&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Papers&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Authors&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Edge density&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;LCC order&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;LCC diameter&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Environment and Resources&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;67&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;37&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.08&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Population and Labour&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.13&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Urban and Regional&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;50&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;32&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.09&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Wellbeing and Macroeconomics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;35&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.13&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Productivity and Innovation&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;18&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.20&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;17&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Environment and Resources boasts the largest number of authors as well as working papers. However, it has the least dense coauthorship network, containing only 8% of all possible edges.
The Productivity and Innovation coauthorship network is the most dense.
The largest connected component of the Wellbeing and Macroeconomics coauthorship network is the smallest among the five areas; however, every pair of authors within its LCC are coauthors or share a common coauthor.&lt;/p&gt;
&lt;p&gt;I also test each area&amp;rsquo;s coauthorship network for small-worldness using the Humphries-Gurney procedure.
The results are tabulated below.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Area&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Clustering coefficient (baseline)&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Mean distance (baseline)&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Small-world coefficient&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Environment and Resources&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.25 (0.08)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.93 (3.16)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;5.13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Population and Labour&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.33 (0.13)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.15 (2.56)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.01&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Urban and Regional&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.17 (0.09)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.13 (3.04)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.71&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Wellbeing and Macroeconomics&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.19 (0.11)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.77 (2.88)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Productivity and Innovation&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.39 (0.19)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.24 (2.31)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.17&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All five areas have small-world coefficients greater than one, and therefore satisfy Humphries and Gurney&amp;rsquo;s criterion.
However, the ratio of observed and baseline clustering coefficients is not as large in any area as it is in the full coauthorship network.
Moreover, only two areas have mean distances close to those expected in an equivalent Erdös-Rényi random graph.
The best candidate for a small world&amp;mdash;that is, a world with high clustering and as-random geodesic distances&amp;mdash;is the Productivity and Innovation coauthorship network, despite it having the lowest small-world coefficient.&lt;/p&gt;
&lt;p&gt;I suspect that network size adds considerable noise to these estimates.
Even the full coauthorship network &lt;code&gt;net&lt;/code&gt; is barely large enough to exhibit any global structure that can be distinguished from randomness.
Applying the Humphries-Gurney test to a larger network, or implementing a more robust procedure such as that proposed by &lt;a href=&#34;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3604768/&#34;&gt;Telesford &lt;em&gt;et al.&lt;/em&gt; (2011)&lt;/a&gt;, may yield cleaner results.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: I updated this post on July 28, 2019 after revising the &lt;a href=&#34;https://github.com/bldavies/motuwp/&#34;&gt;source data&lt;/a&gt;. My results changed slightly due to retroactive author (re)assignments.&lt;/em&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;The linked article is locked behind a paywall. However, Strogatz hosts &lt;a href=&#34;http://www.stevenstrogatz.com/articles/collective-dynamics-of-small-world-networks-pdf&#34;&gt;a free copy&lt;/a&gt; on his website. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Habitat choices of first-generation Pokémon</title>
      <link>https://bldavies.com/blog/habitat-choices-first-generation-pokemon/</link>
      <pubDate>Thu, 01 Mar 2018 00:00:00 +0000</pubDate>
      
      <guid>https://bldavies.com/blog/habitat-choices-first-generation-pokemon/</guid>
      <description>&lt;p&gt;In this post, I use R&amp;rsquo;s &lt;a href=&#34;http://igraph.org&#34;&gt;igraph&lt;/a&gt; package to analyse the cohabitation network among wild Pokémon species.
The underlying data come from &lt;a href=&#34;https://github.com/veekun/pokedex&#34;&gt;the GitHub repository&lt;/a&gt; behind &lt;a href=&#34;https://veekun.com&#34;&gt;veekun&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;matching-species-with-their-habitats&#34;&gt;Matching species with their habitats&lt;/h2&gt;
&lt;p&gt;I infer habitats from random encounter events in the international versions of Pokémon Red, Blue and Yellow.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
I store these events in a data frame named &lt;code&gt;encounters&lt;/code&gt;.
Each encounter has three attributes: the &lt;code&gt;location&lt;/code&gt;, the &lt;code&gt;species&lt;/code&gt; encountered and that species&amp;rsquo; primary &lt;code&gt;type&lt;/code&gt;.
I use these data to generate a species-location incidence matrix:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;table&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encounters&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;species&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;encounters&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;location&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The rows and columns of &lt;code&gt;habits&lt;/code&gt; count where species habitate.
For example, summing the rows of &lt;code&gt;habits&lt;/code&gt; yields the number of unique habitats for each species.
I store these sums as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;pokemon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;species&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rownames&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ubiquity&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;rowSums&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Goldeen, Magikarp and Poliwag are the most ubiquitous species.
Each habitate in 24 unique locations across the Kanto region.&lt;/p&gt;
&lt;p&gt;The boxplots below show the distribution of &lt;code&gt;ubiquity&lt;/code&gt; by species&amp;rsquo; primary type.
Water-types have the highest median ubiquity, closely followed by Grass- and Normal-types.
Species with Dragon, Fairy or Ghost as their primary type each habitate in a single location.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/ubiquity-distribution-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The column sums of &lt;code&gt;habits&lt;/code&gt; count the number of unique species that habitate in each location.
I store these sums as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;locations&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tibble&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;colnames&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;diversity&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;colSums&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I compute the mean value of &lt;code&gt;diversity&lt;/code&gt; across the locations in which each species habitates via&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;pokemon&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean_diversity&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;colSums&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;locations&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;diversity&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pokemon&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ubiquity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;ubiquity&lt;/code&gt; and &lt;code&gt;mean_diversity&lt;/code&gt; share a correlation coefficient of about -0.22, suggesting that they share a weak negative relationship.
Thus, on average, more ubiquitous species tend to live in less diverse locations.
However, this relationship is skewed by a large number of species that cohabitate in one or two locations as shown in the chart below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/ubiquity-mean-diversity-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The chart plots &lt;code&gt;mean_diversity&lt;/code&gt; against &lt;code&gt;ubiquity&lt;/code&gt;, along with the least-squares line of best fit.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;
The top-left cluster comprises species that exclusively habitate inside Cerulean Cave or the Kanto Safari Zone.
This cluster has a strong positive effect on &lt;code&gt;mean_diversity&lt;/code&gt; among species with low &lt;code&gt;ubiquity&lt;/code&gt; values, driving the negative relationship between the two attributes.&lt;/p&gt;
&lt;h2 id=&#34;the-cohabitation-network&#34;&gt;The cohabitation network&lt;/h2&gt;
&lt;p&gt;Species reveal their preference toward spending time with each other through their choice of whether to share habitats.
The more frequently two species cohabitate, the stronger is their implied social connection.
The number of locations in which two species cohabitate is equal to the cross product of the two corresponding rows of &lt;code&gt;habits&lt;/code&gt;.
I store these counts in a symmetric species-species adjacency matrix:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;cohabits&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%*%&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Each entry &lt;code&gt;cohabits[i, j]&lt;/code&gt; is equal to the number of locations in which species &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; cohabitate, and each diagonal entry &lt;code&gt;cohabits[i, i]&lt;/code&gt; is equal to the ubiquity of species &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;estimating-the-strength-of-species-social-ties&#34;&gt;Estimating the strength of species&amp;rsquo; social ties&lt;/h3&gt;
&lt;p&gt;The raw cohabitation counts are an imperfect measure of the strength of the social ties between species.
For example, ubiquitous species tend to have higher cohabitation counts with all other species and so appear to be more social.
However, having many social connections may indicate that a species &amp;ldquo;spreads itself thin&amp;rdquo; and that each of its connections are actually quite weak.
Strong connections arise when two species spend lots of their time together and little of their time apart.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Jaccard_index&#34;&gt;Jaccard index&lt;/a&gt; provides a convenient measure of the tendency for two species to spend most of their time in each others&amp;rsquo; company.
The index counts the number of locations in which two species cohabitate as a proportion of the locations in which at least one of those species habitates.
I define a function &lt;code&gt;jaccard&lt;/code&gt; for computing Jaccard indices from an arbitrary cohabitation matrix &lt;code&gt;C&lt;/code&gt; as follows.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;jaccard&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;U&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;rep&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;diag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;nrow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ncol&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;nrow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;H&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;U&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;U&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;J&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;C&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;H&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;return &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;J&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If &lt;code&gt;C = cohabits&lt;/code&gt; then each column of &lt;code&gt;U&lt;/code&gt; is equal to the vector &lt;code&gt;pokemon$ubiquity&lt;/code&gt;, and each entry &lt;code&gt;H[i, j]&lt;/code&gt; of &lt;code&gt;H&lt;/code&gt; counts the number of locations in which at least one of species &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; habitate.
The Jaccard index &lt;code&gt;J[i, j]&lt;/code&gt; obtains its maximum value of unity when species &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; habitate in precisely the same locations, and its minimum value of zero when they never cohabitate.
The more similar two species&amp;rsquo; habitat choices, the higher is their shared Jaccard index.&lt;/p&gt;
&lt;p&gt;I define the cohabitation network &lt;code&gt;net&lt;/code&gt; as the weighted graph with adjacency matrix equal to &lt;code&gt;jaccard(cohabits)&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;igraph&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph.adjacency&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;jaccard&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cohabits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weighted&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mode&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;undirected&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;simplify&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove loops&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;identifying-the-strongest-connections&#34;&gt;Identifying the strongest connections&lt;/h3&gt;
&lt;p&gt;The cohabitation network contains 1,549 (about 31%) of the 4,950 possible edges between its 100 vertices.
However, many of these edges have low weight and correspond to weak social connections between species, whereas I&amp;rsquo;m most interested in identifying which species share strong connections.&lt;/p&gt;
&lt;p&gt;I identify an edge-induced subgraph of &lt;code&gt;net&lt;/code&gt; that represents the strongest connections as follows.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;
First, I find a maximum spanning forest (MSF) of &lt;code&gt;net&lt;/code&gt;; that is, an edge-induced subgraph that&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;has the same vertex set as &lt;code&gt;net&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;has trees as components, and&lt;/li&gt;
&lt;li&gt;obtains the maximum edge weight sum over all edge-induced subgraphs satisfying criteria 1 and 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The MSF joins each species with one of the species with which it most frequently cohabitates.
However, depending on the algorithm used, the MSF generally doesn&amp;rsquo;t join every species with its most frequent cohabitant and therefore doesn&amp;rsquo;t necessarily contain the strongest connections in &lt;code&gt;net&lt;/code&gt;.&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;
Accordingly, I augment the MSF by taking its union with the subgraph induced by the edges in &lt;code&gt;net&lt;/code&gt; of highest weight.
I choose the number of such edges to be equal to the order of &lt;code&gt;net&lt;/code&gt; so as to achieve a mean vertex degree of about four.&lt;/p&gt;
&lt;p&gt;I define a function &lt;code&gt;augmented_msf&lt;/code&gt; for identifying the augmented MSF of a graph &lt;code&gt;G&lt;/code&gt; as follows.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;augmented_msf&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;seq&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;msf_ids&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;mst&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;cutoff&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;quantile&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gorder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gsize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;[1]&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;aug_ids&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;which&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;$&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cutoff&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;n&#34;&gt;aug_msf&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;subgraph.edges&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eids&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;E&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;[unique&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;msf_ids&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;aug_ids&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
  &lt;span class=&#34;nf&#34;&gt;return &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;aug_msf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The third and fourth lines in the definition of &lt;code&gt;augmented_msf&lt;/code&gt; identify the edges of &lt;code&gt;G&lt;/code&gt; with which to augment its MSF.
For example, if &lt;code&gt;G&lt;/code&gt; has order 20 and size 100 then the MSF of &lt;code&gt;G&lt;/code&gt; is augmented by adding those edges in &lt;code&gt;G&lt;/code&gt; with weights equal to or greater than the weight of the edge at the 80th percentile.&lt;/p&gt;
&lt;!-- This approach adds 143 edges to the MSF of `net`, rather than the predicted 100, because the 100th highest-weight edge in `net` shares a weight of 0.5 with 128 other edges. --&gt;
&lt;h3 id=&#34;visualising-the-network&#34;&gt;Visualising the network&lt;/h3&gt;
&lt;p&gt;The augmented MSF of &lt;code&gt;net&lt;/code&gt; contains 242 edges and is drawn below.
Each vertex is coloured according to the corresponding species&amp;rsquo; primary type and scaled according to that species&amp;rsquo; ubiquity.
I use &lt;a href=&#34;http://onlinelibrary.wiley.com/doi/10.1002/spe.4380211102/abstract&#34;&gt;Fruchterman and Reingold&amp;rsquo;s (1991)&lt;/a&gt; force-directed algorithm for determining vertices&amp;rsquo; layout.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/augmented-msf-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The cohabitation network has two components: one large component of 98 different species and many types, and one isolated pair of Ground-types.
The latter contains Diglett and Dugtrio, which habitate exclusively in Diglett&amp;rsquo;s Cave.
Water-types are most socially connected to other Water-types, suggesting that there are few amphibious species in the Kanto region that spend most of their time in the water.
Poison-types tend to be closely connected to Ground- and Rock-types, which are, presumably, immune to toxicity.&lt;/p&gt;
&lt;p&gt;The augmented MSF reveals two large, densely connected clusters of low ubiquity species.
These clusters represent Cerulean Cave and the Kanto Safari Zone, and are directly bridged by Chansey, Parasect and Rhyhorn.
There is also a small cluster of Fire- and Poison-types that cohabitate inside Pokémon Mansion, and a clique of four Bug-types found in Viridian Forest.&lt;/p&gt;
&lt;h2 id=&#34;estimating-species-social-influence&#34;&gt;Estimating species&amp;rsquo; social influence&lt;/h2&gt;
&lt;p&gt;The structure of &lt;code&gt;net&lt;/code&gt; reveals information about species&amp;rsquo; social influence.
A simple measure of such influence is the &lt;a href=&#34;https://en.wikipedia.org/wiki/Centrality#Degree_centrality&#34;&gt;degree centrality&lt;/a&gt; of each species, which counts the number of other cohabitating species.
The table below displays the species with the highest six degree centralities in the cohabitation network.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Species&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Type&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Degree&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Goldeen&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Water&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Magikarp&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Water&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Poliwag&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Water&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Krabby&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Water&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;69&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Kingler&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Water&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Ditto&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Normal&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;56&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The three most degree-central species are also the three most ubiquitous and cohabitate with 82 of the 99 other species in my sample.
Eight of the 10 most degree-central species are Water-types.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Centrality#Betweenness_centrality&#34;&gt;betweenness centrality&lt;/a&gt; of each species measures the frequency with which that species lies on the shortest path between others in the cohabitation network.
Intuitively, more betweenness-central species tend to have more control over the spread of information due to their relative criticality in other species&amp;rsquo; communication channels.&lt;/p&gt;
&lt;p&gt;The six most betweenness-central species are tabulated below.
Goldeen, Magikarp and Poliwag are important conduits of information due to their high ubiquity.
Cubone takes fifth place because it is the only species through which Gastly and Haunter&amp;mdash;both found exclusively inside Pokémon Tower&amp;mdash;can communicate with species in the Safari Zone.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Species&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Betweenness&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Goldeen&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;269.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Magikarp&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;269.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Poliwag&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;269.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Ditto&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;202.20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Cubone&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;190.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Krabby&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;169.77&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The chart below compares species&amp;rsquo; betweenness and degree centralities.
With the exception of Cubone, more betweenness-central species tend to have more cohabitants.
Water-types are relatively inefficient at accumulating betweenness centrality when they expand their social network, whereas Electric-types appear to gain a relatively large amount of betweenness centrality per extra cohabitant.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/betweenness-degree-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Species with densely connected social networks are unlikely to be very betweenness-central because their cohabitants can share information with each other directly.
The probability that two of a species&amp;rsquo; cohabitants also cohabitate is given by the &lt;a href=&#34;https://en.wikipedia.org/wiki/Clustering_coefficient#Local_clustering_coefficient&#34;&gt;transitivity&lt;/a&gt; of the corresponding vertex in &lt;code&gt;net&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The chart below plots species&amp;rsquo; betweenness centralities against their transitivity within the cohabitation network.
The two attributes share a strong, negative and convex relationship.
Species whose cohabitants also cohabitate are less betweenness-central because the former lack exclusive control of their cohabitants&amp;rsquo; channels for sharing information.
The exceptions to this trend are Cubone and Pikachu, which have unusually high and low betweenness centralities, respectively.
Pikachu habitate in two locations (Viridian Forest and the Kanto Power Plant), each of which contain a small number of species that frequently cohabitate and that generally have much higher degree centralities.
As a result, Pikachu have an unusually low betweenness centrality because their cohabitants are able to communicate with each other directly and with other species indirectly through their wider social networks.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;figures/betweenness-transitivity-1.svg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;the-co-containment-network&#34;&gt;The co-containment network&lt;/h2&gt;
&lt;p&gt;I recycle my method of analysing the cohabitation network among species in order to explore the co-containment network among locations.
In the latter network, two locations are adjacent if and only if they contain a common species.
I generate the co-containment network from a binary location-location adjacency matrix as follows.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;cocontains&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%*%&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;habits&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;cocontains&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;pmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cocontains&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Remove parallel edges&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;location_net&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;graph.adjacency&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cocontains&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mode&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#39;undirected&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The graph &lt;code&gt;location_net&lt;/code&gt; contains 542 (about 60%) of the 903 possible edges between its 43 vertices.&lt;/p&gt;
&lt;p&gt;The locations with the six highest mean ubiquities are tabulated below.
Viridian City and Pallet Town have the least unique demographies; the few species that habitate in these locations tend to also habitate in many other locations.
That Viridian City&amp;rsquo;s mean ubiquity and degree centrality are similar suggests that its four habitants usually cohabitate.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Location&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Mean Ubiquity&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Degree&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Diversity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Viridian City&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;21.25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Pallet Town&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18.40&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Celadon City&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16.40&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Cerulean City&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16.17&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Cinnabar Island&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16.00&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;25&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Route 1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16.00&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;24&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Finally, the table below shows the top six most betweenness-central locations.
Route 10 appears to be an important junction for information flow between species.
This is likely due to the diversity of its contained species, and that Routes 10 and 11 boast the highest degree centralities in the co-containment network.
The Safari Zone, another highly diverse location, is also an important information relay.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Location&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Betweenness&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Degree&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Diversity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Route 10&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;58.54&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;39&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Safari Zone&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;55.89&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;33&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;27&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Route 11&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;23.03&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;39&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Cerulean Cave&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;20.28&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;31&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Route 6&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18.38&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;38&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;Sea Route 21&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;18.38&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;38&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Restricting to random encounters excludes starter Pokémon, species obtainable only through evolution and &amp;ldquo;special&amp;rdquo; encounters (e.g., the Electrodes inside the Kanto Power Plant and the legendary birds) from the sample. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Observations in this and all other charts are coloured by the corresponding species&amp;rsquo; primary type, and are plotted with a small amount of noise in order to reveal coincident points that would otherwise be hidden. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This technique is based on &lt;a href=&#34;http://science.sciencemag.org/content/317/5837/482&#34;&gt;Hidalgo &lt;em&gt;et al.&lt;/em&gt;&amp;lsquo;s (2007)&lt;/a&gt; method of representing the product space of internationally traded goods. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;For example, consider applying a greedy algorithm such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Prim&#39;s_algorithm&#34;&gt;Prim&amp;rsquo;s&lt;/a&gt; to a cohabitation network that contains (i) a large clique of species that cohabitate in a single location and (ii) several species that are spread across many different locations. The algorithm will first connect each species in the clique and then, in order to avoid creating cycles, branch out to connect the relatively weakly connected species until a spanning forest is formed. The resulting subgraph will be a MSF but will contain edges that have lower weights than some of the omitted edges in the clique. &lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
  </channel>
</rss>
