<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>WHITE BELT</title>
<link>https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/</link>
<atom:link href="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/index.xml" rel="self" type="application/rss+xml"/>
<description>An exploration of data, curiosity, and discovery.</description>
<generator>quarto-1.10.18</generator>
<lastBuildDate>Sat, 10 Oct 2026 03:00:00 GMT</lastBuildDate>
<item>
  <title>Today’s Red Card Is Too Harsh on the Team, and Arbitrary</title>
  <dc:creator>Juan Franceschini</dc:creator>
  <link>https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/</link>
  <description><![CDATA[ 





<div class="cell">
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@700;800&family=Roboto:wght@400;500;700&display=swap');

/* StatsBomb-article look: white paper, charcoal type, red rules and accents */
body { background-image: none !important; background-color: #ffffff !important; }
body.quarto-dark #quarto-content { background: #ffffff; color-scheme: light; }
#quarto-content main { font-family: Roboto, system-ui, sans-serif; color: #1d1d1f; }
#quarto-content main p, #quarto-content main li { font-size: 1.04rem; line-height: 1.72; }
#title-block-header .title { font-family: "Roboto Condensed", sans-serif; font-weight: 800; letter-spacing: -.01em; text-transform: uppercase; font-size: clamp(2rem, 5vw, 3rem); line-height: 1.02; }
#title-block-header .subtitle { font-family: Roboto, sans-serif; font-weight: 400; color: #5f6368 !important; font-size: 1.15rem; }
#title-block-header::after { content: ""; display: block; width: 72px; height: 5px; background: #e10a1e; margin-top: 1.2rem; }
main h2 { font-family: "Roboto Condensed", sans-serif; font-weight: 800; letter-spacing: .005em; font-size: 1.4rem; line-height: 1.2;
  border-top: 3px solid #1d1d1f; padding-top: .7rem; margin-top: 2.6rem; }
main h2 .sb-tag { display: block; font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: #e10a1e; margin-bottom: .3rem; }
main h3 { font-family: "Roboto Condensed", sans-serif; font-weight: 700; font-size: 1.15rem; }
.sb-exec { border: 2px solid #1d1d1f; padding: 1.2rem 1.4rem 1rem; margin: 1.6rem 0 2.2rem; }
.sb-exec h4 { font-family: "Roboto Condensed", sans-serif; text-transform: uppercase; font-size: .85rem; letter-spacing: .1em; color: #e10a1e; margin: 0 0 .5rem; }
.sb-exec .sb-answer { font-family: "Roboto Condensed", sans-serif; font-weight: 800; font-size: 1.35rem; line-height: 1.25; margin: 0 0 .9rem; }
.sb-exec ol { margin: 0 0 .8rem; padding-left: 1.2rem; }
.sb-exec li { margin-bottom: .45rem; }
.sb-exec .sb-rec { border-top: 1px solid #ddd; padding-top: .7rem; margin: 0; }
.sb-scr { display: grid; gap: .8rem; margin: 1.2rem 0 1.8rem; }
.sb-scr div { border-left: 4px solid #d9d9d9; padding: .2rem 0 .2rem 1rem; }
.sb-scr div:nth-child(2) { border-left-color: #e10a1e; }
.sb-scr div:nth-child(3) { border-left-color: #1d1d1f; }
.sb-scr b { font-family: "Roboto Condensed", sans-serif; text-transform: uppercase; letter-spacing: .06em; font-size: .85rem; display: block; color: #5f6368; }
.sb-sowhat { background: #f6f6f6; border-left: 5px solid #e10a1e; padding: .8rem 1.1rem; margin: 1.2rem 0 2rem; }
.sb-sowhat b:first-child { font-family: "Roboto Condensed", sans-serif; text-transform: uppercase; letter-spacing: .06em; color: #e10a1e; margin-right: .4rem; }
.sb-compare { overflow-x: auto; margin: 1rem 0 .4rem; }
.sb-compare table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 620px; }
.sb-compare th { font-family: "Roboto Condensed", sans-serif; text-transform: uppercase; letter-spacing: .05em; font-size: .78rem; color: #5f6368; text-align: left; border-bottom: 2px solid #1d1d1f; padding: .5rem .6rem; }
.sb-compare td { border-bottom: 1px solid #e6e6e6; padding: .6rem; vertical-align: top; }
.sb-compare tr.sb-football td { background: #fdeceb; }
.sb-compare td:first-child { font-weight: 700; white-space: nowrap; }
.sb-hl { color: #1b3a6b; font-weight: 700; }
.sb-yes { color: #1a7f37; font-weight: 700; } .sb-no { color: #c21807; font-weight: 700; }
.sb-source { display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-size: .76rem; color: #5f6368; border-top: 1px solid #e3e3e3; padding-top: .45rem; margin: -.2rem 0 1.8rem; }
.sb-source img { height: 16px; width: auto; }
.girafe_container_std { margin-bottom: .4rem; }
@media (max-width: 700px) {
  .cell-output-display:has(.girafe_container_std) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .girafe_container_std, .girafe_container_std svg { min-width: 640px !important; width: 640px !important; max-width: none !important; }
  .sb-source { flex-wrap: wrap; }
}
details.code-fold > summary { font-family: Roboto, sans-serif; font-size: .8rem; color: #5f6368; }
</style>
</div>
<section id="executive-summary" class="level4 sb-exec">
<h4 class="anchored" data-anchor-id="executive-summary">Executive summary</h4>
<p class="sb-answer">
Today’s red card is too harsh on the offending team. It strips the team of half its attack, keeps doing so until the final whistle, and charges a price set by the clock rather than the foul.
</p>
<ol type="1">
<li><strong>It halves the team’s attack and hands the match to the opponent.</strong> In the 20 minutes after a red card, the ten-man side creates <span class="sb-hl">about half the chances</span> of matched 11-v-11 games, and its share of the match’s chances falls <span class="sb-hl">from 44% to 27%</span>.</li>
<li><strong>The punishment never ends.</strong> After 40 minutes a ten-man side is as outgunned as after ten, while the opponent’s advantage keeps growing.</li>
<li><strong>The price is set by the clock, not the foul.</strong> A red card costs the team <span class="sb-hl">0.34 points per game</span> on average: <span class="sb-hl">0.91 points before half-time</span>, 0.06 after the 75th minute.</li>
</ol>
<p class="sb-rec">
<strong>Where we go from here:</strong> keep the sending-off and the ban for the player, and replace the team’s open-ended penalty with a <strong>20-minute power play</strong>. The team is still punished, at about <span class="sb-hl">0.21 points</span>, but the punishment is <span class="sb-hl">limited, not perpetual</span>.
</p>
</section>
<section id="the-thesis-a-red-card-punishes-the-team-far-more-than-the-offence-deserves" class="level2">
<h2 class="anchored" data-anchor-id="the-thesis-a-red-card-punishes-the-team-far-more-than-the-offence-deserves">The thesis: a red card punishes the team far more than the offence deserves</h2>
<p>A red card is meant to punish a player for a serious offence. In practice the heavier punishment falls on his team: ten players who did nothing wrong play the rest of the match a man short, however long that is. The evidence below, drawn from 292 red cards in 1,140 matches across the 2015/16 Premier League, La Liga and Serie A, shows how large, how lasting and how arbitrary that team penalty is.</p>
</section>
<section id="evidence-1" class="level2">
<h2 class="anchored" data-anchor-id="evidence-1">A red card halves the team’s attack and hands the match to the opponent</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the code: chart 1, chances around the red card</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">bins <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb1-2">tilt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(r) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(bins, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(b) {</span>
<span id="cb1-3">  e <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(sets, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(b, b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb1-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start =</span> b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mid =</span> b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treated =</span> e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>treated_after, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>control_after)</span>
<span id="cb1-5">}))))</span>
<span id="cb1-6">tilt[, role_lab <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The team down to ten"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Their opponent"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The team down to ten"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Their opponent"</span>))]</span>
<span id="cb1-7">tilt_long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">melt</span>(tilt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id.vars =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"role_lab"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mid"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variable.name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value.name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rate"</span>)</span>
<span id="cb1-8">tilt_long[, colour <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fifelse</span>(group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"control"</span>, GREY, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fifelse</span>(role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, RED, BLUE))]</span>
<span id="cb1-9">tilt_long[, tip <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;b&gt;%s&lt;/b&gt;&lt;br&gt;%d to %d min from the red&lt;br&gt;%s: %s npxG per 20'"</span>, role_lab, start, start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb1-10">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"control"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Matched 11-v-11 games"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red-card games"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(rate))]</span>
<span id="cb1-11">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(tilt_long, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(mid, rate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rect"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#fbeeec"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> RED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> colour, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> group), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> colour, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> tip, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(role, group, start)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> tilt_long[start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"control"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Twins"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"With a red"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> colour),</span>
<span id="cb1-17">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nudge_x =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red card"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> RED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> role_lab) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linetype_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treated =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"22"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span>, x), x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mult =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The red card flips who is attacking"</span>,</span>
<span id="cb1-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-penalty expected goals (npxG) per 20 minutes around the first red card (%d cases) vs matched 11-v-11 twins"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(sets)),</span>
<span id="cb1-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minutes from the red card"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxG per 20 minutes"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_sb</span>()</span>
<span id="cb1-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sb_chart</span>(p1, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.8</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item" id="htmlwidget-d636ff5c05640200d421" style="width:100%;height:338px;"></div>
<script type="application/json" data-for="htmlwidget-d636ff5c05640200d421">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='graphics-document' id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b' viewBox='0 0 648 345.6'>\n <defs id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_defs'>\n  <clipPath id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_c1'>\n   <rect x='0' y='0' width='648' height='345.6'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_6051e53d_37f1_438e_998a_dbac981dbe7b_c1)'>\n   <rect x='0' y='0' width='648' height='345.6' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n   <rect x='0' y='0' width='648' height='345.6' fill='#FFFFFF' fill-opacity='1' stroke='none'/>\n   <polyline points='37.08,312.85 336.56,312.85' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='37.08,267.15 336.56,267.15' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='37.08,221.46 336.56,221.46' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='37.08,175.76 336.56,175.76' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='37.08,130.07 336.56,130.07' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='37.08,84.37 336.56,84.37' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <rect x='158.84' y='68.61' width='131.64' height='244.24' fill='#FBEEEC' fill-opacity='1' stroke='none'/>\n   <line x1='158.84' y1='312.85' x2='158.84' y2='68.61' stroke='#D7301F' stroke-opacity='1' stroke-width='1.28' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='43.66,224.67 76.57,241.17 109.48,240.04 142.39,225.32 175.30,282.91 208.21,252.95 241.12,233.84 274.03,221.98' fill='none' stroke='#D7301F' stroke-opacity='1' stroke-width='2.35' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='43.66,238.59 76.57,241.22 109.48,246.25 142.39,238.16 175.30,196.63 208.21,189.10 241.12,203.82 274.03,199.21' fill='none' stroke='#8A8F98' stroke-opacity='1' stroke-width='2.35' stroke-dasharray='6,6' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e1' cx='43.66' cy='224.67' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-20 to -15 min from the red&amp;lt;br&amp;gt;Red-card games: 0.19 npxG per 20&amp;#39;' data-id='focal treated -20'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e2' cx='76.57' cy='241.17' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-15 to -10 min from the red&amp;lt;br&amp;gt;Red-card games: 0.16 npxG per 20&amp;#39;' data-id='focal treated -15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e3' cx='109.48' cy='240.04' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-10 to -5 min from the red&amp;lt;br&amp;gt;Red-card games: 0.16 npxG per 20&amp;#39;' data-id='focal treated -10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e4' cx='142.39' cy='225.32' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-5 to 0 min from the red&amp;lt;br&amp;gt;Red-card games: 0.19 npxG per 20&amp;#39;' data-id='focal treated -5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e5' cx='175.3' cy='282.91' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;0 to 5 min from the red&amp;lt;br&amp;gt;Red-card games: 0.07 npxG per 20&amp;#39;' data-id='focal treated 0'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e6' cx='208.21' cy='252.95' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;5 to 10 min from the red&amp;lt;br&amp;gt;Red-card games: 0.13 npxG per 20&amp;#39;' data-id='focal treated 5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e7' cx='241.12' cy='233.84' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;10 to 15 min from the red&amp;lt;br&amp;gt;Red-card games: 0.17 npxG per 20&amp;#39;' data-id='focal treated 10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e8' cx='274.03' cy='221.98' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;15 to 20 min from the red&amp;lt;br&amp;gt;Red-card games: 0.20 npxG per 20&amp;#39;' data-id='focal treated 15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e9' cx='43.66' cy='238.59' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-20 to -15 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.16 npxG per 20&amp;#39;' data-id='focal control -20'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e10' cx='76.57' cy='241.22' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-15 to -10 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.16 npxG per 20&amp;#39;' data-id='focal control -15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e11' cx='109.48' cy='246.25' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-10 to -5 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.15 npxG per 20&amp;#39;' data-id='focal control -10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e12' cx='142.39' cy='238.16' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-5 to 0 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.16 npxG per 20&amp;#39;' data-id='focal control -5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e13' cx='175.3' cy='196.63' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;0 to 5 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.25 npxG per 20&amp;#39;' data-id='focal control 0'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e14' cx='208.21' cy='189.1' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;5 to 10 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.27 npxG per 20&amp;#39;' data-id='focal control 5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e15' cx='241.12' cy='203.82' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;10 to 15 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.24 npxG per 20&amp;#39;' data-id='focal control 10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e16' cx='274.03' cy='199.21' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;The team down to ten&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;15 to 20 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.25 npxG per 20&amp;#39;' data-id='focal control 15'/>\n   <text x='279.95' y='225.46' font-size='7.26pt' font-weight='bold' font-family='Helvetica' fill='#D7301F' fill-opacity='1'>With a red<\/text>\n   <text x='279.95' y='202.69' font-size='7.26pt' font-weight='bold' font-family='Helvetica' fill='#8A8F98' fill-opacity='1'>Twins<\/text>\n   <text x='162.79' y='79.41' font-size='7.04pt' font-weight='bold' font-family='Helvetica' fill='#D7301F' fill-opacity='1'>Red card<\/text>\n   <polyline points='342.54,312.85 642.02,312.85' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='342.54,267.15 642.02,267.15' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='342.54,221.46 642.02,221.46' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='342.54,175.76 642.02,175.76' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='342.54,130.07 642.02,130.07' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='342.54,84.37 642.02,84.37' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <rect x='464.31' y='68.61' width='131.64' height='244.24' fill='#FBEEEC' fill-opacity='1' stroke='none'/>\n   <line x1='464.31' y1='312.85' x2='464.31' y2='68.61' stroke='#D7301F' stroke-opacity='1' stroke-width='1.28' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='349.12,226.80 382.03,230.78 414.94,184.93 447.85,195.79 480.76,189.30 513.67,153.99 546.58,94.78 579.49,127.11' fill='none' stroke='#2B6CB0' stroke-opacity='1' stroke-width='2.35' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='349.12,226.07 382.03,212.59 414.94,220.21 447.85,216.67 480.76,212.21 513.67,200.73 546.58,199.10 579.49,167.30' fill='none' stroke='#8A8F98' stroke-opacity='1' stroke-width='2.35' stroke-dasharray='6,6' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e17' cx='349.12' cy='226.8' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-20 to -15 min from the red&amp;lt;br&amp;gt;Red-card games: 0.19 npxG per 20&amp;#39;' data-id='opponent treated -20'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e18' cx='382.03' cy='230.78' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-15 to -10 min from the red&amp;lt;br&amp;gt;Red-card games: 0.18 npxG per 20&amp;#39;' data-id='opponent treated -15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e19' cx='414.94' cy='184.93' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-10 to -5 min from the red&amp;lt;br&amp;gt;Red-card games: 0.28 npxG per 20&amp;#39;' data-id='opponent treated -10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e20' cx='447.85' cy='195.79' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-5 to 0 min from the red&amp;lt;br&amp;gt;Red-card games: 0.26 npxG per 20&amp;#39;' data-id='opponent treated -5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e21' cx='480.76' cy='189.3' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;0 to 5 min from the red&amp;lt;br&amp;gt;Red-card games: 0.27 npxG per 20&amp;#39;' data-id='opponent treated 0'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e22' cx='513.67' cy='153.99' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;5 to 10 min from the red&amp;lt;br&amp;gt;Red-card games: 0.35 npxG per 20&amp;#39;' data-id='opponent treated 5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e23' cx='546.58' cy='94.78' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;10 to 15 min from the red&amp;lt;br&amp;gt;Red-card games: 0.48 npxG per 20&amp;#39;' data-id='opponent treated 10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e24' cx='579.49' cy='127.11' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;15 to 20 min from the red&amp;lt;br&amp;gt;Red-card games: 0.41 npxG per 20&amp;#39;' data-id='opponent treated 15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e25' cx='349.12' cy='226.07' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-20 to -15 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.19 npxG per 20&amp;#39;' data-id='opponent control -20'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e26' cx='382.03' cy='212.59' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-15 to -10 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.22 npxG per 20&amp;#39;' data-id='opponent control -15'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e27' cx='414.94' cy='220.21' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-10 to -5 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.20 npxG per 20&amp;#39;' data-id='opponent control -10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e28' cx='447.85' cy='216.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;-5 to 0 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.21 npxG per 20&amp;#39;' data-id='opponent control -5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e29' cx='480.76' cy='212.21' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;0 to 5 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.22 npxG per 20&amp;#39;' data-id='opponent control 0'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e30' cx='513.67' cy='200.73' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;5 to 10 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.25 npxG per 20&amp;#39;' data-id='opponent control 5'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e31' cx='546.58' cy='199.1' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;10 to 15 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.25 npxG per 20&amp;#39;' data-id='opponent control 10'/>\n   <circle id='svg_6051e53d_37f1_438e_998a_dbac981dbe7b_e32' cx='579.49' cy='167.3' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Their opponent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;15 to 20 min from the red&amp;lt;br&amp;gt;Matched 11-v-11 games: 0.32 npxG per 20&amp;#39;' data-id='opponent control 15'/>\n   <text x='585.42' y='130.59' font-size='7.26pt' font-weight='bold' font-family='Helvetica' fill='#2B6CB0' fill-opacity='1'>With a red<\/text>\n   <text x='585.42' y='170.78' font-size='7.26pt' font-weight='bold' font-family='Helvetica' fill='#8A8F98' fill-opacity='1'>Twins<\/text>\n   <text x='468.26' y='79.41' font-size='7.04pt' font-weight='bold' font-family='Helvetica' fill='#D7301F' fill-opacity='1'>Red card<\/text>\n   <text x='41.86' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>The team down to ten<\/text>\n   <text x='347.32' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Their opponent<\/text>\n   <text x='86.09' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>-10<\/text>\n   <text x='156.18' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0<\/text>\n   <text x='216.53' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+10<\/text>\n   <text x='282.35' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+20<\/text>\n   <text x='391.55' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>-10<\/text>\n   <text x='461.64' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0<\/text>\n   <text x='521.99' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+10<\/text>\n   <text x='587.81' y='325.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+20<\/text>\n   <text x='18.36' y='316.29' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.0<\/text>\n   <text x='18.36' y='270.6' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.1<\/text>\n   <text x='18.36' y='224.9' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.2<\/text>\n   <text x='18.36' y='179.2' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.3<\/text>\n   <text x='18.36' y='133.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.4<\/text>\n   <text x='18.36' y='87.81' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.5<\/text>\n   <text x='282.59' y='337.4' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Minutes from the red card<\/text>\n   <text transform='translate(13.16,237.13) rotate(-90.00)' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>npxG per 20 minutes<\/text>\n   <text x='5.98' y='33.26' font-size='8.62pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Non-penalty expected goals (npxG) per 20 minutes around the first red card (99 cases) vs matched 11-v-11 twins<\/text>\n   <text x='5.98' y='17.49' font-size='12pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>The red card flips who is attacking<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_6051e53d_37f1_438e_998a_dbac981dbe7b","ratio":1.875,"settings":{"tooltip":{"css":".tooltip_SVGID_ { background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.96,"offx":10,"offy":0,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { stroke-width:3; }","reactive":false,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"fixed":false,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
<div class="sb-source">
<span>Data: StatsBomb Open Data · 2015/16 Premier League, La Liga and Serie A</span>
<img src="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/statsbomb-logo.png" alt="StatsBomb">
</div>
</div>
</div>
<p>Before the card, the team that will be reduced to ten creates chances exactly like its matched 11-v-11 twins. In the 20 minutes after it, its non-penalty expected goals fall by <span class="sb-hl">0.13 per 20 minutes</span> [−0.17, −0.09], <span class="sb-hl">about half</span> of what it would otherwise create, and the opponent’s rise by 0.10 [+0.05, +0.14]. The ten-man side’s share of the match’s chances drops <span class="sb-hl">from 44% to 27%</span>.</p>
<div class="sb-sowhat">
<p><strong>So what</strong> One player’s offence turns an even contest into one-way traffic. Ten teammates carry the cost, and the opponent collects a reward it did nothing to earn.</p>
</div>
</section>
<section id="evidence-2" class="level2">
<h2 class="anchored" data-anchor-id="evidence-2">The punishment never ends: after 40 minutes the gap is as wide as after ten</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the code: chart 2, the 40-minute cohort</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">per <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(r) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(w) {</span>
<span id="cb2-2">  e <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(long, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> w); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">window =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d to %d minutes after"</span>, w[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], w[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]), e)</span>
<span id="cb2-3">}))))</span>
<span id="cb2-4">per[, role_lab <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">focal =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Team down to ten"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opponent =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Opponent"</span>)[role], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Team down to ten"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Opponent"</span>))]</span>
<span id="cb2-5">per[, colour <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">focal =</span> RED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opponent =</span> BLUE)[role]]</span>
<span id="cb2-6">per[, tip <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;b&gt;%s&lt;/b&gt;, %s the red&lt;br&gt;%s npxG per 20' vs twins&lt;br&gt;95%% interval %s&lt;br&gt;%d red cards"</span>, role_lab, window, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">signed</span>(estimate), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ci</span>(lo, hi), n)]</span>
<span id="cb2-7">p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(per, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(estimate, window, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> colour)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#bdbdbd"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_linerange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> hi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> tip, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(role, window)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">signed</span>(estimate)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> role_lab) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> rev) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> signed) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No recovery: the second 20 minutes are as lopsided as the first"</span>,</span>
<span id="cb2-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change in npxG per 20 minutes vs matched 11-v-11 twins, games that stayed 11-v-10 for 40+ minutes (%d cases)"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(long)),</span>
<span id="cb2-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxG per 20 minutes vs twins (with 95% interval)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_sb</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#eeeeee"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK))</span>
<span id="cb2-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sb_chart</span>(p2, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item" id="htmlwidget-a815a1238fd8f673e962" style="width:100%;height:338px;"></div>
<script type="application/json" data-for="htmlwidget-a815a1238fd8f673e962">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='graphics-document' id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513' viewBox='0 0 648 216'>\n <defs id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_defs'>\n  <clipPath id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c1'>\n   <rect x='0' y='0' width='648' height='216'/>\n  <\/clipPath>\n  <clipPath id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c2'>\n   <rect x='104.14' y='68.61' width='265.95' height='114.64'/>\n  <\/clipPath>\n  <clipPath id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c3'>\n   <rect x='376.07' y='68.61' width='265.95' height='114.64'/>\n  <\/clipPath>\n  <clipPath id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c4'>\n   <rect x='104.14' y='47.76' width='265.95' height='20.85'/>\n  <\/clipPath>\n  <clipPath id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c5'>\n   <rect x='376.07' y='47.76' width='265.95' height='20.85'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c1)'>\n   <rect x='0' y='0' width='648' height='216' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n   <rect x='0' y='-0' width='648' height='216' fill='#FFFFFF' fill-opacity='1' stroke='none'/>\n  <\/g>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c2)'>\n   <polyline points='122.08,183.25 122.08,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='177.35,183.25 177.35,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='232.62,183.25 232.62,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='287.89,183.25 287.89,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='343.16,183.25 343.16,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='232.62' y1='183.25' x2='232.62' y2='68.61' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='122.52' y1='99.88' x2='189.9' y2='99.88' stroke='#D7301F' stroke-opacity='1' stroke-width='2.77' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='116.23' y1='151.99' x2='174.05' y2='151.99' stroke='#D7301F' stroke-opacity='1' stroke-width='2.77' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_e1' cx='156.21' cy='99.88' r='3.31pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Team down to ten&amp;lt;/b&amp;gt;, 0 to 20 minutes after the red&amp;lt;br&amp;gt;−0.14 npxG per 20&amp;#39; vs twins&amp;lt;br&amp;gt;95% interval [−0.20, −0.08]&amp;lt;br&amp;gt;44 red cards' data-id='focal 0 to 20 minutes after'/>\n   <circle id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_e2' cx='145.14' cy='151.99' r='3.31pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Team down to ten&amp;lt;/b&amp;gt;, 20 to 40 minutes after the red&amp;lt;br&amp;gt;−0.16 npxG per 20&amp;#39; vs twins&amp;lt;br&amp;gt;95% interval [−0.21, −0.11]&amp;lt;br&amp;gt;44 red cards' data-id='focal 20 to 40 minutes after'/>\n   <text x='143.62' y='92' font-size='7.47pt' font-weight='bold' font-family='Helvetica' fill='#D7301F' fill-opacity='1'>−0.14<\/text>\n   <text x='132.55' y='144.11' font-size='7.47pt' font-weight='bold' font-family='Helvetica' fill='#D7301F' fill-opacity='1'>−0.16<\/text>\n  <\/g>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c3)'>\n   <polyline points='394.01,183.25 394.01,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='449.28,183.25 449.28,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='504.55,183.25 504.55,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='559.82,183.25 559.82,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='615.09,183.25 615.09,68.61' fill='none' stroke='#EEEEEE' stroke-opacity='1' stroke-width='1.16' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='504.55' y1='183.25' x2='504.55' y2='68.61' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='506.98' y1='99.88' x2='579.17' y2='99.88' stroke='#2B6CB0' stroke-opacity='1' stroke-width='2.77' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='538.99' y1='151.99' x2='629.93' y2='151.99' stroke='#2B6CB0' stroke-opacity='1' stroke-width='2.77' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_e3' cx='543.08' cy='99.88' r='3.31pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Opponent&amp;lt;/b&amp;gt;, 0 to 20 minutes after the red&amp;lt;br&amp;gt;+0.07 npxG per 20&amp;#39; vs twins&amp;lt;br&amp;gt;95% interval [0.00, +0.14]&amp;lt;br&amp;gt;44 red cards' data-id='opponent 0 to 20 minutes after'/>\n   <circle id='svg_f569bffc_b56e_4d89_9444_00b8d4af8513_e4' cx='584.46' cy='151.99' r='3.31pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Opponent&amp;lt;/b&amp;gt;, 20 to 40 minutes after the red&amp;lt;br&amp;gt;+0.14 npxG per 20&amp;#39; vs twins&amp;lt;br&amp;gt;95% interval [+0.06, +0.23]&amp;lt;br&amp;gt;44 red cards' data-id='opponent 20 to 40 minutes after'/>\n   <text x='530.48' y='92' font-size='7.47pt' font-weight='bold' font-family='Helvetica' fill='#2B6CB0' fill-opacity='1'>+0.07<\/text>\n   <text x='571.87' y='144.11' font-size='7.47pt' font-weight='bold' font-family='Helvetica' fill='#2B6CB0' fill-opacity='1'>+0.14<\/text>\n  <\/g>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c4)'>\n   <text x='108.92' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Team down to ten<\/text>\n  <\/g>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c5)'>\n   <text x='380.85' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Opponent<\/text>\n  <\/g>\n  <g clip-path='url(#svg_f569bffc_b56e_4d89_9444_00b8d4af8513_c1)'>\n   <text x='109.94' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.20<\/text>\n   <text x='165.21' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.10<\/text>\n   <text x='223.28' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='275.75' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.10<\/text>\n   <text x='331.02' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.20<\/text>\n   <text x='381.88' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.20<\/text>\n   <text x='437.15' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.10<\/text>\n   <text x='495.22' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='547.68' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.10<\/text>\n   <text x='602.95' y='195.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.20<\/text>\n   <text x='5.98' y='155.43' font-size='7.2pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>20 to 40 minutes after<\/text>\n   <text x='11.31' y='103.32' font-size='7.2pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>0 to 20 minutes after<\/text>\n   <text x='265' y='207.8' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>npxG per 20 minutes vs twins (with 95% interval)<\/text>\n   <text x='5.98' y='33.26' font-size='8.62pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Change in npxG per 20 minutes vs matched 11-v-11 twins, games that stayed 11-v-10 for 40+ minutes (44 cases)<\/text>\n   <text x='5.98' y='17.49' font-size='12pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>No recovery: the second 20 minutes are as lopsided as the first<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_f569bffc_b56e_4d89_9444_00b8d4af8513","ratio":3,"settings":{"tooltip":{"css":".tooltip_SVGID_ { background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.96,"offx":10,"offy":0,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { stroke-width:3; }","reactive":false,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"fixed":false,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
<div class="sb-source">
<span>Data: StatsBomb Open Data · 2015/16 Premier League, La Liga and Serie A</span>
<img src="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/statsbomb-logo.png" alt="StatsBomb">
</div>
</div>
<details class="code-fold">
<summary>Show the code: chart 2, the 40-minute cohort</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">own_20 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> per[role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> window <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 20 minutes after"</span>, estimate]; own_40 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> per[role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> window <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 40 minutes after"</span>, estimate]</span>
<span id="cb3-2">opp_20 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> per[role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> window <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 20 minutes after"</span>, estimate]; opp_40 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> per[role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> window <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 40 minutes after"</span>, estimate]</span></code></pre></div></div>
</details>
</div>
<p>Teams don’t adapt to playing with ten. In the 44 games that stayed 11-v-10 for at least 40 minutes, the ten-man side was <span class="sb-hl">0.14 npxG per 20 minutes behind</span> its twins in the first 20 minutes and <span class="sb-hl">0.16 behind in the next 20</span>. The opponent’s advantage grew, from +0.07 to +0.14.</p>
<div class="sb-sowhat">
<p><strong>So what</strong> The team penalty has no end point. Every extra minute at ten is another minute of the same handicap, and the opponent’s reward accumulates until the final whistle.</p>
</div>
</section>
<section id="evidence-3" class="level2">
<h2 class="anchored" data-anchor-id="evidence-3">The price of a red card is set by the clock, not by the foul</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the code: chart 3, points lost by minute of the red card</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">by_time[, tip <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;b&gt;Red card at %s&lt;/b&gt;&lt;br&gt;Ten-man side: %s points per game&lt;br&gt;Matched twins: %s&lt;br&gt;Cost: %s points, 95%% interval [%s, %s]&lt;br&gt;%d red cards"</span>,</span>
<span id="cb4-2">                         bucket, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(ten), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(twins), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(cost), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(lo), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(hi), n)]</span>
<span id="cb4-3">p3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(by_time, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(bucket, cost)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#bdbdbd"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> tip, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> bucket), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> RED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">62</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> hi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> hi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">num</span>(cost)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mult =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">02</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The same red card is %d times more expensive early than late"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(ratio)),</span>
<span id="cb4-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Points lost per game by the ten-man side vs matched 11-v-11 games, by minute of the red card (%d red cards, 95%% intervals)"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(per_card)),</span>
<span id="cb4-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minute of the red card"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Points lost per game"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_sb</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>))</span>
<span id="cb4-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sb_chart</span>(p3, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.9</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item" id="htmlwidget-3521ed115f940c7d3056" style="width:100%;height:338px;"></div>
<script type="application/json" data-for="htmlwidget-3521ed115f940c7d3056">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='graphics-document' id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70' viewBox='0 0 648 280.8'>\n <defs id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_defs'>\n  <clipPath id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_c1'>\n   <rect x='0' y='0' width='648' height='280.8'/>\n  <\/clipPath>\n  <clipPath id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_c2'>\n   <rect x='42.41' y='47.76' width='599.61' height='198.95'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_c1)'>\n   <rect x='0' y='0' width='648' height='280.8' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n   <rect x='0' y='-0' width='648' height='280.8' fill='#FFFFFF' fill-opacity='1' stroke='none'/>\n  <\/g>\n  <g clip-path='url(#svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_c2)'>\n   <polyline points='42.41,241.13 642.02,241.13' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='42.41,204.11 642.02,204.11' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='42.41,167.10 642.02,167.10' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='42.41,130.08 642.02,130.08' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='42.41,93.07 642.02,93.07' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='42.41,56.05 642.02,56.05' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='42.41' y1='241.13' x2='642.02' y2='241.13' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <rect id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_e1' x='83.81' y='106.67' width='88.51' height='134.46' fill='#D7301F' fill-opacity='1' stroke='none' title='&amp;lt;b&amp;gt;Red card at 20–45 min&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Ten-man side: 0.30 points per game&amp;lt;br&amp;gt;Matched twins: 1.21&amp;lt;br&amp;gt;Cost: 0.91 points, 95% interval [0.67, 1.14]&amp;lt;br&amp;gt;37 red cards' data-id='20–45 min'/>\n   <rect id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_e2' x='226.58' y='156.97' width='88.51' height='84.16' fill='#D7301F' fill-opacity='1' stroke='none' title='&amp;lt;b&amp;gt;Red card at 45–60 min&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Ten-man side: 0.74 points per game&amp;lt;br&amp;gt;Matched twins: 1.31&amp;lt;br&amp;gt;Cost: 0.57 points, 95% interval [0.34, 0.80]&amp;lt;br&amp;gt;38 red cards' data-id='45–60 min'/>\n   <rect id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_e3' x='369.34' y='204.56' width='88.51' height='36.57' fill='#D7301F' fill-opacity='1' stroke='none' title='&amp;lt;b&amp;gt;Red card at 60–75 min&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Ten-man side: 1.20 points per game&amp;lt;br&amp;gt;Matched twins: 1.45&amp;lt;br&amp;gt;Cost: 0.25 points, 95% interval [0.03, 0.47]&amp;lt;br&amp;gt;44 red cards' data-id='60–75 min'/>\n   <rect id='svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_e4' x='512.11' y='231.9' width='88.51' height='9.23' fill='#D7301F' fill-opacity='1' stroke='none' title='&amp;lt;b&amp;gt;Red card at 75+ min&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Ten-man side: 0.99 points per game&amp;lt;br&amp;gt;Matched twins: 1.05&amp;lt;br&amp;gt;Cost: 0.06 points, 95% interval [-0.01, 0.14]&amp;lt;br&amp;gt;93 red cards' data-id='75+ min'/>\n   <polyline points='119.50,71.77 136.64,71.77' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='128.07,71.77 128.07,141.57' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='119.50,141.57 136.64,141.57' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='262.27,123.31 279.40,123.31' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='270.83,123.31 270.83,190.62' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='262.27,190.62 279.40,190.62' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='405.03,171.83 422.17,171.83' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='413.60,171.83 413.60,237.29' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='405.03,237.29 422.17,237.29' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='547.80,220.52 564.93,220.52' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='556.36,220.52 556.36,243.27' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='547.80,243.27 564.93,243.27' fill='none' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <text x='117' y='66.04' font-size='8.54pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>0.91<\/text>\n   <text x='259.76' y='117.58' font-size='8.54pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>0.57<\/text>\n   <text x='402.53' y='166.1' font-size='8.54pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>0.25<\/text>\n   <text x='545.29' y='214.79' font-size='8.54pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>0.06<\/text>\n  <\/g>\n  <g clip-path='url(#svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70_c1)'>\n   <text x='18.36' y='244.57' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='18.36' y='207.56' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.25<\/text>\n   <text x='18.36' y='170.54' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.50<\/text>\n   <text x='18.36' y='133.52' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.75<\/text>\n   <text x='18.36' y='96.51' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>1.00<\/text>\n   <text x='18.36' y='59.49' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>1.25<\/text>\n   <text x='101.46' y='260' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>20–45 min<\/text>\n   <text x='244.22' y='260' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>45–60 min<\/text>\n   <text x='386.99' y='260' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>60–75 min<\/text>\n   <text x='535.72' y='260' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>75+ min<\/text>\n   <text x='293.59' y='272.6' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Minute of the red card<\/text>\n   <text transform='translate(13.16,192.80) rotate(-90.00)' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Points lost per game<\/text>\n   <text x='5.98' y='33.26' font-size='8.62pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Points lost per game by the ten-man side vs matched 11-v-11 games, by minute of the red card (212 red cards, 95% intervals)<\/text>\n   <text x='5.98' y='17.49' font-size='12pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>The same red card is 15 times more expensive early than late<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_3ab0eb6b_63c0_4c95_835f_a310204e9e70","ratio":2.307692307692308,"settings":{"tooltip":{"css":".tooltip_SVGID_ { background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.96,"offx":10,"offy":0,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { stroke-width:3; }","reactive":false,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"fixed":false,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
<div class="sb-source">
<span>Data: StatsBomb Open Data · 2015/16 Premier League, La Liga and Serie A</span>
<img src="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/statsbomb-logo.png" alt="StatsBomb">
</div>
</div>
</div>
<p>A team reduced to ten before half-time took 0.30 points per game, against 1.21 for matched games that stayed 11-v-11: a cost of <span class="sb-hl">0.91 points</span>. The same card after the 75th minute cost <span class="sb-hl">0.06</span>. Every ten minutes left on the clock adds 0.16 points to the bill.</p>
<div class="sb-sowhat">
<p><strong>So what</strong> The identical tackle in the 30th and the 80th minute carries a <span class="sb-hl">15-fold difference</span> in punishment. A sanction priced by the clock is arbitrary, and the arbitrariness lands on the team.</p>
</div>
</section>
<section id="method" class="level2">
<h2 class="anchored" data-anchor-id="method">How the evidence was built</h2>
<ul>
<li><strong>Data.</strong> StatsBomb event data for every match of the 2015/16 Premier League, La Liga and Serie A: 1,140 matches, 292 on-field red cards and every shot with its expected-goals value, plus pre-match bookmaker odds from Football-Data.co.uk.</li>
<li><strong>Match states.</strong> From the raw events I rebuilt the score, the players on the pitch and each team’s chances, second by second, for every match.</li>
<li><strong>Matched twins.</strong> Each red card is compared with up to five games from the same league that were still 11-v-11 at the same minute of the same half, with the same score difference, the same team at home or away, the same pre-match favourite (win probability within 0.15) and the most similar attacking output by both teams over the previous 20 minutes.</li>
<li><strong>Effect.</strong> The effect of a red card is the change in the ten-man game minus the change in its twins over the same window, estimated by weighted least squares with standard errors clustered by match.</li>
<li><strong>Cohorts.</strong> Chance creation: 99 first red cards with 20 clean minutes before and after. Persistence: the 44 of those that stayed 11-v-10 for 40 minutes. Points: all 212 first red cards from the 20th minute on, measured to the final whistle.</li>
</ul>
<p>The results point the same way in every league, for straight reds and second yellows, with penalty and goalkeeper reds included, and under every alternative specification tested (appendix).</p>
</section>
<section id="proposal" class="level2">
<h2 class="anchored" data-anchor-id="proposal">Where do we go from here? A 20-minute power play</h2>
<p>The fix is to separate the two punishments. <strong>The player</strong> is sent off for the rest of the match and banned as he is today. <strong>The team</strong> serves a fixed 20-minute power play, a man short, then returns to eleven with a substitute.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code: chart 4, the rule today vs the proposal</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">seg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(</span>
<span id="cb5-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rule =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Today"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proposed: 20-minute power play"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proposed: 20-minute power play"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Today"</span>)),</span>
<span id="cb5-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>),</span>
<span id="cb5-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">state =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 11"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 11"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 11 again"</span>))</span>
<span id="cb5-5">seg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(seg)</span>
<span id="cb5-6">seg[, fill <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 11"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#e6e6e6"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 10"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> RED, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 11 again"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#bfbfbf"</span>)[state]]</span>
<span id="cb5-7">seg[, tip <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;b&gt;%s&lt;/b&gt;&lt;br&gt;Minutes %d to %d: %s"</span>, rule, from, to, state)]</span>
<span id="cb5-8">p4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(seg) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rect_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> from, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> to, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(rule) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(rule) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> fill, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> tip, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(rule, from)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> (from <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> to) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(rule), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> state, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(state <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11 v 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, INK)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"22"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.62</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red card in the 30th minute"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nudge_x =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">72.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">52</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Back to 11 · the offender stays off and is banned"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> MUTED) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(seg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rule), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.75</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(x, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"'"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A real punishment for the team, with an end point"</span>,</span>
<span id="cb5-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"How a 30th-minute red card plays out under today's rule and under a 20-minute power play"</span>,</span>
<span id="cb5-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Match minute"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_sb</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>))</span>
<span id="cb5-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sb_chart</span>(p4, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">note =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Illustration of the proposed rule"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item" id="htmlwidget-0a3296c13581a365cdd1" style="width:100%;height:338px;"></div>
<script type="application/json" data-for="htmlwidget-0a3296c13581a365cdd1">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='graphics-document' id='svg_70fe26b9_464c_4739_98cc_b01503dd482c' viewBox='0 0 648 201.6'>\n <defs id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_defs'>\n  <clipPath id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_c1'>\n   <rect x='0' y='0' width='648' height='201.6'/>\n  <\/clipPath>\n  <clipPath id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_c2'>\n   <rect x='181.32' y='47.76' width='460.7' height='121.09'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_70fe26b9_464c_4739_98cc_b01503dd482c_c1)'>\n   <rect x='0' y='0' width='648' height='201.6' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n   <rect x='0' y='0' width='648' height='201.6' fill='#FFFFFF' fill-opacity='1' stroke='none'/>\n  <\/g>\n  <g clip-path='url(#svg_70fe26b9_464c_4739_98cc_b01503dd482c_c2)'>\n   <polyline points='181.32,135.24 642.02,135.24' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='181.32,88.40 642.02,88.40' fill='none' stroke='#E8E8E8' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <rect id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_e1' x='202.26' y='73.41' width='132.26' height='29.98' fill='#E6E6E6' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='2.13' stroke-linejoin='miter' stroke-linecap='butt' title='&amp;lt;b&amp;gt;Today&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Minutes 0 to 30: 11 v 11' data-id='Today 0'/>\n   <rect id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_e2' x='334.52' y='73.41' width='286.56' height='29.98' fill='#D7301F' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='2.13' stroke-linejoin='miter' stroke-linecap='butt' title='&amp;lt;b&amp;gt;Today&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Minutes 30 to 95: 11 v 10' data-id='Today 30'/>\n   <rect id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_e3' x='202.26' y='120.25' width='132.26' height='29.98' fill='#E6E6E6' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='2.13' stroke-linejoin='miter' stroke-linecap='butt' title='&amp;lt;b&amp;gt;Proposed: 20-minute power play&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Minutes 0 to 30: 11 v 11' data-id='Proposed: 20-minute power play 0'/>\n   <rect id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_e4' x='334.52' y='120.25' width='88.17' height='29.98' fill='#D7301F' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='2.13' stroke-linejoin='miter' stroke-linecap='butt' title='&amp;lt;b&amp;gt;Proposed: 20-minute power play&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Minutes 30 to 50: 11 v 10' data-id='Proposed: 20-minute power play 30'/>\n   <rect id='svg_70fe26b9_464c_4739_98cc_b01503dd482c_e5' x='422.69' y='120.25' width='198.39' height='29.98' fill='#BFBFBF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='2.13' stroke-linejoin='miter' stroke-linecap='butt' title='&amp;lt;b&amp;gt;Proposed: 20-minute power play&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Minutes 50 to 95: 11 v 11 again' data-id='Proposed: 20-minute power play 50'/>\n   <text x='250.38' y='92.28' font-size='8.11pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>11 v 11<\/text>\n   <text x='459.79' y='92.28' font-size='8.11pt' font-weight='bold' font-family='Helvetica' fill='#FFFFFF' fill-opacity='1'>11 v 10<\/text>\n   <text x='250.38' y='139.13' font-size='8.11pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>11 v 11<\/text>\n   <text x='360.59' y='139.13' font-size='8.11pt' font-weight='bold' font-family='Helvetica' fill='#FFFFFF' fill-opacity='1'>11 v 10<\/text>\n   <text x='488.27' y='139.13' font-size='8.11pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>11 v 11 again<\/text>\n   <line x1='334.52' y1='168.85' x2='334.52' y2='47.76' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.07' stroke-dasharray='2,2' stroke-linejoin='round' stroke-linecap='butt'/>\n   <text x='334.52' y='62.83' font-size='7.26pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Red card in the 30th minute<\/text>\n   <text x='424.33' y='160.99' font-size='6.83pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Back to 11 · the offender stays off and is banned<\/text>\n  <\/g>\n  <g clip-path='url(#svg_70fe26b9_464c_4739_98cc_b01503dd482c_c1)'>\n   <text x='5.98' y='139.2' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Proposed: 20-minute power play<\/text>\n   <text x='143.55' y='92.36' font-size='8.25pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Today<\/text>\n   <text x='198.68' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0'<\/text>\n   <text x='262.14' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>15'<\/text>\n   <text x='328.27' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>30'<\/text>\n   <text x='394.4' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>45'<\/text>\n   <text x='460.53' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>60'<\/text>\n   <text x='526.66' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>75'<\/text>\n   <text x='592.79' y='181.11' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>90'<\/text>\n   <text x='381.67' y='193.4' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Match minute<\/text>\n   <text x='5.98' y='33.26' font-size='8.62pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>How a 30th-minute red card plays out under today's rule and under a 20-minute power play<\/text>\n   <text x='5.98' y='17.49' font-size='12pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>A real punishment for the team, with an end point<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_70fe26b9_464c_4739_98cc_b01503dd482c","ratio":3.214285714285714,"settings":{"tooltip":{"css":".tooltip_SVGID_ { background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.96,"offx":10,"offy":0,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { stroke-width:3; }","reactive":false,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"fixed":false,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
<div class="sb-source">
<span>Illustration of the proposed rule</span>
<img src="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/statsbomb-logo.png" alt="StatsBomb">
</div>
</div>
</div>
<p>The power play still punishes the team, and meaningfully so. During those 20 minutes the offending side creates 0.13 fewer npxG and the opponent 0.10 more than in matched games. In points, a red card that leaves a team a man down for 20 minutes costs about <span class="sb-hl">0.21 points</span> (95% interval 0.10 to 0.33). The difference is that the punishment is <span class="sb-hl">limited, not perpetual</span>, and identical for every foul, whether it happens in the 10th minute or the 80th.</p>
<p>This is how other major team sports already handle their most serious fouls: the offender is removed, the opponent is compensated, and the team’s penalty has an end point.</p>
<div class="sb-compare">
<table class="caption-top table">
<colgroup>
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Sport</th>
<th style="text-align: left;">Most serious foul</th>
<th style="text-align: left;">The player</th>
<th style="text-align: left;">The team</th>
<th style="text-align: left;">The opponent gets</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Basketball (NBA)</td>
<td style="text-align: left;">Flagrant 2 foul</td>
<td style="text-align: left;">Ejected, can be suspended</td>
<td style="text-align: left;"><span class="sb-yes">Keeps 5 players</span></td>
<td style="text-align: left;">Two free throws and possession</td>
</tr>
<tr class="even">
<td style="text-align: left;">American football (NFL)</td>
<td style="text-align: left;">Flagrant hit, e.g.&nbsp;on the quarterback</td>
<td style="text-align: left;">Can be ejected and suspended</td>
<td style="text-align: left;"><span class="sb-yes">Keeps 11 players</span></td>
<td style="text-align: left;">A 15-yard penalty and an automatic first down</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Ice hockey (NHL)</td>
<td style="text-align: left;">Match penalty</td>
<td style="text-align: left;">Ejected, suspension reviewed</td>
<td style="text-align: left;"><span class="sb-yes">One player short for 5 minutes, then back to full strength</span></td>
<td style="text-align: left;">A 5-minute power play</td>
</tr>
<tr class="even">
<td style="text-align: left;">Rugby union</td>
<td style="text-align: left;">Red card under the 20-minute trial</td>
<td style="text-align: left;">Off for the rest of the match</td>
<td style="text-align: left;"><span class="sb-yes">One short for 20 minutes, then a replacement</span></td>
<td style="text-align: left;">A 20-minute numerical advantage</td>
</tr>
<tr class="odd">
<td style="text-align: left;"><strong>Football</strong></td>
<td style="text-align: left;">Red card</td>
<td style="text-align: left;">Off for the match, banned for future matches</td>
<td style="text-align: left;"><span class="sb-no">One short until the final whistle</span></td>
<td style="text-align: left;">An advantage of unlimited length</td>
</tr>
</tbody>
</table>
</div>
<p>Ice hockey’s timed power play is the closest model, and rugby union’s 20-minute red card applies the same logic. In basketball and American football the team is never reduced at all; the opponent is compensated with free throws or field position. Football is the only one of these sports where a single foul can decide the remaining hour of a match.</p>
<div class="sb-sowhat">
<p><strong>The recommendation</strong> Keep the red card for the player. Cap it for the team. A 20-minute power play preserves a real punishment, removes the clock as the judge of how big it is, and brings football in line with the sports that already got this right.</p>
</div>
</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section id="appendix-robustness-and-code" class="level2 appendix"><h2 class="anchored quarto-appendix-heading">Appendix: robustness and code</h2><div class="quarto-appendix-contents">

<div class="cell">
<details class="code-fold">
<summary>Show the code: the five-minute gap and every sensitivity check</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">donut_sets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Filter</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(sets, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) {</span>
<span id="cb6-2">  s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Filter</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors); <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) s <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) }))</span>
<span id="cb6-3">broad <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broad =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>); three <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">k =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>); narrow <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caliper =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb6-4">subset_sets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cond) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Filter</span>(cond, sets)</span>
<span id="cb6-5">checks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb6-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main analysis"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(sets, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5-minute gap before the card"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(donut_sets, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)),</span>
<span id="cb6-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Skip the first 2 minutes after"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(sets, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"England only"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset_sets</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>league <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"England"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-10">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spain only"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset_sets</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>league <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spain"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-11">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Italy only"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset_sets</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>league <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Italy"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-12">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Second yellows only"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset_sets</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>card<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Second Yellow"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-13">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Straight reds only"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset_sets</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>card<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red Card"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Include penalty and keeper reds"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(broad, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 twins instead of 5"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(three, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)),</span>
<span id="cb6-16">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tighter strength match"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(narrow, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)))</span>
<span id="cb6-17">rob <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(checks), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(k) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total"</span>), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(r) {</span>
<span id="cb6-18">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> checks[[k]]; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check =</span> k, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> r, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(x[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> x[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">before =</span> x[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]]))</span>
<span id="cb6-19">}))))</span>
<span id="cb6-20">rob[, check <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(check, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(checks)))]</span>
<span id="cb6-21">rob[, role_lab <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">focal =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Team down to ten"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opponent =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Opponent"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Both teams combined"</span>)[role], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Team down to ten"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Opponent"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Both teams combined"</span>))]</span>
<span id="cb6-22">rob[, colour <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(check <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main analysis"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">focal =</span> RED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opponent =</span> BLUE, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total =</span> INK)[role], GREY)]</span>
<span id="cb6-23">rob[, tip <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;b&gt;%s&lt;/b&gt;&lt;br&gt;%s: %s npxG per 20'&lt;br&gt;95%% interval %s&lt;br&gt;%d red cards"</span>, check, role_lab, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">signed</span>(estimate), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ci</span>(lo, hi), n)]</span>
<span id="cb6-24">donut_placebo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(donut_sets, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">before =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb6-25">p5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(rob, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(estimate, check, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> colour)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#bdbdbd"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_linerange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> hi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> tip, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(check, role)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> role_lab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> signed) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Every version of the analysis tells the same story"</span>,</span>
<span id="cb6-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change in npxG per 20 minutes after the red vs matched twins, with 95% intervals"</span>,</span>
<span id="cb6-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxG per 20 minutes vs twins"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_sb</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f2f2f2"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb6-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sb_chart</span>(p5, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.4</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="girafe html-widget html-fill-item" id="htmlwidget-7b9e949473a472c4e393" style="width:100%;height:338px;"></div>
<script type="application/json" data-for="htmlwidget-7b9e949473a472c4e393">{"x":{"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='ggiraph-svg' role='graphics-document' id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c' viewBox='0 0 648 388.8'>\n <defs id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_defs'>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c1'>\n   <rect x='0' y='0' width='648' height='388.8'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c2'>\n   <rect x='153.63' y='68.61' width='158.81' height='287.44'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c3'>\n   <rect x='318.42' y='68.61' width='158.81' height='287.44'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c4'>\n   <rect x='483.21' y='68.61' width='158.81' height='287.44'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c5'>\n   <rect x='153.63' y='47.76' width='158.81' height='20.85'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c6'>\n   <rect x='318.42' y='47.76' width='158.81' height='20.85'/>\n  <\/clipPath>\n  <clipPath id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c7'>\n   <rect x='483.21' y='47.76' width='158.81' height='20.85'/>\n  <\/clipPath>\n <\/defs>\n <g id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_rootg' class='ggiraph-svg-rootg'>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c1)'>\n   <rect x='0' y='0' width='648' height='388.8' fill='#FFFFFF' fill-opacity='1' stroke='#FFFFFF' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='round' class='ggiraph-svg-bg'/>\n   <rect x='-0' y='0' width='648' height='388.8' fill='#FFFFFF' fill-opacity='1' stroke='none'/>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c2)'>\n   <polyline points='153.63,340.65 312.44,340.65' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,314.99 312.44,314.99' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,289.32 312.44,289.32' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,263.66 312.44,263.66' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,238.00 312.44,238.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,212.33 312.44,212.33' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,186.67 312.44,186.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,161.00 312.44,161.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,135.34 312.44,135.34' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,109.67 312.44,109.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='153.63,84.01 312.44,84.01' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='237.96' y1='356.05' x2='237.96' y2='68.61' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='182.49' y1='84.01' x2='210.46' y2='84.01' stroke='#D7301F' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='180.56' y1='109.67' x2='211.03' y2='109.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='185.46' y1='135.34' x2='214.88' y2='135.34' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='160.85' y1='161' x2='211.37' y2='161' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='181.83' y1='186.67' x2='235.87' y2='186.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='170.4' y1='212.33' x2='213.35' y2='212.33' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='176.15' y1='238' x2='208.27' y2='238' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='180.99' y1='263.66' x2='240.15' y2='263.66' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='187.74' y1='289.32' x2='213.42' y2='289.32' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='183.37' y1='314.99' x2='218.08' y2='314.99' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='187.19' y1='340.65' x2='215.4' y2='340.65' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e1' cx='196.48' cy='84.01' r='2.51pt' fill='#D7301F' fill-opacity='1' stroke='#D7301F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Main analysis&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.13 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.17, −0.09]&amp;lt;br&amp;gt;99 red cards' data-id='Main analysis focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e2' cx='195.8' cy='109.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;5-minute gap before the card&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.13 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.18, −0.08]&amp;lt;br&amp;gt;97 red cards' data-id='5-minute gap before the card focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e3' cx='200.17' cy='135.34' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Skip the first 2 minutes after&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.12 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.16, −0.07]&amp;lt;br&amp;gt;99 red cards' data-id='Skip the first 2 minutes after focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e4' cx='186.11' cy='161' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;England only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.16 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.24, −0.08]&amp;lt;br&amp;gt;27 red cards' data-id='England only focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e5' cx='208.85' cy='186.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Spain only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.09 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.17, −0.01]&amp;lt;br&amp;gt;36 red cards' data-id='Spain only focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e6' cx='191.88' cy='212.33' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Italy only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.14 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.21, −0.08]&amp;lt;br&amp;gt;36 red cards' data-id='Italy only focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e7' cx='192.21' cy='238' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Second yellows only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.14 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.19, −0.09]&amp;lt;br&amp;gt;76 red cards' data-id='Second yellows only focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e8' cx='210.57' cy='263.66' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Straight reds only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.09 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.18, +0.01]&amp;lt;br&amp;gt;23 red cards' data-id='Straight reds only focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e9' cx='200.58' cy='289.32' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Include penalty and keeper reds&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.12 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.16, −0.08]&amp;lt;br&amp;gt;115 red cards' data-id='Include penalty and keeper reds focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e10' cx='200.73' cy='314.99' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;3 twins instead of 5&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.12 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.17, −0.06]&amp;lt;br&amp;gt;99 red cards' data-id='3 twins instead of 5 focal'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e11' cx='201.3' cy='340.65' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Tighter strength match&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Team down to ten: −0.11 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.16, −0.07]&amp;lt;br&amp;gt;98 red cards' data-id='Tighter strength match focal'/>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c3)'>\n   <polyline points='318.42,340.65 477.23,340.65' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,314.99 477.23,314.99' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,289.32 477.23,289.32' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,263.66 477.23,263.66' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,238.00 477.23,238.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,212.33 477.23,212.33' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,186.67 477.23,186.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,161.00 477.23,161.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,135.34 477.23,135.34' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,109.67 477.23,109.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='318.42,84.01 477.23,84.01' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='402.75' y1='356.05' x2='402.75' y2='68.61' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='419.31' y1='84.01' x2='448.4' y2='84.01' stroke='#2B6CB0' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='420.84' y1='109.67' x2='452.71' y2='109.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='422.15' y1='135.34' x2='453.52' y2='135.34' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='396.3' y1='161' x2='445.86' y2='161' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='416.71' y1='186.67' x2='470.01' y2='186.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='408.98' y1='212.33' x2='458.87' y2='212.33' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='419.33' y1='238' x2='452.09' y2='238' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='394.46' y1='263.66' x2='460.98' y2='263.66' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='415.37' y1='289.32' x2='443.24' y2='289.32' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='411.48' y1='314.99' x2='446.43' y2='314.99' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='415.85' y1='340.65' x2='445.69' y2='340.65' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e12' cx='433.85' cy='84.01' r='2.51pt' fill='#2B6CB0' fill-opacity='1' stroke='#2B6CB0' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Main analysis&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.10 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.05, +0.14]&amp;lt;br&amp;gt;99 red cards' data-id='Main analysis opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e13' cx='436.78' cy='109.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;5-minute gap before the card&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.11 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.06, +0.16]&amp;lt;br&amp;gt;97 red cards' data-id='5-minute gap before the card opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e14' cx='437.84' cy='135.34' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Skip the first 2 minutes after&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.11 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.06, +0.16]&amp;lt;br&amp;gt;99 red cards' data-id='Skip the first 2 minutes after opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e15' cx='421.08' cy='161' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;England only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.06 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.02, +0.13]&amp;lt;br&amp;gt;27 red cards' data-id='England only opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e16' cx='443.36' cy='186.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Spain only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.13 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.04, +0.21]&amp;lt;br&amp;gt;36 red cards' data-id='Spain only opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e17' cx='433.92' cy='212.33' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Italy only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.10 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.02, +0.17]&amp;lt;br&amp;gt;36 red cards' data-id='Italy only opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e18' cx='435.71' cy='238' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Second yellows only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.10 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.05, +0.15]&amp;lt;br&amp;gt;76 red cards' data-id='Second yellows only opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e19' cx='427.72' cy='263.66' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Straight reds only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.08 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.03, +0.18]&amp;lt;br&amp;gt;23 red cards' data-id='Straight reds only opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e20' cx='429.31' cy='289.32' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Include penalty and keeper reds&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.08 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.04, +0.13]&amp;lt;br&amp;gt;115 red cards' data-id='Include penalty and keeper reds opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e21' cx='428.95' cy='314.99' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;3 twins instead of 5&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.08 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.03, +0.14]&amp;lt;br&amp;gt;99 red cards' data-id='3 twins instead of 5 opponent'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e22' cx='430.77' cy='340.65' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Tighter strength match&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Opponent: +0.09 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [+0.04, +0.13]&amp;lt;br&amp;gt;98 red cards' data-id='Tighter strength match opponent'/>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c4)'>\n   <polyline points='483.21,340.65 642.02,340.65' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,314.99 642.02,314.99' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,289.32 642.02,289.32' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,263.66 642.02,263.66' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,238.00 642.02,238.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,212.33 642.02,212.33' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,186.67 642.02,186.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,161.00 642.02,161.00' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,135.34 642.02,135.34' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,109.67 642.02,109.67' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <polyline points='483.21,84.01 642.02,84.01' fill='none' stroke='#F2F2F2' stroke-opacity='1' stroke-width='0.75' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='567.54' y1='356.05' x2='567.54' y2='68.61' stroke='#BDBDBD' stroke-opacity='1' stroke-width='1.07' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='536.9' y1='84.01' x2='577.43' y2='84.01' stroke='#1D1D1F' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='537.92' y1='109.67' x2='580.9' y2='109.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='543.53' y1='135.34' x2='586.16' y2='135.34' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='500.44' y1='161' x2='567.6' y2='161' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='540.46' y1='186.67' x2='617.62' y2='186.67' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='519.34' y1='212.33' x2='585.93' y2='212.33' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='531.87' y1='238' x2='577.64' y2='238' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='520.35' y1='263.66' x2='609.89' y2='263.66' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='537.31' y1='289.32' x2='576.13' y2='289.32' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='531.97' y1='314.99' x2='581.06' y2='314.99' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <line x1='538.02' y1='340.65' x2='579.78' y2='340.65' stroke='#8A8F98' stroke-opacity='1' stroke-width='1.92' stroke-linejoin='round' stroke-linecap='butt'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e23' cx='557.16' cy='84.01' r='2.51pt' fill='#1D1D1F' fill-opacity='1' stroke='#1D1D1F' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Main analysis&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.03 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.10, +0.03]&amp;lt;br&amp;gt;99 red cards' data-id='Main analysis total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e24' cx='559.41' cy='109.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;5-minute gap before the card&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.03 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.09, +0.04]&amp;lt;br&amp;gt;97 red cards' data-id='5-minute gap before the card total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e25' cx='564.84' cy='135.34' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Skip the first 2 minutes after&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.01 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.07, +0.06]&amp;lt;br&amp;gt;99 red cards' data-id='Skip the first 2 minutes after total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e26' cx='534.02' cy='161' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;England only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.10 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.21, 0.00]&amp;lt;br&amp;gt;27 red cards' data-id='England only total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e27' cx='579.04' cy='186.67' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Spain only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: +0.04 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.08, +0.16]&amp;lt;br&amp;gt;36 red cards' data-id='Spain only total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e28' cx='552.63' cy='212.33' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Italy only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.05 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.15, +0.06]&amp;lt;br&amp;gt;36 red cards' data-id='Italy only total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e29' cx='554.75' cy='238' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Second yellows only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.04 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.11, +0.03]&amp;lt;br&amp;gt;76 red cards' data-id='Second yellows only total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e30' cx='565.12' cy='263.66' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Straight reds only&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.01 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.15, +0.13]&amp;lt;br&amp;gt;23 red cards' data-id='Straight reds only total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e31' cx='556.72' cy='289.32' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Include penalty and keeper reds&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.03 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.09, +0.03]&amp;lt;br&amp;gt;115 red cards' data-id='Include penalty and keeper reds total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e32' cx='556.51' cy='314.99' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;3 twins instead of 5&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.03 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.11, +0.04]&amp;lt;br&amp;gt;99 red cards' data-id='3 twins instead of 5 total'/>\n   <circle id='svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_e33' cx='558.9' cy='340.65' r='2.51pt' fill='#8A8F98' fill-opacity='1' stroke='#8A8F98' stroke-opacity='1' stroke-width='0.71' stroke-linejoin='round' stroke-linecap='round' title='&amp;lt;b&amp;gt;Tighter strength match&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;Both teams combined: −0.03 npxG per 20&amp;#39;&amp;lt;br&amp;gt;95% interval [−0.09, +0.04]&amp;lt;br&amp;gt;98 red cards' data-id='Tighter strength match total'/>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c5)'>\n   <text x='158.41' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Team down to ten<\/text>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c6)'>\n   <text x='323.2' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Opponent<\/text>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c7)'>\n   <text x='487.99' y='62.51' font-size='9pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Both teams combined<\/text>\n  <\/g>\n  <g clip-path='url(#svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c_c1)'>\n   <text x='161.55' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.20<\/text>\n   <text x='193.69' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.10<\/text>\n   <text x='228.62' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='257.96' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.10<\/text>\n   <text x='290.1' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.20<\/text>\n   <text x='326.34' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.20<\/text>\n   <text x='358.48' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.10<\/text>\n   <text x='393.41' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='422.75' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.10<\/text>\n   <text x='454.89' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.20<\/text>\n   <text x='491.13' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.20<\/text>\n   <text x='523.27' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>−0.10<\/text>\n   <text x='558.2' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>0.00<\/text>\n   <text x='587.54' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.10<\/text>\n   <text x='619.68' y='368.31' font-size='7.2pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>+0.20<\/text>\n   <text x='48.23' y='344.24' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Tighter strength match<\/text>\n   <text x='62.66' y='318.58' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>3 twins instead of 5<\/text>\n   <text x='5.98' y='292.91' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Include penalty and keeper reds<\/text>\n   <text x='70.45' y='267.25' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Straight reds only<\/text>\n   <text x='57.67' y='241.58' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Second yellows only<\/text>\n   <text x='108.79' y='215.92' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Italy only<\/text>\n   <text x='101.56' y='190.26' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Spain only<\/text>\n   <text x='90.45' y='164.59' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>England only<\/text>\n   <text x='24.32' y='138.93' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Skip the first 2 minutes after<\/text>\n   <text x='19.87' y='113.26' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>5-minute gap before the card<\/text>\n   <text x='87.68' y='87.6' font-size='7.5pt' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Main analysis<\/text>\n   <text x='332.26' y='380.6' font-size='7.5pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>npxG per 20 minutes vs twins<\/text>\n   <text x='5.98' y='33.26' font-size='8.62pt' font-family='Helvetica' fill='#5F6368' fill-opacity='1'>Change in npxG per 20 minutes after the red vs matched twins, with 95% intervals<\/text>\n   <text x='5.98' y='17.49' font-size='12pt' font-weight='bold' font-family='Helvetica' fill='#1D1D1F' fill-opacity='1'>Every version of the analysis tells the same story<\/text>\n  <\/g>\n <\/g>\n<\/svg>","js":null,"uid":"svg_75ebc19a_aa77_4ae8_b6e9_0f94e149eb4c","ratio":1.666666666666667,"settings":{"tooltip":{"css":".tooltip_SVGID_ { background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif; ; position:absolute;pointer-events:none;z-index:999;}","placement":"doc","opacity":0.96,"offx":10,"offy":0,"use_cursor_pos":true,"use_fill":false,"use_stroke":false,"delay_over":200,"delay_out":500},"hover":{"css":".hover_data_SVGID_ { stroke-width:3; }","reactive":false,"nearest_distance":null},"hover_inv":{"css":""},"hover_key":{"css":".hover_key_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_key_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_key_SVGID_ { fill:orange;stroke:black; }\nline.hover_key_SVGID_, polyline.hover_key_SVGID_ { fill:none;stroke:orange; }\nrect.hover_key_SVGID_, polygon.hover_key_SVGID_, path.hover_key_SVGID_ { fill:orange;stroke:none; }\nimage.hover_key_SVGID_ { stroke:orange; }","reactive":true},"hover_theme":{"css":".hover_theme_SVGID_ { fill:orange;stroke:black;cursor:pointer; }\ntext.hover_theme_SVGID_ { stroke:none;fill:orange; }\ncircle.hover_theme_SVGID_ { fill:orange;stroke:black; }\nline.hover_theme_SVGID_, polyline.hover_theme_SVGID_ { fill:none;stroke:orange; }\nrect.hover_theme_SVGID_, polygon.hover_theme_SVGID_, path.hover_theme_SVGID_ { fill:orange;stroke:none; }\nimage.hover_theme_SVGID_ { stroke:orange; }","reactive":true},"select":{"css":".select_data_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_data_SVGID_ { stroke:none;fill:red; }\ncircle.select_data_SVGID_ { fill:red;stroke:black; }\nline.select_data_SVGID_, polyline.select_data_SVGID_ { fill:none;stroke:red; }\nrect.select_data_SVGID_, polygon.select_data_SVGID_, path.select_data_SVGID_ { fill:red;stroke:none; }\nimage.select_data_SVGID_ { stroke:red; }","type":"multiple","only_shiny":true,"selected":[]},"select_inv":{"css":""},"select_key":{"css":".select_key_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_key_SVGID_ { stroke:none;fill:red; }\ncircle.select_key_SVGID_ { fill:red;stroke:black; }\nline.select_key_SVGID_, polyline.select_key_SVGID_ { fill:none;stroke:red; }\nrect.select_key_SVGID_, polygon.select_key_SVGID_, path.select_key_SVGID_ { fill:red;stroke:none; }\nimage.select_key_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"select_theme":{"css":".select_theme_SVGID_ { fill:red;stroke:black;cursor:pointer; }\ntext.select_theme_SVGID_ { stroke:none;fill:red; }\ncircle.select_theme_SVGID_ { fill:red;stroke:black; }\nline.select_theme_SVGID_, polyline.select_theme_SVGID_ { fill:none;stroke:red; }\nrect.select_theme_SVGID_, polygon.select_theme_SVGID_, path.select_theme_SVGID_ { fill:red;stroke:none; }\nimage.select_theme_SVGID_ { stroke:red; }","type":"single","only_shiny":true,"selected":[]},"zoom":{"min":1,"max":1,"duration":300},"toolbar":{"position":"topright","pngname":"diagram","tooltips":null,"fixed":false,"hidden":"saveaspng","delay_over":200,"delay_out":500},"sizing":{"rescale":true,"width":1}}},"evals":[],"jsHooks":[]}</script>
<div class="sb-source">
<span>Data: StatsBomb Open Data · 2015/16 Premier League, La Liga and Serie A</span>
<img src="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/statsbomb-logo.png" alt="StatsBomb">
</div>
</div>
</div>
<p>The ten-man side’s drop appears in every league, for straight reds and second yellows, with penalty and goalkeeper reds included, with three twins instead of five, with a tighter match on team strength, skipping the first two minutes after the card, and leaving a five-minute gap before it. Across every specification, the combined threat of both teams stays close to zero (−0.03 npxG per 20 minutes in the main analysis): a red card doesn’t change how much football is played, only who gets to play it.</p>
<p>The analysis was first written in Python and rebuilt here in R from the raw event files, reproducing every original estimate to four decimal places.</p>
<p><strong>Data.</strong> Event data: <a href="https://github.com/statsbomb/open-data">StatsBomb Open Data</a> (2015/16 Premier League, La Liga, Serie A). Pre-match odds: <a href="https://www.football-data.co.uk/">Football-Data.co.uk</a>. <code>fetch.R</code> downloads the raw files and <code>prep.R</code> rebuilds the match states.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code: setup and chart style</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggiraph)</span>
<span id="cb7-4"></span>
<span id="cb7-5">RED <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d7301f"</span>; BLUE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2b6cb0"</span>; GREY <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#8a8f98"</span>; INK <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1d1d1f"</span>; MUTED <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#5f6368"</span></span>
<span id="cb7-6"></span>
<span id="cb7-7">theme_sb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_family =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Helvetica"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)),</span>
<span id="cb7-10">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> MUTED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">11.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)),</span>
<span id="cb7-11">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot"</span>,</span>
<span id="cb7-12">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.minor =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb7-13">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#e8e8e8"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>),</span>
<span id="cb7-14">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> MUTED, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> MUTED),</span>
<span id="cb7-15">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strip.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> INK),</span>
<span id="cb7-16">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>))</span>
<span id="cb7-17">}</span>
<span id="cb7-18"></span>
<span id="cb7-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Every chart: interactive SVG + the StatsBomb credit line their data terms require</span></span>
<span id="cb7-20">sb_chart <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">note =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatsBomb Open Data · 2015/16 Premier League, La Liga and Serie A"</span>) {</span>
<span id="cb7-21">  htmltools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tagList</span>(</span>
<span id="cb7-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">girafe</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ggobj =</span> p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width_svg =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height_svg =</span> height,</span>
<span id="cb7-23">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_tooltip</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">css =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"background:#1d1d1f;color:#fff;padding:6px 9px;border-radius:4px;font:12px Helvetica,Arial,sans-serif;"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opacity =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">96</span>),</span>
<span id="cb7-24">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_hover</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">css =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width:3;"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_toolbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">saveaspng =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_sizing</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rescale =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))),</span>
<span id="cb7-25">    htmltools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">div</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sb-source"</span>, htmltools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">span</span>(note), htmltools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">img</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">src =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"statsbomb-logo.png"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alt =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatsBomb"</span>)))</span>
<span id="cb7-26">}</span>
<span id="cb7-27">pct <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formatC</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> d), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>)</span>
<span id="cb7-28">num <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formatC</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> d)</span>
<span id="cb7-29">signed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) { r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(x, d); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"−"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formatC</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(r), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> d)) }</span>
<span id="cb7-30">ci <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(lo, hi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"["</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">signed</span>(lo, d), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">signed</span>(hi, d), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"]"</span>)</span>
<span id="cb7-31">fmt_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">001</span>) <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;0.001"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.3f"</span>, x)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the code: the matching and estimation engine (functions.R)</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Red cards — matched event study in R.</span></span>
<span id="cb8-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Re-implements red_card_matched_study/analyse.py (same eligibility, matching and</span></span>
<span id="cb8-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clustered WLS inference). Shared by replicate.R and the White Belt article.</span></span>
<span id="cb8-4"></span>
<span id="cb8-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table)</span>
<span id="cb8-6"></span>
<span id="cb8-7">load_features <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/features.rds"</span>) {</span>
<span id="cb8-8">  f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readRDS</span>(path)</span>
<span id="cb8-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fast lookup: per match x side x metric, sorted times and a cumulative sum</span></span>
<span id="cb8-10">  parts <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>metrics, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"side"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"metric"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep.by =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># names "&lt;match&gt;.&lt;side&gt;.&lt;metric&gt;"</span></span>
<span id="cb8-11">  f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>idx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list2env</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(parts, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t =</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cumsum</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value)))), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hash =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb8-12">  f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>goals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>metrics[metric <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"goals"</span>, .(time, side)], f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>metrics[metric <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"goals"</span>, match_id])</span>
<span id="cb8-13">  f</span>
<span id="cb8-14">}</span>
<span id="cb8-15"></span>
<span id="cb8-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sum of a metric for one side in [left, right) seconds of elapsed match time</span></span>
<span id="cb8-17">measure <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, mid, side, metric, left, right) {</span>
<span id="cb8-18">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>idx[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(mid, side, metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>)]]</span>
<span id="cb8-19">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(z)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb8-20">  z<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cs[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findInterval</span>(right, z<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left.open =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> z<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cs[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findInterval</span>(left, z<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left.open =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb8-21">}</span>
<span id="cb8-22"></span>
<span id="cb8-23">scores_at <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, mid, t) {</span>
<span id="cb8-24">  g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>goals[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(mid)]]</span>
<span id="cb8-25">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(g)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb8-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb8-27">}</span>
<span id="cb8-28"></span>
<span id="cb8-29">win_prob <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(game, side) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p_home <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p_away</span>
<span id="cb8-30"></span>
<span id="cb8-31">FEATURES  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"win_probability"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"goals_at_index"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_npxg_focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_npxg_opponent"</span>,</span>
<span id="cb8-32">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_shots_focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_shots_opponent"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_passes_focal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pre_passes_opponent"</span>)</span>
<span id="cb8-33">MIN_SCALE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>)</span>
<span id="cb8-34"></span>
<span id="cb8-35">feature <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, game, side, t, scores) {</span>
<span id="cb8-36">  m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s, k) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">measure</span>(f, game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, s, k, t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1200</span>, t)</span>
<span id="cb8-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">win_prob</span>(game, side), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(scores),</span>
<span id="cb8-38">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np_shots"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np_shots"</span>),</span>
<span id="cb8-39">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"passes"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"passes"</span>))</span>
<span id="cb8-40">}</span>
<span id="cb8-41"></span>
<span id="cb8-42">first_red <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, mid) { r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>reds[match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> mid]; <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(r)) r[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(time)] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span> }</span>
<span id="cb8-43"></span>
<span id="cb8-44">eligible <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, game, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">horizon =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broad =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb8-45">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first_red</span>(f, game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id)</span>
<span id="cb8-46">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(r)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no_red"</span>))</span>
<span id="cb8-47">  c1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> r[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]; t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> c1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time</span>
<span id="cb8-48">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1200</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"under_20min_pre"</span>))</span>
<span id="cb8-49">  later <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(r) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>()</span>
<span id="cb8-50">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end, later)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> horizon <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"insufficient_stable_followup"</span>))</span>
<span id="cb8-51">  po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>perm_off[match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, time]</span>
<span id="cb8-52">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(po <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> horizon <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"permanent_off"</span>))</span>
<span id="cb8-53">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>broad <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>penalty) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"penalty_linked"</span>))</span>
<span id="cb8-54">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>broad <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>goalkeeper) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"goalkeeper"</span>))</span>
<span id="cb8-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">card =</span> c1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span>
<span id="cb8-56">}</span>
<span id="cb8-57"></span>
<span id="cb8-58"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build matched sets: same league, half, within-half clock, home/away orientation and score</span></span>
<span id="cb8-59"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># difference; caliper on pre-match win probability; up to k nearest donors by standardized RMS.</span></span>
<span id="cb8-60">match_design <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">horizon =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broad =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">k =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caliper =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>) {</span>
<span id="cb8-61">  games <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>games; sets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(); reasons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">character</span>()</span>
<span id="cb8-62">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (gi <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(games))) {</span>
<span id="cb8-63">    g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> games[gi]; el <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eligible</span>(f, g, horizon, broad)</span>
<span id="cb8-64">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(el<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>why)) { <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (el<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>why <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no_red"</span>) reasons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(reasons, el<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>why); <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span> }</span>
<span id="cb8-65">    cd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> el<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>card; side <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side; t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time</span>
<span id="cb8-66">    score <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_before, cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_before); diff <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> score[side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> score[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side]</span>
<span id="cb8-67">    xt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">feature</span>(f, g, side, t, score)</span>
<span id="cb8-68">    donors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> games[league <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>league <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id]</span>
<span id="cb8-69">    pool <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb8-70">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (di <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(donors))) {</span>
<span id="cb8-71">      d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> donors[di]</span>
<span id="cb8-72">      half_len <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>half_end <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>half_end</span>
<span id="cb8-73">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>half_time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> half_len) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb8-74">      anchor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>half_time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (cd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>half_end <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb8-75">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (anchor <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1200</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> anchor <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> horizon <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb8-76">      dr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first_red</span>(f, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id)</span>
<span id="cb8-77">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(dr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> dr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> anchor <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> horizon <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb8-78">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>perm_off[match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, time] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> anchor <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> horizon <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb8-79">      ds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scores_at</span>(f, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, anchor)</span>
<span id="cb8-80">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (ds[side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ds[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> diff) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb8-81">      pool[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(pool) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match_id =</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">game =</span> d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> anchor, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">feature</span>(f, d, side, anchor, ds))</span>
<span id="cb8-82">    }</span>
<span id="cb8-83">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(pool)) { reasons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(reasons, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no_exact_stratum"</span>); <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span> }</span>
<span id="cb8-84">    X <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(pool, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>))</span>
<span id="cb8-85">    sdv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(X, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(v) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((v <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(v))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)))           <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># population SD, as numpy</span></span>
<span id="cb8-86">    scale <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(sdv, MIN_SCALE)</span>
<span id="cb8-87">    dist <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowMeans</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sweep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sweep</span>(X, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, xt), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, scale, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb8-88">    ok <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(X[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> xt[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> caliper <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> dist <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>)</span>
<span id="cb8-89">    ok <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ok[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(dist[ok], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(pool[ok], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match_id"</span>))]</span>
<span id="cb8-90">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(ok) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) { reasons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(reasons, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fewer_than_3_donors"</span>); <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span> }</span>
<span id="cb8-91">    chosen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(ok, k), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(j) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(pool[[j]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">distance =</span> dist[j]))</span>
<span id="cb8-92">    sets[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(sets) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">game =</span> g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">card =</span> cd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xt =</span> xt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">donors =</span> chosen,</span>
<span id="cb8-93">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pool_mean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colMeans</span>(X), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pool_second =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colMeans</span>(X<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb8-94">  }</span>
<span id="cb8-95">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(sets, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reasons"</span>) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(reasons)</span>
<span id="cb8-96">  sets</span>
<span id="cb8-97">}</span>
<span id="cb8-98"></span>
<span id="cb8-99"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Matched difference-in-differences: treated change minus mean donor change, per 20 minutes.</span></span>
<span id="cb8-100"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Equivalent to WLS with matched-set intercepts; sandwich SEs clustered by source match.</span></span>
<span id="cb8-101">estimate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(f, sets, metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">before =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>) {</span>
<span id="cb8-102">  n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(sets)</span>
<span id="cb8-103">  rate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(mid, side, t, w) {</span>
<span id="cb8-104">    sides <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> side</span>
<span id="cb8-105">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(sides, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">measure</span>(f, mid, s, metric, t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> w[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> w[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>(w) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span></span>
<span id="cb8-106">  }</span>
<span id="cb8-107">  yt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ca <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(n); yc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, n); flat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb8-108">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(n)) {</span>
<span id="cb8-109">    s <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sets[[i]]; side <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (role <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side</span>
<span id="cb8-110">    pre <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rate</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, before); post <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rate</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, after)</span>
<span id="cb8-111">    tb[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pre; ta[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> post; yt[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> post <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pre</span>
<span id="cb8-112">    dv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rate</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, before), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rate</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, after)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)))</span>
<span id="cb8-113">    cb[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]); ca[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]); yc[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> dv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb8-114">    flat[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">set =</span> i, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match_id"</span>)),</span>
<span id="cb8-115">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dv), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dv))), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dv))), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(post <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pre, yc[[i]]))</span>
<span id="cb8-116">  }</span>
<span id="cb8-117">  cm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(yc, mean, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>); beta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(yt <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> cm); alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (yt <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb8-118">  fl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(flat); fl[, u <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> w <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> alpha[set] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z)]</span>
<span id="cb8-119">  g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fl[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(u)), by <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> cluster]</span>
<span id="cb8-120">  N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(fl); p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>; ng <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(g)</span>
<span id="cb8-121">  correction <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ng <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (ng <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p)</span>
<span id="cb8-122">  se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>u<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> correction); crit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qt</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">975</span>, n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-123">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> beta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo =</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> crit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi =</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> crit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se,</span>
<span id="cb8-124">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se), n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower.tail =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>),</span>
<span id="cb8-125">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treated_before =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tb), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treated_after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(ta), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control_before =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(cb), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control_after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(ca),</span>
<span id="cb8-126">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">benchmark_after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(ca) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(cb))</span>
<span id="cb8-127">}</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the code: build the matched comparisons and every number quoted in the text</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">load_features</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/features.rds"</span>)</span>
<span id="cb9-2">n_games <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>games); n_reds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>reds)</span>
<span id="cb9-3"></span>
<span id="cb9-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. Mechanism: 20 clean minutes before and after the first red (no penalty/keeper reds)</span></span>
<span id="cb9-5">sets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f)</span>
<span id="cb9-6">est  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>, ...) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">estimate</span>(f, s, metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> role, ...)</span>
<span id="cb9-7">own  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(sets, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"focal"</span>); opp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(sets, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>); tot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(sets, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">role =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total"</span>)</span>
<span id="cb9-8">pre_placebo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">est</span>(sets, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opponent"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">before =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">after =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb9-9"></span>
<span id="cb9-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. Persistence: games that stay 11-v-10 for 40 minutes</span></span>
<span id="cb9-11">long <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">horizon =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)</span>
<span id="cb9-12"></span>
<span id="cb9-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 3. Cost and timing: every first red from minute 20, matched at the card, outcome = final points</span></span>
<span id="cb9-14">all_sets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match_design</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">horizon =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">broad =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb9-15">points_of <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(game, side) {</span>
<span id="cb9-16">  gf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_score <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_score; ga <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (side <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_score <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_score</span>
<span id="cb9-17">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (gf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> ga) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (gf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> ga) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb9-18">}</span>
<span id="cb9-19">points_gap <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(S) {          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># matched difference in final points, clustered by source match</span></span>
<span id="cb9-20">  pl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(S), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) { s <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> S[[i]]</span>
<span id="cb9-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">set =</span> i, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_of</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side)),</span>
<span id="cb9-22">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">set =</span> i, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match_id"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb9-23">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_of</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))) }))</span>
<span id="cb9-24">  pt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pl[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tr =</span> y[z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cm =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(w[z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> y[z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])), by <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> set]</span>
<span id="cb9-25">  b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cm); a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb9-26">  pl[, u <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> w <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> a[set] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z)]; g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pl[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(u)), by <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> cluster]; n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(pt); N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(pl)</span>
<span id="cb9-27">  se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>u<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(g) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(g) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)); cr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qt</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">975</span>, n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb9-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ten =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">twins =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(pt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cm), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cost =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> cr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se))</span>
<span id="cb9-29">}</span>
<span id="cb9-30">card_min <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(all_sets, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb9-31">buckets  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(card_min, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">right =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20–45 min"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45–60 min"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"60–75 min"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"75+ min"</span>))</span>
<span id="cb9-32">cost_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_gap</span>(all_sets)</span>
<span id="cb9-33">by_time  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(buckets), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(b) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bucket =</span> b, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_gap</span>(all_sets[buckets <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> b]))))</span>
<span id="cb9-34">by_time[, bucket <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(bucket, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(buckets))]</span>
<span id="cb9-35"></span>
<span id="cb9-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Cost as a function of time left at the card -&gt; what a 20-minute power play would cost</span></span>
<span id="cb9-37">per_card <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(all_sets, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(</span>
<span id="cb9-38">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left =</span> (s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>,</span>
<span id="cb9-39">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_of</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points_of</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side))))</span>
<span id="cb9-40">fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(gap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> left, per_card)</span>
<span id="cb9-41">per10 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>]]</span>
<span id="cb9-42">pp20  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(fit, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"confidence"</span>)</span>
<span id="cb9-43">ratio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> by_time[bucket <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20–45 min"</span>, cost] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> by_time[bucket <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"75+ min"</span>, cost]   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># early vs late price</span></span>
<span id="cb9-44"></span>
<span id="cb9-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Share of the match's chances, 20 minutes before and after the card</span></span>
<span id="cb9-46">sh <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(sets, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) {</span>
<span id="cb9-47">  w <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(mid, side, t, a, b) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">measure</span>(f, mid, side, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)</span>
<span id="cb9-48">  tr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb9-49">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>game<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span>
<span id="cb9-50">  dn <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowMeans</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>donors, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb9-51">                                                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>side, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>time, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)))</span>
<span id="cb9-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t1 =</span> tr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t2 =</span> tr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t3 =</span> tr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t4 =</span> tr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c1 =</span> dn[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c2 =</span> dn[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c3 =</span> dn[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c4 =</span> dn[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb9-53">}))</span>
<span id="cb9-54">share_before <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t1) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t2); share_after <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t3) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t4)</span>
<span id="cb9-55">twin_before  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c1) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c2); twin_after  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c3) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c4)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the code: fetch.R (download the raw data)</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Download the raw inputs used by prep.R (run once, from this folder).</span></span>
<span id="cb10-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># StatsBomb Open Data (hudl/open-data) and Football-Data.co.uk 2015/16 odds.</span></span>
<span id="cb10-3">base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://raw.githubusercontent.com/statsbomb/open-data/master/data/"</span></span>
<span id="cb10-4">leagues <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">England =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Spain =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Italy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb10-5">odds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">England =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"E0"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Spain =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SP1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Italy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"I1"</span>)</span>
<span id="cb10-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/events"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showWarnings =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/sources"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showWarnings =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb10-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (l <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(leagues)) {</span>
<span id="cb10-8">  mf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/sources/matches_%s.json"</span>, l)</span>
<span id="cb10-9">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(mf)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">download.file</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%smatches/%d/27.json"</span>, base, leagues[[l]]), mf, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb10-10">  of <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/sources/odds_%s.csv"</span>, l)</span>
<span id="cb10-11">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(of)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">download.file</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.football-data.co.uk/mmz4281/1516/%s.csv"</span>, odds[[l]]), of, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb10-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (id <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> jsonlite<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fromJSON</span>(mf)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id) {</span>
<span id="cb10-13">    ef <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/events/%d.json.gz"</span>, id)</span>
<span id="cb10-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(ef)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb10-15">    tmp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>(); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">download.file</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%sevents/%d.json"</span>, base, id), tmp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb10-16">    con <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gzfile</span>(ef, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wb"</span>); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">writeBin</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readBin</span>(tmp, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.size</span>(tmp)), con); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">close</span>(con)</span>
<span id="cb10-17">  }</span>
<span id="cb10-18">}</span>
<span id="cb10-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/events"</span>)), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"event files ready</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the code: prep.R (rebuild match states and metrics from raw events)</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Red cards — rebuild match states and event metrics from raw StatsBomb events.</span></span>
<span id="cb11-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># An R re-implementation of red_card_matched_study/build_features.py (same rules),</span></span>
<span id="cb11-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reading raw/events/&lt;match_id&gt;.json.gz and raw/sources/. Writes data/features.rds.</span></span>
<span id="cb11-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb11-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run from this folder:  Rscript prep.R</span></span>
<span id="cb11-6"></span>
<span id="cb11-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>({ <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(jsonlite); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(parallel) })</span>
<span id="cb11-8"></span>
<span id="cb11-9">ALIASES <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb11-10">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AFC Bournemouth"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bournemouth"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Leicester City"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Leicester"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manchester City"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Man City"</span>,</span>
<span id="cb11-11">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manchester United"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Man United"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Newcastle United"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Newcastle"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Norwich City"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Norwich"</span>,</span>
<span id="cb11-12">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stoke City"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stoke"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Swansea City"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Swansea"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tottenham Hotspur"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tottenham"</span>,</span>
<span id="cb11-13">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West Bromwich Albion"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West Brom"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West Ham United"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"West Ham"</span>,</span>
<span id="cb11-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AC Milan"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Milan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AS Roma"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Roma"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hellas Verona"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Verona"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inter Milan"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inter"</span>,</span>
<span id="cb11-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Athletic Club"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ath Bilbao"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlético Madrid"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ath Madrid"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Celta Vigo"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Celta"</span>,</span>
<span id="cb11-16">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Espanyol"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Espanol"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Levante UD"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Levante"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Málaga"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Malaga"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RC Deportivo La Coruña"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"La Coruna"</span>,</span>
<span id="cb11-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rayo Vallecano"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vallecano"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Real Betis"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Betis"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Real Sociedad"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sociedad"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sporting Gijón"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sp Gijon"</span>)</span>
<span id="cb11-18">alias <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(ALIASES), ALIASES[x], x)</span>
<span id="cb11-19"></span>
<span id="cb11-20">secs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(ts) { p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(ts, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fixed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>); <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(p, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(z) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3600</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) }</span>
<span id="cb11-21">col  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e, name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(e)) e[[name]] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(default, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(e))</span>
<span id="cb11-22">xy   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(lst, i) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(lst, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(v) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(v) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> i) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(v[i]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb11-23">in_box <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">102</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">62</span></span>
<span id="cb11-24"></span>
<span id="cb11-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- matches + odds ---------------------------------------------------------------</span></span>
<span id="cb11-26">read_league <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(league) {</span>
<span id="cb11-27">  m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fromJSON</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/sources/matches_%s.json"</span>, league), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">flatten =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb11-28">  o <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fread</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/sources/odds_%s.csv"</span>, league), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">encoding =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UTF-8"</span>)</span>
<span id="cb11-29">  o <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> o[HomeTeam <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>]</span>
<span id="cb11-30">  o[, date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(Date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, Date)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d/%m/%y"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d/%m/%Y"</span>))]</span>
<span id="cb11-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anyDuplicated</span>(o[, .(date, HomeTeam, AwayTeam)]))</span>
<span id="cb11-32">  m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match_id =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">league =</span> league, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_date),</span>
<span id="cb11-33">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">home =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_team.home_team_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">away =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_team.away_team_name,</span>
<span id="cb11-34">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">home_id =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_team.home_team_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">away_id =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_team.away_team_id,</span>
<span id="cb11-35">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">home_score =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_score, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">away_score =</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_score)</span>
<span id="cb11-36">  m[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">:=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oh =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alias</span>(home), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oa =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alias</span>(away))]</span>
<span id="cb11-37">  j <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> o[m, on <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .(date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HomeTeam =</span> oh, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AwayTeam =</span> oa)]</span>
<span id="cb11-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anyNA</span>(j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FTHG), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FTHG <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_score <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FTAG <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_score))  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># every join checked against the score</span></span>
<span id="cb11-39">  use_avg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvH) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvH <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvD <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb11-40">  ph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(use_avg, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvH, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>B365H); pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(use_avg, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvD, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>B365D); pa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(use_avg, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BbAvA, j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>B365A)</span>
<span id="cb11-41">  inv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ph, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> pd, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> pa); inv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> inv <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowSums</span>(inv)        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># remove the overround</span></span>
<span id="cb11-42">  j[, .(match_id, league, date, home, away, home_id, away_id, home_score, away_score,</span>
<span id="cb11-43">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_home =</span> inv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_draw =</span> inv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_away =</span> inv[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])]</span>
<span id="cb11-44">}</span>
<span id="cb11-45">matches <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"England"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spain"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Italy"</span>), read_league))</span>
<span id="cb11-46"></span>
<span id="cb11-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- one match --------------------------------------------------------------------</span></span>
<span id="cb11-48">parse_match <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(mid) {</span>
<span id="cb11-49">  meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> matches[match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> mid]</span>
<span id="cb11-50">  path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw/events/%d.json.gz"</span>, mid)</span>
<span id="cb11-51">  e <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fromJSON</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rawToChar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memDecompress</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readBin</span>(path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"raw"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.size</span>(path)), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gzip"</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">flatten =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb11-52">  e <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> e[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>index), ]</span>
<span id="cb11-53">  e <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> e[e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, ]</span>
<span id="cb11-54">  type <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type.name; ts <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">secs</span>(e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>timestamp)</span>
<span id="cb11-55">  half_end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(ts[e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Half End"</span>]), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(ts[e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Half End"</span>]))</span>
<span id="cb11-56">  t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ts <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, half_end[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb11-57">  side <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>team.id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_id, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L)</span>
<span id="cb11-58"></span>
<span id="cb11-59">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Walk events in order to track who is on the pitch and the score</span></span>
<span id="cb11-60">  active <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(); sc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L); sent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L)</span>
<span id="cb11-61">  card <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"foul_committed.card.name"</span>); bb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bad_behaviour.card.name"</span>)</span>
<span id="cb11-62">  card[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(card)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bb[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(card)]</span>
<span id="cb11-63">  pen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"foul_committed.penalty"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>); pen[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(pen)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb11-64">  pos <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"position.id"</span>); pid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"player.id"</span>)</span>
<span id="cb11-65">  repl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"substitution.replacement.id"</span>)</span>
<span id="cb11-66">  shot_out <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"shot.outcome.name"</span>); perm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"player_off.permanent"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>); perm[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(perm)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb11-67">  lineup <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tactics.lineup"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>))</span>
<span id="cb11-68">  end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(half_end)</span>
<span id="cb11-69">  reds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(); goals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(); perm_off <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>()</span>
<span id="cb11-70">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(e))) {</span>
<span id="cb11-71">    tm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>team.id[i])</span>
<span id="cb11-72">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Starting XI"</span>) active[[tm]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lineup[[i]]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>player.id</span>
<span id="cb11-73">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(card[i]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> card[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red Card"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Second Yellow"</span>)) {</span>
<span id="cb11-74">      onfield <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(pid[i]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> pid[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> active[[tm]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> t[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> end</span>
<span id="cb11-75">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (onfield) {</span>
<span id="cb11-76">        reds[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(reds) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">half_time =</span> ts[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">period =</span> e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>period[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minute =</span> e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>minute[i],</span>
<span id="cb11-77">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">player =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"player.name"</span>)[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> card[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">penalty =</span> pen[i],</span>
<span id="cb11-78">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">goalkeeper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isTRUE</span>(pos[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">home_before =</span> sc[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">away_before =</span> sc[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb11-79">        active[[tm]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(active[[tm]], pid[i]); sent[side[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sent[side[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L</span>
<span id="cb11-80">      }</span>
<span id="cb11-81">    }</span>
<span id="cb11-82">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Substitution"</span>) active[[tm]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(active[[tm]], pid[i]), repl[i])</span>
<span id="cb11-83">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Player Off"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isTRUE</span>(perm[i])) perm_off <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(perm_off, t[i])</span>
<span id="cb11-84">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Shot"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isTRUE</span>(shot_out[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Goal"</span>)) { sc[side[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sc[side[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L; goals[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(goals) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[i]) }</span>
<span id="cb11-85">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Own Goal Against"</span>) { s <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> side[i]; sc[s <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sc[s <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L; goals[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(goals) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> s) }</span>
<span id="cb11-86">  }</span>
<span id="cb11-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">identical</span>(sc, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>home_score, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>away_score)))      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reconstructed score must match the source</span></span>
<span id="cb11-88"></span>
<span id="cb11-89">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Metric events: one row per counted event (time, side, metric, value)</span></span>
<span id="cb11-90">  is_shot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Shot"</span>; xg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"shot.statsbomb_xg"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)); is_pen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"shot.type.name"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Penalty"</span></span>
<span id="cb11-91">  pass_ok <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pass"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pass.outcome.name"</span>))</span>
<span id="cb11-92">  loc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"location"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)); pend <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pass.end_location"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)); cend <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(e, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"carry.end_location"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>))</span>
<span id="cb11-93">  sx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(loc, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>); sy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(loc, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>); px <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(pend, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>); py <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(pend, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>); cx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(cend, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>); cy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xy</span>(cend, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-94">  box_pass  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pass_ok <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">in_box</span>(px, py) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">in_box</span>(sx, sy)</span>
<span id="cb11-95">  box_carry <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Carry"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">in_box</span>(cx, cy) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">in_box</span>(sx, sy)</span>
<span id="cb11-96">  m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(</span>
<span id="cb11-97">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[is_shot], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[is_shot], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xg"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> xg[is_shot]),</span>
<span id="cb11-98">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[is_shot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_pen], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[is_shot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_pen], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npxg"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> xg[is_shot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_pen]),</span>
<span id="cb11-99">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[is_shot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_pen], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[is_shot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_pen], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np_shots"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb11-100">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[pass_ok], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[pass_ok], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"passes"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb11-101">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[pass_ok <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(px) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> px <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[pass_ok <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(px) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> px <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"final_third"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb11-102">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> t[box_pass <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> box_carry], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">side =</span> side[box_pass <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> box_carry], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"box_entries"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb11-103">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(goals)) m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(m, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(goals)[, .(time, side, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"goals"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)])</span>
<span id="cb11-104">  m[, match_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> mid]</span>
<span id="cb11-105">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match_id =</span> mid, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">half_end =</span> half_end[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> end, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_events =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(e)),</span>
<span id="cb11-106">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reds =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(reds)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(reds)[, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match_id :=</span> mid] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-107">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">perm_off =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(perm_off)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">match_id =</span> mid, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> perm_off) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-108">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metrics =</span> m)</span>
<span id="cb11-109">}</span>
<span id="cb11-110"></span>
<span id="cb11-111">t0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span>
<span id="cb11-112">parsed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mclapply</span>(matches<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(mid) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parse_match</span>(mid), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(err) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(mid, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">": "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conditionMessage</span>(err))),</span>
<span id="cb11-113">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mc.cores =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detectCores</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb11-114">bad <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vapply</span>(parsed, inherits, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"try-error"</span>); <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(bad)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(parsed[bad][[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]])</span>
<span id="cb11-115"></span>
<span id="cb11-116">clock    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(parsed, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match"</span>))</span>
<span id="cb11-117">reds     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(parsed, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reds"</span>))</span>
<span id="cb11-118">perm_off <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(parsed, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"perm_off"</span>))</span>
<span id="cb11-119">metrics  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(parsed, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"metrics"</span>))</span>
<span id="cb11-120">games    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> clock[matches, on <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"match_id"</span>]</span>
<span id="cb11-121"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setkey</span>(metrics, match_id, side, metric, time)</span>
<span id="cb11-122"></span>
<span id="cb11-123"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">games =</span> games, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reds =</span> reds, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">perm_off =</span> perm_off, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metrics =</span> metrics), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/features.rds"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">compress =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xz"</span>)</span>
<span id="cb11-124"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d matches, %s events, %d on-field reds in %d games, %d shots | %.0fs</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb11-125">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(games), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(games<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n_events), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(reds), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uniqueN</span>(reds<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>match_id),</span>
<span id="cb11-126">            metrics[metric <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xg"</span>, .N], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">difftime</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>(), t0, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"secs"</span>))))</span></code></pre></div></div>
</details>
</div>


</div></section></div> ]]></description>
  <category>football</category>
  <category>StatsBomb</category>
  <category>red cards</category>
  <category>rules</category>
  <guid>https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/</guid>
  <pubDate>Sat, 10 Oct 2026 03:00:00 GMT</pubDate>
  <media:content url="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/ten-men/cover.png" medium="image" type="image/png" height="95" width="144"/>
</item>
<item>
  <title>Why You Can No Longer Win the Premier League With a Weak Defence</title>
  <dc:creator>Juan Franceschini</dc:creator>
  <link>https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/pl-champions/</link>
  <description><![CDATA[ 





<div class="cell">
<style type="text/css">
/* The Athletic-inspired typography and styling */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&family=Inter:wght@400;500;600;700&display=swap');

/* This article is designed for a light page: in dark mode, keep it on light "paper" */
body.quarto-dark #quarto-content { background: #fafaf8; color-scheme: light; }
body.quarto-dark #quarto-content #TOC a,
body.quarto-dark #quarto-content #toc-title,
body.quarto-dark #quarto-content .post-backlink,
body.quarto-dark #quarto-content .post-footer-nav p { color: #495057; }
body.quarto-dark #quarto-content #TOC a.active { color: #37003c; }

/* Vibrant PL-themed title banner */
.quarto-title-block {
  background: linear-gradient(135deg, #37003c 0%, #5a0f5c 50%, #37003c 100%);
  padding: 3rem 2rem 2.5rem !important;
  margin: 0 !important;
  border-bottom: 4px solid #00ff85;
  position: relative;
  overflow: hidden;
}

.quarto-title-block::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(ellipse at 20% 50%, rgba(0, 255, 133, 0.15) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 50%, rgba(232, 250, 47, 0.1) 0%, transparent 50%);
  pointer-events: none;
}

.quarto-title-block .title {
  color: white !important;
  font-family: 'Inter', -apple-system, sans-serif !important;
  font-weight: 800 !important;
  font-size: 2.75rem !important;
  line-height: 1.1 !important;
  letter-spacing: -0.03em;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
  position: relative;
}

.quarto-title-block .subtitle {
  color: rgba(255, 255, 255, 0.85) !important;
  font-family: 'Source Serif 4', Georgia, serif !important;
  font-size: 1.25rem !important;
  font-style: italic;
  margin-top: 0.75rem !important;
  position: relative;
}

.quarto-title-block .quarto-title-meta {
  color: #00ff85 !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.9rem !important;
  margin-top: 1.5rem !important;
  position: relative;
}

.quarto-title-block .quarto-title-meta-contents a,
.quarto-title-block .quarto-title-meta-contents {
  color: #00ff85 !important;
}

.quarto-title-block .quarto-categories {
  margin-top: 1rem;
  position: relative;
}

.quarto-title-block .quarto-category {
  background: rgba(255, 255, 255, 0.15) !important;
  color: white !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.75rem !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Article body - justified text */
body {
  text-align: justify;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

#quarto-content {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.125rem;
  line-height: 1.8;
  color: #1a1a1a;
}

.quarto-article-main {
  max-width: 720px;
  margin: 0 auto;
}

p {
  margin-bottom: 1.5rem;
  text-align: justify;
}

/* Headers */
h1, h2, h3 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 700;
  color: #0d0d0d;
  letter-spacing: -0.02em;
  text-align: left;
}

h2 {
  font-size: 1.75rem;
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid #37003c;
}

h3 {
  font-size: 1.25rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: #37003c;
}

/* Pull quotes */
.pullquote {
  font-family: 'Inter', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.4;
  color: #37003c;
  border-left: 4px solid #00ff85;
  padding-left: 1.5rem;
  margin: 2.5rem 0;
  text-align: left;
}

/* Stats callout */
.stat-callout {
  background: white;
  border-radius: 12px;
  padding: 1.5rem 2rem;
  border: 2px solid #e5e5e5;
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat-callout:hover {
  border-color: #37003c;
  box-shadow: 0 4px 12px rgba(55, 0, 60, 0.1);
}

.stat-callout p {
  margin: 0;
}

.stat-callout-number {
  font-family: 'Inter', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  color: #37003c;
  line-height: 1;
  display: block;
}

.stat-callout-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #666;
  margin-top: 0.5rem;
  display: block;
}

/* Key insight boxes */
.insight-box {
  background: #37003c;
  color: white;
  padding: 1.5rem 2rem;
  border-radius: 8px;
  margin: 2rem 0;
  font-family: 'Inter', sans-serif;
}

.insight-box strong {
  color: #00ff85;
}

/* Data visualization container */
.viz-container {
  background: #37003c;
  border-radius: 12px;
  padding: 2rem;
  margin: 2.5rem 0;
  box-shadow: 0 4px 24px rgba(55, 0, 60, 0.15);
}

/* Table styling - Athletic style */
.athletic-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  margin: 1.5rem 0;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.athletic-table thead {
  background: #1a1a1a;
  color: white;
}

.athletic-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.athletic-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #eee;
}

.athletic-table tbody tr:hover {
  background: #fafafa;
}

.athletic-table .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.athletic-table .highlight {
  background: #e8fa2f;
  color: #1a1a1a;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.athletic-table .positive {
  color: #00875a;
  font-weight: 600;
}

.athletic-table .negative {
  color: #cf3038;
  font-weight: 600;
}

/* Byline and metadata */
.article-meta {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #e5e5e5;
}

/* Footer */
.article-footer {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  color: #666;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e5e5;
}

/* Legend styling */
.legend {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  color: #8c8c8c;
  margin-top: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* Responsive */
@media (max-width: 768px) {
  .quarto-article {
    font-size: 1rem;
    padding: 0 1rem;
  }

  .viz-container {
    padding: 1rem;
    margin: 1.5rem -1rem;
    border-radius: 0;
  }

  .pullquote {
    font-size: 1.25rem;
  }
}
</style>
</div>
<p>In 1997, Manchester United won the league with the eighth-best defence. They conceded more goals than seven other teams — including fifth-place Liverpool.</p>
<p>In 2024, that would be impossible.</p>
<p>Since Pep Guardiola arrived at Manchester City in 2016, no champion has finished worse than second in defence. Not third. Not fourth. Second, at worst. The window for defensive weakness has closed.</p>
<div class="pullquote">
<p>The question isn’t whether attack or defence wins titles. It’s why the old formula stopped working — and what replaced it.</p>
</div>
<p>To understand this shift, I examined every Premier League champion from 1992-93 through Liverpool’s 2024-25 triumph. For each, I ranked their attacking output (goals scored) and defensive record (goals conceded) against the full 20-team field. The data spans 32 seasons, seven different champions, and a structural transformation in what it takes to win.</p>
<section id="the-numbers" class="level2">
<h2 class="anchored" data-anchor-id="the-numbers">The Numbers</h2>
<div class="stat-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1.5rem; margin: 2rem 0;">
<div class="stat-callout">
<p><span class="stat-callout-number">32</span></p>
<p><span class="stat-callout-label">Seasons analysed</span></p>
</div>
<div class="stat-callout">
<p><span class="stat-callout-number">9</span></p>
<p><span class="stat-callout-label">Champions: #1 in both</span></p>
</div>
<div class="stat-callout">
<p><span class="stat-callout-number">15</span></p>
<p><span class="stat-callout-label">Attack-led titles</span></p>
</div>
<div class="stat-callout">
<p><span class="stat-callout-number">5</span></p>
<p><span class="stat-callout-label">Defence-led titles</span></p>
</div>
</div>
</section>
<section id="the-visual-proof" class="level2">
<h2 class="anchored" data-anchor-id="the-visual-proof">The Visual Proof</h2>
<p>The chart below is the argument. Every title winner plotted by their attack rank (yellow) and defence rank (green). Pink dots mark balanced teams — identical rankings in both.</p>
<p>Two patterns emerge immediately. First, every green dot sits in the top third of the chart. No exceptions. Second, the gap between yellow and green dots shrinks over time. Champions of the 1990s could survive with one excellence. Modern champions cannot.</p>
<div class="cell">
<div class="cell-output-display">
<div class="plotly html-widget html-fill-item" id="htmlwidget-c1516b3a67da57aeac8c" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-c1516b3a67da57aeac8c">{"x":{"visdat":{"6275300e750d":["function () ","plotlyVisDat"],"6275526c121":["function () ","data"],"62753351602b":["function () ","data"]},"cur_data":"62753351602b","attrs":{"6275300e750d":{"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"x":[1,1,null,2,2,null,3,3,null,4,4,null,5,5,null,6,6,null,7,7,null,10,10,null,12,12,null,14,14,null,16,16,null,17,17,null,18,18,null,20,20,null,21,21,null,24,24,null,26,26,null,27,27,null,31,31,null,32,32,null],"y":[2,4,null,1,5,null,1,4,null,1,8,null,3,2,null,1,4,null,1,7,null,2,1,null,2,1,null,1,2,null,2,1,null,1,2,null,1,3,null,1,5,null,1,2,null,2,3,null,1,2,null,2,1,null,1,2,null,1,2,null],"type":"scatter","mode":"lines","line":{"color":"#d1d5db","width":1.5},"hoverinfo":"none","showlegend":false,"name":"connector","inherit":true},"6275526c121":{"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"x":{},"y":{},"type":"scatter","mode":"markers","marker":{"color":"#d97706","size":9,"line":{"color":"white","width":1.5}},"text":{},"hovertemplate":"%{text}<extra><\/extra>","showlegend":false,"name":"attack","inherit":true},"62753351602b":{"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"x":{},"y":{},"type":"scatter","mode":"markers","marker":{"color":"#059669","size":9,"line":{"color":"white","width":1.5}},"text":{},"hovertemplate":"%{text}<extra><\/extra>","showlegend":false,"name":"defence","inherit":true}},"layout":{"margin":{"b":80,"l":50,"t":90,"r":20},"title":{"text":"<b>CHAMPIONS' DNA<\/b><br><sup>Attack vs defence ranking · hover any dot<\/sup>","font":{"family":"Inter","size":15,"color":"#1a1a1a"},"x":0,"xanchor":"left"},"xaxis":{"domain":[0,1],"automargin":true,"tickmode":"array","tickvals":[1,5,9,13,17,21,25,29,32],"ticktext":["'93","'97","'01","'05","'09","'13","'17","'21","'24"],"showgrid":false,"zeroline":false,"title":{"text":"SEASON","font":{"family":"Inter","size":10,"color":"#9ca3af"}},"tickfont":{"family":"Inter","size":10,"color":"#9ca3af"}},"yaxis":{"domain":[0,1],"automargin":true,"range":[10.5,0.5],"tickmode":"array","tickvals":[1,3,5,7,9],"ticktext":["#1","#3","#5","#7","#9"],"title":{"text":"LEAGUE RANK","font":{"family":"Inter","size":10,"color":"#9ca3af"}},"tickfont":{"family":"Inter","size":10,"color":"#9ca3af"},"showgrid":true,"gridcolor":"#f3f4f6","zeroline":false},"shapes":[{"type":"rect","x0":0.5,"x1":12.5,"y0":0.5,"y1":10.5,"fillcolor":"rgba(192,57,43,0.10)","line":{"width":0},"layer":"below"},{"type":"rect","x0":12.5,"x1":24.5,"y0":0.5,"y1":10.5,"fillcolor":"rgba(230,126,34,0.10)","line":{"width":0},"layer":"below"},{"type":"rect","x0":24.5,"x1":32.5,"y0":0.5,"y1":10.5,"fillcolor":"rgba(55,0,60,0.10)","line":{"width":0},"layer":"below"},{"type":"line","x0":12.5,"x1":12.5,"y0":0.5,"y1":10.5,"line":{"color":"#d1d5db","dash":"dot","width":1.2}},{"type":"line","x0":24.5,"x1":24.5,"y0":0.5,"y1":10.5,"line":{"color":"#d1d5db","dash":"dot","width":1.2}},{"type":"rect","x0":0.5,"x1":32.5,"y0":0.5,"y1":3.5,"fillcolor":"rgba(5,150,105,0.07)","line":{"color":"rgba(5,150,105,0.35)","dash":"dot","width":1},"layer":"below"}],"annotations":[{"x":6.5,"y":10.199999999999999,"text":"<b>EARLY PL<\/b>","showarrow":false,"xanchor":"center","yanchor":"bottom","bgcolor":"#b91c1c","borderpad":4,"font":{"family":"Inter","size":8.5,"color":"white"}},{"x":18.5,"y":10.199999999999999,"text":"<b>MIDDLE ERA<\/b>","showarrow":false,"xanchor":"center","yanchor":"bottom","bgcolor":"#c2710c","borderpad":4,"font":{"family":"Inter","size":8.5,"color":"white"}},{"x":28.5,"y":10.199999999999999,"text":"<b>GUARDIOLA ERA<\/b>","showarrow":false,"xanchor":"center","yanchor":"bottom","bgcolor":"#37003c","borderpad":4,"font":{"family":"Inter","size":8.5,"color":"white"}},{"x":32.399999999999999,"y":2,"text":"TOP 3","showarrow":false,"xanchor":"right","yanchor":"middle","font":{"family":"Inter","size":8.5,"color":"#047857"}}],"paper_bgcolor":"#ffffff","plot_bgcolor":"#ffffff","font":{"family":"Inter"},"showlegend":false,"updatemenus":[{"type":"buttons","direction":"left","x":0,"y":-0.17999999999999999,"xanchor":"left","yanchor":"top","pad":{"r":6,"t":0},"bgcolor":"#ffffff","bordercolor":"#37003c","borderwidth":1,"font":{"family":"Inter","size":11,"color":"#37003c"},"buttons":[{"label":"Both","method":"update","args":[{"visible":[true,true,true]}]},{"label":"Attack","method":"update","args":[{"visible":[false,true,false]}]},{"label":"Defence","method":"update","args":[{"visible":[false,false,true]}]}]}],"hovermode":"closest"},"source":"A","config":{"modeBarButtonsToAdd":["hoverclosest","hovercompare"],"showSendToCloud":false,"displayModeBar":false},"data":[{"x":[1,1,null,2,2,null,3,3,null,4,4,null,5,5,null,6,6,null,7,7,null,10,10,null,12,12,null,14,14,null,16,16,null,17,17,null,18,18,null,20,20,null,21,21,null,24,24,null,26,26,null,27,27,null,31,31,null,32,32],"y":[2,4,null,1,5,null,1,4,null,1,8,null,3,2,null,1,4,null,1,7,null,2,1,null,2,1,null,1,2,null,2,1,null,1,2,null,1,3,null,1,5,null,1,2,null,2,3,null,1,2,null,2,1,null,1,2,null,1,2],"type":"scatter","mode":"lines","line":{"color":"#d1d5db","width":1.5},"hoverinfo":["none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none",null,"none","none"],"showlegend":false,"name":"connector","marker":{"color":"rgba(31,119,180,1)","line":{"color":"rgba(31,119,180,1)"}},"error_y":{"color":"rgba(31,119,180,1)"},"error_x":{"color":"rgba(31,119,180,1)"},"xaxis":"x","yaxis":"y","frame":null},{"x":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],"y":[2,1,1,1,3,1,1,1,2,2,1,2,1,1,1,2,1,1,1,1,1,2,3,2,1,1,2,1,1,1,1,1],"type":"scatter","mode":"markers","marker":{"color":"#d97706","size":9,"line":{"color":"white","width":1.5}},"text":["<b>Manchester United<\/b><br>1993-94<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Blackburn<\/b><br>1994-95<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #5<\/span>","<b>Manchester United<\/b><br>1995-96<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Manchester United<\/b><br>1996-97<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #8<\/span>","<b>Arsenal<\/b><br>1997-98<br><span style='color:#92400e'>Goals scored rank: #3<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>1998-99<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Manchester United<\/b><br>1999-00<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #7<\/span>","<b>Manchester United<\/b><br>2000-01<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Arsenal<\/b><br>2001-02<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2002-03<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Arsenal<\/b><br>2003-04<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2004-05<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2005-06<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2006-07<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2007-08<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2008-09<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2009-10<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2010-11<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Manchester City<\/b><br>2011-12<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2012-13<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #5<\/span>","<b>Manchester City<\/b><br>2013-14<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Chelsea<\/b><br>2014-15<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Leicester<\/b><br>2015-16<br><span style='color:#92400e'>Goals scored rank: #3<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Chelsea<\/b><br>2016-17<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Manchester City<\/b><br>2017-18<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2018-19<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Liverpool<\/b><br>2019-20<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2020-21<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2021-22<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2022-23<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2023-24<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Liverpool<\/b><br>2024-25<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>"],"hovertemplate":["%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>"],"showlegend":false,"name":"attack","error_y":{"color":"rgba(255,127,14,1)"},"error_x":{"color":"rgba(255,127,14,1)"},"line":{"color":"rgba(255,127,14,1)"},"xaxis":"x","yaxis":"y","frame":null},{"x":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],"y":[4,5,4,8,2,4,7,1,2,1,1,1,1,2,1,1,2,3,1,5,2,2,3,3,1,2,1,1,1,1,2,2],"type":"scatter","mode":"markers","marker":{"color":"#059669","size":9,"line":{"color":"white","width":1.5}},"text":["<b>Manchester United<\/b><br>1993-94<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Blackburn<\/b><br>1994-95<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #5<\/span>","<b>Manchester United<\/b><br>1995-96<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Manchester United<\/b><br>1996-97<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #8<\/span>","<b>Arsenal<\/b><br>1997-98<br><span style='color:#92400e'>Goals scored rank: #3<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>1998-99<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #4<\/span>","<b>Manchester United<\/b><br>1999-00<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #7<\/span>","<b>Manchester United<\/b><br>2000-01<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Arsenal<\/b><br>2001-02<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2002-03<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Arsenal<\/b><br>2003-04<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2004-05<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2005-06<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2006-07<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2007-08<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2008-09<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Chelsea<\/b><br>2009-10<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Manchester United<\/b><br>2010-11<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Manchester City<\/b><br>2011-12<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester United<\/b><br>2012-13<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #5<\/span>","<b>Manchester City<\/b><br>2013-14<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Chelsea<\/b><br>2014-15<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Leicester<\/b><br>2015-16<br><span style='color:#92400e'>Goals scored rank: #3<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Chelsea<\/b><br>2016-17<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #3<\/span>","<b>Manchester City<\/b><br>2017-18<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2018-19<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Liverpool<\/b><br>2019-20<br><span style='color:#92400e'>Goals scored rank: #2<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2020-21<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2021-22<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2022-23<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #1<\/span>","<b>Manchester City<\/b><br>2023-24<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>","<b>Liverpool<\/b><br>2024-25<br><span style='color:#92400e'>Goals scored rank: #1<\/span><br><span style='color:#065f46'>Goals conceded rank: #2<\/span>"],"hovertemplate":["%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>"],"showlegend":false,"name":"defence","error_y":{"color":"rgba(44,160,44,1)"},"error_x":{"color":"rgba(44,160,44,1)"},"line":{"color":"rgba(44,160,44,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.20000000000000001,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot","plotly_sunburstclick"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<section id="the-champion-zone" class="level3">
<h3 class="anchored" data-anchor-id="the-champion-zone">The Champion Zone</h3>
<p>The scatter plot below reveals the same data from a different angle. Each dot is a title-winning season, positioned by attack rank (x-axis) and defence rank (y-axis). The green shaded area marks the top-5 in both metrics.</p>
<p>The clustering is striking: every champion since 2004 sits inside or at the edge of this zone. The outliers — Ferguson’s attack-dominant sides with seventh and eighth-ranked defences — are relics of a different era.</p>
<div class="cell">
<div class="cell-output-display">
<div class="plotly html-widget html-fill-item" id="htmlwidget-6eba092af2910be97327" style="width:100%;height:464px;"></div>
<script type="application/json" data-for="htmlwidget-6eba092af2910be97327">{"x":{"visdat":{"62755a17562e":["function () ","plotlyVisDat"]},"cur_data":"62755a17562e","attrs":{"62755a17562e":{"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"x":{},"y":{},"type":"scatter","mode":"markers","marker":{"color":"#37003c","size":32,"line":{"color":"white","width":1.5}},"text":{},"hovertemplate":"%{text}<extra><\/extra>","hoverlabel":{"bgcolor":"#1a1a1a","bordercolor":"rgba(255,255,255,0.15)","font":{"family":"Inter","size":13,"color":"white"},"align":"left"},"showlegend":false,"name":"champion","inherit":true},"62755a17562e.1":{"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"x":{},"y":{},"text":{},"type":"scatter","mode":"text","textfont":{"family":"Inter","size":11,"color":"white"},"hoverinfo":"none","showlegend":false,"name":"count","inherit":true}},"layout":{"margin":{"b":60,"l":60,"t":80,"r":20},"title":{"text":"<b>WHERE CHAMPIONS LIVE<\/b><br><sup>Every PL winner ranked by goals scored vs. goals conceded · hover a dot<\/sup>","font":{"family":"Inter","size":15,"color":"#1a1a1a"},"x":0,"xanchor":"left"},"xaxis":{"domain":[0,1],"automargin":true,"range":[0.5,10.5],"tickmode":"array","tickvals":[1,2,3,4,5,6,7,8,9,10],"ticktext":["#10","#9","#8","#7","#6","#5","#4","#3","#2","#1"],"title":{"text":"worse ←   GOALS SCORED RANK   → better","font":{"family":"Inter","size":9,"color":"#9ca3af"}},"tickfont":{"family":"Inter","size":9,"color":"#9ca3af"},"showgrid":true,"gridcolor":"#f3f4f6","zeroline":false,"fixedrange":true},"yaxis":{"domain":[0,1],"automargin":true,"range":[0.5,10.5],"tickmode":"array","tickvals":[1,2,3,4,5,6,7,8,9,10],"ticktext":["#10","#9","#8","#7","#6","#5","#4","#3","#2","#1"],"title":{"text":"worse ↓   GOALS CONCEDED RANK   ↑ better","font":{"family":"Inter","size":9,"color":"#9ca3af"}},"tickfont":{"family":"Inter","size":9,"color":"#9ca3af"},"showgrid":true,"gridcolor":"#f3f4f6","zeroline":false,"scaleanchor":"x","scaleratio":1,"fixedrange":true},"shapes":[{"type":"rect","x0":5.5,"x1":10.5,"y0":5.5,"y1":10.5,"fillcolor":"rgba(0,192,96,0.07)","line":{"width":0},"layer":"below"},{"type":"rect","x0":7.5,"x1":10.5,"y0":7.5,"y1":10.5,"fillcolor":"rgba(0,192,96,0.13)","line":{"width":0},"layer":"below"},{"type":"line","x0":5.5,"x1":5.5,"y0":0.5,"y1":10.5,"line":{"color":"rgba(150,150,150,0.45)","dash":"dash","width":0.80000000000000004}},{"type":"line","x0":0.5,"x1":10.5,"y0":5.5,"y1":5.5,"line":{"color":"rgba(150,150,150,0.45)","dash":"dash","width":0.80000000000000004}},{"type":"line","x0":0.5,"x1":10.5,"y0":0.5,"y1":10.5,"line":{"color":"rgba(150,150,150,0.35)","dash":"dot","width":0.80000000000000004}}],"paper_bgcolor":"#ffffff","plot_bgcolor":"#ffffff","font":{"family":"Inter","color":"#1a1a1a"},"showlegend":false,"hovermode":"closest"},"source":"A","config":{"modeBarButtonsToAdd":["hoverclosest","hovercompare"],"showSendToCloud":false,"displayModeBar":false,"responsive":true},"data":[{"x":[10,10,10,10,10,10,10,9,9,9,9,8,8],"y":[10,9,8,7,6,4,3,10,9,8,7,9,8],"type":"scatter","mode":"markers","marker":{"color":"#37003c","size":32,"line":{"color":"white","width":1.5}},"text":["<b>Manchester United<\/b> (2000-01)<br><b>Arsenal<\/b> (2003-04)<br><b>Chelsea<\/b> (2005-06)<br><b>Manchester United<\/b> (2007-08)<br><b>Manchester City<\/b> (2011-12)<br><b>Manchester City<\/b> (2017-18)<br><b>Manchester City<\/b> (2020-21)<br><b>Manchester City<\/b> (2021-22)<br><b>Manchester City<\/b> (2022-23)<br>Goals scored rank: #1<br>Goals conceded rank: #1","<b>Manchester United<\/b> (2006-07)<br><b>Chelsea<\/b> (2009-10)<br><b>Manchester City<\/b> (2013-14)<br><b>Manchester City<\/b> (2018-19)<br><b>Manchester City<\/b> (2023-24)<br><b>Liverpool<\/b> (2024-25)<br>Goals scored rank: #1<br>Goals conceded rank: #2","<b>Manchester United<\/b> (2010-11)<br>Goals scored rank: #1<br>Goals conceded rank: #3","<b>Manchester United<\/b> (1995-96)<br><b>Manchester United<\/b> (1998-99)<br>Goals scored rank: #1<br>Goals conceded rank: #4","<b>Blackburn<\/b> (1994-95)<br><b>Manchester United<\/b> (2012-13)<br>Goals scored rank: #1<br>Goals conceded rank: #5","<b>Manchester United<\/b> (1999-00)<br>Goals scored rank: #1<br>Goals conceded rank: #7","<b>Manchester United<\/b> (1996-97)<br>Goals scored rank: #1<br>Goals conceded rank: #8","<b>Manchester United<\/b> (2002-03)<br><b>Chelsea<\/b> (2004-05)<br><b>Manchester United<\/b> (2008-09)<br><b>Liverpool<\/b> (2019-20)<br>Goals scored rank: #2<br>Goals conceded rank: #1","<b>Arsenal<\/b> (2001-02)<br><b>Chelsea<\/b> (2014-15)<br>Goals scored rank: #2<br>Goals conceded rank: #2","<b>Chelsea<\/b> (2016-17)<br>Goals scored rank: #2<br>Goals conceded rank: #3","<b>Manchester United<\/b> (1993-94)<br>Goals scored rank: #2<br>Goals conceded rank: #4","<b>Arsenal<\/b> (1997-98)<br>Goals scored rank: #3<br>Goals conceded rank: #2","<b>Leicester<\/b> (2015-16)<br>Goals scored rank: #3<br>Goals conceded rank: #3"],"hovertemplate":["%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>","%{text}<extra><\/extra>"],"hoverlabel":{"bgcolor":"#1a1a1a","bordercolor":"rgba(255,255,255,0.15)","font":{"family":"Inter","size":13,"color":"white"},"align":"left"},"showlegend":false,"name":"champion","error_y":{"color":"rgba(31,119,180,1)"},"error_x":{"color":"rgba(31,119,180,1)"},"line":{"color":"rgba(31,119,180,1)"},"xaxis":"x","yaxis":"y","frame":null},{"x":[10,10,10,10,10,10,10,9,9,9,9,8,8],"y":[10,9,8,7,6,4,3,10,9,8,7,9,8],"text":["9","6","1","2","2","1","1","4","2","1","1","1","1"],"type":"scatter","mode":"text","textfont":{"family":"Inter","size":11,"color":"white"},"hoverinfo":["none","none","none","none","none","none","none","none","none","none","none","none","none"],"showlegend":false,"name":"count","marker":{"color":"rgba(255,127,14,1)","line":{"color":"rgba(255,127,14,1)"}},"error_y":{"color":"rgba(255,127,14,1)"},"error_x":{"color":"rgba(255,127,14,1)"},"line":{"color":"rgba(255,127,14,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.20000000000000001,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot","plotly_sunburstclick"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>The pattern is clear: early champions scatter across the space, while recent seasons crowd the top-right corner. The number inside each dot shows how many champions share that exact position — a stack of nine at #1/#1 tells its own story. The feasible region has shrunk.</p>
</section>
</section>
<section id="the-tightening-window" class="level2">
<h2 class="anchored" data-anchor-id="the-tightening-window">The Tightening Window</h2>
<p>The raw numbers suggest attack wins. <strong>15 of 32 champions</strong> ranked higher in attack than defence. Only <strong>5</strong> leaned more heavily on defensive prowess. Case closed?</p>
<p>Not quite. Because the <em>range</em> of acceptable defensive positions has collapsed.</p>
<p>Early Premier League champions could survive with middling defences — <strong>4 titles</strong> went to teams ranked fifth or worse in goals conceded. Ferguson’s United won with an eighth-ranked defence. Blackburn won with the fifth-best. These teams compensated with overwhelming attacking firepower.</p>
<p>That path is now closed. Since 2017, every champion has ranked first or second in defence. No exceptions.</p>
<p>The era of acceptable trade-offs is ending.</p>
<section id="the-ferguson-formula" class="level3">
<h3 class="anchored" data-anchor-id="the-ferguson-formula">The Ferguson Formula</h3>
<p>Sir Alex Ferguson won 13 Premier League titles. Only one saw United finish first in both attack and defence.</p>
<p>This was a feature, not a bug. Ferguson operated in an era when defensive weakness was survivable. In 1996-97, United conceded 44 goals — eighth-best in the league. They won anyway because they scored the most. In 1999-00, United’s defence ranked only seventh; their attack compensated with 97 goals.</p>
<p>Ferguson’s genius was understanding the exchange rate. In his era, one rank in attack was worth roughly two ranks in defence. His teams weren’t imbalanced by accident — they were <em>optimized for their environment</em>.</p>
<p>That environment no longer exists.</p>
</section>
<section id="the-leicester-exception" class="level3">
<h3 class="anchored" data-anchor-id="the-leicester-exception">The Leicester Exception</h3>
<p>Leicester 2015-16: third in attack, third in defence. No elite dimension. Perfect balance.</p>
<p>This title shouldn’t exist by the usual rules. Leicester weren’t the best at anything. But they were the only team that season to be top-three in both metrics. Chelsea imploded. Manchester City couldn’t sustain form. Arsenal faded in March. Every rival had a fatal weakness. Leicester’s balance became, by default, supremacy.</p>
<div class="insight-box">
<p><strong>The Leicester principle:</strong> When no team dominates both ends of the pitch, the most <em>consistent</em> team across both wins.</p>
</div>
</section>
<section id="the-guardiola-reset" class="level3">
<h3 class="anchored" data-anchor-id="the-guardiola-reset">The Guardiola Reset</h3>
<p>Guardiola didn’t optimize within the old constraints. He rewrote them.</p>
<p>Manchester City have won <strong>8 Premier League titles</strong>. In <strong>5 of those seasons</strong>, they finished first in both attack <em>and</em> defence. This isn’t balance — it’s total dominance across every dimension.</p>
<p>The numbers tell the story. 2017-18: 106 goals scored (best), 27 conceded (best). 2018-19: 95 scored (best), 23 conceded (second). 2020-21, 2021-22, 2022-23: first in both, every time.</p>
<p>When one team occupies both poles, the competitive landscape shifts for everyone else. Ferguson’s seventh-ranked defence was viable because no rival combined elite attack <em>and</em> elite defence. Against Guardiola’s City, a fifth-ranked defence means conceding 10-15 more goals per season than the team you’re chasing. Even a brilliant attack can’t close that gap.</p>
</section>
<section id="liverpools-two-routes" class="level3">
<h3 class="anchored" data-anchor-id="liverpools-two-routes">Liverpool’s Two Routes</h3>
<p>Liverpool prove you can reach the summit from different directions — if you stay within the constraint.</p>
<p><strong>2019-20:</strong> First in defence, second in attack. Van Dijk and Alisson anchored the league’s best backline. The attack finished second. Title secured.</p>
<p><strong>2024-25:</strong> First in attack, second in defence. Arne Slot’s side flipped the emphasis. Different ratio, same result.</p>
<p>Both campaigns respected the constraint. Neither defence ranked lower than second. Liverpool didn’t choose attack <em>or</em> defence — they chose attack <em>and</em> defence, with different weightings.</p>
</section>
</section>
<section id="the-process-test" class="level2">
<h2 class="anchored" data-anchor-id="the-process-test">The Process Test</h2>
<p>Goals measure outcomes. Expected Goals (xG) measures process — the quality of chances created and conceded, independent of finishing luck.</p>
<p>The distinction matters. A team can win a title by outperforming their xG — clinical finishing, goalkeeper heroics, fortunate bounces. But that’s not repeatable. The champions who dominate year after year don’t rely on overperformance. They win at the process level.</p>
<div style="overflow-x: auto; margin: 1.5rem 0;">
<table class="athletic-table">
<thead>
<tr>
<th>
Season
</th>
<th>
Champion
</th>
<th class="num">
Goals
</th>
<th class="num">
xG
</th>
<th class="num">
+/-
</th>
<th class="num">
xG Rank
</th>
<th class="num">
GA
</th>
<th class="num">
xGA
</th>
<th class="num">
+/-
</th>
<th class="num">
xGA Rank
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
2017-18
</td>
<td>
Manchester City
</td>
<td class="num">
103
</td>
<td class="num">
78.6
</td>
<td class="num positive">
+24.4
</td>
<td class="num">
#1
</td>
<td class="num">
25
</td>
<td class="num">
23.8
</td>
<td class="num negative">
+1.2
</td>
<td class="num">
#1
</td>
</tr>
<tr>
<td>
2018-19
</td>
<td>
Manchester City
</td>
<td class="num">
91
</td>
<td class="num">
84.3
</td>
<td class="num positive">
+6.7
</td>
<td class="num">
#1
</td>
<td class="num">
23
</td>
<td class="num">
24.7
</td>
<td class="num positive">
-1.7
</td>
<td class="num">
#1
</td>
</tr>
<tr>
<td>
2019-20
</td>
<td>
Liverpool
</td>
<td class="num">
83
</td>
<td class="num">
68.9
</td>
<td class="num positive">
+14.1
</td>
<td class="num">
#3
</td>
<td class="num">
32
</td>
<td class="num">
37.7
</td>
<td class="num positive">
-5.7
</td>
<td class="num">
#2
</td>
</tr>
<tr>
<td>
2020-21
</td>
<td>
Manchester City
</td>
<td class="num">
82
</td>
<td class="num">
68.2
</td>
<td class="num positive">
+13.8
</td>
<td class="num">
#1
</td>
<td class="num">
31
</td>
<td class="num">
30.2
</td>
<td class="num negative">
+0.8
</td>
<td class="num">
#1
</td>
</tr>
<tr>
<td>
2021-22
</td>
<td>
Manchester City
</td>
<td class="num">
96
</td>
<td class="num">
88.7
</td>
<td class="num positive">
+7.3
</td>
<td class="num">
#1
</td>
<td class="num">
26
</td>
<td class="num">
24.6
</td>
<td class="num negative">
+1.4
</td>
<td class="num">
#1
</td>
</tr>
<tr>
<td>
2022-23
</td>
<td>
Manchester City
</td>
<td class="num">
92
</td>
<td class="num">
78.7
</td>
<td class="num positive">
+13.3
</td>
<td class="num">
#1
</td>
<td class="num">
32
</td>
<td class="num">
32.1
</td>
<td class="num positive">
-0.1
</td>
<td class="num">
#1
</td>
</tr>
<tr>
<td>
2023-24
</td>
<td>
Manchester City
</td>
<td class="num">
94
</td>
<td class="num">
80.5
</td>
<td class="num positive">
+13.5
</td>
<td class="num">
#2
</td>
<td class="num">
33
</td>
<td class="num">
35.6
</td>
<td class="num positive">
-2.6
</td>
<td class="num">
#2
</td>
</tr>
</tbody>
</table>
</div>
<section id="what-xg-confirms" class="level3">
<h3 class="anchored" data-anchor-id="what-xg-confirms">What xG Confirms</h3>
<p><strong>5 of 7 recent champions</strong> ranked first in xG — best chances created. <strong>5</strong> ranked first in both xG and xGA. These titles weren’t stolen through finishing luck. They were earned at the process level.</p>
<p>Manchester City’s xG dominance is structural. Season after season: first in xG, first in xGA. They don’t just score more — they create better chances. They don’t just concede fewer — they allow worse chances. The outcome and the process align.</p>
<p>Liverpool 2019-20 is the exception that tests the rule. Klopp’s side ranked only <strong>third</strong> in xG — not the best chances created. But they ranked first in xGA (fewest quality chances conceded) and overperformed their expected goals by a significant margin. The title was real; the process was less dominant. Liverpool couldn’t replicate it the following season.</p>
<p><em>Note: 2024-25 xG data will be added when the season’s FBref data is fully released.</em></p>
</section>
</section>
<section id="the-answer" class="level2">
<h2 class="anchored" data-anchor-id="the-answer">The Answer</h2>
<p>The question was never attack <em>or</em> defence.</p>
<p>It was: <strong>how much defensive weakness can your attack compensate for?</strong></p>
<p>In 1997, the answer was: quite a lot. Ferguson’s United won with an eighth-ranked defence. Today, the answer is: almost none. Since 2017, no champion has ranked worse than second in defence.</p>
<p>The data reveals not a fixed rule, but a <em>shrinking window</em>. Attack still wins titles — 47% of champions ranked higher in attack than defence. But the minimum defensive threshold has risen dramatically. What was once a wide corridor has become a narrow path.</p>
<div class="pullquote">
<p>In the Ferguson era, attack was the multiplier. In the Guardiola era, defence became the filter.</p>
</div>
<p>This explains everything:</p>
<p><strong>Ferguson’s United</strong> exploited a lenient era. Elite attack, acceptable defence. The exchange rate favoured goalscorers.</p>
<p><strong>Leicester 2015-16</strong> found a window between eras. Third in both metrics — balance as a survival strategy when no rival dominated both ends.</p>
<p><strong>Guardiola’s City</strong> closed the window entirely. By setting the standard in both attack <em>and</em> defence, they forced every competitor to match both or fall short.</p>
<p><strong>28% of Premier League champions</strong> have finished first in both attack and defence. That percentage has accelerated in the modern era. The old trade-off is obsolete.</p>
<p>The teams that win now don’t ask whether to prioritize attack or defence. They refuse the question. They dominate both — because against City, that’s the only math that works.</p>
<hr>
<div class="article-footer">
<p><strong>Data sources:</strong> Goals data from <a href="https://www.football-data.co.uk/">football-data.co.uk</a> (1992-93 to 2024-25). xG data from <a href="https://fbref.com/">FBref</a> via the worldfootballR package (2017-18 to 2023-24).</p>
<p><strong>Methodology:</strong> Teams ranked 1-20 each season by goals scored (attack) and goals conceded (defence). Rank 1 = best. “Balanced” champions achieved identical ranks in both metrics.</p>
</div>


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>football</category>
  <category>data visualization</category>
  <category>Premier League</category>
  <category>analytics</category>
  <guid>https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/pl-champions/</guid>
  <pubDate>Mon, 17 Mar 2025 03:00:00 GMT</pubDate>
  <media:content url="https://jafranceschini.quarto.pub/juan-franceschini-lab/posts/post-with-code/pl-champions/pl-champions-cover.svg" medium="image" type="image/svg+xml"/>
</item>
</channel>
</rss>
