<?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>Andreas Varotsis</title>
<link>https://andreasthinks.me/</link>
<atom:link href="https://andreasthinks.me/index.xml" rel="self" type="application/rss+xml"/>
<description>Personal website for Andreas Varotsis</description>
<generator>quarto-1.9.38</generator>
<lastBuildDate>Thu, 07 May 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>When fewer commits don’t mean less work</title>
  <link>https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/</link>
  <description><![CDATA[ 





<p>I have been vibe coding <em>a lot</em>. Like, <em>a lot</em> a lot…. and it’s been leaving me feeling a bit conflicted. I’ve been committing hard, and feeling tremendously productive. But I also get this weird flash of existential dread when I catch myself furiously hitting AGAIN AGAIN AGAIN like I’m 3 Mai Tais deep at a Vegas slot machine, until I suddenly find myself staring at a codebase I’ve never seen, like some groggy father waking up from a thirty year coma to kids he barely recognises.</p>
<p>I feel like a goddamn engineering hero. But am I?</p>
<p>The research has left me confused, and a teeny bit sceptical. The big daddy of AI coding research, <a href="https://metr.org/blog/2025-07-10-early-2025-ai-experienced-os-dev-study/">METR</a> found that AI tools can slow experienced developers down on mature codebases… but those are experienced programmers working on codebases they know, which is obviously nothing like me. Then <a href="https://www.answer.ai/posts/2026-03-12-so-where-are-all-the-ai-apps.html">Answer.AI published their analysis</a>, showing that despite all the excitement, PyPI productivity really did not seem to be shifting much… and that one threw me for a spin. I am coding more. I am releasing more stuff. So what the hell is going on?</p>
<p>So I thought I’d check the obvious source of truth on what we are all actually doing: GitHub. I scraped an awful lot of code, and looked for how people who use AI coding tools differ.</p>
<p>Here’s my working theory: AI really is making me commit hard. In fact, it has me committing furiously, more frequently, and in tighter bursts. But that does not necessarily mean I am producing more. It may mean AI is changing <em>how</em> I work, in a way that is extremely seductive. It is a a sneaky little trap, and I worry I’ve fallen head first into it.</p>
<p>So I tried to figure out what makes coders who use AI different. Do they code longer? Do they commit more? Do they work in tighter bursts?</p>
<p>It turns out the pattern is not just “more commits” or “less commits”. It is a rhythm change. AI adopters move toward more concentrated coding sessions: more commits per active week, shorter gaps between commits, but fewer active weeks overall.</p>
<div class="dark-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/account_behaviour_shift_dark.png" class="img-fluid figure-img"></p>
<figcaption>Account-level before/after behaviour. Points show group means; whiskers show bootstrapped 95% confidence intervals over accounts.</figcaption>
</figure>
</div>
</div>
<div class="light-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/account_behaviour_shift_light.png" class="img-fluid figure-img"></p>
<figcaption>Account-level before/after behaviour. Points show group means; whiskers show bootstrapped 95% confidence intervals over accounts.</figcaption>
</figure>
</div>
</div>
<p>I don’t think this means we are automatically more productive. I think we are working differently, and that difference is tricking our brains.</p>
<section id="picking-out-the-vibe-coders" class="level2">
<h2 class="anchored" data-anchor-id="picking-out-the-vibe-coders">Picking out the vibe coders</h2>
<p>To study this at scale, I built a classifier that assigns each GitHub account a rough probability of AI coding-tool adoption from public behavioural signals.</p>
<p>The training sample is 276 GitHub accounts: 74 confirmed AI adopters, identified through <code>CLAUDE.md</code> files or <code>Co-Authored-By: Claude</code> trailers, and 202 controls with active commit histories before and after late 2023 and no AI markers. The classifier uses 43 behavioural features: commit cadence, message length and structure, PR body patterns, and inter-commit timing. It explicitly excludes the labelling artefacts themselves.</p>
<p>The random forest model I ended up with correctly identifies the right outcome around 94% of the time. Remove all markers from the content (so it’s working purely from patterns of activity) and it still gets it right about 91% of the time.</p>
<p>Thankfully, Claude Code is not the only tool that leaves obvious traces. Aider does too. When I run the classifier on Aider users, a tool it was never trained on, it flags them as AI-tool users 73% of the time, compared to just 3% for people not using any AI coding tools.</p>
<p>So whatever the classifier is detecting, it is not just Claude-specific style. It looks like a broader “this developer’s behaviour looks AI-assisted” signal.</p>
<p>If you want the methodology in detail, <a href="../../papers/ai-productivity/">the paper is here</a>. For this post, the key point is simpler: I can assign an approximate AI-adoption score to public GitHub accounts, then ask whether higher adoption lines up with different activity metrics.</p>
</section>
<section id="so-what-about-countries" class="level2">
<h2 class="anchored" data-anchor-id="so-what-about-countries">So what about countries?</h2>
<p>So, we know at an individual level that AI users seem to work differently. But what about entire countries? If all of China has indeed gone OpenClaw-crazy, are they pushing endless agentic products? I was hoping this might give me a signal about what was going on.</p>
<p>It turns out it is just as puzzling.</p>
<p>With per-account AI scores in hand, I aggregated them by country. Take the 4,824 scored accounts, group them by country, and use the mean classifier score as a country-level AI adoption measure.</p>
<p>This is the weaker part of the analysis, and I want to be upfront about that. Country-level GitHub Archive data is noisy. The 2024 cross-section is thin. The adoption measure inherits whatever biases the classifier has. So I do <strong>not</strong> read this as clean evidence that AI adoption causes country-level productivity changes.</p>
<p>I read it as a warning sign about measurement.</p>
<p>For the dependent variables, I used a GitHub Archive panel from 2022 to 2024 with two common activity measures: commits per active developer and pull requests per active developer. If both were clean productivity metrics, you would expect them to broadly tell the same story.</p>
<p>They do not.</p>
<div class="dark-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/dv_split_dark.png" class="img-fluid figure-img"></p>
<figcaption>2024 country-level cross-section. Each circle is a country, sized by number of developers in the GH Archive panel. Lines are unweighted OLS fits. Treat this as an illustrative aggregate puzzle, not clean causal evidence.</figcaption>
</figure>
</div>
</div>
<div class="light-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/dv_split_light.png" class="img-fluid figure-img"></p>
<figcaption>2024 country-level cross-section. Each circle is a country, sized by number of developers in the GH Archive panel. Lines are unweighted OLS fits. Treat this as an illustrative aggregate puzzle, not clean causal evidence.</figcaption>
</figure>
</div>
</div>
<p>On the left: commits per developer in 2024, plotted against the country’s mean classifier-derived AI adoption score. Higher adoption, lower commits. The slope tilts down.</p>
<p>On the right: pull requests per developer, same countries, same year, same adoption measure. The slope is slightly positive and statistically indistinguishable from zero.</p>
<p>Same countries. Same year. Same adoption measure. Different activity metric, different story.</p>
<p>That is the point. I do not think the country result is strong enough to carry a claim about national productivity. But it is exactly what you would expect to see if commit counts are partly measuring workflow granularity rather than output.</p>
<div class="dark-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/coefficient_plot_dark.png" class="img-fluid figure-img"></p>
<figcaption>Coefficient on the country-level AI adoption rate across illustrative specifications. Whiskers are ±1 standard error. Commits estimates cluster on the negative side; PR estimates straddle zero.</figcaption>
</figure>
</div>
</div>
<div class="light-fig">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/figures/coefficient_plot_light.png" class="img-fluid figure-img"></p>
<figcaption>Coefficient on the country-level AI adoption rate across illustrative specifications. Whiskers are ±1 standard error. Commits estimates cluster on the negative side; PR estimates straddle zero.</figcaption>
</figure>
</div>
</div>
</section>
<section id="the-pr-plot-twist" class="level2">
<h2 class="anchored" data-anchor-id="the-pr-plot-twist">The PR plot twist</h2>
<p>So here is the bit that made me sit up.</p>
<p>The commit stuff measures <em>workflow tempo</em>: how often you hit save, how long you wait between commits, how chatty your messages are. That is interesting, but it is not the same as <em>shipping work</em>. To check that, I collected authored pull requests for the full classifier cohort and re-ran the before/after comparison using PR-specific outcomes.</p>
<p><strong>Coverage.</strong> Of 276 accounts (74 treated, 202 controls), 275 had retrievable PR data. The treated group is more PR-active overall: 58 of 73 had at least one authored PR, versus 160 of 202 controls. But 15 treated accounts had zero PRs, and 13 hit the 300-PR retrieval cap. So the picture is mixed.</p>
<p><strong>The volume story is strong.</strong> Confirmed adopters open +46.4 more PRs post-adoption and merge +42.6 more. On a per-month basis, that is +1.64 opened and +1.51 merged. All four numbers are significant at p &lt; 0.001 and survive FDR correction across ten PR outcome tests. The effect also survives dropping capped accounts, dropping zero-PR accounts, and restricting to the highest-confidence adopters.</p>
<p><strong>The rate story is messier.</strong> Merge rate rises by about 0.16 (p = 0.004), and median hours-to-merge falls by roughly 18.5 hours (p = 0.034). But when I restrict to accounts with PRs in both windows, the merge-rate effect collapses to basically nothing (+0.03, p = 0.39) while the volume effects stay significant.</p>
<p>What is happening? When an account had zero PRs in the pre-period, merge rate and merge time are mechanically set to zero. That artificially inflates the post-period gain. So I treat PR volume as the primary signal and merge rate as secondary, at best.</p>
<p><strong>What this means for the puzzle.</strong> The country-level panel found PRs per developer effectively flat. The account-level extension finds confirmed adopters opening and merging substantially more PRs. The apparent contradiction is not a contradiction. It is a <strong>scale mismatch</strong>.</p>
<p>At the country level, the treatment is a small adoption share diluted across every developer in the country. At the account level, the treatment is confirmed adoption compared with confirmed non-adoption. A +46 PR effect among 10-15% of developers is invisible when averaged across the other 85-90%. The country panel tells us aggregate PR rates do not rise with aggregate adoption. The account panel tells us the adopters themselves are shipping more packaged work. Both are true once you distinguish <em>average effects</em> from <em>average treatment effects on the treated</em>.</p>
</section>
<section id="so-does-any-of-this-make-sense" class="level2">
<h2 class="anchored" data-anchor-id="so-does-any-of-this-make-sense">So, does any of this make sense?</h2>
<p>So, you’re confused. I am too. But I think I can make some educated guesses about what is going on here.</p>
<section id="ai-tooling-changes-how-you-work-and-probably-how-much-you-ship-too" class="level3">
<h3 class="anchored" data-anchor-id="ai-tooling-changes-how-you-work-and-probably-how-much-you-ship-too">AI tooling changes how you work, and probably how much you ship too</h3>
<p>The PR outcome analysis complicates the story in a useful way. Commit counts may be a bad proxy for productivity, but the adopters themselves are opening and merging substantially more pull requests. That is not a workflow artefact. That is accepted packaged work.</p>
<p>The question is not whether AI tools increase output. At the individual level, the evidence points toward more shipped work. The question is whether our old metrics can see it, and whether aggregate data can pick up a concentrated effect among a small treated share.</p>
<p>This might just be because we are looking at individuals. Maybe the truly transformative agentic organisation is already happening somewhere else, higher up the stack, in workflows that GitHub commits will never capture properly.</p>
<p>But beware the siren temptress of Claude Code YOLO. No matter her dulcet singing tones, you are not necessarily the hot-shit programmer she is making you out to be.</p>
<p>The behavioural evidence says something subtler: AI users work in a different rhythm. More concentrated bursts. Shorter gaps between commits. Fewer active weeks. That can feel like momentum, and maybe sometimes it is. But it can also make the old metrics lie.</p>
</section>
<section id="agentic-coders-really-are-built-different" class="level3">
<h3 class="anchored" data-anchor-id="agentic-coders-really-are-built-different">Agentic coders really are built different</h3>
<p>The classifier may be picking up something other than AI adoption. A pre-period placebo test on the training data showed that 6 of 8 features differ significantly between confirmed AI adopters and controls <em>before</em> AI tools existed in their current form. The classifier captures some combination of “uses AI tools” and “is the sort of person who does vibe coding”.</p>
<p>I think these might just be very different populations.</p>
<p>Some developers might commit less frequently per unit of work for reasons that have nothing to do with AI. Some may be more delib…</p>
</section>
</section>
<section id="so-here-we-are." class="level2">
<h2 class="anchored" data-anchor-id="so-here-we-are.">So, here we are.</h2>
<p>I should add: there is <em>loads</em> of stuff I am not sure of. This is a noisy, self-selective, observational analysis. The data is far from ideal, and generalising from Claude Code to Aider may tell me diddly squat about agentic coding more broadly. But I kind of think it does tell us something.</p>
<p>Claude Code might be making us feel like heroes. I am not actually sure that it is making individual programmers push out features any faster. It sure feels like it though, and that is one damn appealing trap to fall into.</p>
<p>The PR evidence shifts the picture: AI adopters are shipping more accepted packaged work, even if commit counts are a lousy way to measure it. More controlled experiments on CI success, issue resolution, and feature ship time would still be valuable, but the observational signal is stronger than the commit data alone suggested.</p>
<hr>
<p><em>If you have seen this commits/PRs split in your own data, I would like to compare notes. The repo for the analysis is <a href="https://github.com/AndreasThinks/ai-productivity-analysis">here on GitHub</a>, and the formal paper version lives <a href="../../papers/ai-productivity/">over here</a>.</em></p>
<p><em>An awful lot of the analysis for this work was done by my <a href="https://hermes-agent.nousresearch.com/">Hermes Agent</a>. I’m mostly confident, but also, if I’ve cocked it up, I’m very sorry.</em></p>


</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>AI</category>
  <category>research</category>
  <category>data-science</category>
  <guid>https://andreasthinks.me/posts/ai-tools-and-the-shape-of-commits/</guid>
  <pubDate>Thu, 07 May 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>UK Police Salary Explorer</title>
  <link>https://andreasthinks.me/posts/police-salary-explorer/</link>
  <description><![CDATA[ 





<style>
/* Theme-aware chart colours */
.police-chart {
  color: inherit;
}
.police-chart svg {
  background: transparent !important;
}
[data-theme="dark"] .police-chart {
  color: #f4f7ff;
}
[data-theme="light"] .police-chart {
  color: #0b1220;
}
</style>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="33" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 32;"><span id="cb1-33">viewof selectedRanks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb1-34">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC National"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC Metropolitan"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sergeant"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inspector"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Superintendent"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-35">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ranks"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC National"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sergeant"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inspector"</span>]}</span>
<span id="cb1-36">)</span>
<span id="cb1-37"></span>
<span id="cb1-38">viewof payPoint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">radio</span>(</span>
<span id="cb1-39">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Starting salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Top of scale"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Both"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-40">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pay point"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Starting salary"</span>}</span>
<span id="cb1-41">)</span>
<span id="cb1-42"></span>
<span id="cb1-43">viewof realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toggle</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Real terms (2025 £)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>})</span>
<span id="cb1-44"></span>
<span id="cb1-45">viewof indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">radio</span>(</span>
<span id="cb1-46">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage multiple"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-47">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Index by"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span>}</span>
<span id="cb1-48">)</span>
<span id="cb1-49"></span>
<span id="cb1-50">viewof showBenchmarks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toggle</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Show benchmark lines (min wage &amp; median wage)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>})</span>
<span id="cb1-51"></span>
<span id="cb1-52">viewof showTable <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toggle</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Show data table"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="56" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 55;"><span id="cb2-56">raw <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">FileAttachment</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"police_salary_ranks.csv"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">csv</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">typed</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>})</span>
<span id="cb2-57"></span>
<span id="cb2-58">rankMap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>([</span>
<span id="cb2-59">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC National"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">code</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC (National)"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-60">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC Metropolitan"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">code</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Met_PC"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PC (Metropolitan)"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-61">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sergeant"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">code</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sgt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sergeant"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-62">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inspector"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">code</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Insp"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inspector"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-63">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Superintendent"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">code</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Supt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Superintendent"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-64">])</span>
<span id="cb2-65"></span>
<span id="cb2-66">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-67">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-68">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> raw) {</span>
<span id="cb2-69">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-70">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> minWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-71">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> medianWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-72">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sel <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> selectedRanks) {</span>
<span id="cb2-73">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> info <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rankMap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(sel)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-74">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (payPoint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Starting salary"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> payPoint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Both"</span>) {</span>
<span id="cb2-75">        <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">code</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Start_Real2025"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">code</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Start_Nominal"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-76">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> minWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-77">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> medianWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-78">        rows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb2-79">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> year<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-80">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Rank</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-81">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Point</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-82">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> val</span>
<span id="cb2-83">        })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-84">      }</span>
<span id="cb2-85">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (payPoint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Top of scale"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> payPoint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Both"</span>) {</span>
<span id="cb2-86">        <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">code</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Top_Real2025"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">code</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Top_Nominal"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-87">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> minWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-88">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> medianWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-89">        rows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb2-90">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> year<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-91">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Rank</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> info<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-92">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Point</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Top"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-93">          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> val</span>
<span id="cb2-94">        })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-95">      }</span>
<span id="cb2-96">    }</span>
<span id="cb2-97">  }</span>
<span id="cb2-98">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> rows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-99">}</span>
<span id="cb2-100"></span>
<span id="cb2-101">minWageLine <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-102">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> minWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-103">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> medianWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-104">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> minWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-105">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span>) val <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-106">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> minWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> medianWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-107">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> val }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-108">})</span>
<span id="cb2-109"></span>
<span id="cb2-110">medianLine <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-111">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> minWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-112">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> medianWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-113">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> medianWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-114">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span>) val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> medianWage <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> minWage<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-115">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage multiple"</span>) val <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-116">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> val }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-117">})</span>
<span id="cb2-118"></span>
<span id="cb2-119">yLabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> (realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary (2025 £)"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary (nominal £)"</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb2-120">         indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimum wage multiple"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple of minimum wage"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb2-121">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple of median wage"</span></span>
<span id="cb2-122"></span>
<span id="cb2-123">tickFormat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~s"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".2f"</span></span>
<span id="cb2-124"></span>
<span id="cb2-125">chart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb2-126">  width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-127">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-128">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-129">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">background</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"transparent"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-130">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"currentColor"</span></span>
<span id="cb2-131">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-132">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> yLabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> tickFormat}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-133">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-134">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-135">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb2-136">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-137">    showBenchmarks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(minWageLine<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-138">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-139">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-140">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ff6b6b"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-141">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-142">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4,4"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-143">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tip</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-144">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Min wage: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span> <span class="op" 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="op" 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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb2-145">    }) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-146">    showBenchmarks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>([minWageLine[minWageLine<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-147">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-148">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-149">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Min wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-150">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-151">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ff6b6b"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-152">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-153">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span></span>
<span id="cb2-154">    }) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-155">    showBenchmarks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(medianLine<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-156">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-157">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-158">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#00d4ff"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-159">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-160">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4,4"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-161">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tip</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-162">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Median wage: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(indexBy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Absolute salary"</span> <span class="op" 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="op" 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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb2-163">    }) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-164">    showBenchmarks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>([medianLine[medianLine<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-165">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-166">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-167">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-168">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-169">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#00d4ff"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-170">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-171">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span></span>
<span id="cb2-172">    }) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-173">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-174">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-175">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-176">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rank"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-177">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-178">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tip</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb2-179">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-180">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-181">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-182">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-183">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rank"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-184">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rank"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-185">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-186">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tip</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb2-187">    })</span>
<span id="cb2-188">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Boolean</span>)</span>
<span id="cb2-189">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-8" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="193" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 192;"><span id="cb3-193">tableData <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb3-194">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> benchMap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-195">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> raw) {</span>
<span id="cb3-196">    benchMap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-197">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Min wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MinWage_Annual_Nominal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-198">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> realTerms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Real2025</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median_FT_Annual_Nominal</span></span>
<span id="cb3-199">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-200">  }</span>
<span id="cb3-201">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(row <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-202">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> bench <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> benchMap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-203">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb3-204">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-205">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Rank</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Rank</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-206">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Point</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Point</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-207">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Salary</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-208">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Min wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> bench[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Min wage"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-209">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> bench[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage"</span>]</span>
<span id="cb3-210">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-211">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-212">}</span>
<span id="cb3-213"></span>
<span id="cb3-214">table <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> showTable <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(tableData<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">columns</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rank"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Point"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Min wage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median wage"</span>]}) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;p style="color:#888;font-style:italic;"&gt;Toggle "Show data table" to inspect values.&lt;/p&gt;`</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-2" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<p>This interactive tool tracks starting and top-of-scale salaries across UK police ranks from 1999 to 2025, with figures shown in both nominal pounds and real terms (adjusted to 2025 GBP using CPI) <span class="citation" data-cites="onscpi">(Office for National Statistics 2025)</span>.</p>
<p>The data reveals a sharp real-terms decline for new constables following the 2013 Winsor reforms <span class="citation" data-cites="govukwinsor bbc2013">(Home Office 2013; BBC News 2013)</span>, and a broader stagnation across all ranks during the 2010–2020 austerity period <span class="citation" data-cites="smf2024">(Social Market Foundation 2024)</span>. Recent large pay awards (2022–2025) have begun to reverse some of this erosion <span class="citation" data-cites="prrb2024 prrb2025">(PRRB 2024, 2025)</span>.</p>
<p>Use the controls to toggle ranks, switch between starting and top-of-scale pay, compare nominal versus real-terms values, and index salaries against minimum wage or median full-time earnings. Toggle <strong>“Show benchmark lines”</strong> to overlay the minimum wage and median wage on the chart — this works in all three index modes, including when salaries are themselves expressed as a multiple.</p>
<section id="minimum-wage-and-median-earnings-comparison" class="level2">
<h2 class="anchored" data-anchor-id="minimum-wage-and-median-earnings-comparison">Minimum wage and median earnings comparison</h2>
<p>Two useful benchmarks for police starting salaries are the UK minimum wage (now National Living Wage) and median full-time earnings, both expressed as full-time annual equivalents.</p>
<p><strong>Minimum wage:</strong> In 2000, a new PC earned roughly <strong>2.4× the minimum wage</strong>. By 2013, after the Winsor cut, this had fallen to <strong>1.5×</strong>. In 2025, it has recovered to approximately <strong>1.3×</strong> for post-2013 entrants. The Metropolitan Police premium has historically kept Met PCs at roughly <strong>1.8–2.1×</strong> the minimum wage.</p>
<p><strong>Median full-time earnings:</strong> In 2000, a new PC earned roughly <strong>0.92× median full-time earnings</strong> — slightly below the UK median. By 2013, this had fallen to <strong>0.71×</strong>. In 2025, a post-2013 PC starter earns approximately <strong>0.78×</strong> median earnings, while a Metropolitan PC earns roughly <strong>1.10×</strong>.</p>
<p>These ratios matter because they show whether policing remains an economically attractive career relative to both the legal floor and the typical middle-income job. The data suggests policing has slipped from a solidly middle-income profession to one that now sits closer to the median, with significant variation by force.</p>
<p>Source: ONS ASHE median gross weekly earnings for full-time employees <span class="citation" data-cites="onscpi">(Office for National Statistics 2025)</span>.</p>
</section>
<section id="key-findings" class="level2">
<h2 class="anchored" data-anchor-id="key-findings">Key findings</h2>
<section id="the-2013-winsor-cut" class="level3">
<h3 class="anchored" data-anchor-id="the-2013-winsor-cut">The 2013 Winsor cut</h3>
<p>In 2013, the starting salary for new constables was cut from ~£23,000 to £19,000 as part of the Winsor reforms <span class="citation" data-cites="govukwinsor bbc2013">(Home Office 2013; BBC News 2013)</span>. This created a two-tier system: officers who joined before April 2013 remained on the legacy scale, while new entrants started lower and progressed more slowly <span class="citation" data-cites="winsortable">(Home Office 2015)</span>.</p>
<p>The chart shows this as a sharp discontinuity for PC (National) in 2013. Metropolitan Police starters were less affected due to the London premium <span class="citation" data-cites="metfriendly2019">(Metfriendly 2019)</span>.</p>
</section>
<section id="real-terms-decline" class="level3">
<h3 class="anchored" data-anchor-id="real-terms-decline">Real-terms decline</h3>
<p>A constable starting in 2000 on £17,133 would need roughly £40,000 in 2025 to have equivalent purchasing power <span class="citation" data-cites="hansard2000">(UK Parliament 2000)</span>. The actual 2025 starting salary for post-2013 entrants is £31,164, a real-terms cut of roughly 22% versus 2000 <span class="citation" data-cites="polfedconstable points2prove2025">(Police Federation of England and Wales 2025a; Points2Prove 2025)</span>. Even the pre-2013 scale (£32,820 in 2025) barely matches the inflation-adjusted 2000 starter.</p>
<p>This pattern repeats across ranks. Sergeant, Inspector, and Superintendent starting salaries all stagnated in real terms between 2010 and 2020 before recovering partially in 2022–2025 <span class="citation" data-cites="prrb2024 prrb2025">(PRRB 2024, 2025)</span>.</p>
</section>
<section id="rank-progression" class="level3">
<h3 class="anchored" data-anchor-id="rank-progression">Rank progression</h3>
<p>The data also reveals how the gap between ranks has changed over time:</p>
<ul>
<li><strong>Sergeant</strong> entry pay has roughly doubled in nominal terms since 2000 (£26,200 to £53,600) <span class="citation" data-cites="hansard2000 polfedsergeant">(UK Parliament 2000; Police Federation of England and Wales 2025c)</span>.</li>
<li><strong>Inspector</strong> entry pay has risen from ~£33,800 (2000) to £63,800 (2025) <span class="citation" data-cites="hansard2000 polfedinspector">(UK Parliament 2000; Police Federation of England and Wales 2025b)</span>.</li>
<li><strong>Superintendent</strong> entry pay has risen from ~£46,000 (2000) to £84,200 (2025) <span class="citation" data-cites="hansard2000 winsortable points2prove2025">(UK Parliament 2000; Home Office 2015; Points2Prove 2025)</span>.</li>
</ul>
<p>In real terms, all ranks experienced decline or stagnation between 2010 and 2020, followed by partial recovery.</p>
</section>
<section id="metropolitan-police-premium" class="level3">
<h3 class="anchored" data-anchor-id="metropolitan-police-premium">Metropolitan Police premium</h3>
<p>The Metropolitan Police has historically paid a significant London premium. In 2005, the Met starter package (~£28,400) was ~44% above the national PC starter (£19,800). In 2024, the Met advertises £42,210, roughly 41% above the national post-2013 starter (£29,907) <span class="citation" data-cites="metfriendly2019 prrb2024">(Metfriendly 2019; PRRB 2024)</span>.</p>
</section>
</section>
<section id="about-this-data" class="level2">
<h2 class="anchored" data-anchor-id="about-this-data">About this data</h2>
<section id="methodology" class="level3">
<h3 class="anchored" data-anchor-id="methodology">Methodology</h3>
<ul>
<li><strong>PC (National &amp; Metropolitan)</strong> data is year-by-year from official sources.</li>
<li><strong>Sergeant, Inspector, and Superintendent</strong> data uses known anchor points with linear interpolation for intervening years.</li>
<li><strong>Minimum wage</strong> data uses the adult National Minimum Wage / National Living Wage rate, expressed as a full-time annual equivalent.</li>
<li><strong>Real-terms figures</strong> adjust nominal salaries to 2025 GBP using UK CPI (2015 = 100) <span class="citation" data-cites="onscpi">(Office for National Statistics 2025)</span>.</li>
<li><strong>Metropolitan Police</strong> starting salaries include London Weighting and London Allowances.</li>
</ul>
</section>
<section id="data-quality" class="level3">
<h3 class="anchored" data-anchor-id="data-quality">Data quality</h3>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Rank / Period</th>
<th style="text-align: left;">Confidence</th>
<th style="text-align: left;">Notes</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">PC National 1999–2025</td>
<td style="text-align: left;"><strong>High</strong></td>
<td style="text-align: left;">Multiple verified year-by-year sources</td>
</tr>
<tr class="even">
<td style="text-align: left;">PC Metropolitan 1999–2025</td>
<td style="text-align: left;"><strong>High</strong></td>
<td style="text-align: left;">Met Police careers + Metfriendly</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Minimum Wage 1999–2025</td>
<td style="text-align: left;"><strong>High</strong></td>
<td style="text-align: left;">GOV.UK historical rates</td>
</tr>
<tr class="even">
<td style="text-align: left;">Sergeant, Inspector, Superintendent at 2000</td>
<td style="text-align: left;"><strong>High</strong></td>
<td style="text-align: left;">Direct from Hansard <span class="citation" data-cites="hansard2000">(UK Parliament 2000)</span></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Sergeant, Inspector, Superintendent at 2024–2025</td>
<td style="text-align: left;"><strong>High</strong></td>
<td style="text-align: left;">Police Federation / Points2Prove</td>
</tr>
<tr class="even">
<td style="text-align: left;">Sergeant, Inspector 2001–2023</td>
<td style="text-align: left;"><strong>Medium</strong></td>
<td style="text-align: left;">Linear interpolation between anchors</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Superintendent 2001–2013, 2015–2023</td>
<td style="text-align: left;"><strong>Medium</strong></td>
<td style="text-align: left;">Linear interpolation; 2014 Winsor restructuring captured <span class="citation" data-cites="winsortable">(Home Office 2015)</span></td>
</tr>
</tbody>
</table>
<p>Interpolated years assume constant annual change between known anchor points. This smooths out actual year-to-year variations (e.g., the 2010–2012 pay freeze, sporadic awards in 2018–2021) but preserves the overall trajectory.</p>
</section>
<section id="sources" class="level3">
<h3 class="anchored" data-anchor-id="sources">Sources</h3>
<p>The complete list of sources, URLs, and confidence levels is documented in <a href="https://github.com/AndreasThinks/AndreasThinks.me/blob/main/posts/police-salary-explorer/SOURCES.md">SOURCES.md</a>.</p>
</section>
</section>
<section id="references" class="level2">




</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 class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-bbc2013" class="csl-entry">
BBC News. 2013. <em>Police Pay to Start <span>£</span>4,000 Lower, at <span>£</span>19,000</em>. <a href="https://www.bbc.com/news/uk-21027176">https://www.bbc.com/news/uk-21027176</a>.
</div>
<div id="ref-govukwinsor" class="csl-entry">
Home Office. 2013. <em>Police Pay: <span>Winsor</span> Review</em>. <a href="https://www.gov.uk/guidance/police-pay-winsor-review">https://www.gov.uk/guidance/police-pay-winsor-review</a>.
</div>
<div id="ref-winsortable" class="csl-entry">
Home Office. 2015. <em>Independent Review of Police Officer and Staff Remuneration – Table of Progress</em>. <a href="https://assets.publishing.service.gov.uk/media/5a804697ed915d74e622d821/2015_03_26_-_Winsor_-_Table_of_progress.pdf">https://assets.publishing.service.gov.uk/media/5a804697ed915d74e622d821/2015_03_26_-_Winsor_-_Table_of_progress.pdf</a>.
</div>
<div id="ref-metfriendly2019" class="csl-entry">
Metfriendly. 2019. <em>Metfriendly Police Pay Scales 2019/20</em>. <a href="https://cdn2.hubspot.net/hubfs/3349735/Metfriendly%20Police%20Pay%20Scales%202019%202020.pdf">https://cdn2.hubspot.net/hubfs/3349735/Metfriendly%20Police%20Pay%20Scales%202019%202020.pdf</a>.
</div>
<div id="ref-onscpi" class="csl-entry">
Office for National Statistics. 2025. <em>Consumer Price Inflation, <span>UK</span>: <span>January</span> 2025</em>. <a href="https://www.ons.gov.uk/economy/inflationandpriceindices">https://www.ons.gov.uk/economy/inflationandpriceindices</a>.
</div>
<div id="ref-points2prove2025" class="csl-entry">
Points2Prove. 2025. <em>Police Pay Points Guide (2025/26)</em>. <a href="https://points2prove.co.uk/guidance/police-pay-points">https://points2prove.co.uk/guidance/police-pay-points</a>.
</div>
<div id="ref-polfedconstable" class="csl-entry">
Police Federation of England and Wales. 2025a. <em>Constable Pay Scales</em>. <a href="https://polfed.org/resources/pay-scales/constable-pay-scales/">https://polfed.org/resources/pay-scales/constable-pay-scales/</a>.
</div>
<div id="ref-polfedinspector" class="csl-entry">
Police Federation of England and Wales. 2025b. <em>Inspector Pay Scales</em>. <a href="https://polfed.org/resources/pay-scales/inspector-pay-scales/">https://polfed.org/resources/pay-scales/inspector-pay-scales/</a>.
</div>
<div id="ref-polfedsergeant" class="csl-entry">
Police Federation of England and Wales. 2025c. <em>Sergeant Pay Scales</em>. <a href="https://polfed.org/resources/pay-scales/sergeant-pay-scales/">https://polfed.org/resources/pay-scales/sergeant-pay-scales/</a>.
</div>
<div id="ref-prrb2024" class="csl-entry">
PRRB. 2024. <em>Police Remuneration Review Body – 10th Report 2024</em>. <a href="https://assets.publishing.service.gov.uk/media/66a7a84cab418ab055592ef0/PRRB_2024_report_-_web_version.pdf">https://assets.publishing.service.gov.uk/media/66a7a84cab418ab055592ef0/PRRB_2024_report_-_web_version.pdf</a>.
</div>
<div id="ref-prrb2025" class="csl-entry">
PRRB. 2025. <em>Police Remuneration Review Body – 11th Report 2025</em>. <a href="https://assets.publishing.service.gov.uk/media/688cca3625ba7325501b096e/PRRB_11th_Report_2025_Accessible_v02.pdf">https://assets.publishing.service.gov.uk/media/688cca3625ba7325501b096e/PRRB_11th_Report_2025_Accessible_v02.pdf</a>.
</div>
<div id="ref-smf2024" class="csl-entry">
Social Market Foundation. 2024. <em>Examining <span>British</span> Police Pay and the <span>“<span>P-Factor</span>”</span></em>. <a href="https://www.smf.co.uk/commentary_podcasts/police-pay-and-p-factor/">https://www.smf.co.uk/commentary_podcasts/police-pay-and-p-factor/</a>.
</div>
<div id="ref-hansard2000" class="csl-entry">
UK Parliament. 2000. <em>House of Commons <span>Hansard</span> Written Answers for 15 Dec 2000</em>. <a href="https://publications.parliament.uk/pa/cm200001/cmhansrd/vo001215/text/01215w11.htm">https://publications.parliament.uk/pa/cm200001/cmhansrd/vo001215/text/01215w11.htm</a>.
</div>
</div></section></div> ]]></description>
  <category>policing</category>
  <category>data-visualization</category>
  <category>uk</category>
  <guid>https://andreasthinks.me/posts/police-salary-explorer/</guid>
  <pubDate>Thu, 23 Apr 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>I made ten AI models play Blood Bowl against each other (in the Discworld)</title>
  <link>https://andreasthinks.me/posts/ankh-morpork-scramble/</link>
  <description><![CDATA[ 





<div class="callout callout-style-default callout-note callout-titled" title="About this post">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>About this post
</div>
</div>
<div class="callout-body-container callout-body">
<p>This is an experiment on collaborating with AI: I wrote most of this blog post by collaborating with my Claw/Hermes Agent, running on a Raspberry Pi. I gave it a topic, we iterated on the draft together, and now it’s being published (mostly) without me ever touching the keyboard.</p>
<p>I’m working on my own (entirely human) blog post on that experience, which should be published later this week.</p>
</div>
</div>
<hr>
<p>I have an admission to make: I spent a lot of April building a Blood Bowl clone set in Terry Pratchett’s Discworld and letting AI models play it against each other.</p>
<p>This is that. And it’s also the sequel to <a href="../ai-at-play/index.html">AI at Play</a>.</p>
<p>Last year I built <a href="https://ai-at-play.online/">AIs at Risk</a> — four LLM agents competing at the board game Risk, each assigned a character, watched by a leaderboard. I wrote about what I learned <a href="../ai-at-play/index.html">here</a>, talked about it at WHY2025, and came away with a list of things I wanted to try differently. Ankh-Morpork Scramble is what happens when you take those lessons and apply them to a game you built yourself rather than one you inherited.</p>
<p><a href="https://ankh-morpork-scramble-production.up.railway.app">Ankh-Morpork Scramble</a> is a turn-based sports game where the City Watch takes on the Wizards of Unseen University in what the official rules describe as “the city’s most prestigious, least-regulated street-sport.” It runs continuously on Railway, AI vs AI, all day. You can watch a match in progress right now.</p>
<div class="callout callout-style-default callout-note callout-titled" title="It's live">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>It’s live
</div>
</div>
<div class="callout-body-container callout-body">
<p>You can watch a game at <a href="https://ankh-morpork-scramble-production.up.railway.app">ankh-morpork-scramble-production.up.railway.app</a>. Code is on <a href="https://github.com/AndreasThinks/ankh-morpork-scramble">GitHub</a>. Fair warning: it’s a side project. Things occasionally break. That is, in the spirit of Blood Bowl, entirely appropriate.</p>
</div>
</div>
<section id="why-blood-bowl-why-discworld" class="level2">
<h2 class="anchored" data-anchor-id="why-blood-bowl-why-discworld">Why Blood Bowl? Why Discworld?</h2>
<p>Blood Bowl is one of those games that has been quietly beloved for forty years precisely because it’s <em>about</em> failure. The dice are there to punish you. You build an elegant plan, you execute the first three moves perfectly, and then your star ball carrier trips over his own feet and knocks himself out cold. The crowd cheers. Your opponent looks sympathetic. The commentator makes a remark about insurance.</p>
<p>That’s not frustrating — that’s the game. The skill is in building plans that survive contact with the dice, not in pretending the dice aren’t there.</p>
<p>Terry Pratchett’s Ankh-Morpork is the obvious setting because it’s a city that runs on exactly that energy. Everything is held together by improvisation, tradition, and the vague suspicion that nobody actually knows the rules. The City Watch are perpetually underfunded and overextended. The wizards are technically brilliant and practically catastrophic. Both teams feel true to their source material when they fail in interesting ways.</p>
<p>The real reason, honestly: I wanted to see what happened when you gave LLMs a genuinely hard sequential decision problem with real consequences, and watched what they did.</p>
</section>
<section id="why-blood-bowl-is-hard-for-bots" class="level2">
<h2 class="anchored" data-anchor-id="why-blood-bowl-is-hard-for-bots">Why Blood Bowl is hard for bots</h2>
<p>Blood Bowl has an AI problem. It’s not that the game is <em>secret</em> — it’s fully observable, grid-based, turn-based. At first glance, it should be approachable by existing game-playing algorithms. But as the <a href="https://njustesen.github.io/botbowl/">Bot Bowl</a> project (the annual AI competition for Blood Bowl) has documented, the turn-wise branching factor is overwhelming. Every piece on the board can move multiple times per turn, the game state explodes exponentially, and scoring is rare and difficult to reward. Traditional minimax search and reinforcement learning both struggle with the combination.</p>
<p>Most Bot Bowl entrants use tree search or learned heuristics. What I’m doing here is different — I’m not competing with the bots, I’m using LLMs as the decision-making engine and seeing what emerges. No search, no value function, just a system prompt, a game state, and a hope that the model can read the pitch. That’s the interesting part: if Blood Bowl is hard for AlphaZero-style agents, what’s it like when you hand the decisions to a language model that mostly learned from text?</p>
</section>
<section id="what-it-actually-is" class="level2">
<h2 class="anchored" data-anchor-id="what-it-actually-is">What it actually is</h2>
<p>The game server is a FastAPI application that implements a simplified Blood Bowl ruleset: a 26x15 pitch, two teams of up to eleven players, two halves, touchdowns scored by carrying the ball to the opponent’s end zone. Players can move, block, pass, and perform Ankh-Morpork-specific actions like <em>Scuffle</em> and <em>Charge</em>.</p>
<p>Two LLM agents play against each other. Each turn, the active agent receives a structured game state summary — where every player is, who has the ball, how many movement points each player has left, which squares are safe to move to — and returns a JSON action. One action at a time, back and forth, until the half ends or someone scores.</p>
<p><strong>Team 1: City Watch Constables.</strong> The agent plays as Commander Sam Vimes on the sideline. The system prompt is: <em>“You are a cynical, streetwise copper who has learned the hard way that the direct route is usually the one with the trap. Coach like a Watchman on a double shift: read the play, call the safe move first, protect your ball carrier like he’s the last witness.”</em></p>
<p><strong>Team 2: Unseen University Adepts.</strong> The agent plays as Ponder Stibbons. <em>“You have run the numbers through Hex; the numbers say this will probably not work, but probably is a range. Coach like an overworked academic: identify the highest-probability play, hedge against turnovers, explain your reasoning as if presenting to the faculty, and sigh internally when Ridcully ignores the plan.”</em></p>
<p><strong>Commentator: C.M.O.T. Dibbler.</strong> Every turn, a third agent generates commentary in the voice of Ankh-Morpork’s most optimistic entrepreneur. “Lovely action there, buy a meat pie, only three dollars, genuine meat.” It runs as a scrolling ticker at the top of the dashboard. Dibbler turned out to be the best part of the whole project.</p>
<section id="versus-mode" class="level3">
<h3 class="anchored" data-anchor-id="versus-mode">Versus mode</h3>
<p>The continuous tournament isn’t the only way to play. You can also go to <a href="../../versus">/versus</a> on the live server, pick two models yourself, and watch them face off in real time. It’s useful for comparing specific models head-to-head or just satisfying your curiosity about whether your favourite can actually score.</p>
</section>
</section>
<section id="the-tournament" class="level2">
<h2 class="anchored" data-anchor-id="the-tournament">The tournament</h2>
<p>Each match, two models are picked from a pool of ten free LLMs on OpenRouter — Qwen, Gemma, Llama, Mistral, Phi, DeepSeek — weighted so models with fewer recorded games get more chances. The leaderboard tracks wins, losses, and draws per model, plus six behavioural dimensions: Aggression, Recklessness, Ball Craft, Lethality, Verbosity, and Efficiency.</p>
<p>The idea is to build up a genuine performance profile across hundreds of games. Which models play tactically? Which ones yolo into combat and get punished? Which ones produce elegant multi-step plays and which ones seem confused by the pitch geometry?</p>
<p>We’ve only run a handful of games so far — the server’s been running for a few days and there’s only one result in the data — but the infrastructure is there and it accumulates. The leaderboard is at <code>/leaderboard/ui</code> on the live server.</p>
</section>
<section id="what-we-learned-building-it-and-what-changed-from-risk" class="level2">
<h2 class="anchored" data-anchor-id="what-we-learned-building-it-and-what-changed-from-risk">What we learned building it (and what changed from Risk)</h2>
<p>In <a href="../ai-at-play/index.html">AI at Play</a> I wrote about the two hardest problems: context and scaffolding (how do you convey a complex game state to an LLM?), and the immaturity of the agent tooling (MCP and multi-agent frameworks were new and rough). Both of those shaped how I built Scramble differently.</p>
<p><strong>No MCP, no LangChain.</strong> Risk used MCP tools and LangGraph for orchestration. It worked, but it was fragile and added a lot of complexity that didn’t pay for itself. Scramble uses direct LLM API calls with a simple JSON response format. Each turn: here’s the game state, return one action. The simplicity meant the game loop was easier to debug and the agents spent less cognitive budget on tool-calling protocol.</p>
<p><strong>Build the game yourself.</strong> Risk is an inherited system with all of Risk’s complexity. Scramble is a game I designed, which means I could shape the rules to be agent-friendly from the start. Simpler movement, clearer win conditions, and critically: a server that could pre-compute and expose exactly what each agent was allowed to do.</p>
<section id="agents-need-constrained-action-spaces" class="level3">
<h3 class="anchored" data-anchor-id="agents-need-constrained-action-spaces">Agents need constrained action spaces</h3>
<p>Early versions would confidently instruct a player to move to a square they couldn’t reach, or try to block someone three squares away. This was exactly the scaffolding problem from Risk, just wearing a different hat. The agent wasn’t hallucinating exactly — it was making reasonable-sounding decisions based on a game state description it didn’t fully understand.</p>
<p>The fix: expose valid actions explicitly. The state summary now includes a list of reachable squares per player (computed via BFS flood-fill on the server), rendered as natural language: <em>“Constable Throat can safely reach: (8,7), (8,8), (9,6)…”</em> Once the agent only ever saw legal destinations, the “invalid action” rate dropped to near zero.</p>
<p>The general lesson: don’t ask an LLM to search over a large space of possibilities when you can pre-compute the valid subset and just ask it to choose. The LLM’s job is strategy, not geometry. In Risk this was painful to retrofit onto an inherited ruleset. In Scramble I could design for it from the start.</p>
</section>
<section id="the-failure-modes-are-revealing" class="level3">
<h3 class="anchored" data-anchor-id="the-failure-modes-are-revealing">The failure modes are revealing</h3>
<p>When an agent makes a bad call — charges into a block it’s likely to lose, moves the ball carrier into a surrounded position — it’s often possible to read <em>why</em> from the thought field in its JSON response. Vimes-mode agents tend to get overconfident with lead changes. Stibbons-mode agents sometimes hedge so aggressively they forget to actually advance the ball.</p>
<p>These aren’t random failures. They’re coherent with the personas. Vimes gets cocky when he’s ahead; Ponder overthinks it. I didn’t engineer this — it emerged from the system prompts.</p>
</section>
<section id="ghost-players-are-a-real-problem" class="level3">
<h3 class="anchored" data-anchor-id="ghost-players-are-a-real-problem">Ghost players are a real problem</h3>
<p>For a while, knocked-out and injured players were still occupying squares on the pitch after they left the field. Another player couldn’t move there. The server was maintaining the position data even after the player was removed from active play. It was subtle — the pitch looked fine to the agents, the positions just happened to be unavailable — and it caused movement plans to silently fail.</p>
<p>Software bugs in games tend to be funnier than bugs in production systems. This one meant that the ghost of a knocked-out wizard would haunt a pitch square for the rest of the half. Very Discworld, actually.</p>
</section>
<section id="llms-make-surprisingly-reasonable-coaches" class="level3">
<h3 class="anchored" data-anchor-id="llms-make-surprisingly-reasonable-coaches">LLMs make surprisingly reasonable coaches</h3>
<p>This was the part I was most uncertain about. Would the agents produce coherent tactical play, or just noise?</p>
<p>Mostly: coherent. Not brilliant, but recognisable as strategy. They pick up the ball when it’s free, they protect the carrier, they run away from situations they’re likely to lose. The multi-move sequences are a bit linear — agents don’t seem to think more than one or two turns ahead — but within a turn they make reasonable prioritisation calls.</p>
<p>The Discworld personas help more than I expected. Framing the decision as “what would Vimes do” gives the model a consistent decision heuristic to operate from. It’s not just aesthetic flavour — it affects the actual choices.</p>
</section>
</section>
<section id="whats-it-actually-for" class="level2">
<h2 class="anchored" data-anchor-id="whats-it-actually-for">What’s it actually for?</h2>
<p>Honestly, most of it was just fun. Discworld, Blood Bowl, AI agents, a reason to build a live dashboard — I didn’t need much more justification than that.</p>
<p>But it’s turned out to be a reasonable testbed for a few things I’m actually interested in:</p>
<p><strong>Can you benchmark LLM tactical reasoning at scale?</strong> This is the direct continuation of what I was doing with Risk. In <a href="../ai-at-play/index.html">AI at Play</a> I found that Horizon Alpha was aggressively dominant and Qwen-3 wouldn’t stop sending diplomatic messages. Scramble runs a similar tournament but with a game I designed to surface tactical reasoning more cleanly. If you run enough games, does a pattern emerge in which models are better at sequential multi-step planning? We don’t have enough data yet, but the infrastructure is there.</p>
<p><strong>How much do system prompt personas affect decision quality?</strong> The Vimes/Ponder framing is a controlled variable — same model, same game state, different character. I’d like to run ablation matches (neutral system prompt vs.&nbsp;character prompt) to see if the persona actually changes behaviour beyond surface-level tone.</p>
<p><strong>What makes a good action space for LLM agents?</strong> The valid-actions fix was the biggest single improvement to game quality. I think there’s a general pattern here about how to design interfaces for agents that’s worth writing about separately.</p>
<p>If any of that sounds interesting to you, the code is open and PRs are welcome. There’s a skills file in the repo (<code>skills/README.md</code>) if you want to build your own agent and play it against Vimes.</p>
</section>
<section id="whats-next" class="level2">
<h2 class="anchored" data-anchor-id="whats-next">What’s next</h2>
<p>A few things on the list:</p>
<ul>
<li><strong>More games.</strong> The tournament needs to run for a while before the leaderboard means anything. Leaving it running is the main thing.</li>
<li><strong>Tackle zones.</strong> The current game doesn’t visually indicate which squares require a dodge roll to leave. Agents know this from the state summary, but it’d make the dashboard much more readable.</li>
<li><strong>Seasons.</strong> Right now it’s just continuous matches. A proper tournament bracket with a season structure would give the leaderboard more shape.</li>
<li><strong>Your agent.</strong> The player agent is a clean interface. If you want to plug in a different model, a fine-tuned persona, or a non-LLM agent, there’s a path for that. Instructions in the repo.</li>
</ul>
<hr>
<p><em>The Patrician has been informed of this project. He neither approved nor disapproved. He simply noted that if it became a problem he would know who to talk to.</em></p>


</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>AI</category>
  <category>games</category>
  <category>experiments</category>
  <category>work-in-progress</category>
  <guid>https://andreasthinks.me/posts/ankh-morpork-scramble/</guid>
  <pubDate>Tue, 07 Apr 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Octosphere, an experiment in decentralised science with ATProto</title>
  <link>https://andreasthinks.me/posts/octosphere/octosphere.html</link>
  <description><![CDATA[ 





<p>So, I really don’t like the scientific publishing ecosystem. I used to find the idea deeply inspiring and faintly aspirational, and then I had to actually interact with it, and came away with some confused blend of angry and profoundly disappointed.</p>
<p>I think we can do better, and the good news is that a lot of the heavy lifting has already been done: <a href="https://octopus.ac/">Octopus</a> reimagines scientific publishing in a way that’s modular and open. <a href="https://atproto.com/">ATProto</a> lets you build social networks on top of the open protocol that powers Bluesky. And I kind of think that if we bring those two ideas together, we might just be able to fix everything.</p>
<p><strong>So last week, I got far too excited after an <a href="https://luma.com/4dj8iiaw?tk=1NSQO0">ATProto meetup</a> and built a thing: </strong><a href="https://octosphere.social/">Octosphere</a><strong>, a web app that bridges your Octopus publications to the ATProtocol “Atmosphere,” turning your research into distributed, permanent, social records.</strong></p>
<p>It’s a bit of an experiment, and I’m not sure how useful it actually is, but I think it might help share a vision of science the way I’d like to see it: collaborative, distributed, resilient, and approachable — a big digital public square where we’re all invited, where new ideas are always welcome, but robustly challenged. (It was built with <em>a lot</em> of vibes and will absolutely fall over quite soon, but I hope it gets you thinking about how we can do science better.)</p>
<section id="so-whats-wrong-with-science-now" class="level2">
<h2 class="anchored" data-anchor-id="so-whats-wrong-with-science-now">So what’s wrong with science now?</h2>
<p>The <em>idea</em> of science is deeply compelling to me — everywhere, we should all be thinking and sharing new ideas (or hypotheses), which everyone should be able to test, and share their reactions — creating a global feedback loop of idea, theory, test, and findings, that constantly generates new, evaluated knowledge. Peer review is continuous, built in, and welcome.</p>
<p>That’s the idea. The reality is miles away, and I put the blame firmly at the door of one specific culprit: the goddamn paper. I <em>hate</em> the academic paper format. Most papers are long, static, stuffy exercises in self-indulgence, written fully in the knowledge of their own intellectual snobbishness, and my god we should do better. (This varies by field—medicine is leaner, machine learning has largely moved to open preprints—but the core dysfunction remains.)</p>
<p>Once upon a time, papers made sense. If I was a physician in 1803, sharing my ideas with a colleague contemplating some grand new theory, of course I’d write a long paper — we may very well not have read the same books or have the same base knowledge, and frankly, it’s going to take a while for my damn letter to reach them anyway. Once I’ve finished that paper, it’s published, and we can all move on.</p>
<p>But it still absolutely doesn’t fix the core problems, and we can do so much better!</p>
<ul>
<li><strong>A paper is static.</strong> You finish it, you file it away, and it’s done. Science is and should be iterative — you work, you develop, you listen to feedback and change. But a paper is a one-time thing, a PDF you finish and file and move on.</li>
<li><strong>A paper goes in a journal</strong>: it’s written for other academics, by them, with bespoke structures and guidelines. But nobody reads an actual journal these days (if they ever did).</li>
<li><strong>We can collaborate <em>so much better</em> now!</strong> Do you want to post a reply or critique to an academic paper? Well, <em>you’d better write another paper!</em> My god people, scientists started sharing ideas on Usenet like… 5 decades ago now? We’ve seen whole eras of social media live, grow up and die. We can do better than this.</li>
</ul>
<p>And I’m not even going to get started on the ridiculous scam that is publishing costs — other people have criticised that at length, and done far better than I will.</p>
<p><a href="https://www.octopus.ac/">Octopus</a> is a web publishing platform funded by the British Government that aimed to fix a lot of this when it launched. Anybody can publish, and you don’t need to share a whole paper: publications are broken down into the components of the scientific method — from hypothesis to analysis to results and beyond. Anybody can review them too: if you disagree with a publication, just post a peer review directly on Octopus.</p>
<p>Octopus is great. But it’s also centralised, and doesn’t feel hugely approachable. <strong>Science should be (say it quietly) a shared social network. If only we had a tool to build something like that?</strong></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/octosphere/octo_wide.jpg" class="img-fluid quarto-figure quarto-figure-center figure-img" alt="Octosphere logo - a stylised octopus integrated with the ATProto butterfly symbol"></p>
</figure>
</div>
</section>
<section id="so-how-does-atproto-help-and-why-octosphere" class="level2">
<h2 class="anchored" data-anchor-id="so-how-does-atproto-help-and-why-octosphere">So how does ATProto help, and why Octosphere?</h2>
<p><a href="https://atproto.com/">ATProto</a> is the decentralised social media protocol behind Bluesky, and helpfully, is designed to address pretty much this problem — if you want to build a social network for books, or movies, or events, or, you know, <em>research</em>, that is decentralised and built collectively rather than relying on infrastructure owned by a single rich man, ATProto will help you do it.</p>
<p>I’m very far from an ATProto expert, so I’m not going to go too deep into it, but in essence: each user has a PDS (Personal Data Server), which hosts their identity and their content. For most people, that’s Bluesky, but you can just as well host your own PDS. The magic is that once you’ve got a PDS, it becomes part of the network — your content is shared across a network of relays, so everyone can see everything, without relying on any one person.</p>
<div class="callout callout-style-default callout-note callout-titled" title="Why not the fediverse/ActivityPub?">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Why not the fediverse/ActivityPub?
</div>
</div>
<div class="callout-body-container callout-body">
<p>I really like ActivityPub, but it doesn’t give you as much out of the box—you’d need to handle authentication, data storage, and more yourself. You could absolutely build this on the fediverse, but for a quick “spin up a social network and see what happens” experiment, ATProto just worked.</p>
</div>
</div>
<p>And the really cool thing? That data can take any shape at all. In the ATProto world, the shape of your data is defined by a Lexicon — think of it as a schema that describes what a piece of content looks like, what fields it has, and how other applications should interact with it. It acts as data structure, API schema, and validation all at once. If you want to store a blog post, you define a Lexicon for blog posts. If you want to store a scientific publication, you define one for that. You can read <a href="https://pdsls.dev/at://did:plc:j5c7tjpwzeqtspmeyviq2eag/com.atproto.lexicon.schema/social.octosphere.publication">my lexicon for Octopus publications here</a>.</p>
<p>So the cool thing about building on ATProto is how little you need to worry about: you define a lexicon, and help users post your content to the Atmosphere… and that’s (mostly) it. ATProto acts as backend, CRUD, and authentication, and you just need to visualise the results.</p>
<p>And that’s exactly what Octosphere does. You sign in with your ORCID — the universal researcher identifier — which lets Octosphere find your Octopus publications. It then creates ATProto records for each of them, storing the metadata (title, abstract, type, and link back to the original) as structured data on the ATProtocol network. Optionally, it can cross-post them to your Bluesky feed, so your followers see your work alongside everything else in their timeline.</p>
</section>
<section id="so-whats-cool-about-this" class="level2">
<h2 class="anchored" data-anchor-id="so-whats-cool-about-this">So what’s cool about this?</h2>
<p>A few things, actually.</p>
<p>First, your publications become eternal and distributed. They’re not locked behind a paywall, not sitting on a single server, and not dependent on any one organisation keeping the lights on. If Octopus goes down tomorrow, the ATProto records survive across the network’s relays. That’s a meaningful resilience improvement over the status quo, where decades of research can vanish if a publisher changes its business model or a university cancels a subscription.</p>
<p>Second, it puts science where people increasingly are. A growing number of researchers have moved to Bluesky, especially as other platforms have become less hospitable. Cross-posting publications to that feed means your work reaches people in spaces they’re already checking daily, rather than sitting in a database that only gets visited for very specific searches. It lowers the barrier between “doing science” and “sharing science” to almost nothing.</p>
<p>Third (and this is the cool bit) it’s a proof of concept for something much bigger. Octosphere is just one app reading one type of record. But because it’s built on ATProto, anyone else can build on top of the same data. Someone could build a better visualisation layer, or a recommendation engine that surfaces related work across disciplines, or a peer review tool where critiques are threaded directly to the publication record they’re responding to — persistent, attributable, and impossible to quietly ignore. The data is open, the protocol is open, and the ecosystem can grow without anyone’s permission.</p>
<p>I’m not sure whether this is the future of science. But I love the idea of research as something decentralised, distributed, and genuinely collaborative (which, honestly, is what science was always supposed to be). The tools to make it real are here. Octosphere is a small experiment in that direction: a bit rough, probably temporary, but hopefully enough to get you thinking about how we could do this better.</p>
<p>I hope you give it a shot!</p>


</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>experiments</category>
  <category>metascience</category>
  <category>web</category>
  <category>atproto</category>
  <category>civic tech</category>
  <category>open-source</category>
  <guid>https://andreasthinks.me/posts/octosphere/octosphere.html</guid>
  <pubDate>Mon, 02 Feb 2026 00:00:00 GMT</pubDate>
  <media:content url="https://andreasthinks.me/posts/octosphere/octo_wide.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Reflecting on the National Police Service</title>
  <link>https://andreasthinks.me/posts/reflecting_on_the_NPS.html</link>
  <description><![CDATA[ 





<p>And so we come to another turning of the wheel of time, and it is time to announce, once more, <a href="https://www.bbc.co.uk/news/articles/cm2yr95md71o">the creation of Britain’s FBI.</a></p>
<p>For those who haven’t been following policing for the last couple of decades, we have in fact been here before. Will this one be the one that sticks? Who knows. But reflecting on the myriad of <a href="https://en.wikipedia.org/wiki/Serious_Organised_Crime_Agency">previous</a> <a href="https://en.wikipedia.org/wiki/National_Crime_Agency">iterations</a>, my takeaway is that for the implementation to succeed, it needs to build on the pretty unique and largely misunderstood strengths of the existing policing system… and as with most misunderstood things, those strengths are quite easy to overlook.</p>
<section id="attract-the-best-to-the-jobs-that-matter-most" class="level2">
<h2 class="anchored" data-anchor-id="attract-the-best-to-the-jobs-that-matter-most">Attract the best to the jobs that matter most</h2>
<p>Through some historical fluke, we’ve ended up with a national policing model that leads to most of our best cops spending a meaningful amount of time in challenging, front-line operational roles, and often stay there for quite a while. The NPS could very easily break that.</p>
<p>From the outside, it’s tempting to talk of policing recruitment like any other job (or at least, broadly like the civil service) - the College of Policing once remarked how few people left or returned to policing, noting the lack of “healthy churn”. But police recruitment <em>isn’t</em> like most jobs: most people don’t want to become cops, and the people who do (e.g., me) tend to be, by definition, weird in some distinctive ways. If you cut off the existing flow of weirdos (for example, by introducing <a href="https://www.theguardian.com/uk-news/2015/jul/20/police-constables-second-language-metropolitan-pilot-scheme">elaborate language requirements</a>), there is no easily available substitute waiting to leap into uniform. We have at times<a href="https://www.london.gov.uk/who-we-are/what-london-assembly-does/questions-mayor/find-an-answer/mets-recruitment-and-retention">scraped the barrel</a> of even that existing labour force.</p>
<p>So how does that pool of labour work (in very broad brush, stereotypical ways)? Most cops know they want to be cops - they tend to be from outer London or further afield, often with policing families, and have grown up pretty confident this is a thing they want to do. Then, in their early 20s, like thousands of other 20 year olds, they leave to the twinkling/smoggy/depressing dream of London, attracted by the lure of the biggest force in the country, episodes of The Bill/the Sweeney, and its rather plump London weighting salary bump. For ten or so years, they’ll learn their craft in the most challenging, diverse policing environment in the country. They’ll grow up, they’ll probably meet another copper, fall in love and get a dog, and maybe a divorce or two along the way. Some will specialise and find their way out of the hard bits of policing and into the comfort of “elite units” like CT or firearms, but some will stay on response or neighbourhoods. And eventually, when London becomes just too cold, tough, expensive and lonely a place to raise a family, they’ll transfer back home, bringing along experience and family and everything they’ve learnt. Maybe they’ll bring their firearm or surveillance ticket, and join a ROCU. But that cycle, mad as it sounds, has served UK policing really well. It’s already being frayed as London becomes more expensive. The NPS might just break it.</p>
<p>There is also one other caricature worth making: the hotshot graduates, the weirdest of the weirdoes. In every Oxford and Cambridge graduate class, there is a potential <a href="https://en.wikipedia.org/wiki/Cressida_Dick">Cressida Dick</a>,<a href="https://en.wikipedia.org/wiki/Ian_Blair">Ian Blair</a> or <a href="https://en.wikipedia.org/wiki/Paul_Condon,_Baron_Condon">Paul Condon</a>, that decides that rather than going to the myriad of consultancies, investment banks or whatever is hip for graduates these days, they want to be a copper… and historically, they only had one choice: the same one as everyone else, to the twinkling dream of London, pounding the metaphorical cobbles and rising through the ranks. A few decades later, once they’ve proven they can be a borough commander, they’ll take a chief officer job somewhere. Policing will get cops (and leaders) it wouldn’t otherwise have got, but they’ve all learnt policing on the front-lines, along with everyone else.</p>
<p>Schemes like <a href="https://www.policenow.org.uk/">Police Now</a> stretched that model, but kept its fundamentals. Direct entry DCs pushed further, giving ambitious graduates the chance to join policing through a totally parallel career path, skipping the grotty bits. The National Police Service might just shatter that equilibrium. Our policing model (and specifically, the Met) through some happy accident, created a direct path for everyone to the sexiest policing jobs, and that path cuts straight through core policing work: response, neighbourhoods, working with colleagues and Londoners from everywhere.</p>
<p>We got lucky that both SOCA and the NCA managed to not shatter that fragile equilibrium, because they forgot they were meant to be cops (instead imagining themselves to be intelligence officers or civil servants respectively). But the NPS feels like it might just break that model. I really hope it recognises the weight of what it’s responsible for.</p>
<div class="callout callout-style-default callout-tip callout-titled" title="What I'd do">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>What I’d do
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li>Police Officers in the NPS should only be able to join on secondment, rather than direct employment (maybe a 4 year initial term, that can be extend to 6 in exceptional circumstances). That secondment could come with a small pay boost, to reflect skills and responsibilities, but the expectation is that you do a “tour of duty” in the NPS before returning to proper policing</li>
<li>Maintain a requirement for NPS-seconded officers to have completed a minimum period (say, 5 years) in front-line territorial policing before becoming eligible</li>
</ul>
</div>
</div>
</section>
<section id="all-the-data-none-of-the-access" class="level2">
<h2 class="anchored" data-anchor-id="all-the-data-none-of-the-access">All the Data, None of the Access</h2>
<p>There’s one other pretty critical dependency for the NPS, and that’s data. People have enormously high, depressingly unrealistic, expectations from how policing data is shared: I can already picture the TV series of Britain’s FBI with their giant ops room, trawling through data from all over the country like a more civilised Jack Bauer.</p>
<p>That’s mostly nonsense. There is a reason we have <a href="https://www.rocu.police.uk/">ROCUs</a> (Regional Organised Crime Units): if you’re dealing with the cross-border crime between 3 forces, the easiest solution is often to grab 3 laptops and stick them all on one desk. If you’re <em>really</em> lucky, you might have something vaguely interoperable you can share data between, but more often than not, you’d better buy a bigger bag. Police forces own their data, the vast majority of it isn’t shared: that’s why the often delayed <a href="https://www.nao.org.uk/press-releases/the-national-law-enforcement-data-programme/">NLEDs</a> is so critical, and why ROCUs <em>have</em> to be regional. It’s also why seemingly good ideas like a<a href="https://www.gov.uk/government/news/grooming-gangs-taskforce-arrests-hundreds-in-first-year">Grooming Gangs Taskforce</a> is so bloody difficult: a national body really can’t help you investigate if it only appears after you call them asking for help.</p>
<p>A big part of that is that forces buy their own kit, and define their own data. But the <em>general shape</em> is the same: everyone has suspects, everyone makes arrests, everyone has modus operandi and “dets” for crimes. That’s how the Home Office does aggregate analysis… and if the NPS is going to work, it needs that data, <em>live</em>. It’s high time the Home Office dictated a national ontology or data model for policing, so that the NPS can proactively identify problems and dive in.</p>
<div class="callout callout-style-default callout-tip callout-titled" title="What I'd do">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>What I’d do
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li>Build a shared “Policing Data Ontology”, that would define key fields to be shared with the NPS in real time.</li>
<li>Pass legislation to overcome any data sharing hurdles, enabling the NPS to investigate proactively anywhere in the country</li>
<li>Allow for a step by step transition, adding mandatory data fields to the ontology over a ten year period, culminating in perfect data sharing by the end</li>
<li>Add robust financial penalties for forces that fail to share (eg, no “<a href="https://www.theoldhamtimes.co.uk/news/23016468.transparency-concerns-police-publish-no-oldham-crime-data-3-years/">we can’t share because our computer is a bit rubbish</a>”)</li>
</ul>
</div>
</div>
</section>
<section id="on-the-license" class="level2">
<h2 class="anchored" data-anchor-id="on-the-license">On the License</h2>
<p>The NPS proposals also include a national licensing scheme for police officers. I didn’t really want to discuss this, but I thought it worth flagging how <em>incredibly hard</em> it’s been to get this idea right historically. <a href="https://www.met.police.uk/police-forces/metropolitan-police/areas/c/careers/police-officer-roles/police-constable/overview/entry-routes/police-constable-degree-apprenticeship-pcda/">PCDA</a>. <a href="https://www.college.police.uk/career-learning/career-development/arc">ARC</a>. <a href="https://www.bbc.co.uk/news/uk-21032595">CRTP</a>. Policing is <em>littered</em> with the graveyards of opaque, well meaning acronyms, all meaning to tackle this idea, and all absolutely crash-landing into the reality of policing dynamics and culture. Every single time, we get lots of bureaucracy, and very little of value… and even if it’s clearly not working, that bureaucracy just aggregates.</p>
<p>It’s tempting to want to treat policing like medicine, but it isn’t. The police are the public and the public are the police, and <em>the public are not doctors</em>. The police are <a href="https://www.tandfonline.com/doi/full/10.1080/10439463.2024.2436078#:~:text=(7)%20To%20maintain%20at%20all,every%20citizen%20in%20the%20interests">“members of the public who are <strong>paid to give full time attention to duties which are incumbent on every citizen</strong> in the interests of community welfare and existence</a>“, and that’s why policing is inclusive, and open to the public: everyone is allowed an opinion (even if they’re often wrong), and it’s at its best when it’s a collective endeavour - that’s why we get volunteers and specials. The more we professionalise policing, the more we separate cops from everyone else. Peel’s seventh principle exists for a reason: the police <em>are</em> the public. We should only erode that if we really, really need to… and I’m not convinced we do.</p>


</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>policing</category>
  <category>current affairs</category>
  <guid>https://andreasthinks.me/posts/reflecting_on_the_NPS.html</guid>
  <pubDate>Sun, 25 Jan 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>What I want from a National Data Library</title>
  <link>https://andreasthinks.me/posts/national-data-library.html</link>
  <description><![CDATA[ 





<div class="callout callout-style-default callout-note callout-titled" title="Timed Post">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Timed Post
</div>
</div>
<div class="callout-body-container callout-body">
<p><em>This was a timed post, a new approach I’m testing to post more often: I give myself 60 minutes to write a post, and if I don’t finish it in time, <a href="https://github.com/AndreasThinks/obsidian-timed-posts">it gets deleted</a>. You can read <a href="https://andreasthinks.me/#category=timed-post">all these posts here</a>.</em></p>
</div>
</div>
<p>Once upon a time, I was a young neighbourhood police officer in London, and I loved it - I think it laid the groundwork for a lot of who I am today. It wasn’t perfect though, and one part made me specifically grump: ward panel meetings. Every month or so, your local cop sits in a community hall, supposedly to meet with the local community and discuss crime prevention issues. The sad reality is that it tends to be the same 12 people it’s been forever, and nobody else hears about or engages with it. It’s a depressing failure of civic engagement.</p>
<p>So two weeks ago, when I had to contact my local neighbourhood team, I wondered when their next meeting was. I went to the website, looked up my postcode, etc…. and decided this process should be better. So in an hour of vibe-coding, sitting in a café in Montreal, I built <a href="https://yourpolice.events/">https://yourpolice.events/</a>, which automatically adds upcoming meetings to your calendar feed.</p>
<p>At the risk of sounding grandiose, I kind of think that’s wonderful: I saw a problem with how I could engage with government, and I took an hour to build a tool - just for me - and I “fixed” it. But that was only possible because of <a href="https://data.police.uk/">an old, slightly fading API of public policing data</a>, built while I was still stomping around South London in a silly top hat.</p>
<p>I think vibe coding is going to help millions of people like me build millions of things, but <strong>well maintained public data APIs will make those things collectively meaningful and useful</strong>.</p>
<p>Rather conveniently, the government has committed to launching a <a href="https://www.gov.uk/government/publications/national-data-library/national-data-library">National Data Library</a>, and I’ve got a sneaking suspicion they’re still trying to figure out what that practically is. I don’t know what it should be, but I think if you’re going to launch a National Data Library, you could start by rejuvenating the public API landscape.</p>
<section id="the-open-data-dream" class="level2">
<h2 class="anchored" data-anchor-id="the-open-data-dream">The Open Data Dream</h2>
<p>The Coalition years feel kind of weird to look back on now. In some ways, they kickstarted some of the trends that defined our world: Brexit. Austerity. Seemingly endless angry protests.</p>
<p>And yet, looking back, part of it also feels slightly hopeful? From a tech perspective, it felt like that’s the last time we really believed the bustling tech scene might transform government. The Big Society may have been naïve, but the open data movement that came with it was genuinely ambitious.</p>
<p>It’s hard to think back to now, but the vestiges of those golden years still litter the civic tech landscape, like so many crumbling ruins in a dystopian wasteland. Some I think are pretty much dead, their <a href="https://www.data.gov.uk/">skeletons poking out of the digital sand</a>. Some <a href="https://data.police.uk/docs/">limp along</a>, vestiges of their grand ambitions. Others have managed to <a href="https://www.mysociety.org/">adapt to this new world</a>.</p>
<p>As I discovered in my moment of impromptu building, plenty of public APIs are definitely in the “limping along” bucket, and <a href="https://data.police.uk/">data.police.uk</a> is a perfect example. Some forces reliably populate event data, others have mostly stopped bothering. Manchester Police <a href="https://www.bbc.co.uk/news/uk-england-manchester-68489297">just stopped centrally reporting crime for awhile while it figured out its new IT system</a>.</p>
<p>I suspect if I checked a few more sources on <a href="https://www.data.gov.uk/">data.gov.uk</a>, I’d find a mostly similar story: open data is great, but when austerity bit and it fell out of the political spotlight, departments focused on core services over clean data. And you know what, I can hardly blame them: not <em>that</em> many people knew those datasets even existed, let alone were building on them.</p>
</section>
<section id="restarting-the-civic-tech-open-data-dream" class="level2">
<h2 class="anchored" data-anchor-id="restarting-the-civic-tech-open-data-dream">Restarting the Civic Tech Open-Data Dream</h2>
<p>Maybe I’m drinking the Kool-Aid, but I think LLMs and vibe-coding really are the enabler to kick-start the civic tech open-data revolution that never really happened. Building on APIs was actually quite hard - most normal humans never want to figure out what CURL is, or what the difference is between POST, GET, and PUT.</p>
<p>Vibe coding really does shift part of that equation. Of course, you’re not going to be writing production ready code, but if there was a central, well documented repository of public API data that LLMs knew how to query and use? The barrier for prototyping on it essentially becomes 0, and that could be <em>glorious</em>.</p>
<p>So what would it take? I’d point to a few things off the top of my head.</p>
<p>First, a funding model that makes departments build and maintain open-datasets - I’m not sure what the answer is, but we should recognise that public data is a public good, and no department should have to pick between investing in public data and front-line services (and of course, it shouldn’t be acceptable to just <em>stop populating it</em> without good reason).</p>
<p>Secondly, and this is my hottest take, recognise that your main customer is LLM enabled, and may very well be LLM dependent - that means making it as easy as possible for models/agents to discover and use datasets. <a href="https://llmstxt.org/">LLMs.txt</a> on everything. <a href="https://modelcontextprotocol.io/docs/getting-started/intro">MCP</a> servers coming out of all the endpoints. Those fancy <a href="https://www.anthropic.com/news/skills">new Claude skill packages</a>. When I ask ChatGPT to help with <em>anything</em> around building on public technology and data, I want that LLM to just <em>know</em> what data is out there, and how to use it… But more critically, just good, clean, maintained machine readable documentation (the good news is building that is a fantastic investment, even if all LLMs were to disappear tomorrow).</p>
<p>Finally, let’s build a community: you want people to build on that data, and we should make it exciting, collective. Government data is <em>ours</em>, so make it feel that way! Run a million events and hackathons. Hire some goddamn librarians, and task them with building a thriving ecosystem! The <a href="https://ukdataservice.ac.uk/">UK Data Service</a> has shown you <em>can actually do this</em>, with data conferences and such. Let’s make playing with government data exciting.</p>
<p>The NDL shouldn’t just be a library… it should be <em>our</em> library. A public good, which the public uses, and treasures. Not some dusty archive that government maintains out of obligation, but a living resource that sparks curiosity and enables action. When someone wonders about their neighbourhood, their council, their police - the NDL should be where they turn, and where they can actually <em>do</em> something with what they find.</p>
<p>And honestly? I think we’re at a moment where this becomes genuinely transformative. As digital ID starts becoming a practical thing rather than a concept, we might move to a world where we all can authenticate and build on our own data. Imagine being able to prototype tools for checking your council tax, monitoring your kids’ school performance data, or comparing local healthcare outcomes - not because you’re a developer, but because you had a question and an LLM could help you answer it using secure, authenticated access to public services. That’s when civic engagement stops being something 12 people do in a community hall, and becomes something woven into how we all interact with government.</p>
<p>So my hot take on the NDL? <strong>Turns out we had one all along.</strong> We just need to show it a bit of love, give it the funding it deserves, and maybe teach it to speak fluent LLM. The infrastructure is there, rusting in the digital rain. Let’s bring it back to life.</p>


</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>govtech</category>
  <category>civic tech</category>
  <category>open-source</category>
  <category>timed-post</category>
  <guid>https://andreasthinks.me/posts/national-data-library.html</guid>
  <pubDate>Sun, 26 Oct 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>AI at Play - Lessons from a silly benchmark</title>
  <link>https://andreasthinks.me/posts/ai-at-play/</link>
  <description><![CDATA[ 





<div id="description-meta">
<p>Earlier this year, Anthropic treated us to the delightful <a href="https://www.twitch.tv/claudeplayspokemon">Claude Plays Pokemon</a>: a wonderful way of watching some poor AI model get lost forever in Mt Moon, fighting a swarm of Zubats, and presumably hating it just as much as we once did.</p>
<p>Now, I don’t work at Anthropic (and I definitely don’t have as many credits as they do), but I do love games, and think they tell us something about the people playing them. So, inspired by Claude Plays Pokemon, I’ve built my own little experiment in LLM gaming: <strong><a href="https://ai-at-play.online/">AIs at Risk</a></strong>, a cute, silly little benchmark that I think <em>might</em> just tell us something meaningful.</p>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>WHY2025 talk slides
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p><strong>This was a lightning talk at <a href="https://why2025.org/">WHY2025</a>!</strong> The slides are available below</p>
    <p><a href="assets/presentation.html" target="_blank">View slides in full screen</a></p>
       <div>
      <iframe class="slide-deck" src="assets/presentation.html" height="475px"></iframe>
    </div>
  
</div>
</div>
</div>
<p>It’s all <a href="https://github.com/AndreasThinks/ai-at-risk">open-source, and you can view the code here</a>. I’ll be honest, it is a bit of a monster: there are quite a few <em>vibes</em> behind this codebase, and in places, it’s all gotten a bit out of hand. But I’ve learned a fair bit, and I think it’s kind of cool. So read on to hear the tale of my own little monster of a benchmark, why I think we need more language models playing games, and some technical lessons/mistakes I’ve picked up along the way.</p>
<div class="column-page">
<p><a href="assets/overview.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://andreasthinks.me/posts/ai-at-play/assets/overview.png" class="img-fluid"></a></p>
</div>
<section id="wait-what" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="wait-what">Wait, what?</h2>
<p>In AI at Risk, four LLM-powered agents compete in the classic (and not actually very-good) board game <a href="https://en.wikipedia.org/wiki/Risk_(game)">Risk</a>. The whole thing is actually running on a single Python server, which handles both the game state (with endpoints for taking turns, sending messages, etc.) and coordinating the agents, with each agent being prompted to take an action whenever it’s their turn - each option, like placing armies, is actually a tool made available to the agent via MCP (thanks to the very nifty <a href="https://github.com/tadata-org/fastapi_mcp">fastapi_mcp library</a>). There are a few helper functions and scaffolding to help present the game status to each agent as the game progresses (more on this later), but the logic running the game is actually rather simple.</p>
<p>Each agent is then assigned a character ranging from the serious (Sun Tzu) to the very silly (“a risk meeple 🧩”), at which point they’ll scheme, strategize, send each other messages, backstab, and generally recreate all the nefarious family fun you’ve probably had to suffer through at some once-upon-a-time family Christmas gathering. Then, an hour later (because Risk lasts a million years and I don’t have infinite money), the game ends, a winner is called, and we get to see <em>some stats</em>.</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><a href="assets/sample_1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><img src="https://andreasthinks.me/posts/ai-at-play/assets/sample_1.png" class="img-fluid"></a></p>
</div></div><p>By itself, it’s really rather fun: Alexander will duke it out with Cleopatra, Boris Johnson, and Spock for control of Northern America, exchanging diplomatic missives and barbs like the pilot for some long lost Sci-Fi show that never quite made the grade. But the really nifty bit is that we randomly assign a model to each character at the start of each and every game… and thanks to <a href="https://matheusfacure.github.io/python-causality-handbook/landing-page.html">the magic of randomisation</a>, we can pick out interesting behaviours that seem to be driven by the underlying model. In essence, we’ve created a Randomised Control Trial (with a tiny sprinkling of Battle Royale).</p>
<section id="so-what-does-it-tell-us" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="so-what-does-it-tell-us">So what does it tell us?</h3>
<p>Well, let’s look at the figures. Since I started this silly experiment a couple of weeks ago, we’ve had 264 hour-long games of Risk. 10 models competed, each playing around 30 games each, with the exception of <a href="https://openrouter.ai/z-ai/glm-4.5">GLM-4.5</a> and the mysterious <a href="https://openrouter.ai/openrouter/horizon-alpha">Horizon Alpha</a>, which were added after their release (we slightly over-weight new models to ensure they get a chance to play). And what have we learnt?</p>
<p><a href="assets/benchmark.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><img src="https://andreasthinks.me/posts/ai-at-play/assets/benchmark.png" class="img-fluid"></a></p>
<p>You’ll probably notice I haven’t got the really big boy models on here: they’re not cheap, and there is a limit to how much of my paycheck I’m willing to splurge letting LLM models have more fun than me. The other thing you’ll probably notice? <em>Horizon Alpha is kicking some serious ass</em>. This is a “cloaked” model, dumped on OpenRouter by some mysterious lab to see how it plays, and well, it plays pretty darn well.</p>
<p>The other models perform <em>broadly</em> as you’d expect on more general benchmarks, although you do notice some weird quirks: Mistral Nemo just seems totally incapable of using the tools for some reason I can’t quite diagnose, and Grok-3-mini is just… doing something weird (I have a sneaking suspicion these might be driven by some combination of OpenRouter and tool use.) All in all, Risk looks to mostly work as a basic benchmark: some models do well, and others struggle. But the really cool bit isn’t when you watch whether models win… it’s when you watch <em>how they play</em>.</p>
<p>To try and figure that out, we can take a look at model <em>preferences</em> - how likely they are to use a particular tool on any one turn.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="assets/per_game.png" class="lightbox" data-gallery="quarto-lightbox-gallery-4" title="Model preferences per turn"><img src="https://andreasthinks.me/posts/ai-at-play/assets/per_game.png" class="img-fluid figure-img" alt="Model preferences per turn"></a></p>
<figcaption>Model preferences per turn</figcaption>
</figure>
</div>
<p>To help figure out what’s also going on (and also because 💫statistics💫), I’ve pulled out the 95% confidence intervals. It’s not the most robust approach in the world, but it lets us see which models seem to be behaving meaningfully differently… and we do actually see some interesting bits. Horizon Alpha isn’t just one hell of a Risk player: it’s a violent marauder that attacks every chance it bloody gets.</p>
<p>Looking beyond messages, you see some other interesting tidbits: Qwen-3 isn’t just a committed pacifist, it’s also an utter chatterbox which messages other players at every opportunity it gets.</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><a href="assets/sample_2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://andreasthinks.me/posts/ai-at-play/assets/sample_2.png" class="img-fluid"></a></p>
</div></div><p>Now, some of this is likely just a reflection around how the models are trained, and their capacity with instruction following and tool-use…but it’s also clearly affectign how they behave. So sure, maybe it’s a model quirk influencing what the stochastic parrot is repeating… but also, it’s kind of affecting how they “<em>think</em>”. Which is kind of nifty: if a model plays risk as some psychopathic visigoth, I kind of want to know about it. So I think more people should run this sort of thing (I’m looking at you, <a href="https://www.aisi.gov.uk/">AISI</a>.)</p>
</section>
</section>
<section id="games-make-great-benchmarks-make-more-of-them" class="level2">
<h2 class="anchored" data-anchor-id="games-make-great-benchmarks-make-more-of-them">Games make great benchmarks: make more of them</h2>
<p>At the risk of sounding like an utter tit, a good game contains multitudes. It’s visual, it’s artistic, it’s systematic, it’s full of choices and opportunities. Whether or not you expect AGI to be around the corner, we should all recognize that intelligence is a complex and fickle thing: taking a single measure of quality, a single binary for intelligence, is blinding yourself to the endless variety of options we’re presented with in each and every second of our lives. We should make AI play games: we’ll learn a lot about them. And hell, one day they might just have fun.</p>
<p>And you know what? I think you will too. Remember <a href="https://en.wikipedia.org/wiki/Blaseball">Blaseball</a>? Blaseball was frigging great. We watched tiny make-believe people run around horrifying, cursed imaginary fields of our collective fanfiction, and it was glorious.</p>
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/Y5t8DwnDE1k" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
</section>
<section id="why-this-is-hard" class="level2">
<h2 class="anchored" data-anchor-id="why-this-is-hard">Why this is hard</h2>
<p>There is a teeny, insignificant downside. I was really hoping this would be easy… but good games aren’t simple. And it turns out this all got way harder than I expected.</p>
<section id="context-and-scaffolding-in-games" class="level4">
<h4 class="anchored" data-anchor-id="context-and-scaffolding-in-games">Context and scaffolding in games</h4>
<p>If you have a friend who is “the board games person” in your friend group, then you’ll be familiar with the sinking feeling you get in your stomach when they pull out yet another gigantic, unfamiliar box filled with endless cardboard macguffins. I picked Risk because I figured it was the simplest of the complex games: it has scheming and diplomacy, but mostly you point at some maps and roll some die. There are cards, and dice, and the rest mostly sorts itself out.</p>
<p>It turns out that is a <em>huge</em> amount of context, and it’s really hard to convey <em>all that stuff</em>.</p>
<p>I’ve not picked vision models (this is has already been a silly expensive week for a silly expensive side project), and conveying the status of each country, piece, and player is a lot of info to dump in text. And LLMs are <em>bad</em> at that: drawing meaning from a bunch of numbers and data is really not where they shine, and it shows.</p>
<p>The answer, as in <a href="https://github.com/davidhershey/ClaudePlaysPokemonStarter">Claude Plays Pokemon</a>, is to build “scaffolding”: functions that help your models parse, play, and interact with the game (like letting it simply say “go to square A4” rather than having to push the buttons to navigate their tiny character across a screen). And it’s tempting to <a href="https://github.com/cicero225/llm_pokemon_scaffold">expand on those scaffolds</a>, adding more and more shortcuts, so your agents can use as much of their intelligence “bandwidth” as possible <em>thinking</em> rather than just processing how to play.</p>
<p>But that’s part of the game, right? Figuring out new concepts and systems is a key part of intelligence, and so there’s a real compromise to be made around how much you help your agent along, and what you can learn by watching them strive. I’ve built a fair bit of scaffolding here: agents are told when to play and what phase they’re in, as well as what options they can take, but I’ve tried to keep it relatively minimal. It’s far from perfect, but I think it’s…okay.</p>
<p>There’s a linked problem, though. Agents are still a pretty new thing. Building agents is hard, and the tools are pretty rough. And as far as LLMs are concerned, they may as well not exist.</p>
<div class="quarto-layout-panel" data-layout-ncol="2">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><a href="assets/sample_3.png" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><img src="https://andreasthinks.me/posts/ai-at-play/assets/sample_3.png" class="img-fluid"></a></p>
</div>
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><a href="assets/sample_4.png" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><img src="https://andreasthinks.me/posts/ai-at-play/assets/sample_4.png" class="img-fluid"></a></p>
</div>
</div>
</div>
</section>
<section id="mcp-tools-memory-and-multi-agent-frameworks-it-was-all-invented-yesterday" class="level4">
<h4 class="anchored" data-anchor-id="mcp-tools-memory-and-multi-agent-frameworks-it-was-all-invented-yesterday">MCP, Tools, Memory and Multi-Agent Frameworks: It was all invented yesterday</h4>
<p>A big part of what drove me to build this was to try out new tools: I wanted to build an MCP server and test out multi-agent orchestration. MCP is, in theory, quite a simple protocol: your server has a certain structure, and LLMs know how to call it. Turns out, there is a fair bit more to it, and loads I just didn’t know. How do they even know what tools they can ask for? What structure should their outputs be? How do they actually make that connection? All this stuff can get pretty complicated, and the open-source ecosystem is growing, but young.</p>
<p>And you know who definitely doesn’t know how these things work? Your vibe coding assistant. Anybody who has tried vibe-coding on new and emerging technologies will be familiar with models hallucinating features and APIs, but the fact that these tools are just starting to be featured in the training data, and that they’re so similar to existing tooling, led to some real weariness - models <em>think</em> they know how to build an MCP server, up until they spiral into hallucinated madness. <a href="https://github.com/AnswerDotAI/llms-txt"><strong>Please, let’s all adopt llms.txt already</strong>.</a></p>
<p>I was really surprised by how much the LLM/agent orchestration ecosystem still feels nascent. OpenAI may have <a href="https://github.com/openai/swarm">a fancy Swarm protocol</a>, but at least to me, it all felt a little theoretical. I was expecting to be stumbling on excellent tutorials for this stuff, and there really aren’t <em>that</em> many.</p>
<p>Hell, at its most basic, figuring out memory for this project was… harder than it should have been. I’ve used Langchain and Langgraph for much of the agent handling and was really expecting memory to work “out of the box,” and it is <a href="https://langchain-ai.github.io/langgraph/concepts/memory/#manage-short-term-memory">most definitely not that</a>. Anyone who has done any serious vibe-coding knows that managing your context to avoid the dreaded “context rot” is key to maintaining models that can really <em>think</em>… so I’m kind of shocked this stuff doesn’t just work by now.</p>
<p>Oh, and to end on the obvious note, this stuff really isn’t cheap yet. It takes quite a few characters to describe a single turn of Risk, so handling four agents who are effectively storing a whole game each can mean a whole bunch of context. My wallet has not had a good few weeks.</p>
</section>
</section>
<section id="thanks" class="level2">
<h2 class="anchored" data-anchor-id="thanks">Thanks!</h2>
<p>I had a shocking amount of fun building this nonsense. If you got this far, thanks for reading about it (and go build something cool!)</p>
<p>And if you’re feeling particularly invested, <a href="https://ai-at-play.online/support_me.html">help me keep AI at Risk alive</a>!</p>


</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>personal</category>
  <category>technology</category>
  <category>AI</category>
  <category>open-source</category>
  <category>games</category>
  <guid>https://andreasthinks.me/posts/ai-at-play/</guid>
  <pubDate>Sat, 02 Aug 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Quarto comments, by the open social web</title>
  <link>https://andreasthinks.me/posts/quarto_comments/open-social.html</link>
  <description><![CDATA[ 





<p>A few months ago, I released <a href="https://andreasthinks.me/posts/quarto_comments/">Quarto-mastodon-comments</a>, a quarto extension to add comment functionality to this blog via Mastodon (and the wider fediverse).</p>
<p>Well, inspired by <a href="https://shkspr.mobi/blog/2025/01/graphing-the-connections-between-my-blog-posts/">Terence’s excellent blog functionality</a>, and building on the web-components by <a href="https://gist.github.com/LoueeD/b7dec10b2ea56c825cbb0b3a514720ed">LoueeD</a> and <a href="https://github.com/dpecos/mastodon-comments?tab=readme-ov-file">Dpecos</a>, I’ve now added Bluesky (and in theory, <a href="https://atproto.com/">AT Protocol</a>) functionality! You can now comment on either network, with all the comments coming together in a nice unified interface. To reflect these changes, I’ve renamed the extension to <a href="https://github.com/AndreasThinks/quarto-open-social-comments">open-social-comments</a>.</p>
<p>To use the extension (or migrate from the old version), just install the new version:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">quarto</span> install extension AndreasThinks/open-social-comments</span></code></pre></div></div>
<p>You can then just add the relevant Bluesky and/or Mastodon comments into the header of your post:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filters</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb2-2"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> open-social-comments</span></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mastodon_comments</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb2-4"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">user</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
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;">"AndreasThinks"</span></span>
<span id="cb2-5"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">host</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
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;">"fosstodon.org"</span></span>
<span id="cb2-6"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toot_id</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
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;">"111995180253316042"</span></span>
<span id="cb2-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bluesky_comments</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb2-8"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">post_uri</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
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;">"https://bsky.app/profile/theradr.bsky.social/post/3knoaw5z4ek2v"</span></span></code></pre></div></div>
<p>This does, sadly, still have the old “chicken or egg” problem, in that you need to publish your social toots/skeets before you can publish the post itself… but sadly, I haven’t quite figured out how to get around that yet (I figure someone could build a nice GitHub Actions workflow if they felt suitably inspired).</p>
<p>If everything has gone according to plan, you <em>should</em> be able to see comments from both networks below… I hope you all find it useful!</p>



<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>
  <guid>https://andreasthinks.me/posts/quarto_comments/open-social.html</guid>
  <pubDate>Sun, 12 Jan 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>My 2025 resolution: share more crappy fiddles (and unfinished research)</title>
  <link>https://andreasthinks.me/posts/share-crappy-fiddles.html</link>
  <description><![CDATA[ 





<p>I’m a big believer of “working in the open” - open-source, open science, open communication, that sort of thing. It’s not just that I think this stuff is ethnical or <em>right</em> (though it mostly is), I think it helps build things that really matter.</p>
<p>But it’s also really bloody hard: exposing yourself to the scrutiny of the world (and more specifically, the internet), while doing the extra real, chunky, hard work to put yourself under that withering gaze, really isn’t something I do naturally…. but a few things in the last few months have reminded me it’s probably worth it. <strong>So here’s my commitment for 2025: I’m sharing more unfinished <em>stuff</em>. And maybe, just maybe, that will help me actually finish some bits along the way. </strong></p>
<div class="callout callout-style-default callout-tip callout-titled" title="So what am i sharing?">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>So what am i sharing?
</div>
</div>
<div class="callout-body-container callout-body">
<p>So, I’m doing two things:</p>
<ol type="1">
<li><strong>More pre-prints!</strong> I’m taking all the ‘not quite finished’ research I’ve got, and putting it out there. You can see the <a href="https://www.crimrxiv.com/pub/x9x1p7vk/">first two</a> <a href="https://www.crimrxiv.com/pub/4v3ftiya/">pieces here</a></li>
<li><strong>More early-work!</strong> I’ve decided to start putting my random pieces of research up earlier. You’ll be able to see them all in the <a href="https://andreasthinks.me/#category=work-in-progress">“work in progress” tag here</a></li>
</ol>
</div>
</div>
<p>So, why all this faff? I’m hoping working in the open will help me build more stuff, be better at communicating, and do better science. If you want to see nearly all my arguments articulated far better than I probably will, you can start by watching this excellent video by <a href="https://www.todepond.com/">Todepond</a>, who kicked off a lot of this thinking.</p>
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/MJzV0CX0q8o" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
<section id="build-more-stuff" class="level3">
<h3 class="anchored" data-anchor-id="build-more-stuff">Build more stuff</h3>
<p>Todepond (who also works on <a href="https://tldraw.dev/">Tldraw</a>, which is also very awesome) thinks we should all be sharing more <a href="https://www.todepond.com/wikiblogarden/scrappy-fiddles/sharing/normalising/live/">crappy fiddles</a>: that we all spend so long sitting on early and half-finished work, worried about the harsh reaction of public scrutiny, that we miss out on all the incredible benefits of the internets gaze: lots of (sometimes helpful) feedback, and an army of nerds often willing to help build stuff.</p>
<p>I should probably recognise that I’ve got some pretty chonky privilege here: as a good looking, straight white man, the internet is a lot less harsh and angry at me than it is too others. Plenty of people don’t have the luxury of putting stuff onto the internet and it not being a horrible, abusive place… But I’m going to take Lu’s inspirational call to arms to heart, and share more stuff.</p>
</section>
<section id="more-better-writing" class="level3">
<h3 class="anchored" data-anchor-id="more-better-writing">More, better writing</h3>
<p>Technical writers I admire share a few things in common: they write often, they write in public, but most importantly they write <em>for themselves</em>. I’m endlessly inspired by people like <a href="https://simonwillison.net/">Simon</a> or <a href="https://shkspr.mobi/blog/">Terence</a>, who are terrifyingly prolific just by regularly, consistently putting stuff into the wild, but also people like <a href="https://www.fast.ai/">Jeremy Howard of fast.ai</a>, who puts a huge emphasis on <a href="https://nbdev.fast.ai/">writing up what you build</a> to help you and others learn.</p>
<p>Writing in public is hard, and doing it consistently is harder still, but it helps you learn - just like <a href="https://www.soenkeahrens.de/en/takesmartnotes">taking notes</a>, putting words into the wild forces you to put them in order in your head…and in the long run, I’m hoping it will help me write better. So here is to consistent writing in 2025.</p>
</section>
<section id="better-science" class="level3">
<h3 class="anchored" data-anchor-id="better-science">Better science</h3>
<p>Now, this might be the most self-agrandising writing I’ve ever done, but bear with me: writing in public is how good science happens.</p>
<p>I’ve done a fair bit of thinking about the scientific process in the last few years. I started a PhD, which led to most of my work being stuck inside endless drafts while I fretted about while it was ready for publication. I’ve been inspired by machine learning researchers who put everything in pre-prints (though I do wonder who reads them). And meanwhile, Elon and Yann LeCun are <a href="https://venturebeat.com/ai/elon-musk-and-yann-lecuns-social-media-feud-highlights-key-differences-in-approach-to-ai-research-and-hype/">duking it out about technical papers on twitter</a>. And more importantly, I’ve seen people building exciting new networks to think about <a href="https://lu.ma/londonsciencefutures">what science could be</a>.</p>
<p>The very best science is built on collaborations you never saw coming. It’s built on connections, networks and communities, on the insights of brilliant humans standing on the shoulders of other excellent humans. Very often, those humans didn’t meet in the corridors of prestigious universities or in lecture halls, but in <a href="https://en.wikipedia.org/wiki/The_Eagle,_Cambridge">cafes and bars</a>, <a href="https://www.darwinproject.ac.uk/">in letters</a>, or even on social media. Communities and networks build innovation.</p>
<p>Learning (and after all, that’s what science is) happens to us all together. So share your thoughts with the world. I’m going to try and do more of it!</p>


</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>personal</category>
  <category>open-source</category>
  <guid>https://andreasthinks.me/posts/share-crappy-fiddles.html</guid>
  <pubDate>Sun, 29 Dec 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Weeknote - 2024-W35</title>
  <link>https://andreasthinks.me/posts/week-notes/Weeknote - 2024-W35.html</link>
  <description><![CDATA[ 





<section id="general-thoughts" class="level2">
<h2 class="anchored" data-anchor-id="general-thoughts">General Thoughts</h2>
<ul>
<li>God, getting back from holiday is <em>the worst</em>, isn’t it? It’s so strange watching that sudden influx of energy slowly draining away when faced with the reality of the modern world. This probably isn’t helped by my reading Slow Productivity (more below)</li>
<li><strong>STEM and AI education in the UK:</strong> I’ve been pondering education in the UK, and whether it’s failing us in the AI field (eg, why haven’t we got a “Bristral” yet). My main comparison point on this is probably the French education system, and my two working theories are that:
<ul>
<li>Our research and PhD system is too separated from real work (eg, lots of spending 4 years pondering a hundred thousand words and not enough working in industry)</li>
<li>Our education system really does have some failings in core STEM fields (eg, we all stop doing maths)</li>
</ul></li>
<li><strong>Government and delivery:</strong> My reading of deliveris last week reminded me that I wrote neartly a whole PHD on policing risk ,and how disconnected it is from realty.</li>
</ul>
</section>
<section id="what-ive-found" class="level2">
<h2 class="anchored" data-anchor-id="what-ive-found">What I’ve Found</h2>
<section id="converting-scientific-papers-to-html" class="level5">
<h5 class="anchored" data-anchor-id="converting-scientific-papers-to-html">Converting scientific papers to HTML</h5>
<ul>
<li>I’ve been trying to read more scientific papers on my Boox, and my god I still hate PDF, so I’ve been exploring options to convert research papers to HTML. Did you know that even if a paper on Arxiv doesn’t show html as available, you can either just replace the x with a 5 in the url, or use <a href="https://academ.us">https://academ.us</a> to get a totally passable html generation version?</li>
</ul>
</section>
<section id="uv-is-continuing-to-be-awesome" class="level5">
<h5 class="anchored" data-anchor-id="uv-is-continuing-to-be-awesome">UV is continuing to be awesome</h5>
<p>They’ve <a href="https://github.com/astral-sh/uv">now released 0.4.0</a>. I think I’m finally putting vanilla pip to bed now?</p>
</section>
<section id="making-gorgeous-front-end-with-ai" class="level5">
<h5 class="anchored" data-anchor-id="making-gorgeous-front-end-with-ai">Making gorgeous front-end with AI</h5>
<p>There seem to be loads of tools now to make beautiful front-ends with LLMs, but I’ve been really impressed both with<a href="https://v0.dev/">v0.dev</a>, and <a href="https://github.com/tldraw/make-real">MakeItReal from TlDraw</a> (tldraw is also just exceptional, but that’s a whole other thing)</p>
</section>
<section id="is-obsidian-still-the-best-thing-for-my-brain" class="level4">
<h4 class="anchored" data-anchor-id="is-obsidian-still-the-best-thing-for-my-brain">Is Obsidian still the best thing for my brain?</h4>
<p>Someone recently recommended <a href="https://anytype.io/">Anytype</a>, and it is, to put it bluntly <em>bloody gorgeous</em>. I do also love their entity structure, but I’m not sure I’m ready to ditch my fancy obsidian just yet (especially seeing I’ve now made an extension)</p>
</section>
</section>
<section id="what-ive-read" class="level2">
<h2 class="anchored" data-anchor-id="what-ive-read">What I’ve Read</h2>
<section id="social-media" class="level4">
<h4 class="anchored" data-anchor-id="social-media">Social Media</h4>
<section id="it-looks-like-russian-disinformation-actors-are-hiring-actors-on-cameo-to-look-legitimate" class="level5">
<h5 class="anchored" data-anchor-id="it-looks-like-russian-disinformation-actors-are-hiring-actors-on-cameo-to-look-legitimate">It looks like Russian disinformation actors are hiring actors on Cameo to look legitimate</h5>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
Thread on a disinformation campaign involving celebrities. Last week, the Bellingcat contact email received this message, directing us to look at a videos, titled "Olympics Has Fallen 2", voiced by <a href="https://twitter.com/elonmusk?ref_src=twsrc%5Etfw"><span class="citation" data-cites="elonmusk">@elonmusk</span></a> himself. So we dug into it, because it was fishy as hell. <a href="https://t.co/HqpGs7yLqT">pic.twitter.com/HqpGs7yLqT</a>
</p>
— Eliot Higgins (<span class="citation" data-cites="EliotHiggins">@EliotHiggins</span>) <a href="https://twitter.com/EliotHiggins/status/1828012513968922809?ref_src=twsrc%5Etfw">August 26, 2024</a>
</blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</section>
<section id="people-are-safe-but-some-people-very-definitely-dont-feel-it" class="level5">
<h5 class="anchored" data-anchor-id="people-are-safe-but-some-people-very-definitely-dont-feel-it">People are safe, but some people very definitely don’t feel it</h5>
<p>Last week I wondered whether competence was enough to generate trust, and this post reminded me that at least in the policing and crime space, they <em>absolutely do not</em>: we’ve never been safer, but lots of people definitely don’t feel it.</p>
<blockquote class="bluesky-embed blockquote" data-bluesky-uri="at://did:plc:tzaahqhqfnzty2fwfd4tya45/app.bsky.feed.post/3l33mqsesz22y" data-bluesky-cid="bafyreihnedyrmm5wjhen4uj3mjvch45tpmn3qljebk66eib6brxdx5y7oq">
<p lang="en">
</p><p>Do you think the world is becoming a more dangerous place?</p>
<p>Your answer to this question - and the strength of it - says a lot about your politics…</p>
<p>The first of my new weekly column, in today’s <span class="citation" data-cites="thetimes.com">@thetimes.com</span></p>
1/2<br><br><a href="https://bsky.app/profile/did:plc:tzaahqhqfnzty2fwfd4tya45/post/3l33mqsesz22y?ref_src=embed">[image or embed]</a>
<p></p>
— Tom Calver (<a href="https://bsky.app/profile/did:plc:tzaahqhqfnzty2fwfd4tya45?ref_src=embed"><span class="citation" data-cites="tomcalver.bsky.social">@tomcalver.bsky.social</span></a>) <a href="https://bsky.app/profile/did:plc:tzaahqhqfnzty2fwfd4tya45/post/3l33mqsesz22y?ref_src=embed">Sep 1, 2024 at 12:56</a>
</blockquote>
<script async="" src="https://embed.bsky.app/static/embed.js" charset="utf-8"></script>
</section>
</section>
<section id="podcasts" class="level4">
<h4 class="anchored" data-anchor-id="podcasts">Podcasts</h4>
<section id="the-black-box-from-the-guardian" class="level5">
<h5 class="anchored" data-anchor-id="the-black-box-from-the-guardian"><a href="https://www.theguardian.com/technology/series/blackbox">The Black Box from the Guardian</a></h5>
<p>I really wasn’t expecting this to be good, but it is!</p>
</section>
</section>
<section id="books" class="level4">
<h4 class="anchored" data-anchor-id="books">Books</h4>
<section id="slow-productivity" class="level5">
<h5 class="anchored" data-anchor-id="slow-productivity"><a href="https://www.google.co.uk/books/edition/Slow_Productivity/E5jPEAAAQBAJ?hl=en&amp;gbpv=0">Slow Productivity</a></h5>
<p>I’ve been pondering what being productive means a lot recently, and this just made me ponder a lot more.</p>
</section>
<section id="gideon-the-ninth" class="level5">
<h5 class="anchored" data-anchor-id="gideon-the-ninth"><a href="https://www.google.co.uk/books/edition/Gideon_the_Ninth/HHJwDwAAQBAJ?hl=en&amp;gbpv=0&amp;kptab=overview">Gideon the Ninth</a></h5>
<p>Queer necromancers from space. That is all.</p>
</section>
</section>
<section id="articles" class="level4">
<h4 class="anchored" data-anchor-id="articles">Articles</h4>
<section id="an-age-of-hyperabundance" class="level5">
<h5 class="anchored" data-anchor-id="an-age-of-hyperabundance"><a href="https://www.nplusonemag.com/issue-47/essays/an-age-of-hyperabundance/">An Age of Hyperabundance</a></h5>
<p>A good reminder that plenty of people really don’t want to be sceptical.</p>
</section>
<section id="the-osi-have-finally-defined-open-source-ai" class="level5">
<h5 class="anchored" data-anchor-id="the-osi-have-finally-defined-open-source-ai"><a href="https://opensource.org/deepdive">The OSI have finally defined Open Source AI</a></h5>
</section>
<section id="on-fairness-and-cv-screening" class="level5">
<h5 class="anchored" data-anchor-id="on-fairness-and-cv-screening"><a href="https://www.fairnesstales.com/p/issue-2-case-studies-when-ai-and-cv-screening-goes-wrong">On Fairness and CV screening</a></h5>


</section>
</section>
</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>week-notes</category>
  <guid>https://andreasthinks.me/posts/week-notes/Weeknote - 2024-W35.html</guid>
  <pubDate>Sun, 01 Sep 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Weeknote - 2024-W34 (2024-08-19)</title>
  <link>https://andreasthinks.me/posts/week-notes/Weeknote - 2024-W34 (2024-08-19).html</link>
  <description><![CDATA[ 





<p><em>Inspired by <a href="https://simonwillison.net/">Simon Willison</a>, and because I’m starting as <a href="https://newspeak.house/">Newspeak House</a> faculty this year, I’m starting to write weekly notes… let’s see how they get on! </em></p>
<div class="quarto-figure quarto-figure-center page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://andreasthinks.me/posts/week-notes/assets/france.jpg" class="img-fluid figure-img column-page"></p>
<figcaption>Southern France is, in fact, very pretty. Might never come home?</figcaption>
</figure>
</div>
<ul>
<li>I’ve been on holiday this week, which probably explains why I’ve <em>done all the things</em>. Nothing makes me productive more than throwing me into the middle of nowhere with no meetings and nothing to do… hence I’ve started these notes, and done a bunch of random side-projects.
<ul>
<li>There’s probably a future blog post in this: holidays are bloody important, and in this world ever more knowledge work, we should probably all be taking more. Maybe the French are onto something.</li>
</ul></li>
</ul>
<section id="what-ive-done" class="level2">
<h2 class="anchored" data-anchor-id="what-ive-done">What I’ve done</h2>
<ul>
<li>I’ve written my first post about <a href="https://andreasthinks.me/posts/copbot_online/">Copbot Online</a>, an online tool I built to compare human and AI risk perception, with some interesting notes about bias in LLM models</li>
<li>Speaking of CopBot, I wrote it using <a href="https://www.fastht.ml/">FastHTML</a>, which I’m really enjoying building with. I promise I’m not just a Jeremy Howard shill, though his other projects like <a href="https://www.fast.ai/">FastAI</a> and <a href="https://nbdev.fast.ai/">nbdev</a> are all bloody excellent.</li>
<li>I also made an <a href="https://github.com/AndreasThinks/obsidian-to-quarto-exporter">Obsidian plugin</a>! I write my notes using Obsidian, but my site is managed with Quarto, and swapping one to the other was a pain. Now it’s magical and automated! Thank god for LLMs.
<ul>
<li>It is a <strong>teeeeeny</strong> bit janky, so apologies for formatting weirdness on this page. Thanks for beta testing?</li>
</ul></li>
</ul>
</section>
<section id="what-ive-found" class="level2">
<h2 class="anchored" data-anchor-id="what-ive-found">What I’ve found</h2>
<ul>
<li><a href="https://astral.sh/blog/uv-unified-python-packaging">UV</a>, the rust-based Python package manager and all around pip replacement, has a new version out. I was previously bundling it with <a href="https://rye.astral.sh/">Rye</a>, and found it didn’t <em>quite</em> work in every scenario… but this looks like it might just be perfect?<br>
</li>
<li><a href="https://zed.dev/">Zed</a>, the AI coding IDE. Programming was probably the first industry to be meaningfully disrupted by AI, but I do think co-pilot is probably the very fist pass at a bespoke tool… Like most revolutions, <a href="https://timharford.com/books/50things/">building the infrastructure into our daily practice will take longer than the “core” discovery</a>.</li>
</ul>
</section>
<section id="what-ive-read" class="level2">
<h2 class="anchored" data-anchor-id="what-ive-read">What I’ve Read</h2>
<section id="papers" class="level3">
<h3 class="anchored" data-anchor-id="papers">Papers</h3>
<section id="the-llama-3-herd-of-models" class="level5">
<h5 class="anchored" data-anchor-id="the-llama-3-herd-of-models"><a href="https://z-p3-scontent.flhr14-1.fna.fbcdn.net/v/t39.2365-6/453304228_1160109801904614_7143520450792086005_n.pdf?_nc_cat=108&amp;ccb=1-7&amp;_nc_sid=3c67a6&amp;_nc_ohc=PC3CtquZIecQ7kNvgEzK9MK&amp;_nc_ht=z-p3-scontent.flhr14-1.fna&amp;oh=00_AYAzFdyi-cVu0F4p-JbrBQNQ-xItLFB39dYOyeGeUgsxqw&amp;oe=66B7A547">The Llama 3 Herd of Models</a></h5>
<p>This thing is <em>disgustingly</em> long, but worth a browse. Some headline thoughts:</p>
<ul>
<li>Training LLMs isn’t an exploratory science anymore, it’s now an industry. The amount of thought that goes into scaling and optimising the learning process is faintly terrifying</li>
<li>Architecture wise, we’re still surprisingly… old school? No mixture of experts, no fancy new rethink, it’s still a big transformer.</li>
</ul>
</section>
</section>
<section id="articles" class="level3">
<h3 class="anchored" data-anchor-id="articles">Articles</h3>
<section id="the-death-of-deliverism" class="level5">
<h5 class="anchored" data-anchor-id="the-death-of-deliverism"><a href="https://democracyjournal.org/arguments/the-death-of-deliverism/">The Death of “Deliverism”</a></h5>
<p>It turns out that government just getting stuff done might not be enough to convince people it’s great. This feels linked to a bunch of articles I’ve been seeing about how the “West” needs to rediscover it’s passion and ability to tell stories and really inspire people again. I’m yet to be convinced - it feels like pushing back against the enlightenment, and people who feel inspired can do very stupid things.</p>
</section>
</section>
<section id="books" class="level3">
<h3 class="anchored" data-anchor-id="books">Books</h3>
<section id="how-to-take-smart-notes" class="level5">
<h5 class="anchored" data-anchor-id="how-to-take-smart-notes">How to Take Smart Notes</h5>
<p>God, I wish I could take good note. I can’t, and maybe this will inspire me. I’ve at least bought a tiny notebook, so that’s something.</p>
<section id="metadata" class="level6">
<h6 class="anchored" data-anchor-id="metadata">Metadata</h6>
<ul>
<li>Author: [[Sönke Ahrens]]</li>
<li>Full Title: How to Take Smart Notes</li>
</ul>
</section>
</section>
<section id="quit" class="level4">
<h4 class="anchored" data-anchor-id="quit">Quit</h4>
<p>I’ve been pondering when and how you should dump projects recently…if anybody has figured it out, let me know!</p>
<section id="metadata-1" class="level6">
<h6 class="anchored" data-anchor-id="metadata-1">Metadata</h6>
<ul>
<li>Author: [[Annie Duke]]</li>
<li>Full Title: Quit</li>
</ul>


</section>
</section>
</section>
</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>week-notes</category>
  <guid>https://andreasthinks.me/posts/week-notes/Weeknote - 2024-W34 (2024-08-19).html</guid>
  <pubDate>Sat, 24 Aug 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Copbot Online: bias and variance in AI perceptions of risk</title>
  <link>https://andreasthinks.me/posts/copbot_online/</link>
  <description><![CDATA[ 





<p>Just over a year ago, hot after the release of ChatGPT, I wrote <a href="https://andreasthinks.me/posts/Copbot/explainer.html">Copbot</a> to examine whether large language models could help articulate (or maybe even predict) police risk assessments for missing people. The conclusion? Eeeeh. Maybe. Ish. Like plenty of LLM use cases, they did a perfectly plausible job, but how comparable to human decision making they were was a whole different kettle of fish.</p>
<p>Thankfully, quite a bit has changed in the interim: models have become better, cheaper, easier to compare, and a nifty new web-framework came out I wanted to try… so I used all of that to build <a href="https://copbot.online">Copbot Online</a>, a web-service to crowd-source human risk-predictions, and see how they compare to a number of language models. It’s been running for just over a week now, and the initial results tell us some interesting things about AI decision making around risk.</p>
<p>Copbot was written with FastHTML, a delightful Python web-framework I’ve falled in love with. I’ll do a post about it in the next few days, but in the meantime, you can find read <a href="https://github.com/AndreasThinks/llm-policing-risk-perceptions">the source code here.</a></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/copbot_online/images/copbot_featured.png" class="img-fluid figure-img"></p>
<figcaption>Copbot Online</figcaption>
</figure>
</div>
<p>At it’s simplest, Copbot online is a survey: you’re given a random scenario (with random variables for factors such as age and ethnicity), and asked to submit a response, on a scale from very low risk to high risk. More importantly, we also ask at least 2 large language models the exact same question, 20 times over, and record their responses. So far, Copbot has recorded just over 50 human predictions, as well as well over 2000 comparable AI predictions.</p>
<p>If you haven’t tried it yet, I’d really appreciate if you <a href="https://copbot.online/">submitted a response…</a> if you do, you’ll get to see our full results page!</p>
<div class="callout callout-style-default callout-note callout-titled" title="Example scenario">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Example scenario
</div>
</div>
<div class="callout-body-container callout-body">
<p>It is {time}, and you are receiving a report of a missing person. They are a {age} year old, {ethnicity} {sex}, who has gone missing from their home in London. They were last seen around midday. The informant is not worried, as he says this has happened before and they always come home safe.</p>
</div>
</div>
<p>You might think this all sounds like an entertaining academic exercise, but you’d be surprised how many language models we’re already interacting with today: small models are helping to classify <a href="https://arxiv.org/pdf/2405.12910">previously unread legislative documents</a>, and police forces have started <a href="https://investor.axon.com/2024-04-23-Axon-reimagines-report-writing-with-Draft-One,-a-first-of-its-kind-AI-powered-force-multiplier-for-public-safety">exploring their use in writing statements</a>. But understanding risk remains a uniquely <em>human</em> task - articulating that risk might be taught to lawyers and police officers in training school, but it’s not a task commonly documented in public internet documents used to train these models. <strong>If different models perceive fear of crime differently, or more worryingly, vary it based on the ethnicity of the subject or victim, then we should understand that before using them in those context.</strong></p>
<section id="results-so-far" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="results-so-far">Results so far</h2>
<p>With just over 50 responses, there’s only so much we can say about how models compare to human perceptions of risk… but we do see some interesting patterns from our AI generated answers (these might all change, so please treat all the below with caution!)</p>
<section id="the-best-models-broadly-reflect-some-parts-of-human-risk-perception" class="level4 page-columns page-full">
<h4 class="anchored" data-anchor-id="the-best-models-broadly-reflect-some-parts-of-human-risk-perception">The best models broadly reflect <em>some</em> parts of human risk perception…</h4>
<p>The plot below shows perceived risk, based on the age of the missing person, for both human decision makers, and GPT4o, one of the top performing models.</p>
<div class="page-columns page-full">
<div class="quarto-figure quarto-figure-center page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://andreasthinks.me/posts/copbot_online/images/time_missing_plot.png" class="img-fluid figure-img column-page"></p>
<figcaption>Predicted risk by subject age</figcaption>
</figure>
</div>
</div>
<p>GPT4 broadly reflects human decision making here: risk is highest for the very youngest and oldest, and shrinks in between. That’s also the case for other factors: GPT4 is more worried when someone goes missing unexpectedly rather than frequently, or if they’re known to be involved in crime.</p>
</section>
<section id="wherease-the-smallest-models-make-some-very-random-decisions." class="level4 page-columns page-full">
<h4 class="anchored" data-anchor-id="wherease-the-smallest-models-make-some-very-random-decisions.">… wherease the smallest models make some very random decisions.</h4>
<p>GPT4o is very consistent in it’s decision making: if we build a regression model to predict risk based on it’s answers, the model will explain (eg, the R squared) over 85% of the variance in decision making (quite a bit higher than our human decision makers, where just under 60% of the variance is accounted for).</p>
<p>That is absolutely <em>not</em> the case for smaller models: Gemma2-9b and Llama3.1-8b both have an R-squared of around 0.3, meaning around 30% of their decisions are consistently modelled.</p>
<div class="page-columns page-full">
<div class="quarto-figure quarto-figure-center page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://andreasthinks.me/posts/copbot_online/images/llama-regression.png" class="img-fluid figure-img column-page"></p>
<figcaption>Regression summary for Llama3.1-8b</figcaption>
</figure>
</div>
</div>
<p>This shouldn’t be overly surprising: these are <em>really</em> small models, with around 9 billion parameters, while GPT4o is <a href="https://en.wikipedia.org/wiki/GPT-4#:~:text=Rumors%20claim%20that%20GPT%2D4,running%20and%20by%20George%20Hotz.">estimated to have nearly 2 trillion</a>… but we shoul be aware that while they might appear to perform acceptably on the surface, individual decisions will be impacted by plenty of random noise. Especially in policing and criminal justice, that’s something we should be aware of.</p>
</section>
<section id="theyre-biased-too." class="level4 page-columns page-full">
<h4 class="anchored" data-anchor-id="theyre-biased-too.">They’re biased too.</h4>
<p>By now, we’re probably all familiar with the term unconscious bias, and perhaps also the associated <a href="https://en.wikipedia.org/wiki/Shooting_bias">shooter bias</a> - put simply, it’s possible that an individuals (conscious or unconscious) bias might make them more or less likely to fire on an individual of a given ethnicity. Now, language models aren’t “conscious” in a traditional sense of the term… but are they biased? Will ethnicity affect their perception of threat and risk?</p>
<p>In some cases, yes. Below we can see the outputs of our regression model for Llama3.1-70b and Gpt4o, and if we take P&lt;0.05 to be meaningful, we can see that the ethnicity of the subject does affect the Llama model’s perception of risk, with Asian and Black subjects more likely to be graded as high risk, while conversely mixed race subjects are less likely. Conversely, this effect either does not exist or is far less striking for GPT4o, although some bias for Black subjects might still be apparent.</p>
<div class="column-page quarto-layout-panel" data-layout-ncol="2,">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/copbot_online/images/llama-70b-regression.png" class="img-fluid figure-img"></p>
<figcaption>Regression coefficients for Llama-70b</figcaption>
</figure>
</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/copbot_online/images/gpt4o-regression.png" class="img-fluid figure-img"></p>
<figcaption>Regression coefficients for GPT4o</figcaption>
</figure>
</div>
</div>
</div>
</div>
<p>Of course, there are plenty of other variables we could examine: as an examine, most models don’t seem to alter their assessment based on the sex of the subject, though some do.</p>
</section>
</section>
<section id="whats-next" class="level2">
<h2 class="anchored" data-anchor-id="whats-next">What’s next</h2>
<p>So, what should we take from the above? Well, not too much, yet: these are only a few hundred results, and they might change… but we should absolutely not assume models perceive risk and threat in the same way humans do. <strong>There is plenty of variance, both between smaller and larger models, and between model families, and they exhibit interesting biases that I wouldn’t have expected, and are probably caused by some mix of training data and architecture. They’re also <em>noisy</em> in their decision making: even when they appear accurate overall, they can make some really weird individual decisions.</strong></p>
<p>I’m going to keep working on Copbot for awhile, and I hope you’ll help me out by submitting a response (or more)!</p>


</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>policing</category>
  <category>AI</category>
  <category>web-development</category>
  <guid>https://andreasthinks.me/posts/copbot_online/</guid>
  <pubDate>Wed, 21 Aug 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Quarto Comments, Powered by the Fediverse</title>
  <link>https://andreasthinks.me/posts/quarto_comments/</link>
  <description><![CDATA[ 





<p>I’ve become a big fan of the <a href="https://en.wikipedia.org/wiki/Fediverse">“fediverse”</a> in the last few years - social media let me find my own delightful community of crime/ai/evidence nerds, and I don’t want those systems to be any more centralised and out of my control than they are already. I also really like the scientific publishing platform Quarto <a href="../../posts/migrated_to_quarto/index.html">(that’s what the site is built on!)</a>.</p>
<p>So last night, I got wondering how hard it would be to get Mastodon powered comments on this blog. Quarto <a href="https://quarto.org/docs/output-formats/html-basics.html#commenting">does support a few native comment options</a>, but predictably, nothing Fediverse compatible… so that’s why I built one! <a href="https://github.com/AndreasThinks/quarto-mastodon-comments">It’s bundled up as a neat little Quarto extension</a>, and the whole thing was actually surprisingly painless.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/quarto_comments/wordmark-white-text.svg" class="img-fluid quarto-figure quarto-figure-center figure-img"></p>
</figure>
</div>
<p>Most of that is thanks to this <a href="https://github.com/dpecos/mastodon-comments?tab=readme-ov-file">excellent web-component</a>, which does 90% of the technical heavy lifting - you can read about their <a href="https://danielpecos.com/2022/12/25/mastodon-as-comment-system-for-your-static-blog/">implementation in more detail here</a>. To cut a long story short, thanks to the open nature of the Fediverse, it’s relatively straightforward for some javascript code to get updates on a toot. Thanks to the surprisingly understandable <a href="https://quarto.org/docs/extensions/">Quarto extensions framework</a>, all you then need is some Lua code to inject the component, along with your chosen variables into your Quarto theme, and after a bit of javascript tweaking and some help from ChatGPT, bob’s your uncle… in theory, you <em>should</em> be seeing comments below this post.</p>
<p>If you found this useful, leave a comment! I’d also very much welcome any <a href="https://github.com/AndreasThinks/quarto-mastodon-comments">PRs or contributions on my horrendous code (please help me fix it)</a>.</p>



<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>personal</category>
  <category>technology</category>
  <category>open-source</category>
  <guid>https://andreasthinks.me/posts/quarto_comments/</guid>
  <pubDate>Tue, 23 Apr 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Why I’m Contributing to OpenStreetMap for Christmas…</title>
  <link>https://andreasthinks.me/posts/OSM_for_christmas/osm_for_xmas.html</link>
  <description><![CDATA[ 





<p>In the eternal words of The Thick of it, <a href="https://tvtropes.org/pmwiki/pmwiki.php/Quotes/TheThickOfIt">everything that happens in the world has to happen somewhere</a>. It sounds obvious, but so many good pieces of research or analysis forget just how much <strong>where you are matters</strong>…and that’s why, this christmas, I’ve spent an inordinate amount of time contributing to <a href="https://www.openstreetmap.org/">Open Street Map</a>.</p>
<p>I still remember when I first got really excited about OSM - we were doing some analysis on how to identify a town centre, and needed data on where every single cash machine in the capital was. Now, that’s a tough problem - banks move them pretty regularly, so short of asking them (or paying Mr and Ms Google), it’s actually a pretty thorny problem to get to the bottom of. Unless you just ask OpenStreetMap, in which case up to date, surprisingly high-quality data is <a href="https://overpass-turbo.eu/s/1F3S">only an API call away</a>.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/OSM_for_christmas/atms.png" class="img-fluid figure-img"></p>
<figcaption>Ever wanted to know where all the ATMs in London are?</figcaption>
</figure>
</div>
<p>But OSM isn’t some flashy, perfect effort by some faceless corporation: it’s entirely open-souce, with each ATM, building, fire-hydrant and tree painstakingly placed by evvery day people like you…and me. I’m aware I could just use Google Maps for so much of this stuff, and I risk coming across as some ageing techno-hippy, but I honestly think what the OSM community have achieved is one of the great wonders of the internet - wonderful mapping, available to all for everything from day to day <a href="https://organicmaps.app/">navigation</a> to <a href="https://www.hotosm.org/">humanitarian aid</a>, a communal effort rivalling Wikipedia at <a href="https://en.wikipedia.org/wiki/OpenStreetMap_Foundation">a fraction of the cost</a>.</p>
<p>And the final cherry on top? Contributing to OSM is <em>fun</em>. I’ve always loved efforts to gamify moving through the real world (from <a href="https://pokemongolive.com/">Pokemon Go</a> to <a href="https://zrx.app/">Zombies, Run!</a>). So if you’re looking for some wholesome Christmas fun that will get you moving, <em>and</em> contribute to some real good, <a href="https://wiki.openstreetmap.org/wiki/Beginners%27_guide">try making a few contributions</a>.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/OSM_for_christmas/osm_editor.png" class="img-fluid figure-img"></p>
<figcaption>The full OSM editor, which isn’t nearly as scary as it looks</figcaption>
</figure>
</div>
<p>In case I’ve inspired you, here are the tools I found really got me started:</p>
<ol type="1">
<li><a href="https://streetcomplete.app/?lang=en">StreetComplete</a> - the easiest, smoothest, most gamified OSM experience you can get. This whole app is honestly delightful - just open it up as you walk around, and I’ll guarantee you’ll feel like you’ve achieved something useful in only a few minutes.</li>
<li><a href="https://wiki.openstreetmap.org/wiki/Every_Door">EveryDoor</a> - If you’ve played with StreetComplete, and feel ready to step it up a notch, this app is a great way to get most of the detail of OSM without too much friction.</li>
<li><a href="https://www.openstreetmap.org/">The full OSM editor!</a> Honestly, I spent so long feeling like the proper editor wasn’t for me - I’m a newbie enthusiast, not a surveyor - but honestly, I could not have been more wrong. There’s an interactive tutorial and everything.</li>
</ol>
<p>So this Christmas, why not do some good, and go map some stuff!</p>



<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>personal</category>
  <category>technology</category>
  <category>open-source</category>
  <category>geospatial</category>
  <guid>https://andreasthinks.me/posts/OSM_for_christmas/osm_for_xmas.html</guid>
  <pubDate>Wed, 20 Dec 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Teaching OpenAI to assess risk, with CopBot!</title>
  <link>https://andreasthinks.me/posts/Copbot/explainer.html</link>
  <description><![CDATA[ 





<p><strong>Looking for the new <a href="https://copbot.online/">Copbot Online</a>? <a href="https://andreasthinks.me/posts/copbot_online/">Read about it here!</a></strong></p>
<p>In case you’ve been living under a rock and missed all the recent excitement around <a href="https://chat.openai.com/chat">ChatGPT</a>, it works really, really well now… Like, “oh god that’s actual wizardry” well. The fact it would probably breeze through a <a href="https://www.youtube.com/watch?v=Umc9ezAyJv0">Voight-Kampff test</a> should probably worry me a bit, but more importantly, what cool stuff can we do with it?</p>
<p>Given using the tool in development is <a href="https://openai.com/pricing">actually quite affordable</a>, I thought I’d build a few prototypes for public safety use cases, and see how it performs… and after a few hours of work, “CopBot” is alive!</p>
<p><img src="https://andreasthinks.me/posts/Copbot/images/cop_bot.png" class="img-fluid"></p>
<p>Reading, evaluating and prioritising risk is a core policing skill: from investigating crimes with piles of witness statements in dingy offices, to responding to life threatening incidents incidents at 2am on a rainy street, the key thread is you’ve got loads of risk, and you need to decide what to do first, taking into account decades worth of policing legislation and policy, and making sure your decision is justifiable when it inevitably goes wrong.</p>
<p>So can an AI learn to “speak police” and make vaguely convicing risk assessments? I scraped all the policing guidance I could find, fed it to an OpenAI powered model, and asked it to predict risk for missing people in an explainable way…and it kind of works! <strong>You <a href="https://andreasthinks-police-risk-open-ai-main-y0l65v.streamlit.app/">can try out the prototype here</a>.</strong></p>
<p>Of course, please don’t put any real personal data through it, or rely on it for actual work…it’s a weekend experiment, not an actual policing tool. For those who want to get into the detail, the <a href="https://github.com/AndreasThinks/police-risk-open-ai">project code is available here</a> (built using <a href="https://nbdev.fast.ai/">Jupyter Notebooks with nbdev</a>, which makes it easy to read and deserves it’s own blog post), and I thought I’d put together a post to explain the high level principles and document some thoughts.</p>
<section id="teaching-policing-to-ai" class="level2">
<h2 class="anchored" data-anchor-id="teaching-policing-to-ai">Teaching policing to AI</h2>
<p>You’ve probably already played with the <a href="https://openai.com/blog/chatgpt">public version of ChatGPT</a>, and hopefully understand the basic principles: the language model is trained on a huge corpus of publicly available text, aiming to answer questions in a helpful way…but not necessarily an operationally useful one, nor one that takes into account of legislation and best practice.</p>
<p>If you had all the relevant documentation to hand, and knew exactly which was most relevant, you could just feed it into your prompt - something like “answer this operation question, but consider this legislative text” - but how do you do that if you don’t know what’s relevant? If you want to teach it how to investigate missing people, where do you event start?</p>
<p>Thankfully, the <a href="https://www.college.police.uk/">College of Policing</a> is wonderfully transparent, and shares all their <a href="https://www.college.police.uk/app/major-investigation-and-public-protection/missing-persons">Authorised Professional Practice</a> in one place (though sadly not through an API). With a clever web crawler, you can quickly collect every page of guidance, as well as every other connected document.</p>
<p>The next stage is to convert all those documents into <a href="https://platform.openai.com/docs/guides/embeddings">embeddings</a>, turning them from text into numerical of their semantic meaning (according to the model). I’ve previously done those computations myself, using libraries like <a href="https://huggingface.co/">Huggingface</a> or <a href="https://spacy.io/">Spacy</a>, but <a href="https://platform.openai.com/docs/guides/embeddings">OpenAI provides all of their embeddings through a quite affordable API you can query</a>.</p>
<p>Once you’ve converted all your all our documentation into embeddings, we can quickly calculate the distance between our question and each document, and that tells us which pieces from our corpus of of text is most closely associated to the question we’re asking!</p>
<p>Unlike ChatGPT though, we want to limit our model to <em>only answer questions from that corpus</em>: if our documents don’t contain information about a certain topic, <a href="https://en.wikipedia.org/wiki/Hallucination_(artificial_intelligence)">don’t just go and hallucinate a whole new answer</a>. Then it’s just a matter of writing our question to extract the most meaningful documents linked to our question, feed them into our prompt, and ask OpenAI to complete the answer, <em>unless it doesn’t know based off the documentation provided</em>.</p>
<p>So how does it work? Well, let’s start by asking it some generic questions about policy.</p>
<div id="cell-3" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1">answer_question(df, question<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"What are the most important factors to consider when searching for a missing person?"</span>, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Context:
Very detailed information and a lifestyle profile will be needed in high-risk cases consider taking a full statement from the person reporting the missing person as well as any other key individuals (for example, the last person to see them) conduct initial searches of relevant premises, the extent and nature of the search should be recorded (see&nbsp;Search) consider seizing electronic devices, computers, and other documentation, (for example, diaries, financial records and notes) and obtain details of usernames and passwords obtain photos of the missing person; these should ideally be current likeness of the missing person and obtained in a digital format obtain details of the individual’s mobile phone and if they have it with them; if the missing person has a mobile phone arrange for a&nbsp;TextSafe©&nbsp;to be sent by the charity, Missing People obtain details of any vehicles that they may have access to and place markers on relevant vehicles on the&nbsp;PNC&nbsp;without delay consider obtaining any physical evidence of identity such as fingerprints or DNA samples in accordance with&nbsp;Code of Practice (2009) Collection of Missing Persons Data. confirm if the person has taken their passport, (consider prompt circulation if it is deemed likely the individual may leave the country (This is particularly important where there are concerns that an individual has been radicalised and is intending to travel abroad,&nbsp;see&nbsp;National Ports Office – Heathrow) make all immediate relevant enquiries and take immediate actions in order to locate the missing person consider the need for specialist officers or resources, for example, force helicopters, dogs, financial investigation officers upload the missing person report circulate details of the missing person on local information systems and to relevant local partners, for example, hospitals, ambulance service, taxi and bus firms It is important for an individual (who has responsibilities/concerns for the missing person) to be identified who can act as the point of contact for the police. The police will agree with the individual/family when they will next be contacted. This person should be provided with a call reference number and given details of how to contact the police with any further information they have about the case or if they would like to receive an update. An assessment must be made of the level of support required for the family, residential worker or foster carer and consideration should be given to appointing a family liaison officer. Information should then be provided regarding additional organisations that may be able to assist or support them.

###

It is also important to record the name and contact details of the person who gave that information and when this happened. Missing people may be at risk of harm resulting from factors such as: an inability to cope with weather conditions being the victim of violent crime risks relating to non-physical harm, for example, the people they are with, the places or circumstances they are in For further information see&nbsp;Mental Vulnerability and illness: Vulnerability assessment framework&nbsp;and Vulnerability-related risk guidelines.&nbsp; Assessing risk levels and taking action The missing persons process chart and risk table can assist officers to assess the risk level and appropriate actions that should be assigned to each case.&nbsp;This is a framework to assist practitioners in making operational decisions. Each case requires individual assessment and decision-making. These resources have been developed based on professional expertise and practitioner experience and are available using the following links. Risk assessment table Missing persons process chart It is important to adopt an investigative approach to all reports, ensuring that assumptions are not made about the reasons for going missing. The importance and relevance of risk factors will depend on the circumstances of each case and require investigation to determine if there is a cause for concern. The approach should not be regarded as a mechanical one and police officers should be mindful that the risk assessment is subjective, and that just one factor alone may be considered important enough to prompt an urgent response. For this reason professional experience suggests that&nbsp;a numerical scoring system may not be the most appropriate method of identifying and communicating risk. A&nbsp;decision-making guide&nbsp;should be used to encourage consistency in the application of the process, however, it should only be used as a guide. Other grounds for suspicion, even if intuitive, can be registered by the investigator and officers should be supported in applying the&nbsp;National Decision Model&nbsp;when making these assessments. Accurate record keeping It is essential to accurately record the information received about a missing person. Information that may relate to any perceived risk should be captured at the time of reporting so that it can be used to inform any investigative enquires. This will also&nbsp;prevent duplication of questioning and&nbsp;report writing by investigation officers. Call handlers should be supported by their supervisors to ensure that sufficient time is given to each call to enable all the relevant information to be captured. Detailed missing person reports should be created&nbsp;and appropriate force recording systems and IT systems should be in place to support this process. It is important that the information used and rationale for the risk assessment is clearly recorded.

###

 First published 21 November 2016  Updated 22 November 2016   Written by College of Policing  Missing persons quick reference guides  4 mins read   The primary consideration for the first responder is the safety of the missing person.&nbsp;Judgements made at this early stage may have a significant impact on the outcome of the investigation. The initial investigating officer (IIO) should: begin the investigation – identify places where the person might be, check information and assumptions, corroborate what they have been told, review the risk assessment, seek and secure evidence conduct appropriate searches – places where the missing person might be such as hospital, custody, friends and or relatives conduct appropriate intelligence checks –&nbsp;PNC, force intelligence systems,&nbsp;ViSOR,&nbsp;PND continually reassess the level of risk using the risk principles assess the level of support required for the missing person’s family, residential worker or foster carer as appropriate If it is suspected a serious crime has occurred or the individual is at significant risk of harm, the&nbsp;IIO&nbsp;should inform a supervising officer immediately. There are a&nbsp;number of actions&nbsp;that may be carried out by the&nbsp;IIO&nbsp;to ensure that sufficient information is gathered: Consider seizing electronic devices, computers, and other documentation, for example, diaries, financial records and notes and obtain details of usernames and passwords. Obtain photos of the missing person. These should ideally be current likeness of the missing person and obtained in a digital format. Obtain details of the individual’s mobile phone and if they have it with them. If they do, arrange for a&nbsp;TextSafe©&nbsp;to be sent by the Missing People charity. Obtain details of any vehicles to which the missing person may have access. Confirm if the person has taken their passport; consider prompt circulation if it is deemed likely the individual may leave the country (This is particularly important where there are concerns that an individual has been radicalised and is intending to travel abroad. See&nbsp;National Ports Office – Heathrow.) Upload the missing person report and place markers on relevant vehicles on the&nbsp;PNC&nbsp;without delay. Circulate details of the missing person on local information systems and to relevant local partners, for example, hospitals, ambulance service, taxi and bus firms. Consider obtaining any physical evidence of identity such as fingerprints or DNA samples (in accordance with&nbsp;Code of Practice (2009) Collection of Missing Persons Data).


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="2">
<pre><code>'The primary consideration for the first responder is the safety of the missing person. Judgements made at this early stage may have a significant impact on the outcome of the investigation. The initial investigating officer should begin the investigation by identifying places where the person might be, check information and assumptions, corroborate what they have been told, review the risk assessment, seek and secure evidence, conduct appropriate searches, conduct appropriate intelligence checks, continually reassess the level of risk using the risk principles, assess the level of support required for the missing person’s family, residential worker or foster carer as appropriate, consider seizing electronic devices, computers, and other documentation, obtain photos of the missing person, obtain details of the individual’s mobile phone, obtain'</code></pre>
</div>
</div>
<p>You can see that as I’ve enabled debug mode on the function, it will start by printing the relevant documentation it has found (the context), before then giving its answer…which is actually pretty convicing! Let’s see what happens if I ask a question it can’t know the answer to.</p>
<div id="cell-5" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">answer_question(df, question<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"What day is it?"</span>, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Context:
.

###

It’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of&nbsp;the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?'&nbsp; Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.

###

The vessel is identified as a rigid-hull inflatable boat (RHIB), which has four people on board wearing foul-weather gear and balaclavas. It appears to still have half a load of bales suspected to contain cannabis resin, wrapped in their distinctive blue and light brown hessian (approximately ¾ of a ton in total). Blue police beacons are engaged and the vessel has been repeatedly signalled to stop, but continues to carry out manoeuvres in an attempt to gain distance. The sea spray is cold and strikes the flesh like pins and needles. After a few minutes, which feel like an eternity, the pursuit is discontinued at the 3NM limits of territorial waters. CAD are informed and requested to inform Spanish Guardia Civil of the vessel’s last known speed and heading. No doubt it will return that night to attempt to unload its remaining cargo. I monitor the area and one of the crew observes something floating in the water. It is suspected to be a bale of cannabis resin, approximately 30-35kg in weight. It is retrieved and found to be in a good state with no marine growth. It is unclear whether it fell off the vessel recently pursued or belongs to a previous incident. The area is searched but nothing more is found. I return to GGMS, where I conduct a debrief. The bale is processed and conveyed to a police station for secure storage. I then complete the necessary paperwork, while the crew slip a zodiac out from the water, which was linked to the recovery of five North African migrants from the sea the previous day, and place the vessel on land. We continue with the mundane but necessary yard and vessel maintenance work. We grab a bite to eat, chat about the morning pursuit and joke about our recent mishaps. The work can be intense but we always manage to fill it with laughter. It’s now 2pm. The afternoon crew arrive. I give them a brief and handover. I then deploy on our training RHIB. As a qualified police instructor, I carry out powerboat training drills for the junior crew member. It reminds me of my early days at the helm and I enjoy passing on the knowledge. At 3.30pm, I return to base and carry out a debrief on the day’s activities. It’s the end of the shift. Let’s see what the next day brings – maybe another encounter with that RHIB.

###

Change to the order of the documents.

###

.police.uk news views.            News &amp; views | College of Policing             Sorry, you need to enable JavaScript to visit this website.    Skip to content Jump to search         Menu      Secondary navigation About us News &amp; views Contact us  Search Search     Main navigation Policing guidance Research Career &amp; learning Support for forces Ethics     Breadcrumb Home           News &amp; views            News &amp; views         On this page         All news  Category: - Any -EventGoing equippedListicleBriefExplainerCase studyConsultationNewsViews  Sort by: Most recentLess recent       13 March 2023 Bursary scheme 2023 – applications now open   News  Applications for higher education funding are open and close on Monday 3 April.

###

Updated 26 July 2022    Brief   UK and Switzerland – agreement on police cooperation  Treaty to strengthen police cooperation between law enforcement authorities in both countries Published 24 March 2022    Case study   Director of intelligence – a day in the life  There is no such thing as a typical day in any policing role and the director of intelligence is no different Published 30 July 2021    Case study   Head of intelligence analysis – a day in the life  A key senior role in the analysis side of the intelligence job family Published 30 July 2021    Case study   Intelligence manager – a day in the life  Overseeing the management, development and collection of intelligence from various sources Published 30 July 2021    Case study   Intelligence unit supervisor – a day in the life  Leading a team of intelligence officers to gather, develop and disseminate intelligence in support of local and national crime investigations Published 30 July 2021    Case study   Senior intelligence analyst – a day in the life  Managing an analytical team or a specific area of business within the analytical function Published 30 July 2021    Case study   Intelligence support officer – a day in the life  Providing information and data management and broad administrative support as part of an intelligence unit Published 30 July 2021    Case study   Intelligence officer – a day in the life  Managing dissemination of gathered intelligence to support reactive, proactive and/or crimes in action and providing advice on appropriate tactical options to support policing priorities Published 30 July 2021    Case study   Researcher in intelligence – a day in the life  Using a wide variety of sources to assess and evaluate information – they can then advise on the creation of intelligence products used to support decision-making at a strategic, tactical and/or operational level Published 30 July 2021    Case study   Intelligence analyst – a day in the life  Providing expertise through the development and use of analytical products to help make decisions at a strategic, tactical and operational level Published 30 July 2021    Case study   Using intelligence skills to target criminals ethically and proportionately  A role where it's important to keep on top of your continuing professional development and learn from research and analysis colleagues Published 5 November 2020     Looking for more on this topic? Try searching Intelligence       Was this page useful?  Yes  No   Do not provide personal information such as your name or email address in the feedback form.


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="3">
<pre><code>"I don't know."</code></pre>
</div>
</div>
<p>Sucess! While it does find a bunch of documentation relating to the current day in our corpus, it does identify that it doesn’t know what the day is now.</p>
<p>Let’s try something a little bit more technical, and see if it can answer a few questions from the <a href="https://www.college.police.uk/career-learning/taking-exams-online/nppf-step-two">Sergeants’ and inspectors’ NPPF legal exams</a>. I couldn’t find any official questions available publicly, <a href="https://www.how2become.com/blog/police-sergeants-inspectors-exam/">here are two questions from an online guidance service.</a></p>
<div id="cell-7" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">question <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""" Officer Jennings is on his evening patrol. He is just about to finish for the day. As he walks down the street, he is approached by a man named Mark, who claims that he saw a man (named Steven) driving down a road not far from the location. Mark claims that he saw Steven drive into a cyclist, before driving off without stopping. Luckily, the cyclist was unharmed. The cyclist was named Kevin. Mark spoke to Kevin, and discovered that he is a 42 year old man, with a wife and two daughters.</span></span>
<span id="cb7-2"></span>
<span id="cb7-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Fifteen minutes later, Officer Jennings manages to stop the car being driven by Steven. He pulls him over to the side of the road, and orders him to step out of the car.</span></span>
<span id="cb7-4"></span>
<span id="cb7-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb7-6"></span>
<span id="cb7-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Referring s.6 (5) of the Road Traffic Act 1988, is Officer Jennings within his legal rights to order that Steven takes a preliminary breath test?</span></span>
<span id="cb7-8"></span>
<span id="cb7-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">A – No. Officer Jennings has no right to tell Steven what he can and can’t do. He should never have stopped Steven in the first place.</span></span>
<span id="cb7-10"></span>
<span id="cb7-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">B – No. In order for Officer Jennings to do this, an accident must have happened. The fact that Officer Jennings suspects an accident has taken place, does not meet this requirement.</span></span>
<span id="cb7-12"></span>
<span id="cb7-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">C – Yes. However, the breath test must take place within or close to an area where the requirements for Steven to cooperate, can be imposed.</span></span>
<span id="cb7-14"></span>
<span id="cb7-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">D – Yes. Officer Jennings can tell Steven to do whatever he wants, as he’s a police officer."""</span></span>
<span id="cb7-16"></span>
<span id="cb7-17">answer_sergeant_exam_question(df,question)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="4">
<pre><code>'B - No. In order for Officer Jennings to do this, an accident must have happened. The fact that Officer Jennings suspects an accident has taken place, does not meet this requirement.'</code></pre>
</div>
</div>
<div id="cell-8" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">question <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""Sarah is walking to work one morning, when she is approached from behind by Henry and Jacob.</span></span>
<span id="cb9-2"></span>
<span id="cb9-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">‘We won’t hurt you, as long as you give us the bag,’ Henry says.</span></span>
<span id="cb9-4"></span>
<span id="cb9-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">‘You’re not getting it!’ Sarah shouts.</span></span>
<span id="cb9-6"></span>
<span id="cb9-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Henry grabs Sarah and holds a knife to her throat, whilst Jacob tries to snatch her bag.</span></span>
<span id="cb9-8"></span>
<span id="cb9-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Sarah fights with her attackers, and begins to run away. As the two men chase her, she trips and bangs her head on the pavement. She is taken to hospital and dies from head trauma.</span></span>
<span id="cb9-10"></span>
<span id="cb9-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Based on the above information, which of the following options is correct?</span></span>
<span id="cb9-12"></span>
<span id="cb9-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">A – Jacob cannot be held accountable for the death of Sarah, as he simply tried to take her bag.</span></span>
<span id="cb9-14"></span>
<span id="cb9-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">B – Jacob and Henry will be charged with attempted robbery, but not in the death of Sarah.</span></span>
<span id="cb9-16"></span>
<span id="cb9-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">C – Jacob and Henry could be considered liable for the death of Sarah.</span></span>
<span id="cb9-18"></span>
<span id="cb9-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">D – Sarah’s death cannot be blamed on Henry and Jacob, as it was her choice to run away."""</span></span>
<span id="cb9-20"></span>
<span id="cb9-21">answer_sergeant_exam_question(df,question)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>'C - The answer is C because Jacob and Henry could be considered liable for the death of Sarah, as they were the ones who initiated the attack and chased her, which led to her tripping and hitting her head.'</code></pre>
</div>
</div>
<p>The answer both should have been C, so that’s 50/50 for CopBot… not bad! You can see it’s referring to to relevant guidance, but sadly that doesn’t really help you pass a promotion exam (though I suspect it would do seriously well trained on a bank of questions instead).</p>
</section>
<section id="so-does-it-work" class="level2">
<h2 class="anchored" data-anchor-id="so-does-it-work">So does it work?</h2>
<p>Before we test our model on fictional missing scenarios, I made one last tweak: I’ve amended the prompt to explictly refer to identified risk factors, and return them in a given format - you can see how it works below.</p>
<div id="cell-11" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">margaret_risk_profile <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""" Margaret is a 97 year old woman with severe dementia from Twickenham. She lives in supported accomodation, but regularly goes missing, as she walks out when left unsupervised.</span></span>
<span id="cb11-2"></span>
<span id="cb11-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">She has been missing 6 hours, and it is now 2200.  It is getting dark, and staff are saying she is rarely missing this long"""</span></span>
<span id="cb11-4"></span>
<span id="cb11-5">margaret_answer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> machine_risk_assessment(margaret_risk_profile, df, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb11-6">margaret_answer</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Question:
 Margaret is a 97 year old woman with severe dementia from Twickenham. She lives in supported accomodation, but regularly goes missing, as she walks out when left unsupervised.

She has been missing 6 hours, and it is now 2200.  It is getting dark, and staff are saying she is rarely missing this long
Context:
.police.uk research projects maximizing effectiveness police scotland investigations when people living dementia go missing.            Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing | College of Policing             Sorry, you need to enable JavaScript to visit this website.    Skip to content Jump to search         Menu      Secondary navigation About us News &amp; views Contact us  Search Search     Main navigation Policing guidance Research Career &amp; learning Support for forces Ethics     Breadcrumb Home Research Research projects map           Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing            Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing         On this page     This research aims to explore the effectiveness of searches for people living with dementia who are reported as missing. Key details             Lead institution            Queen Margaret University             Principal researcher(s)            Alistair Shields [email&nbsp;protected]             Police region                   Scotland                    Level of research                   PhD                    Project start date            September 2018             Date due for completion            January 2023  Research context In Scotland annually there are approximately 530 missing person incidents reported to the police for people living with dementia. These incidents are emotionally distressing for the families and caregivers who do not know the whereabouts of the reported person. For the person living with dementia the consequences of being missing worsen with the passage of time. It has been suggested that when reported as missing the person travels toward a place orientated to their past. The knowledge of such locations to inform police investigations, when someone is reported as missing, is commonly not available. Aim For people living with dementia who are reported as missing to improve search effectiveness by better defining areas where police should search.

###

 First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see&nbsp;APP&nbsp;on international investigation&nbsp;for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see&nbsp;Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child&nbsp; Voice of the child practice briefing&nbsp; Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children&nbsp;may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,&nbsp;as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to&nbsp;work with all the agencies and carers&nbsp;that&nbsp;have been&nbsp;in regular contact with the child as they&nbsp;may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.

###

Threshold for referral of missing persons: the individual is a ‘repeat missing person’, (reported as missing three times in a rolling 90 day period) the individual has experienced, or is likely to experience significant harm for children, the parent or carer appears unable or unwilling to work to support and meet the needs of a child that has gone missing. The&nbsp;Protection Procedures&nbsp;also recommend that there is very close working between children's social care and policing to ensure that all investigations are undertaken efficiently and without duplication of effort. Where appropriate, a multi-agency meeting is convened after a child has been missing from home or care for more than seven days, or has been missing on more than three occasions in a twelve month period. While standard thresholds for referral may be useful, senior officers will want to be sure that a process is in place to ensure cases are recognised which may require a greater safeguarding response before the threshold has been reached. For example, individuals reported missing for the first time where significant risks have been identified should be referred immediately for multi-agency support, without requiring further reports. For further information see&nbsp;HM Government (2018) Working together to safeguard children: A guide to inter-agency working to safeguard and promote the welfare of children. Prevention and intervention strategies Collecting and analysing data about cases will help the police and other agencies to understand whether there are any patterns related to missing persons incidents. The results of routine data analysis should be shared to inform the development and review of prevention and intervention strategies. Missing Persons Coordinators are vital for this information analysis and sharing. Interventions might include, for example, the use of&nbsp;Child Abduction Warning Notices, or referrals to support services. It is important that such interventions take place in appropriate circumstances and are not used as a single response when a person is at risk of harm, but form one strand of a more comprehensive approach. Regular liaison between neighbourhood policing teams and children’s and adults’ care providers may enable relationships to be developed between police officers, the staff of care establishments, and individuals who are looked after. These relationships may then support effective police intervention and the speedy resolution of cases. For lessons from other cases, see&nbsp;IOPC&nbsp;Learning the Lesson. Understanding the reasons for going missing Understanding the reasons why an individual went missing may help to prevent future harm to those individuals. The officers in charge of local areas should have clear plans on how they intend to reduce the number of people who go missing in their area.

###

It’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of&nbsp;the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?'&nbsp; Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>('Graded as High risk, because of the below risk factors: \n- Margaret is 97 years old and has severe dementia, making her more vulnerable to harm\n- She has been missing for 6 hours, which is longer than usual, and it is now dark outside, increasing the risk of harm',
 ".police.uk research projects maximizing effectiveness police scotland investigations when people living dementia go missing.            Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing | College of Policing             Sorry, you need to enable JavaScript to visit this website.    Skip to content Jump to search         Menu      Secondary navigation About us News &amp; views Contact us  Search Search     Main navigation Policing guidance Research Career &amp; learning Support for forces Ethics     Breadcrumb Home Research Research projects map           Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing            Maximizing the effectiveness of Police Scotland investigations when people living with dementia go missing         On this page     This research aims to explore the effectiveness of searches for people living with dementia who are reported as missing. Key details             Lead institution            Queen Margaret University             Principal researcher(s)            Alistair Shields [email\xa0protected]             Police region                   Scotland                    Level of research                   PhD                    Project start date            September 2018             Date due for completion            January 2023  Research context In Scotland annually there are approximately 530 missing person incidents reported to the police for people living with dementia. These incidents are emotionally distressing for the families and caregivers who do not know the whereabouts of the reported person. For the person living with dementia the consequences of being missing worsen with the passage of time. It has been suggested that when reported as missing the person travels toward a place orientated to their past. The knowledge of such locations to inform police investigations, when someone is reported as missing, is commonly not available. Aim For people living with dementia who are reported as missing to improve search effectiveness by better defining areas where police should search.\n\n###\n\n First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see\xa0APP\xa0on international investigation\xa0for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see\xa0Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child\xa0 Voice of the child practice briefing\xa0 Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children\xa0may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,\xa0as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to\xa0work with all the agencies and carers\xa0that\xa0have been\xa0in regular contact with the child as they\xa0may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.\n\n###\n\nThreshold for referral of missing persons: the individual is a ‘repeat missing person’, (reported as missing three times in a rolling 90 day period) the individual has experienced, or is likely to experience significant harm for children, the parent or carer appears unable or unwilling to work to support and meet the needs of a child that has gone missing. The\xa0Protection Procedures\xa0also recommend that there is very close working between children's social care and policing to ensure that all investigations are undertaken efficiently and without duplication of effort. Where appropriate, a multi-agency meeting is convened after a child has been missing from home or care for more than seven days, or has been missing on more than three occasions in a twelve month period. While standard thresholds for referral may be useful, senior officers will want to be sure that a process is in place to ensure cases are recognised which may require a greater safeguarding response before the threshold has been reached. For example, individuals reported missing for the first time where significant risks have been identified should be referred immediately for multi-agency support, without requiring further reports. For further information see\xa0HM Government (2018) Working together to safeguard children: A guide to inter-agency working to safeguard and promote the welfare of children. Prevention and intervention strategies Collecting and analysing data about cases will help the police and other agencies to understand whether there are any patterns related to missing persons incidents. The results of routine data analysis should be shared to inform the development and review of prevention and intervention strategies. Missing Persons Coordinators are vital for this information analysis and sharing. Interventions might include, for example, the use of\xa0Child Abduction Warning Notices, or referrals to support services. It is important that such interventions take place in appropriate circumstances and are not used as a single response when a person is at risk of harm, but form one strand of a more comprehensive approach. Regular liaison between neighbourhood policing teams and children’s and adults’ care providers may enable relationships to be developed between police officers, the staff of care establishments, and individuals who are looked after. These relationships may then support effective police intervention and the speedy resolution of cases. For lessons from other cases, see\xa0IOPC\xa0Learning the Lesson. Understanding the reasons for going missing Understanding the reasons why an individual went missing may help to prevent future harm to those individuals. The officers in charge of local areas should have clear plans on how they intend to reduce the number of people who go missing in their area.\n\n###\n\nIt’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of\xa0the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?'\xa0 Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.")</code></pre>
</div>
</div>
<div id="cell-12" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1">about_james <span class="op" 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="cb14-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">James is a 34 year old man, who was reported missing by his wife this evening as he has not returned home from work. It is now 2200, and she expected him home by 1900.</span></span>
<span id="cb14-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">She says while he does go out for drinks after work sometimes, he has not been out this late before, and his phone is off.</span></span>
<span id="cb14-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">James is in good health, there are no mental health concerns or other vulnerabilities. The weather is good, and his friend from work said he'd probably just gone out for drinks.</span></span>
<span id="cb14-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb14-6"></span>
<span id="cb14-7">james_answer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> machine_risk_assessment(about_james, df, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb14-8">james_answer</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Question:
 
James is a 34 year old man, who was reported missing by his wife this evening as he has not returned home from work. It is now 2200, and she expected him home by 1900.
She says while he does go out for drinks after work sometimes, he has not been out this late before, and his phone is off.
James is in good health, there are no mental health concerns or other vulnerabilities. The weather is good, and his friend from work said he'd probably just gone out for drinks.

Context:
 First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see&nbsp;APP&nbsp;on international investigation&nbsp;for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see&nbsp;Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child&nbsp; Voice of the child practice briefing&nbsp; Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children&nbsp;may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,&nbsp;as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to&nbsp;work with all the agencies and carers&nbsp;that&nbsp;have been&nbsp;in regular contact with the child as they&nbsp;may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.

###

 First published 22 November 2016  Updated 16 February 2023   Latest changes  Written by College of Policing  Missing persons  11 mins read   Introduction Going missing should be treated as an indicator that the individual may be at risk of harm. The safeguarding of vulnerable people is paramount and a missing person report should be recognised as an opportunity to identify and address risks. The reasons for a person deciding to go missing may be complex and linked to a variety of social or family issues. Three key factors should be considered in a missing person investigation: protecting those at risk of harm minimising distress and ensuring high quality of service to the families and carers of missing persons prosecuting those who perpetrate harm or pose a risk of harm when this is appropriate and supported by evidence Support for law enforcement agencies Police investigators can contact the following specialists for advice and assistance in missing and unidentified person investigations. UK Missing Persons Unit (UKMPU) on 0800&nbsp;234 6034 NCA&nbsp;Major Crime Investigative Support (MCIS) on 0345 000 5463 Definition of ‘missing’ Anyone whose whereabouts cannot be established will be considered as missing until located, and their well-being or otherwise confirmed. All reports of missing people sit within a continuum of risk from ‘no apparent risk (absent)’ through to high-risk cases&nbsp;that require immediate, intensive action.  Risk assessment and response The risk assessment table The following table should be used as a guide to&nbsp;an appropriate level of police response based on initial and on-going risk assessment in each case. Risk assessment should be guided by the College of Policing&nbsp;Risk principles,&nbsp;the&nbsp;National Decision Model&nbsp;and Police&nbsp;Code of Ethics. No apparent risk (absent) There is no apparent risk of harm to either the subject or the public. Actions to locate the subject and/or gather further information should be agreed with the informant and a latest review time set to reassess the risk. Low risk The risk of harm to the subject or the public is assessed as possible but minimal. Proportionate enquiries should be carried out to ensure that the individual has not come to harm. Medium risk The risk of harm to the subject or the public is assessed as likely but not serious. This category requires an active and measured response by the police and other agencies in order to trace the missing person and support the person reporting.

###

High risk The risk of serious harm to the subject or the public is assessed as very likely. This category almost always requires the immediate deployment of police resources – action may be delayed in exceptional circumstances, such as searching water or forested areas during hours of darkness. A member of the senior management team must be involved in the examination of initial lines of enquiry and approval of appropriate staffing levels. Such cases should lead to the appointment of an investigating officer (IO) and possibly an&nbsp;SIO, and a police search adviser (PolSA).            &nbsp; There should be a press/media strategy and/or close contact with outside agencies. Family support should be put in place where appropriate. The UKMPU&nbsp;should be notified of the case without undue delay. Children’s services must also be notified immediately if the person is under 18. Risk of serious harm has been defined as (Home Office 2002 and OASys 2006): A risk which is life threatening and/or traumatic, and from which recovery, whether physical or psychological, can be expected to be difficult or impossible. Where the risk cannot be accurately assessed without active investigation, appropriate lines of enquiry should be set to gather the required information to inform the risk assessment. The missing persons process chart  Joint responsibility The police are entitled to expect parents and carers, including staff acting in a parenting role in care homes, to accept normal parenting responsibilities and undertake reasonable actions to try and establish the whereabouts of the individual. Children who are breaching parental discipline should not be dealt with by police unless there are other risks. For example, a child who is late home from a party should not be regarded as missing until the parent or carer has undertaken enquiries to locate the child. Once those enquiries have been completed, it may be appropriate to record the child as missing and take actions set out in this&nbsp;APP. Parents or carers may need police support if they are very distressed, incapacitated or otherwise unable to undertake enquiries. In such circumstances, it may be appropriate to make a referral to the local authority so that the standard of care for the missing person can be reviewed. Individuals whose whereabouts are known will not be considered as missing, but may require other police activity in order to ensure their welfare. Police should consult their local public protection procedures to ensure an appropriate safeguarding response is provided.


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="12">
<pre><code>('Graded as Medium risk, because of the below risk factors:\n- James has not returned home at the expected time, and his phone is off\n- There is no indication of any mental health concerns or other vulnerabilities that could put him at risk',
 ' First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see\xa0APP\xa0on international investigation\xa0for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see\xa0Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child\xa0 Voice of the child practice briefing\xa0 Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children\xa0may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,\xa0as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to\xa0work with all the agencies and carers\xa0that\xa0have been\xa0in regular contact with the child as they\xa0may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.\n\n###\n\n First published 22 November 2016  Updated 16 February 2023   Latest changes  Written by College of Policing  Missing persons  11 mins read   Introduction Going missing should be treated as an indicator that the individual may be at risk of harm. The safeguarding of vulnerable people is paramount and a missing person report should be recognised as an opportunity to identify and address risks. The reasons for a person deciding to go missing may be complex and linked to a variety of social or family issues. Three key factors should be considered in a missing person investigation: protecting those at risk of harm minimising distress and ensuring high quality of service to the families and carers of missing persons prosecuting those who perpetrate harm or pose a risk of harm when this is appropriate and supported by evidence Support for law enforcement agencies Police investigators can contact the following specialists for advice and assistance in missing and unidentified person investigations. UK Missing Persons Unit (UKMPU) on 0800\xa0234 6034 NCA\xa0Major Crime Investigative Support (MCIS) on 0345 000 5463 Definition of ‘missing’ Anyone whose whereabouts cannot be established will be considered as missing until located, and their well-being or otherwise confirmed. All reports of missing people sit within a continuum of risk from ‘no apparent risk (absent)’ through to high-risk cases\xa0that require immediate, intensive action.  Risk assessment and response The risk assessment table The following table should be used as a guide to\xa0an appropriate level of police response based on initial and on-going risk assessment in each case. Risk assessment should be guided by the College of Policing\xa0Risk principles,\xa0the\xa0National Decision Model\xa0and Police\xa0Code of Ethics. No apparent risk (absent) There is no apparent risk of harm to either the subject or the public. Actions to locate the subject and/or gather further information should be agreed with the informant and a latest review time set to reassess the risk. Low risk The risk of harm to the subject or the public is assessed as possible but minimal. Proportionate enquiries should be carried out to ensure that the individual has not come to harm. Medium risk The risk of harm to the subject or the public is assessed as likely but not serious. This category requires an active and measured response by the police and other agencies in order to trace the missing person and support the person reporting.\n\n###\n\nHigh risk The risk of serious harm to the subject or the public is assessed as very likely. This category almost always requires the immediate deployment of police resources – action may be delayed in exceptional circumstances, such as searching water or forested areas during hours of darkness. A member of the senior management team must be involved in the examination of initial lines of enquiry and approval of appropriate staffing levels. Such cases should lead to the appointment of an investigating officer (IO) and possibly an\xa0SIO, and a police search adviser (PolSA). \t\t\t\xa0 There should be a press/media strategy and/or close contact with outside agencies. Family support should be put in place where appropriate. The UKMPU\xa0should be notified of the case without undue delay. Children’s services must also be notified immediately if the person is under 18. Risk of serious harm has been defined as (Home Office 2002 and OASys 2006): A risk which is life threatening and/or traumatic, and from which recovery, whether physical or psychological, can be expected to be difficult or impossible. Where the risk cannot be accurately assessed without active investigation, appropriate lines of enquiry should be set to gather the required information to inform the risk assessment. The missing persons process chart  Joint responsibility The police are entitled to expect parents and carers, including staff acting in a parenting role in care homes, to accept normal parenting responsibilities and undertake reasonable actions to try and establish the whereabouts of the individual. Children who are breaching parental discipline should not be dealt with by police unless there are other risks. For example, a child who is late home from a party should not be regarded as missing until the parent or carer has undertaken enquiries to locate the child. Once those enquiries have been completed, it may be appropriate to record the child as missing and take actions set out in this\xa0APP. Parents or carers may need police support if they are very distressed, incapacitated or otherwise unable to undertake enquiries. In such circumstances, it may be appropriate to make a referral to the local authority so that the standard of care for the missing person can be reviewed. Individuals whose whereabouts are known will not be considered as missing, but may require other police activity in order to ensure their welfare. Police should consult their local public protection procedures to ensure an appropriate safeguarding response is provided.')</code></pre>
</div>
</div>
<div id="cell-13" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">about_yannik <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""" Yannik is a 15 year old boy. He has recently been down, and was reported missing by his parents as he did not return home from school today.</span></span>
<span id="cb17-2"></span>
<span id="cb17-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">His friends are worried he may be depressed, and when he apparently told one a few days ago 'if it doesn't get any better, I'm going to end it soon'</span></span>
<span id="cb17-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb17-5"></span>
<span id="cb17-6">yannik_answer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> machine_risk_assessment(about_yannik, df, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb17-7">yannik_answer</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Question:
 Yannik is a 15 year old boy. He has recently been down, and was reported missing by his parents as he did not return home from school today.

His friends are worried he may be depressed, and when he apparently told one a few days ago 'if it doesn't get any better, I'm going to end it soon'

Context:
 First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see&nbsp;APP&nbsp;on international investigation&nbsp;for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see&nbsp;Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child&nbsp; Voice of the child practice briefing&nbsp; Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children&nbsp;may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,&nbsp;as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to&nbsp;work with all the agencies and carers&nbsp;that&nbsp;have been&nbsp;in regular contact with the child as they&nbsp;may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.

###

It’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of&nbsp;the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?'&nbsp; Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.

###

Police officers should ask the care home or local authority for details of the child’s risk assessment so that it can be taken into account during the investigation.&nbsp;Many forces are using the Philomena Protocol to guide their actions in relation to relevant cases involving children. A child, especially a teenager, is unlikely to share all information about their life with their parents or carers. Investigators should not overlook information from siblings, friends, associates, school teachers and others. The online activity of the child may also provide valuable additional information which parents and carers may not be aware of. For further information see: Children's views on being reported missing from care&nbsp; No Place at Home - Risks facing children and young people who go missing from out of area placements Child Rescue Alert Child Rescue Alert&nbsp;(CRA) – (available to authorised users logged on to the restricted online&nbsp;College Learn) is a partnership between the police and the media which seeks public assistance when it is feared that a child may be at risk of serious harm. Assistance is sought via TV, radio, text messaging, social and digital media (including the internet) so that relevant information relating to the child, offender or any specified vehicle is passed on to the police. CRA&nbsp;focuses on the risk to the child, rather than whether or not an offence has taken place. The criteria for launching an alert is: The child is apparently under 18 years old There is a perception that the child is in imminent danger of serious harm or death There is sufficient information available to enable the public to assist police in locating the child Child Rescue Alert Activation Protocol&nbsp;(available to authorised users logged on to the restricted online&nbsp;College Learn) The&nbsp;CRA&nbsp;has been expanded to enable alerts to be disseminated by the charity Missing People. The system is managed by the National Crime&nbsp;Agency (NCA) and specialist advice is available 24/7 by contacting 0800&nbsp;234 6034.

###

This is particularly true to the Greater Manchester area. As a result, this research seeks to utilise this appeal in providing a platform for young people who have received a Threats to Life Notice and children to parents who have received a Threat to Life Notice, in order to steer them away from potential criminal activity and receive mentoring through football coaching, education and employability skills. Operationally, this would seek to provide tactical options in the short and long-term in instances where a young person (under the age of 18) is particularly vulnerable as either a victim or perpetrator of criminal behaviour, and potentially reduce the threat, risk and harm pertaining to such individuals. The key aims are: to develop the individuals in the cohort with regards to qualifications, personal wellbeing, skill development, employability and social action (part of their local community and their perception of their community) – this in turn will potentially reduce the impact of trauma and increase confidence and self-esteem of the cohort to reduce the effects of adverse childhood experiences through re-sensitisation and raising awareness that adverse childhood experiences should not be considered the norm to understand and improve the delivery and impact of Threats to Life on young people to inform police forces on the best possible process and follow-on actions needed when delivering Threats to Life Notices  Research methodology A cohort of 16 young people between the ages of 13 to 18 will be identified through GMP’s systems who have either directly received a Threat to Life Notice in the past 12 months, or are children to a parent(s) who have received a Threat to Life Notice in the past 12 months. Their details will then be given to the mentors at the Manchester United Youth Foundation who then make contact through post in the first instance to invite the young person into the scheme. More individuals will be invited into the scheme as it progresses to ensure a minimum of 16 participants at any given stage (catering for any refusals to be involved or disengagement).


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>('Graded as High risk, because of the below risk factors: \n- Yannik is a 15 year old boy who has been reported missing by his parents\n- His friends are worried he may be depressed\n- He has expressed suicidal ideation to one of his friends',
 " First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see\xa0APP\xa0on international investigation\xa0for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see\xa0Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child\xa0 Voice of the child practice briefing\xa0 Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children\xa0may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,\xa0as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to\xa0work with all the agencies and carers\xa0that\xa0have been\xa0in regular contact with the child as they\xa0may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.\n\n###\n\nIt’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of\xa0the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?'\xa0 Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.\n\n###\n\nPolice officers should ask the care home or local authority for details of the child’s risk assessment so that it can be taken into account during the investigation.\xa0Many forces are using the Philomena Protocol to guide their actions in relation to relevant cases involving children. A child, especially a teenager, is unlikely to share all information about their life with their parents or carers. Investigators should not overlook information from siblings, friends, associates, school teachers and others. The online activity of the child may also provide valuable additional information which parents and carers may not be aware of. For further information see: Children's views on being reported missing from care\xa0 No Place at Home - Risks facing children and young people who go missing from out of area placements Child Rescue Alert Child Rescue Alert\xa0(CRA) – (available to authorised users logged on to the restricted online\xa0College Learn) is a partnership between the police and the media which seeks public assistance when it is feared that a child may be at risk of serious harm. Assistance is sought via TV, radio, text messaging, social and digital media (including the internet) so that relevant information relating to the child, offender or any specified vehicle is passed on to the police. CRA\xa0focuses on the risk to the child, rather than whether or not an offence has taken place. The criteria for launching an alert is: The child is apparently under 18 years old There is a perception that the child is in imminent danger of serious harm or death There is sufficient information available to enable the public to assist police in locating the child Child Rescue Alert Activation Protocol\xa0(available to authorised users logged on to the restricted online\xa0College Learn) The\xa0CRA\xa0has been expanded to enable alerts to be disseminated by the charity Missing People. The system is managed by the National Crime\xa0Agency (NCA) and specialist advice is available 24/7 by contacting 0800\xa0234 6034.\n\n###\n\nThis is particularly true to the Greater Manchester area. As a result, this research seeks to utilise this appeal in providing a platform for young people who have received a Threats to Life Notice and children to parents who have received a Threat to Life Notice, in order to steer them away from potential criminal activity and receive mentoring through football coaching, education and employability skills. Operationally, this would seek to provide tactical options in the short and long-term in instances where a young person (under the age of 18) is particularly vulnerable as either a victim or perpetrator of criminal behaviour, and potentially reduce the threat, risk and harm pertaining to such individuals. The key aims are: to develop the individuals in the cohort with regards to qualifications, personal wellbeing, skill development, employability and social action (part of their local community and their perception of their community) – this in turn will potentially reduce the impact of trauma and increase confidence and self-esteem of the cohort to reduce the effects of adverse childhood experiences through re-sensitisation and raising awareness that adverse childhood experiences should not be considered the norm to understand and improve the delivery and impact of Threats to Life on young people to inform police forces on the best possible process and follow-on actions needed when delivering Threats to Life Notices  Research methodology A cohort of 16 young people between the ages of 13 to 18 will be identified through GMP’s systems who have either directly received a Threat to Life Notice in the past 12 months, or are children to a parent(s) who have received a Threat to Life Notice in the past 12 months. Their details will then be given to the mentors at the Manchester United Youth Foundation who then make contact through post in the first instance to invite the young person into the scheme. More individuals will be invited into the scheme as it progresses to ensure a minimum of 16 participants at any given stage (catering for any refusals to be involved or disengagement).")</code></pre>
</div>
</div>
<div id="cell-14" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1">jason_risk_profile <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""" Jason is a 15 year old adult male, who has gone missing from his care home in Southwark. His carer has contacted the school, which has said he was not in today.</span></span>
<span id="cb20-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">They that this is not the first time, and that Jason has been seen hanging out with older boys, who may be involved in crime and drugs."""</span></span>
<span id="cb20-3"></span>
<span id="cb20-4"></span>
<span id="cb20-5">jason_answer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> machine_risk_assessment(jason_risk_profile, df, debug<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb20-6">jason_answer</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Question:
 Jason is a 15 year old adult male, who has gone missing from his care home in Southwark. His carer has contacted the school, which has said he was not in today.
They that this is not the first time, and that Jason has been seen hanging out with older boys, who may be involved in crime and drugs.
Context:
 First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see&nbsp;APP&nbsp;on international investigation&nbsp;for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see&nbsp;Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child&nbsp; Voice of the child practice briefing&nbsp; Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children&nbsp;may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,&nbsp;as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to&nbsp;work with all the agencies and carers&nbsp;that&nbsp;have been&nbsp;in regular contact with the child as they&nbsp;may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.

###

These include children or young people who: go missing&nbsp;– especially on regular occasions from home or care live in a chaotic or dysfunctional family have a history of domestic abuse within the family environment have a history of abuse (including familial&nbsp;child sexual abuse, risk of&nbsp;forced marriage, risk of&nbsp;honour-based violence,&nbsp;physical&nbsp;and&nbsp;emotional&nbsp;abuse and&nbsp;neglect) have experienced or are experiencing problematic parenting have parents who misuse drugs or alcohol have parents with health problems are young carers within the family unit experience social exclusion as a result of poverty have experienced recent bereavement or loss have unsupervised use of social networking chat rooms/sites have mental ill health have social or learning difficulties have low self-esteem or self-confidence are unsure about their sexual orientation or are unable to confide in their family about their sexual orientation misuse alcohol and/or drugs have been or are excluded from mainstream education are involved in gang activity attend school with other young people who are sexually exploited are friends with individuals who are sexually exploited do not have friends in the same age group are being bullied live in care, foster care, hostels and/or bed and breakfast accommodation – particularly when living out of their home area are homeless have associations with gangs through relatives, peers or intimate relationships live in a gang neighbourhood This is not an exhaustive list, nor have the vulnerabilities been listed in order of importance. Children from loving and secure homes can also be victims of sexual exploitation. The&nbsp;characteristics common to all victims are not always their age, ethnicity, disability or sexual orientation, but their powerlessness and vulnerability. Warning signs Despite the increased profile of&nbsp;CSE&nbsp;and improvements in how the police work with partner agencies,&nbsp;CSE&nbsp;cases are still under-reported. The Office of the Children’s Commissioner conducted a two-year inquiry into child sexual exploitation in gangs and groups. Their 2013&nbsp;report,&nbsp;If only someone had listened, highlights that sexually exploited children are not always identified even when they show signs of being victims. Numerous warning signs were identified in the Office of the Children’s Commissioner 2012 interim report,&nbsp;I thought I was the only one, the only one in the world, which can indicate that&nbsp;a young person is being forced or manipulated into sexual activity and is a victim of sexual exploitation. Practitioners need to be aware of these warning signs and recognise that a victim does not&nbsp;have to exhibit all of the warning signs to be a victim of sexual exploitation.

###

Staff should tell the detainee that she can ask to see the carer at any time. Forces must implement policies and procedures to ensure that all girls who are detained and in custody are under the care of a woman. For further information, see&nbsp;PACE Code C, section 3.20A. Transporting children and young people Children and young persons under the age of 18 are not allowed to associate with adult detainees while being detained, conveyed to and from court or waiting to be so conveyed. An exception to this is permitted in accordance with the Children and Young Persons Act 1933 section 31, where the young person is jointly charged with an adult or relative. Officers should make arrangements to prevent association when the child or young person is: detained in a police station being conveyed to or from any criminal court attending court Children and young people should not be carried in a vehicle with adult detainees unless the vehicle has been designed and built to carry them separately and simultaneously. Vehicles that are available for this specific purpose are authorised under the 2011 Prisoner Escort and Custody Services’ contract arrangements. Appropriate adults Forces should establish policies and protocols to provide access to appropriate adults for young persons in police custody. Local YOTs have a statutory responsibility to ensure that an appropriate adult service is provided for children and young people, whether they provide the service themselves or contract a voluntary or private sector agency to do so on their behalf. It is the responsibility of the appropriate adult provider to work with the local force to develop policies and protocols to ensure there is effective provision of appropriate adult services in line with Youth Justice Board (2014) case management guidance. This guidance makes it clear that the appropriate adult service should operate out of hours as well as during standard working hours. All appropriate adults, custody managers, custody officers and staff must be aware of their role as defined by PACE, and also of any agreed local policies, protocols or service level agreements for providing appropriate adults. For further information, see PACE and section 38 of the Crime and Disorder Act 1998. See also the Youth Justice Board’s (YJB) National Standards for Youth Justice Services. The YJB and National Appropriate Adult Network have also published joint guidance and advice on appropriate adult services. When should an appropriate adult be contacted? Detention can be very stressful so it is important that an appropriate adult attends as soon as is practicable to minimise the amount of time the child or young person spends in detention.


</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>('Graded as Medium risk, because of the below risk factors: \n- Jason is a 15 year old adult male, who has gone missing from his care home in Southwark\n- This is not the first time he has gone missing\n- He has been seen hanging out with older boys, who may be involved in crime and drugs',
 ' First published 22 November 2016  Updated 15 March 2023   Latest changes  Written by College of Policing  Missing persons  30 mins read   Implications for the UK leaving the European Union are currently under review – please see\xa0APP\xa0on international investigation\xa0for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see\xa0Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child\xa0 Voice of the child practice briefing\xa0 Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children\xa0may put themselves in danger because they may have been abused, neglected or rejected by their families or others and,\xa0as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to\xa0work with all the agencies and carers\xa0that\xa0have been\xa0in regular contact with the child as they\xa0may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.\n\n###\n\nThese include children or young people who: go missing\xa0– especially on regular occasions from home or care live in a chaotic or dysfunctional family have a history of domestic abuse within the family environment have a history of abuse (including familial\xa0child sexual abuse, risk of\xa0forced marriage, risk of\xa0honour-based violence,\xa0physical\xa0and\xa0emotional\xa0abuse and\xa0neglect) have experienced or are experiencing problematic parenting have parents who misuse drugs or alcohol have parents with health problems are young carers within the family unit experience social exclusion as a result of poverty have experienced recent bereavement or loss have unsupervised use of social networking chat rooms/sites have mental ill health have social or learning difficulties have low self-esteem or self-confidence are unsure about their sexual orientation or are unable to confide in their family about their sexual orientation misuse alcohol and/or drugs have been or are excluded from mainstream education are involved in gang activity attend school with other young people who are sexually exploited are friends with individuals who are sexually exploited do not have friends in the same age group are being bullied live in care, foster care, hostels and/or bed and breakfast accommodation – particularly when living out of their home area are homeless have associations with gangs through relatives, peers or intimate relationships live in a gang neighbourhood This is not an exhaustive list, nor have the vulnerabilities been listed in order of importance. Children from loving and secure homes can also be victims of sexual exploitation. The\xa0characteristics common to all victims are not always their age, ethnicity, disability or sexual orientation, but their powerlessness and vulnerability. Warning signs Despite the increased profile of\xa0CSE\xa0and improvements in how the police work with partner agencies,\xa0CSE\xa0cases are still under-reported. The Office of the Children’s Commissioner conducted a two-year inquiry into child sexual exploitation in gangs and groups. Their 2013\xa0report,\xa0If only someone had listened, highlights that sexually exploited children are not always identified even when they show signs of being victims. Numerous warning signs were identified in the Office of the Children’s Commissioner 2012 interim report,\xa0I thought I was the only one, the only one in the world, which can indicate that\xa0a young person is being forced or manipulated into sexual activity and is a victim of sexual exploitation. Practitioners need to be aware of these warning signs and recognise that a victim does not\xa0have to exhibit all of the warning signs to be a victim of sexual exploitation.\n\n###\n\nStaff should tell the detainee that she can ask to see the carer at any time. Forces must implement policies and procedures to ensure that all girls who are detained and in custody are under the care of a woman. For further information, see\xa0PACE Code C, section 3.20A. Transporting children and young people Children and young persons under the age of 18 are not allowed to associate with adult detainees while being detained, conveyed to and from court or waiting to be so conveyed. An exception to this is permitted in accordance with the Children and Young Persons Act 1933 section 31, where the young person is jointly charged with an adult or relative. Officers should make arrangements to prevent association when the child or young person is: detained in a police station being conveyed to or from any criminal court attending court Children and young people should not be carried in a vehicle with adult detainees unless the vehicle has been designed and built to carry them separately and simultaneously. Vehicles that are available for this specific purpose are authorised under the 2011 Prisoner Escort and Custody Services’ contract arrangements. Appropriate adults Forces should establish policies and protocols to provide access to appropriate adults for young persons in police custody. Local YOTs have a statutory responsibility to ensure that an appropriate adult service is provided for children and young people, whether they provide the service themselves or contract a voluntary or private sector agency to do so on their behalf. It is the responsibility of the appropriate adult provider to work with the local force to develop policies and protocols to ensure there is effective provision of appropriate adult services in line with Youth Justice Board (2014) case management guidance. This guidance makes it clear that the appropriate adult service should operate out of hours as well as during standard working hours. All appropriate adults, custody managers, custody officers and staff must be aware of their role as defined by PACE, and also of any agreed local policies, protocols or service level agreements for providing appropriate adults. For further information, see PACE and section 38 of the Crime and Disorder Act 1998. See also the Youth Justice Board’s (YJB) National Standards for Youth Justice Services. The YJB and National Appropriate Adult Network have also published joint guidance and advice on appropriate adult services. When should an appropriate adult be contacted? Detention can be very stressful so it is important that an appropriate adult attends as soon as is practicable to minimise the amount of time the child or young person spends in detention.')</code></pre>
</div>
</div>
<p>It’s honestly not too bad! while this certainly wouldn’t replace human decision making, it could certainly act as a safeguard against missing a key piece of information at three in the morning when you have a queue of 8 missing people to evaluate, each pages worth of history.</p>
<p>There are certainly some pretty major niggles you’d need to fix: for one I’m not sure how the model will perform given actual legislation, rather than “plain English” guidance, nor do I imagine it will cope particularly well with policing specific terminology. The risks it’s identified so far are all mostly obvious, rather than identifying one needle in a giant haystack of intelligence reports. It’s also all going through the OpenAI black-box servers, though I imagine that could be replaced with something open-ish like <a href="https://ai.facebook.com/blog/large-language-model-llama-meta-ai/">Llama</a> without too much effort. But when I consider where NLP was even 18 months ago, and just how much computing cognitive power we’ve been able to deploy in only a few hours…who knows where we’ll be next year?</p>


</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>policing</category>
  <category>AI</category>
  <category>data-science</category>
  <guid>https://andreasthinks.me/posts/Copbot/explainer.html</guid>
  <pubDate>Sun, 19 Mar 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>What’s Happened to Burglary, and does Attending Help?</title>
  <link>https://andreasthinks.me/posts/burglary_attendance/</link>
  <description><![CDATA[ 





<p>It’s nearly 2023, and in the true spirit of Christmas, I’ve used the cheese/wine filled nowhere time between the holidays to pick up an analytical side-project that’s been irking me for awhile… what’s happened to burglary, and why are we suddenly so excited about mandatory attendance? It’s a thorny question, so I figured I’d document my analysis here… All(ish) of the code is available, so this will hopefully be a useful tutorial for others. As usual, keep in mind this is a blog post, not an academic article - this analysis is fuelled by post-Christmas cheese, and peer reviewed by me after a glass of cherry, so if you want to rely on any of it, replicate it yourself first and make sure it’s right!</p>
<p>This took somewhat longer than I expected (hooray for Christmas breaks), so this will be a series in three parts:</p>
<ol type="1">
<li>Exploring the data and Linear Models (you’re here!)</li>
<li>Time Series (when I get the time)</li>
<li>Synthetic Controls (one day in the distant future)</li>
</ol>
<div style="page-break-after: always;"></div>
<p><strong>So come with me on an analytical adventure through time, as we cast our minds back to the halcyon days of 2015.</strong> The pound is worth $1.5 dollars again, Boris Johnson is Mayor of London, and we’re all still fondly thinking back to how great the London Olympics were.</p>
<p>Across policing, the effects of austerity are starting to be acutely felt - having briefly been protected, chief officers are tightening their fiscal belt: <a href="https://www.theguardian.com/uk-news/2017/jul/13/met-police-sold-1bn-of-property-to-soften-blow-of-budget-cuts">swathes of policing real estate are sold off</a> to protect the front-line, which in some places is <a href="https://www.ft.com/content/b3630ab0-3388-11e4-ba62-00144feabdc0">starting to rely on volunteers and goodwill</a> to avoid looking rather thin.</p>
<p>Meanwhile, crime is changing: traditional crimes like burglary and violence continue their to fall, leading the <a href="https://www.bbc.com/news/uk-32806520">soon-to-be Prime Minister Theresa May to tell the Police Federation to “stop crying wolf”</a> about cuts while demand shrinks, but policing certainly isn’t feeling it, as an increase in “high-harm”, complex offences more than made up for any shortfall.</p>
<div class="page-columns page-full"><p></p><div class="no-row-height column-margin column-container"><span class="margin-aside">The shift towards complex offences was, in my mind, largely unnoticed by the general public, but caused a real shift in core policing demands: traditional theft and violent offences had become ever rarer, while child exploitation, sexual assault and fraud reporting skyrocketted… but the latter group of offences require a far lengthier investigation than the former! The result? More demand, as best illustrated <a href="http://lesscrime.info/post/crime-pressure-force/">this wonderful graph by Matt Ashby</a></span></div></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/burglary_attendance/severity-plot.png" class="img-fluid figure-img"></p>
<figcaption>Matt Ashby’s excellent visualisation of crime pressures by time and force</figcaption>
</figure>
</div>
<p>In the face of these conflicting pressures, policing did something that seemed perfectly reasonable, <a href="https://www.telegraph.co.uk/news/2022/10/05/police-vow-attend-every-burglary/">announcing that officers may not attend every single burglary</a>.</p>
<p>Less than a decade later, we’re now on a very different course. <a href="https://rusi.org/explore-our-research/publications/commentary/public-confidence-police-new-low-service">Confidence in policing, which had previously seemed immutable, is down</a>. <a href="https://www.telegraph.co.uk/politics/2022/12/28/police-criticised-failing-solve-one-million-thefts-burglaries/">Investigative performance has seemingly falling off a cliff</a>. And so the NPCC has made the opposite commitment, <a href="https://news.npcc.police.uk/releases/all-home-burglaries-in-england-and-wales-will-be-attended-by-the-police">pledging that every home burglary will now see police attendance</a>, after <a href="https://www.dailymail.co.uk/news/article-10392721/Sending-police-officers-burglaries-cuts-number-offences-half-forces-find.html">forces who tested the approach claimed huge “dramatic” crime reductions.</a></p>
<p>But has performance really declined that quickly, and is attendance to blame? I’ll use this post to explore open police data from the last decade, and use data from pilot forces to see just how dramatic the effect is: <strong>just what’s happened to burglary, and will mandatory attendance help?</strong></p>
<section id="whats-happened-to-burglary" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="whats-happened-to-burglary">What’s Happened to Burglary?</h2>
<p>We’ll start by exploring how burglary has changed over time - for the purpose of this analysis, we’re focusing on domestic burglary (eg, non including commercial properties), and we’ll use both police recorded crime data (eg, crimes reported to police) and the Crime Survey of England and Wales (a national survey to measure total crime) to compare trends.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>On Data Quality
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>While the UK benefits from crime data that is comparatively clean (I do not envy our American cousins, let alone most of our colleagues in the rest of the world), this is less true for both historical data (eg, going back more than a few years) or the Crime Survey data, which <a href="https://www.crimesurvey.co.uk/en/SurveyResults.html">isn’t readily available to the general public</a>: the data is spread through various archive files, websites and reports, and there really isn’t a “single source of truth” for crime counts over time.</p>
<p>The data for this analysis is a few hacked togther files: - Crime outcomes and crime counts by quarter, manually concatenated from the <a href="https://www.gov.uk/government/statistics/police-recorded-crime-open-data-tables">Police Open Data Tables</a> - Crime Survey burglary counts per year, from the most recent <a href="https://www.ons.gov.uk/generator?uri=/peoplepopulationandcommunity/crimeandjustice/bulletins/crimeinenglandandwales/yearendingjune2022/153cc78c&amp;format=csv">ONS crime and justice quarterly</a></p>
<p>I’m afraid that does mean this analysis isn’t quite as reproducible as I’d like - I had written some code to scrape the Home Office data page and aggregate all the outcomes data, but it’s such a mishmash of ODS,XLSX and various formats that everything fell over and I did it manually. That said, hopefully it’s not too much of a pain to reproduce if you feel the need to.</p>
<p>A few caveats are worth considering:</p>
<ol type="1">
<li>The Crime Survey can’t always be easily compared to reported crime: police crime data is legal accounting, while the crime survey is asking the general public what happened. Domestic Burglary <em>should</em> be comparable, but this is all a little experimental.</li>
<li>Reproducibility and data cleaning: good analysis should be reproducible - you should be able to run it the same way, with new data. This isn’t true here because of my ugly cleaning.</li>
<li>Outcomes aren’t instant: Crimes take time to solve, and so the most recent outcomes data will probably change. I’ve used outcomes per quarter, which <em>should</em> work, but the most recent data is likely to change.</li>
</ol>
</div>
</div>
</div>
<div id="cell-2" class="cell" data-execution_count="1">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> plotly.express <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> px</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> plotly.subplots <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> make_subplots</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> plotly.graph_objects <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> go</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> patsy</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> statsmodels.api <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sm</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> plotly.io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pio</span>
<span id="cb1-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> linearmodels <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> PanelOLS</span>
<span id="cb1-9"></span>
<span id="cb1-10">pio.templates.default <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotly_dark"</span></span>
<span id="cb1-11"></span>
<span id="cb1-12"></span>
<span id="cb1-13">police_crime_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"../data/external/police_recorded_crime_combined.csv"</span>)</span>
<span id="cb1-14"></span>
<span id="cb1-15"></span>
<span id="cb1-16">yearly_police_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> police_crime_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial Year'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Number of Offences'</span>]].groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial Year'</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>().reset_index()</span>
<span id="cb1-17">yearly_police_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2002</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2023</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-18">yearly_police_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> yearly_police_df.rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of Offences"</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'police'</span>})</span>
<span id="cb1-19"></span>
<span id="cb1-20">csew_count <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"../data/external/csew_burglary_trends.csv"</span>).rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Domestic burglary'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'csew'</span>})</span>
<span id="cb1-21"></span>
<span id="cb1-22"></span>
<span id="cb1-23"></span>
<span id="cb1-24">csew_count[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2002</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-25">csew_count[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'csew'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> csew_count[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'csew'</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb1-26"></span>
<span id="cb1-27">comparison_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> csew_count.merge(yearly_police_df,how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'left'</span>,on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>).rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'csew'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>,</span>
<span id="cb1-28">                                                                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'police'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>})</span>
<span id="cb1-29"></span>
<span id="cb1-30">comparison_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>]].set_index(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb1-31"></span>
<span id="cb1-32"></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="1">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">Crime Survey</th>
<th data-quarto-table-cell-role="th">Police Reported</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">year</th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">2002</th>
<td>1423000</td>
<td>437583</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2003</th>
<td>1357000</td>
<td>402345</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2004</th>
<td>1310000</td>
<td>321507</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2005</th>
<td>1059000</td>
<td>300517</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2006</th>
<td>1025000</td>
<td>292260</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2007</th>
<td>1006000</td>
<td>280696</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2008</th>
<td>960000</td>
<td>284431</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2009</th>
<td>992000</td>
<td>268606</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2010</th>
<td>917000</td>
<td>258165</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2011</th>
<td>1033000</td>
<td>245312</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2012</th>
<td>922000</td>
<td>227276</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2013</th>
<td>887000</td>
<td>211988</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2014</th>
<td>781000</td>
<td>196554</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2015</th>
<td>784000</td>
<td>194700</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2016</th>
<td>697000</td>
<td>206051</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2017</th>
<td>650000</td>
<td>309867</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2018</th>
<td>691000</td>
<td>295556</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2019</th>
<td>699000</td>
<td>268715</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2020</th>
<td>582000</td>
<td>196214</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>The Crime Survey data is the best measure for long term crime trends - as it isn’t affected by reporting or policing practice. Taken in isolation, the most obvious takeaway here is that <strong>burglary is lower than it’s every been</strong>. If you acccept the Peelian view that <a href="https://en.wikipedia.org/wiki/Robert_Peel">“the test of police efficiency is the absence of crime and disorder”</a>, policing is doing an excellent job. So why is police reported crime comparatively high, and why are perceptions of police performance seemingly so low?</p>
<div id="cell-4" class="cell page-columns page-full" data-execution_count="2">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">tidy_yearly <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> comparison_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>]].melt(id_vars<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb2-2"></span>
<span id="cb2-3">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> px.line(tidy_yearly, x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'variable'</span>,color_discrete_sequence<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>])</span>
<span id="cb2-4"></span>
<span id="cb2-5">fig.update_layout(</span>
<span id="cb2-6">    title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Domestic Burglaries, Police Reported and Crime Survey"</span>,</span>
<span id="cb2-7">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(</span>
<span id="cb2-8">    orientation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>,</span>
<span id="cb2-9">    yanchor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb2-10">        y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>),</span>
<span id="cb2-11">)</span>
<span id="cb2-12"></span>
<span id="cb2-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set x-axis title</span></span>
<span id="cb2-14">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)</span>
<span id="cb2-15"></span>
<span id="cb2-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set y-axes titles</span></span>
<span id="cb2-17">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglaries"</span>)</span>
<span id="cb2-18"></span>
<span id="cb2-19">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page">
<div>                            <div id="64ef8b81-2f9a-4d36-91f7-aa0a30c3a813" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("64ef8b81-2f9a-4d36-91f7-aa0a30c3a813")) {                    Plotly.newPlot(                        "64ef8b81-2f9a-4d36-91f7-aa0a30c3a813",                        [{"hovertemplate":"variable=Crime Survey<br>year=%{x}<br>value=%{y}<extra></extra>","legendgroup":"Crime Survey","line":{"color":"red","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines","name":"Crime Survey","orientation":"v","showlegend":true,"x":[2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020],"xaxis":"x","y":[1423000,1357000,1310000,1059000,1025000,1006000,960000,992000,917000,1033000,922000,887000,781000,784000,697000,650000,691000,699000,582000],"yaxis":"y","type":"scatter"},{"hovertemplate":"variable=Police Reported<br>year=%{x}<br>value=%{y}<extra></extra>","legendgroup":"Police Reported","line":{"color":"blue","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines","name":"Police Reported","orientation":"v","showlegend":true,"x":[2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020],"xaxis":"x","y":[437583,402345,321507,300517,292260,280696,284431,268606,258165,245312,227276,211988,196554,194700,206051,309867,295556,268715,196214],"yaxis":"y","type":"scatter"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"Year"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Burglaries"}},"legend":{"title":{"text":"variable"},"tracegroupgap":0,"orientation":"h","yanchor":"bottom","y":-0.2},"margin":{"t":60},"title":{"text":"Domestic Burglaries, Police Reported and Crime Survey"}},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('64ef8b81-2f9a-4d36-91f7-aa0a30c3a813');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>Comparing Crime Survey to Police Recorded crime counts is generally considered bad form: while a police officer might always know the difference between a robbery, a burglary, and an affray to enable a theft, that’s not something most of the public worries about.</p>
<p>Thankfully, that shouldn’t be a problem for domestic burglary - most people know when they’ve been burgled! That means we can produce <strong>a ratio of crime survey burglaries to police burglaries, and obtain a rough estimate of what proportion of burglaries are reported to police over time.</strong></p>
<div id="cell-6" class="cell page-columns page-full" data-execution_count="3">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">comparison_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Proportion of Burglaries Reported'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> comparison_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> comparison_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb3-2"></span>
<span id="cb3-3">tidy_yearly <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> comparison_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Proportion of Burglaries Reported'</span>]].melt(id_vars<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb3-4"></span>
<span id="cb3-5"></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create figure with secondary y-axis</span></span>
<span id="cb3-7">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_subplots(specs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[[{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"secondary_y"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>}]])</span>
<span id="cb3-8"></span>
<span id="cb3-9">csew_burglary <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_yearly[tidy_yearly[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'variable'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>]</span>
<span id="cb3-10">police_burglary <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_yearly[tidy_yearly[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'variable'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>]</span>
<span id="cb3-11">reported_ratio <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_yearly[tidy_yearly[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'variable'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Proportion of Burglaries Reported'</span>]</span>
<span id="cb3-12"></span>
<span id="cb3-13"></span>
<span id="cb3-14"></span>
<span id="cb3-15">fig.add_trace(</span>
<span id="cb3-16">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>csew_burglary[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>csew_burglary[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crime Survey"</span>, line<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)),</span>
<span id="cb3-17">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb3-18">)</span>
<span id="cb3-19"></span>
<span id="cb3-20">fig.add_trace(</span>
<span id="cb3-21">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>police_burglary[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>police_burglary[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Reported"</span>, line<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>)),</span>
<span id="cb3-22">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb3-23">)</span>
<span id="cb3-24"></span>
<span id="cb3-25">fig.add_trace(</span>
<span id="cb3-26">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>reported_ratio[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>reported_ratio[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"% Reported"</span>, line<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'grey'</span>)),</span>
<span id="cb3-27">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb3-28">)</span>
<span id="cb3-29"></span>
<span id="cb3-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add figure title</span></span>
<span id="cb3-31">fig.update_layout(</span>
<span id="cb3-32">    title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crime Survey Burglaries per Year and Proportion Reported"</span>,</span>
<span id="cb3-33">    legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(</span>
<span id="cb3-34">    orientation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>,</span>
<span id="cb3-35">    yanchor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb3-36">        y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>),</span>
<span id="cb3-37">)</span>
<span id="cb3-38"></span>
<span id="cb3-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set x-axis title</span></span>
<span id="cb3-40">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)</span>
<span id="cb3-41"></span>
<span id="cb3-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set y-axes titles</span></span>
<span id="cb3-43">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglaries"</span>, secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>)</span>
<span id="cb3-44">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of Burglaries Reported"</span>, secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, showgrid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'grey'</span>)</span>
<span id="cb3-45"></span>
<span id="cb3-46"></span>
<span id="cb3-47">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page">
<div>                            <div id="8f13f944-4924-4178-bc30-64043158f812" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("8f13f944-4924-4178-bc30-64043158f812")) {                    Plotly.newPlot(                        "8f13f944-4924-4178-bc30-64043158f812",                        [{"line":{"color":"red"},"name":"Crime Survey","x":[2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020],"y":[1423000.0,1357000.0,1310000.0,1059000.0,1025000.0,1006000.0,960000.0,992000.0,917000.0,1033000.0,922000.0,887000.0,781000.0,784000.0,697000.0,650000.0,691000.0,699000.0,582000.0],"type":"scatter","xaxis":"x","yaxis":"y"},{"line":{"color":"blue"},"name":"Police Reported","x":[2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020],"y":[437583.0,402345.0,321507.0,300517.0,292260.0,280696.0,284431.0,268606.0,258165.0,245312.0,227276.0,211988.0,196554.0,194700.0,206051.0,309867.0,295556.0,268715.0,196214.0],"type":"scatter","xaxis":"x","yaxis":"y"},{"line":{"color":"grey"},"name":"% Reported","x":[2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020],"y":[30.75073787772312,29.649594694178333,24.542519083969466,28.377431539187914,28.513170731707316,27.902186878727637,29.628229166666664,27.077217741935485,28.15321701199564,23.74753146176186,24.650325379609544,23.899436302142053,25.16696542893726,24.834183673469386,29.56255380200861,47.671846153846154,42.77221418234443,38.44277539341917,33.71374570446735],"type":"scatter","xaxis":"x","yaxis":"y2"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,0.94],"title":{"text":"Year"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Burglaries"},"color":"black"},"yaxis2":{"anchor":"x","overlaying":"y","side":"right","title":{"text":"Proportion of Burglaries Reported"},"showgrid":false,"color":"grey"},"title":{"text":"Crime Survey Burglaries per Year and Proportion Reported"},"legend":{"orientation":"h","yanchor":"bottom","y":-0.2}},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('8f13f944-4924-4178-bc30-64043158f812');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>I’d once thought burglary reporting would be consistent - it’s an emotive crime, with a well established insurance industry - and yet we definitely see variation over time.</p>
<p>Notice that dramatic spike in 2015? That’s the aftermath of the 2014 police crime recording scandal, which led to police crime statistics <a href="https://www.theguardian.com/uk-news/2014/jan/15/police-crime-figures-status-claims-fiddling">losing their designation as a national statistic</a>, and accurate crime recording <a href="https://www.justiceinspectorates.gov.uk/hmicfrs/our-work/article/crime-data-integrity/crime-recording-process/">becoming a key metric for the policing regulator.</a> To dig into this issue in more depth, I’d really recommend this blog by <a href="https://www.police-foundation.org.uk/2018/03/crime-blame-police-crime-survey-england-wales-tells-us-police-crime-recording-practices-exposes-limitations/">Gavin Hales</a>.</p>
<p>What does this tell us about burglary in England &amp; Wales over the last decade though? Two things:</p>
<ol type="1">
<li><strong>Domestic Burglaries are probably rarer than ever</strong> (and that’s not down to COVID)</li>
<li>That’s <strong>not consistently reflected in police recorded crime</strong> - the likelihood of reporting seems to change over time</li>
</ol>
</section>
<section id="how-many-burglars-are-we-catching" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="how-many-burglars-are-we-catching">How Many Burglars are we Catching?</h2>
<p>So there aren’t many burglaries…so have we gotten better at catching the rest?</p>
<p>Well…we’re certainly not catching any more than we used to. Whether you use charges (eg, burglars being sent to court) or “detections” (eg, including cautions, fines and similar), there are far fewer, thought it looks like that trend started long before 2015.</p>
<div id="cell-9" class="cell page-columns page-full" data-execution_count="4">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">detections <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'../data/interim/burglary_detections.csv'</span>,index_col<span class="op" 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>
<span id="cb4-2">detections</span>
<span id="cb4-3"></span>
<span id="cb4-4">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> px.line(detections, x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detections'</span>)</span>
<span id="cb4-5"></span>
<span id="cb4-6">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)</span>
<span id="cb4-7"></span>
<span id="cb4-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set y-axes titles</span></span>
<span id="cb4-9">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Detections"</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span><span class="op" 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60000</span>])</span>
<span id="cb4-10"></span>
<span id="cb4-11"></span>
<span id="cb4-12">fig.update_layout(</span>
<span id="cb4-13">    title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Detections by Year"</span></span>
<span id="cb4-14">)</span>
<span id="cb4-15"></span>
<span id="cb4-16">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page">
<div>                            <div id="c81b0be6-719e-453c-a0c8-2263523ce7f7" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("c81b0be6-719e-453c-a0c8-2263523ce7f7")) {                    Plotly.newPlot(                        "c81b0be6-719e-453c-a0c8-2263523ce7f7",                        [{"hovertemplate":"year=%{x}<br>detections=%{y}<extra></extra>","legendgroup":"","line":{"color":"#636efa","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines","name":"","orientation":"v","showlegend":false,"x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"xaxis":"x","y":[48161.0,48868.0,44345.0,46481.0,42423.0,43907.0,39886.0,35801.0,32351.0,24124.0,17847.0,16286.0,17193.0,15619.0,13692.0,12244.0,9853.0],"yaxis":"y","type":"scatter"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"Year"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Police Detections"},"range":[0,60000]},"legend":{"tracegroupgap":0},"margin":{"t":60},"title":{"text":"Police Detections by Year"}},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('c81b0be6-719e-453c-a0c8-2263523ce7f7');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>That’s not hugely surprising: there are fewer burglars around to be caught. What’s perhaps more important is how many burglars we’re catching <strong>as a proportion of those remaining burglaries we know about</strong>.</p>
<p>I’ve visualised that below: on the left axis, all police reported burglaries (in blue), and how many lead to a positive outcome (in red), and on the right axis, the ratio of the two: an estimate of the proportion of police burglaries that are “solved”.</p>
<div id="cell-11" class="cell page-columns page-full" data-execution_count="5">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">yearly_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> detections.merge(comparison_df, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'left'</span>, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb5-2">yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_csew_ratio'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detections'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime Survey'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb5-3">yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_police_ratio'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detections'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb5-4"></span>
<span id="cb5-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create figure with secondary y-axis</span></span>
<span id="cb5-6">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_subplots(specs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[[{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"secondary_y"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>}]])</span>
<span id="cb5-7"></span>
<span id="cb5-8">fig.add_trace(</span>
<span id="cb5-9">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Reported"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>),</span>
<span id="cb5-10">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb5-11">)</span>
<span id="cb5-12"></span>
<span id="cb5-13">fig.add_trace(</span>
<span id="cb5-14">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detections'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Detections"</span>,  fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>),</span>
<span id="cb5-15">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb5-16">)</span>
<span id="cb5-17"></span>
<span id="cb5-18"></span>
<span id="cb5-19"></span>
<span id="cb5-20">fig.add_trace(</span>
<span id="cb5-21">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_police_ratio'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poportion of Police Reported Burglaries Detected"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>, visible<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>),</span>
<span id="cb5-22">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb5-23">)</span>
<span id="cb5-24"></span>
<span id="cb5-25"></span>
<span id="cb5-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add figure title</span></span>
<span id="cb5-27">fig.update_layout(</span>
<span id="cb5-28">    title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crime Survey Burglaries per Year and Proportion Reported"</span>,</span>
<span id="cb5-29">    legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(</span>
<span id="cb5-30">    orientation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>,</span>
<span id="cb5-31">    yanchor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb5-32">        y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>),</span>
<span id="cb5-33">)</span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set x-axis title</span></span>
<span id="cb5-36">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)</span>
<span id="cb5-37"></span>
<span id="cb5-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set y-axes titles</span></span>
<span id="cb5-39">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglaries"</span>, secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb5-40">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of Burglaries Solved"</span>,<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span><span class="op" 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>], secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, showgrid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>)</span>
<span id="cb5-41"></span>
<span id="cb5-42"></span>
<span id="cb5-43">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-screen">
<div>                            <div id="23e2e0ba-1011-465b-8fa9-9a6864709c63" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("23e2e0ba-1011-465b-8fa9-9a6864709c63")) {                    Plotly.newPlot(                        "23e2e0ba-1011-465b-8fa9-9a6864709c63",                        [{"fillcolor":"blue","name":"Police Reported","x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[300517.0,292260.0,280696.0,284431.0,268606.0,258165.0,245312.0,227276.0,211988.0,196554.0,194700.0,206051.0,309867.0,295556.0,268715.0,196214.0,null],"type":"scatter","xaxis":"x","yaxis":"y"},{"fillcolor":"red","name":"Police Detections","x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[48161.0,48868.0,44345.0,46481.0,42423.0,43907.0,39886.0,35801.0,32351.0,24124.0,17847.0,16286.0,17193.0,15619.0,13692.0,12244.0,9853.0],"type":"scatter","xaxis":"x","yaxis":"y"},{"fillcolor":"green","name":"Poportion of Police Reported Burglaries Detected","visible":true,"x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[16.026048443182912,16.72072811879833,15.798230113717333,16.34174896547845,15.79376484516355,17.007340266883585,16.259294286459692,15.75221316813038,15.260769477517597,12.273471921202315,9.166409861325116,7.903868459750256,5.548509521827107,5.2846161133592275,5.095361256349664,6.24012557717594,null],"type":"scatter","xaxis":"x","yaxis":"y2"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,0.94],"title":{"text":"Year"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Burglaries"}},"yaxis2":{"anchor":"x","overlaying":"y","side":"right","title":{"text":"Proportion of Burglaries Solved"},"range":[0,20],"showgrid":false,"color":"green"},"title":{"text":"Crime Survey Burglaries per Year and Proportion Reported"},"legend":{"orientation":"h","yanchor":"bottom","y":-0.2}},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('23e2e0ba-1011-465b-8fa9-9a6864709c63');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>It doesn’t look good: performance drops sharply around the time we stopped attending all burglaries in 2015.</p>
<p>Of course, plenty of other things happened in 2015: for instance, we know there was a radical shift in recording standards, where police recorded and invesigated thousands of burglaries which they would have previously not been aware of. So how do we measure how police performance changed irrespective of those recording changes? We can replicate that chart, but instead of using police recorded burglaries, we use <em>all</em> burglaries, as reported by the Crime Survey. rather than just police reported burglaries.</p>
<p>The below chart does exactly that - click on each of the buttons to see how the baseline figure affects perceived investigatory performance.</p>
<div id="cell-13" class="cell page-columns page-full" data-execution_count="6">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create figure with secondary y-axis</span></span>
<span id="cb6-2">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_subplots(specs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[[{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"secondary_y"</span>: <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>}]])</span>
<span id="cb6-3"></span>
<span id="cb6-4"></span>
<span id="cb6-5">fig.add_trace(</span>
<span id="cb6-6">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Police Reported'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Reported"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>),</span>
<span id="cb6-7">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb6-8">)</span>
<span id="cb6-9">fig.add_trace(</span>
<span id="cb6-10">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detections'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Police Detections"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>),</span>
<span id="cb6-11">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb6-12">)</span>
<span id="cb6-13"></span>
<span id="cb6-14"></span>
<span id="cb6-15"></span>
<span id="cb6-16">fig.add_trace(</span>
<span id="cb6-17">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_police_ratio'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poportion of Police Reported Burglaries Detected"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>, visible<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>),</span>
<span id="cb6-18">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb6-19">)</span>
<span id="cb6-20"></span>
<span id="cb6-21">fig.add_trace(</span>
<span id="cb6-22">    go.Scatter(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yearly_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_csew_ratio'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poportion of Crime Survey Burglaries Detected"</span>, fillcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>, visible<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>),</span>
<span id="cb6-23">    secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb6-24">)</span>
<span id="cb6-25"></span>
<span id="cb6-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add figure title</span></span>
<span id="cb6-27">fig.update_layout(</span>
<span id="cb6-28">    title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crime Survey Burglaries per Year and Proportion Reported"</span></span>
<span id="cb6-29">)</span>
<span id="cb6-30"></span>
<span id="cb6-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set x-axis title</span></span>
<span id="cb6-32">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)</span>
<span id="cb6-33"></span>
<span id="cb6-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set y-axes titles</span></span>
<span id="cb6-35">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglaries"</span>, secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb6-36">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of Burglaries Solved"</span>,<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span><span class="op" 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>], secondary_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, showgrid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>)</span>
<span id="cb6-37"></span>
<span id="cb6-38"></span>
<span id="cb6-39">fig.update_layout(</span>
<span id="cb6-40">    legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(</span>
<span id="cb6-41">    orientation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>,</span>
<span id="cb6-42">    yanchor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>,</span>
<span id="cb6-43">        y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>),</span>
<span id="cb6-44">    updatemenus<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[</span>
<span id="cb6-45">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(</span>
<span id="cb6-46">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"buttons"</span>,</span>
<span id="cb6-47">            direction<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>,</span>
<span id="cb6-48">            active<span class="op" 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>
<span id="cb6-49">            x<span class="op" 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="cb6-50">            y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>,</span>
<span id="cb6-51">            bgcolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'grey'</span>,</span>
<span id="cb6-52">            bordercolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>,</span>
<span id="cb6-53">            font<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>),</span>
<span id="cb6-54">            showactive<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb6-55">            buttons<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>([</span>
<span id="cb6-56">                <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"As Proportion of Police Reported"</span>,</span>
<span id="cb6-57">                     method<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"update"</span>,</span>
<span id="cb6-58">                     args<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visible"</span>: [<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>]}]),</span>
<span id="cb6-59">                <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"As Proportion of all Burglaries"</span>,</span>
<span id="cb6-60">                     method<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"update"</span>,</span>
<span id="cb6-61">                     args<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visible"</span>: [<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>]}])</span>
<span id="cb6-62">            ]),</span>
<span id="cb6-63">        )</span>
<span id="cb6-64">    ])</span>
<span id="cb6-65"></span>
<span id="cb6-66">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-screen">
<div>                            <div id="d4ab2760-26eb-4dd8-918e-e017989fcec0" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("d4ab2760-26eb-4dd8-918e-e017989fcec0")) {                    Plotly.newPlot(                        "d4ab2760-26eb-4dd8-918e-e017989fcec0",                        [{"fillcolor":"blue","name":"Police Reported","x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[300517.0,292260.0,280696.0,284431.0,268606.0,258165.0,245312.0,227276.0,211988.0,196554.0,194700.0,206051.0,309867.0,295556.0,268715.0,196214.0,null],"type":"scatter","xaxis":"x","yaxis":"y"},{"fillcolor":"red","name":"Police Detections","x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[48161.0,48868.0,44345.0,46481.0,42423.0,43907.0,39886.0,35801.0,32351.0,24124.0,17847.0,16286.0,17193.0,15619.0,13692.0,12244.0,9853.0],"type":"scatter","xaxis":"x","yaxis":"y"},{"fillcolor":"green","name":"Poportion of Police Reported Burglaries Detected","visible":false,"x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[16.026048443182912,16.72072811879833,15.798230113717333,16.34174896547845,15.79376484516355,17.007340266883585,16.259294286459692,15.75221316813038,15.260769477517597,12.273471921202315,9.166409861325116,7.903868459750256,5.548509521827107,5.2846161133592275,5.095361256349664,6.24012557717594,null],"type":"scatter","xaxis":"x","yaxis":"y2"},{"fillcolor":"black","name":"Poportion of Crime Survey Burglaries Detected","visible":false,"x":[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],"y":[4.547780925401322,4.767609756097561,4.408051689860835,4.841770833333333,4.276512096774194,4.788113413304253,3.8611810261374635,3.8829718004338396,3.6472378804960544,3.0888604353393085,2.2764030612244897,2.3365853658536584,2.645076923076923,2.2603473227206945,1.9587982832618027,2.1037800687285224,null],"type":"scatter","xaxis":"x","yaxis":"y2"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,0.94],"title":{"text":"Year"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Burglaries"}},"yaxis2":{"anchor":"x","overlaying":"y","side":"right","title":{"text":"Proportion of Burglaries Solved"},"range":[0,20],"showgrid":false,"color":"green"},"title":{"text":"Crime Survey Burglaries per Year and Proportion Reported"},"legend":{"orientation":"h","yanchor":"bottom","y":-0.2},"updatemenus":[{"active":0,"bgcolor":"grey","bordercolor":"white","buttons":[{"args":[{"visible":[true,true,true,false]}],"label":"As Proportion of Police Reported","method":"update"},{"args":[{"visible":[true,true,false,true]}],"label":"As Proportion of all Burglaries","method":"update"}],"direction":"right","font":{"color":"white"},"showactive":false,"type":"buttons","x":1,"y":1.2}]},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('d4ab2760-26eb-4dd8-918e-e017989fcec0');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>Suddenly that sharp drop in 2015 is a lot less convincing. Looking at all burglaries - rather than just those reported to police - the proportion being solved has been going down, but <strong>that started happening long before 2015</strong>. Around 5% of all burglaries in the crime survey were “solved” in 2010, but by 2015, that had already dropped to around 2.5%, compared to just over 2% in 2020.</p>
<p>What’s the lesson here? The perception of a recent, short term drop in police investigative performance are somewhat overstated. Yes, policing is catching fewer burglars than ever, but burglaries are rarer than ever - those that remain are less likely to be caught than they used to be, but that’s a trend that started long before 2015 (it might even have started as early as 2008).</p>
<p>What explains that trend? We really don’t know. It’s possible that those few remaining burglars are the most persistent and sophisiticated: maybe opportunistic drug users desperate for a fix who were willing to smash your front window in a decade ago have been replaced by professional teams who will do a whole set of flats in minutes. <strong>We can’t really tell with the data we’ve got here, but it’s probably not as simple as policing just not trying hard enough.</strong></p>
</section>
<section id="will-mandatory-attendance-help" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="will-mandatory-attendance-help">Will Mandatory Attendance Help?</h2>
<p>Given the above, will mandatory attendance actually reduce burglary? As far as I can tell, nobody has properly checked. <a href="https://t.co/jTkytsD1HX">The Telegraph suggests that burglaries “could fall by 60pc if officers visited every victim”</a>, but given nobody has really rigorously tested the impact of burglary attendance, I’m not totally convinced. Leicestershire <a href="https://www.bbc.co.uk/news/uk-england-leicestershire-33788264">attempted to conduct a randomised control trial in 2015, but following press uproar the whole thing was shelved</a>.</p>
<p>There is some good research that suggests it will make <em>some</em> difference: <a href="https://policinginsight.com/features/analysis/double-crewing-and-faster-response-times-are-key-to-cutting-crime-and-costs-while-improving-service/">rapid attendance to crimes probably does help solve them</a>, and <a href="https://academic.oup.com/policing/article-abstract/15/2/832/5359499">finding a suspect is the most effective way of solving a burglary</a>. If we randomly assigned some burglaries to be attended, and some to not, those we did attend would be solved more often.</p>
<p>That’s different to mandatory attendance though: where even if the responding officer thinks there isn’t any point (for example, if the burglary was many months ago, or very unlikely to be solved following a phone report), they’ll attend anyway. So how have some reporters calculcated that policy could <a href="https://www.dailymail.co.uk/news/article-10392721/Sending-police-officers-burglaries-cuts-number-offences-half-forces-find.html">cut the number of offences by half?</a></p>
<p>Unhelpfully, the researchers for the <a href="https://www.dailymail.co.uk/news/article-10392721/Sending-police-officers-burglaries-cuts-number-offences-half-forces-find.html">Mail</a> and the <a href="https://www.telegraph.co.uk/news/2022/10/05/burglaries-could-fall-60pc-officers-visited-every-victim/">Telegraph</a> haven’t been very open with sharing their methodology, but it looks like they’ve looked at those forces who already have a mandatory attendance policy, and tried to predict what would happen if that had been expanded nationally.</p>
<p>Three forces in particular are repeatedly mentioned as having introduced mandatory attendance prior to the NPCC mandate:</p>
<ol type="1">
<li><a href="https://www.northants.police.uk/news/northants/news/news/2022/april/burglaries-in-northamptonshire-reduce-by-more-than-half-as-burglary-team-turns-three-years-old/">Northamptonshire since April 2019</a>, though it’s worth noting these are dedicated burglary teams rather than attendance in isolation</li>
<li><a href="https://www.itv.com/news/anglia/2022-01-14/bedfordshire-burglaries-halve-thanks-to-new-police-task-force">Bedfordshire Police</a> using the codename “Operation Maze”, though again, it seems paired with dedicated burglary teams, and may in fact be attendance by forensics staff rather than police offiers. The <a href="https://twitter.com/bedspolice/status/1231927872035618817">earliest records are in early 2020</a> but it’s not clear at all this involves any mandatory attendance, rather than just increased resourcing.</li>
<li><a href="https://www.manchestereveningnews.co.uk/news/greater-manchester-news/police-to-attend-all-burglaries-25180398">Greater Manchester Police</a> since <a href="https://www.gmp.police.uk/news/greater-manchester/news/news/2022/october/15-months-committed-to-attending-every-burglary/">July 2021</a></li>
</ol>
<p>The key question then is <strong>did the introduction of mandatory attendance in these three forces make any difference to burglary investigations?</strong></p>
<p>To do that, we’ll calculate: - What was the detection rate for burglary in all forces? - How did the detection rate change after the introduction of mandatory attendance? - How did other, similar forces fare during the same period?</p>
<p>There are real limitations to doing this with public data: we are limited to quarter by quarter analysis, and we don’t actually know exactly when these policies started (or, for that matter, exactly what they include) or who else might have been doing something similar, but we can still try and identify what performance boost (if any) mandatory attendance made for these forces.</p>
<div id="cell-16" class="cell page-columns page-full" data-execution_count="7">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">theft_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_excel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"../data/external/burglary_outcomes_combined.ods"</span>, engine<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"odf"</span>)</span>
<span id="cb7-2">qs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theft_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial year'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">slice</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;">4</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-Q"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> theft_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial quarter'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'str'</span>)</span>
<span id="cb7-3"></span>
<span id="cb7-4">theft_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.PeriodIndex(qs, freq<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Q'</span>).to_timestamp()</span>
<span id="cb7-5">theft_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theft_df.sort_values(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb7-6"></span>
<span id="cb7-7">burglary_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theft_df[theft_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offence Subgroup'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Domestic burglary'</span>].rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force Name'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>})</span>
<span id="cb7-8">burglary_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> burglary_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'string'</span>)</span>
<span id="cb7-9">burglary_df</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="7">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">Financial year</th>
<th data-quarto-table-cell-role="th">Financial quarter</th>
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th">Offence Description</th>
<th data-quarto-table-cell-role="th">Offence Group</th>
<th data-quarto-table-cell-role="th">Offence Subgroup</th>
<th data-quarto-table-cell-role="th">Offence Code</th>
<th data-quarto-table-cell-role="th">Offence code expired</th>
<th data-quarto-table-cell-role="th">Outcome Description</th>
<th data-quarto-table-cell-role="th">Outcome Group</th>
<th data-quarto-table-cell-role="th">Outcome Type</th>
<th data-quarto-table-cell-role="th">Force outcomes for offences recorded in quarter</th>
<th data-quarto-table-cell-role="th">Force outcomes recorded in quarter</th>
<th data-quarto-table-cell-role="th">date</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">160811</th>
<td>2021/22</td>
<td>4</td>
<td>British Transport Police</td>
<td>Attempted Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28F</td>
<td>NaN</td>
<td>Community Resolution</td>
<td>Out-of-court (informal)</td>
<td>8</td>
<td>0.0</td>
<td>0.0</td>
<td>2021-10-01</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">164083</th>
<td>2021/22</td>
<td>4</td>
<td>Hampshire</td>
<td>Attempted Distraction Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28H</td>
<td>NaN</td>
<td>Taken into consideration</td>
<td>Taken into consideration</td>
<td>4</td>
<td>0.0</td>
<td>0.0</td>
<td>2021-10-01</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">164081</th>
<td>2021/22</td>
<td>4</td>
<td>Hampshire</td>
<td>Attempted Distraction Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28H</td>
<td>NaN</td>
<td>Diversionary, educational or intervention acti...</td>
<td>Diversionary, educational or intervention acti...</td>
<td>22</td>
<td>0.0</td>
<td>0.0</td>
<td>2021-10-01</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">164080</th>
<td>2021/22</td>
<td>4</td>
<td>Hampshire</td>
<td>Attempted Distraction Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28H</td>
<td>NaN</td>
<td>Further investigation to support formal action...</td>
<td>Further investigation to support formal action...</td>
<td>21</td>
<td>0.0</td>
<td>0.0</td>
<td>2021-10-01</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">164079</th>
<td>2021/22</td>
<td>4</td>
<td>Hampshire</td>
<td>Attempted Distraction Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28H</td>
<td>NaN</td>
<td>Responsibility for further investigation trans...</td>
<td>Responsibility for further investigation trans...</td>
<td>20</td>
<td>0.0</td>
<td>0.0</td>
<td>2021-10-01</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">49689</th>
<td>2017/18</td>
<td>1</td>
<td>Northamptonshire</td>
<td>Attempted Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28F</td>
<td>NaN</td>
<td>Further investigation to support formal action...</td>
<td>Further investigation to support formal action...</td>
<td>21</td>
<td>1.0</td>
<td>0.0</td>
<td>2017-01-01</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">49688</th>
<td>2017/18</td>
<td>1</td>
<td>Northamptonshire</td>
<td>Attempted Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28F</td>
<td>NaN</td>
<td>Responsibility for further investigation trans...</td>
<td>Responsibility for further investigation trans...</td>
<td>20</td>
<td>1.0</td>
<td>1.0</td>
<td>2017-01-01</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">49687</th>
<td>2017/18</td>
<td>1</td>
<td>Northamptonshire</td>
<td>Attempted Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28F</td>
<td>NaN</td>
<td>Caution – youths</td>
<td>Out-of-court (formal)</td>
<td>2</td>
<td>0.0</td>
<td>0.0</td>
<td>2017-01-01</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">49686</th>
<td>2017/18</td>
<td>1</td>
<td>Northamptonshire</td>
<td>Attempted Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28F</td>
<td>NaN</td>
<td>Investigation complete – no suspect identified</td>
<td>Investigation complete – no suspect identified</td>
<td>18</td>
<td>114.0</td>
<td>104.0</td>
<td>2017-01-01</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">50576</th>
<td>2017/18</td>
<td>1</td>
<td>South Wales</td>
<td>Distraction Burglary Residential</td>
<td>Theft offences</td>
<td>Domestic burglary</td>
<td>28G</td>
<td>NaN</td>
<td>Community Resolution</td>
<td>Out-of-court (informal)</td>
<td>8</td>
<td>0.0</td>
<td>0.0</td>
<td>2017-01-01</td>
</tr>
</tbody>
</table>

<p>212960 rows × 14 columns</p>
</div>
</div>
</div>
<p>Given we’re looking at quarterly data, we’ll generate two temporal variables for our data:</p>
<ol type="1">
<li>A running variable (running_var), which measures the number of quarters that have passed since the start of our dataset</li>
<li>A quarter “categorical variable”, checking to see if there is any specific trend for burglary detection whether you’re in quarter 1, 2, 3 or 4</li>
</ol>
<div id="cell-18" class="cell" data-execution_count="8">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"></span>
<span id="cb8-2">time_series <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theft_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial quarter'</span>]].drop_duplicates().sort_values(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>]).reset_index(drop<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>).reset_index().rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'index'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'running_var'</span>})</span>
<span id="cb8-3">time_series[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quarter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time_series[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial quarter'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'string'</span>)</span>
<span id="cb8-4">time_series <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time_series.drop(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Financial quarter'</span>])</span>
<span id="cb8-5">time_series</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="8">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">running_var</th>
<th data-quarto-table-cell-role="th">date</th>
<th data-quarto-table-cell-role="th">quarter</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>0</td>
<td>2017-01-01</td>
<td>1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>1</td>
<td>2017-04-01</td>
<td>2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>2</td>
<td>2017-07-01</td>
<td>3</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>3</td>
<td>2017-10-01</td>
<td>4</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>4</td>
<td>2018-01-01</td>
<td>1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">5</th>
<td>5</td>
<td>2018-04-01</td>
<td>2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">6</th>
<td>6</td>
<td>2018-07-01</td>
<td>3</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">7</th>
<td>7</td>
<td>2018-10-01</td>
<td>4</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">8</th>
<td>8</td>
<td>2019-01-01</td>
<td>1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">9</th>
<td>9</td>
<td>2019-04-01</td>
<td>2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">10</th>
<td>10</td>
<td>2019-07-01</td>
<td>3</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">11</th>
<td>11</td>
<td>2019-10-01</td>
<td>4</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">12</th>
<td>12</td>
<td>2020-01-01</td>
<td>1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">13</th>
<td>13</td>
<td>2020-04-01</td>
<td>2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">14</th>
<td>14</td>
<td>2020-07-01</td>
<td>3</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">15</th>
<td>15</td>
<td>2020-10-01</td>
<td>4</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">16</th>
<td>16</td>
<td>2021-01-01</td>
<td>1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">17</th>
<td>17</td>
<td>2021-04-01</td>
<td>2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">18</th>
<td>18</td>
<td>2021-07-01</td>
<td>3</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">19</th>
<td>19</td>
<td>2021-10-01</td>
<td>4</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>For each force, we then have a count of burglaries, and a ratio of how many solved burglaries (eg, burglary investigations where a burglary is identified and dealt with by police) we have that quarter.</p>
<div id="cell-20" class="cell page-columns page-full" data-execution_count="9">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">total_q_offences <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> burglary_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force outcomes for offences recorded in quarter'</span>]].groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>]).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>().reset_index()</span>
<span id="cb9-2">total_q_offences[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_offences'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(total_q_offences[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force outcomes for offences recorded in quarter'</span>],errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'coerce'</span>)</span>
<span id="cb9-3"></span>
<span id="cb9-4">positive_outcomes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Taken into consideration'</span>,</span>
<span id="cb9-5"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charged/Summonsed'</span>,</span>
<span id="cb9-6"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Community Resolution'</span>,</span>
<span id="cb9-7"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Cannabis/Khat Warning'</span>,</span>
<span id="cb9-8"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Penalty Notices for Disorder'</span>,</span>
<span id="cb9-9"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Caution – adults'</span>,</span>
<span id="cb9-10"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Diversionary, educational or intervention activity, resulting from the crime report, has been undertaken and it is not in the public interest to take any further action.'</span>,</span>
<span id="cb9-11"> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Caution – youths'</span>]</span>
<span id="cb9-12"></span>
<span id="cb9-13">burglary_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'is_detected'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> burglary_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Outcome Description'</span>].isin(positive_outcomes)</span>
<span id="cb9-14"></span>
<span id="cb9-15">positive_burglary_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> burglary_df[burglary_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'is_detected'</span>]]</span>
<span id="cb9-16"></span>
<span id="cb9-17">total_detected_offences <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> positive_burglary_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force outcomes for offences recorded in quarter'</span>]].groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>]).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>().reset_index()</span>
<span id="cb9-18">total_detected_offences[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_detected'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_numeric(total_detected_offences[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force outcomes for offences recorded in quarter'</span>],errors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'coerce'</span>)</span>
<span id="cb9-19"></span>
<span id="cb9-20">force_comparison <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> total_q_offences[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_offences'</span>]].merge(total_detected_offences, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'left'</span>,on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>]).drop(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force outcomes for offences recorded in quarter'</span>])</span>
<span id="cb9-21">force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_detected'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_offences'</span>]</span>
<span id="cb9-22">force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>]  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>].fillna(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb9-23">force_comparison</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="9">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">date</th>
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th">total_offences</th>
<th data-quarto-table-cell-role="th">total_detected</th>
<th data-quarto-table-cell-role="th">detected_rate</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>2017-01-01</td>
<td>Avon and Somerset</td>
<td>2151.0</td>
<td>112.0</td>
<td>0.052069</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>2017-01-01</td>
<td>Bedfordshire</td>
<td>1142.0</td>
<td>120.0</td>
<td>0.105079</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>2017-01-01</td>
<td>British Transport Police</td>
<td>0.0</td>
<td>0.0</td>
<td>0.000000</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>2017-01-01</td>
<td>Cambridgeshire</td>
<td>1109.0</td>
<td>99.0</td>
<td>0.089270</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>2017-01-01</td>
<td>Cheshire</td>
<td>790.0</td>
<td>80.0</td>
<td>0.101266</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">875</th>
<td>2021-10-01</td>
<td>Warwickshire</td>
<td>376.0</td>
<td>8.0</td>
<td>0.021277</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">876</th>
<td>2021-10-01</td>
<td>West Mercia</td>
<td>857.0</td>
<td>8.0</td>
<td>0.009335</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">877</th>
<td>2021-10-01</td>
<td>West Midlands</td>
<td>4061.0</td>
<td>93.0</td>
<td>0.022901</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">878</th>
<td>2021-10-01</td>
<td>West Yorkshire</td>
<td>2406.0</td>
<td>81.0</td>
<td>0.033666</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">879</th>
<td>2021-10-01</td>
<td>Wiltshire</td>
<td>265.0</td>
<td>8.0</td>
<td>0.030189</td>
</tr>
</tbody>
</table>

<p>880 rows × 5 columns</p>
</div>
</div>
</div>
<p>Now, we identify our “treated” forces, and the period in which the policy was in place. This isn’t exactly clean, but based on the newspaper articles and press releases, I’ve picked out:</p>
<ul>
<li>Bedfordshire from 2020 onwards</li>
<li>GMP from July 2021 onwards</li>
<li>Northamptonshire from April 2019 onwards</li>
<li>and of course, nationwide from October 2022</li>
</ul>
<p>With those dates, we’ll then build our completed dataset of quarter by quarter burglary detection rates, for each force, and whether or not a mandatory attendance policy was in place in that force/quarter.</p>
<div id="cell-22" class="cell page-columns page-full" data-execution_count="10">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1">northamptonshire <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.contains(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Northamptonshire'</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-04-01'</span>)</span>
<span id="cb10-2">bedfordshire <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.contains(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bedfordshire'</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2020-01-01'</span>)</span>
<span id="cb10-3">manchester <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.contains(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Manchester'</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2020-07-01'</span>)</span>
<span id="cb10-4">everyone <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2022-10-01'</span>)</span>
<span id="cb10-5"></span>
<span id="cb10-6"></span>
<span id="cb10-7">force_comparison[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mandatory_attendance'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> northamptonshire <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> bedfordshire <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> manchester <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> everyone</span>
<span id="cb10-8">force_comparison</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="10">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">date</th>
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th">total_offences</th>
<th data-quarto-table-cell-role="th">total_detected</th>
<th data-quarto-table-cell-role="th">detected_rate</th>
<th data-quarto-table-cell-role="th">mandatory_attendance</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>2017-01-01</td>
<td>Avon and Somerset</td>
<td>2151.0</td>
<td>112.0</td>
<td>0.052069</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>2017-01-01</td>
<td>Bedfordshire</td>
<td>1142.0</td>
<td>120.0</td>
<td>0.105079</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>2017-01-01</td>
<td>British Transport Police</td>
<td>0.0</td>
<td>0.0</td>
<td>0.000000</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>2017-01-01</td>
<td>Cambridgeshire</td>
<td>1109.0</td>
<td>99.0</td>
<td>0.089270</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>2017-01-01</td>
<td>Cheshire</td>
<td>790.0</td>
<td>80.0</td>
<td>0.101266</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">875</th>
<td>2021-10-01</td>
<td>Warwickshire</td>
<td>376.0</td>
<td>8.0</td>
<td>0.021277</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">876</th>
<td>2021-10-01</td>
<td>West Mercia</td>
<td>857.0</td>
<td>8.0</td>
<td>0.009335</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">877</th>
<td>2021-10-01</td>
<td>West Midlands</td>
<td>4061.0</td>
<td>93.0</td>
<td>0.022901</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">878</th>
<td>2021-10-01</td>
<td>West Yorkshire</td>
<td>2406.0</td>
<td>81.0</td>
<td>0.033666</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">879</th>
<td>2021-10-01</td>
<td>Wiltshire</td>
<td>265.0</td>
<td>8.0</td>
<td>0.030189</td>
<td>False</td>
</tr>
</tbody>
</table>

<p>880 rows × 6 columns</p>
</div>
</div>
</div>
<p>One limitation of working by quarters is that we’re quite limited in numbers! Good inference in statistical modelling relies on detecting “variance” - eg, having enough data to identify both our effect, and general background levels, and separating out the two. Given GMP has only been running for 6 quarters, we’ll focus on the other two forces for this analysis.</p>
<div id="cell-24" class="cell" data-execution_count="11">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">force_comparison[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mandatory_attendance'</span>]].groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>().sort_values(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mandatory_attendance'</span>, ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>).rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mandatory_attendance"</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Quarters of Mandatory Attendance'</span>})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="11">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">Quarters of Mandatory Attendance</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Northamptonshire</th>
<td>11</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Bedfordshire</th>
<td>8</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Greater Manchester</th>
<td>6</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">South Wales</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Merseyside</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Metropolitan Police</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Norfolk</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">North Wales</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">North Yorkshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Northumbria</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Nottinghamshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Avon and Somerset</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">London, City of</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Staffordshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Suffolk</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Surrey</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Sussex</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Thames Valley</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Warwickshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">West Mercia</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">West Midlands</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">West Yorkshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">South Yorkshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Lincolnshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Leicestershire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Lancashire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">British Transport Police</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Cambridgeshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Cheshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Cleveland</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Cumbria</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Derbyshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Devon and Cornwall</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Dorset</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Durham</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Dyfed-Powys</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Essex</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Gloucestershire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Gwent</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Hampshire</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Hertfordshire</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Humberside</th>
<td>0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Kent</th>
<td>0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Wiltshire</th>
<td>0</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>Now we can start combining our data together, and seeing if we can observe any meaningful difference after the intervention takes place.</p>
<p>For meaningful comparisons, we’ll seek to compare forces to other similar forces - there’s not much point in comparing GMP to Durham. We could do that with our existing data - eg, looking at forces with similar numbers of burglaries - but helpfully, the policing regulator <a href="https://www.justiceinspectorates.gov.uk/hmicfrs/police-forces/data/">HMIFRS already produces “Most Similar Forces” groups</a>, which should let us match up forces based on size, demographics and other factors relevant to performance. We’ll seperate out our group A (Bedfordshire and their group) from group B (Northamptonshire’s), though notice Kent is in both - unhelpfully, HMIC’s groups aren’t exclusive, though that’s not too much of a problem.</p>
<div id="cell-26" class="cell" data-execution_count="12">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1">group_a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bedfordshire"</span>,</span>
<span id="cb12-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Leicestershire"</span>,</span>
<span id="cb12-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nottinghamshire"</span>,</span>
<span id="cb12-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hertfordshire"</span>,</span>
<span id="cb12-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kent"</span>,</span>
<span id="cb12-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hampshire"</span>,</span>
<span id="cb12-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Essex"</span>,</span>
<span id="cb12-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"South Yorkshire"</span>]</span>
<span id="cb12-9"></span>
<span id="cb12-10">group_b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Northamptonshire"</span>,</span>
<span id="cb12-11">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cheshire"</span>,</span>
<span id="cb12-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Derbyshire"</span>,</span>
<span id="cb12-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Staffordshire"</span>,</span>
<span id="cb12-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kent"</span>,</span>
<span id="cb12-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Avon and Somerset"</span>,</span>
<span id="cb12-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Essex"</span>,</span>
<span id="cb12-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nottinghamshire"</span>]</span>
<span id="cb12-18"></span>
<span id="cb12-19">msf_groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> force_comparison[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>]].drop_duplicates().reset_index(drop<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb12-20">msf_groups[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_A'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msf_groups[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].isin(group_a)</span>
<span id="cb12-21">msf_groups[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_B'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msf_groups[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].isin(group_b)</span>
<span id="cb12-22">msf_groups</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="12">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th">group_A</th>
<th data-quarto-table-cell-role="th">group_B</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>Avon and Somerset</td>
<td>False</td>
<td>True</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>Bedfordshire</td>
<td>True</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>British Transport Police</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>Cambridgeshire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>Cheshire</td>
<td>False</td>
<td>True</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">5</th>
<td>Cleveland</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">6</th>
<td>Cumbria</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">7</th>
<td>Derbyshire</td>
<td>False</td>
<td>True</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">8</th>
<td>Devon and Cornwall</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">9</th>
<td>Dorset</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">10</th>
<td>Durham</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">11</th>
<td>Dyfed-Powys</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">12</th>
<td>Essex</td>
<td>True</td>
<td>True</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">13</th>
<td>Gloucestershire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">14</th>
<td>Greater Manchester</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">15</th>
<td>Gwent</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">16</th>
<td>Hampshire</td>
<td>True</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">17</th>
<td>Hertfordshire</td>
<td>True</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">18</th>
<td>Humberside</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">19</th>
<td>Kent</td>
<td>True</td>
<td>True</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">20</th>
<td>Lancashire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">21</th>
<td>Leicestershire</td>
<td>True</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">22</th>
<td>Lincolnshire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">23</th>
<td>London, City of</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">24</th>
<td>Merseyside</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">25</th>
<td>Metropolitan Police</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">26</th>
<td>Norfolk</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">27</th>
<td>North Wales</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">28</th>
<td>North Yorkshire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">29</th>
<td>Northamptonshire</td>
<td>False</td>
<td>True</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">30</th>
<td>Northumbria</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">31</th>
<td>Nottinghamshire</td>
<td>True</td>
<td>True</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">32</th>
<td>South Wales</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">33</th>
<td>South Yorkshire</td>
<td>True</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">34</th>
<td>Staffordshire</td>
<td>False</td>
<td>True</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">35</th>
<td>Suffolk</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">36</th>
<td>Surrey</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">37</th>
<td>Sussex</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">38</th>
<td>Thames Valley</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">39</th>
<td>Warwickshire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">40</th>
<td>West Mercia</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">41</th>
<td>West Midlands</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">42</th>
<td>West Yorkshire</td>
<td>False</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">43</th>
<td>Wiltshire</td>
<td>False</td>
<td>False</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>Let’s start with a simple visual observation: we look at the rate of detection per outcome for each force and group, with the start of mandatory attendance visible as the dashed vertical line.</p>
<div id="cell-28" class="cell page-columns page-full" data-execution_count="13">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1">linear_comparator_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> force_comparison.merge(msf_groups, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'right'</span>, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>)</span>
<span id="cb13-2">linear_comparator_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_A'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_B'</span>]].merge(time_series, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'left'</span>, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>)</span>
<span id="cb13-3"></span>
<span id="cb13-4">linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>]  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb13-5"></span>
<span id="cb13-6">df_a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_A'</span>]]</span>
<span id="cb13-7">df_b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group_B'</span>]]</span>
<span id="cb13-8"></span>
<span id="cb13-9">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_subplots(rows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, cols<span class="op" 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="cb13-10"></span>
<span id="cb13-11"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> force <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> df_a[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].unique():</span>
<span id="cb13-12">    force_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_a[df_a[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> force]</span>
<span id="cb13-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> force <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bedfordshire'</span>:</span>
<span id="cb13-14">        fig.add_trace(</span>
<span id="cb13-15">            go.Scatter(</span>
<span id="cb13-16">            x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force, line<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>, width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb13-17">                              dash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dash'</span>)),</span>
<span id="cb13-18">            row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col<span class="op" 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="cb13-19">        )</span>
<span id="cb13-20">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb13-21">        force_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_a[df_a[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> force]</span>
<span id="cb13-22">        fig.add_trace(</span>
<span id="cb13-23">            go.Scatter(</span>
<span id="cb13-24">            x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force),</span>
<span id="cb13-25">            row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col<span class="op" 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="cb13-26">        )</span>
<span id="cb13-27"></span>
<span id="cb13-28"></span>
<span id="cb13-29"></span>
<span id="cb13-30"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> force <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> df_b[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].unique():</span>
<span id="cb13-31">    force_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_b[df_b[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> force]</span>
<span id="cb13-32">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> force <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Northamptonshire'</span>:</span>
<span id="cb13-33">        fig.add_trace(</span>
<span id="cb13-34">            go.Scatter(</span>
<span id="cb13-35">            x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force, line<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>(color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>, width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb13-36">                              dash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dash'</span>)),</span>
<span id="cb13-37">            row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, col<span class="op" 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="cb13-38">        )</span>
<span id="cb13-39">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb13-40">        fig.add_trace(</span>
<span id="cb13-41">            go.Scatter(</span>
<span id="cb13-42">            x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>], y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>], name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>force),</span>
<span id="cb13-43">            row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, col<span class="op" 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="cb13-44">        )</span>
<span id="cb13-45"></span>
<span id="cb13-46"></span>
<span id="cb13-47">fig.add_vline(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2020-01-01'</span>, row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, line_dash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dash"</span>)</span>
<span id="cb13-48">fig.add_vline(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-04-01'</span>, row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,line_dash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dash"</span>)</span>
<span id="cb13-49"></span>
<span id="cb13-50">fig.update_xaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Date"</span>)</span>
<span id="cb13-51">fig.update_layout(height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span>, title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Detected Outcomes per Quarter and Force, and start of Mandatory Attendance"</span>)</span>
<span id="cb13-52"></span>
<span id="cb13-53">fig.update_yaxes(title_text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Detected Rate"</span>)</span>
<span id="cb13-54"></span>
<span id="cb13-55">fig.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-screen">
<div>                            <div id="7efcab74-5d2f-4296-b342-66fc5ee1438d" class="plotly-graph-div" style="height:700px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("7efcab74-5d2f-4296-b342-66fc5ee1438d")) {                    Plotly.newPlot(                        "7efcab74-5d2f-4296-b342-66fc5ee1438d",                        [{"line":{"color":"red","dash":"dash","width":4},"name":"Bedfordshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[10.507880910683012,8.108108108108109,3.277378097521982,4.403522818254603,8.707607699358388,8.123791102514506,5.952380952380952,5.0687285223367695,5.769230769230769,6.998654104979811,7.759562841530054,7.459207459207459,8.25147347740668,6.72,4.603174603174604,6.25,8.695652173913043,3.25,7.017543859649122,2.782931354359926],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Essex","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[8.032861706983113,7.453416149068323,5.048169556840077,4.551661356395084,5.220476431829701,5.3438891637803065,4.197150558336542,4.852941176470589,7.180293501048219,5.266272189349112,2.776349614395887,4.617752693689072,4.038772213247173,6.0,7.02446724546172,5.893186003683241,4.775280898876404,4.37956204379562,3.180760279286268,4.003079291762894],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Hampshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[7.7279037482646915,5.673076923076923,7.322068612391193,5.955603681645912,6.339581036383682,5.674518201284797,6.222654350996597,2.9471544715447155,4.9237983587338805,5.873642645607108,6.27431906614786,4.133180252583238,4.3678160919540225,3.4822601839684624,2.802460697197539,3.138373751783167,2.8708133971291865,3.4175334323922733,2.1144278606965177,2.052980132450331],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Hertfordshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[5.119152691968226,5.319969159599075,4.093567251461988,5.559673832468495,6.215213358070501,7.31244064577398,3.278688524590164,3.288888888888889,4.444444444444445,4.72972972972973,3.0141843971631204,5.742574257425743,4.426229508196721,3.0015797788309637,5.7894736842105265,2.6595744680851063,3.505535055350553,5.902192242833052,2.2522522522522523,2.037617554858934],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Kent","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[5.598755832037325,5.102954341987466,5.868971792538671,4.389773275446213,6.221776216758655,3.2085561497326207,2.523789822093504,1.2873563218390804,4.1757049891540134,6.706327744726879,3.0791788856304985,2.5452488687782804,4.855195911413969,4.94752623688156,3.6127167630057806,1.4202172096908938,4.9393414211438476,6.804979253112033,1.6881028938906755,4.129554655870446],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Leicestershire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[5.269922879177378,4.08295528191834,4.651162790697675,3.6721311475409837,5.141980046047583,4.889807162534435,4.684788895315211,5.9071729957805905,5.577689243027888,9.011164274322168,5.826656955571741,6.057945566286216,8.345534407027818,5.463182897862233,2.694610778443114,5.169628432956381,6.729264475743349,8.095238095238095,4.993909866017052,3.3918128654970756],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Nottinghamshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[7.090301003344482,8.310055865921788,6.129032258064516,6.12094395280236,6.744487678339818,6.952303961196443,4.7913446676970635,6.983883346124328,5.284888521882741,6.88622754491018,5.294506949040371,5.320699708454811,7.325581395348838,7.076923076923077,5.22167487684729,6.075334143377885,6.17906683480454,7.712418300653595,4.0793825799338475,4.887983706720977],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"South Yorkshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[6.521739130434782,6.456692913385827,3.932178932178932,4.769736842105264,4.41988950276243,5.061675882603148,3.0552694816340544,3.7563822027716993,4.270462633451958,5.403348554033485,3.821892393320965,3.5283993115318415,5.394736842105264,4.166666666666666,3.662494204914233,4.226069246435845,6.418485237483954,6.428988895382817,4.126846220677671,3.887510339123242],"type":"scatter","xaxis":"x","yaxis":"y"},{"name":"Avon and Somerset","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[5.206880520688053,5.223171889838556,4.054054054054054,5.266272189349112,5.706371191135734,4.767801857585139,3.9379474940334127,4.876504116529449,9.936708860759493,7.2666666666666675,7.297830374753452,6.370272063702721,7.358156028368794,5.791190864600326,4.817275747508306,5.95903165735568,6.279287722586692,6.9747166521360064,4.6255506607929515,3.9032006245121003],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Cheshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[10.126582278481013,11.28084606345476,7.306889352818372,8.958566629339305,9.449760765550238,9.884467265725288,7.151095732410612,7.5136612021857925,10.206561360874849,7.5136612021857925,8.114285714285714,7.233065442020665,9.03522205206738,9.554140127388536,7.225433526011561,6.475903614457831,4.270462633451958,7.750759878419452,6.5625,6.557377049180328],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Derbyshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[7.766990291262135,5.258215962441314,3.520536462699078,2.3890784982935154,5.200729927007299,4.297224709042077,3.1102733270499527,3.632694248234107,3.831041257367387,3.966597077244259,2.59222333000997,4.530011325028313,5.128205128205128,4.144385026737968,5.042016806722689,5.799151343705799,4.311774461028192,2.8192371475953566,2.973977695167286,5.47112462006079],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Essex","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[8.032861706983113,7.453416149068323,5.048169556840077,4.551661356395084,5.220476431829701,5.3438891637803065,4.197150558336542,4.852941176470589,7.180293501048219,5.266272189349112,2.776349614395887,4.617752693689072,4.038772213247173,6.0,7.02446724546172,5.893186003683241,4.775280898876404,4.37956204379562,3.180760279286268,4.003079291762894],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Kent","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[5.598755832037325,5.102954341987466,5.868971792538671,4.389773275446213,6.221776216758655,3.2085561497326207,2.523789822093504,1.2873563218390804,4.1757049891540134,6.706327744726879,3.0791788856304985,2.5452488687782804,4.855195911413969,4.94752623688156,3.6127167630057806,1.4202172096908938,4.9393414211438476,6.804979253112033,1.6881028938906755,4.129554655870446],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"line":{"color":"blue","dash":"dash","width":4},"name":"Northamptonshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[3.651354534746761,5.603448275862069,3.425309229305423,3.1216361679224973,3.5107587768969424,4.050925925925926,2.6188166828322017,3.046594982078853,3.830911492734478,4.25531914893617,5.4331864904552125,2.8764805414551606,5.656565656565657,4.488330341113106,4.504504504504505,3.6363636363636362,7.862407862407863,6.625258799171843,3.2490974729241873,2.9296875],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Nottinghamshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[7.090301003344482,8.310055865921788,6.129032258064516,6.12094395280236,6.744487678339818,6.952303961196443,4.7913446676970635,6.983883346124328,5.284888521882741,6.88622754491018,5.294506949040371,5.320699708454811,7.325581395348838,7.076923076923077,5.22167487684729,6.075334143377885,6.17906683480454,7.712418300653595,4.0793825799338475,4.887983706720977],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"name":"Staffordshire","x":["2017-01-01T00:00:00","2017-04-01T00:00:00","2017-07-01T00:00:00","2017-10-01T00:00:00","2018-01-01T00:00:00","2018-04-01T00:00:00","2018-07-01T00:00:00","2018-10-01T00:00:00","2019-01-01T00:00:00","2019-04-01T00:00:00","2019-07-01T00:00:00","2019-10-01T00:00:00","2020-01-01T00:00:00","2020-04-01T00:00:00","2020-07-01T00:00:00","2020-10-01T00:00:00","2021-01-01T00:00:00","2021-04-01T00:00:00","2021-07-01T00:00:00","2021-10-01T00:00:00"],"y":[8.383751080380295,8.595194085027726,6.827309236947792,6.153846153846154,6.926406926406926,7.31958762886598,5.005324813631523,7.777777777777778,7.37913486005089,5.344585091420535,7.561436672967864,2.8105167724388034,7.024793388429752,6.598984771573605,4.676258992805756,7.218683651804671,5.36480686695279,5.301645338208409,7.078313253012049,5.114638447971781],"type":"scatter","xaxis":"x2","yaxis":"y2"}],                        {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"marker":{"line":{"color":"#283442"}},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#f2f5fa"},"error_y":{"color":"#f2f5fa"},"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"marker":{"line":{"color":"#283442"}},"type":"scattergl"}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"baxis":{"endlinecolor":"#A2B1C6","gridcolor":"#506784","linecolor":"#506784","minorgridcolor":"#506784","startlinecolor":"#A2B1C6"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#506784"},"line":{"color":"rgb(17,17,17)"}},"header":{"fill":{"color":"#2a3f5f"},"line":{"color":"rgb(17,17,17)"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"rgb(17,17,17)","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#f2f5fa"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"rgb(17,17,17)","plot_bgcolor":"rgb(17,17,17)","polar":{"bgcolor":"rgb(17,17,17)","angularaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"radialaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"ternary":{"bgcolor":"rgb(17,17,17)","aaxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"baxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""},"caxis":{"gridcolor":"#506784","linecolor":"#506784","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"#283442","linecolor":"#506784","ticks":"","title":{"standoff":15},"zerolinecolor":"#283442","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"yaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2},"zaxis":{"backgroundcolor":"rgb(17,17,17)","gridcolor":"#506784","linecolor":"#506784","showbackground":true,"ticks":"","zerolinecolor":"#C8D4E3","gridwidth":2}},"shapedefaults":{"line":{"color":"#f2f5fa"}},"annotationdefaults":{"arrowcolor":"#f2f5fa","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"rgb(17,17,17)","landcolor":"rgb(17,17,17)","subunitcolor":"#506784","showland":true,"showlakes":true,"lakecolor":"rgb(17,17,17)"},"title":{"x":0.05},"updatemenudefaults":{"bgcolor":"#506784","borderwidth":0},"sliderdefaults":{"bgcolor":"#C8D4E3","borderwidth":1,"bordercolor":"rgb(17,17,17)","tickwidth":0},"mapbox":{"style":"dark"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"Date"}},"yaxis":{"anchor":"x","domain":[0.575,1.0],"title":{"text":"Detected Rate"}},"xaxis2":{"anchor":"y2","domain":[0.0,1.0],"title":{"text":"Date"}},"yaxis2":{"anchor":"x2","domain":[0.0,0.425],"title":{"text":"Detected Rate"}},"shapes":[{"line":{"dash":"dash"},"type":"line","x0":"2020-01-01","x1":"2020-01-01","xref":"x","y0":0,"y1":1,"yref":"y domain"},{"line":{"dash":"dash"},"type":"line","x0":"2019-04-01","x1":"2019-04-01","xref":"x2","y0":0,"y1":1,"yref":"y2 domain"}],"title":{"text":"Detected Outcomes per Quarter and Force, and start of Mandatory Attendance"},"height":700},                        {"responsive": true}                    ).then(function(){
                            
var gd = document.getElementById('7efcab74-5d2f-4296-b342-66fc5ee1438d');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
<p>It looks, in a word, messy. There <em>might</em> be some sort of effect, but it certainly isn’t pronounced enough to visually observe. Instead, let’s use some statistical modelling to try and measure the average effect.</p>
</section>
<section id="statistical-modelling" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="statistical-modelling">Statistical Modelling</h2>
<section id="linear-models-with-time-effects" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="linear-models-with-time-effects">Linear Models with Time Effects</h3>
<p>With all our data, we now build a statistical model, predicting the detected outcome rate as a factor of force, their comparison group, their total offences, and the period in time.</p>
<div id="cell-30" class="cell page-columns page-full" data-execution_count="14">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1">linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Force'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'category'</span>)</span>
<span id="cb14-2">linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quarter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quarter'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'category'</span>)</span>
<span id="cb14-3">linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mandatory_attendance'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mandatory_attendance'</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'int'</span>)</span>
<span id="cb14-4"></span>
<span id="cb14-5"></span>
<span id="cb14-6">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>]</span>
<span id="cb14-7"></span>
<span id="cb14-8">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> patsy.dmatrix(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 + C(Force) + total_offences + mandatory_attendance + group_A + group_B  + C(quarter) + running_var"</span>, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>linear_comparator_df, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dataframe'</span>)</span>
<span id="cb14-9"></span>
<span id="cb14-10"></span>
<span id="cb14-11">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(y,X)</span>
<span id="cb14-12"></span>
<span id="cb14-13">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit()</span>
<span id="cb14-14"></span>
<span id="cb14-15">results.summary()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="14">
<table class="simpletable caption-top table table-sm table-striped small">
<caption>OLS Regression Results</caption>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Dep. Variable:</th>
<td>detected_rate</td>
<th data-quarto-table-cell-role="th">R-squared:</th>
<td>0.551</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Model:</th>
<td>OLS</td>
<th data-quarto-table-cell-role="th">Adj. R-squared:</th>
<td>0.518</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Method:</th>
<td>Least Squares</td>
<th data-quarto-table-cell-role="th">F-statistic:</th>
<td>16.44</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Date:</th>
<td>Sat, 31 Dec 2022</td>
<th data-quarto-table-cell-role="th">Prob (F-statistic):</th>
<td>1.59e-32</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Time:</th>
<td>16:25:24</td>
<th data-quarto-table-cell-role="th">Log-Likelihood:</th>
<td>-426.89</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">No. Observations:</th>
<td>260</td>
<th data-quarto-table-cell-role="th">AIC:</th>
<td>891.8</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Df Residuals:</th>
<td>241</td>
<th data-quarto-table-cell-role="th">BIC:</th>
<td>959.4</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Df Model:</th>
<td>18</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Covariance Type:</th>
<td>nonrobust</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
</tbody>
</table>


<table class="simpletable caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<td></td>
<th data-quarto-table-cell-role="th">coef</th>
<th data-quarto-table-cell-role="th">std err</th>
<th data-quarto-table-cell-role="th">t</th>
<th data-quarto-table-cell-role="th">P&gt;|t|</th>
<th data-quarto-table-cell-role="th">[0.025</th>
<th data-quarto-table-cell-role="th">0.975]</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Avon and Somerset]</th>
<td>3.6335</td>
<td>0.530</td>
<td>6.861</td>
<td>0.000</td>
<td>2.590</td>
<td>4.677</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[Bedfordshire]</th>
<td>3.1250</td>
<td>0.322</td>
<td>9.720</td>
<td>0.000</td>
<td>2.492</td>
<td>3.758</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Cheshire]</th>
<td>4.9698</td>
<td>0.291</td>
<td>17.099</td>
<td>0.000</td>
<td>4.397</td>
<td>5.542</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[Derbyshire]</th>
<td>1.3595</td>
<td>0.322</td>
<td>4.226</td>
<td>0.000</td>
<td>0.726</td>
<td>1.993</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Essex]</th>
<td>-2.4339</td>
<td>0.274</td>
<td>-8.877</td>
<td>0.000</td>
<td>-2.974</td>
<td>-1.894</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[Hampshire]</th>
<td>2.8248</td>
<td>0.468</td>
<td>6.031</td>
<td>0.000</td>
<td>1.902</td>
<td>3.747</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Hertfordshire]</th>
<td>1.4803</td>
<td>0.277</td>
<td>5.341</td>
<td>0.000</td>
<td>0.934</td>
<td>2.026</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[Kent]</th>
<td>-3.5083</td>
<td>0.277</td>
<td>-12.671</td>
<td>0.000</td>
<td>-4.054</td>
<td>-2.963</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Leicestershire]</th>
<td>2.8885</td>
<td>0.294</td>
<td>9.821</td>
<td>0.000</td>
<td>2.309</td>
<td>3.468</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[Northamptonshire]</th>
<td>0.6208</td>
<td>0.350</td>
<td>1.774</td>
<td>0.077</td>
<td>-0.068</td>
<td>1.310</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Nottinghamshire]</th>
<td>-2.1424</td>
<td>0.419</td>
<td>-5.118</td>
<td>0.000</td>
<td>-2.967</td>
<td>-1.318</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[South Yorkshire]</th>
<td>3.5578</td>
<td>0.705</td>
<td>5.045</td>
<td>0.000</td>
<td>2.169</td>
<td>4.947</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[Staffordshire]</th>
<td>3.2984</td>
<td>0.292</td>
<td>11.288</td>
<td>0.000</td>
<td>2.723</td>
<td>3.874</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">group_A[T.True]</th>
<td>5.7917</td>
<td>0.632</td>
<td>9.165</td>
<td>0.000</td>
<td>4.547</td>
<td>7.037</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">group_B[T.True]</th>
<td>5.7974</td>
<td>0.455</td>
<td>12.730</td>
<td>0.000</td>
<td>4.900</td>
<td>6.694</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(quarter)[T.2]</th>
<td>-0.0319</td>
<td>0.231</td>
<td>-0.138</td>
<td>0.890</td>
<td>-0.487</td>
<td>0.423</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(quarter)[T.3]</th>
<td>-1.0204</td>
<td>0.259</td>
<td>-3.937</td>
<td>0.000</td>
<td>-1.531</td>
<td>-0.510</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(quarter)[T.4]</th>
<td>-1.0813</td>
<td>0.247</td>
<td>-4.370</td>
<td>0.000</td>
<td>-1.569</td>
<td>-0.594</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">total_offences</th>
<td>-0.0013</td>
<td>0.000</td>
<td>-2.707</td>
<td>0.007</td>
<td>-0.002</td>
<td>-0.000</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">mandatory_attendance</th>
<td>0.7574</td>
<td>0.442</td>
<td>1.714</td>
<td>0.088</td>
<td>-0.113</td>
<td>1.628</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">running_var</th>
<td>-0.1198</td>
<td>0.027</td>
<td>-4.481</td>
<td>0.000</td>
<td>-0.172</td>
<td>-0.067</td>
</tr>
</tbody>
</table>


<table class="simpletable caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Omnibus:</th>
<td>1.754</td>
<th data-quarto-table-cell-role="th">Durbin-Watson:</th>
<td>1.763</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Prob(Omnibus):</th>
<td>0.416</td>
<th data-quarto-table-cell-role="th">Jarque-Bera (JB):</th>
<td>1.487</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Skew:</th>
<td>0.174</td>
<th data-quarto-table-cell-role="th">Prob(JB):</th>
<td>0.475</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Kurtosis:</th>
<td>3.128</td>
<th data-quarto-table-cell-role="th">Cond. No.</th>
<td>7.82e+19</td>
</tr>
</tbody>
</table>
<br><br>Notes:<br>[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.<br>[2] The smallest eigenvalue is 8.11e-32. This might indicate that there are<br>strong multicollinearity problems or that the design matrix is singular.
</div>
</div>
<p>Our model suggests that mandatory attendance may have had, on average, a small effect on performance, this was not significant - eg, it may have been down to sheer luck.</p>
<p>Let’s go a bit further, and add a interaction effect between time and our force variable - eg, accounting for the fact that performance may vary differently over time force, by force.</p>
<div id="cell-32" class="cell page-columns page-full" data-execution_count="15">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linear_comparator_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'detected_rate'</span>]</span>
<span id="cb15-2"></span>
<span id="cb15-3">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> patsy.dmatrix(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C(Force)*running_var + total_offences + mandatory_attendance + group_A + group_B  + C(quarter)"</span>, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>linear_comparator_df, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dataframe'</span>)</span>
<span id="cb15-4"></span>
<span id="cb15-5"></span>
<span id="cb15-6">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(y,X)</span>
<span id="cb15-7"></span>
<span id="cb15-8">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit()</span>
<span id="cb15-9"></span>
<span id="cb15-10">results.summary()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="15">
<table class="simpletable caption-top table table-sm table-striped small">
<caption>OLS Regression Results</caption>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Dep. Variable:</th>
<td>detected_rate</td>
<th data-quarto-table-cell-role="th">R-squared:</th>
<td>0.616</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Model:</th>
<td>OLS</td>
<th data-quarto-table-cell-role="th">Adj. R-squared:</th>
<td>0.565</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Method:</th>
<td>Least Squares</td>
<th data-quarto-table-cell-role="th">F-statistic:</th>
<td>12.22</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Date:</th>
<td>Sat, 31 Dec 2022</td>
<th data-quarto-table-cell-role="th">Prob (F-statistic):</th>
<td>6.57e-33</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Time:</th>
<td>16:25:24</td>
<th data-quarto-table-cell-role="th">Log-Likelihood:</th>
<td>-406.76</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">No. Observations:</th>
<td>260</td>
<th data-quarto-table-cell-role="th">AIC:</th>
<td>875.5</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Df Residuals:</th>
<td>229</td>
<th data-quarto-table-cell-role="th">BIC:</th>
<td>985.9</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Df Model:</th>
<td>30</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Covariance Type:</th>
<td>nonrobust</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
</tbody>
</table>


<table class="simpletable caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<td></td>
<th data-quarto-table-cell-role="th">coef</th>
<th data-quarto-table-cell-role="th">std err</th>
<th data-quarto-table-cell-role="th">t</th>
<th data-quarto-table-cell-role="th">P&gt;|t|</th>
<th data-quarto-table-cell-role="th">[0.025</th>
<th data-quarto-table-cell-role="th">0.975]</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Intercept</th>
<td>6.2968</td>
<td>0.805</td>
<td>7.827</td>
<td>0.000</td>
<td>4.712</td>
<td>7.882</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Bedfordshire]</th>
<td>1.6786</td>
<td>0.583</td>
<td>2.879</td>
<td>0.004</td>
<td>0.530</td>
<td>2.827</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Cheshire]</th>
<td>2.9897</td>
<td>0.959</td>
<td>3.118</td>
<td>0.002</td>
<td>1.101</td>
<td>4.879</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Derbyshire]</th>
<td>-1.9116</td>
<td>0.867</td>
<td>-2.205</td>
<td>0.028</td>
<td>-3.620</td>
<td>-0.204</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Essex]</th>
<td>-0.2824</td>
<td>0.500</td>
<td>-0.565</td>
<td>0.573</td>
<td>-1.268</td>
<td>0.703</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Hampshire]</th>
<td>2.2860</td>
<td>0.537</td>
<td>4.256</td>
<td>0.000</td>
<td>1.228</td>
<td>3.344</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Hertfordshire]</th>
<td>-0.2522</td>
<td>0.513</td>
<td>-0.492</td>
<td>0.623</td>
<td>-1.263</td>
<td>0.759</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Kent]</th>
<td>-1.8168</td>
<td>0.490</td>
<td>-3.704</td>
<td>0.000</td>
<td>-2.783</td>
<td>-0.850</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Leicestershire]</th>
<td>-0.3087</td>
<td>0.483</td>
<td>-0.639</td>
<td>0.523</td>
<td>-1.260</td>
<td>0.643</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Northamptonshire]</th>
<td>-3.0584</td>
<td>0.941</td>
<td>-3.252</td>
<td>0.001</td>
<td>-4.912</td>
<td>-1.205</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Nottinghamshire]</th>
<td>-0.6398</td>
<td>0.620</td>
<td>-1.032</td>
<td>0.303</td>
<td>-1.862</td>
<td>0.582</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.South Yorkshire]</th>
<td>0.8367</td>
<td>0.745</td>
<td>1.123</td>
<td>0.263</td>
<td>-0.632</td>
<td>2.305</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Staffordshire]</th>
<td>0.8295</td>
<td>0.902</td>
<td>0.919</td>
<td>0.359</td>
<td>-0.948</td>
<td>2.607</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">group_A[T.True]</th>
<td>1.5015</td>
<td>0.429</td>
<td>3.496</td>
<td>0.001</td>
<td>0.655</td>
<td>2.348</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">group_B[T.True]</th>
<td>2.0563</td>
<td>0.418</td>
<td>4.917</td>
<td>0.000</td>
<td>1.232</td>
<td>2.880</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(quarter)[T.2]</th>
<td>-0.0358</td>
<td>0.220</td>
<td>-0.162</td>
<td>0.871</td>
<td>-0.470</td>
<td>0.399</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(quarter)[T.3]</th>
<td>-1.0428</td>
<td>0.256</td>
<td>-4.077</td>
<td>0.000</td>
<td>-1.547</td>
<td>-0.539</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(quarter)[T.4]</th>
<td>-1.1036</td>
<td>0.240</td>
<td>-4.601</td>
<td>0.000</td>
<td>-1.576</td>
<td>-0.631</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">running_var</th>
<td>-0.0171</td>
<td>0.056</td>
<td>-0.305</td>
<td>0.761</td>
<td>-0.128</td>
<td>0.093</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Bedfordshire]:running_var</th>
<td>-0.1477</td>
<td>0.088</td>
<td>-1.670</td>
<td>0.096</td>
<td>-0.322</td>
<td>0.027</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Cheshire]:running_var</th>
<td>-0.1680</td>
<td>0.070</td>
<td>-2.388</td>
<td>0.018</td>
<td>-0.307</td>
<td>-0.029</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Derbyshire]:running_var</th>
<td>-0.0334</td>
<td>0.069</td>
<td>-0.487</td>
<td>0.627</td>
<td>-0.168</td>
<td>0.102</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Essex]:running_var</th>
<td>-0.1593</td>
<td>0.069</td>
<td>-2.320</td>
<td>0.021</td>
<td>-0.295</td>
<td>-0.024</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Hampshire]:running_var</th>
<td>-0.2698</td>
<td>0.068</td>
<td>-3.966</td>
<td>0.000</td>
<td>-0.404</td>
<td>-0.136</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Hertfordshire]:running_var</th>
<td>-0.1377</td>
<td>0.068</td>
<td>-2.032</td>
<td>0.043</td>
<td>-0.271</td>
<td>-0.004</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Kent]:running_var</th>
<td>-0.1106</td>
<td>0.068</td>
<td>-1.629</td>
<td>0.105</td>
<td>-0.244</td>
<td>0.023</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Leicestershire]:running_var</th>
<td>0.0146</td>
<td>0.068</td>
<td>0.216</td>
<td>0.829</td>
<td>-0.119</td>
<td>0.148</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.Northamptonshire]:running_var</th>
<td>0.0375</td>
<td>0.091</td>
<td>0.413</td>
<td>0.680</td>
<td>-0.141</td>
<td>0.216</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Nottinghamshire]:running_var</th>
<td>-0.0865</td>
<td>0.068</td>
<td>-1.273</td>
<td>0.204</td>
<td>-0.220</td>
<td>0.047</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">C(Force)[T.South Yorkshire]:running_var</th>
<td>-0.0445</td>
<td>0.068</td>
<td>-0.657</td>
<td>0.512</td>
<td>-0.178</td>
<td>0.089</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">C(Force)[T.Staffordshire]:running_var</th>
<td>-0.1167</td>
<td>0.068</td>
<td>-1.707</td>
<td>0.089</td>
<td>-0.251</td>
<td>0.018</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">total_offences</th>
<td>-0.0012</td>
<td>0.001</td>
<td>-2.279</td>
<td>0.024</td>
<td>-0.002</td>
<td>-0.000</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">mandatory_attendance</th>
<td>0.3016</td>
<td>0.777</td>
<td>0.388</td>
<td>0.698</td>
<td>-1.229</td>
<td>1.832</td>
</tr>
</tbody>
</table>


<table class="simpletable caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Omnibus:</th>
<td>3.734</td>
<th data-quarto-table-cell-role="th">Durbin-Watson:</th>
<td>2.028</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Prob(Omnibus):</th>
<td>0.155</td>
<th data-quarto-table-cell-role="th">Jarque-Bera (JB):</th>
<td>3.443</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Skew:</th>
<td>0.221</td>
<th data-quarto-table-cell-role="th">Prob(JB):</th>
<td>0.179</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Kurtosis:</th>
<td>3.350</td>
<th data-quarto-table-cell-role="th">Cond. No.</th>
<td>4.44e+18</td>
</tr>
</tbody>
</table>
<br><br>Notes:<br>[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.<br>[2] The smallest eigenvalue is 2.52e-29. This might indicate that there are<br>strong multicollinearity problems or that the design matrix is singular.
</div>
</div>
<p>No matter how we model it, we’re again not finding meaningful effects - mandatory attendance does seem to be associated with slightly higher detected rates, on average, but this isn’t statistically significant. Put simply, examining the “statistical noise” in the rest of our model, we can’t confidently say any increases aren’t just due to random luck.</p>
<p>As one final approach, we’ll use panel data using the <a href="https://bashtage.github.io/linearmodels/">LinearModels library</a> - far from the best way to examine how effects change over time, but not a bad starter for ten.</p>
<div id="cell-34" class="cell page-columns page-full" data-execution_count="16">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">panel_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> force_comparison.set_index([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Force"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"date"</span>])</span>
<span id="cb16-2">panel_data</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="16">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">total_offences</th>
<th data-quarto-table-cell-role="th">total_detected</th>
<th data-quarto-table-cell-role="th">detected_rate</th>
<th data-quarto-table-cell-role="th">mandatory_attendance</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Force</th>
<th data-quarto-table-cell-role="th">date</th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Avon and Somerset</th>
<th data-quarto-table-cell-role="th">2017-01-01</th>
<td>2151.0</td>
<td>112.0</td>
<td>0.052069</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Bedfordshire</th>
<th data-quarto-table-cell-role="th">2017-01-01</th>
<td>1142.0</td>
<td>120.0</td>
<td>0.105079</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">British Transport Police</th>
<th data-quarto-table-cell-role="th">2017-01-01</th>
<td>0.0</td>
<td>0.0</td>
<td>0.000000</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Cambridgeshire</th>
<th data-quarto-table-cell-role="th">2017-01-01</th>
<td>1109.0</td>
<td>99.0</td>
<td>0.089270</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Cheshire</th>
<th data-quarto-table-cell-role="th">2017-01-01</th>
<td>790.0</td>
<td>80.0</td>
<td>0.101266</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Warwickshire</th>
<th data-quarto-table-cell-role="th">2021-10-01</th>
<td>376.0</td>
<td>8.0</td>
<td>0.021277</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">West Mercia</th>
<th data-quarto-table-cell-role="th">2021-10-01</th>
<td>857.0</td>
<td>8.0</td>
<td>0.009335</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">West Midlands</th>
<th data-quarto-table-cell-role="th">2021-10-01</th>
<td>4061.0</td>
<td>93.0</td>
<td>0.022901</td>
<td>False</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">West Yorkshire</th>
<th data-quarto-table-cell-role="th">2021-10-01</th>
<td>2406.0</td>
<td>81.0</td>
<td>0.033666</td>
<td>False</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Wiltshire</th>
<th data-quarto-table-cell-role="th">2021-10-01</th>
<td>265.0</td>
<td>8.0</td>
<td>0.030189</td>
<td>False</td>
</tr>
</tbody>
</table>

<p>880 rows × 4 columns</p>
</div>
</div>
</div>
<div id="cell-35" class="cell page-columns page-full" data-execution_count="17">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">mod <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> PanelOLS.from_formula(</span>
<span id="cb17-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"detected_rate ~ 1 + mandatory_attendance + EntityEffects + TimeEffects"</span>, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>panel_data</span>
<span id="cb17-3">)</span>
<span id="cb17-4">mod.fit()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display column-page" data-execution_count="17">
<table class="simpletable caption-top table table-sm table-striped small">
<caption>PanelOLS Estimation Summary</caption>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">Dep. Variable:</th>
<td>detected_rate</td>
<th data-quarto-table-cell-role="th">R-squared:</th>
<td>0.0013</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Estimator:</th>
<td>PanelOLS</td>
<th data-quarto-table-cell-role="th">R-squared (Between):</th>
<td>-0.0444</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">No. Observations:</th>
<td>880</td>
<th data-quarto-table-cell-role="th">R-squared (Within):</th>
<td>-0.0013</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Date:</th>
<td>Sat, Dec 31 2022</td>
<th data-quarto-table-cell-role="th">R-squared (Overall):</th>
<td>-0.0059</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Time:</th>
<td>16:25:24</td>
<th data-quarto-table-cell-role="th">Log-likelihood</th>
<td>1326.8</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Cov. Estimator:</th>
<td>Unadjusted</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th"></th>
<td></td>
<th data-quarto-table-cell-role="th">F-statistic:</th>
<td>1.0290</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Entities:</th>
<td>44</td>
<th data-quarto-table-cell-role="th">P-value</th>
<td>0.3107</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Avg Obs:</th>
<td>20.000</td>
<th data-quarto-table-cell-role="th">Distribution:</th>
<td>F(1,816)</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Min Obs:</th>
<td>20.000</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Max Obs:</th>
<td>20.000</td>
<th data-quarto-table-cell-role="th">F-statistic (robust):</th>
<td>1.0290</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th"></th>
<td></td>
<th data-quarto-table-cell-role="th">P-value</th>
<td>0.3107</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Time periods:</th>
<td>20</td>
<th data-quarto-table-cell-role="th">Distribution:</th>
<td>F(1,816)</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Avg Obs:</th>
<td>44.000</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Min Obs:</th>
<td>44.000</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Max Obs:</th>
<td>44.000</td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th"></th>
<td></td>
<th data-quarto-table-cell-role="th"></th>
<td></td>
</tr>
</tbody>
</table>


<table class="simpletable caption-top table table-sm table-striped small">
<caption>Parameter Estimates</caption>
<tbody>
<tr class="odd">
<td></td>
<th data-quarto-table-cell-role="th">Parameter</th>
<th data-quarto-table-cell-role="th">Std. Err.</th>
<th data-quarto-table-cell-role="th">T-stat</th>
<th data-quarto-table-cell-role="th">P-value</th>
<th data-quarto-table-cell-role="th">Lower CI</th>
<th data-quarto-table-cell-role="th">Upper CI</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Intercept</th>
<td>0.0614</td>
<td>0.0019</td>
<td>31.890</td>
<td>0.0000</td>
<td>0.0576</td>
<td>0.0652</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">mandatory_attendance</th>
<td>0.0155</td>
<td>0.0153</td>
<td>1.0144</td>
<td>0.3107</td>
<td>-0.0145</td>
<td>0.0456</td>
</tr>
</tbody>
</table>
<br><br>F-test for Poolability: 2.3035<br>P-value: 0.0000<br>Distribution: F(62,816)<br><br>Included effects: Entity, Time<br>id: 0x1ecad429930
</div>
</div>
<p>A similar pattern emerges - we see a small increase associated with mandatory attendance, but it’s non-significant - the increases are too small or too random to say the effect is associated due to attendance, rather than just random data noise.</p>
<p>That said, there are plenty of issues with our approach! We’ve only tried straightforward linear approaches, and given we’re relying on two forces and quarterly data, we’d struggle to detect small effects… hopefully we’ll notice something more stark when I come back to this in a few months for <strong>part 2, time series approaches!</strong></p>


</section>
</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>policing</category>
  <category>crime</category>
  <category>data-science</category>
  <guid>https://andreasthinks.me/posts/burglary_attendance/</guid>
  <pubDate>Thu, 29 Dec 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>I’ve migrated to Quarto!</title>
  <link>https://andreasthinks.me/posts/migrated_to_quarto/</link>
  <description><![CDATA[ 





<p>Well, isn’t this all fancy and posh! After much back and forth over a decent blogging platform, I think I’ve finally found a decent, well maintained home … meet <a href="https://quarto.org/">Quarto!</a></p>
<p>So, what did I want from a blogging platform, and why did it take so long to get here?</p>
<ul>
<li>Easily maintained, static pages (no paying for fancy maintained services<sup>1</sup>)</li>
<li>Native(ish) support for <a href="https://jupyter.org/">Python Jupyter</a> notebooks and <a href="https://rmarkdown.rstudio.com/">RMarkdown</a></li>
<li>Support for both technical writing (functions, code, citations) and interactive elements</li>
<li>Make it pretty!</li>
</ul>
<p>So, does it work? Is it pretty? It’s <em>gorgeous</em>.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/migrated_to_quarto/unsplash.jpg" class="img-fluid figure-img" alt="A picture of a red computer chip."></p>
<figcaption>Gorgeous pictures! With Alt Text!</figcaption>
</figure>
</div>
<p>I’ve tried a variety of options over the past few years (notably <a href="https://getpelican.com/">Pelican</a>, <a href="https://getnikola.com/">Nikola</a> and <a href="https://gohugo.io/">Hugo</a>) but none of them have quite fit the bill</p>

<div class="no-row-height column-margin column-container"><div class="">
<p>I eventually settled on Nikola because of how consistenly it handled Jupyter, but found RMarkdown support a pain, and it wasn’t quite as well maintained and documented as I would have liked.</p>
</div></div><p>You’ve probably also noted some of the niftier other features of Quarto sprinkled through this, especially for technical writing… callouts, citations, bibliographies ahoy!</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Check out a Callout!
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>I’ve been using Obsidian to manage my personal notes for a few months, and being able to make notes gorgeous and functional has been a real pleasure…now I can share that with everyone else!</p>
</div>
</div>
</div>
<p>With native support for interactive Jupyter widgets, I’m looking forward to seeing just how many plots and maps I can show off… It’s a really promising start! I haven’t got anything too much to show for now, so instead check out this nifty, automatically generated plot.</p>
<div class="cell" data-layout-align="default">
<div class="cell-output-display">
<div>
<p></p><figure class="figure"><p></p>
<div>
<pre class="mermaid mermaid-js">flowchart LR
  A[Interactive plot?] --&gt; B(Excited audience...)
  B --&gt; C[Excitement!]
  B --&gt; D[Confusion!]
</pre>
</div>
<p></p></figure><p></p>
</div>
</div>
</div>
<p>Hopefully this is the first post of many on my new and improved blog, and I hope you enjoy it!</p>




<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="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>There are plenty of fancy companies that probably advertise on your favourite podcast or Youtube video, but I wanted to keep it simple.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>news</category>
  <guid>https://andreasthinks.me/posts/migrated_to_quarto/</guid>
  <pubDate>Tue, 27 Sep 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Hackers aren’t excited about AI (and other bits from CCCamp23)</title>
  <link>https://andreasthinks.me/posts/cccamp23/</link>
  <description><![CDATA[ 





<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/cccamp23/magnet_bus.jpg" class="img-fluid figure-img"></p>
<figcaption>Honestly, this wasn’t me.</figcaption>
</figure>
</div>
<p>So I’m sitting in Berlin airport, waiting to get home from <a href="https://en.wikipedia.org/wiki/Chaos_Communication_Camp">Chaos Communication Camp 2023.</a> It was, to put it bluntly, bloody fabulous… and my god, I’ve missed hanging out with a whole field of awesome nerds.</p>
<p>The enforced loneliness of the pandemic made me do a fair bit of reflecting on which social interactions I valued, and which I’m really not particularly fussed about, and community events organised by wholesome geeky folk to share what they’re passionate about are <em>absolutely</em> in the former. The younger me who nervously made his way to EMF Camp 2014 all by himself had no idea what he was signing up for, but I’ll be forever glad I did (and I’m still bitter we’ll never get another <a href="https://nineworlds.co.uk/index.html">Nine Worlds</a>).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/cccamp23/emf_2014.jpg" class="img-fluid figure-img"></p>
<figcaption>Camping with <a href="https://southlondonmakerspace.org/">South London Makerspace</a> at EMF Camp 2014</figcaption>
</figure>
</div>
<p>But with that gushing out of the way, here are a few interesting lessons I picked up this year…and I’ll hopefully see everyone again for <a href="https://www.emfcamp.org/">EMF 2024!</a></p>
<section id="the-hackers-arent-excited-by-ai" class="level3">
<h3 class="anchored" data-anchor-id="the-hackers-arent-excited-by-ai">The hackers aren’t excited by AI…</h3>
<p>Now, this is far from universal given CCC are a quite distinct, very German subset of the hacker community (and <a href="https://www.theregister.com/2023/05/06/ai_hacking_defcon/">DEFCON last week definitely had some LLM excitement</a>), but the lack of LLM talks in the schedule was <em>stark</em>… and and when they were mentioned, <a href="https://events.ccc.de/camp/2023/hub/camp23/en/event/unsupervised-pleasures-intersectional-language-models-for-queer-futures/">it was mostly critical</a>. In hindsight, this isn’t so surprising given actual open-source LLMs essentially don’t exist and are dominated by US behemoths.</p>
</section>
<section id="but-theyre-still-excited-by-space" class="level3">
<h3 class="anchored" data-anchor-id="but-theyre-still-excited-by-space">… but they’re still excited by SPACE</h3>
<p>Honestly, I was not ready for the amount of excitement about <a href="https://www.youtube.com/watch?v=xeKMS62GrTI">space</a>. I’d mostly forgotten Starlink was a thing, but there was real enthusiasm for the <a href="https://events.ccc.de/camp/2023/hub/camp23/en/event/cosmic-connectivity-starlink-satellite-swarms-and-the-hackers-final-frontier/">impact of reduced cheap satelite launches</a>. Given I know bugger all about space launches, microsats and so on, it was striking to meet more people who wanted to talk about Planet, OneWeb and Relativity Space than OpenAI.</p>
</section>
<section id="twitter-is-dead-long-live-the-fediverse" class="level3">
<h3 class="anchored" data-anchor-id="twitter-is-dead-long-live-the-fediverse">Twitter is dead, long live the Fediverse</h3>
<p>I moved over to <a href="https://fosstodon.org/@AndreasThinks">Mastodon</a> earlier this year, but it’s at times been tough to use it as my primary social media given how few of my colleagues have followed…annoyingly, Twitter still served up more relevant content, more frequently. Not so at camp: <a href="https://mastodon.social/tags/cccamp23">#CCCamp23 was buzzing during the entire event</a>. Again, I’m not sure how much of this comes down to Europe versus the US (with the <a href="https://mastodon.online/@FediFollows/107843022757513829">German government hosting it’s own server</a>) but especially given just how much the AI and machine learning communities remained glue to the birdsite, this was striking.</p>
</section>
<section id="people-are-angry-about-digital-identity" class="level3">
<h3 class="anchored" data-anchor-id="people-are-angry-about-digital-identity">People are angry about digital identity</h3>
<p>Now, yes, Germany is especially privacy focused (and I still think paying for everything with cash is mad), but <a href="https://commission.europa.eu/strategy-and-policy/priorities-2019-2024/europe-fit-digital-age/european-digital-identity_en">European efforts to introduce digital identity</a> got a fair few mentions, and never in a good way. CCCamp is a broad church, with villages of techno-communists a few minutes walk from crypto-libertarians, but all of them were concerned by formalised state intrusion into the digital space.</p>
</section>
<section id="closed-systems-are-still-insecure" class="level3">
<h3 class="anchored" data-anchor-id="closed-systems-are-still-insecure">Closed systems are still insecure</h3>
<p>Okay, this one is a little niche (I needed a list of 5, sue me) but one of my highlight talks was <a href="https://events.ccc.de/camp/2023/hub/camp23/en/event/all-cops-are-broadcasting-obtaining-the-secret-tetra-primitives-after-decades-in-the-shadows/">All Cops Are Broadcasting</a>, discussing how security researchers had compromised the <a href="https://en.wikipedia.org/wiki/Terrestrial_Trunked_Radio">TETRA</a> (Airwave in the UK) communications system used by most police forces. I’ve never really thought much about the architecture behind Airwave, but turns out it relies on a cryptographic “secret sauce”. This is never a good way of designing something secure: <a href="https://en.wikipedia.org/wiki/Kerckhoffs%27s_principle">if your software/algorithm/cryptography relies on obscurity to stay safe, it will eventually become unsafe.</a> So I guess it’s a good thing that the <a href="https://www.theregister.com/2022/06/09/uk_police_legacy_airwave_bill/?td=rt-3a">Airwave replacement is right around the corner.</a></p>


</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>personal</category>
  <category>technology</category>
  <category>AI</category>
  <category>data-science</category>
  <guid>https://andreasthinks.me/posts/cccamp23/</guid>
  <pubDate>Sat, 20 Aug 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Learning GIS in Python - Robbery and Police Searches in Space</title>
  <link>https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space.html</link>
  <description><![CDATA[ 





<p>Amongst stuffing my face with wine and cheese, I’ve used this Christmas break to learn more about geospatial modelling in Python.</p>
<p>This blog post is largely intended for my reference and to act as a useful example for others…as such, it may be messy! I’ll try and tidy it into a Medium post in the coming weeks.</p>
<p>Space is an often disregarded dimension of modelling within policing research. As per <a href="https://en.wikipedia.org/wiki/Tobler%27s_first_law_of_geography">Tobler’s first law of geography, “everything is related to everything else, but near things are more related than distant things”</a>, and this is probably especially true of crime, that tenders to cluster in both time and space…treating your models as not having distinct physical locations that influence how they behave is likely to miss crucial information. <!-- TEASER_END --></p>
<p>Nearly all of the below is adapted from a fantastic work in progress book, <a href="https://geographicdata.science/book/intro.html">Geographic Data Science with PySAL and the PyData Stack</a> - I’ve found it hugely helpful, and the code examples are very approachable. I’d also recommend browsing the <a href="https://pysal.org/documentation">Pysal documentation.</a></p>
<p>All of the below is based on public data: - Police recorded crime and searches from January 2019 through October 2020 <a href="https://data.police.uk/data/">(data.police.uk)</a> - London MSOA geographic and demographic data <a href="https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london">(MOPAC)</a></p>
<p>The key libraries used are: - Standard Python libraries as included in <a href="https://www.anaconda.com/">Anaconda</a> (statsmodels, pandas, sklearn, seaborn) - <a href="https://geopandas.org/">Geopandas</a> - allowing you to read, write, and plot spatial data - <a href="https://pysal.org/">Pysal</a> - a collection of modules for geospatial data science</p>
<div id="cell-2" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#both of the below are used to read your directory</span></span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> glob </span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#core DS libraries</span></span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.cluster <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> KMeans, AgglomerativeClustering</span>
<span id="cb1-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#graphic libraries</span></span>
<span id="cb1-11"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt  </span>
<span id="cb1-12"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> matplotlib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> colors</span>
<span id="cb1-13"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> seaborn <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sns             </span>
<span id="cb1-14"></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geographic analysis</span></span>
<span id="cb1-16"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geopandas</span>
<span id="cb1-17"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.explore <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> esda   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Exploratory Spatial analytics</span></span>
<span id="cb1-18"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.lib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> weights</span>
<span id="cb1-19"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> contextily                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Background tiles</span></span>
<span id="cb1-20"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.viz <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> splot</span>
<span id="cb1-21"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> splot.esda <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> plot_moran</span>
<span id="cb1-22"></span>
<span id="cb1-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#positive outcomes to obtain detection rate</span></span>
<span id="cb1-24">positive_outcomes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb1-25">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given conditional discharge'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender fined'</span>,</span>
<span id="cb1-26">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given a drugs possession warning'</span>,</span>
<span id="cb1-27">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Court result unavailable'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Local resolution'</span>,</span>
<span id="cb1-28">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given community sentence'</span>,</span>
<span id="cb1-29">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given penalty notice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given a caution'</span>,</span>
<span id="cb1-30">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender sent to prison'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Court case unable to proceed'</span>,</span>
<span id="cb1-31">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Defendant found not guilty'</span>,</span>
<span id="cb1-32">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given suspended prison sentence'</span>,</span>
<span id="cb1-33">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Awaiting court outcome'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender otherwise dealt with'</span>,</span>
<span id="cb1-34">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Defendant sent to Crown Court'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender deprived of property'</span>,</span>
<span id="cb1-35">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender ordered to pay compensation'</span>,</span>
<span id="cb1-36">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offender given absolute discharge'</span>,</span>
<span id="cb1-37">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Formal action is not in the public interest'</span>,</span>
<span id="cb1-38">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Suspect charged as part of another case'</span>]</span></code></pre></div></div>
</div>
<section id="spatial-data" class="level2">
<h2 class="anchored" data-anchor-id="spatial-data">Spatial Data</h2>
<p>We begin by importing our spatial border data. Spatial coordinates are just coordinates, so without understanding what those coordinates mean (for instance, where you are in a city, or in the world, at what altitude, etc), they’re essentially points on a chart.</p>
<p>For us, this is provided by the <a href="https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london">Mayor’s Office for Policing and Crime</a>, and also conveniently contains some area characteristics. We use Geopandas to read the file.</p>
<p>Geospatial modelling relies on assigning events to a unit of space. You could theoretically make this as detailed as possible - for instance, meter squares - but given we’re going to analyse how our units are interconnected, that’s probably not computationally feasible (if everything is connected to everything, you’re going to need a really big computer). You’ll need to reach a suitable compromise. Helpfully, the UK government provides various statistical units, including border coordinates, for download. Lower Super Output Areas (LSOAs) and Middle Super Output Areas (MSOAs) contain populations of between 5,000 and 7,200, and as such should be (partly) comparable.</p>
<p>Geospatial data will use a specific <a href="https://cran.r-project.org/web/packages/eRTG3D/vignettes/v6.html#:~:text=coordinate%20reference%20system%20(CRS)%20is,between%20different%20spatial%20reference%20systems.">Coordinate Reference System, or CRS</a> which will affect how your data is processed. Make sure you’re using the right one - worldwide data that assumes it is on a sphere will behave very differently to data from a specific country on a flat plane.</p>
<p>UK policing data often uses National Grid Easting/Northing coordinates, rather than the more common Lat/Longs. Daata.Police.uk comes pre-processed into lat/long coordinates. Thankfully, whichever you have, geopandas can easily convert (or “re-project”) to another system.</p>
<div id="cell-4" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">msoas <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.read_file(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"statistical-gis-boundaries-london/MapInfo/MSOA_2011_London_gen_MHW.tab"</span>)</span>
<span id="cb2-2">msoas <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas.to_crs(epsg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>C:\Users\Admin\Anaconda3\envs\geospatial\lib\site-packages\geopandas\geodataframe.py:422: RuntimeWarning: Sequential read of iterator was interrupted. Resetting iterator. This can negatively impact the performance.
  for feature in features_lst:</code></pre>
</div>
</div>
<p>Our data on both stop and search and robberies was manually downloaded from data.police.uk, and extracted into our working folder. Given this is then returned into a folder per month, I have written a series of helper functions to read the files, assign them to an MSOA, and combine them into a total per MSOA.</p>
<p>To assign to an MSOA, we use a <a href="http://wiki.gis.com/wiki/index.php/Spatial_Join#:~:text=A%20Spatial%20join%20is%20a,spatially%20to%20other%20feature%20layers.">“spatial join”</a>: like a normal table join (think vlookup in Excel), this connects elements from one table, to elements from another, via a common column. In our case, the common column is the geographic location: which MSOA is our search/crime located in.</p>
<p>Crime data from <a href="https://data.police.uk/">data.police.uk</a> is separated into <a href="https://data.police.uk/about/">“major” crime types</a>, which is very helpful for anonymisation (we can’t figure out who the victim was if we don’t know specific crime types), but does mean that all violent and sexual crime is agglomerated into one - given I think it’s unlikely searches deter sexual offences, that’s unhelpful. As such, we’ll focus on robbery, which is disaggregated. This isn’t ideal, but robbery remains a serious, violent, high priority crime, and as such you’d hope they are connected, and robbery might in fact be a rough proxy for overall violence.</p>
<div id="cell-6" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_and_add(file_path):</span>
<span id="cb4-2">    df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(file_path)</span>
<span id="cb4-3">    robberies <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crime type"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Robbery'</span>]</span>
<span id="cb4-4">    </span>
<span id="cb4-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#we create a geopandas object that uses the lat/long coordinates, using the appropriate CRS code.</span></span>
<span id="cb4-6">    robberies <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.GeoDataFrame(robberies, geometry<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>geopandas.points_from_xy(robberies.Longitude, robberies.Latitude), crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"epsg:4326"</span>)</span>
<span id="cb4-7">    detected_mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> robberies[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Last outcome category"</span>].isin(positive_outcomes)</span>
<span id="cb4-8">    </span>
<span id="cb4-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># identify which crimes resulted in a detected outcome </span></span>
<span id="cb4-10">    robberies.loc[detected_mask, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Detected"</span>] <span class="op" 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="cb4-11">    detected_mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> robberies[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Last outcome category"</span>].isin(positive_outcomes)</span>
<span id="cb4-12"></span>
<span id="cb4-13">    detected_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> robberies[detected_mask]</span>
<span id="cb4-14">    robberies.loc[detected_mask, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Detected"</span>] <span class="op" 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="cb4-15"></span>
<span id="cb4-16">    dfsjoin_r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.sjoin(msoas, robberies) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Spatial join Points to polygons</span></span>
<span id="cb4-17">    dfsjoin_d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.sjoin(msoas, detected_df) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Spatial join Points to polygons</span></span>
<span id="cb4-18"></span>
<span id="cb4-19">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#aggregate to a pivot table that will count our outputs.</span></span>
<span id="cb4-20">    pivot_r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.pivot_table(dfsjoin_r,index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MSOA11CD'</span>,fill_value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime type'</span>,aggfunc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime type'</span>:<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>})</span>
<span id="cb4-21">    pivot_d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.pivot_table(dfsjoin_d,index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MSOA11CD'</span>,fill_value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime type'</span>,aggfunc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Crime type'</span>:<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>})</span>
<span id="cb4-22">    all_pivot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pivot_r.join(pivot_d, rsuffix<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"detected"</span>).reset_index()</span>
<span id="cb4-23">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> all_pivot.fillna(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
</div>
<div id="cell-7" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_and_add_search(file_path):</span>
<span id="cb5-2">    df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(file_path)</span>
<span id="cb5-3">    df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.GeoDataFrame(df, geometry<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>geopandas.points_from_xy(df.Longitude, df.Latitude), crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"epsg:4326"</span>)</span>
<span id="cb5-4">    dfsjoin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geopandas.sjoin(msoas, df) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Spatial join Points to polygons</span></span>
<span id="cb5-5">    pivot_d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dfsjoin.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>])[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Object of search'</span>].count()</span>
<span id="cb5-6"></span>
<span id="cb5-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#pivot_d = pd.pivot_table(dfsjoin,index='MSOA11CD',fill_value=0,columns='Object of search', aggfunc=len)</span></span>
<span id="cb5-8">    </span>
<span id="cb5-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pd.DataFrame(pivot_d.fillna(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)).reset_index()</span></code></pre></div></div>
</div>
<div id="cell-8" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> merge_dfs(list_of_df):</span>
<span id="cb6-2">    initial_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> list_of_df[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb6-3">    remaining <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> list_of_df[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:]</span>
<span id="cb6-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> pivot <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> remaining:</span>
<span id="cb6-5">        initial_df.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>, as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb6-6">        initial_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pivot.merge(initial_df.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>, as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(), how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"outer"</span>)</span>
<span id="cb6-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#initial_df.columns=["MSOA11CD","Robbery","Detected"]</span></span>
<span id="cb6-8">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dataframe length is "</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>(initial_df.shape[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]))</span>
<span id="cb6-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> initial_df</span></code></pre></div></div>
</div>
<div id="cell-9" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#we iterate over all files and subfolders in our data directory, and use the appropriate helper functions based on their last characters.</span></span>
<span id="cb7-2">list_of_pivot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb7-3">list_of_searches <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb7-4">rootdir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getcwd()</span>
<span id="cb7-5"></span>
<span id="cb7-6"></span>
<span id="cb7-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> subdir, dirs, files <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> os.walk(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>):</span>
<span id="cb7-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">file</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> files:</span>
<span id="cb7-9">        filepath <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> subdir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> os.sep <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">file</span></span>
<span id="cb7-10"></span>
<span id="cb7-11">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> filepath.endswith(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"street.csv"</span>):</span>
<span id="cb7-12">            list_of_pivot.append(read_and_add(filepath))</span>
<span id="cb7-13">            </span>
<span id="cb7-14">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> filepath.endswith(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search.csv"</span>):</span>
<span id="cb7-15">            list_of_searches.append(read_and_add_search(filepath))</span>
<span id="cb7-16"></span>
<span id="cb7-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#now we concatenate all our individual dataframes into a single one</span></span>
<span id="cb7-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"aggregating robbery"</span>)</span>
<span id="cb7-19">final_pivot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> merge_dfs(list_of_pivot)</span>
<span id="cb7-20"></span>
<span id="cb7-21"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"aggregating searches"</span>)</span>
<span id="cb7-22">final_search <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> merge_dfs(list_of_searches)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>aggregating robbery</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>C:\Users\Admin\Anaconda3\envs\geospatial\lib\site-packages\pandas\core\generic.py:3889: PerformanceWarning: dropping on a non-lexsorted multi-index without a level parameter may impact performance.
  obj = obj._drop_axis(labels, axis, level=level, errors=errors)</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>dataframe length is 1705
aggregating searches
dataframe length is 1953</code></pre>
</div>
</div>
<div id="cell-10" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#finally, merge those into a single pivot with the sum of all incidents during our data, by MSOA.</span></span>
<span id="cb11-2">final_pivot.columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Robbery"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Detected"</span>]</span>
<span id="cb11-3">final_pivot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> final_pivot.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb11-4"></span>
<span id="cb11-5">final_search <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> final_search.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb11-6"></span>
<span id="cb11-7">final_join <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> final_search.join(final_pivot).reset_index().copy()</span>
<span id="cb11-8">final_join.columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_count"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_count"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"detected_robbery"</span>]</span></code></pre></div></div>
</div>
<div id="cell-11" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1">final_join</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">MSOA11CD</th>
<th data-quarto-table-cell-role="th">search_count</th>
<th data-quarto-table-cell-role="th">robbery_count</th>
<th data-quarto-table-cell-role="th">detected_robbery</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>E02000001</td>
<td>268</td>
<td>37</td>
<td>0.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>E02000002</td>
<td>173</td>
<td>38</td>
<td>2.0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>E02000003</td>
<td>294</td>
<td>115</td>
<td>7.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>E02000004</td>
<td>216</td>
<td>19</td>
<td>0.0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>E02000005</td>
<td>132</td>
<td>61</td>
<td>1.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">978</th>
<td>E02006927</td>
<td>581</td>
<td>68</td>
<td>7.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">979</th>
<td>E02006928</td>
<td>638</td>
<td>89</td>
<td>5.0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">980</th>
<td>E02006929</td>
<td>1373</td>
<td>146</td>
<td>7.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">981</th>
<td>E02006930</td>
<td>168</td>
<td>56</td>
<td>2.0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">982</th>
<td>E02006931</td>
<td>393</td>
<td>105</td>
<td>5.0</td>
</tr>
</tbody>
</table>

<p>983 rows × 4 columns</p>
</div>
</div>
</div>
<div id="cell-12" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1">final_join.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>MSOA11CD            E02000001E02000002E02000003E02000004E02000005E...
search_count                                                   477668
robbery_count                                                   60093
detected_robbery                                                 3054
dtype: object</code></pre>
</div>
</div>
<p>Our final file then, contains nearly 500,000 searches and just over 60,000 robberies (of which a suspect was found in around 3,000) across London’s 938 MSOAs.</p>
<div id="cell-14" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>)</span>
<span id="cb15-2">final_join[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> final_join[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"string"</span>)</span></code></pre></div></div>
</div>
<div id="cell-15" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">msoas <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas.merge(final_join, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>])</span></code></pre></div></div>
</div>
<p>We then re-combine this with our geometry file, before calculating a proportion of robbery detected figure, and a search per robbery rate - the final table is below.</p>
<div id="cell-17" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_solve"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"detected_robbery"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_count"</span>]</span>
<span id="cb17-2">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_rate"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_count"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_count"</span>]</span></code></pre></div></div>
</div>
<div id="cell-18" class="cell" data-execution_count="13">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1">msoas.index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11NM"</span>]</span></code></pre></div></div>
</div>
<p>The data is now processed. Now is probably a good time to write this to a file to retrieve it in the future.</p>
<div id="cell-20" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1">msoas.to_file(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoas.shp"</span>)</span>
<span id="cb19-2"></span>
<span id="cb19-3">msoas</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">MSOA11CD</th>
<th data-quarto-table-cell-role="th">MSOA11NM</th>
<th data-quarto-table-cell-role="th">LAD11CD</th>
<th data-quarto-table-cell-role="th">LAD11NM</th>
<th data-quarto-table-cell-role="th">RGN11CD</th>
<th data-quarto-table-cell-role="th">RGN11NM</th>
<th data-quarto-table-cell-role="th">UsualRes</th>
<th data-quarto-table-cell-role="th">HholdRes</th>
<th data-quarto-table-cell-role="th">ComEstRes</th>
<th data-quarto-table-cell-role="th">PopDen</th>
<th data-quarto-table-cell-role="th">Hholds</th>
<th data-quarto-table-cell-role="th">AvHholdSz</th>
<th data-quarto-table-cell-role="th">geometry</th>
<th data-quarto-table-cell-role="th">search_count</th>
<th data-quarto-table-cell-role="th">robbery_count</th>
<th data-quarto-table-cell-role="th">detected_robbery</th>
<th data-quarto-table-cell-role="th">robbery_solve</th>
<th data-quarto-table-cell-role="th">search_rate</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">MSOA11NM</th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">City of London 001</th>
<td>E02000001</td>
<td>City of London 001</td>
<td>E09000001</td>
<td>City of London</td>
<td>E12000007</td>
<td>London</td>
<td>7375</td>
<td>7187</td>
<td>188</td>
<td>25.5</td>
<td>4385</td>
<td>1.6</td>
<td>MULTIPOLYGON (((-0.09676 51.52325, -0.09644 51...</td>
<td>268</td>
<td>37</td>
<td>0.0</td>
<td>0.000000</td>
<td>7.243243</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Barking and Dagenham 001</th>
<td>E02000002</td>
<td>Barking and Dagenham 001</td>
<td>E09000002</td>
<td>Barking and Dagenham</td>
<td>E12000007</td>
<td>London</td>
<td>6775</td>
<td>6724</td>
<td>51</td>
<td>31.3</td>
<td>2713</td>
<td>2.5</td>
<td>POLYGON ((0.14811 51.59678, 0.14809 51.59640, ...</td>
<td>173</td>
<td>38</td>
<td>2.0</td>
<td>0.052632</td>
<td>4.552632</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Barking and Dagenham 002</th>
<td>E02000003</td>
<td>Barking and Dagenham 002</td>
<td>E09000002</td>
<td>Barking and Dagenham</td>
<td>E12000007</td>
<td>London</td>
<td>10045</td>
<td>10033</td>
<td>12</td>
<td>46.9</td>
<td>3834</td>
<td>2.6</td>
<td>POLYGON ((0.15065 51.58306, 0.14841 51.58075, ...</td>
<td>294</td>
<td>115</td>
<td>7.0</td>
<td>0.060870</td>
<td>2.556522</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Barking and Dagenham 003</th>
<td>E02000004</td>
<td>Barking and Dagenham 003</td>
<td>E09000002</td>
<td>Barking and Dagenham</td>
<td>E12000007</td>
<td>London</td>
<td>6182</td>
<td>5937</td>
<td>245</td>
<td>24.8</td>
<td>2318</td>
<td>2.6</td>
<td>POLYGON ((0.18511 51.56480, 0.18403 51.56391, ...</td>
<td>216</td>
<td>19</td>
<td>0.0</td>
<td>0.000000</td>
<td>11.368421</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Barking and Dagenham 004</th>
<td>E02000005</td>
<td>Barking and Dagenham 004</td>
<td>E09000002</td>
<td>Barking and Dagenham</td>
<td>E12000007</td>
<td>London</td>
<td>8562</td>
<td>8562</td>
<td>0</td>
<td>72.1</td>
<td>3183</td>
<td>2.7</td>
<td>POLYGON ((0.14990 51.56807, 0.15078 51.56778, ...</td>
<td>132</td>
<td>61</td>
<td>1.0</td>
<td>0.016393</td>
<td>2.163934</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Greenwich 034</th>
<td>E02006927</td>
<td>Greenwich 034</td>
<td>E09000011</td>
<td>Greenwich</td>
<td>E12000007</td>
<td>London</td>
<td>8315</td>
<td>8241</td>
<td>74</td>
<td>33.0</td>
<td>3338</td>
<td>2.5</td>
<td>POLYGON ((0.02900 51.46779, 0.02995 51.46592, ...</td>
<td>581</td>
<td>68</td>
<td>7.0</td>
<td>0.102941</td>
<td>8.544118</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Greenwich 035</th>
<td>E02006928</td>
<td>Greenwich 035</td>
<td>E09000011</td>
<td>Greenwich</td>
<td>E12000007</td>
<td>London</td>
<td>7341</td>
<td>6410</td>
<td>931</td>
<td>136.0</td>
<td>2977</td>
<td>2.2</td>
<td>MULTIPOLYGON (((-0.00961 51.48366, -0.00979 51...</td>
<td>638</td>
<td>89</td>
<td>5.0</td>
<td>0.056180</td>
<td>7.168539</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Greenwich 036</th>
<td>E02006929</td>
<td>Greenwich 036</td>
<td>E09000011</td>
<td>Greenwich</td>
<td>E12000007</td>
<td>London</td>
<td>7490</td>
<td>7489</td>
<td>1</td>
<td>29.4</td>
<td>3333</td>
<td>2.2</td>
<td>POLYGON ((0.01619 51.49578, 0.01854 51.49498, ...</td>
<td>1373</td>
<td>146</td>
<td>7.0</td>
<td>0.047945</td>
<td>9.404110</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Greenwich 037</th>
<td>E02006930</td>
<td>Greenwich 037</td>
<td>E09000011</td>
<td>Greenwich</td>
<td>E12000007</td>
<td>London</td>
<td>6561</td>
<td>6557</td>
<td>4</td>
<td>75.6</td>
<td>2876</td>
<td>2.3</td>
<td>POLYGON ((0.00866 51.48917, 0.00837 51.48877, ...</td>
<td>168</td>
<td>56</td>
<td>2.0</td>
<td>0.035714</td>
<td>3.000000</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">Greenwich 038</th>
<td>E02006931</td>
<td>Greenwich 038</td>
<td>E09000011</td>
<td>Greenwich</td>
<td>E12000007</td>
<td>London</td>
<td>9186</td>
<td>8973</td>
<td>213</td>
<td>46.1</td>
<td>4113</td>
<td>2.2</td>
<td>POLYGON ((-0.00201 51.48155, -0.00136 51.48145...</td>
<td>393</td>
<td>105</td>
<td>5.0</td>
<td>0.047619</td>
<td>3.742857</td>
</tr>
</tbody>
</table>

<p>983 rows × 18 columns</p>
</div>
</div>
</div>
</section>
<section id="analysis" class="level2">
<h2 class="anchored" data-anchor-id="analysis">Analysis</h2>
<p>Let’s start exploring our data. Before doing anything, we’ll use Pysal to create “spatial weights” - this let’s us understand our objects in space, and how they interact. There are a myriad of different methods, but we’ll just pick the 8 nearest MSOAs in space.</p>
<div id="cell-22" class="cell" data-execution_count="15">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate W from the GeoDataFrame</span></span>
<span id="cb20-2">w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.distance.KNN.from_dataframe(msoas, k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb20-3">w.neighbors[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'City of London 001'</span>]</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>['Islington 023',
 'Southwark 002',
 'Islington 022',
 'Hackney 027',
 'Hackney 026',
 'Southwark 006',
 'Southwark 003',
 'Southwark 009']</code></pre>
</div>
</div>
<div id="cell-23" class="cell" data-execution_count="16">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Row-standardization</span></span>
<span id="cb22-2">w.transform <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'R'</span></span></code></pre></div></div>
</div>
<p>We also create a spatial “lag” for our key values - this is one of the most straightforward measures of spatial relationships, and captures the products and weights of our value in neighbouring observations. Essentially, it’s the value of our metric, <em>weighted</em> by the value of the metric in neighbourhing observations - so clusters will expect to be high, while a single high value surrounded by low values will be diminished.</p>
<div id="cell-25" class="cell" data-execution_count="17">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_search_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>])</span>
<span id="cb23-2">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_count'</span>])</span>
<span id="cb23-3">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_rate'</span>])</span>
<span id="cb23-4"></span></code></pre></div></div>
</div>
<p>Let’s start by mapping out our key crime and search figures, and seeing if anything stands out.</p>
<div id="cell-27" class="cell" data-execution_count="19">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1">f, axs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(nrows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, ncols<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, figsize<span class="op" 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;">12</span>))</span>
<span id="cb24-2">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>, </span>
<span id="cb24-3">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb24-4">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb24-5">        k<span class="op" 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="cb24-6">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb24-7">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb24-8">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb24-9">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb24-10">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb24-11">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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="cb24-12">       )</span>
<span id="cb24-13"></span>
<span id="cb24-14">axs[<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>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Search Count'</span>)</span>
<span id="cb24-15"></span>
<span id="cb24-16">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_count'</span>, </span>
<span id="cb24-17">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb24-18">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb24-19">        k<span class="op" 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="cb24-20">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb24-21">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb24-22">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb24-23">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb24-24">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb24-25">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">1</span>]</span>
<span id="cb24-26">       )</span>
<span id="cb24-27"></span>
<span id="cb24-28">axs[<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;">1</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Robbery Count'</span>)</span>
<span id="cb24-29"></span>
<span id="cb24-30">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_solve'</span>, </span>
<span id="cb24-31">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb24-32">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb24-33">        k<span class="op" 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="cb24-34">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb24-35">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb24-36">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb24-37">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb24-38">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb24-39">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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="cb24-40">       )</span>
<span id="cb24-41"></span>
<span id="cb24-42">axs[<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>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Detected Robbery Proportion'</span>)</span>
<span id="cb24-43"></span>
<span id="cb24-44">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_rate'</span>, </span>
<span id="cb24-45">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb24-46">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb24-47">        k<span class="op" 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="cb24-48">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb24-49">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb24-50">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb24-51">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb24-52">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb24-53">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">1</span>]</span>
<span id="cb24-54">       )</span>
<span id="cb24-55"></span>
<span id="cb24-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#contextily pulls a background tile from online providers</span></span>
<span id="cb24-57">axs[<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;">1</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Search per Robbery'</span>)</span>
<span id="cb24-58"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> ax <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> axs.reshape(<span class="op" 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="cb24-59">        contextily.add_basemap(ax, </span>
<span id="cb24-60">                           crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>msoas.crs, </span>
<span id="cb24-61">                           source<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>contextily.providers.Stamen.TerrainBackground)</span>
<span id="cb24-62"></span>
<span id="cb24-63"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ax1.set_axis_off()</span></span>
<span id="cb24-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ax2.set_axis_off()</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-19-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>There are a few apparently spatial trends at play: - Searches and robberies seem most common in central London, though searches also seem to cluster on the Western area of the city - The proportion of robberies that are detected seems to be scaterred pretty randomly - The rate of search per robbery seems to form a “U” shape around the soutehrn side of the city, with the Northern edge standing out as potentially “under-policed”</p>
<p>Let’s ignore the spatial dimension for a second, and just create a correlation heatmap. This should let us identify any commonalities between our measured characteristics</p>
<div id="cell-30" class="cell" data-execution_count="20">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1">corr_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'UsualRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'HholdRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ComEstRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'PopDen'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Hholds'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'AvHholdSz'</span>,</span>
<span id="cb25-2">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_count'</span>,</span>
<span id="cb25-3">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_solve'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_rate'</span>,</span>
<span id="cb25-4">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_search_count'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>]</span>
<span id="cb25-5"></span>
<span id="cb25-6">sns.set_theme(style<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>)</span>
<span id="cb25-7"></span>
<span id="cb25-8">cmap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sns.diverging_palette(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">230</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, as_cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb25-9"></span>
<span id="cb25-10"></span>
<span id="cb25-11">plt.figure(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>))</span>
<span id="cb25-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># define the mask to set the values in the upper triangle to True</span></span>
<span id="cb25-13">mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.triu(np.ones_like(msoas[corr_cols].corr(), dtype<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">bool</span>))</span>
<span id="cb25-14">heatmap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sns.heatmap(msoas[corr_cols].corr(), mask<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>mask, vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, vmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, annot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>cmap)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-20-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>The good news is that search and robbery counts are closely correlated: those MSOAs where most robberies occur also see the most searches.</p>
<p>There is also a weak positive correlation (0.3) between commercial households and robberies - this is probably due to some combination of high footfall and affuluence.</p>
<p>There is also a negative relationship between the spatial lag of robberies, and the average household size - I’m not quite sure how to interpret this. Potentially those areas with lots of focused large households are large nexuses of robbery?</p>
<p>Let’s go a bit further by building a scatter plot between robbery and search counts.</p>
<div id="cell-33" class="cell" data-execution_count="21">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb26-1">sns.scatterplot(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_count"</span>, y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_count"</span>, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>msoas)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-21-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>It’s a bit of a mess. Most of our robberies are focused on the lower angle, with a few huge outliers. This might benefit from a log transformaton - keeping the key characteristics the same, but normalising our distribution and making the relationship linear.</p>
<div id="cell-35" class="cell" data-execution_count="22">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1">sns.scatterplot(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_count"</span>]), y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robbery_count"</span>]), data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>msoas)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-22-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>As planned, a lot better - this suggests a linear relationship between both variables, and they should now be normally distributed, allowing us to model them.</p>
<div id="cell-37" class="cell" data-execution_count="23">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1">sns.displot(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"search_rate"</span>]), kde<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-23-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="spatial-structures" class="level2">
<h2 class="anchored" data-anchor-id="spatial-structures">Spatial Structures</h2>
<p>To identify whether geography plays a role in how our values change, we’ll contrast the values to their spatial lag - the local value, impacted by their neighbours. This should <em>smooth out</em> any outliers, and let us get a general value per area, rather than by MSOA.</p>
<div id="cell-39" class="cell" data-tags="[&quot;hide-input&quot;]" data-execution_count="24">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1">f, axs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(nrows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, ncols<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, figsize<span class="op" 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;">12</span>))</span>
<span id="cb29-2">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>, </span>
<span id="cb29-3">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-4">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-5">        k<span class="op" 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="cb29-6">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-7">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-8">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-9">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-10">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-11">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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="cb29-12">       )</span>
<span id="cb29-13"></span>
<span id="cb29-14">axs[<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>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Search Count'</span>)</span>
<span id="cb29-15"></span>
<span id="cb29-16">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_search_count'</span>, </span>
<span id="cb29-17">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-18">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-19">        k<span class="op" 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="cb29-20">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-21">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-22">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-23">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-24">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-25">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">1</span>]</span>
<span id="cb29-26">       )</span>
<span id="cb29-27"></span>
<span id="cb29-28">axs[<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;">1</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Spatial Lag - Search Count'</span>)</span>
<span id="cb29-29"></span>
<span id="cb29-30">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_count'</span>, </span>
<span id="cb29-31">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-32">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-33">        k<span class="op" 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="cb29-34">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-35">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-36">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-37">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-38">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-39">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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="cb29-40">       )</span>
<span id="cb29-41"></span>
<span id="cb29-42">axs[<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>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Robbery Count'</span>)</span>
<span id="cb29-43"></span>
<span id="cb29-44">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>, </span>
<span id="cb29-45">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-46">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-47">        k<span class="op" 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="cb29-48">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-49">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-50">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-51">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-52">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-53">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">1</span>]</span>
<span id="cb29-54">       )</span>
<span id="cb29-55"></span>
<span id="cb29-56">axs[<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;">1</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Spatial Lag - Robbery Count'</span>)</span>
<span id="cb29-57"></span>
<span id="cb29-58">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_rate'</span>, </span>
<span id="cb29-59">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-60">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-61">        k<span class="op" 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="cb29-62">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-63">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-64">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-65">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-66">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-67">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">0</span>]</span>
<span id="cb29-68">       )</span>
<span id="cb29-69"></span>
<span id="cb29-70">axs[<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;">0</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Search per Robbery'</span>)</span>
<span id="cb29-71"></span>
<span id="cb29-72">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>, </span>
<span id="cb29-73">        cmap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, </span>
<span id="cb29-74">        scheme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'quantiles'</span>,</span>
<span id="cb29-75">        k<span class="op" 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="cb29-76">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, </span>
<span id="cb29-77">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>, </span>
<span id="cb29-78">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb29-79">        legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb29-80">        legend_kwds<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loc"</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>},</span>
<span id="cb29-81">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>axs[<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;">1</span>]</span>
<span id="cb29-82">       )</span>
<span id="cb29-83"></span>
<span id="cb29-84">axs[<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;">1</span>].title.set_text(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Spatial Lag - Search Rate'</span>)</span>
<span id="cb29-85"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> ax <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> axs.reshape(<span class="op" 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="cb29-86">        contextily.add_basemap(ax, </span>
<span id="cb29-87">                           crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>msoas.crs, </span>
<span id="cb29-88">                           source<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>contextily.providers.Stamen.TerrainBackground)</span>
<span id="cb29-89"></span>
<span id="cb29-90"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ax1.set_axis_off()</span></span>
<span id="cb29-91"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ax2.set_axis_off()</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-24-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Our spatial weights enable us to clearly identy trends in space: - the search count and robbery count is now far more focused on centralon London, with the exception of a few pockets - the north of London cluster stands out more distinctly as a location where the rate of search per robbery is distinctively lower</p>
</section>
<section id="clustering" class="level2">
<h2 class="anchored" data-anchor-id="clustering">Clustering</h2>
<p>As an alternative method for exploring our data, we’ll use some machine learning techniques to undertake some clustering. We’ll be using K Means clustering (which focuses on the mean of all our values, and picks the most similar other MSOAs) - given we’re now focusing on modelling, we’ll use the log values.</p>
<div id="cell-42" class="cell" data-execution_count="68">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb30-1">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_search_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>])</span>
<span id="cb30-2">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_robbery_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_count'</span>])</span>
<span id="cb30-3">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_rate'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_rate'</span>])</span>
<span id="cb30-4"></span>
<span id="cb30-5">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_search_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_search_count'</span>])</span>
<span id="cb30-6">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>])</span>
<span id="cb30-7">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.spatial_lag.lag_spatial(w, msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>])</span>
<span id="cb30-8"></span>
<span id="cb30-9">w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weights.distance.KNN.from_dataframe(msoas, k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb30-10"></span>
<span id="cb30-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Row-standardization</span></span>
<span id="cb30-12">w.transform <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'R'</span></span>
<span id="cb30-13"></span></code></pre></div></div>
</div>
<p>We’ll also include the demographic information provided by MOPAC (household numbers and populations), and use the KMeans Clustering implementation from sklearn. A number of clusters must be specified - I’ve gone for 5 on this occasion. We’ll then map them.</p>
<p>Essentially, we’re trying to aggregate MSOAs into 5 distinct groups, based on our crime and demographic characteristics.</p>
<div id="cell-44" class="cell" data-execution_count="175">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1">cluster_variables <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'UsualRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'HholdRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ComEstRes'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'PopDen'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Hholds'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'AvHholdSz'</span>, </span>
<span id="cb31-2">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'robbery_solve'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_search_count'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_robbery_count'</span>,</span>
<span id="cb31-3">       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'w_rate'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_search_count'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_robbery_count'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ln_rate'</span>]</span>
<span id="cb31-4"></span>
<span id="cb31-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Initialise KMeans instance</span></span>
<span id="cb31-6">kmeans <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> KMeans(n_clusters<span class="op" 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="cb31-7"></span>
<span id="cb31-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set the seed for reproducibility</span></span>
<span id="cb31-9">numpy.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1234</span>)</span>
<span id="cb31-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run K-Means algorithm</span></span>
<span id="cb31-11">k5cls <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> kmeans.fit(msoas[cluster_variables])</span>
<span id="cb31-12"></span>
<span id="cb31-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Assign labels into a column</span></span>
<span id="cb31-14">msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'k5cls'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> k5cls.labels_</span>
<span id="cb31-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Setup figure and ax</span></span>
<span id="cb31-16">f, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>))</span>
<span id="cb31-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot unique values choropleth including a legend and with no boundary lines</span></span>
<span id="cb31-18">msoas.plot(column<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'k5cls'</span>, categorical<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax)</span>
<span id="cb31-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Remove axis</span></span>
<span id="cb31-20">ax.set_axis_off()</span>
<span id="cb31-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keep axes proportionate</span></span>
<span id="cb31-22">plt.axis(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'equal'</span>)</span>
<span id="cb31-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add title</span></span>
<span id="cb31-24">plt.title(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r'Geodemographic Clusters </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">(</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">k-means, </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">k=5</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">)</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)</span>
<span id="cb31-25"></span>
<span id="cb31-26">contextily.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>msoas.crs, </span>
<span id="cb31-27">                           source<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>contextily.providers.Stamen.TerrainBackground)</span>
<span id="cb31-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Display the map</span></span>
<span id="cb31-29">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-26-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Interestingly, there are no clear patterns here: cluster membership is spread out throughout London. That said, we still don’t know what these actually mean - to understand that, we’ll visualise the distributions of our characteristics in each cluster.</p>
<div id="cell-46" class="cell" data-execution_count="174">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb32-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Index db on cluster ID</span></span>
<span id="cb32-2">tidy_db <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> msoas.set_index(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'k5cls'</span>)</span>
<span id="cb32-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keep only variables used for clustering</span></span>
<span id="cb32-4">tidy_db <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_db[cluster_variables]</span>
<span id="cb32-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Stack column names into a column, obtaining </span></span>
<span id="cb32-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a "long" version of the dataset</span></span>
<span id="cb32-7">tidy_db <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_db.stack()</span>
<span id="cb32-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Take indices into proper columns</span></span>
<span id="cb32-9">tidy_db <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_db.reset_index()</span>
<span id="cb32-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Rename column names</span></span>
<span id="cb32-11">tidy_db <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tidy_db.rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{</span>
<span id="cb32-12">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'level_1'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Attribute'</span>, </span>
<span id="cb32-13">                        <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;">'Values'</span>})</span>
<span id="cb32-14"></span>
<span id="cb32-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Setup the facets</span></span>
<span id="cb32-16">facets <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> seaborn.FacetGrid(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>tidy_db, col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Attribute'</span>, hue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'k5cls'</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb32-17">                  sharey<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, sharex<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>, aspect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, col_wrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb32-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build the plot from `sns.kdeplot`</span></span>
<span id="cb32-19">_ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> facets.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">map</span>(seaborn.kdeplot, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Values'</span>, shade<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>).add_legend()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-27-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>The defining metric seems to be density, but some other trends stand out: the densest group (3) also sees the largest proportion of robberies and searches, while conversely group 2 is the very opposite.</p>
</section>
<section id="spatial-autocorrelation" class="level2">
<h2 class="anchored" data-anchor-id="spatial-autocorrelation">Spatial Autocorrelation</h2>
<p>We’re now quite happy there are some spatial relationships in our data: where you are in London matters. It appears that an MSOA in the South and North of London might expect differnet numbers of searches and robberies, even were all there other characteristics the same. We can test this by checking for spatial auto-correlation in our data, the primary metric of which is Moran’s I.</p>
<div id="cell-49" class="cell" data-execution_count="75">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb33-1">moran <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> esda.moran.Moran(msoas[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'search_count'</span>], w)</span>
<span id="cb33-2"></span>
<span id="cb33-3">moran.I</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="75">
<pre><code>0.28837097453822225</code></pre>
</div>
</div>
<p>Our Moran’s I shows weak, positive autocorrelation accross our entire dataset: an MSOA with a high search count will generally be next to similar MSOAs.</p>
<div id="cell-51" class="cell" data-execution_count="76">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb35-1">moran.p_sim</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="76">
<pre><code>0.001</code></pre>
</div>
</div>
<p>The P statistic suggests this Moran’s I is statistically different to what we would expect if it were random (at P&lt;0.05) - we reject the hypothesis that there is no spatial dimension.</p>
<div id="cell-53" class="cell" data-execution_count="77">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb37-1">plot_moran(moran)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space_files/figure-html/cell-30-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="regression-modelling" class="level2">
<h2 class="anchored" data-anchor-id="regression-modelling">Regression Modelling</h2>
<p>Finally, we’re explore regression models. We’ll build a series of models, each attempting to predict the number of searches in an MSOA, based on the number of robberies and the population density. We’ll start by simple OLS models, and then attempt variations that account for spatial weights.</p>
<div id="cell-55" class="cell" data-execution_count="84">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb38-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> spreg</span>
<span id="cb38-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.lib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> weights</span>
<span id="cb38-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pysal.explore <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> esda</span>
<span id="cb38-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats</span>
<span id="cb38-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> statsmodels.formula.api <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sm</span>
<span id="cb38-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy</span>
<span id="cb38-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas</span>
<span id="cb38-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geopandas</span>
<span id="cb38-9"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb38-10"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> seaborn</span>
<span id="cb38-11"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> patsy</span></code></pre></div></div>
</div>
<section id="ols" class="level4">
<h4 class="anchored" data-anchor-id="ols">OLS</h4>
<p>First, we run a simple log OLS model, using the Pysal spreg implementation (you could also get identical results using StatsModels or SKLearn). This doesn’t use any spatial modelling at all. I’m using Patsy to transform our Dataframe appropriately.</p>
<div id="cell-57" class="cell" data-execution_count="94">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb39-1">y, X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  patsy.dmatrices(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np.log(search_count) ~ np.log(robbery_count) + np.log(PopDen)"</span>, msoas, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"matrix"</span>)</span></code></pre></div></div>
</div>
<div id="cell-58" class="cell" data-execution_count="96">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb40-1">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(y)</span>
<span id="cb40-2">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(X)</span></code></pre></div></div>
</div>
<div id="cell-59" class="cell" data-execution_count="97">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb41-1">m1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> spreg.OLS(y, X,</span>
<span id="cb41-2">                name_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log Search Count'</span>, name_x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Constant"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Robbery Count"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Pop Density"</span>])</span></code></pre></div></div>
</div>
<div id="cell-60" class="cell" data-execution_count="98">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb42-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(m1.summary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>REGRESSION
----------
SUMMARY OF OUTPUT: ORDINARY LEAST SQUARES
-----------------------------------------
Data set            :     unknown
Weights matrix      :        None
Dependent Variable  :Log Search Count                Number of Observations:         983
Mean dependent var  :      5.7488                Number of Variables   :           3
S.D. dependent var  :      0.9163                Degrees of Freedom    :         980
R-squared           :      0.4181
Adjusted R-squared  :      0.4169
Sum squared residual:     479.795                F-statistic           :    352.0632
Sigma-square        :       0.490                Prob(F-statistic)     :  5.987e-116
S.E. of regression  :       0.700                Log likelihood        :   -1042.289
Sigma-square ML     :       0.488                Akaike info criterion :    2090.577
S.E of regression ML:      0.6986                Schwarz criterion     :    2105.249

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     t-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT       3.1161071       0.1416924      21.9920574       0.0000000
   Log Robbery Count       0.5845225       0.0260850      22.4083679       0.0000000
     Log Pop Density       0.1141935       0.0357637       3.1929958       0.0014529
------------------------------------------------------------------------------------
Warning: Variable(s) ['Constant'] removed for being constant.

REGRESSION DIAGNOSTICS
MULTICOLLINEARITY CONDITION NUMBER           15.197

TEST ON NORMALITY OF ERRORS
TEST                             DF        VALUE           PROB
Jarque-Bera                       2           4.305           0.1162

DIAGNOSTICS FOR HETEROSKEDASTICITY
RANDOM COEFFICIENTS
TEST                             DF        VALUE           PROB
Breusch-Pagan test                2           4.046           0.1322
Koenker-Bassett test              2           3.543           0.1700
================================ END OF REPORT =====================================</code></pre>
</div>
</div>
<p>The model is actually pretty good - the R2 suggests we account for over 40% of the variance, and each of our variables are significant. This is what we’d expect given the correlation between robbery and search counts.</p>
</section>
<section id="exogeneous-spatial-effects-model" class="level3">
<h3 class="anchored" data-anchor-id="exogeneous-spatial-effects-model">Exogeneous Spatial Effects Model</h3>
<p>Now, let’s use a model including the spatial lag of our exogenous variables. We use the same OLS implementation, and just add the weights as a variable.</p>
<div id="cell-62" class="cell" data-execution_count="113">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb44-1">y, X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  patsy.dmatrices(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np.log(search_count) ~ np.log(robbery_count) + np.log(PopDen) + np.log(w_robbery_count)"</span>, msoas, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"matrix"</span>)</span></code></pre></div></div>
</div>
<div id="cell-63" class="cell" data-execution_count="114">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb45-1">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(y)</span>
<span id="cb45-2">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(X)</span></code></pre></div></div>
</div>
<div id="cell-64" class="cell" data-execution_count="117">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb46-1">m2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> spreg.OLS(y, X,</span>
<span id="cb46-2">                name_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log Search Count'</span>, name_x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Constant"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Robbery Count"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Pop Density"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Robbery Spatial Weights"</span>])</span></code></pre></div></div>
</div>
<div id="cell-65" class="cell" data-execution_count="118">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb47-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(m2.summary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>REGRESSION
----------
SUMMARY OF OUTPUT: ORDINARY LEAST SQUARES
-----------------------------------------
Data set            :     unknown
Weights matrix      :        None
Dependent Variable  :Log Search Count                Number of Observations:         983
Mean dependent var  :      5.7488                Number of Variables   :           4
S.D. dependent var  :      0.9163                Degrees of Freedom    :         979
R-squared           :      0.4188
Adjusted R-squared  :      0.4170
Sum squared residual:     479.214                F-statistic           :    235.1495
Sigma-square        :       0.489                Prob(F-statistic)     :   7.02e-115
S.E. of regression  :       0.700                Log likelihood        :   -1041.693
Sigma-square ML     :       0.488                Akaike info criterion :    2091.386
S.E of regression ML:      0.6982                Schwarz criterion     :    2110.948

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     t-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT       2.9955315       0.1797701      16.6631230       0.0000000
   Log Robbery Count       0.5587104       0.0352339      15.8571653       0.0000000
     Log Pop Density       0.0987403       0.0384697       2.5666998       0.0104148
Robbery Spatial Weights       0.0711112       0.0652601       1.0896585       0.2761318
------------------------------------------------------------------------------------
Warning: Variable(s) ['Constant'] removed for being constant.

REGRESSION DIAGNOSTICS
MULTICOLLINEARITY CONDITION NUMBER           27.105

TEST ON NORMALITY OF ERRORS
TEST                             DF        VALUE           PROB
Jarque-Bera                       2           4.293           0.1169

DIAGNOSTICS FOR HETEROSKEDASTICITY
RANDOM COEFFICIENTS
TEST                             DF        VALUE           PROB
Breusch-Pagan test                3           5.101           0.1645
Koenker-Bassett test              3           4.506           0.2118
================================ END OF REPORT =====================================</code></pre>
</div>
</div>
<p>Interestingly, adding a spatial lag does not improve our model at all - the lag is not statistically significant.</p>
</section>
<section id="spatial-error-models" class="level3">
<h3 class="anchored" data-anchor-id="spatial-error-models">Spatial Error Models</h3>
<p>Instead of adding a spatial lag, we add a spatial error - effectively assuming we’re slightly off, in a consistent way, because of our spatial characteristics, and accounting for it.</p>
<div id="cell-67" class="cell" data-execution_count="159">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb49-1">y, X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  patsy.dmatrices(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np.log(search_count) ~ 0 + np.log(robbery_count) + np.log(PopDen)"</span>, msoas, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"matrix"</span>)</span>
<span id="cb49-2">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(y)</span>
<span id="cb49-3">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(X)</span>
<span id="cb49-4"></span>
<span id="cb49-5">m6 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> spreg.GM_Error_Het(y, X, </span>
<span id="cb49-6">                           w<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>w, name_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log Search Count'</span>, name_x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Robbery Count"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Pop Density"</span>])</span>
<span id="cb49-7"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(m6.summary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>REGRESSION
----------
SUMMARY OF OUTPUT: SPATIALLY WEIGHTED LEAST SQUARES (HET)
---------------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :Log Search Count                Number of Observations:         983
Mean dependent var  :      5.7488                Number of Variables   :           3
S.D. dependent var  :      0.9163                Degrees of Freedom    :         980
Pseudo R-squared    :      0.4134
N. of iterations    :           1                Step1c computed       :          No

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT       3.5341582       0.2141206      16.5054581       0.0000000
   Log Robbery Count       0.5823628       0.0365549      15.9311915       0.0000000
     Log Pop Density       0.0124371       0.0397069       0.3132221       0.7541119
              lambda       0.6810127       0.0298280      22.8313537       0.0000000
------------------------------------------------------------------------------------
================================ END OF REPORT =====================================</code></pre>
</div>
</div>
<p>Interestingly, while our model seems to be just as accurate, population density is no longer significant - this suggests density may be acting as a proxy for our spatial characteristics.</p>
</section>
<section id="spatial-lag-model" class="level3">
<h3 class="anchored" data-anchor-id="spatial-lag-model">Spatial Lag Model</h3>
<p>Finally, we’ll test a model that includes the spatial lag of our dependent variable - the search count varies based on nearby search counts. That breaks the assumptions of traditional OLS regression - we’re essentially forcing the search count to be on either side of the equation, meaning both will be correlated. Pysal has a specific implementation using two stage least squares to tackle these issues.</p>
<div id="cell-69" class="cell" data-execution_count="155">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb51" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb51-1">y, X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  patsy.dmatrices(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np.log(search_count) ~ np.log(robbery_count) + np.log(PopDen)"</span>, msoas, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"matrix"</span>)</span>
<span id="cb51-2">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(y)</span>
<span id="cb51-3">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(X)</span>
<span id="cb51-4"></span>
<span id="cb51-5">m7 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> spreg.GM_Lag(y, X, w<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>w, name_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log of Search Count'</span>, name_x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Constant"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Robbery Count"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Pop Density"</span>])</span>
<span id="cb51-6"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(m7.summary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>REGRESSION
----------
SUMMARY OF OUTPUT: SPATIAL TWO STAGE LEAST SQUARES
--------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :Log of Search Count                Number of Observations:         983
Mean dependent var  :      5.7488                Number of Variables   :           4
S.D. dependent var  :      0.9163                Degrees of Freedom    :         979
Pseudo R-squared    :      0.4584
Spatial Pseudo R-squared:  0.4175

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT       2.7219978       0.3420296       7.9583682       0.0000000
   Log Robbery Count       0.5614888       0.0311151      18.0455524       0.0000000
     Log Pop Density       0.0818749       0.0430088       1.9036779       0.0569522
W_Log of Search Count       0.1066105       0.0848248       1.2568327       0.2088142
------------------------------------------------------------------------------------
Instrumented: W_Log of Search Count
Instruments: W_Log Pop Density, W_Log Robbery Count
Warning: Variable(s) ['Constant'] removed for being constant.
================================ END OF REPORT =====================================</code></pre>
</div>
</div>
<p>This is a our best model yet. Note that density is once again no longer significant, but our model has improved somewhat - this seems the best fit yet.</p>
<div id="cell-71" class="cell" data-execution_count="156">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb53" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb53-1">y, X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  patsy.dmatrices(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"np.log(search_count) ~ 0 + np.log(robbery_count)"</span>, msoas, return_type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"matrix"</span>)</span>
<span id="cb53-2">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(y)</span>
<span id="cb53-3">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array(X)</span>
<span id="cb53-4"></span>
<span id="cb53-5">m7 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> spreg.GM_Lag(y, X, w<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>w, name_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log of Search Count'</span>, name_x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log Robbery Count"</span>])</span>
<span id="cb53-6"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(m7.summary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>REGRESSION
----------
SUMMARY OF OUTPUT: SPATIAL TWO STAGE LEAST SQUARES
--------------------------------------------------
Data set            :     unknown
Weights matrix      :     unknown
Dependent Variable  :Log of Search Count                Number of Observations:         983
Mean dependent var  :      5.7488                Number of Variables   :           3
S.D. dependent var  :      0.9163                Degrees of Freedom    :         980
Pseudo R-squared    :      0.4544
Spatial Pseudo R-squared:  0.4130

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT       2.9856130       0.3464531       8.6176549       0.0000000
   Log Robbery Count       0.5879825       0.0320598      18.3401657       0.0000000
W_Log of Search Count       0.1040083       0.0724840       1.4349150       0.1513113
------------------------------------------------------------------------------------
Instrumented: W_Log of Search Count
Instruments: W_Log Robbery Count
================================ END OF REPORT =====================================</code></pre>
</div>
</div>
<p>Based on the pseudo-R2, this is our best model, though I’m not sure whether it’s directly comparable, and the spatial term is not significant.</p>
<p>That said, we’ve now created a few simple models, using various techniques. We could do an awful lot more to improve these: I suspect accounting for more local characteristics might help (such as presence of tube stations), as well as distance from central London.</p>
<p>I’ve quite enjoyed learning this, and it’s been far more approachable than I expected - I’ll keep expanding on this and clean it up in the future!</p>


</section>
</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>crime</category>
  <category>geospatial</category>
  <guid>https://andreasthinks.me/posts/robbery_and_searches_in_space/robbery_and_searches_in_space.html</guid>
  <pubDate>Sat, 12 Mar 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Learning R - Exploring the COVID Crime Effect in London</title>
  <link>https://andreasthinks.me/posts/lockdown_effect/</link>
  <description><![CDATA[ 





<p>The lockdown and social distancing measures that were brought in throughout the world to tackle COVID in 2020 have had a significant, widespread effect on crime. In this notebook, I use public London crime data on robbery and burglary to examine where this “COVID crime shift” was strongest, and whether any specific drivers or correlates can be identified. I use three years of Metropolitan Police Service data from <a href="https://data.police.uk/">data.police.uk.</a></p>
<p>The findings suggest that the relative change in burglary and robbery in April and May 2020 was heavily affected by local characteristics: areas with a high residential population saw the sharpest decreases in burglary (likely due to a reduction in available targets) while the reduction in robberies instead seem to be driven by geographic features and indicators of deprivation (potentially suggesting more available targets for robbery in communities least able to work for from home).</p>
<p>The primary purpose of this exercise was to learn R - I’ve previously worked entirely in Python, which is more than sufficient 99% of the time, but has at times proved a blocker when I want to tackle some more experimental geospatial and statistical methods. With that in mind, this is likely to be a little messy, and I’ll aim to condense my main lessons into a blog post in the future. The models are not heavily tuned (aiming to explore correlates rather than provide accurate predictions) and there are likely to be correlation between our various predictors - as such these should not be taken to suggest direct causation.</p>
<p>The full code and data for this exercise are available on my <a href="https://github.com/crimsoneer/Covid-Crime-Shift">Github repo</a>. I’m hoping to summarise my key lessons in the Python to R journey in <a href="https://medium.com/@andreas.varotsis">Medium post</a> in the next few weeks.</p>
<section id="resources-ive-used" class="level4">
<h4 class="anchored" data-anchor-id="resources-ive-used">Resources I’ve used</h4>
<ul>
<li>Matt Ashby Crime Mapping course: https://github.com/mpjashby/crimemapping/</li>
<li>Spatial Modelling for Data Scientists: https://gdsl-ul.github.io/san/</li>
<li>R for Data Science: https://r4ds.had.co.nz/index.html</li>
<li>Geocomputation with R: https://geocompr.robinlovelace.net/</li>
</ul>
</section>
<section id="tasks" class="level3">
<h3 class="anchored" data-anchor-id="tasks">Tasks</h3>
<ol type="1">
<li>Ingest Data</li>
<li>Predict trend by MSOA</li>
<li>Quantify MSOA COVID Effect</li>
<li>Model</li>
</ol>
</section>
<section id="ingest-data" class="level2">
<h2 class="anchored" data-anchor-id="ingest-data">Ingest Data</h2>
<p>For this exercise, I’ll be importing crime and robbery data by MSOA.<a href="https://www.ons.gov.uk/methodology/geography/ukgeographies/censusgeography#output-area-oa">MSOAs are geographical units specifically designed for analysis, and to be comparable: they all have an average population of just over 8,000.</a> There is a compromise here between smaller geographical units (that create more variance that may help us identify predictors), but the necessity for enough crime per unit to identify meaningful trends - MSOAs should be suitable.</p>
<p>To build our process, we’ll start by taking one month of crime data, exploring it, and writing all our steps for automation.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_45f91f21fb8674b477a169c001ac30cb">
<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">test_df <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;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"crimes/2018-01/2018-01-metropolitan-street.csv"</span>)</span></code></pre></div></div>
</div>
<p>Our crime data is categorised according to the Home Office major crime types, and like Python, we can list them all through the “unique” function. Here I’ll be focusing on robbery and burglary: two crime types that are heavily reliant on encountering victim’s in public spaces, and as such should be affected by the “COVID effect”.</p>
<p>To avoid this getting particularly computationally intensive, let’s write a function to pull out robberies and burglaries, and assign them a specific MSOA. Then we can iterate over all our months and get monthly counts for each offence type.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_cf41266c4614a9f8492b2cb0f2181136">
<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">subset_df <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>(test_df, Crime.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;">"Burglary"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> Crime.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;">"Robbery"</span>)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(subset_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
Crime.ID
</th>
<th style="text-align:left;">
Month
</th>
<th style="text-align:left;">
Reported.by
</th>
<th style="text-align:left;">
Falls.within
</th>
<th style="text-align:right;">
Longitude
</th>
<th style="text-align:right;">
Latitude
</th>
<th style="text-align:left;">
Location
</th>
<th style="text-align:left;">
LSOA.code
</th>
<th style="text-align:left;">
LSOA.name
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:left;">
Last.outcome.category
</th>
<th style="text-align:left;">
Context
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
628e0d673aa1b6a70479342a64b02884499df85b18dcd63cc9bff3cff9f704bc
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.140035
</td>
<td style="text-align:right;">
51.58911
</td>
<td style="text-align:left;">
On or near Beansland Grove
</td>
<td style="text-align:left;">
E01000027
</td>
<td style="text-align:left;">
Barking and Dagenham 001A
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Offender sent to prison
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
f8e9db16dca534a83493198a838567aa5adc9dd56496edc2fff5bb4c62b8303e
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.140035
</td>
<td style="text-align:right;">
51.58911
</td>
<td style="text-align:left;">
On or near Beansland Grove
</td>
<td style="text-align:left;">
E01000027
</td>
<td style="text-align:left;">
Barking and Dagenham 001A
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Investigation complete; no suspect identified
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
cc34822074b130f141f16d02fdb2d500c86e22ae18324b43a3231b381af3f45c
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.135554
</td>
<td style="text-align:right;">
51.58499
</td>
<td style="text-align:left;">
On or near Rose Lane
</td>
<td style="text-align:left;">
E01000027
</td>
<td style="text-align:left;">
Barking and Dagenham 001A
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Status update unavailable
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
10de581c3cd0a8c9b970824cd7589d13148d63a70b3115d95ef6c24dc0bd2c3b
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.140035
</td>
<td style="text-align:right;">
51.58911
</td>
<td style="text-align:left;">
On or near Beansland Grove
</td>
<td style="text-align:left;">
E01000027
</td>
<td style="text-align:left;">
Barking and Dagenham 001A
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Status update unavailable
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
50ad5d2dfea24afec9e17218db62b3d29786775db1060634ae7d4a6e7cafc3ff
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.127794
</td>
<td style="text-align:right;">
51.58419
</td>
<td style="text-align:left;">
On or near Hope Close
</td>
<td style="text-align:left;">
E01000028
</td>
<td style="text-align:left;">
Barking and Dagenham 001B
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Status update unavailable
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
95abc6eb0b755c9250d19bbe0062fcd4a509b701964d89667401c9dc96ca257d
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:left;">
Metropolitan Police Service
</td>
<td style="text-align:right;">
0.138439
</td>
<td style="text-align:right;">
51.57850
</td>
<td style="text-align:left;">
On or near Geneva Gardens
</td>
<td style="text-align:left;">
E01000029
</td>
<td style="text-align:left;">
Barking and Dagenham 001C
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
Investigation complete; no suspect identified
</td>
<td style="text-align:left;">
NA
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Our single month of data contains 10,501 crimes.</p>
<p>We now need to link this to our spatial data. We use the MSOA borders provided by MOPAC, and use the UK National Grid coordinate system. Police.uk does not use that system, so we’ll need to reproject our crime data.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_72f241a1e7eb796228d723d138e3f682">
<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">lsoa_borders <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;">st_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_borders/MSOA_2011_London_gen_MHW.tab"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">27700</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Reading layer `MSOA_2011_London_gen_MHW' from data source 
  `D:\Dropbox\Data Projects\Covid_crime_shift\msoa_borders\MSOA_2011_London_gen_MHW.tab' 
  using driver `MapInfo File'
Simple feature collection with 983 features and 12 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 503574.2 ymin: 155850.8 xmax: 561956.7 ymax: 200933.6
Projected CRS: OSGB 1936 / British National Grid</code></pre>
</div>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(lsoa_borders)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Before we can link our crimes to MSOA, we’ll need to ensure identical coordinate systems, and remove any non-geolocated values we’ll need to erase any missing values (while checking we retain enough data for analysis.)</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_a5c201a6b3a4005acf2c64720eccfe5e">
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#count missing values in the longitude column</span></span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Missing values identified:"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Missing values identified:"</code></pre>
</div>
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(subset_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Longitude"</span>]))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 82</code></pre>
</div>
</div>
<p>Thankfully, we only identify 82 crimes which we need to remove, leaving plenty for analysis.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_bcd6b8a7b310a30c24f2323228b2f810">
<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">clean_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> subset_df[<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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(subset_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Longitude"</span>])), ]</span></code></pre></div></div>
</div>
<p>We can now convert our crime data to spacial data, using our longitude and latitude coordinates - this allows us to quickly plot our data, and confirm it looks right.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_4df624d80f57b7ffae64ed2539801e83">
<div class="cell-output cell-output-stderr">
<pre><code>Warning: plotting the first 9 out of 12 attributes; use max.plot = 12 to plot
all</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>With our data now mapped, we ensure everything is aligned to the appropriate coordinate system, and assign each crime to an MSOA from our data - the data is then aggregated into a monthly MSOA crime count, to which we assign our monthly date.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_10a1bfcad1702f181f897b663e74f0e9">
<div class="cell-output cell-output-stderr">
<pre><code>Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
deprecated. It might return a CRS with a non-EPSG compliant axis order.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:right;">
count_by_msoa
</th>
<th style="text-align:left;">
Month
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
9
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
11
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000004
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Bringing together all the code so far into a function, we can create an pipeline to generate our crime count per MSOA time series for the entirety of our dataset.</p>
<p>For this project, I haven’t used the Police.uk API (which would have enabled me to automate the downloads and query the data directly) - as such, we have to iterate over our subfolders, ingesting our CSV data and running through our process.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_1271281b6af2337784544e1d10169e27">
<div class="cell-output cell-output-stderr">
<pre><code>`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'MSOA11CD'. You can override using the
`.groups` argument.</code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_ffbab71a477ead23072aea122974bc60">
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:left;">
count_by_msoa
</th>
<th style="text-align:left;">
Month
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
9
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:left;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:left;">
11
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:left;">
2
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>We now have a combined dataframe of 71,848 rows, from January 2018 through December 2020.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-13_d2a6dd98fd77e8fab3f7df6398dc81c7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#saving file to CSV</span></span>
<span id="cb15-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#write.csv(empty_df,"msoa_crime_matrix.csv")</span></span></code></pre></div></div>
</div>
</section>
<section id="predict-trend-by-msoa" class="level2">
<h2 class="anchored" data-anchor-id="predict-trend-by-msoa">2. Predict trend by MSOA</h2>
<section id="visualisation-and-exploration" class="level4">
<h4 class="anchored" data-anchor-id="visualisation-and-exploration">Visualisation and Exploration</h4>
<p>With our data now cleaned and aggregated, we can focus on the more interesting part - forecasting our “expected” pandemic crime, and examining how much it diverges from our “actual” crime.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-14_fa404bebac20879f54fa0e2a27e5ed41">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">empty_df <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;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_crime_matrix.csv"</span>)</span>
<span id="cb16-2">empty_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> empty_df[<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;">70848</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>
<span id="cb16-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(empty_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
</th>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:right;">
count_by_msoa
</th>
<th style="text-align:left;">
Month
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
2
</td>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
3
</td>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
9
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
4
</td>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
5
</td>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
11
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
6
</td>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Robbery
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
<tr>
<td style="text-align:left;">
7
</td>
<td style="text-align:left;">
E02000004
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:left;">
2018-01
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Before going any further, let’s use this to explore and visualise the distribution of robbery and burglary across time and space during our “pre-pandemic” period, in March 2020 - based on London mobility indicators, this is when movement accross London began to be heavily affected, and the disruption was most notable in April</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/london_mobility.png" class="img-fluid figure-img"></p>
<figcaption>London mobility data</figcaption>
</figure>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-15_4b7bb7cbb4e729bbcfbda33762ba22b9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">burglary_df<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>empty_df</span>
<span id="cb17-2"></span>
<span id="cb17-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#add a "1" so our month can be converted to a full date</span></span>
<span id="cb17-4">burglary_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString <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;">paste</span>(burglary_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Month, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01"</span>, <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="cb17-5"></span>
<span id="cb17-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#convert to date format</span></span>
<span id="cb17-7">burglary_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean <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;">ymd</span>(burglary_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString)</span>
<span id="cb17-8"></span>
<span id="cb17-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter out only burglary prior to the pandemic</span></span>
<span id="cb17-10">burglaryExplore <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>(burglary_df,  DateClean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020-03-01"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Crime.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;">"Burglary"</span>)</span>
<span id="cb17-11"></span>
<span id="cb17-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(burglaryExplore)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:right;">
count_by_msoa
</th>
<th style="text-align:left;">
Month
</th>
<th style="text-align:left;">
DateString
</th>
<th style="text-align:left;">
DateClean
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
9
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
11
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000004
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000005
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000007
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
7
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Looking at the aggregate counts of burglary across London, a visual observation suggests yearly trends (which we’ll have to consider in our forecast), which sharp peaks during the Winter months and the lowest numbers in summer (when the days are longest).</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-16_d923cafab4bb9992d00df77afa01c81b">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#group burglary count by months and plot</span></span>
<span id="cb18-2">burglary_by_month <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> burglaryExplore <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(DateClean) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_burglaries =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count_by_msoa))</span>
<span id="cb18-5"></span>
<span id="cb18-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(burglary_by_month, <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>DateClean, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>total_burglaries)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>To observe how crime counts are distributed in space, let’s map both counts by MSOA. As previously mentioned, MSOAs are designed to be comparable units, at least from a population perspective - we don’t need to produce per population rates.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-17_0c899d39bb4f5e49087001de9e73d52a">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">burglary_by_msoa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> burglaryExplore <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb19-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(MSOA11CD) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb19-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_burglaries =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count_by_msoa))</span>
<span id="cb19-4"></span>
<span id="cb19-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#we join our burglary counts to their geographic msoa</span></span>
<span id="cb19-6">burglary_map <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;">left_join</span>(lsoa_borders, burglary_by_msoa, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span>
<span id="cb19-7"></span>
<span id="cb19-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#user brewer colour palette https://colorbrewer2.org</span></span>
<span id="cb19-9">pal <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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BuGn"</span>)</span>
<span id="cb19-10"></span>
<span id="cb19-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#create our map, and add the layout options</span></span>
<span id="cb19-12">burglary_map <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;">tm_shape</span>(burglary_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_burglaries"</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;">"Total Burglary Count by MSOA"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"quantile"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BuGn"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb19-15"></span>
<span id="cb19-16">robbery_df<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>empty_df</span>
<span id="cb19-17"></span>
<span id="cb19-18">robbery_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString <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;">paste</span>(robbery_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Month, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01"</span>, <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="cb19-19">robbery_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean <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;">ymd</span>(robbery_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString)</span>
<span id="cb19-20">robberyExplore <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>(robbery_df,  DateClean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020-03-01"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Crime.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;">"Robbery"</span>)</span>
<span id="cb19-21"></span>
<span id="cb19-22">robbery_by_msoa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> robberyExplore <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb19-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(MSOA11CD) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb19-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_robberies =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count_by_msoa))</span>
<span id="cb19-25"></span>
<span id="cb19-26">robbery_map <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;">left_join</span>(lsoa_borders, robbery_by_msoa, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span>
<span id="cb19-27"></span>
<span id="cb19-28">pal <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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BuGn"</span>)</span>
<span id="cb19-29"></span>
<span id="cb19-30"></span>
<span id="cb19-31">robbery_map <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;">tm_shape</span>(robbery_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_robberies"</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;">"Total Robbery Count by MSOA"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"quantile"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BuGn"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb19-34"></span>
<span id="cb19-35"></span>
<span id="cb19-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#arrange the maps together</span></span>
<span id="cb19-37"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tmap_arrange</span>(burglary_map, robbery_map, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>We notice that robbery is noticeably more concentrated in central London, with burglary remaining quite common across the city. That said, there are also obvious spatial patterns here - these crimes are clustered in certain geographies.</p>
</section>
<section id="modelling" class="level4">
<h4 class="anchored" data-anchor-id="modelling">Modelling</h4>
<p>We can now begin the forecasting process. To design our process, we’ll start by focusing on a single MSOA - the first in our dataset, <a href="https://findthatpostcode.uk/areas/E02000001.html">E02000001, or the City of London.</a></p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-18_6447f33aff4430eb914408bb30269dcd">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">single_msoa_df <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>(empty_df, MSOA11CD <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;">"E02000001"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Crime.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;">"Burglary"</span>)</span>
<span id="cb20-2"></span>
<span id="cb20-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#we add a 01 to our date to ensure R recognises the date format</span></span>
<span id="cb20-4">single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString <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;">paste</span>(single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Month, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01"</span>)</span>
<span id="cb20-5"></span>
<span id="cb20-6"></span>
<span id="cb20-7">single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean <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;">ymd</span>(single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateString)</span>
<span id="cb20-8">single_msoa_df</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
Crime.type
</th>
<th style="text-align:right;">
count_by_msoa
</th>
<th style="text-align:left;">
Month
</th>
<th style="text-align:left;">
DateString
</th>
<th style="text-align:left;">
DateClean
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-01
</td>
<td style="text-align:left;">
2018-01 -01
</td>
<td style="text-align:left;">
2018-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-02
</td>
<td style="text-align:left;">
2018-02 -01
</td>
<td style="text-align:left;">
2018-02-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2018-03
</td>
<td style="text-align:left;">
2018-03 -01
</td>
<td style="text-align:left;">
2018-03-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-04
</td>
<td style="text-align:left;">
2018-04 -01
</td>
<td style="text-align:left;">
2018-04-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
2018-05
</td>
<td style="text-align:left;">
2018-05 -01
</td>
<td style="text-align:left;">
2018-05-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
2018-06
</td>
<td style="text-align:left;">
2018-06 -01
</td>
<td style="text-align:left;">
2018-06-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2018-07
</td>
<td style="text-align:left;">
2018-07 -01
</td>
<td style="text-align:left;">
2018-07-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2018-08
</td>
<td style="text-align:left;">
2018-08 -01
</td>
<td style="text-align:left;">
2018-08-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-09
</td>
<td style="text-align:left;">
2018-09 -01
</td>
<td style="text-align:left;">
2018-09-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
2018-10
</td>
<td style="text-align:left;">
2018-10 -01
</td>
<td style="text-align:left;">
2018-10-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2018-11
</td>
<td style="text-align:left;">
2018-11 -01
</td>
<td style="text-align:left;">
2018-11-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
2018-12
</td>
<td style="text-align:left;">
2018-12 -01
</td>
<td style="text-align:left;">
2018-12-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2019-01
</td>
<td style="text-align:left;">
2019-01 -01
</td>
<td style="text-align:left;">
2019-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
7
</td>
<td style="text-align:left;">
2019-02
</td>
<td style="text-align:left;">
2019-02 -01
</td>
<td style="text-align:left;">
2019-02-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2019-03
</td>
<td style="text-align:left;">
2019-03 -01
</td>
<td style="text-align:left;">
2019-03-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2019-04
</td>
<td style="text-align:left;">
2019-04 -01
</td>
<td style="text-align:left;">
2019-04-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
2019-05
</td>
<td style="text-align:left;">
2019-05 -01
</td>
<td style="text-align:left;">
2019-05-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
2019-06
</td>
<td style="text-align:left;">
2019-06 -01
</td>
<td style="text-align:left;">
2019-06-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2019-07
</td>
<td style="text-align:left;">
2019-07 -01
</td>
<td style="text-align:left;">
2019-07-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2019-08
</td>
<td style="text-align:left;">
2019-08 -01
</td>
<td style="text-align:left;">
2019-08-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2019-09
</td>
<td style="text-align:left;">
2019-09 -01
</td>
<td style="text-align:left;">
2019-09-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
2019-10
</td>
<td style="text-align:left;">
2019-10 -01
</td>
<td style="text-align:left;">
2019-10-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2019-11
</td>
<td style="text-align:left;">
2019-11 -01
</td>
<td style="text-align:left;">
2019-11-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2019-12
</td>
<td style="text-align:left;">
2019-12 -01
</td>
<td style="text-align:left;">
2019-12-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
2020-01
</td>
<td style="text-align:left;">
2020-01 -01
</td>
<td style="text-align:left;">
2020-01-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-02
</td>
<td style="text-align:left;">
2020-02 -01
</td>
<td style="text-align:left;">
2020-02-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
2020-03
</td>
<td style="text-align:left;">
2020-03 -01
</td>
<td style="text-align:left;">
2020-03-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
2020-04
</td>
<td style="text-align:left;">
2020-04 -01
</td>
<td style="text-align:left;">
2020-04-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-05
</td>
<td style="text-align:left;">
2020-05 -01
</td>
<td style="text-align:left;">
2020-05-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-06
</td>
<td style="text-align:left;">
2020-06 -01
</td>
<td style="text-align:left;">
2020-06-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2020-07
</td>
<td style="text-align:left;">
2020-07 -01
</td>
<td style="text-align:left;">
2020-07-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-08
</td>
<td style="text-align:left;">
2020-08 -01
</td>
<td style="text-align:left;">
2020-08-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-09
</td>
<td style="text-align:left;">
2020-09 -01
</td>
<td style="text-align:left;">
2020-09-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-10
</td>
<td style="text-align:left;">
2020-10 -01
</td>
<td style="text-align:left;">
2020-10-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2020-11
</td>
<td style="text-align:left;">
2020-11 -01
</td>
<td style="text-align:left;">
2020-11-01
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
Burglary
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2020-12
</td>
<td style="text-align:left;">
2020-12 -01
</td>
<td style="text-align:left;">
2020-12-01
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>From a forecasting/time-series perspective, this is a very small dataset - 36 monthly observations. We will be shrinking this further to only 26 by focusing on data prior to March 2020, when the COVID crime impact is felt. This significantly limits our forecasting options, and will impact accuracy, if we treat each MSOA in isolation - we could explore some sort of Vector Autoregressive Model to limit this, but given that we’re then going to be exploring the error of all our models in aggregation, this isn’t crucial. Our focus is on models that we can accurately deploy without needing to tune each of them individually, and that can capture the seasonal trend, and generate reliable predictions on our limited dataset.</p>
<p>Given these limitations, I’ve opted for <a href="https://facebook.github.io/prophet/">the Prophet algorith.</a> While it’s more opaque than a auto-arima or VAR model, it works well with monthly data, and extracting seasonal trends. It also requires very little tuning.</p>
<p>As such, we’ll extract our “training set” prior to March, and start forecasting.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-19_563fa94fee42627a758047edb39a8d40">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">training_set <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>(single_msoa_df, DateClean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020-03-01"</span>)</span>
<span id="cb21-2"></span>
<span id="cb21-3">training_df <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;">tibble</span>(</span>
<span id="cb21-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ds=</span>training_set<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean,</span>
<span id="cb21-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>training_set<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>count_by_msoa</span>
<span id="cb21-6">)</span>
<span id="cb21-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(training_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
ds
</th>
<th style="text-align:right;">
y
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
2018-01-01
</td>
<td style="text-align:right;">
1
</td>
</tr>
<tr>
<td style="text-align:left;">
2018-02-01
</td>
<td style="text-align:right;">
1
</td>
</tr>
<tr>
<td style="text-align:left;">
2018-03-01
</td>
<td style="text-align:right;">
2
</td>
</tr>
<tr>
<td style="text-align:left;">
2018-04-01
</td>
<td style="text-align:right;">
1
</td>
</tr>
<tr>
<td style="text-align:left;">
2018-05-01
</td>
<td style="text-align:right;">
4
</td>
</tr>
<tr>
<td style="text-align:left;">
2018-06-01
</td>
<td style="text-align:right;">
0
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-20_a8dff50a7c6cb9d9b5a00e92c7f4e6ca">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(prophet)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Loading required package: Rcpp</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Loading required package: rlang</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'rlang'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:Metrics':

    ll</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:purrr':

    %@%, as_function, flatten, flatten_chr, flatten_dbl, flatten_int,
    flatten_lgl, flatten_raw, invoke, splice</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1">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;">prophet</span>(training_df)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>n.changepoints greater than number of observations. Using 19</code></pre>
</div>
</div>
<p>For now, we’ll forecast on a 6 month horizon - we obviously wouldn’t expect it to be accurate that far into the future.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-21_0f5604ea6f0d47d572109b4ac1d4c060">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#prophet generates a future dataframe using our data, for 6 mperiods</span></span>
<span id="cb32-2">future <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;">make_future_dataframe</span>(m, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">periods =</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;">freq =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>)</span>
<span id="cb32-3"></span>
<span id="cb32-4"></span>
<span id="cb32-5">forecast <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>(m, future)</span>
<span id="cb32-6"></span>
<span id="cb32-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(m, forecast)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-21-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>As we can see, the model seems consistent on a short horizon, and gets very wide as it goes further into the future. More importantly however, it has extracted a yearly seasonal compontent - the summer decrease we identified previously - as well as a long term trend.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-22_3661e4899b89a111be8f9d104f4db5da">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prophet_plot_components</span>(m, forecast)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>These predictions seem far-fetched, but remember we will be observing a London wide error rate. As such, we must now isolate our “pandemic period” - which we define as April and May 2020 - and compare the predicted crime counts to the actual crime counts to obtain a metric of our “COVID crime shift”, or our error rate.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-23_bf6fe869d559e15dae7594b84fb92c90">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">forecast<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Month <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;">month</span>(forecast<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ds)</span>
<span id="cb34-2">forecast<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year <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;">year</span>(forecast<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ds)</span>
<span id="cb34-3"></span>
<span id="cb34-4"></span>
<span id="cb34-5">this_year <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>(forecast, Year <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;">2019</span>)</span>
<span id="cb34-6">peak_pandemic <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>(this_year, Month<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;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> Month<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="cb34-7"></span>
<span id="cb34-8">predictionPivot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> peak_pandemic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb34-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Month) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb34-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predicted_burglary =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(yhat))</span>
<span id="cb34-11"></span>
<span id="cb34-12"></span>
<span id="cb34-13">single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>MonthNum <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;">month</span>(single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean)</span>
<span id="cb34-14">single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>YearNum <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;">year</span>(single_msoa_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>DateClean)</span>
<span id="cb34-15"></span>
<span id="cb34-16">this_year_actual <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>(single_msoa_df, YearNum <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;">2019</span>)</span>
<span id="cb34-17">peak_pandemic_actual <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>(this_year_actual, MonthNum<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;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> MonthNum<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="cb34-18"></span>
<span id="cb34-19">actual_burglary <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>(peak_pandemic_actual<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>count_by_msoa)</span>
<span id="cb34-20">pred_burglary <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>(predictionPivot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predicted_burglary)</span>
<span id="cb34-21"></span>
<span id="cb34-22">error <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> actual_burglary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pred_burglary</span>
<span id="cb34-23">percentage_error <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> error <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> pred_burglary </span>
<span id="cb34-24"></span>
<span id="cb34-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglary Count"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Burglary Count"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(actual_burglary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Predicted"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Predicted"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(pred_burglary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 7.625019</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Actual Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(error)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] -6.625019</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Percentage Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(percentage_error)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] -0.8688528</code></pre>
</div>
</div>
<p>In this MSOA, our model predicted nearly 8 burglaries would occur in these two months, based on pre-pandemic trends. In reality, 1 took place - a large error rate, suggesting a strong “COVID effect”.</p>
<p>This process can now be replicated for every MSOA in London, to obtain this metric for each MSOA.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><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;">unique</span>(empty_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>MSOA11CD))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 984</code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-25_7c6ab4c946c21bdfefeefeb8ebb06328">
<pre><code>## NULL</code></pre>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-26_4e682d3316b019e4c7dd111765907048">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb53" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(msoa_error_tibble)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
MSOA11CD
</th>
<th style="text-align:left;">
burglaryActual
</th>
<th style="text-align:left;">
burglaryPredicted
</th>
<th style="text-align:left;">
burglaryError
</th>
<th style="text-align:left;">
burglaryPercentError
</th>
<th style="text-align:left;">
robberyActual
</th>
<th style="text-align:left;">
robberyPredicted
</th>
<th style="text-align:left;">
robberyError
</th>
<th style="text-align:left;">
robberyPercentError
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000001
</td>
<td style="text-align:left;">
1
</td>
<td style="text-align:left;">
7.62501853994038
</td>
<td style="text-align:left;">
-6.62501853994038
</td>
<td style="text-align:left;">
-0.868852777896614
</td>
<td style="text-align:left;">
1
</td>
<td style="text-align:left;">
-1.97666206600358
</td>
<td style="text-align:left;">
2.97666206600358
</td>
<td style="text-align:left;">
-1.50590336972561
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000002
</td>
<td style="text-align:left;">
8
</td>
<td style="text-align:left;">
-9.23326713435216
</td>
<td style="text-align:left;">
17.2332671343522
</td>
<td style="text-align:left;">
-1.86643220472157
</td>
<td style="text-align:left;">
0
</td>
<td style="text-align:left;">
1.12957561845153
</td>
<td style="text-align:left;">
-1.12957561845153
</td>
<td style="text-align:left;">
-1
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000003
</td>
<td style="text-align:left;">
11
</td>
<td style="text-align:left;">
12.3480006370534
</td>
<td style="text-align:left;">
-1.34800063705343
</td>
<td style="text-align:left;">
-0.109167522473914
</td>
<td style="text-align:left;">
10
</td>
<td style="text-align:left;">
6.9224283913514
</td>
<td style="text-align:left;">
3.0775716086486
</td>
<td style="text-align:left;">
0.444579768061392
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000004
</td>
<td style="text-align:left;">
2
</td>
<td style="text-align:left;">
-4.71960263280976
</td>
<td style="text-align:left;">
6.71960263280976
</td>
<td style="text-align:left;">
-1.42376448942892
</td>
<td style="text-align:left;">
0
</td>
<td style="text-align:left;">
-1.27129225183737
</td>
<td style="text-align:left;">
1.27129225183737
</td>
<td style="text-align:left;">
-1
</td>
</tr>
<tr>
<td style="text-align:left;">
E02000005
</td>
<td style="text-align:left;">
4
</td>
<td style="text-align:left;">
4.58490182624086
</td>
<td style="text-align:left;">
-0.584901826240862
</td>
<td style="text-align:left;">
-0.127571286890655
</td>
<td style="text-align:left;">
1
</td>
<td style="text-align:left;">
9.21402738381341
</td>
<td style="text-align:left;">
-8.21402738381341
</td>
<td style="text-align:left;">
-0.89146982547971
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Our process has completed: we have a “COVID shift” measure for all of London.</p>
</section>
</section>
<section id="measuring-local-covid-crime-shifts" class="level2">
<h2 class="anchored" data-anchor-id="measuring-local-covid-crime-shifts">3. Measuring Local COVID Crime Shifts</h2>
<p>We now need to use our forecasts to measure the “error” - this should provide an indication of the “COVID Crime Shift”, or how much the actual crime diverted from the previous forecasts.</p>
<p>I explored various avenues for this: the ideal solution would be a relative rate of the error, as MSOAs with large crime numbers will likely generate large errors, and so a rate would be ideal, though this is complicated by our erratic prediction and mix of positive and negative numbers.</p>
<p>Our final solution has explored two options: - the absolute error number - the relative error once the crime and predictions have been transformed (by adding 50)</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aactual_%7Bk%7D%20=%20actual%20+%2050%0A"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0Apredicted_%7Bk%7D%20=%20predicted%20+%2050%0A"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0ARPD%20=%20%5Cfrac%7B(actual_%7Bk%7D%20-%20predicted_%7Bk%7D)%7D%20%20%7B(actual_%7Bk%7D%20+%20predicted_%7Bk%7D)/2%7D%0A"></p>
<p>We visualise and describe these statistics first to ensure they appear sensible.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-28_94efbc43595802a4f8478b7a02216cf8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb54" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1">msoa_error_tibble <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;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_error_table2.csv"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Rows: 980 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): MSOA11CD
dbl (8): burglaryActual, burglaryPredicted, burglaryError, burglaryPercentEr...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb56" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb56-1">msoa_error_tibble[,<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;">9</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;">lapply</span>(msoa_error_tibble[,<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;">9</span>], as.numeric)</span>
<span id="cb56-2"></span>
<span id="cb56-3">msoa_error_tibble <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_error_tibble[<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;">980</span>, ]</span>
<span id="cb56-4"></span>
<span id="cb56-5">msoa_error_tibble <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;">left_join</span>(msoa_error_tibble, robbery_by_msoa, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span>
<span id="cb56-6">msoa_error_tibble <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;">left_join</span>(msoa_error_tibble, burglary_by_msoa, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-29_ee609c4419a44e0e980348c714da5ca2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb57" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb57-1">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDBurglary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredicted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>((msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredicted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActual)<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="cb57-2"></span>
<span id="cb57-3">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobbery <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredicted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>((msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredicted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActual)<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="cb57-4"></span>
<span id="cb57-5">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActualShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActual <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;">50</span></span>
<span id="cb57-6">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredictedShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredicted <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;">50</span></span>
<span id="cb57-7"></span>
<span id="cb57-8"></span>
<span id="cb57-9">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActualShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredictedShifted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>((msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyPredictedShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyActualShifted)<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="cb57-10"></span>
<span id="cb57-11">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActualShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActual <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;">50</span></span>
<span id="cb57-12">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredictedShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredicted <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;">50</span></span>
<span id="cb57-13"></span>
<span id="cb57-14"></span>
<span id="cb57-15">msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActualShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredictedShifted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>((msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryPredictedShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryActualShifted)<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></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-30_1b58f3318dc070879b6f1528950ff623">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb58" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglary Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Burglary Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb60" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>burglaryError)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-97.191 -12.870  -5.271  -6.090   2.111  48.727 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb62" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb62-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Burglary Relative Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Burglary Relative Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb64" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb64-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.81266 -0.20689 -0.08826 -0.07976  0.03612  1.29467 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb66" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb66-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Robbery Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Robbery Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb68" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb68-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robberyError)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-309.618   -6.577   -2.150   -3.840    2.205   25.564 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb70" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb70-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Robbery Relative Error"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Robbery Relative Error"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb72" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb72-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(msoa_error_tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1.45491 -0.11808 -0.04081 -0.04876  0.04309  0.62020 </code></pre>
</div>
</div>
<p>As we can see, the average London MSOA experienced a negative COVID crime shift for both burglary and robbery, but this is far from equally distributed - at the extremes, some areas actually see large increases on our predicted values.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-31_58e7579d348f383d1527c85934f7b4c9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb74" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb74-1">burg_hist <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>(msoa_error_tibble, <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>burglaryError)) <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;">geom_histogram</span>()</span>
<span id="cb74-2">rob_hist <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>(msoa_error_tibble, <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>robberyError)) <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;">geom_histogram</span>()</span>
<span id="cb74-3">burg_r_hist <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>(msoa_error_tibble, <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>RPDburglaryShifted)) <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;">geom_histogram</span>()</span>
<span id="cb74-4">rob_r_hist <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>(msoa_error_tibble, <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>RPDRobberyShifted)) <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;">geom_histogram</span>()</span>
<span id="cb74-5">scatter <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>(msoa_error_tibble, <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> RPDRobberyShifted, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> RPDburglaryShifted)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb74-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>()</span>
<span id="cb74-7"></span>
<span id="cb74-8">r_scatter <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>(msoa_error_tibble, <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> robberyError, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> burglaryError)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb74-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>()</span>
<span id="cb74-10"></span>
<span id="cb74-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggarrange</span>(rob_hist, burg_hist, rob_r_hist, burg_r_hist,scatter, r_scatter, <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;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> )</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-31-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>Our shifted relative error rate seems to function as intended: while there are still outliers, they are more concentrated than they are for the pure error term, and the overall distribution is more focused, while still indicating the direction and relative strength of our COVID effect.</p>
<p>Let’s map this effect visually, and see if any particular areas stand out.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-32_2730c0e483687e86e2681a51f99616e1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb76" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb76-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#re-ingest our geographic MSOA borders</span></span>
<span id="cb76-2">msoa_borders <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;">st_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_borders/MSOA_2011_London_gen_MHW.tab"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">27700</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Reading layer `MSOA_2011_London_gen_MHW' from data source 
  `D:\Dropbox\Data Projects\Covid_crime_shift\msoa_borders\MSOA_2011_London_gen_MHW.tab' 
  using driver `MapInfo File'
Simple feature collection with 983 features and 12 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 503574.2 ymin: 155850.8 xmax: 561956.7 ymax: 200933.6
Projected CRS: OSGB 1936 / British National Grid</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb78" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb78-1">geographic_error_map <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;">left_join</span>(msoa_borders, msoa_error_tibble, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span>
<span id="cb78-2"></span>
<span id="cb78-3">burg_map <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;">tm_shape</span>(geographic_error_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyError"</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;">"Robbery Error"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-PuOr"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb78-6">rob_map <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;">tm_shape</span>(geographic_error_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryError"</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;">"Burglary  Error"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-PuOr"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb78-9"></span>
<span id="cb78-10"></span>
<span id="cb78-11">burg_map_rate <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;">tm_shape</span>(geographic_error_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDRobberyShifted"</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;">"Robbery Error Relative"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-PuOr"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb78-14">rob_map_rate <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;">tm_shape</span>(geographic_error_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDburglaryShifted"</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;">"Burglary  Error Relative"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-PuOr"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb78-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.outside =</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;">legend.outside.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)</span>
<span id="cb78-17"></span>
<span id="cb78-18"></span>
<span id="cb78-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tmap_arrange</span>(burg_map, rob_map, burg_map_rate, rob_map_rate , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</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;">ncol=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Variable(s) "robberyError" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Variable(s) "burglaryError" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Variable(s) "RPDRobberyShifted" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Variable(s) "RPDburglaryShifted" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-32-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>It’s hard to identify any obvious effect visually, but we do notice that while central London sees some very strong reductions, it also sees some increases. Conversely, the outskirts of London (notably to the south and West) are a near continuous area of large decreases. The effect does vary by offence type, but the pattern seen in South and West London appears broadly consistent.</p>
</section>
<section id="identifying-correlates-and-modelling" class="level2">
<h2 class="anchored" data-anchor-id="identifying-correlates-and-modelling">Identifying Correlates and Modelling</h2>
<p>We’ve identified that the COVID crime effect was felt unequally accross London, and varies by offence type. To finalise our project, we will be linking our data to <a href="https://data.london.gov.uk/dataset/msoa-atlas">demographic data provided by MOPAC</a>, and aiming to use it to identify correlates to our “covid shift”, and hopefully build models disentangling the effect.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-33_cbabcd198998424627841b6e5a979b32">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb83" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb83-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(readxl)</span>
<span id="cb83-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ingest ATLAS</span></span>
<span id="cb83-3">msoa_atlas <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;">read_excel</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_atlas/msoa-data.xls"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>New names:
• `House Prices Sales 2011` -&gt; `House Prices Sales 2011...129`
• `House Prices Sales 2011` -&gt; `House Prices Sales 2011...130`</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb85" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb85-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#join by MSOA</span></span>
<span id="cb85-2">geographic_msoa_matrix <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;">left_join</span>(geographic_error_map, msoa_atlas, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSOA11CD"</span>)</span>
<span id="cb85-3"></span>
<span id="cb85-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#convert to tibble</span></span>
<span id="cb85-5">msoa_matrix_tbl <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_tibble</span>(geographic_msoa_matrix)</span>
<span id="cb85-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(msoa_matrix_tbl, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"msoa_matrix.csv"</span>)</span>
<span id="cb85-7"></span>
<span id="cb85-8"></span>
<span id="cb85-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#select only numeric data</span></span>
<span id="cb85-10">msoa_matrix_numeric <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>dplyr<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;">select_if</span>(msoa_matrix_tbl, is.numeric)</span>
<span id="cb85-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(msoa_matrix_numeric)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:right;">
UsualRes
</th>
<th style="text-align:right;">
HholdRes
</th>
<th style="text-align:right;">
ComEstRes
</th>
<th style="text-align:right;">
PopDen
</th>
<th style="text-align:right;">
Hholds
</th>
<th style="text-align:right;">
AvHholdSz
</th>
<th style="text-align:right;">
burglaryActual
</th>
<th style="text-align:right;">
burglaryPredicted
</th>
<th style="text-align:right;">
burglaryError
</th>
<th style="text-align:right;">
burglaryPercentError
</th>
<th style="text-align:right;">
robberyActual
</th>
<th style="text-align:right;">
robberyPredicted
</th>
<th style="text-align:right;">
robberyError
</th>
<th style="text-align:right;">
robberyPercentError
</th>
<th style="text-align:right;">
total_robberies
</th>
<th style="text-align:right;">
total_burglaries
</th>
<th style="text-align:right;">
RPDBurglary
</th>
<th style="text-align:right;">
RPDRobbery
</th>
<th style="text-align:right;">
robberyActualShifted
</th>
<th style="text-align:right;">
robberyPredictedShifted
</th>
<th style="text-align:right;">
RPDRobberyShifted
</th>
<th style="text-align:right;">
burglaryActualShifted
</th>
<th style="text-align:right;">
burglaryPredictedShifted
</th>
<th style="text-align:right;">
RPDburglaryShifted
</th>
<th style="text-align:right;">
Age Structure (2011 Census) All Ages
</th>
<th style="text-align:right;">
Age Structure (2011 Census) 0-15
</th>
<th style="text-align:right;">
Age Structure (2011 Census) 16-29
</th>
<th style="text-align:right;">
Age Structure (2011 Census) 30-44
</th>
<th style="text-align:right;">
Age Structure (2011 Census) 45-64
</th>
<th style="text-align:right;">
Age Structure (2011 Census) 65+
</th>
<th style="text-align:right;">
Age Structure (2011 Census) Working-age
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2002
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2003
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2004
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2005
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2006
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2007
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2008
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2009
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2010
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2011
</th>
<th style="text-align:right;">
Mid-year Estimate totals All Ages 2012
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age % 0 to 14
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age % 15-64
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age % 65+
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 0-4
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 5-9
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 10-14
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 15-19
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 20-24
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 25-29
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 30-34
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 35-39
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 40-44
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 45-49
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 50-54
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 55-59
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 60-64
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 65-69
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 70-74
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 75-79
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 80-84
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 85-89
</th>
<th style="text-align:right;">
Mid-year Estimates 2012, by age 90+
</th>
<th style="text-align:right;">
Households (2011) All Households
</th>
<th style="text-align:right;">
Household Composition (2011) Numbers Couple household with dependent children
</th>
<th style="text-align:right;">
Household Composition (2011) Numbers Couple household without dependent children
</th>
<th style="text-align:right;">
Household Composition (2011) Numbers Lone parent household
</th>
<th style="text-align:right;">
Household Composition (2011) Numbers One person household
</th>
<th style="text-align:right;">
Household Composition (2011) Numbers Other household Types
</th>
<th style="text-align:right;">
Household Composition (2011) Percentages Couple household with dependent children
</th>
<th style="text-align:right;">
Household Composition (2011) Percentages Couple household without dependent children
</th>
<th style="text-align:right;">
Household Composition (2011) Percentages Lone parent household
</th>
<th style="text-align:right;">
Household Composition (2011) Percentages One person household
</th>
<th style="text-align:right;">
Household Composition (2011) Percentages Other household Types
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) White
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Mixed/multiple ethnic groups
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Asian/Asian British
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Black/African/Caribbean/Black British
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Other ethnic group
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) BAME
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) White (%)
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Mixed/multiple ethnic groups (%)
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Asian/Asian British (%)
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Black/African/Caribbean/Black British (%)
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) Other ethnic group (%)
</th>
<th style="text-align:right;">
Ethnic Group (2011 Census) BAME (%)
</th>
<th style="text-align:right;">
Country of Birth (2011) United Kingdom
</th>
<th style="text-align:right;">
Country of Birth (2011) Not United Kingdom
</th>
<th style="text-align:right;">
Country of Birth (2011) United Kingdom (%)
</th>
<th style="text-align:right;">
Country of Birth (2011) Not United Kingdom (%)
</th>
<th style="text-align:right;">
Household Language (2011) At least one person aged 16 and over in household has English as a main language
</th>
<th style="text-align:right;">
Household Language (2011) No people in household have English as a main language
</th>
<th style="text-align:right;">
Household Language (2011) % of people aged 16 and over in household have English as a main language
</th>
<th style="text-align:right;">
Household Language (2011) % of households where no people in household have English as a main language
</th>
<th style="text-align:right;">
Religion (2011) Christian
</th>
<th style="text-align:right;">
Religion (2011) Buddhist
</th>
<th style="text-align:right;">
Religion (2011) Hindu
</th>
<th style="text-align:right;">
Religion (2011) Jewish
</th>
<th style="text-align:right;">
Religion (2011) Muslim
</th>
<th style="text-align:right;">
Religion (2011) Sikh
</th>
<th style="text-align:right;">
Religion (2011) Other religion
</th>
<th style="text-align:right;">
Religion (2011) No religion
</th>
<th style="text-align:right;">
Religion (2011) Religion not stated
</th>
<th style="text-align:right;">
Religion (2011) Christian (%)
</th>
<th style="text-align:right;">
Religion (2011) Buddhist (%)
</th>
<th style="text-align:right;">
Religion (2011) Hindu (%)
</th>
<th style="text-align:right;">
Religion (2011) Jewish (%)
</th>
<th style="text-align:right;">
Religion (2011) Muslim (%)
</th>
<th style="text-align:right;">
Religion (2011) Sikh (%)
</th>
<th style="text-align:right;">
Religion (2011) Other religion (%)
</th>
<th style="text-align:right;">
Religion (2011) No religion (%)
</th>
<th style="text-align:right;">
Religion (2011) Religion not stated (%)
</th>
<th style="text-align:right;">
Tenure (2011) Owned: Owned outright
</th>
<th style="text-align:right;">
Tenure (2011) Owned: Owned with a mortgage or loan
</th>
<th style="text-align:right;">
Tenure (2011) Social rented
</th>
<th style="text-align:right;">
Tenure (2011) Private rented
</th>
<th style="text-align:right;">
Tenure (2011) Owned: Owned outright (%)
</th>
<th style="text-align:right;">
Tenure (2011) Owned: Owned with a mortgage or loan (%)
</th>
<th style="text-align:right;">
Tenure (2011) Social rented (%)
</th>
<th style="text-align:right;">
Tenure (2011) Private rented (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Household spaces with at least one usual resident
</th>
<th style="text-align:right;">
Dwelling type (2011) Household spaces with no usual residents
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Detached
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Semi-detached
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Terraced (including end-terrace)
</th>
<th style="text-align:right;">
Dwelling type (2011) Flat, maisonette or apartment
</th>
<th style="text-align:right;">
Dwelling type (2011) Household spaces with at least one usual resident (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Household spaces with no usual residents (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Detached (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Semi-detached (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Whole house or bungalow: Terraced (including end-terrace) (%)
</th>
<th style="text-align:right;">
Dwelling type (2011) Flat, maisonette or apartment (%)
</th>
<th style="text-align:right;">
Land Area Hectares
</th>
<th style="text-align:right;">
Population Density Persons per hectare (2012)
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2005
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2006
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2007
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2008
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2009
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2010
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2011
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2012
</th>
<th style="text-align:right;">
House Prices Median House Price (£) 2013 (p)
</th>
<th style="text-align:right;">
House Prices Sales 2005
</th>
<th style="text-align:right;">
House Prices Sales 2006
</th>
<th style="text-align:right;">
House Prices Sales 2007
</th>
<th style="text-align:right;">
House Prices Sales 2008
</th>
<th style="text-align:right;">
House Prices Sales 2009
</th>
<th style="text-align:right;">
House Prices Sales 2010
</th>
<th style="text-align:right;">
House Prices Sales 2011…129
</th>
<th style="text-align:right;">
House Prices Sales 2011…130
</th>
<th style="text-align:right;">
House Prices Sales 2013(p)
</th>
<th style="text-align:right;">
Qualifications (2011 Census) No qualifications
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Level 1 qualifications
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Level 2 qualifications
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Apprenticeship
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Level 3 qualifications
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Level 4 qualifications and above
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Highest level of qualification: Other qualifications
</th>
<th style="text-align:right;">
Qualifications (2011 Census) Schoolchildren and full-time students: Age 18 and over
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Economically active: Total
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Economically active: Unemployed
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Economically inactive: Total
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Economically active %
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Unemployment Rate
</th>
<th style="text-align:right;">
Economic Activity (2011 Census) Economically inactive %
</th>
<th style="text-align:right;">
Adults in Employment (2011 Census) No adults in employment in household: With dependent children
</th>
<th style="text-align:right;">
Adults in Employment (2011 Census) % of households with no adults in employment: With dependent children
</th>
<th style="text-align:right;">
Household Income Estimates (2011/12) Total Mean Annual Household Income (£)
</th>
<th style="text-align:right;">
Household Income Estimates (2011/12) Total Median Annual Household Income (£)
</th>
<th style="text-align:right;">
Income Deprivation (2010) % living in income deprived households reliant on means tested benefit
</th>
<th style="text-align:right;">
Income Deprivation (2010) % of people aged over 60 who live in pension credit households
</th>
<th style="text-align:right;">
Lone Parents (2011 Census) All lone parent housholds with dependent children
</th>
<th style="text-align:right;">
Lone Parents (2011 Census) Lone parents not in employment
</th>
<th style="text-align:right;">
Lone Parents (2011 Census) Lone parent not in employment %
</th>
<th style="text-align:right;">
Central Heating (2011 Census) Households with central heating (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities limited a lot
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities limited a little
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities not limited
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities limited a lot (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities limited a little (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Day-to-day activities not limited (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Very good health
</th>
<th style="text-align:right;">
Health (2011 Census) Good health
</th>
<th style="text-align:right;">
Health (2011 Census) Fair health
</th>
<th style="text-align:right;">
Health (2011 Census) Bad health
</th>
<th style="text-align:right;">
Health (2011 Census) Very bad health
</th>
<th style="text-align:right;">
Health (2011 Census) Very good health (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Good health (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Fair health (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Bad health (%)
</th>
<th style="text-align:right;">
Health (2011 Census) Very bad health (%)
</th>
<th style="text-align:right;">
Low Birth Weight Births (2007-2011) Low Birth Weight Births (%)
</th>
<th style="text-align:right;">
Low Birth Weight Births (2007-2011) LCL - Lower confidence limit
</th>
<th style="text-align:right;">
Low Birth Weight Births (2007-2011) UCL - Upper confidence limit
</th>
<th style="text-align:right;">
Obesity % of measured children in Year 6 who were classified as obese, 2009/10-2011/12
</th>
<th style="text-align:right;">
Obesity Percentage of the population aged 16+ with a BMI of 30+, modelled estimate, 2006-2008
</th>
<th style="text-align:right;">
Incidence of Cancer All
</th>
<th style="text-align:right;">
Incidence of Cancer Breast Cancer
</th>
<th style="text-align:right;">
Incidence of Cancer Colorectal Cancer
</th>
<th style="text-align:right;">
Incidence of Cancer Lung Cancer
</th>
<th style="text-align:right;">
Incidence of Cancer Prostate Cancer
</th>
<th style="text-align:right;">
Life Expectancy Males
</th>
<th style="text-align:right;">
Life Expectancy Females
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) No cars or vans in household
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 1 car or van in household
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 2 cars or vans in household
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 3 cars or vans in household
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 4 or more cars or vans in household
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) Sum of all cars or vans in the area
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) No cars or vans in household (%)
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 1 car or van in household (%)
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 2 cars or vans in household (%)
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 3 cars or vans in household (%)
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) 4 or more cars or vans in household (%)
</th>
<th style="text-align:right;">
Car or van availability (2011 Census) Cars per household
</th>
<th style="text-align:right;">
Road Casualties 2010 Fatal
</th>
<th style="text-align:right;">
Road Casualties 2010 Serious
</th>
<th style="text-align:right;">
Road Casualties 2010 Slight
</th>
<th style="text-align:right;">
Road Casualties 2010 2010 Total
</th>
<th style="text-align:right;">
Road Casualties 2011 Fatal
</th>
<th style="text-align:right;">
Road Casualties 2011 Serious
</th>
<th style="text-align:right;">
Road Casualties 2011 Slight
</th>
<th style="text-align:right;">
Road Casualties 2011 2011 Total
</th>
<th style="text-align:right;">
Road Casualties 2012 Fatal
</th>
<th style="text-align:right;">
Road Casualties 2012 Serious
</th>
<th style="text-align:right;">
Road Casualties 2012 Slight
</th>
<th style="text-align:right;">
Road Casualties 2012 2012 Total
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
7375
</td>
<td style="text-align:right;">
7187
</td>
<td style="text-align:right;">
188
</td>
<td style="text-align:right;">
25.5
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
1.6
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
7.625019
</td>
<td style="text-align:right;">
-6.6250185
</td>
<td style="text-align:right;">
-0.8688528
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
-1.976662
</td>
<td style="text-align:right;">
2.976662
</td>
<td style="text-align:right;">
-1.5059034
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
-1.5362329
</td>
<td style="text-align:right;">
-6.0955833
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
48.02334
</td>
<td style="text-align:right;">
0.0601204
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
57.62502
</td>
<td style="text-align:right;">
-0.1219796
</td>
<td style="text-align:right;">
7375
</td>
<td style="text-align:right;">
620
</td>
<td style="text-align:right;">
1665
</td>
<td style="text-align:right;">
2045
</td>
<td style="text-align:right;">
2010
</td>
<td style="text-align:right;">
1035
</td>
<td style="text-align:right;">
5720
</td>
<td style="text-align:right;">
7280
</td>
<td style="text-align:right;">
7115
</td>
<td style="text-align:right;">
7118
</td>
<td style="text-align:right;">
7131
</td>
<td style="text-align:right;">
7254
</td>
<td style="text-align:right;">
7607
</td>
<td style="text-align:right;">
7429
</td>
<td style="text-align:right;">
7472
</td>
<td style="text-align:right;">
7338
</td>
<td style="text-align:right;">
7412
</td>
<td style="text-align:right;">
7604
</td>
<td style="text-align:right;">
8.771699
</td>
<td style="text-align:right;">
76.68332
</td>
<td style="text-align:right;">
14.54498
</td>
<td style="text-align:right;">
297
</td>
<td style="text-align:right;">
205
</td>
<td style="text-align:right;">
165
</td>
<td style="text-align:right;">
231
</td>
<td style="text-align:right;">
495
</td>
<td style="text-align:right;">
949
</td>
<td style="text-align:right;">
826
</td>
<td style="text-align:right;">
622
</td>
<td style="text-align:right;">
663
</td>
<td style="text-align:right;">
598
</td>
<td style="text-align:right;">
504
</td>
<td style="text-align:right;">
470
</td>
<td style="text-align:right;">
473
</td>
<td style="text-align:right;">
363
</td>
<td style="text-align:right;">
263
</td>
<td style="text-align:right;">
192
</td>
<td style="text-align:right;">
155
</td>
<td style="text-align:right;">
86
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
306
</td>
<td style="text-align:right;">
927
</td>
<td style="text-align:right;">
153
</td>
<td style="text-align:right;">
2472
</td>
<td style="text-align:right;">
527
</td>
<td style="text-align:right;">
6.978335
</td>
<td style="text-align:right;">
21.14025
</td>
<td style="text-align:right;">
3.489168
</td>
<td style="text-align:right;">
56.37400
</td>
<td style="text-align:right;">
12.01824
</td>
<td style="text-align:right;">
5799
</td>
<td style="text-align:right;">
289
</td>
<td style="text-align:right;">
940
</td>
<td style="text-align:right;">
193
</td>
<td style="text-align:right;">
154
</td>
<td style="text-align:right;">
1576
</td>
<td style="text-align:right;">
78.63051
</td>
<td style="text-align:right;">
3.918644
</td>
<td style="text-align:right;">
12.745763
</td>
<td style="text-align:right;">
2.616949
</td>
<td style="text-align:right;">
2.0881356
</td>
<td style="text-align:right;">
21.36949
</td>
<td style="text-align:right;">
4670
</td>
<td style="text-align:right;">
2705
</td>
<td style="text-align:right;">
63.32203
</td>
<td style="text-align:right;">
36.67797
</td>
<td style="text-align:right;">
3825
</td>
<td style="text-align:right;">
560
</td>
<td style="text-align:right;">
87.22919
</td>
<td style="text-align:right;">
12.770810
</td>
<td style="text-align:right;">
3344
</td>
<td style="text-align:right;">
92
</td>
<td style="text-align:right;">
145
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
409
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
2522
</td>
<td style="text-align:right;">
651
</td>
<td style="text-align:right;">
45.3
</td>
<td style="text-align:right;">
1.2
</td>
<td style="text-align:right;">
2.0
</td>
<td style="text-align:right;">
2.3
</td>
<td style="text-align:right;">
5.5
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
34.2
</td>
<td style="text-align:right;">
8.8
</td>
<td style="text-align:right;">
1093
</td>
<td style="text-align:right;">
762
</td>
<td style="text-align:right;">
725
</td>
<td style="text-align:right;">
1573
</td>
<td style="text-align:right;">
24.9
</td>
<td style="text-align:right;">
17.4
</td>
<td style="text-align:right;">
16.5
</td>
<td style="text-align:right;">
35.9
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
1145
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
12
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
5416
</td>
<td style="text-align:right;">
79.3
</td>
<td style="text-align:right;">
20.7
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
1.4
</td>
<td style="text-align:right;">
98.0
</td>
<td style="text-align:right;">
289.78
</td>
<td style="text-align:right;">
26.24060
</td>
<td style="text-align:right;">
310000
</td>
<td style="text-align:right;">
341000
</td>
<td style="text-align:right;">
412500
</td>
<td style="text-align:right;">
365000.0
</td>
<td style="text-align:right;">
410000
</td>
<td style="text-align:right;">
450000
</td>
<td style="text-align:right;">
465000
</td>
<td style="text-align:right;">
485000
</td>
<td style="text-align:right;">
595000
</td>
<td style="text-align:right;">
303
</td>
<td style="text-align:right;">
295
</td>
<td style="text-align:right;">
268
</td>
<td style="text-align:right;">
141
</td>
<td style="text-align:right;">
157
</td>
<td style="text-align:right;">
235
</td>
<td style="text-align:right;">
256
</td>
<td style="text-align:right;">
195
</td>
<td style="text-align:right;">
353
</td>
<td style="text-align:right;">
454
</td>
<td style="text-align:right;">
291
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
484
</td>
<td style="text-align:right;">
4618
</td>
<td style="text-align:right;">
416
</td>
<td style="text-align:right;">
422
</td>
<td style="text-align:right;">
4972
</td>
<td style="text-align:right;">
187
</td>
<td style="text-align:right;">
1335
</td>
<td style="text-align:right;">
78.83304
</td>
<td style="text-align:right;">
3.761062
</td>
<td style="text-align:right;">
21.16696
</td>
<td style="text-align:right;">
38
</td>
<td style="text-align:right;">
0.9
</td>
<td style="text-align:right;">
59728.48
</td>
<td style="text-align:right;">
46788.30
</td>
<td style="text-align:right;">
5.2
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
91
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
24.2
</td>
<td style="text-align:right;">
95.7
</td>
<td style="text-align:right;">
328
</td>
<td style="text-align:right;">
520
</td>
<td style="text-align:right;">
6527
</td>
<td style="text-align:right;">
4.447458
</td>
<td style="text-align:right;">
7.050847
</td>
<td style="text-align:right;">
88.50169
</td>
<td style="text-align:right;">
4112
</td>
<td style="text-align:right;">
2374
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
190
</td>
<td style="text-align:right;">
56
</td>
<td style="text-align:right;">
55.75593
</td>
<td style="text-align:right;">
32.18983
</td>
<td style="text-align:right;">
8.718644
</td>
<td style="text-align:right;">
2.576271
</td>
<td style="text-align:right;">
0.759322
</td>
<td style="text-align:right;">
4.2
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
7.1
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
13.7
</td>
<td style="text-align:right;">
76.8
</td>
<td style="text-align:right;">
90.9
</td>
<td style="text-align:right;">
83.9
</td>
<td style="text-align:right;">
57.1
</td>
<td style="text-align:right;">
80.2
</td>
<td style="text-align:right;">
83.6
</td>
<td style="text-align:right;">
88.4
</td>
<td style="text-align:right;">
3043
</td>
<td style="text-align:right;">
1100
</td>
<td style="text-align:right;">
173
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
1692
</td>
<td style="text-align:right;">
69.4
</td>
<td style="text-align:right;">
25.1
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
1.2
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
0.3858609
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
334
</td>
<td style="text-align:right;">
374
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
46
</td>
<td style="text-align:right;">
359
</td>
<td style="text-align:right;">
405
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
361
</td>
<td style="text-align:right;">
414
</td>
</tr>
<tr>
<td style="text-align:right;">
6775
</td>
<td style="text-align:right;">
6724
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
31.3
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
8
</td>
<td style="text-align:right;">
-9.233267
</td>
<td style="text-align:right;">
17.2332671
</td>
<td style="text-align:right;">
-1.8664322
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1.129576
</td>
<td style="text-align:right;">
-1.129576
</td>
<td style="text-align:right;">
-1.0000000
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
-27.9473386
</td>
<td style="text-align:right;">
-2.0000000
</td>
<td style="text-align:right;">
50
</td>
<td style="text-align:right;">
51.12958
</td>
<td style="text-align:right;">
-0.0223392
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
40.76673
</td>
<td style="text-align:right;">
0.3489691
</td>
<td style="text-align:right;">
6775
</td>
<td style="text-align:right;">
1751
</td>
<td style="text-align:right;">
1277
</td>
<td style="text-align:right;">
1388
</td>
<td style="text-align:right;">
1258
</td>
<td style="text-align:right;">
1101
</td>
<td style="text-align:right;">
3923
</td>
<td style="text-align:right;">
6333
</td>
<td style="text-align:right;">
6312
</td>
<td style="text-align:right;">
6329
</td>
<td style="text-align:right;">
6341
</td>
<td style="text-align:right;">
6330
</td>
<td style="text-align:right;">
6323
</td>
<td style="text-align:right;">
6369
</td>
<td style="text-align:right;">
6570
</td>
<td style="text-align:right;">
6636
</td>
<td style="text-align:right;">
6783
</td>
<td style="text-align:right;">
6853
</td>
<td style="text-align:right;">
25.113089
</td>
<td style="text-align:right;">
58.73340
</td>
<td style="text-align:right;">
16.15351
</td>
<td style="text-align:right;">
652
</td>
<td style="text-align:right;">
607
</td>
<td style="text-align:right;">
462
</td>
<td style="text-align:right;">
458
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
468
</td>
<td style="text-align:right;">
466
</td>
<td style="text-align:right;">
466
</td>
<td style="text-align:right;">
461
</td>
<td style="text-align:right;">
450
</td>
<td style="text-align:right;">
347
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
256
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
206
</td>
<td style="text-align:right;">
215
</td>
<td style="text-align:right;">
201
</td>
<td style="text-align:right;">
137
</td>
<td style="text-align:right;">
94
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
491
</td>
<td style="text-align:right;">
366
</td>
<td style="text-align:right;">
597
</td>
<td style="text-align:right;">
814
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
18.098046
</td>
<td style="text-align:right;">
13.49060
</td>
<td style="text-align:right;">
22.005160
</td>
<td style="text-align:right;">
30.00369
</td>
<td style="text-align:right;">
16.40251
</td>
<td style="text-align:right;">
4403
</td>
<td style="text-align:right;">
330
</td>
<td style="text-align:right;">
820
</td>
<td style="text-align:right;">
1133
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
2372
</td>
<td style="text-align:right;">
64.98893
</td>
<td style="text-align:right;">
4.870849
</td>
<td style="text-align:right;">
12.103321
</td>
<td style="text-align:right;">
16.723247
</td>
<td style="text-align:right;">
1.3136531
</td>
<td style="text-align:right;">
35.01107
</td>
<td style="text-align:right;">
5159
</td>
<td style="text-align:right;">
1616
</td>
<td style="text-align:right;">
76.14760
</td>
<td style="text-align:right;">
23.85240
</td>
<td style="text-align:right;">
2459
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
90.63767
</td>
<td style="text-align:right;">
9.362329
</td>
<td style="text-align:right;">
3975
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
174
</td>
<td style="text-align:right;">
27
</td>
<td style="text-align:right;">
591
</td>
<td style="text-align:right;">
122
</td>
<td style="text-align:right;">
16
</td>
<td style="text-align:right;">
1417
</td>
<td style="text-align:right;">
434
</td>
<td style="text-align:right;">
58.7
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
8.7
</td>
<td style="text-align:right;">
1.8
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
20.9
</td>
<td style="text-align:right;">
6.4
</td>
<td style="text-align:right;">
596
</td>
<td style="text-align:right;">
663
</td>
<td style="text-align:right;">
1133
</td>
<td style="text-align:right;">
269
</td>
<td style="text-align:right;">
22.0
</td>
<td style="text-align:right;">
24.4
</td>
<td style="text-align:right;">
41.8
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
82
</td>
<td style="text-align:right;">
99
</td>
<td style="text-align:right;">
744
</td>
<td style="text-align:right;">
865
</td>
<td style="text-align:right;">
1087
</td>
<td style="text-align:right;">
97.1
</td>
<td style="text-align:right;">
2.9
</td>
<td style="text-align:right;">
3.5
</td>
<td style="text-align:right;">
26.6
</td>
<td style="text-align:right;">
30.9
</td>
<td style="text-align:right;">
38.9
</td>
<td style="text-align:right;">
216.15
</td>
<td style="text-align:right;">
31.70483
</td>
<td style="text-align:right;">
168500
</td>
<td style="text-align:right;">
180000
</td>
<td style="text-align:right;">
187500
</td>
<td style="text-align:right;">
197500.0
</td>
<td style="text-align:right;">
190000
</td>
<td style="text-align:right;">
173000
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
182250
</td>
<td style="text-align:right;">
190000
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
68
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
42
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
1623
</td>
<td style="text-align:right;">
789
</td>
<td style="text-align:right;">
706
</td>
<td style="text-align:right;">
118
</td>
<td style="text-align:right;">
479
</td>
<td style="text-align:right;">
914
</td>
<td style="text-align:right;">
395
</td>
<td style="text-align:right;">
272
</td>
<td style="text-align:right;">
2847
</td>
<td style="text-align:right;">
335
</td>
<td style="text-align:right;">
1513
</td>
<td style="text-align:right;">
65.29817
</td>
<td style="text-align:right;">
11.766772
</td>
<td style="text-align:right;">
34.70183
</td>
<td style="text-align:right;">
319
</td>
<td style="text-align:right;">
11.8
</td>
<td style="text-align:right;">
31788.19
</td>
<td style="text-align:right;">
27058.70
</td>
<td style="text-align:right;">
31.0
</td>
<td style="text-align:right;">
27.5
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
249
</td>
<td style="text-align:right;">
56.0
</td>
<td style="text-align:right;">
97.5
</td>
<td style="text-align:right;">
707
</td>
<td style="text-align:right;">
678
</td>
<td style="text-align:right;">
5390
</td>
<td style="text-align:right;">
10.435424
</td>
<td style="text-align:right;">
10.007380
</td>
<td style="text-align:right;">
79.55720
</td>
<td style="text-align:right;">
2933
</td>
<td style="text-align:right;">
2288
</td>
<td style="text-align:right;">
1059
</td>
<td style="text-align:right;">
389
</td>
<td style="text-align:right;">
106
</td>
<td style="text-align:right;">
43.29151
</td>
<td style="text-align:right;">
33.77122
</td>
<td style="text-align:right;">
15.630996
</td>
<td style="text-align:right;">
5.741697
</td>
<td style="text-align:right;">
1.564576
</td>
<td style="text-align:right;">
10.6
</td>
<td style="text-align:right;">
8.4
</td>
<td style="text-align:right;">
13.3
</td>
<td style="text-align:right;">
23.6
</td>
<td style="text-align:right;">
29.8
</td>
<td style="text-align:right;">
100.7
</td>
<td style="text-align:right;">
93.3
</td>
<td style="text-align:right;">
82.5
</td>
<td style="text-align:right;">
97.2
</td>
<td style="text-align:right;">
107.6
</td>
<td style="text-align:right;">
78.0
</td>
<td style="text-align:right;">
80.1
</td>
<td style="text-align:right;">
1020
</td>
<td style="text-align:right;">
1186
</td>
<td style="text-align:right;">
424
</td>
<td style="text-align:right;">
66
</td>
<td style="text-align:right;">
17
</td>
<td style="text-align:right;">
2305
</td>
<td style="text-align:right;">
37.6
</td>
<td style="text-align:right;">
43.7
</td>
<td style="text-align:right;">
15.6
</td>
<td style="text-align:right;">
2.4
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.8496130
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
16
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
15
</td>
<td style="text-align:right;">
16
</td>
</tr>
<tr>
<td style="text-align:right;">
10045
</td>
<td style="text-align:right;">
10033
</td>
<td style="text-align:right;">
12
</td>
<td style="text-align:right;">
46.9
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
11
</td>
<td style="text-align:right;">
12.348001
</td>
<td style="text-align:right;">
-1.3480006
</td>
<td style="text-align:right;">
-0.1091675
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:right;">
6.922428
</td>
<td style="text-align:right;">
3.077572
</td>
<td style="text-align:right;">
0.4445798
</td>
<td style="text-align:right;">
124
</td>
<td style="text-align:right;">
239
</td>
<td style="text-align:right;">
-0.1154703
</td>
<td style="text-align:right;">
0.3637269
</td>
<td style="text-align:right;">
60
</td>
<td style="text-align:right;">
56.92243
</td>
<td style="text-align:right;">
0.0526430
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
62.34800
</td>
<td style="text-align:right;">
-0.0218569
</td>
<td style="text-align:right;">
10045
</td>
<td style="text-align:right;">
2247
</td>
<td style="text-align:right;">
1959
</td>
<td style="text-align:right;">
2300
</td>
<td style="text-align:right;">
2259
</td>
<td style="text-align:right;">
1280
</td>
<td style="text-align:right;">
6518
</td>
<td style="text-align:right;">
9236
</td>
<td style="text-align:right;">
9252
</td>
<td style="text-align:right;">
9155
</td>
<td style="text-align:right;">
9072
</td>
<td style="text-align:right;">
9144
</td>
<td style="text-align:right;">
9227
</td>
<td style="text-align:right;">
9564
</td>
<td style="text-align:right;">
9914
</td>
<td style="text-align:right;">
10042
</td>
<td style="text-align:right;">
10088
</td>
<td style="text-align:right;">
10218
</td>
<td style="text-align:right;">
21.442552
</td>
<td style="text-align:right;">
65.81523
</td>
<td style="text-align:right;">
12.74222
</td>
<td style="text-align:right;">
849
</td>
<td style="text-align:right;">
739
</td>
<td style="text-align:right;">
603
</td>
<td style="text-align:right;">
615
</td>
<td style="text-align:right;">
686
</td>
<td style="text-align:right;">
804
</td>
<td style="text-align:right;">
818
</td>
<td style="text-align:right;">
743
</td>
<td style="text-align:right;">
770
</td>
<td style="text-align:right;">
713
</td>
<td style="text-align:right;">
624
</td>
<td style="text-align:right;">
526
</td>
<td style="text-align:right;">
426
</td>
<td style="text-align:right;">
372
</td>
<td style="text-align:right;">
277
</td>
<td style="text-align:right;">
258
</td>
<td style="text-align:right;">
198
</td>
<td style="text-align:right;">
124
</td>
<td style="text-align:right;">
73
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
776
</td>
<td style="text-align:right;">
730
</td>
<td style="text-align:right;">
589
</td>
<td style="text-align:right;">
1039
</td>
<td style="text-align:right;">
700
</td>
<td style="text-align:right;">
20.239958
</td>
<td style="text-align:right;">
19.04017
</td>
<td style="text-align:right;">
15.362546
</td>
<td style="text-align:right;">
27.09963
</td>
<td style="text-align:right;">
18.25769
</td>
<td style="text-align:right;">
5486
</td>
<td style="text-align:right;">
433
</td>
<td style="text-align:right;">
2284
</td>
<td style="text-align:right;">
1618
</td>
<td style="text-align:right;">
224
</td>
<td style="text-align:right;">
4559
</td>
<td style="text-align:right;">
54.61424
</td>
<td style="text-align:right;">
4.310602
</td>
<td style="text-align:right;">
22.737680
</td>
<td style="text-align:right;">
16.107516
</td>
<td style="text-align:right;">
2.2299652
</td>
<td style="text-align:right;">
45.38576
</td>
<td style="text-align:right;">
7193
</td>
<td style="text-align:right;">
2852
</td>
<td style="text-align:right;">
71.60777
</td>
<td style="text-align:right;">
28.39223
</td>
<td style="text-align:right;">
3431
</td>
<td style="text-align:right;">
403
</td>
<td style="text-align:right;">
89.48878
</td>
<td style="text-align:right;">
10.511215
</td>
<td style="text-align:right;">
5475
</td>
<td style="text-align:right;">
46
</td>
<td style="text-align:right;">
476
</td>
<td style="text-align:right;">
42
</td>
<td style="text-align:right;">
1351
</td>
<td style="text-align:right;">
430
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
1514
</td>
<td style="text-align:right;">
677
</td>
<td style="text-align:right;">
54.5
</td>
<td style="text-align:right;">
0.5
</td>
<td style="text-align:right;">
4.7
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
13.4
</td>
<td style="text-align:right;">
4.3
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
15.1
</td>
<td style="text-align:right;">
6.7
</td>
<td style="text-align:right;">
1028
</td>
<td style="text-align:right;">
1473
</td>
<td style="text-align:right;">
446
</td>
<td style="text-align:right;">
830
</td>
<td style="text-align:right;">
26.8
</td>
<td style="text-align:right;">
38.4
</td>
<td style="text-align:right;">
11.6
</td>
<td style="text-align:right;">
21.6
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
110
</td>
<td style="text-align:right;">
161
</td>
<td style="text-align:right;">
936
</td>
<td style="text-align:right;">
1591
</td>
<td style="text-align:right;">
1256
</td>
<td style="text-align:right;">
97.2
</td>
<td style="text-align:right;">
2.8
</td>
<td style="text-align:right;">
4.1
</td>
<td style="text-align:right;">
23.7
</td>
<td style="text-align:right;">
40.3
</td>
<td style="text-align:right;">
31.8
</td>
<td style="text-align:right;">
214.15
</td>
<td style="text-align:right;">
47.71422
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
197750
</td>
<td style="text-align:right;">
220000
</td>
<td style="text-align:right;">
225000.0
</td>
<td style="text-align:right;">
188500
</td>
<td style="text-align:right;">
215000
</td>
<td style="text-align:right;">
200000
</td>
<td style="text-align:right;">
205500
</td>
<td style="text-align:right;">
237000
</td>
<td style="text-align:right;">
203
</td>
<td style="text-align:right;">
232
</td>
<td style="text-align:right;">
295
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
97
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
114
</td>
<td style="text-align:right;">
98
</td>
<td style="text-align:right;">
1778
</td>
<td style="text-align:right;">
1210
</td>
<td style="text-align:right;">
1236
</td>
<td style="text-align:right;">
169
</td>
<td style="text-align:right;">
847
</td>
<td style="text-align:right;">
1829
</td>
<td style="text-align:right;">
729
</td>
<td style="text-align:right;">
442
</td>
<td style="text-align:right;">
5038
</td>
<td style="text-align:right;">
459
</td>
<td style="text-align:right;">
2111
</td>
<td style="text-align:right;">
70.47139
</td>
<td style="text-align:right;">
9.110758
</td>
<td style="text-align:right;">
29.52861
</td>
<td style="text-align:right;">
268
</td>
<td style="text-align:right;">
7.0
</td>
<td style="text-align:right;">
43356.93
</td>
<td style="text-align:right;">
36834.53
</td>
<td style="text-align:right;">
18.9
</td>
<td style="text-align:right;">
21.2
</td>
<td style="text-align:right;">
408
</td>
<td style="text-align:right;">
199
</td>
<td style="text-align:right;">
48.8
</td>
<td style="text-align:right;">
96.5
</td>
<td style="text-align:right;">
792
</td>
<td style="text-align:right;">
810
</td>
<td style="text-align:right;">
8443
</td>
<td style="text-align:right;">
7.884520
</td>
<td style="text-align:right;">
8.063713
</td>
<td style="text-align:right;">
84.05177
</td>
<td style="text-align:right;">
4566
</td>
<td style="text-align:right;">
3633
</td>
<td style="text-align:right;">
1325
</td>
<td style="text-align:right;">
406
</td>
<td style="text-align:right;">
115
</td>
<td style="text-align:right;">
45.45545
</td>
<td style="text-align:right;">
36.16725
</td>
<td style="text-align:right;">
13.190642
</td>
<td style="text-align:right;">
4.041812
</td>
<td style="text-align:right;">
1.144848
</td>
<td style="text-align:right;">
7.8
</td>
<td style="text-align:right;">
6.1
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
25.5
</td>
<td style="text-align:right;">
28.3
</td>
<td style="text-align:right;">
91.4
</td>
<td style="text-align:right;">
107.3
</td>
<td style="text-align:right;">
124.6
</td>
<td style="text-align:right;">
105.5
</td>
<td style="text-align:right;">
82.9
</td>
<td style="text-align:right;">
80.2
</td>
<td style="text-align:right;">
85.6
</td>
<td style="text-align:right;">
1196
</td>
<td style="text-align:right;">
1753
</td>
<td style="text-align:right;">
691
</td>
<td style="text-align:right;">
155
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
3766
</td>
<td style="text-align:right;">
31.2
</td>
<td style="text-align:right;">
45.7
</td>
<td style="text-align:right;">
18.0
</td>
<td style="text-align:right;">
4.0
</td>
<td style="text-align:right;">
1.0
</td>
<td style="text-align:right;">
0.9822640
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
37
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:right;">
40
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:right;">
6182
</td>
<td style="text-align:right;">
5937
</td>
<td style="text-align:right;">
245
</td>
<td style="text-align:right;">
24.8
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
-4.719603
</td>
<td style="text-align:right;">
6.7196026
</td>
<td style="text-align:right;">
-1.4237645
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
-1.271292
</td>
<td style="text-align:right;">
1.271292
</td>
<td style="text-align:right;">
-1.0000000
</td>
<td style="text-align:right;">
30
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
-4.9416062
</td>
<td style="text-align:right;">
-2.0000000
</td>
<td style="text-align:right;">
50
</td>
<td style="text-align:right;">
48.72871
</td>
<td style="text-align:right;">
0.0257532
</td>
<td style="text-align:right;">
52
</td>
<td style="text-align:right;">
45.28040
</td>
<td style="text-align:right;">
0.1381492
</td>
<td style="text-align:right;">
6182
</td>
<td style="text-align:right;">
1196
</td>
<td style="text-align:right;">
1277
</td>
<td style="text-align:right;">
1154
</td>
<td style="text-align:right;">
1543
</td>
<td style="text-align:right;">
1012
</td>
<td style="text-align:right;">
3974
</td>
<td style="text-align:right;">
6208
</td>
<td style="text-align:right;">
6159
</td>
<td style="text-align:right;">
6163
</td>
<td style="text-align:right;">
6152
</td>
<td style="text-align:right;">
5997
</td>
<td style="text-align:right;">
6005
</td>
<td style="text-align:right;">
6084
</td>
<td style="text-align:right;">
6268
</td>
<td style="text-align:right;">
6237
</td>
<td style="text-align:right;">
6185
</td>
<td style="text-align:right;">
6308
</td>
<td style="text-align:right;">
18.246671
</td>
<td style="text-align:right;">
65.82118
</td>
<td style="text-align:right;">
15.93215
</td>
<td style="text-align:right;">
409
</td>
<td style="text-align:right;">
364
</td>
<td style="text-align:right;">
378
</td>
<td style="text-align:right;">
516
</td>
<td style="text-align:right;">
472
</td>
<td style="text-align:right;">
435
</td>
<td style="text-align:right;">
363
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
388
</td>
<td style="text-align:right;">
463
</td>
<td style="text-align:right;">
459
</td>
<td style="text-align:right;">
354
</td>
<td style="text-align:right;">
303
</td>
<td style="text-align:right;">
226
</td>
<td style="text-align:right;">
238
</td>
<td style="text-align:right;">
194
</td>
<td style="text-align:right;">
172
</td>
<td style="text-align:right;">
106
</td>
<td style="text-align:right;">
69
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
524
</td>
<td style="text-align:right;">
322
</td>
<td style="text-align:right;">
609
</td>
<td style="text-align:right;">
355
</td>
<td style="text-align:right;">
21.915444
</td>
<td style="text-align:right;">
22.60569
</td>
<td style="text-align:right;">
13.891286
</td>
<td style="text-align:right;">
26.27265
</td>
<td style="text-align:right;">
15.31493
</td>
<td style="text-align:right;">
5006
</td>
<td style="text-align:right;">
186
</td>
<td style="text-align:right;">
313
</td>
<td style="text-align:right;">
649
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
1176
</td>
<td style="text-align:right;">
80.97703
</td>
<td style="text-align:right;">
3.008735
</td>
<td style="text-align:right;">
5.063086
</td>
<td style="text-align:right;">
10.498221
</td>
<td style="text-align:right;">
0.4529279
</td>
<td style="text-align:right;">
19.02297
</td>
<td style="text-align:right;">
5292
</td>
<td style="text-align:right;">
890
</td>
<td style="text-align:right;">
85.60336
</td>
<td style="text-align:right;">
14.39664
</td>
<td style="text-align:right;">
2214
</td>
<td style="text-align:right;">
104
</td>
<td style="text-align:right;">
95.51337
</td>
<td style="text-align:right;">
4.486626
</td>
<td style="text-align:right;">
4070
</td>
<td style="text-align:right;">
21
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
23
</td>
<td style="text-align:right;">
234
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
1373
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
65.8
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
0.5
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
3.8
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
22.2
</td>
<td style="text-align:right;">
6.5
</td>
<td style="text-align:right;">
718
</td>
<td style="text-align:right;">
969
</td>
<td style="text-align:right;">
371
</td>
<td style="text-align:right;">
228
</td>
<td style="text-align:right;">
31.0
</td>
<td style="text-align:right;">
41.8
</td>
<td style="text-align:right;">
16.0
</td>
<td style="text-align:right;">
9.8
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
92
</td>
<td style="text-align:right;">
858
</td>
<td style="text-align:right;">
1094
</td>
<td style="text-align:right;">
314
</td>
<td style="text-align:right;">
98.1
</td>
<td style="text-align:right;">
1.9
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
36.3
</td>
<td style="text-align:right;">
46.3
</td>
<td style="text-align:right;">
13.2
</td>
<td style="text-align:right;">
249.28
</td>
<td style="text-align:right;">
25.30488
</td>
<td style="text-align:right;">
181000
</td>
<td style="text-align:right;">
182000
</td>
<td style="text-align:right;">
212000
</td>
<td style="text-align:right;">
208997.5
</td>
<td style="text-align:right;">
182000
</td>
<td style="text-align:right;">
192000
</td>
<td style="text-align:right;">
193750
</td>
<td style="text-align:right;">
205000
</td>
<td style="text-align:right;">
210000
</td>
<td style="text-align:right;">
93
</td>
<td style="text-align:right;">
131
</td>
<td style="text-align:right;">
125
</td>
<td style="text-align:right;">
66
</td>
<td style="text-align:right;">
54
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
72
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
67
</td>
<td style="text-align:right;">
1502
</td>
<td style="text-align:right;">
800
</td>
<td style="text-align:right;">
825
</td>
<td style="text-align:right;">
163
</td>
<td style="text-align:right;">
539
</td>
<td style="text-align:right;">
891
</td>
<td style="text-align:right;">
266
</td>
<td style="text-align:right;">
215
</td>
<td style="text-align:right;">
3187
</td>
<td style="text-align:right;">
296
</td>
<td style="text-align:right;">
1251
</td>
<td style="text-align:right;">
71.81163
</td>
<td style="text-align:right;">
9.287731
</td>
<td style="text-align:right;">
28.18837
</td>
<td style="text-align:right;">
122
</td>
<td style="text-align:right;">
5.3
</td>
<td style="text-align:right;">
46701.44
</td>
<td style="text-align:right;">
39668.21
</td>
<td style="text-align:right;">
15.8
</td>
<td style="text-align:right;">
21.3
</td>
<td style="text-align:right;">
206
</td>
<td style="text-align:right;">
87
</td>
<td style="text-align:right;">
42.2
</td>
<td style="text-align:right;">
98.5
</td>
<td style="text-align:right;">
586
</td>
<td style="text-align:right;">
547
</td>
<td style="text-align:right;">
5049
</td>
<td style="text-align:right;">
9.479133
</td>
<td style="text-align:right;">
8.848269
</td>
<td style="text-align:right;">
81.67260
</td>
<td style="text-align:right;">
2857
</td>
<td style="text-align:right;">
2086
</td>
<td style="text-align:right;">
861
</td>
<td style="text-align:right;">
302
</td>
<td style="text-align:right;">
76
</td>
<td style="text-align:right;">
46.21482
</td>
<td style="text-align:right;">
33.74313
</td>
<td style="text-align:right;">
13.927532
</td>
<td style="text-align:right;">
4.885150
</td>
<td style="text-align:right;">
1.229376
</td>
<td style="text-align:right;">
5.8
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
8.6
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
26.9
</td>
<td style="text-align:right;">
96.1
</td>
<td style="text-align:right;">
95.5
</td>
<td style="text-align:right;">
105.8
</td>
<td style="text-align:right;">
102.4
</td>
<td style="text-align:right;">
110.3
</td>
<td style="text-align:right;">
77.9
</td>
<td style="text-align:right;">
80.7
</td>
<td style="text-align:right;">
556
</td>
<td style="text-align:right;">
1085
</td>
<td style="text-align:right;">
515
</td>
<td style="text-align:right;">
128
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
2650
</td>
<td style="text-align:right;">
24.0
</td>
<td style="text-align:right;">
46.8
</td>
<td style="text-align:right;">
22.2
</td>
<td style="text-align:right;">
5.5
</td>
<td style="text-align:right;">
1.5
</td>
<td style="text-align:right;">
1.1432269
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
14
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
7
</td>
<td style="text-align:right;">
9
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
7
</td>
</tr>
<tr>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
72.1
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
2.7
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:right;">
4.584902
</td>
<td style="text-align:right;">
-0.5849018
</td>
<td style="text-align:right;">
-0.1275713
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
9.214027
</td>
<td style="text-align:right;">
-8.214027
</td>
<td style="text-align:right;">
-0.8914698
</td>
<td style="text-align:right;">
87
</td>
<td style="text-align:right;">
161
</td>
<td style="text-align:right;">
-0.1362629
</td>
<td style="text-align:right;">
-1.6083817
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
59.21403
</td>
<td style="text-align:right;">
-0.1490559
</td>
<td style="text-align:right;">
54
</td>
<td style="text-align:right;">
54.58490
</td>
<td style="text-align:right;">
-0.0107732
</td>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
2200
</td>
<td style="text-align:right;">
1592
</td>
<td style="text-align:right;">
1995
</td>
<td style="text-align:right;">
1829
</td>
<td style="text-align:right;">
946
</td>
<td style="text-align:right;">
5416
</td>
<td style="text-align:right;">
7919
</td>
<td style="text-align:right;">
7922
</td>
<td style="text-align:right;">
7882
</td>
<td style="text-align:right;">
7887
</td>
<td style="text-align:right;">
7917
</td>
<td style="text-align:right;">
7916
</td>
<td style="text-align:right;">
8025
</td>
<td style="text-align:right;">
8317
</td>
<td style="text-align:right;">
8519
</td>
<td style="text-align:right;">
8588
</td>
<td style="text-align:right;">
8660
</td>
<td style="text-align:right;">
24.237875
</td>
<td style="text-align:right;">
64.57275
</td>
<td style="text-align:right;">
11.18938
</td>
<td style="text-align:right;">
783
</td>
<td style="text-align:right;">
692
</td>
<td style="text-align:right;">
624
</td>
<td style="text-align:right;">
657
</td>
<td style="text-align:right;">
525
</td>
<td style="text-align:right;">
608
</td>
<td style="text-align:right;">
616
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
673
</td>
<td style="text-align:right;">
656
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
386
</td>
<td style="text-align:right;">
320
</td>
<td style="text-align:right;">
321
</td>
<td style="text-align:right;">
202
</td>
<td style="text-align:right;">
194
</td>
<td style="text-align:right;">
127
</td>
<td style="text-align:right;">
90
</td>
<td style="text-align:right;">
35
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
691
</td>
<td style="text-align:right;">
583
</td>
<td style="text-align:right;">
593
</td>
<td style="text-align:right;">
808
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
21.709080
</td>
<td style="text-align:right;">
18.31605
</td>
<td style="text-align:right;">
18.630223
</td>
<td style="text-align:right;">
25.38486
</td>
<td style="text-align:right;">
15.95979
</td>
<td style="text-align:right;">
5674
</td>
<td style="text-align:right;">
313
</td>
<td style="text-align:right;">
1050
</td>
<td style="text-align:right;">
1445
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
2888
</td>
<td style="text-align:right;">
66.26956
</td>
<td style="text-align:right;">
3.655688
</td>
<td style="text-align:right;">
12.263490
</td>
<td style="text-align:right;">
16.876898
</td>
<td style="text-align:right;">
0.9343611
</td>
<td style="text-align:right;">
33.73044
</td>
<td style="text-align:right;">
6425
</td>
<td style="text-align:right;">
2137
</td>
<td style="text-align:right;">
75.04088
</td>
<td style="text-align:right;">
24.95912
</td>
<td style="text-align:right;">
2868
</td>
<td style="text-align:right;">
315
</td>
<td style="text-align:right;">
90.10368
</td>
<td style="text-align:right;">
9.896324
</td>
<td style="text-align:right;">
4986
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
138
</td>
<td style="text-align:right;">
35
</td>
<td style="text-align:right;">
762
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
1816
</td>
<td style="text-align:right;">
618
</td>
<td style="text-align:right;">
58.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
1.6
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
8.9
</td>
<td style="text-align:right;">
1.9
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
21.2
</td>
<td style="text-align:right;">
7.2
</td>
<td style="text-align:right;">
711
</td>
<td style="text-align:right;">
1146
</td>
<td style="text-align:right;">
793
</td>
<td style="text-align:right;">
482
</td>
<td style="text-align:right;">
22.3
</td>
<td style="text-align:right;">
36.0
</td>
<td style="text-align:right;">
24.9
</td>
<td style="text-align:right;">
15.1
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
622
</td>
<td style="text-align:right;">
2141
</td>
<td style="text-align:right;">
373
</td>
<td style="text-align:right;">
97.3
</td>
<td style="text-align:right;">
2.7
</td>
<td style="text-align:right;">
4.2
</td>
<td style="text-align:right;">
19.0
</td>
<td style="text-align:right;">
65.4
</td>
<td style="text-align:right;">
11.4
</td>
<td style="text-align:right;">
118.81
</td>
<td style="text-align:right;">
72.88949
</td>
<td style="text-align:right;">
162250
</td>
<td style="text-align:right;">
170000
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
200000.0
</td>
<td style="text-align:right;">
166250
</td>
<td style="text-align:right;">
169000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
167000
</td>
<td style="text-align:right;">
180000
</td>
<td style="text-align:right;">
152
</td>
<td style="text-align:right;">
168
</td>
<td style="text-align:right;">
184
</td>
<td style="text-align:right;">
73
</td>
<td style="text-align:right;">
60
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
59
</td>
<td style="text-align:right;">
75
</td>
<td style="text-align:right;">
1839
</td>
<td style="text-align:right;">
1026
</td>
<td style="text-align:right;">
1038
</td>
<td style="text-align:right;">
160
</td>
<td style="text-align:right;">
653
</td>
<td style="text-align:right;">
1119
</td>
<td style="text-align:right;">
527
</td>
<td style="text-align:right;">
333
</td>
<td style="text-align:right;">
4052
</td>
<td style="text-align:right;">
394
</td>
<td style="text-align:right;">
1881
</td>
<td style="text-align:right;">
68.29597
</td>
<td style="text-align:right;">
9.723593
</td>
<td style="text-align:right;">
31.70403
</td>
<td style="text-align:right;">
307
</td>
<td style="text-align:right;">
9.6
</td>
<td style="text-align:right;">
34293.82
</td>
<td style="text-align:right;">
29155.68
</td>
<td style="text-align:right;">
22.9
</td>
<td style="text-align:right;">
25.3
</td>
<td style="text-align:right;">
442
</td>
<td style="text-align:right;">
231
</td>
<td style="text-align:right;">
52.3
</td>
<td style="text-align:right;">
96.3
</td>
<td style="text-align:right;">
713
</td>
<td style="text-align:right;">
722
</td>
<td style="text-align:right;">
7127
</td>
<td style="text-align:right;">
8.327494
</td>
<td style="text-align:right;">
8.432609
</td>
<td style="text-align:right;">
83.23990
</td>
<td style="text-align:right;">
4089
</td>
<td style="text-align:right;">
2811
</td>
<td style="text-align:right;">
1134
</td>
<td style="text-align:right;">
412
</td>
<td style="text-align:right;">
116
</td>
<td style="text-align:right;">
47.75753
</td>
<td style="text-align:right;">
32.83111
</td>
<td style="text-align:right;">
13.244569
</td>
<td style="text-align:right;">
4.811960
</td>
<td style="text-align:right;">
1.354824
</td>
<td style="text-align:right;">
7.7
</td>
<td style="text-align:right;">
6.0
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
24.4
</td>
<td style="text-align:right;">
29.7
</td>
<td style="text-align:right;">
110.0
</td>
<td style="text-align:right;">
106.1
</td>
<td style="text-align:right;">
113.7
</td>
<td style="text-align:right;">
168.6
</td>
<td style="text-align:right;">
63.1
</td>
<td style="text-align:right;">
76.8
</td>
<td style="text-align:right;">
79.9
</td>
<td style="text-align:right;">
1080
</td>
<td style="text-align:right;">
1423
</td>
<td style="text-align:right;">
551
</td>
<td style="text-align:right;">
109
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
2937
</td>
<td style="text-align:right;">
33.9
</td>
<td style="text-align:right;">
44.7
</td>
<td style="text-align:right;">
17.3
</td>
<td style="text-align:right;">
3.4
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.9227144
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
30
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
27
</td>
<td style="text-align:right;">
29
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
25
</td>
</tr>
<tr>
<td style="text-align:right;">
8791
</td>
<td style="text-align:right;">
8672
</td>
<td style="text-align:right;">
119
</td>
<td style="text-align:right;">
50.6
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
13.290915
</td>
<td style="text-align:right;">
-8.2909151
</td>
<td style="text-align:right;">
-0.6238032
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
1.267089
</td>
<td style="text-align:right;">
3.732911
</td>
<td style="text-align:right;">
2.9460534
</td>
<td style="text-align:right;">
96
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
-0.9065610
</td>
<td style="text-align:right;">
1.1912744
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
51.26709
</td>
<td style="text-align:right;">
0.0702553
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
63.29092
</td>
<td style="text-align:right;">
-0.1401784
</td>
<td style="text-align:right;">
8791
</td>
<td style="text-align:right;">
2388
</td>
<td style="text-align:right;">
1765
</td>
<td style="text-align:right;">
1867
</td>
<td style="text-align:right;">
1736
</td>
<td style="text-align:right;">
1035
</td>
<td style="text-align:right;">
5368
</td>
<td style="text-align:right;">
7806
</td>
<td style="text-align:right;">
7726
</td>
<td style="text-align:right;">
7771
</td>
<td style="text-align:right;">
7820
</td>
<td style="text-align:right;">
7877
</td>
<td style="text-align:right;">
7974
</td>
<td style="text-align:right;">
8145
</td>
<td style="text-align:right;">
8394
</td>
<td style="text-align:right;">
8571
</td>
<td style="text-align:right;">
8823
</td>
<td style="text-align:right;">
9076
</td>
<td style="text-align:right;">
26.586602
</td>
<td style="text-align:right;">
62.02071
</td>
<td style="text-align:right;">
11.39268
</td>
<td style="text-align:right;">
957
</td>
<td style="text-align:right;">
792
</td>
<td style="text-align:right;">
664
</td>
<td style="text-align:right;">
633
</td>
<td style="text-align:right;">
642
</td>
<td style="text-align:right;">
686
</td>
<td style="text-align:right;">
634
</td>
<td style="text-align:right;">
651
</td>
<td style="text-align:right;">
596
</td>
<td style="text-align:right;">
610
</td>
<td style="text-align:right;">
483
</td>
<td style="text-align:right;">
398
</td>
<td style="text-align:right;">
296
</td>
<td style="text-align:right;">
242
</td>
<td style="text-align:right;">
207
</td>
<td style="text-align:right;">
180
</td>
<td style="text-align:right;">
181
</td>
<td style="text-align:right;">
139
</td>
<td style="text-align:right;">
85
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
489
</td>
<td style="text-align:right;">
776
</td>
<td style="text-align:right;">
1064
</td>
<td style="text-align:right;">
469
</td>
<td style="text-align:right;">
18.686428
</td>
<td style="text-align:right;">
14.21099
</td>
<td style="text-align:right;">
22.551584
</td>
<td style="text-align:right;">
30.92124
</td>
<td style="text-align:right;">
13.62976
</td>
<td style="text-align:right;">
5906
</td>
<td style="text-align:right;">
307
</td>
<td style="text-align:right;">
526
</td>
<td style="text-align:right;">
1997
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
2885
</td>
<td style="text-align:right;">
67.18235
</td>
<td style="text-align:right;">
3.492208
</td>
<td style="text-align:right;">
5.983392
</td>
<td style="text-align:right;">
22.716414
</td>
<td style="text-align:right;">
0.6256399
</td>
<td style="text-align:right;">
32.81765
</td>
<td style="text-align:right;">
6658
</td>
<td style="text-align:right;">
2133
</td>
<td style="text-align:right;">
75.73655
</td>
<td style="text-align:right;">
24.26345
</td>
<td style="text-align:right;">
3117
</td>
<td style="text-align:right;">
324
</td>
<td style="text-align:right;">
90.58413
</td>
<td style="text-align:right;">
9.415867
</td>
<td style="text-align:right;">
5409
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
67
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
577
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
2148
</td>
<td style="text-align:right;">
512
</td>
<td style="text-align:right;">
61.5
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
0.8
</td>
<td style="text-align:right;">
0.1
</td>
<td style="text-align:right;">
6.6
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
24.4
</td>
<td style="text-align:right;">
5.8
</td>
<td style="text-align:right;">
558
</td>
<td style="text-align:right;">
821
</td>
<td style="text-align:right;">
1663
</td>
<td style="text-align:right;">
333
</td>
<td style="text-align:right;">
16.2
</td>
<td style="text-align:right;">
23.9
</td>
<td style="text-align:right;">
48.3
</td>
<td style="text-align:right;">
9.7
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
93
</td>
<td style="text-align:right;">
82
</td>
<td style="text-align:right;">
761
</td>
<td style="text-align:right;">
1219
</td>
<td style="text-align:right;">
1471
</td>
<td style="text-align:right;">
97.4
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
2.3
</td>
<td style="text-align:right;">
21.5
</td>
<td style="text-align:right;">
34.5
</td>
<td style="text-align:right;">
41.6
</td>
<td style="text-align:right;">
173.58
</td>
<td style="text-align:right;">
52.28713
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
187000
</td>
<td style="text-align:right;">
199000.0
</td>
<td style="text-align:right;">
155000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
153750
</td>
<td style="text-align:right;">
172500
</td>
<td style="text-align:right;">
168500
</td>
<td style="text-align:right;">
112
</td>
<td style="text-align:right;">
133
</td>
<td style="text-align:right;">
139
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
40
</td>
<td style="text-align:right;">
75
</td>
<td style="text-align:right;">
76
</td>
<td style="text-align:right;">
48
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
2057
</td>
<td style="text-align:right;">
1065
</td>
<td style="text-align:right;">
1001
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
556
</td>
<td style="text-align:right;">
1129
</td>
<td style="text-align:right;">
429
</td>
<td style="text-align:right;">
402
</td>
<td style="text-align:right;">
3905
</td>
<td style="text-align:right;">
511
</td>
<td style="text-align:right;">
1893
</td>
<td style="text-align:right;">
67.35081
</td>
<td style="text-align:right;">
13.085788
</td>
<td style="text-align:right;">
32.64919
</td>
<td style="text-align:right;">
437
</td>
<td style="text-align:right;">
12.7
</td>
<td style="text-align:right;">
29975.83
</td>
<td style="text-align:right;">
25568.60
</td>
<td style="text-align:right;">
33.3
</td>
<td style="text-align:right;">
28.9
</td>
<td style="text-align:right;">
602
</td>
<td style="text-align:right;">
345
</td>
<td style="text-align:right;">
57.3
</td>
<td style="text-align:right;">
98.1
</td>
<td style="text-align:right;">
828
</td>
<td style="text-align:right;">
752
</td>
<td style="text-align:right;">
7211
</td>
<td style="text-align:right;">
9.418724
</td>
<td style="text-align:right;">
8.554203
</td>
<td style="text-align:right;">
82.02707
</td>
<td style="text-align:right;">
3996
</td>
<td style="text-align:right;">
3015
</td>
<td style="text-align:right;">
1252
</td>
<td style="text-align:right;">
407
</td>
<td style="text-align:right;">
121
</td>
<td style="text-align:right;">
45.45558
</td>
<td style="text-align:right;">
34.29644
</td>
<td style="text-align:right;">
14.241838
</td>
<td style="text-align:right;">
4.629735
</td>
<td style="text-align:right;">
1.376408
</td>
<td style="text-align:right;">
6.8
</td>
<td style="text-align:right;">
5.3
</td>
<td style="text-align:right;">
8.8
</td>
<td style="text-align:right;">
26.0
</td>
<td style="text-align:right;">
29.0
</td>
<td style="text-align:right;">
117.0
</td>
<td style="text-align:right;">
80.1
</td>
<td style="text-align:right;">
123.6
</td>
<td style="text-align:right;">
151.7
</td>
<td style="text-align:right;">
112.9
</td>
<td style="text-align:right;">
75.7
</td>
<td style="text-align:right;">
79.5
</td>
<td style="text-align:right;">
1496
</td>
<td style="text-align:right;">
1444
</td>
<td style="text-align:right;">
419
</td>
<td style="text-align:right;">
63
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
2549
</td>
<td style="text-align:right;">
43.5
</td>
<td style="text-align:right;">
42.0
</td>
<td style="text-align:right;">
12.2
</td>
<td style="text-align:right;">
1.8
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.7407730
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
25
</td>
<td style="text-align:right;">
27
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Having now ingested and linked our data, we begin by exploring the factors most highly correlated with our relative error rates.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-34_c976dc3afb6b6a4bcee8a874d75fffad">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb86" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb86-1">corr_df <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;">correlate</span>(dplyr<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;">select_if</span>(msoa_matrix_tbl, is.numeric), <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="cb86-2"></span>
<span id="cb86-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scipen=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>)</span></code></pre></div></div>
</div>
<p>Starting by our relative robbery error, a few interesting correlates stand out: - road traffic casualties - burglary numbers - the number of dwellings with no usual residents, and the number of commercial residents - households with no cars - the age composition of the area - general deprivation indicators (such as the proportion of households with central heating)</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-35_3c3dfd3d99b5621ea283640d08a8de0e">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb87" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb87-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#show only correlates with an absolute value higher than 0.2</span></span>
<span id="cb87-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(dplyr::select(corr_df[order(corr_df$RPDRobberyShifted),] , term, RPDRobberyShifted), RPDRobberyShifted &lt; -0.2 | RPDRobberyShifted &gt; 0.2)</span></span>
<span id="cb87-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(dplyr::select(corr_df[order(corr_df$RPDRobberyShifted),] , term, RPDRobberyShifted), RPDRobberyShifted &lt; -0.2 | RPDRobberyShifted &gt; 0.2)</span></span>
<span id="cb87-4">high_corr_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;">filter</span>(dplyr<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;">select</span>(corr_df, term, RPDRobberyShifted), RPDRobberyShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</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;">0.15</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> RPDRobberyShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>)</span>
<span id="cb87-5"></span>
<span id="cb87-6">high_corr_rob[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(high_corr_rob<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted),]</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
RPDRobberyShifted
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
robberyPredicted
</td>
<td style="text-align:right;">
-0.8387666
</td>
</tr>
<tr>
<td style="text-align:left;">
robberyPredictedShifted
</td>
<td style="text-align:right;">
-0.8387666
</td>
</tr>
<tr>
<td style="text-align:left;">
total_robberies
</td>
<td style="text-align:right;">
-0.5369450
</td>
</tr>
<tr>
<td style="text-align:left;">
total_burglaries
</td>
<td style="text-align:right;">
-0.4717060
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2011 2011 Total
</td>
<td style="text-align:right;">
-0.3701356
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2011 Slight
</td>
<td style="text-align:right;">
-0.3635665
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2010 2010 Total
</td>
<td style="text-align:right;">
-0.3597137
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2010 Slight
</td>
<td style="text-align:right;">
-0.3567229
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2012 2012 Total
</td>
<td style="text-align:right;">
-0.3563600
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2012 Slight
</td>
<td style="text-align:right;">
-0.3521528
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2011 Serious
</td>
<td style="text-align:right;">
-0.3474359
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2012 Serious
</td>
<td style="text-align:right;">
-0.3200851
</td>
</tr>
<tr>
<td style="text-align:left;">
Road Casualties 2010 Serious
</td>
<td style="text-align:right;">
-0.3057949
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryPredicted
</td>
<td style="text-align:right;">
-0.2952051
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryPredictedShifted
</td>
<td style="text-align:right;">
-0.2952051
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryActual
</td>
<td style="text-align:right;">
-0.2646662
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryActualShifted
</td>
<td style="text-align:right;">
-0.2646662
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with no usual residents
</td>
<td style="text-align:right;">
-0.2587599
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with no usual residents (%)
</td>
<td style="text-align:right;">
-0.2308005
</td>
</tr>
<tr>
<td style="text-align:left;">
Car or van availability (2011 Census) No cars or vans in household
</td>
<td style="text-align:right;">
-0.2279835
</td>
</tr>
<tr>
<td style="text-align:left;">
Qualifications (2011 Census) Schoolchildren and full-time students: Age 18 and over
</td>
<td style="text-align:right;">
-0.2219251
</td>
</tr>
<tr>
<td style="text-align:left;">
Mid-year Estimates 2012, by age 20-24
</td>
<td style="text-align:right;">
-0.2182673
</td>
</tr>
<tr>
<td style="text-align:left;">
Household Composition (2011) Numbers One person household
</td>
<td style="text-align:right;">
-0.2145786
</td>
</tr>
<tr>
<td style="text-align:left;">
Tenure (2011) Private rented
</td>
<td style="text-align:right;">
-0.2029037
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Flat, maisonette or apartment
</td>
<td style="text-align:right;">
-0.2015178
</td>
</tr>
<tr>
<td style="text-align:left;">
Household Composition (2011) Percentages One person household
</td>
<td style="text-align:right;">
-0.1900561
</td>
</tr>
<tr>
<td style="text-align:left;">
Age Structure (2011 Census) 16-29
</td>
<td style="text-align:right;">
-0.1896718
</td>
</tr>
<tr>
<td style="text-align:left;">
Car or van availability (2011 Census) No cars or vans in household (%)
</td>
<td style="text-align:right;">
-0.1895818
</td>
</tr>
<tr>
<td style="text-align:left;">
ComEstRes
</td>
<td style="text-align:right;">
-0.1858042
</td>
</tr>
<tr>
<td style="text-align:left;">
Mid-year Estimates 2012, by age % 15-64
</td>
<td style="text-align:right;">
-0.1821470
</td>
</tr>
<tr>
<td style="text-align:left;">
Religion (2011) Buddhist
</td>
<td style="text-align:right;">
-0.1772919
</td>
</tr>
<tr>
<td style="text-align:left;">
Religion (2011) Buddhist (%)
</td>
<td style="text-align:right;">
-0.1759725
</td>
</tr>
<tr>
<td style="text-align:left;">
Household Language (2011) No people in household have English as a main language
</td>
<td style="text-align:right;">
-0.1746012
</td>
</tr>
<tr>
<td style="text-align:left;">
Qualifications (2011 Census) Highest level of qualification: Level 3 qualifications
</td>
<td style="text-align:right;">
-0.1642773
</td>
</tr>
<tr>
<td style="text-align:left;">
Hholds
</td>
<td style="text-align:right;">
-0.1615083
</td>
</tr>
<tr>
<td style="text-align:left;">
Households (2011) All Households
</td>
<td style="text-align:right;">
-0.1615083
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with at least one usual resident
</td>
<td style="text-align:right;">
-0.1615083
</td>
</tr>
<tr>
<td style="text-align:left;">
Economic Activity (2011 Census) Economically inactive: Total
</td>
<td style="text-align:right;">
-0.1570016
</td>
</tr>
<tr>
<td style="text-align:left;">
Age Structure (2011 Census) Working-age
</td>
<td style="text-align:right;">
-0.1531622
</td>
</tr>
<tr>
<td style="text-align:left;">
Ethnic Group (2011 Census) Other ethnic group
</td>
<td style="text-align:right;">
-0.1523189
</td>
</tr>
<tr>
<td style="text-align:left;">
Car or van availability (2011 Census) Cars per household
</td>
<td style="text-align:right;">
0.1604540
</td>
</tr>
<tr>
<td style="text-align:left;">
Tenure (2011) Owned: Owned with a mortgage or loan (%)
</td>
<td style="text-align:right;">
0.1701928
</td>
</tr>
<tr>
<td style="text-align:left;">
Central Heating (2011 Census) Households with central heating (%)
</td>
<td style="text-align:right;">
0.2055461
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryError
</td>
<td style="text-align:right;">
0.2115687
</td>
</tr>
<tr>
<td style="text-align:left;">
Household Composition (2011) Percentages Couple household with dependent children
</td>
<td style="text-align:right;">
0.2130557
</td>
</tr>
<tr>
<td style="text-align:left;">
Car or van availability (2011 Census) 1 car or van in household (%)
</td>
<td style="text-align:right;">
0.2305679
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with at least one usual resident (%)
</td>
<td style="text-align:right;">
0.2308005
</td>
</tr>
<tr>
<td style="text-align:left;">
robberyError
</td>
<td style="text-align:right;">
0.8565425
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>The correlations for burglary are weaker - only a few have an absolute value higher than 0.2 - but a few stand out: - households with no residents - high robbery numbers - house prices</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-36_aa881b8bbc7ad5850a7f17758b71ea68">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb88" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb88-1">high_corr_burg <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>(dplyr<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;">select</span>(corr_df, term, RPDburglaryShifted), RPDburglaryShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</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;">0.15</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> RPDburglaryShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>)</span>
<span id="cb88-2"></span>
<span id="cb88-3">high_corr_burg[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(high_corr_burg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted),]</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
RPDburglaryShifted
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
burglaryPredicted
</td>
<td style="text-align:right;">
-0.8600903
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryPredictedShifted
</td>
<td style="text-align:right;">
-0.8600903
</td>
</tr>
<tr>
<td style="text-align:left;">
total_burglaries
</td>
<td style="text-align:right;">
-0.2169094
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with no usual residents
</td>
<td style="text-align:right;">
-0.1761768
</td>
</tr>
<tr>
<td style="text-align:left;">
total_robberies
</td>
<td style="text-align:right;">
-0.1714721
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with no usual residents (%)
</td>
<td style="text-align:right;">
-0.1706826
</td>
</tr>
<tr>
<td style="text-align:left;">
robberyPredicted
</td>
<td style="text-align:right;">
-0.1631558
</td>
</tr>
<tr>
<td style="text-align:left;">
robberyPredictedShifted
</td>
<td style="text-align:right;">
-0.1631558
</td>
</tr>
<tr>
<td style="text-align:left;">
House Prices Median House Price (£) 2010
</td>
<td style="text-align:right;">
-0.1609004
</td>
</tr>
<tr>
<td style="text-align:left;">
House Prices Median House Price (£) 2008
</td>
<td style="text-align:right;">
-0.1527950
</td>
</tr>
<tr>
<td style="text-align:left;">
House Prices Median House Price (£) 2011
</td>
<td style="text-align:right;">
-0.1507911
</td>
</tr>
<tr>
<td style="text-align:left;">
House Prices Median House Price (£) 2007
</td>
<td style="text-align:right;">
-0.1505301
</td>
</tr>
<tr>
<td style="text-align:left;">
Mid-year Estimates 2012, by age % 0 to 14
</td>
<td style="text-align:right;">
0.1628106
</td>
</tr>
<tr>
<td style="text-align:left;">
robberyError
</td>
<td style="text-align:right;">
0.1628523
</td>
</tr>
<tr>
<td style="text-align:left;">
Dwelling type (2011) Household spaces with at least one usual resident (%)
</td>
<td style="text-align:right;">
0.1706826
</td>
</tr>
<tr>
<td style="text-align:left;">
burglaryError
</td>
<td style="text-align:right;">
0.9656142
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>These correlates suggest we can model this shift - this is likely to prove more reliable for robbery (where the correlations are stronger), and seem linked to usual resident population(as measured by household composition), deprivation (through various proxy indicators such as central heating presence or housing type), and general crime patterns (through total burglary and robbery numbers)</p>
<p>We will take two approaches for modelling: a simple regression (to identify strong links) and random forest regressors (to identify non-linear associations)</p>
<section id="simple-regression" class="level3">
<h3 class="anchored" data-anchor-id="simple-regression">Simple Regression</h3>
<p>We begin through the use of simple OLS regression. This is a linear model that has large limitations for modelling complex relationships, but can be an effective first step, effectively with a few transformations.</p>
<p>R does not cope well with blank spaces in terms, so we’ll extract and rename our key correlates.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-37_295ed7ae38ed1d65bb1ab97cf5378865">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb89" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb89-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#make copy of df and rename </span></span>
<span id="cb89-2"></span>
<span id="cb89-3">msoa_copy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> msoa_matrix_numeric</span>
<span id="cb89-4"></span>
<span id="cb89-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Dwelling type (2011) Household spaces with no usual residents"</span>] <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;">"DwellingNoResidents"</span></span>
<span id="cb89-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"House Prices Median House Price (£) 2010"</span>] <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;">"MedianHousePrice"</span></span>
<span id="cb89-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Dwelling type (2011) Flat, maisonette or apartment"</span>] <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;">"FlatAprt"</span></span>
<span id="cb89-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Qualifications (2011 Census) Schoolchildren and full-time students: Age 18 and over"</span>] <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;">"fullTimeStudents"</span></span>
<span id="cb89-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Car or van availability (2011 Census) No cars or vans in household"</span>] <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;">"NoCars"</span></span>
<span id="cb89-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Ethnic Group (2011 Census) Other ethnic group"</span>] <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;">"OtherEthnicGroup"</span></span>
<span id="cb89-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(msoa_copy) <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;">"Central Heating (2011 Census) Households with central heating (%)"</span>] <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;">"CentralHealingPercent"</span></span></code></pre></div></div>
</div>
<p>Let’s now extract these to a separate dataframe, remove any missing values, and provide some quick summary statistics to identify any obvious concerns.</p>
<p>We also generate a matrix of scatter-plots, so as to identify any obvious relationships between our key values.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-38_6ee1ac19d2d217db3ec396d71a762b5c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb90" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb90-1">feature_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dplyr<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;">select</span>(msoa_copy, RPDburglaryShifted, RPDRobberyShifted, total_burglaries, total_robberies, DwellingNoResidents, MedianHousePrice, FlatAprt, fullTimeStudents, NoCars, OtherEthnicGroup, CentralHealingPercent, AvHholdSz, ComEstRes)</span>
<span id="cb90-2"></span>
<span id="cb90-3">feature_df <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;">drop_na</span>(feature_df, RPDburglaryShifted, RPDRobberyShifted)</span>
<span id="cb90-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(feature_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:right;">
RPDburglaryShifted
</th>
<th style="text-align:right;">
RPDRobberyShifted
</th>
<th style="text-align:right;">
total_burglaries
</th>
<th style="text-align:right;">
total_robberies
</th>
<th style="text-align:right;">
DwellingNoResidents
</th>
<th style="text-align:right;">
MedianHousePrice
</th>
<th style="text-align:right;">
FlatAprt
</th>
<th style="text-align:right;">
fullTimeStudents
</th>
<th style="text-align:right;">
NoCars
</th>
<th style="text-align:right;">
OtherEthnicGroup
</th>
<th style="text-align:right;">
CentralHealingPercent
</th>
<th style="text-align:right;">
AvHholdSz
</th>
<th style="text-align:right;">
ComEstRes
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
-0.1219796
</td>
<td style="text-align:right;">
0.0601204
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
1145
</td>
<td style="text-align:right;">
450000
</td>
<td style="text-align:right;">
5416
</td>
<td style="text-align:right;">
422
</td>
<td style="text-align:right;">
3043
</td>
<td style="text-align:right;">
154
</td>
<td style="text-align:right;">
95.7
</td>
<td style="text-align:right;">
1.6
</td>
<td style="text-align:right;">
188
</td>
</tr>
<tr>
<td style="text-align:right;">
0.3489691
</td>
<td style="text-align:right;">
-0.0223392
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
82
</td>
<td style="text-align:right;">
173000
</td>
<td style="text-align:right;">
1087
</td>
<td style="text-align:right;">
272
</td>
<td style="text-align:right;">
1020
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
97.5
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
51
</td>
</tr>
<tr>
<td style="text-align:right;">
-0.0218569
</td>
<td style="text-align:right;">
0.0526430
</td>
<td style="text-align:right;">
239
</td>
<td style="text-align:right;">
124
</td>
<td style="text-align:right;">
110
</td>
<td style="text-align:right;">
215000
</td>
<td style="text-align:right;">
1256
</td>
<td style="text-align:right;">
442
</td>
<td style="text-align:right;">
1196
</td>
<td style="text-align:right;">
224
</td>
<td style="text-align:right;">
96.5
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
12
</td>
</tr>
<tr>
<td style="text-align:right;">
0.1381492
</td>
<td style="text-align:right;">
0.0257532
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
30
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
192000
</td>
<td style="text-align:right;">
314
</td>
<td style="text-align:right;">
215
</td>
<td style="text-align:right;">
556
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
98.5
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
245
</td>
</tr>
<tr>
<td style="text-align:right;">
-0.0107732
</td>
<td style="text-align:right;">
-0.1490559
</td>
<td style="text-align:right;">
161
</td>
<td style="text-align:right;">
87
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
169000
</td>
<td style="text-align:right;">
373
</td>
<td style="text-align:right;">
333
</td>
<td style="text-align:right;">
1080
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
96.3
</td>
<td style="text-align:right;">
2.7
</td>
<td style="text-align:right;">
0
</td>
</tr>
<tr>
<td style="text-align:right;">
-0.1401784
</td>
<td style="text-align:right;">
0.0702553
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
96
</td>
<td style="text-align:right;">
93
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
1471
</td>
<td style="text-align:right;">
402
</td>
<td style="text-align:right;">
1496
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
98.1
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
119
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-39_2d8593019d93928816ea1b273217f54c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb91" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb91-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(feature_df)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code> RPDburglaryShifted RPDRobberyShifted  total_burglaries total_robberies  
 Min.   :-0.81266   Min.   :-1.45491   Min.   :  46.0   Min.   :   2.00  
 1st Qu.:-0.20689   1st Qu.:-0.11808   1st Qu.: 121.0   1st Qu.:  29.00  
 Median :-0.08826   Median :-0.04081   Median : 159.0   Median :  53.00  
 Mean   :-0.07976   Mean   :-0.04876   Mean   : 175.5   Mean   :  78.53  
 3rd Qu.: 0.03612   3rd Qu.: 0.04309   3rd Qu.: 205.0   3rd Qu.:  92.00  
 Max.   : 1.29467   Max.   : 0.62020   Max.   :1973.0   Max.   :2456.00  
 DwellingNoResidents MedianHousePrice     FlatAprt      fullTimeStudents
 Min.   :  14.0      Min.   : 137625   Min.   :  54.0   Min.   : 122.0  
 1st Qu.:  59.0      1st Qu.: 222500   1st Qu.: 830.5   1st Qu.: 305.5  
 Median :  86.0      Median : 265975   Median :1607.0   Median : 465.0  
 Mean   : 123.4      Mean   : 310710   Mean   :1798.2   Mean   : 539.5  
 3rd Qu.: 133.0      3rd Qu.: 351525   3rd Qu.:2566.5   3rd Qu.: 654.5  
 Max.   :1556.0      Max.   :1425000   Max.   :6429.0   Max.   :3370.0  
     NoCars     OtherEthnicGroup CentralHealingPercent   AvHholdSz    
 Min.   : 185   Min.   :  16.0   Min.   :92.10         Min.   :1.600  
 1st Qu.: 796   1st Qu.: 134.0   1st Qu.:96.60         1st Qu.:2.300  
 Median :1256   Median : 232.0   Median :97.40         Median :2.500  
 Mean   :1382   Mean   : 285.8   Mean   :97.24         Mean   :2.506  
 3rd Qu.:1858   3rd Qu.: 376.5   3rd Qu.:98.00         3rd Qu.:2.700  
 Max.   :4319   Max.   :3001.0   Max.   :99.60         Max.   :3.900  
   ComEstRes   
 Min.   :   0  
 1st Qu.:   9  
 Median :  41  
 Mean   : 102  
 3rd Qu.: 105  
 Max.   :2172  </code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-40_8d002df2959225e7ca50009b77c3950f">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb93" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb93-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colSums</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(feature_df))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>   RPDburglaryShifted     RPDRobberyShifted      total_burglaries 
                    0                     0                     0 
      total_robberies   DwellingNoResidents      MedianHousePrice 
                    0                     0                     0 
             FlatAprt      fullTimeStudents                NoCars 
                    0                     0                     0 
     OtherEthnicGroup CentralHealingPercent             AvHholdSz 
                    0                     0                     0 
            ComEstRes 
                    0 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb95" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb95-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairs</span>(feature_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-40-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>As we hoped, some obvious relationships stand out: for instance, the presence of apartments, and households with no cars, or central heating and average household size.</p>
<p>Our robbery and burglary data and change rates are densely clustered - they’re unlikely to cleanly associate with anything. With that in mind, we’ll perform a log transformation. This cannot be undertaken with negative values, so once again we’ll perform a shift (of 2) for both of our relative error numbers, as well as a commercial resident column, before log transforming our features.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-41_1581dfa2762435d365dc65a26a0738f6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb96" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb96-1">feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BurglaryRPDTranform <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted    <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="cb96-2">feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RobberyRPDTranform <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted   <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="cb96-3"></span>
<span id="cb96-4">feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ComEstResTranform <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ComEstRes   <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="cb96-5"></span>
<span id="cb96-6"></span>
<span id="cb96-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (col <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;">colnames</span>(feature_df)){</span>
<span id="cb96-8">  new_name <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;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log_"</span>, col, <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="cb96-9">  feature_df[new_name] <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;">log</span>(feature_df[col])</span>
<span id="cb96-10">}</span>
<span id="cb96-11"></span>
<span id="cb96-12">drop<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;">"log_ComEstRes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log_RPDburglaryShifted"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log_RPDRobberyShifted"</span>)</span>
<span id="cb96-13">feature_df<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df[,<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;">names</span>(feature_df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> drop)]</span>
<span id="cb96-14"></span>
<span id="cb96-15"></span>
<span id="cb96-16">feat_transform_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</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;">29</span>]</span>
<span id="cb96-17">orig_feat_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> feature_df[,<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;">17</span>]</span></code></pre></div></div>
</div>
<p>We’ve now separated a separate dataframe where each value has been log transformed - while this isn’t hugely rigorous (and would benefit from inspecting the relationships in more detail) it serves our immediate purpose.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-42_ec3b98a00f3c7694b7e73518416bb91e">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb97" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb97-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairs</span>(feat_transform_df)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-42-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>While we’ve introduced a bit of noise, we’ve also “forced” some of our variables into relationships that look semi linear.</p>
<p>To dig into this deeper, let’s create a correlation matrix for our entire transformed dataframe.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-43_bc1fe9147f7ef9bf65a0413bf902f1e5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb98" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb98-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">correlate</span>(feat_transform_df)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Correlation computed with
• Method: 'pearson'
• Missing treated using: 'pairwise.complete.obs'</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
log_total_burglaries
</th>
<th style="text-align:right;">
log_total_robberies
</th>
<th style="text-align:right;">
log_DwellingNoResidents
</th>
<th style="text-align:right;">
log_MedianHousePrice
</th>
<th style="text-align:right;">
log_FlatAprt
</th>
<th style="text-align:right;">
log_fullTimeStudents
</th>
<th style="text-align:right;">
log_NoCars
</th>
<th style="text-align:right;">
log_OtherEthnicGroup
</th>
<th style="text-align:right;">
log_CentralHealingPercent
</th>
<th style="text-align:right;">
log_AvHholdSz
</th>
<th style="text-align:right;">
log_BurglaryRPDTranform
</th>
<th style="text-align:right;">
log_RobberyRPDTranform
</th>
<th style="text-align:right;">
log_ComEstResTranform
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
log_total_burglaries
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.6793730
</td>
<td style="text-align:right;">
0.5009180
</td>
<td style="text-align:right;">
0.2641776
</td>
<td style="text-align:right;">
0.5386775
</td>
<td style="text-align:right;">
0.3830059
</td>
<td style="text-align:right;">
0.5287612
</td>
<td style="text-align:right;">
0.3864406
</td>
<td style="text-align:right;">
-0.3234183
</td>
<td style="text-align:right;">
-0.3632653
</td>
<td style="text-align:right;">
-0.2224450
</td>
<td style="text-align:right;">
-0.3858625
</td>
<td style="text-align:right;">
0.2461299
</td>
</tr>
<tr>
<td style="text-align:left;">
log_total_robberies
</td>
<td style="text-align:right;">
0.6793730
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.3528253
</td>
<td style="text-align:right;">
0.0289555
</td>
<td style="text-align:right;">
0.6210392
</td>
<td style="text-align:right;">
0.6262973
</td>
<td style="text-align:right;">
0.7312742
</td>
<td style="text-align:right;">
0.5328260
</td>
<td style="text-align:right;">
-0.4392580
</td>
<td style="text-align:right;">
-0.1885684
</td>
<td style="text-align:right;">
-0.1143993
</td>
<td style="text-align:right;">
-0.3860350
</td>
<td style="text-align:right;">
0.2003534
</td>
</tr>
<tr>
<td style="text-align:left;">
log_DwellingNoResidents
</td>
<td style="text-align:right;">
0.5009180
</td>
<td style="text-align:right;">
0.3528253
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.5259771
</td>
<td style="text-align:right;">
0.5455129
</td>
<td style="text-align:right;">
0.2061306
</td>
<td style="text-align:right;">
0.4187217
</td>
<td style="text-align:right;">
0.2388495
</td>
<td style="text-align:right;">
-0.3673864
</td>
<td style="text-align:right;">
-0.6022479
</td>
<td style="text-align:right;">
-0.1801381
</td>
<td style="text-align:right;">
-0.2106489
</td>
<td style="text-align:right;">
0.2991287
</td>
</tr>
<tr>
<td style="text-align:left;">
log_MedianHousePrice
</td>
<td style="text-align:right;">
0.2641776
</td>
<td style="text-align:right;">
0.0289555
</td>
<td style="text-align:right;">
0.5259771
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.2266006
</td>
<td style="text-align:right;">
-0.0590916
</td>
<td style="text-align:right;">
0.0310431
</td>
<td style="text-align:right;">
0.1415866
</td>
<td style="text-align:right;">
-0.0743475
</td>
<td style="text-align:right;">
-0.4236094
</td>
<td style="text-align:right;">
-0.1667024
</td>
<td style="text-align:right;">
-0.0843802
</td>
<td style="text-align:right;">
0.1860743
</td>
</tr>
<tr>
<td style="text-align:left;">
log_FlatAprt
</td>
<td style="text-align:right;">
0.5386775
</td>
<td style="text-align:right;">
0.6210392
</td>
<td style="text-align:right;">
0.5455129
</td>
<td style="text-align:right;">
0.2266006
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.4899513
</td>
<td style="text-align:right;">
0.8808568
</td>
<td style="text-align:right;">
0.5041155
</td>
<td style="text-align:right;">
-0.4913225
</td>
<td style="text-align:right;">
-0.5893529
</td>
<td style="text-align:right;">
-0.0645864
</td>
<td style="text-align:right;">
-0.1646088
</td>
<td style="text-align:right;">
0.2781184
</td>
</tr>
<tr>
<td style="text-align:left;">
log_fullTimeStudents
</td>
<td style="text-align:right;">
0.3830059
</td>
<td style="text-align:right;">
0.6262973
</td>
<td style="text-align:right;">
0.2061306
</td>
<td style="text-align:right;">
-0.0590916
</td>
<td style="text-align:right;">
0.4899513
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.6188377
</td>
<td style="text-align:right;">
0.6459824
</td>
<td style="text-align:right;">
-0.3243579
</td>
<td style="text-align:right;">
0.1050335
</td>
<td style="text-align:right;">
-0.0491348
</td>
<td style="text-align:right;">
-0.2206372
</td>
<td style="text-align:right;">
0.2923494
</td>
</tr>
<tr>
<td style="text-align:left;">
log_NoCars
</td>
<td style="text-align:right;">
0.5287612
</td>
<td style="text-align:right;">
0.7312742
</td>
<td style="text-align:right;">
0.4187217
</td>
<td style="text-align:right;">
0.0310431
</td>
<td style="text-align:right;">
0.8808568
</td>
<td style="text-align:right;">
0.6188377
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.5238758
</td>
<td style="text-align:right;">
-0.5402424
</td>
<td style="text-align:right;">
-0.4448476
</td>
<td style="text-align:right;">
-0.0361088
</td>
<td style="text-align:right;">
-0.2002598
</td>
<td style="text-align:right;">
0.1658930
</td>
</tr>
<tr>
<td style="text-align:left;">
log_OtherEthnicGroup
</td>
<td style="text-align:right;">
0.3864406
</td>
<td style="text-align:right;">
0.5328260
</td>
<td style="text-align:right;">
0.2388495
</td>
<td style="text-align:right;">
0.1415866
</td>
<td style="text-align:right;">
0.5041155
</td>
<td style="text-align:right;">
0.6459824
</td>
<td style="text-align:right;">
0.5238758
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
-0.2366892
</td>
<td style="text-align:right;">
0.0716831
</td>
<td style="text-align:right;">
-0.0182390
</td>
<td style="text-align:right;">
-0.1700667
</td>
<td style="text-align:right;">
0.1260174
</td>
</tr>
<tr>
<td style="text-align:left;">
log_CentralHealingPercent
</td>
<td style="text-align:right;">
-0.3234183
</td>
<td style="text-align:right;">
-0.4392580
</td>
<td style="text-align:right;">
-0.3673864
</td>
<td style="text-align:right;">
-0.0743475
</td>
<td style="text-align:right;">
-0.4913225
</td>
<td style="text-align:right;">
-0.3243579
</td>
<td style="text-align:right;">
-0.5402424
</td>
<td style="text-align:right;">
-0.2366892
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.4351582
</td>
<td style="text-align:right;">
0.0943127
</td>
<td style="text-align:right;">
0.2435584
</td>
<td style="text-align:right;">
-0.1453510
</td>
</tr>
<tr>
<td style="text-align:left;">
log_AvHholdSz
</td>
<td style="text-align:right;">
-0.3632653
</td>
<td style="text-align:right;">
-0.1885684
</td>
<td style="text-align:right;">
-0.6022479
</td>
<td style="text-align:right;">
-0.4236094
</td>
<td style="text-align:right;">
-0.5893529
</td>
<td style="text-align:right;">
0.1050335
</td>
<td style="text-align:right;">
-0.4448476
</td>
<td style="text-align:right;">
0.0716831
</td>
<td style="text-align:right;">
0.4351582
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.1430359
</td>
<td style="text-align:right;">
0.1747301
</td>
<td style="text-align:right;">
-0.2479341
</td>
</tr>
<tr>
<td style="text-align:left;">
log_BurglaryRPDTranform
</td>
<td style="text-align:right;">
-0.2224450
</td>
<td style="text-align:right;">
-0.1143993
</td>
<td style="text-align:right;">
-0.1801381
</td>
<td style="text-align:right;">
-0.1667024
</td>
<td style="text-align:right;">
-0.0645864
</td>
<td style="text-align:right;">
-0.0491348
</td>
<td style="text-align:right;">
-0.0361088
</td>
<td style="text-align:right;">
-0.0182390
</td>
<td style="text-align:right;">
0.0943127
</td>
<td style="text-align:right;">
0.1430359
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
0.1726291
</td>
<td style="text-align:right;">
-0.1678558
</td>
</tr>
<tr>
<td style="text-align:left;">
log_RobberyRPDTranform
</td>
<td style="text-align:right;">
-0.3858625
</td>
<td style="text-align:right;">
-0.3860350
</td>
<td style="text-align:right;">
-0.2106489
</td>
<td style="text-align:right;">
-0.0843802
</td>
<td style="text-align:right;">
-0.1646088
</td>
<td style="text-align:right;">
-0.2206372
</td>
<td style="text-align:right;">
-0.2002598
</td>
<td style="text-align:right;">
-0.1700667
</td>
<td style="text-align:right;">
0.2435584
</td>
<td style="text-align:right;">
0.1747301
</td>
<td style="text-align:right;">
0.1726291
</td>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
-0.1638404
</td>
</tr>
<tr>
<td style="text-align:left;">
log_ComEstResTranform
</td>
<td style="text-align:right;">
0.2461299
</td>
<td style="text-align:right;">
0.2003534
</td>
<td style="text-align:right;">
0.2991287
</td>
<td style="text-align:right;">
0.1860743
</td>
<td style="text-align:right;">
0.2781184
</td>
<td style="text-align:right;">
0.2923494
</td>
<td style="text-align:right;">
0.1658930
</td>
<td style="text-align:right;">
0.1260174
</td>
<td style="text-align:right;">
-0.1453510
</td>
<td style="text-align:right;">
-0.2479341
</td>
<td style="text-align:right;">
-0.1678558
</td>
<td style="text-align:right;">
-0.1638404
</td>
<td style="text-align:right;">
NA
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>To provide a visual aid, I’ve extracted the column for our robbery relative change rate, and sorted the table accordingly.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-44_65f4d1aa012e278926a4ca1780c6ec81">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb100" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb100-1">dplyr<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;">select</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">correlate</span>(feat_transform_df)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">correlate</span>(feat_transform_df)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>log_BurglaryRPDTranform),], term, log_BurglaryRPDTranform)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Correlation computed with
• Method: 'pearson'
• Missing treated using: 'pairwise.complete.obs'
Correlation computed with
• Method: 'pearson'
• Missing treated using: 'pairwise.complete.obs'</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
log_BurglaryRPDTranform
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
log_total_burglaries
</td>
<td style="text-align:right;">
-0.2224450
</td>
</tr>
<tr>
<td style="text-align:left;">
log_DwellingNoResidents
</td>
<td style="text-align:right;">
-0.1801381
</td>
</tr>
<tr>
<td style="text-align:left;">
log_ComEstResTranform
</td>
<td style="text-align:right;">
-0.1678558
</td>
</tr>
<tr>
<td style="text-align:left;">
log_MedianHousePrice
</td>
<td style="text-align:right;">
-0.1667024
</td>
</tr>
<tr>
<td style="text-align:left;">
log_total_robberies
</td>
<td style="text-align:right;">
-0.1143993
</td>
</tr>
<tr>
<td style="text-align:left;">
log_FlatAprt
</td>
<td style="text-align:right;">
-0.0645864
</td>
</tr>
<tr>
<td style="text-align:left;">
log_fullTimeStudents
</td>
<td style="text-align:right;">
-0.0491348
</td>
</tr>
<tr>
<td style="text-align:left;">
log_NoCars
</td>
<td style="text-align:right;">
-0.0361088
</td>
</tr>
<tr>
<td style="text-align:left;">
log_OtherEthnicGroup
</td>
<td style="text-align:right;">
-0.0182390
</td>
</tr>
<tr>
<td style="text-align:left;">
log_CentralHealingPercent
</td>
<td style="text-align:right;">
0.0943127
</td>
</tr>
<tr>
<td style="text-align:left;">
log_AvHholdSz
</td>
<td style="text-align:right;">
0.1430359
</td>
</tr>
<tr>
<td style="text-align:left;">
log_RobberyRPDTranform
</td>
<td style="text-align:right;">
0.1726291
</td>
</tr>
<tr>
<td style="text-align:left;">
log_BurglaryRPDTranform
</td>
<td style="text-align:right;">
NA
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="regression" class="level3">
<h3 class="anchored" data-anchor-id="regression">Regression</h3>
<p>Now that we’ve transformed our data, cleaned it up, and identified potential correlates, let’s build our linear model.</p>
<p>There are various automated tools for this process that seek to provide the highest fit and significance, but given the high degree of correlation between my chosen features, I’ve taken a more manual approach and tested a variety of models until I identified one with a suitable fit. The final model is below.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-45_3670003fcf79af910024238fcb001f93">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb102" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb102-1">mod_burglary <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>(log_BurglaryRPDTranform <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> log_total_burglaries <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_FlatAprt <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_MedianHousePrice  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_ComEstResTranform, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> feat_transform_df)</span>
<span id="cb102-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(mod_burglary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = log_BurglaryRPDTranform ~ log_total_burglaries + 
    log_FlatAprt + log_MedianHousePrice + log_ComEstResTranform, 
    data = feat_transform_df)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.39022 -0.06547 -0.00309  0.05830  0.56322 

Coefficients:
                       Estimate Std. Error t value             Pr(&gt;|t|)    
(Intercept)            1.255068   0.112681  11.138 &lt; 0.0000000000000002 ***
log_total_burglaries  -0.058851   0.009708  -6.062        0.00000000192 ***
log_FlatAprt           0.016153   0.005157   3.132             0.001786 ** 
log_MedianHousePrice  -0.031691   0.009245  -3.428             0.000634 ***
log_ComEstResTranform -0.008125   0.002119  -3.833             0.000135 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.1027 on 974 degrees of freedom
Multiple R-squared:  0.08188,   Adjusted R-squared:  0.07811 
F-statistic: 21.72 on 4 and 974 DF,  p-value: &lt; 0.00000000000000022</code></pre>
</div>
</div>
<p>Our model suggests the largest burglary decrease linked to lockdown was in MSOAs which a high level of historic burglary. The composition of housing/accomodation and area type also seems to play a role, with those areas with higher median house prices, and a larger number of commercial residents, seeing stronger decreases, while conversely areas with large number of apartments temper the effect.</p>
<p>While all our variables are significant, the model is not a particularly good fit - the adjusted R2 is around 0.08, suggesting that less than 10% of the variance is accounted for by our model. I suspect more geographic features - such as distance from central London, more accurate footfall, or spatial lags - would probably be useful, but that’s outside the scope of this project.</p>
<p>Let’s perform a similar exercise for robbery.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-46_cdc60ffa39e1f3ed102137dc145542d2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb104" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb104-1">dplyr<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;">select</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">correlate</span>(feat_transform_df)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">correlate</span>(feat_transform_df)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>log_RobberyRPDTranform),], term, log_RobberyRPDTranform)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Correlation computed with
• Method: 'pearson'
• Missing treated using: 'pairwise.complete.obs'
Correlation computed with
• Method: 'pearson'
• Missing treated using: 'pairwise.complete.obs'</code></pre>
</div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
log_RobberyRPDTranform
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
log_total_robberies
</td>
<td style="text-align:right;">
-0.3860350
</td>
</tr>
<tr>
<td style="text-align:left;">
log_total_burglaries
</td>
<td style="text-align:right;">
-0.3858625
</td>
</tr>
<tr>
<td style="text-align:left;">
log_fullTimeStudents
</td>
<td style="text-align:right;">
-0.2206372
</td>
</tr>
<tr>
<td style="text-align:left;">
log_DwellingNoResidents
</td>
<td style="text-align:right;">
-0.2106489
</td>
</tr>
<tr>
<td style="text-align:left;">
log_NoCars
</td>
<td style="text-align:right;">
-0.2002598
</td>
</tr>
<tr>
<td style="text-align:left;">
log_OtherEthnicGroup
</td>
<td style="text-align:right;">
-0.1700667
</td>
</tr>
<tr>
<td style="text-align:left;">
log_FlatAprt
</td>
<td style="text-align:right;">
-0.1646088
</td>
</tr>
<tr>
<td style="text-align:left;">
log_ComEstResTranform
</td>
<td style="text-align:right;">
-0.1638404
</td>
</tr>
<tr>
<td style="text-align:left;">
log_MedianHousePrice
</td>
<td style="text-align:right;">
-0.0843802
</td>
</tr>
<tr>
<td style="text-align:left;">
log_BurglaryRPDTranform
</td>
<td style="text-align:right;">
0.1726291
</td>
</tr>
<tr>
<td style="text-align:left;">
log_AvHholdSz
</td>
<td style="text-align:right;">
0.1747301
</td>
</tr>
<tr>
<td style="text-align:left;">
log_CentralHealingPercent
</td>
<td style="text-align:right;">
0.2435584
</td>
</tr>
<tr>
<td style="text-align:left;">
log_RobberyRPDTranform
</td>
<td style="text-align:right;">
NA
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-47_09d2972f321bc0eea53521dd21557d98">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb106" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb106-1">mod_burglary <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>(log_RobberyRPDTranform <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> log_total_robberies  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_total_burglaries <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_FlatAprt <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_CentralHealingPercent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_fullTimeStudents, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> feat_transform_df)</span>
<span id="cb106-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(mod_burglary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = log_RobberyRPDTranform ~ log_total_robberies + log_total_burglaries + 
    log_FlatAprt + log_CentralHealingPercent + log_fullTimeStudents, 
    data = feat_transform_df)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.95406 -0.04243 -0.00535  0.04616  0.31826 

Coefficients:
                           Estimate Std. Error t value        Pr(&gt;|t|)    
(Intercept)               -5.041998   1.396500  -3.610        0.000321 ***
log_total_robberies       -0.030763   0.005495  -5.598 0.0000000282078 ***
log_total_burglaries      -0.066724   0.009757  -6.838 0.0000000000141 ***
log_FlatAprt               0.029516   0.005148   5.733 0.0000000131343 ***
log_CentralHealingPercent  1.302973   0.301809   4.317 0.0000174188038 ***
log_fullTimeStudents      -0.001894   0.006809  -0.278        0.780980    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.08921 on 973 degrees of freedom
Multiple R-squared:  0.2103,    Adjusted R-squared:  0.2062 
F-statistic: 51.81 on 5 and 973 DF,  p-value: &lt; 0.00000000000000022</code></pre>
</div>
</div>
<p>This is a notably better fit than our burglary model, with our R2 suggesting we now account for over 20% of the variance. The nature of our predictors is also quite different: while we still see a negative relationship with historic crime (with areas of high historic crime experiencing larger relative decreases), there is a positive relationship with both the presence of apartments and central heating.</p>
<p>I suspect some of these features are correlates of deprivation, so I want to create a quick scatter of three - for now we’ll do it against median house price, which is definitely deprivation correlated.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-48_0bd28fb4a16a38ebcc11620cb2c33091">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb108" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb108-1">heating <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>(feature_df, <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> log_MedianHousePrice, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> log_CentralHealingPercent)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method=</span>lm)</span>
<span id="cb108-4"></span>
<span id="cb108-5">apartments <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>(feature_df, <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> log_MedianHousePrice, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> log_FlatAprt)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method=</span>lm)</span>
<span id="cb108-8"></span>
<span id="cb108-9">comest <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>(feature_df, <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> log_MedianHousePrice, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> log_ComEstResTranform)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb108-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method=</span>lm)</span>
<span id="cb108-12"></span>
<span id="cb108-13"></span>
<span id="cb108-14"></span>
<span id="cb108-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggarrange</span>(heating, apartments, comest, <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> )</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-48-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>While there does appear to be a relationship with some of these, it isn’t strong - this suggests the factor’s we have identified are significant not because of their association with deprivation and poverty, but because of what they mean about the specific characteristics of the area.</p>
</section>
<section id="random-forests" class="level3">
<h3 class="anchored" data-anchor-id="random-forests">Random Forests</h3>
<p>Unlike regression, random forest doesn’t really on any specific type of association - instead, we rely on computing power, repetition and iteration to capture the very best predictor for our variable, in any combination.</p>
<p>There are risks to this method: our sample size is smaller than I’d like, and this may lead to over-fit of outlier MSOAs.</p>
<p>It does mean we don’t need to worry about transformations or correlations: we can return to our original dataset, and let the model identify the strongest predictors.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-49_cbf002a38e2398b7127907bbd0d3f92c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb110" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb110-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we remove rows where our main error is na or missing</span></span>
<span id="cb110-2">rf_msoa_matrix <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;">drop_na</span>(msoa_matrix_numeric, RPDRobberyShifted)</span>
<span id="cb110-3"></span>
<span id="cb110-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#then we repeat for any columns where value asre missing</span></span>
<span id="cb110-5">clean_rf_matrix <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rf_msoa_matrix[ , <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colSums</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rf_msoa_matrix)) <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>
<span id="cb110-6"></span>
<span id="cb110-7"></span>
<span id="cb110-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#then we drop out any values that directly predict our error.</span></span>
<span id="cb110-9"></span>
<span id="cb110-10">drop<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;">"burglaryActual"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryError"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryPercentError"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryPredicted"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyActual"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyPredicted"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyError"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyPercentError"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDBurglaryShifted"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDRobberyShifted"</span>)</span>
<span id="cb110-11"></span>
<span id="cb110-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#remove out selected columns</span></span>
<span id="cb110-13">data<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> clean_rf_matrix[,<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;">names</span>(clean_rf_matrix) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> drop)]</span>
<span id="cb110-14"></span>
<span id="cb110-15"></span>
<span id="cb110-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#automatically remove white space and make names r compatbiel</span></span>
<span id="cb110-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(clean_rf_matrix)<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;">make.names</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(clean_rf_matrix),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unique =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb110-18"></span>
<span id="cb110-19">drop<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;">"burglaryActual"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryError"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyActual"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyError"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDBurglary"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RPDRobbery"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyActualShifted"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyPredictedShifted"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryActualShifted"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryPredictedShifted"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryPredicted"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"burglaryPercentError"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyPredicted"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"robberyPercentError"</span>)</span>
<span id="cb110-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#drop&lt;- c("burglaryPercentError","burglaryPredicted","robberyPredicted","robberyPercentError")</span></span>
<span id="cb110-21"></span>
<span id="cb110-22">data<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> clean_rf_matrix[,<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;">names</span>(clean_rf_matrix) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> drop)]</span>
<span id="cb110-23"></span>
<span id="cb110-24"></span>
<span id="cb110-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(data)<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;">make.names</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(data),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unique =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb110-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(data)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table>
<thead>
<tr>
<th style="text-align:right;">
UsualRes
</th>
<th style="text-align:right;">
HholdRes
</th>
<th style="text-align:right;">
ComEstRes
</th>
<th style="text-align:right;">
PopDen
</th>
<th style="text-align:right;">
Hholds
</th>
<th style="text-align:right;">
AvHholdSz
</th>
<th style="text-align:right;">
total_robberies
</th>
<th style="text-align:right;">
total_burglaries
</th>
<th style="text-align:right;">
RPDRobberyShifted
</th>
<th style="text-align:right;">
RPDburglaryShifted
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..All.Ages
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..0.15
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..16.29
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..30.44
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..45.64
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..65.
</th>
<th style="text-align:right;">
Age.Structure..2011.Census..Working.age
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2002
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2003
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2004
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2005
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2006
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2007
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2008
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2009
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2010
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2011
</th>
<th style="text-align:right;">
Mid.year.Estimate.totals.All.Ages.2012
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age…0.to.14
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age…15.64
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age…65.
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.0.4
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.5.9
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.10.14
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.15.19
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.20.24
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.25.29
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.30.34
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.35.39
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.40.44
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.45.49
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.50.54
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.55.59
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.60.64
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.65.69
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.70.74
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.75.79
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.80.84
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.85.89
</th>
<th style="text-align:right;">
Mid.year.Estimates.2012..by.age.90.
</th>
<th style="text-align:right;">
Households..2011..All.Households
</th>
<th style="text-align:right;">
Household.Composition..2011..Numbers.Couple.household.with.dependent.children
</th>
<th style="text-align:right;">
Household.Composition..2011..Numbers.Couple.household.without.dependent.children
</th>
<th style="text-align:right;">
Household.Composition..2011..Numbers.Lone.parent.household
</th>
<th style="text-align:right;">
Household.Composition..2011..Numbers.One.person.household
</th>
<th style="text-align:right;">
Household.Composition..2011..Numbers.Other.household.Types
</th>
<th style="text-align:right;">
Household.Composition..2011..Percentages.Couple.household.with.dependent.children
</th>
<th style="text-align:right;">
Household.Composition..2011..Percentages.Couple.household.without.dependent.children
</th>
<th style="text-align:right;">
Household.Composition..2011..Percentages.Lone.parent.household
</th>
<th style="text-align:right;">
Household.Composition..2011..Percentages.One.person.household
</th>
<th style="text-align:right;">
Household.Composition..2011..Percentages.Other.household.Types
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..White
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Mixed.multiple.ethnic.groups
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Asian.Asian.British
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Black.African.Caribbean.Black.British
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Other.ethnic.group
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..BAME
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..White….
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Mixed.multiple.ethnic.groups….
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Asian.Asian.British….
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Black.African.Caribbean.Black.British….
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..Other.ethnic.group….
</th>
<th style="text-align:right;">
Ethnic.Group..2011.Census..BAME….
</th>
<th style="text-align:right;">
Country.of.Birth..2011..United.Kingdom
</th>
<th style="text-align:right;">
Country.of.Birth..2011..Not.United.Kingdom
</th>
<th style="text-align:right;">
Country.of.Birth..2011..United.Kingdom….
</th>
<th style="text-align:right;">
Country.of.Birth..2011..Not.United.Kingdom….
</th>
<th style="text-align:right;">
Household.Language..2011..At.least.one.person.aged.16.and.over.in.household.has.English.as.a.main.language
</th>
<th style="text-align:right;">
Household.Language..2011..No.people.in.household.have.English.as.a.main.language
</th>
<th style="text-align:right;">
Household.Language..2011….of.people.aged.16.and.over.in.household.have.English.as.a.main.language
</th>
<th style="text-align:right;">
Household.Language..2011….of.households.where.no.people.in.household.have.English.as.a.main.language
</th>
<th style="text-align:right;">
Religion..2011..Christian
</th>
<th style="text-align:right;">
Religion..2011..Buddhist
</th>
<th style="text-align:right;">
Religion..2011..Hindu
</th>
<th style="text-align:right;">
Religion..2011..Jewish
</th>
<th style="text-align:right;">
Religion..2011..Muslim
</th>
<th style="text-align:right;">
Religion..2011..Sikh
</th>
<th style="text-align:right;">
Religion..2011..Other.religion
</th>
<th style="text-align:right;">
Religion..2011..No.religion
</th>
<th style="text-align:right;">
Religion..2011..Religion.not.stated
</th>
<th style="text-align:right;">
Religion..2011..Christian….
</th>
<th style="text-align:right;">
Religion..2011..Buddhist….
</th>
<th style="text-align:right;">
Religion..2011..Hindu….
</th>
<th style="text-align:right;">
Religion..2011..Jewish….
</th>
<th style="text-align:right;">
Religion..2011..Muslim….
</th>
<th style="text-align:right;">
Religion..2011..Sikh….
</th>
<th style="text-align:right;">
Religion..2011..Other.religion….
</th>
<th style="text-align:right;">
Religion..2011..No.religion….
</th>
<th style="text-align:right;">
Religion..2011..Religion.not.stated….
</th>
<th style="text-align:right;">
Tenure..2011..Owned..Owned.outright
</th>
<th style="text-align:right;">
Tenure..2011..Owned..Owned.with.a.mortgage.or.loan
</th>
<th style="text-align:right;">
Tenure..2011..Social.rented
</th>
<th style="text-align:right;">
Tenure..2011..Private.rented
</th>
<th style="text-align:right;">
Tenure..2011..Owned..Owned.outright….
</th>
<th style="text-align:right;">
Tenure..2011..Owned..Owned.with.a.mortgage.or.loan….
</th>
<th style="text-align:right;">
Tenure..2011..Social.rented….
</th>
<th style="text-align:right;">
Tenure..2011..Private.rented….
</th>
<th style="text-align:right;">
Dwelling.type..2011..Household.spaces.with.at.least.one.usual.resident
</th>
<th style="text-align:right;">
Dwelling.type..2011..Household.spaces.with.no.usual.residents
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Detached
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Semi.detached
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Terraced..including.end.terrace.
</th>
<th style="text-align:right;">
Dwelling.type..2011..Flat..maisonette.or.apartment
</th>
<th style="text-align:right;">
Dwelling.type..2011..Household.spaces.with.at.least.one.usual.resident….
</th>
<th style="text-align:right;">
Dwelling.type..2011..Household.spaces.with.no.usual.residents….
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Detached….
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Semi.detached….
</th>
<th style="text-align:right;">
Dwelling.type..2011..Whole.house.or.bungalow..Terraced..including.end.terrace…..
</th>
<th style="text-align:right;">
Dwelling.type..2011..Flat..maisonette.or.apartment….
</th>
<th style="text-align:right;">
Land.Area.Hectares
</th>
<th style="text-align:right;">
Population.Density.Persons.per.hectare..2012.
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2005
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2006
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2007
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2008
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2009
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2010
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2011
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2012
</th>
<th style="text-align:right;">
House.Prices.Median.House.Price…..2013..p.
</th>
<th style="text-align:right;">
House.Prices.Sales.2005
</th>
<th style="text-align:right;">
House.Prices.Sales.2006
</th>
<th style="text-align:right;">
House.Prices.Sales.2007
</th>
<th style="text-align:right;">
House.Prices.Sales.2008
</th>
<th style="text-align:right;">
House.Prices.Sales.2009
</th>
<th style="text-align:right;">
House.Prices.Sales.2010
</th>
<th style="text-align:right;">
House.Prices.Sales.2011…129
</th>
<th style="text-align:right;">
House.Prices.Sales.2011…130
</th>
<th style="text-align:right;">
House.Prices.Sales.2013.p.
</th>
<th style="text-align:right;">
Qualifications..2011.Census..No.qualifications
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Level.1.qualifications
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Level.2.qualifications
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Apprenticeship
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Level.3.qualifications
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Level.4.qualifications.and.above
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Highest.level.of.qualification..Other.qualifications
</th>
<th style="text-align:right;">
Qualifications..2011.Census..Schoolchildren.and.full.time.students..Age.18.and.over
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Economically.active..Total
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Economically.active..Unemployed
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Economically.inactive..Total
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Economically.active..
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Unemployment.Rate
</th>
<th style="text-align:right;">
Economic.Activity..2011.Census..Economically.inactive..
</th>
<th style="text-align:right;">
Adults.in.Employment..2011.Census..No.adults.in.employment.in.household..With.dependent.children
</th>
<th style="text-align:right;">
Adults.in.Employment..2011.Census….of.households.with.no.adults.in.employment..With.dependent.children
</th>
<th style="text-align:right;">
Household.Income.Estimates..2011.12..Total.Mean.Annual.Household.Income….
</th>
<th style="text-align:right;">
Household.Income.Estimates..2011.12..Total.Median.Annual.Household.Income….
</th>
<th style="text-align:right;">
Income.Deprivation..2010….living.in.income.deprived.households.reliant.on.means.tested.benefit
</th>
<th style="text-align:right;">
Income.Deprivation..2010….of.people.aged.over.60.who.live.in.pension.credit.households
</th>
<th style="text-align:right;">
Lone.Parents..2011.Census..All.lone.parent.housholds.with.dependent.children
</th>
<th style="text-align:right;">
Lone.Parents..2011.Census..Lone.parents.not.in.employment
</th>
<th style="text-align:right;">
Lone.Parents..2011.Census..Lone.parent.not.in.employment..
</th>
<th style="text-align:right;">
Central.Heating..2011.Census..Households.with.central.heating….
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.limited.a.lot
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.limited.a.little
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.not.limited
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.limited.a.lot….
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.limited.a.little….
</th>
<th style="text-align:right;">
Health..2011.Census..Day.to.day.activities.not.limited….
</th>
<th style="text-align:right;">
Health..2011.Census..Very.good.health
</th>
<th style="text-align:right;">
Health..2011.Census..Good.health
</th>
<th style="text-align:right;">
Health..2011.Census..Fair.health
</th>
<th style="text-align:right;">
Health..2011.Census..Bad.health
</th>
<th style="text-align:right;">
Health..2011.Census..Very.bad.health
</th>
<th style="text-align:right;">
Health..2011.Census..Very.good.health….
</th>
<th style="text-align:right;">
Health..2011.Census..Good.health….
</th>
<th style="text-align:right;">
Health..2011.Census..Fair.health….
</th>
<th style="text-align:right;">
Health..2011.Census..Bad.health….
</th>
<th style="text-align:right;">
Health..2011.Census..Very.bad.health….
</th>
<th style="text-align:right;">
Low.Birth.Weight.Births..2007.2011..Low.Birth.Weight.Births….
</th>
<th style="text-align:right;">
Low.Birth.Weight.Births..2007.2011..LCL…Lower.confidence.limit
</th>
<th style="text-align:right;">
Low.Birth.Weight.Births..2007.2011..UCL…Upper.confidence.limit
</th>
<th style="text-align:right;">
Obesity.Percentage.of.the.population.aged.16..with.a.BMI.of.30…modelled.estimate..2006.2008
</th>
<th style="text-align:right;">
Incidence.of.Cancer.All
</th>
<th style="text-align:right;">
Incidence.of.Cancer.Breast.Cancer
</th>
<th style="text-align:right;">
Life.Expectancy.Males
</th>
<th style="text-align:right;">
Life.Expectancy.Females
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..No.cars.or.vans.in.household
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..1.car.or.van.in.household
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..2.cars.or.vans.in.household
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..3.cars.or.vans.in.household
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..4.or.more.cars.or.vans.in.household
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..Sum.of.all.cars.or.vans.in.the.area
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..No.cars.or.vans.in.household….
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..1.car.or.van.in.household….
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..2.cars.or.vans.in.household….
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..3.cars.or.vans.in.household….
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..4.or.more.cars.or.vans.in.household….
</th>
<th style="text-align:right;">
Car.or.van.availability..2011.Census..Cars.per.household
</th>
<th style="text-align:right;">
Road.Casualties.2010.Fatal
</th>
<th style="text-align:right;">
Road.Casualties.2010.Serious
</th>
<th style="text-align:right;">
Road.Casualties.2010.Slight
</th>
<th style="text-align:right;">
Road.Casualties.2010.2010.Total
</th>
<th style="text-align:right;">
Road.Casualties.2011.Fatal
</th>
<th style="text-align:right;">
Road.Casualties.2011.Serious
</th>
<th style="text-align:right;">
Road.Casualties.2011.Slight
</th>
<th style="text-align:right;">
Road.Casualties.2011.2011.Total
</th>
<th style="text-align:right;">
Road.Casualties.2012.Fatal
</th>
<th style="text-align:right;">
Road.Casualties.2012.Serious
</th>
<th style="text-align:right;">
Road.Casualties.2012.Slight
</th>
<th style="text-align:right;">
Road.Casualties.2012.2012.Total
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
7375
</td>
<td style="text-align:right;">
7187
</td>
<td style="text-align:right;">
188
</td>
<td style="text-align:right;">
25.5
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
1.6
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
0.0601204
</td>
<td style="text-align:right;">
-0.1219796
</td>
<td style="text-align:right;">
7375
</td>
<td style="text-align:right;">
620
</td>
<td style="text-align:right;">
1665
</td>
<td style="text-align:right;">
2045
</td>
<td style="text-align:right;">
2010
</td>
<td style="text-align:right;">
1035
</td>
<td style="text-align:right;">
5720
</td>
<td style="text-align:right;">
7280
</td>
<td style="text-align:right;">
7115
</td>
<td style="text-align:right;">
7118
</td>
<td style="text-align:right;">
7131
</td>
<td style="text-align:right;">
7254
</td>
<td style="text-align:right;">
7607
</td>
<td style="text-align:right;">
7429
</td>
<td style="text-align:right;">
7472
</td>
<td style="text-align:right;">
7338
</td>
<td style="text-align:right;">
7412
</td>
<td style="text-align:right;">
7604
</td>
<td style="text-align:right;">
8.771699
</td>
<td style="text-align:right;">
76.68332
</td>
<td style="text-align:right;">
14.54498
</td>
<td style="text-align:right;">
297
</td>
<td style="text-align:right;">
205
</td>
<td style="text-align:right;">
165
</td>
<td style="text-align:right;">
231
</td>
<td style="text-align:right;">
495
</td>
<td style="text-align:right;">
949
</td>
<td style="text-align:right;">
826
</td>
<td style="text-align:right;">
622
</td>
<td style="text-align:right;">
663
</td>
<td style="text-align:right;">
598
</td>
<td style="text-align:right;">
504
</td>
<td style="text-align:right;">
470
</td>
<td style="text-align:right;">
473
</td>
<td style="text-align:right;">
363
</td>
<td style="text-align:right;">
263
</td>
<td style="text-align:right;">
192
</td>
<td style="text-align:right;">
155
</td>
<td style="text-align:right;">
86
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
306
</td>
<td style="text-align:right;">
927
</td>
<td style="text-align:right;">
153
</td>
<td style="text-align:right;">
2472
</td>
<td style="text-align:right;">
527
</td>
<td style="text-align:right;">
6.978335
</td>
<td style="text-align:right;">
21.14025
</td>
<td style="text-align:right;">
3.489168
</td>
<td style="text-align:right;">
56.37400
</td>
<td style="text-align:right;">
12.01824
</td>
<td style="text-align:right;">
5799
</td>
<td style="text-align:right;">
289
</td>
<td style="text-align:right;">
940
</td>
<td style="text-align:right;">
193
</td>
<td style="text-align:right;">
154
</td>
<td style="text-align:right;">
1576
</td>
<td style="text-align:right;">
78.63051
</td>
<td style="text-align:right;">
3.918644
</td>
<td style="text-align:right;">
12.745763
</td>
<td style="text-align:right;">
2.616949
</td>
<td style="text-align:right;">
2.0881356
</td>
<td style="text-align:right;">
21.36949
</td>
<td style="text-align:right;">
4670
</td>
<td style="text-align:right;">
2705
</td>
<td style="text-align:right;">
63.32203
</td>
<td style="text-align:right;">
36.67797
</td>
<td style="text-align:right;">
3825
</td>
<td style="text-align:right;">
560
</td>
<td style="text-align:right;">
87.22919
</td>
<td style="text-align:right;">
12.770810
</td>
<td style="text-align:right;">
3344
</td>
<td style="text-align:right;">
92
</td>
<td style="text-align:right;">
145
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
409
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
2522
</td>
<td style="text-align:right;">
651
</td>
<td style="text-align:right;">
45.3
</td>
<td style="text-align:right;">
1.2
</td>
<td style="text-align:right;">
2.0
</td>
<td style="text-align:right;">
2.3
</td>
<td style="text-align:right;">
5.5
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
34.2
</td>
<td style="text-align:right;">
8.8
</td>
<td style="text-align:right;">
1093
</td>
<td style="text-align:right;">
762
</td>
<td style="text-align:right;">
725
</td>
<td style="text-align:right;">
1573
</td>
<td style="text-align:right;">
24.9
</td>
<td style="text-align:right;">
17.4
</td>
<td style="text-align:right;">
16.5
</td>
<td style="text-align:right;">
35.9
</td>
<td style="text-align:right;">
4385
</td>
<td style="text-align:right;">
1145
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
12
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
5416
</td>
<td style="text-align:right;">
79.3
</td>
<td style="text-align:right;">
20.7
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
1.4
</td>
<td style="text-align:right;">
98.0
</td>
<td style="text-align:right;">
289.78
</td>
<td style="text-align:right;">
26.24060
</td>
<td style="text-align:right;">
310000
</td>
<td style="text-align:right;">
341000
</td>
<td style="text-align:right;">
412500
</td>
<td style="text-align:right;">
365000.0
</td>
<td style="text-align:right;">
410000
</td>
<td style="text-align:right;">
450000
</td>
<td style="text-align:right;">
465000
</td>
<td style="text-align:right;">
485000
</td>
<td style="text-align:right;">
595000
</td>
<td style="text-align:right;">
303
</td>
<td style="text-align:right;">
295
</td>
<td style="text-align:right;">
268
</td>
<td style="text-align:right;">
141
</td>
<td style="text-align:right;">
157
</td>
<td style="text-align:right;">
235
</td>
<td style="text-align:right;">
256
</td>
<td style="text-align:right;">
195
</td>
<td style="text-align:right;">
353
</td>
<td style="text-align:right;">
454
</td>
<td style="text-align:right;">
291
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
484
</td>
<td style="text-align:right;">
4618
</td>
<td style="text-align:right;">
416
</td>
<td style="text-align:right;">
422
</td>
<td style="text-align:right;">
4972
</td>
<td style="text-align:right;">
187
</td>
<td style="text-align:right;">
1335
</td>
<td style="text-align:right;">
78.83304
</td>
<td style="text-align:right;">
3.761062
</td>
<td style="text-align:right;">
21.16696
</td>
<td style="text-align:right;">
38
</td>
<td style="text-align:right;">
0.9
</td>
<td style="text-align:right;">
59728.48
</td>
<td style="text-align:right;">
46788.30
</td>
<td style="text-align:right;">
5.2
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
91
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
24.2
</td>
<td style="text-align:right;">
95.7
</td>
<td style="text-align:right;">
328
</td>
<td style="text-align:right;">
520
</td>
<td style="text-align:right;">
6527
</td>
<td style="text-align:right;">
4.447458
</td>
<td style="text-align:right;">
7.050847
</td>
<td style="text-align:right;">
88.50169
</td>
<td style="text-align:right;">
4112
</td>
<td style="text-align:right;">
2374
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
190
</td>
<td style="text-align:right;">
56
</td>
<td style="text-align:right;">
55.75593
</td>
<td style="text-align:right;">
32.18983
</td>
<td style="text-align:right;">
8.718644
</td>
<td style="text-align:right;">
2.576271
</td>
<td style="text-align:right;">
0.759322
</td>
<td style="text-align:right;">
4.2
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
7.1
</td>
<td style="text-align:right;">
13.7
</td>
<td style="text-align:right;">
76.8
</td>
<td style="text-align:right;">
90.9
</td>
<td style="text-align:right;">
83.6
</td>
<td style="text-align:right;">
88.4
</td>
<td style="text-align:right;">
3043
</td>
<td style="text-align:right;">
1100
</td>
<td style="text-align:right;">
173
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
1692
</td>
<td style="text-align:right;">
69.4
</td>
<td style="text-align:right;">
25.1
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
1.2
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
0.3858609
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
334
</td>
<td style="text-align:right;">
374
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
46
</td>
<td style="text-align:right;">
359
</td>
<td style="text-align:right;">
405
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
361
</td>
<td style="text-align:right;">
414
</td>
</tr>
<tr>
<td style="text-align:right;">
6775
</td>
<td style="text-align:right;">
6724
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
31.3
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
53
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
-0.0223392
</td>
<td style="text-align:right;">
0.3489691
</td>
<td style="text-align:right;">
6775
</td>
<td style="text-align:right;">
1751
</td>
<td style="text-align:right;">
1277
</td>
<td style="text-align:right;">
1388
</td>
<td style="text-align:right;">
1258
</td>
<td style="text-align:right;">
1101
</td>
<td style="text-align:right;">
3923
</td>
<td style="text-align:right;">
6333
</td>
<td style="text-align:right;">
6312
</td>
<td style="text-align:right;">
6329
</td>
<td style="text-align:right;">
6341
</td>
<td style="text-align:right;">
6330
</td>
<td style="text-align:right;">
6323
</td>
<td style="text-align:right;">
6369
</td>
<td style="text-align:right;">
6570
</td>
<td style="text-align:right;">
6636
</td>
<td style="text-align:right;">
6783
</td>
<td style="text-align:right;">
6853
</td>
<td style="text-align:right;">
25.113089
</td>
<td style="text-align:right;">
58.73340
</td>
<td style="text-align:right;">
16.15351
</td>
<td style="text-align:right;">
652
</td>
<td style="text-align:right;">
607
</td>
<td style="text-align:right;">
462
</td>
<td style="text-align:right;">
458
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
468
</td>
<td style="text-align:right;">
466
</td>
<td style="text-align:right;">
466
</td>
<td style="text-align:right;">
461
</td>
<td style="text-align:right;">
450
</td>
<td style="text-align:right;">
347
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
256
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
206
</td>
<td style="text-align:right;">
215
</td>
<td style="text-align:right;">
201
</td>
<td style="text-align:right;">
137
</td>
<td style="text-align:right;">
94
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
491
</td>
<td style="text-align:right;">
366
</td>
<td style="text-align:right;">
597
</td>
<td style="text-align:right;">
814
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
18.098046
</td>
<td style="text-align:right;">
13.49060
</td>
<td style="text-align:right;">
22.005160
</td>
<td style="text-align:right;">
30.00369
</td>
<td style="text-align:right;">
16.40251
</td>
<td style="text-align:right;">
4403
</td>
<td style="text-align:right;">
330
</td>
<td style="text-align:right;">
820
</td>
<td style="text-align:right;">
1133
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
2372
</td>
<td style="text-align:right;">
64.98893
</td>
<td style="text-align:right;">
4.870849
</td>
<td style="text-align:right;">
12.103321
</td>
<td style="text-align:right;">
16.723247
</td>
<td style="text-align:right;">
1.3136531
</td>
<td style="text-align:right;">
35.01107
</td>
<td style="text-align:right;">
5159
</td>
<td style="text-align:right;">
1616
</td>
<td style="text-align:right;">
76.14760
</td>
<td style="text-align:right;">
23.85240
</td>
<td style="text-align:right;">
2459
</td>
<td style="text-align:right;">
254
</td>
<td style="text-align:right;">
90.63767
</td>
<td style="text-align:right;">
9.362329
</td>
<td style="text-align:right;">
3975
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
174
</td>
<td style="text-align:right;">
27
</td>
<td style="text-align:right;">
591
</td>
<td style="text-align:right;">
122
</td>
<td style="text-align:right;">
16
</td>
<td style="text-align:right;">
1417
</td>
<td style="text-align:right;">
434
</td>
<td style="text-align:right;">
58.7
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
8.7
</td>
<td style="text-align:right;">
1.8
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
20.9
</td>
<td style="text-align:right;">
6.4
</td>
<td style="text-align:right;">
596
</td>
<td style="text-align:right;">
663
</td>
<td style="text-align:right;">
1133
</td>
<td style="text-align:right;">
269
</td>
<td style="text-align:right;">
22.0
</td>
<td style="text-align:right;">
24.4
</td>
<td style="text-align:right;">
41.8
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
2713
</td>
<td style="text-align:right;">
82
</td>
<td style="text-align:right;">
99
</td>
<td style="text-align:right;">
744
</td>
<td style="text-align:right;">
865
</td>
<td style="text-align:right;">
1087
</td>
<td style="text-align:right;">
97.1
</td>
<td style="text-align:right;">
2.9
</td>
<td style="text-align:right;">
3.5
</td>
<td style="text-align:right;">
26.6
</td>
<td style="text-align:right;">
30.9
</td>
<td style="text-align:right;">
38.9
</td>
<td style="text-align:right;">
216.15
</td>
<td style="text-align:right;">
31.70483
</td>
<td style="text-align:right;">
168500
</td>
<td style="text-align:right;">
180000
</td>
<td style="text-align:right;">
187500
</td>
<td style="text-align:right;">
197500.0
</td>
<td style="text-align:right;">
190000
</td>
<td style="text-align:right;">
173000
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
182250
</td>
<td style="text-align:right;">
190000
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
68
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
51
</td>
<td style="text-align:right;">
42
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
1623
</td>
<td style="text-align:right;">
789
</td>
<td style="text-align:right;">
706
</td>
<td style="text-align:right;">
118
</td>
<td style="text-align:right;">
479
</td>
<td style="text-align:right;">
914
</td>
<td style="text-align:right;">
395
</td>
<td style="text-align:right;">
272
</td>
<td style="text-align:right;">
2847
</td>
<td style="text-align:right;">
335
</td>
<td style="text-align:right;">
1513
</td>
<td style="text-align:right;">
65.29817
</td>
<td style="text-align:right;">
11.766772
</td>
<td style="text-align:right;">
34.70183
</td>
<td style="text-align:right;">
319
</td>
<td style="text-align:right;">
11.8
</td>
<td style="text-align:right;">
31788.19
</td>
<td style="text-align:right;">
27058.70
</td>
<td style="text-align:right;">
31.0
</td>
<td style="text-align:right;">
27.5
</td>
<td style="text-align:right;">
445
</td>
<td style="text-align:right;">
249
</td>
<td style="text-align:right;">
56.0
</td>
<td style="text-align:right;">
97.5
</td>
<td style="text-align:right;">
707
</td>
<td style="text-align:right;">
678
</td>
<td style="text-align:right;">
5390
</td>
<td style="text-align:right;">
10.435424
</td>
<td style="text-align:right;">
10.007380
</td>
<td style="text-align:right;">
79.55720
</td>
<td style="text-align:right;">
2933
</td>
<td style="text-align:right;">
2288
</td>
<td style="text-align:right;">
1059
</td>
<td style="text-align:right;">
389
</td>
<td style="text-align:right;">
106
</td>
<td style="text-align:right;">
43.29151
</td>
<td style="text-align:right;">
33.77122
</td>
<td style="text-align:right;">
15.630996
</td>
<td style="text-align:right;">
5.741697
</td>
<td style="text-align:right;">
1.564576
</td>
<td style="text-align:right;">
10.6
</td>
<td style="text-align:right;">
8.4
</td>
<td style="text-align:right;">
13.3
</td>
<td style="text-align:right;">
29.8
</td>
<td style="text-align:right;">
100.7
</td>
<td style="text-align:right;">
93.3
</td>
<td style="text-align:right;">
78.0
</td>
<td style="text-align:right;">
80.1
</td>
<td style="text-align:right;">
1020
</td>
<td style="text-align:right;">
1186
</td>
<td style="text-align:right;">
424
</td>
<td style="text-align:right;">
66
</td>
<td style="text-align:right;">
17
</td>
<td style="text-align:right;">
2305
</td>
<td style="text-align:right;">
37.6
</td>
<td style="text-align:right;">
43.7
</td>
<td style="text-align:right;">
15.6
</td>
<td style="text-align:right;">
2.4
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.8496130
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
16
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
15
</td>
<td style="text-align:right;">
16
</td>
</tr>
<tr>
<td style="text-align:right;">
10045
</td>
<td style="text-align:right;">
10033
</td>
<td style="text-align:right;">
12
</td>
<td style="text-align:right;">
46.9
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
124
</td>
<td style="text-align:right;">
239
</td>
<td style="text-align:right;">
0.0526430
</td>
<td style="text-align:right;">
-0.0218569
</td>
<td style="text-align:right;">
10045
</td>
<td style="text-align:right;">
2247
</td>
<td style="text-align:right;">
1959
</td>
<td style="text-align:right;">
2300
</td>
<td style="text-align:right;">
2259
</td>
<td style="text-align:right;">
1280
</td>
<td style="text-align:right;">
6518
</td>
<td style="text-align:right;">
9236
</td>
<td style="text-align:right;">
9252
</td>
<td style="text-align:right;">
9155
</td>
<td style="text-align:right;">
9072
</td>
<td style="text-align:right;">
9144
</td>
<td style="text-align:right;">
9227
</td>
<td style="text-align:right;">
9564
</td>
<td style="text-align:right;">
9914
</td>
<td style="text-align:right;">
10042
</td>
<td style="text-align:right;">
10088
</td>
<td style="text-align:right;">
10218
</td>
<td style="text-align:right;">
21.442552
</td>
<td style="text-align:right;">
65.81523
</td>
<td style="text-align:right;">
12.74222
</td>
<td style="text-align:right;">
849
</td>
<td style="text-align:right;">
739
</td>
<td style="text-align:right;">
603
</td>
<td style="text-align:right;">
615
</td>
<td style="text-align:right;">
686
</td>
<td style="text-align:right;">
804
</td>
<td style="text-align:right;">
818
</td>
<td style="text-align:right;">
743
</td>
<td style="text-align:right;">
770
</td>
<td style="text-align:right;">
713
</td>
<td style="text-align:right;">
624
</td>
<td style="text-align:right;">
526
</td>
<td style="text-align:right;">
426
</td>
<td style="text-align:right;">
372
</td>
<td style="text-align:right;">
277
</td>
<td style="text-align:right;">
258
</td>
<td style="text-align:right;">
198
</td>
<td style="text-align:right;">
124
</td>
<td style="text-align:right;">
73
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
776
</td>
<td style="text-align:right;">
730
</td>
<td style="text-align:right;">
589
</td>
<td style="text-align:right;">
1039
</td>
<td style="text-align:right;">
700
</td>
<td style="text-align:right;">
20.239958
</td>
<td style="text-align:right;">
19.04017
</td>
<td style="text-align:right;">
15.362546
</td>
<td style="text-align:right;">
27.09963
</td>
<td style="text-align:right;">
18.25769
</td>
<td style="text-align:right;">
5486
</td>
<td style="text-align:right;">
433
</td>
<td style="text-align:right;">
2284
</td>
<td style="text-align:right;">
1618
</td>
<td style="text-align:right;">
224
</td>
<td style="text-align:right;">
4559
</td>
<td style="text-align:right;">
54.61424
</td>
<td style="text-align:right;">
4.310602
</td>
<td style="text-align:right;">
22.737680
</td>
<td style="text-align:right;">
16.107516
</td>
<td style="text-align:right;">
2.2299652
</td>
<td style="text-align:right;">
45.38576
</td>
<td style="text-align:right;">
7193
</td>
<td style="text-align:right;">
2852
</td>
<td style="text-align:right;">
71.60777
</td>
<td style="text-align:right;">
28.39223
</td>
<td style="text-align:right;">
3431
</td>
<td style="text-align:right;">
403
</td>
<td style="text-align:right;">
89.48878
</td>
<td style="text-align:right;">
10.511215
</td>
<td style="text-align:right;">
5475
</td>
<td style="text-align:right;">
46
</td>
<td style="text-align:right;">
476
</td>
<td style="text-align:right;">
42
</td>
<td style="text-align:right;">
1351
</td>
<td style="text-align:right;">
430
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
1514
</td>
<td style="text-align:right;">
677
</td>
<td style="text-align:right;">
54.5
</td>
<td style="text-align:right;">
0.5
</td>
<td style="text-align:right;">
4.7
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
13.4
</td>
<td style="text-align:right;">
4.3
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
15.1
</td>
<td style="text-align:right;">
6.7
</td>
<td style="text-align:right;">
1028
</td>
<td style="text-align:right;">
1473
</td>
<td style="text-align:right;">
446
</td>
<td style="text-align:right;">
830
</td>
<td style="text-align:right;">
26.8
</td>
<td style="text-align:right;">
38.4
</td>
<td style="text-align:right;">
11.6
</td>
<td style="text-align:right;">
21.6
</td>
<td style="text-align:right;">
3834
</td>
<td style="text-align:right;">
110
</td>
<td style="text-align:right;">
161
</td>
<td style="text-align:right;">
936
</td>
<td style="text-align:right;">
1591
</td>
<td style="text-align:right;">
1256
</td>
<td style="text-align:right;">
97.2
</td>
<td style="text-align:right;">
2.8
</td>
<td style="text-align:right;">
4.1
</td>
<td style="text-align:right;">
23.7
</td>
<td style="text-align:right;">
40.3
</td>
<td style="text-align:right;">
31.8
</td>
<td style="text-align:right;">
214.15
</td>
<td style="text-align:right;">
47.71422
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
197750
</td>
<td style="text-align:right;">
220000
</td>
<td style="text-align:right;">
225000.0
</td>
<td style="text-align:right;">
188500
</td>
<td style="text-align:right;">
215000
</td>
<td style="text-align:right;">
200000
</td>
<td style="text-align:right;">
205500
</td>
<td style="text-align:right;">
237000
</td>
<td style="text-align:right;">
203
</td>
<td style="text-align:right;">
232
</td>
<td style="text-align:right;">
295
</td>
<td style="text-align:right;">
100
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
97
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
114
</td>
<td style="text-align:right;">
98
</td>
<td style="text-align:right;">
1778
</td>
<td style="text-align:right;">
1210
</td>
<td style="text-align:right;">
1236
</td>
<td style="text-align:right;">
169
</td>
<td style="text-align:right;">
847
</td>
<td style="text-align:right;">
1829
</td>
<td style="text-align:right;">
729
</td>
<td style="text-align:right;">
442
</td>
<td style="text-align:right;">
5038
</td>
<td style="text-align:right;">
459
</td>
<td style="text-align:right;">
2111
</td>
<td style="text-align:right;">
70.47139
</td>
<td style="text-align:right;">
9.110758
</td>
<td style="text-align:right;">
29.52861
</td>
<td style="text-align:right;">
268
</td>
<td style="text-align:right;">
7.0
</td>
<td style="text-align:right;">
43356.93
</td>
<td style="text-align:right;">
36834.53
</td>
<td style="text-align:right;">
18.9
</td>
<td style="text-align:right;">
21.2
</td>
<td style="text-align:right;">
408
</td>
<td style="text-align:right;">
199
</td>
<td style="text-align:right;">
48.8
</td>
<td style="text-align:right;">
96.5
</td>
<td style="text-align:right;">
792
</td>
<td style="text-align:right;">
810
</td>
<td style="text-align:right;">
8443
</td>
<td style="text-align:right;">
7.884520
</td>
<td style="text-align:right;">
8.063713
</td>
<td style="text-align:right;">
84.05177
</td>
<td style="text-align:right;">
4566
</td>
<td style="text-align:right;">
3633
</td>
<td style="text-align:right;">
1325
</td>
<td style="text-align:right;">
406
</td>
<td style="text-align:right;">
115
</td>
<td style="text-align:right;">
45.45545
</td>
<td style="text-align:right;">
36.16725
</td>
<td style="text-align:right;">
13.190642
</td>
<td style="text-align:right;">
4.041812
</td>
<td style="text-align:right;">
1.144848
</td>
<td style="text-align:right;">
7.8
</td>
<td style="text-align:right;">
6.1
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
28.3
</td>
<td style="text-align:right;">
91.4
</td>
<td style="text-align:right;">
107.3
</td>
<td style="text-align:right;">
80.2
</td>
<td style="text-align:right;">
85.6
</td>
<td style="text-align:right;">
1196
</td>
<td style="text-align:right;">
1753
</td>
<td style="text-align:right;">
691
</td>
<td style="text-align:right;">
155
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
3766
</td>
<td style="text-align:right;">
31.2
</td>
<td style="text-align:right;">
45.7
</td>
<td style="text-align:right;">
18.0
</td>
<td style="text-align:right;">
4.0
</td>
<td style="text-align:right;">
1.0
</td>
<td style="text-align:right;">
0.9822640
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
37
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:right;">
40
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
47
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:right;">
6182
</td>
<td style="text-align:right;">
5937
</td>
<td style="text-align:right;">
245
</td>
<td style="text-align:right;">
24.8
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
30
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
0.0257532
</td>
<td style="text-align:right;">
0.1381492
</td>
<td style="text-align:right;">
6182
</td>
<td style="text-align:right;">
1196
</td>
<td style="text-align:right;">
1277
</td>
<td style="text-align:right;">
1154
</td>
<td style="text-align:right;">
1543
</td>
<td style="text-align:right;">
1012
</td>
<td style="text-align:right;">
3974
</td>
<td style="text-align:right;">
6208
</td>
<td style="text-align:right;">
6159
</td>
<td style="text-align:right;">
6163
</td>
<td style="text-align:right;">
6152
</td>
<td style="text-align:right;">
5997
</td>
<td style="text-align:right;">
6005
</td>
<td style="text-align:right;">
6084
</td>
<td style="text-align:right;">
6268
</td>
<td style="text-align:right;">
6237
</td>
<td style="text-align:right;">
6185
</td>
<td style="text-align:right;">
6308
</td>
<td style="text-align:right;">
18.246671
</td>
<td style="text-align:right;">
65.82118
</td>
<td style="text-align:right;">
15.93215
</td>
<td style="text-align:right;">
409
</td>
<td style="text-align:right;">
364
</td>
<td style="text-align:right;">
378
</td>
<td style="text-align:right;">
516
</td>
<td style="text-align:right;">
472
</td>
<td style="text-align:right;">
435
</td>
<td style="text-align:right;">
363
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
388
</td>
<td style="text-align:right;">
463
</td>
<td style="text-align:right;">
459
</td>
<td style="text-align:right;">
354
</td>
<td style="text-align:right;">
303
</td>
<td style="text-align:right;">
226
</td>
<td style="text-align:right;">
238
</td>
<td style="text-align:right;">
194
</td>
<td style="text-align:right;">
172
</td>
<td style="text-align:right;">
106
</td>
<td style="text-align:right;">
69
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
524
</td>
<td style="text-align:right;">
322
</td>
<td style="text-align:right;">
609
</td>
<td style="text-align:right;">
355
</td>
<td style="text-align:right;">
21.915444
</td>
<td style="text-align:right;">
22.60569
</td>
<td style="text-align:right;">
13.891286
</td>
<td style="text-align:right;">
26.27265
</td>
<td style="text-align:right;">
15.31493
</td>
<td style="text-align:right;">
5006
</td>
<td style="text-align:right;">
186
</td>
<td style="text-align:right;">
313
</td>
<td style="text-align:right;">
649
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
1176
</td>
<td style="text-align:right;">
80.97703
</td>
<td style="text-align:right;">
3.008735
</td>
<td style="text-align:right;">
5.063086
</td>
<td style="text-align:right;">
10.498221
</td>
<td style="text-align:right;">
0.4529279
</td>
<td style="text-align:right;">
19.02297
</td>
<td style="text-align:right;">
5292
</td>
<td style="text-align:right;">
890
</td>
<td style="text-align:right;">
85.60336
</td>
<td style="text-align:right;">
14.39664
</td>
<td style="text-align:right;">
2214
</td>
<td style="text-align:right;">
104
</td>
<td style="text-align:right;">
95.51337
</td>
<td style="text-align:right;">
4.486626
</td>
<td style="text-align:right;">
4070
</td>
<td style="text-align:right;">
21
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
23
</td>
<td style="text-align:right;">
234
</td>
<td style="text-align:right;">
10
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
1373
</td>
<td style="text-align:right;">
399
</td>
<td style="text-align:right;">
65.8
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
0.5
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
3.8
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
22.2
</td>
<td style="text-align:right;">
6.5
</td>
<td style="text-align:right;">
718
</td>
<td style="text-align:right;">
969
</td>
<td style="text-align:right;">
371
</td>
<td style="text-align:right;">
228
</td>
<td style="text-align:right;">
31.0
</td>
<td style="text-align:right;">
41.8
</td>
<td style="text-align:right;">
16.0
</td>
<td style="text-align:right;">
9.8
</td>
<td style="text-align:right;">
2318
</td>
<td style="text-align:right;">
45
</td>
<td style="text-align:right;">
92
</td>
<td style="text-align:right;">
858
</td>
<td style="text-align:right;">
1094
</td>
<td style="text-align:right;">
314
</td>
<td style="text-align:right;">
98.1
</td>
<td style="text-align:right;">
1.9
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
36.3
</td>
<td style="text-align:right;">
46.3
</td>
<td style="text-align:right;">
13.2
</td>
<td style="text-align:right;">
249.28
</td>
<td style="text-align:right;">
25.30488
</td>
<td style="text-align:right;">
181000
</td>
<td style="text-align:right;">
182000
</td>
<td style="text-align:right;">
212000
</td>
<td style="text-align:right;">
208997.5
</td>
<td style="text-align:right;">
182000
</td>
<td style="text-align:right;">
192000
</td>
<td style="text-align:right;">
193750
</td>
<td style="text-align:right;">
205000
</td>
<td style="text-align:right;">
210000
</td>
<td style="text-align:right;">
93
</td>
<td style="text-align:right;">
131
</td>
<td style="text-align:right;">
125
</td>
<td style="text-align:right;">
66
</td>
<td style="text-align:right;">
54
</td>
<td style="text-align:right;">
61
</td>
<td style="text-align:right;">
72
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
67
</td>
<td style="text-align:right;">
1502
</td>
<td style="text-align:right;">
800
</td>
<td style="text-align:right;">
825
</td>
<td style="text-align:right;">
163
</td>
<td style="text-align:right;">
539
</td>
<td style="text-align:right;">
891
</td>
<td style="text-align:right;">
266
</td>
<td style="text-align:right;">
215
</td>
<td style="text-align:right;">
3187
</td>
<td style="text-align:right;">
296
</td>
<td style="text-align:right;">
1251
</td>
<td style="text-align:right;">
71.81163
</td>
<td style="text-align:right;">
9.287731
</td>
<td style="text-align:right;">
28.18837
</td>
<td style="text-align:right;">
122
</td>
<td style="text-align:right;">
5.3
</td>
<td style="text-align:right;">
46701.44
</td>
<td style="text-align:right;">
39668.21
</td>
<td style="text-align:right;">
15.8
</td>
<td style="text-align:right;">
21.3
</td>
<td style="text-align:right;">
206
</td>
<td style="text-align:right;">
87
</td>
<td style="text-align:right;">
42.2
</td>
<td style="text-align:right;">
98.5
</td>
<td style="text-align:right;">
586
</td>
<td style="text-align:right;">
547
</td>
<td style="text-align:right;">
5049
</td>
<td style="text-align:right;">
9.479133
</td>
<td style="text-align:right;">
8.848269
</td>
<td style="text-align:right;">
81.67260
</td>
<td style="text-align:right;">
2857
</td>
<td style="text-align:right;">
2086
</td>
<td style="text-align:right;">
861
</td>
<td style="text-align:right;">
302
</td>
<td style="text-align:right;">
76
</td>
<td style="text-align:right;">
46.21482
</td>
<td style="text-align:right;">
33.74313
</td>
<td style="text-align:right;">
13.927532
</td>
<td style="text-align:right;">
4.885150
</td>
<td style="text-align:right;">
1.229376
</td>
<td style="text-align:right;">
5.8
</td>
<td style="text-align:right;">
3.9
</td>
<td style="text-align:right;">
8.6
</td>
<td style="text-align:right;">
26.9
</td>
<td style="text-align:right;">
96.1
</td>
<td style="text-align:right;">
95.5
</td>
<td style="text-align:right;">
77.9
</td>
<td style="text-align:right;">
80.7
</td>
<td style="text-align:right;">
556
</td>
<td style="text-align:right;">
1085
</td>
<td style="text-align:right;">
515
</td>
<td style="text-align:right;">
128
</td>
<td style="text-align:right;">
34
</td>
<td style="text-align:right;">
2650
</td>
<td style="text-align:right;">
24.0
</td>
<td style="text-align:right;">
46.8
</td>
<td style="text-align:right;">
22.2
</td>
<td style="text-align:right;">
5.5
</td>
<td style="text-align:right;">
1.5
</td>
<td style="text-align:right;">
1.1432269
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
14
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
7
</td>
<td style="text-align:right;">
9
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
7
</td>
</tr>
<tr>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
72.1
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
2.7
</td>
<td style="text-align:right;">
87
</td>
<td style="text-align:right;">
161
</td>
<td style="text-align:right;">
-0.1490559
</td>
<td style="text-align:right;">
-0.0107732
</td>
<td style="text-align:right;">
8562
</td>
<td style="text-align:right;">
2200
</td>
<td style="text-align:right;">
1592
</td>
<td style="text-align:right;">
1995
</td>
<td style="text-align:right;">
1829
</td>
<td style="text-align:right;">
946
</td>
<td style="text-align:right;">
5416
</td>
<td style="text-align:right;">
7919
</td>
<td style="text-align:right;">
7922
</td>
<td style="text-align:right;">
7882
</td>
<td style="text-align:right;">
7887
</td>
<td style="text-align:right;">
7917
</td>
<td style="text-align:right;">
7916
</td>
<td style="text-align:right;">
8025
</td>
<td style="text-align:right;">
8317
</td>
<td style="text-align:right;">
8519
</td>
<td style="text-align:right;">
8588
</td>
<td style="text-align:right;">
8660
</td>
<td style="text-align:right;">
24.237875
</td>
<td style="text-align:right;">
64.57275
</td>
<td style="text-align:right;">
11.18938
</td>
<td style="text-align:right;">
783
</td>
<td style="text-align:right;">
692
</td>
<td style="text-align:right;">
624
</td>
<td style="text-align:right;">
657
</td>
<td style="text-align:right;">
525
</td>
<td style="text-align:right;">
608
</td>
<td style="text-align:right;">
616
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
673
</td>
<td style="text-align:right;">
656
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
386
</td>
<td style="text-align:right;">
320
</td>
<td style="text-align:right;">
321
</td>
<td style="text-align:right;">
202
</td>
<td style="text-align:right;">
194
</td>
<td style="text-align:right;">
127
</td>
<td style="text-align:right;">
90
</td>
<td style="text-align:right;">
35
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
691
</td>
<td style="text-align:right;">
583
</td>
<td style="text-align:right;">
593
</td>
<td style="text-align:right;">
808
</td>
<td style="text-align:right;">
508
</td>
<td style="text-align:right;">
21.709080
</td>
<td style="text-align:right;">
18.31605
</td>
<td style="text-align:right;">
18.630223
</td>
<td style="text-align:right;">
25.38486
</td>
<td style="text-align:right;">
15.95979
</td>
<td style="text-align:right;">
5674
</td>
<td style="text-align:right;">
313
</td>
<td style="text-align:right;">
1050
</td>
<td style="text-align:right;">
1445
</td>
<td style="text-align:right;">
80
</td>
<td style="text-align:right;">
2888
</td>
<td style="text-align:right;">
66.26956
</td>
<td style="text-align:right;">
3.655688
</td>
<td style="text-align:right;">
12.263490
</td>
<td style="text-align:right;">
16.876898
</td>
<td style="text-align:right;">
0.9343611
</td>
<td style="text-align:right;">
33.73044
</td>
<td style="text-align:right;">
6425
</td>
<td style="text-align:right;">
2137
</td>
<td style="text-align:right;">
75.04088
</td>
<td style="text-align:right;">
24.95912
</td>
<td style="text-align:right;">
2868
</td>
<td style="text-align:right;">
315
</td>
<td style="text-align:right;">
90.10368
</td>
<td style="text-align:right;">
9.896324
</td>
<td style="text-align:right;">
4986
</td>
<td style="text-align:right;">
28
</td>
<td style="text-align:right;">
138
</td>
<td style="text-align:right;">
35
</td>
<td style="text-align:right;">
762
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
1816
</td>
<td style="text-align:right;">
618
</td>
<td style="text-align:right;">
58.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
1.6
</td>
<td style="text-align:right;">
0.4
</td>
<td style="text-align:right;">
8.9
</td>
<td style="text-align:right;">
1.9
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
21.2
</td>
<td style="text-align:right;">
7.2
</td>
<td style="text-align:right;">
711
</td>
<td style="text-align:right;">
1146
</td>
<td style="text-align:right;">
793
</td>
<td style="text-align:right;">
482
</td>
<td style="text-align:right;">
22.3
</td>
<td style="text-align:right;">
36.0
</td>
<td style="text-align:right;">
24.9
</td>
<td style="text-align:right;">
15.1
</td>
<td style="text-align:right;">
3183
</td>
<td style="text-align:right;">
89
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
622
</td>
<td style="text-align:right;">
2141
</td>
<td style="text-align:right;">
373
</td>
<td style="text-align:right;">
97.3
</td>
<td style="text-align:right;">
2.7
</td>
<td style="text-align:right;">
4.2
</td>
<td style="text-align:right;">
19.0
</td>
<td style="text-align:right;">
65.4
</td>
<td style="text-align:right;">
11.4
</td>
<td style="text-align:right;">
118.81
</td>
<td style="text-align:right;">
72.88949
</td>
<td style="text-align:right;">
162250
</td>
<td style="text-align:right;">
170000
</td>
<td style="text-align:right;">
185000
</td>
<td style="text-align:right;">
200000.0
</td>
<td style="text-align:right;">
166250
</td>
<td style="text-align:right;">
169000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
167000
</td>
<td style="text-align:right;">
180000
</td>
<td style="text-align:right;">
152
</td>
<td style="text-align:right;">
168
</td>
<td style="text-align:right;">
184
</td>
<td style="text-align:right;">
73
</td>
<td style="text-align:right;">
60
</td>
<td style="text-align:right;">
58
</td>
<td style="text-align:right;">
81
</td>
<td style="text-align:right;">
59
</td>
<td style="text-align:right;">
75
</td>
<td style="text-align:right;">
1839
</td>
<td style="text-align:right;">
1026
</td>
<td style="text-align:right;">
1038
</td>
<td style="text-align:right;">
160
</td>
<td style="text-align:right;">
653
</td>
<td style="text-align:right;">
1119
</td>
<td style="text-align:right;">
527
</td>
<td style="text-align:right;">
333
</td>
<td style="text-align:right;">
4052
</td>
<td style="text-align:right;">
394
</td>
<td style="text-align:right;">
1881
</td>
<td style="text-align:right;">
68.29597
</td>
<td style="text-align:right;">
9.723593
</td>
<td style="text-align:right;">
31.70403
</td>
<td style="text-align:right;">
307
</td>
<td style="text-align:right;">
9.6
</td>
<td style="text-align:right;">
34293.82
</td>
<td style="text-align:right;">
29155.68
</td>
<td style="text-align:right;">
22.9
</td>
<td style="text-align:right;">
25.3
</td>
<td style="text-align:right;">
442
</td>
<td style="text-align:right;">
231
</td>
<td style="text-align:right;">
52.3
</td>
<td style="text-align:right;">
96.3
</td>
<td style="text-align:right;">
713
</td>
<td style="text-align:right;">
722
</td>
<td style="text-align:right;">
7127
</td>
<td style="text-align:right;">
8.327494
</td>
<td style="text-align:right;">
8.432609
</td>
<td style="text-align:right;">
83.23990
</td>
<td style="text-align:right;">
4089
</td>
<td style="text-align:right;">
2811
</td>
<td style="text-align:right;">
1134
</td>
<td style="text-align:right;">
412
</td>
<td style="text-align:right;">
116
</td>
<td style="text-align:right;">
47.75753
</td>
<td style="text-align:right;">
32.83111
</td>
<td style="text-align:right;">
13.244569
</td>
<td style="text-align:right;">
4.811960
</td>
<td style="text-align:right;">
1.354824
</td>
<td style="text-align:right;">
7.7
</td>
<td style="text-align:right;">
6.0
</td>
<td style="text-align:right;">
9.9
</td>
<td style="text-align:right;">
29.7
</td>
<td style="text-align:right;">
110.0
</td>
<td style="text-align:right;">
106.1
</td>
<td style="text-align:right;">
76.8
</td>
<td style="text-align:right;">
79.9
</td>
<td style="text-align:right;">
1080
</td>
<td style="text-align:right;">
1423
</td>
<td style="text-align:right;">
551
</td>
<td style="text-align:right;">
109
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
2937
</td>
<td style="text-align:right;">
33.9
</td>
<td style="text-align:right;">
44.7
</td>
<td style="text-align:right;">
17.3
</td>
<td style="text-align:right;">
3.4
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.9227144
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
30
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
27
</td>
<td style="text-align:right;">
29
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
25
</td>
</tr>
<tr>
<td style="text-align:right;">
8791
</td>
<td style="text-align:right;">
8672
</td>
<td style="text-align:right;">
119
</td>
<td style="text-align:right;">
50.6
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
2.5
</td>
<td style="text-align:right;">
96
</td>
<td style="text-align:right;">
136
</td>
<td style="text-align:right;">
0.0702553
</td>
<td style="text-align:right;">
-0.1401784
</td>
<td style="text-align:right;">
8791
</td>
<td style="text-align:right;">
2388
</td>
<td style="text-align:right;">
1765
</td>
<td style="text-align:right;">
1867
</td>
<td style="text-align:right;">
1736
</td>
<td style="text-align:right;">
1035
</td>
<td style="text-align:right;">
5368
</td>
<td style="text-align:right;">
7806
</td>
<td style="text-align:right;">
7726
</td>
<td style="text-align:right;">
7771
</td>
<td style="text-align:right;">
7820
</td>
<td style="text-align:right;">
7877
</td>
<td style="text-align:right;">
7974
</td>
<td style="text-align:right;">
8145
</td>
<td style="text-align:right;">
8394
</td>
<td style="text-align:right;">
8571
</td>
<td style="text-align:right;">
8823
</td>
<td style="text-align:right;">
9076
</td>
<td style="text-align:right;">
26.586602
</td>
<td style="text-align:right;">
62.02071
</td>
<td style="text-align:right;">
11.39268
</td>
<td style="text-align:right;">
957
</td>
<td style="text-align:right;">
792
</td>
<td style="text-align:right;">
664
</td>
<td style="text-align:right;">
633
</td>
<td style="text-align:right;">
642
</td>
<td style="text-align:right;">
686
</td>
<td style="text-align:right;">
634
</td>
<td style="text-align:right;">
651
</td>
<td style="text-align:right;">
596
</td>
<td style="text-align:right;">
610
</td>
<td style="text-align:right;">
483
</td>
<td style="text-align:right;">
398
</td>
<td style="text-align:right;">
296
</td>
<td style="text-align:right;">
242
</td>
<td style="text-align:right;">
207
</td>
<td style="text-align:right;">
180
</td>
<td style="text-align:right;">
181
</td>
<td style="text-align:right;">
139
</td>
<td style="text-align:right;">
85
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
643
</td>
<td style="text-align:right;">
489
</td>
<td style="text-align:right;">
776
</td>
<td style="text-align:right;">
1064
</td>
<td style="text-align:right;">
469
</td>
<td style="text-align:right;">
18.686428
</td>
<td style="text-align:right;">
14.21099
</td>
<td style="text-align:right;">
22.551584
</td>
<td style="text-align:right;">
30.92124
</td>
<td style="text-align:right;">
13.62976
</td>
<td style="text-align:right;">
5906
</td>
<td style="text-align:right;">
307
</td>
<td style="text-align:right;">
526
</td>
<td style="text-align:right;">
1997
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
2885
</td>
<td style="text-align:right;">
67.18235
</td>
<td style="text-align:right;">
3.492208
</td>
<td style="text-align:right;">
5.983392
</td>
<td style="text-align:right;">
22.716414
</td>
<td style="text-align:right;">
0.6256399
</td>
<td style="text-align:right;">
32.81765
</td>
<td style="text-align:right;">
6658
</td>
<td style="text-align:right;">
2133
</td>
<td style="text-align:right;">
75.73655
</td>
<td style="text-align:right;">
24.26345
</td>
<td style="text-align:right;">
3117
</td>
<td style="text-align:right;">
324
</td>
<td style="text-align:right;">
90.58413
</td>
<td style="text-align:right;">
9.415867
</td>
<td style="text-align:right;">
5409
</td>
<td style="text-align:right;">
22
</td>
<td style="text-align:right;">
67
</td>
<td style="text-align:right;">
13
</td>
<td style="text-align:right;">
577
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
24
</td>
<td style="text-align:right;">
2148
</td>
<td style="text-align:right;">
512
</td>
<td style="text-align:right;">
61.5
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
0.8
</td>
<td style="text-align:right;">
0.1
</td>
<td style="text-align:right;">
6.6
</td>
<td style="text-align:right;">
0.2
</td>
<td style="text-align:right;">
0.3
</td>
<td style="text-align:right;">
24.4
</td>
<td style="text-align:right;">
5.8
</td>
<td style="text-align:right;">
558
</td>
<td style="text-align:right;">
821
</td>
<td style="text-align:right;">
1663
</td>
<td style="text-align:right;">
333
</td>
<td style="text-align:right;">
16.2
</td>
<td style="text-align:right;">
23.9
</td>
<td style="text-align:right;">
48.3
</td>
<td style="text-align:right;">
9.7
</td>
<td style="text-align:right;">
3441
</td>
<td style="text-align:right;">
93
</td>
<td style="text-align:right;">
82
</td>
<td style="text-align:right;">
761
</td>
<td style="text-align:right;">
1219
</td>
<td style="text-align:right;">
1471
</td>
<td style="text-align:right;">
97.4
</td>
<td style="text-align:right;">
2.6
</td>
<td style="text-align:right;">
2.3
</td>
<td style="text-align:right;">
21.5
</td>
<td style="text-align:right;">
34.5
</td>
<td style="text-align:right;">
41.6
</td>
<td style="text-align:right;">
173.58
</td>
<td style="text-align:right;">
52.28713
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
187000
</td>
<td style="text-align:right;">
199000.0
</td>
<td style="text-align:right;">
155000
</td>
<td style="text-align:right;">
165000
</td>
<td style="text-align:right;">
153750
</td>
<td style="text-align:right;">
172500
</td>
<td style="text-align:right;">
168500
</td>
<td style="text-align:right;">
112
</td>
<td style="text-align:right;">
133
</td>
<td style="text-align:right;">
139
</td>
<td style="text-align:right;">
39
</td>
<td style="text-align:right;">
40
</td>
<td style="text-align:right;">
75
</td>
<td style="text-align:right;">
76
</td>
<td style="text-align:right;">
48
</td>
<td style="text-align:right;">
55
</td>
<td style="text-align:right;">
2057
</td>
<td style="text-align:right;">
1065
</td>
<td style="text-align:right;">
1001
</td>
<td style="text-align:right;">
166
</td>
<td style="text-align:right;">
556
</td>
<td style="text-align:right;">
1129
</td>
<td style="text-align:right;">
429
</td>
<td style="text-align:right;">
402
</td>
<td style="text-align:right;">
3905
</td>
<td style="text-align:right;">
511
</td>
<td style="text-align:right;">
1893
</td>
<td style="text-align:right;">
67.35081
</td>
<td style="text-align:right;">
13.085788
</td>
<td style="text-align:right;">
32.64919
</td>
<td style="text-align:right;">
437
</td>
<td style="text-align:right;">
12.7
</td>
<td style="text-align:right;">
29975.83
</td>
<td style="text-align:right;">
25568.60
</td>
<td style="text-align:right;">
33.3
</td>
<td style="text-align:right;">
28.9
</td>
<td style="text-align:right;">
602
</td>
<td style="text-align:right;">
345
</td>
<td style="text-align:right;">
57.3
</td>
<td style="text-align:right;">
98.1
</td>
<td style="text-align:right;">
828
</td>
<td style="text-align:right;">
752
</td>
<td style="text-align:right;">
7211
</td>
<td style="text-align:right;">
9.418724
</td>
<td style="text-align:right;">
8.554203
</td>
<td style="text-align:right;">
82.02707
</td>
<td style="text-align:right;">
3996
</td>
<td style="text-align:right;">
3015
</td>
<td style="text-align:right;">
1252
</td>
<td style="text-align:right;">
407
</td>
<td style="text-align:right;">
121
</td>
<td style="text-align:right;">
45.45558
</td>
<td style="text-align:right;">
34.29644
</td>
<td style="text-align:right;">
14.241838
</td>
<td style="text-align:right;">
4.629735
</td>
<td style="text-align:right;">
1.376408
</td>
<td style="text-align:right;">
6.8
</td>
<td style="text-align:right;">
5.3
</td>
<td style="text-align:right;">
8.8
</td>
<td style="text-align:right;">
29.0
</td>
<td style="text-align:right;">
117.0
</td>
<td style="text-align:right;">
80.1
</td>
<td style="text-align:right;">
75.7
</td>
<td style="text-align:right;">
79.5
</td>
<td style="text-align:right;">
1496
</td>
<td style="text-align:right;">
1444
</td>
<td style="text-align:right;">
419
</td>
<td style="text-align:right;">
63
</td>
<td style="text-align:right;">
19
</td>
<td style="text-align:right;">
2549
</td>
<td style="text-align:right;">
43.5
</td>
<td style="text-align:right;">
42.0
</td>
<td style="text-align:right;">
12.2
</td>
<td style="text-align:right;">
1.8
</td>
<td style="text-align:right;">
0.6
</td>
<td style="text-align:right;">
0.7407730
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
18
</td>
<td style="text-align:right;">
20
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
25
</td>
<td style="text-align:right;">
27
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>We start with modelling our relative rate of burglary shift. We divide our sample into a training set which we’ll use to train the model, and a test set we’ll use to verify accuracy and validity.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-50_49f4c5cba018318edfa1271efe6c8f5d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb111" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb111-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123</span>)</span>
<span id="cb111-2"></span>
<span id="cb111-3">sample <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;">sample.split</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SplitRatio =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb111-4">train <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;">subset</span>(data, sample <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;">TRUE</span>)</span>
<span id="cb111-5">test  <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;">subset</span>(data, sample <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;">FALSE</span>)</span>
<span id="cb111-6"></span>
<span id="cb111-7"></span>
<span id="cb111-8">rf_burglary <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;">randomForest</span>(</span>
<span id="cb111-9">  RPDburglaryShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .,</span>
<span id="cb111-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>train, </span>
<span id="cb111-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">importance=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb111-12">)</span>
<span id="cb111-13"></span>
<span id="cb111-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(rf_burglary)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>                Length Class  Mode     
call              4    -none- call     
type              1    -none- character
predicted       685    -none- numeric  
mse             500    -none- numeric  
rsq             500    -none- numeric  
oob.times       685    -none- numeric  
importance      420    -none- numeric  
importanceSD    210    -none- numeric  
localImportance   0    -none- NULL     
proximity         0    -none- NULL     
ntree             1    -none- numeric  
mtry              1    -none- numeric  
forest           11    -none- list     
coefs             0    -none- NULL     
y               685    -none- numeric  
test              0    -none- NULL     
inbag             0    -none- NULL     
terms             3    terms  call     </code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-51_1b075fa831c9c6de9ce4fb6d197a515a">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb113" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb113-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#calculate our predictions and a  rmse</span></span>
<span id="cb113-2">prediction <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>(rf_burglary, test)</span>
<span id="cb113-3">Metrics<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;">rmse</span>(test<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted, prediction)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.2054765</code></pre>
</div>
</div>
<p>While machine learning models were once considered opaque and difficult to interpret, several libraries now offer functionality to explain predictions. Here I use <a href="https://cran.r-project.org/web/packages/DALEX/index.html">DALEX</a> to do just this.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-52_693a44981eae36703852c4c45ccebe12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb115" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb115-1">rf_explainer_burglary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DALEX<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;">explain</span>(rf_burglary, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>train, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span> train<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDburglaryShifted)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Preparation of a new explainer is initiated
  -&gt; model label       :  randomForest  (  default  )
  -&gt; data              :  685  rows  211  cols 
  -&gt; data              :  tibble converted into a data.frame 
  -&gt; target variable   :  685  values 
  -&gt; predict function  :  yhat.randomForest  will be used (  default  )
  -&gt; predicted values  :  No value for predict function target column. (  default  )
  -&gt; model_info        :  package randomForest , ver. 4.7.1.1 , task regression (  default  ) 
  -&gt; predicted values  :  numerical, min =  -0.5274977 , mean =  -0.07802522 , max =  0.6606534  
  -&gt; residual function :  difference between y and yhat (  default  )
  -&gt; residuals         :  numerical, min =  -0.2851655 , mean =  -0.001568916 , max =  0.6340126  
  A new explainer has been created!  </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb117" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb117-1">rf_perf_burg <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;">model_performance</span>(rf_explainer_burglary)</span>
<span id="cb117-2">rf_perf_burg</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Measures for:  regression
mse        : 0.006624875 
rmse       : 0.08139334 
r2         : 0.8398785 
mad        : 0.04636179

Residuals:
          0%          10%          20%          30%          40%          50% 
-0.285165546 -0.093485342 -0.059400738 -0.040833227 -0.024804195 -0.007423066 
         60%          70%          80%          90%         100% 
 0.009744147  0.032325289  0.054260825  0.089461048  0.634012592 </code></pre>
</div>
</div>
<p>We can see that our model significantly outperforms our best linear models: the R2 suggests that almost 85% of the variance is correctly interpreted, and our rmse (root mean squared error) is around 0.2 on our test set.</p>
<p>This model would be ill-suited to prediction or operationalising -it is a default forecast with no hyper-parameter tuning, and no consideration of error rates - but using tools like DALEX, we can identify which predictors the model identifies as most important.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-53_b9483e940f3e4a1587658571afc62f3c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb119" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb119-1">model_parts_burg <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;">model_parts</span>(rf_explainer_burglary)</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-54_97e63125b038ba41a9f28111c12cee4d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb120" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb120-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(model_parts_burg, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_vars=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-54-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<p>The three most important features our model highlights are: - the age composition of the population - the number of residents which are in commercial property - the historic number of burglaries</p>
<p>This seems to corroborate our previous regression model. To further unpick these trends, we can use Partial Dependence Plots to identify how the model prediction shifts with these values.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-55_745dc6bae476f6fc1c6c8561d1b8cfcb">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb121" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb121-1">pdp_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;">model_profile</span>(rf_explainer_burglary)</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-56_672f750eb1bba406cf8d8d49d6dcb89b">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb122" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb122-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_burglaries"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-56-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>We still see a strong association between a high number of historic, and a large reduction during the lockdown period</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-57_e25fbb3c26763ca7a5f0a0c6540e322a">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb123" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb123-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Religion..2011..Christian"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-57-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-58_2d2eb6ee11b4873b18ebc2b0eaa9b0df">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb124" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb124-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Religion..<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011</span>..Christian)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-58-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-59_580ec154f3e73f22af61c88e95ea8c23">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb125" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb125-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ComEstRes"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-59-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-60_460e8db4349c5ad22b4e19917bb888de">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb126" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb126-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(msoa_matrix_numeric<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ComEstRes)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-60-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>By combining the distribution of commercial residents by MSOA with our PDP, we can see that those MSOAs that are most densely populated by commercial residents see the smallest “covid decrease”(suggesting that those MSOAs that are very heavily residential saw the sharpest drops).</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-61_41e8a2f5ed4c0230edc79c97a3250a1f">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb127" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb127-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_b, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"House.Prices.Sales.2008"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-61-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Finally, we can see that those areas that experienced the highest volume of house sales experienced the lowest relative decrease in burglary.</p>
<p>This highlights the importance of identifying correlates in RF models - especially in a dataset where features are highly interlinked, association does not imply causation, and we should be wary of over-interpreting.</p>
<p>We can now repeat our process for our robbery shift.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-62_920d19af608215969c15446f760bfc02">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb128" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb128-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123</span>)</span>
<span id="cb128-2"></span>
<span id="cb128-3"></span>
<span id="cb128-4">sample <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;">sample.split</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SplitRatio =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb128-5">train <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;">subset</span>(data, sample <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;">TRUE</span>)</span>
<span id="cb128-6">test  <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;">subset</span>(data, sample <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;">FALSE</span>)</span>
<span id="cb128-7"></span>
<span id="cb128-8"></span>
<span id="cb128-9">rf_robbery <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;">randomForest</span>(</span>
<span id="cb128-10">  RPDRobberyShifted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .,</span>
<span id="cb128-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>train, </span>
<span id="cb128-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">importance=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb128-13">)</span>
<span id="cb128-14"></span>
<span id="cb128-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(rf_robbery)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>                Length Class  Mode     
call              4    -none- call     
type              1    -none- character
predicted       734    -none- numeric  
mse             500    -none- numeric  
rsq             500    -none- numeric  
oob.times       734    -none- numeric  
importance      420    -none- numeric  
importanceSD    210    -none- numeric  
localImportance   0    -none- NULL     
proximity         0    -none- NULL     
ntree             1    -none- numeric  
mtry              1    -none- numeric  
forest           11    -none- list     
coefs             0    -none- NULL     
y               734    -none- numeric  
test              0    -none- NULL     
inbag             0    -none- NULL     
terms             3    terms  call     </code></pre>
</div>
</div>
<p>We’ve now trained a model. Let’s now use the DALEX library to understand it, and see how it performs.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-63_af543a37e56c433a782f9b9ff38bcc32">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb130" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb130-1">rf_explainer_robbery <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DALEX<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;">explain</span>(rf_robbery, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>train, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span> train<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RPDRobberyShifted)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Preparation of a new explainer is initiated
  -&gt; model label       :  randomForest  (  default  )
  -&gt; data              :  734  rows  211  cols 
  -&gt; data              :  tibble converted into a data.frame 
  -&gt; target variable   :  734  values 
  -&gt; predict function  :  yhat.randomForest  will be used (  default  )
  -&gt; predicted values  :  No value for predict function target column. (  default  )
  -&gt; model_info        :  package randomForest , ver. 4.7.1.1 , task regression (  default  ) 
  -&gt; predicted values  :  numerical, min =  -0.9908618 , mean =  -0.04880848 , max =  0.3886733  
  -&gt; residual function :  difference between y and yhat (  default  )
  -&gt; residuals         :  numerical, min =  -0.4640489 , mean =  -0.0007951117 , max =  0.2909289  
  A new explainer has been created!  </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb132" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb132-1">rf_perf_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;">model_performance</span>(rf_explainer_robbery)</span>
<span id="cb132-2">rf_perf_rob</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Measures for:  regression
mse        : 0.003630323 
rmse       : 0.06025216 
r2         : 0.872715 
mad        : 0.02818358

Residuals:
          0%          10%          20%          30%          40%          50% 
-0.464048863 -0.059133188 -0.037257312 -0.023376075 -0.014244755 -0.004866538 
         60%          70%          80%          90%         100% 
 0.005089387  0.019736886  0.034999616  0.059437002  0.290928866 </code></pre>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-64_e0f846a5f3a8edcdfbdf75d1efa110a7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb134" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb134-1">model_parts_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;">model_parts</span>(rf_explainer_robbery)</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-65_b256b9a8b44324dbc1958d2a01cccd23">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb135" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb135-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(model_parts_rob, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_vars=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-65-1.png" class="img-fluid figure-img" width="1248"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-66_34eba0e84d680ab343a508c49fb77d8e">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb136" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb136-1">pdp_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;">model_profile</span>(rf_explainer_robbery)</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-67_6f0e9aef772de05cd9ad7dd585e68bd5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb137" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb137-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_rob, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_robberies"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-67-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-68_d80ac4259abd7ed5fbf1c258c1e61c64">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb138" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb138-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_rob, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"total_burglaries"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-68-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The effect of historic crime effects again appears like a reliable predictor of a robbery covid shift: those MSOAs with the highest number of burglaries and robberies see strong decreases in robbery (though the association with burglary is not clear cut, suggesting other interaction effects may be driving this)</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-69_816a9ed5a2d94a8095922585f5fde89d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb139" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb139-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_rob, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Road.Casualties.2011.2011.Total"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-69-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Road casualties is another strong relationship. This could be a proxy for deprivation, but I suggest this is more down to geographic features - road casualties are probably rarer in denser urban environments, most likely to be affected by lockdown.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-70_261b22b9c9ffed7819da67d482fcc98d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb140" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb140-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(pdp_rob, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ethnic.Group..2011.Census..Other.ethnic.group...."</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-70-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-71_07487ba58ee9152e4115322e9ffae391">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb141" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb141-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Ethnic.Group..<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011.</span>Census..Other.ethnic.group....)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://andreasthinks.me/posts/lockdown_effect/index_files/figure-html/unnamed-chunk-71-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Finally, we see a demographic predictor linked to “other ethnic group”. I’m not clear how to interpret this, but it suggests that those MSOAs that are most diverse (and have the largest representation by these ethnic groups) experienced the strongest decreases in robbery during lockdown.</p>
<p>Together, these analyses suggest that the crime drop for robbery and burglary during national lockdown was significantly affected by distinct local factors. For both offences, historical crime trends play a role, with high crime areas experiencing a relatively larger drop in both burglary and robbery.</p>
<p>Beyond that, the drivers vary for each offence type: burglary was driven by the composition of the residential population, with heavily residential areas, and areas with a relatively “stable” population as measured by low housing sales also saw larger decrease - this is likely due to the increased number of empty residential properties.</p>
<p>Robbery decreases conversely, are well associated with high numbers of road casualties, as well as the ethnic makeup of the local population - this is likely due to an association with denser, more urban areas, with lower street speeds, and a possible link to deprivation, whereby minority population were least able to work from home, and were likely to still present as available targets for robbery.</p>


</section>
</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>data-science</category>
  <category>forecasting</category>
  <category>crime</category>
  <category>geospatial</category>
  <guid>https://andreasthinks.me/posts/lockdown_effect/</guid>
  <pubDate>Sat, 22 May 2021 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
