<?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>Mountain Doodles</title>
<link>https://doodles.mountainmath.ca/</link>
<atom:link href="https://doodles.mountainmath.ca/index.xml" rel="self" type="application/rss+xml"/>
<description>Thoughts on housing, demographics and random things</description>
<generator>quarto-1.9.23</generator>
<lastBuildDate>Mon, 04 May 2026 07:00:00 GMT</lastBuildDate>
<item>
  <title>CensusMapper 2.0</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Leia Chen</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/</link>
  <description><![CDATA[ 






<style>
.no-copy .code-copy-button {
  display: none !important;
}
</style>
<p>CensusMapper is a web-based Geographic Information System that allows for dynamic mapping of Canadian Census data. CensusMapper is eleven years old now, and it was showing it’s age. Today CensusMapper go a major update.</p>
<section id="tldr" class="level2">
<h2 class="anchored" data-anchor-id="tldr">TL;DR</h2>
<p><a href="https://censusmapper.ca" class="btn btn-primary">Try out the new CensusMapper, it’s great!</a></p>
</section>
<section id="history" class="level2">
<h2 class="anchored" data-anchor-id="history">History</h2>
<p>Here we focus on what’s new in this CensusMapper update, we refer those interested in how CensusMapper started and how we got here to posts chronicling the motivation and history of CensusMapper. <span class="citation" data-cites="the-hidden-mortgage.2015 census-mapper.2015 census-drilldown.2015 canvas-vs-svg.2015 census-week.2016 census-mapping-for-everyone.2016 comparing-censuses.2017 2001-census-data-and-tongfen.2019 census-tract-level-t1ff-tax-data.2020 canadian-1996-census.2020 censusmapper-p-review.2021">(<span class="nocase">von Bergmann</span> 2015b, 2015a, 2016b, 2016a, 2017a, 2019, 2020b, 2020a, 2021; <span class="nocase">von Bergmann and Cervantes</span> 2015b, 2015a)</span></p>
<p><a href="https://censusmapper.ca"> <img src="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/cm-logo.png" style="padding-left:10px;float:right;max-width:30%;"> </a></p>
</section>
<section id="the-new-censusmapper" class="level2">
<h2 class="anchored" data-anchor-id="the-new-censusmapper">The new CensusMapper</h2>
<p>After putting off revamping CensusMapper for many years in early 2025 the stars aligned. Just as Jens was mapping out what it would take to modernize CensusMapper Leia, a UBC Computer Science student, approached Jens for an internship opportunity. After some discussions to make sure skills and interested aligned we decided to take the plunge. With both of us having other main responsibilities it took some time, but we have been slowly hacking away at it and are finally ready to roll it out.</p>
<section id="the-technology-stack" class="level3">
<h3 class="anchored" data-anchor-id="the-technology-stack">The technology stack</h3>
<p>The old CensusMapper used to be one giant Ruby on Rails app is now a collection of services. We only kept the Postgres/PostGIS database structure and bits and pieces of custom front-end javascript logic and rebuilt everything else from scratch. Now we have</p>
<ul>
<li>An API backend that serves data and map tiles, and does some minimal user management using <a href="https://fastapi.tiangolo.com">FastApi</a> backed by our existing PostgreSQL/PostGIS database.</li>
<li>A <a href="https://react.dev">React</a> frontend that is responsible for the user interface.</li>
<li>A mapping stack built on <a href="https://maplibre.org">Maplibre</a> and custom <a href="https://deck.gl">Deck.gl</a> extensions for the GPU-powered data layer rendering.</li>
<li>A background tile server that’s responsible for creating and serving contextual map tiles designed to work with the census data powered by <a href="https://martin.maplibre.org">Martin</a>.</li>
<li>An IP geolocation microservice so maps can scroll by default to regions relevant to each user using duckdb and a lightweight approximate <a href="https://lite.ip2location.com">IP geolocation lookup table from IP2Location</a>.</li>
<li>A microservice to create social preview images for sharing on social media, built on <a href="https://pptr.dev">Puppeteer</a>.</li>
<li>A Model Context Protocol (MCP) microservice that breaks down the data API into useful components for LLMs to interact with census data using natural language queries, built on the <a href="https://py.sdk.modelcontextprotocol.io">MCP Python SDK</a>.</li>
</ul>
</section>
</section>
<section id="changed-user-experience" class="level2">
<h2 class="anchored" data-anchor-id="changed-user-experience">Changed user experience</h2>
<p>How do these technology choices translate to the user experience? We want to highlight a couple of the impacts of these changes.</p>
<section id="new-mapping-stack" class="level3">
<h3 class="anchored" data-anchor-id="new-mapping-stack">New mapping stack</h3>
<p>Switching to full vector maps gives much more control over how the data is shown, and tying into WebGL makes this very performant and fast. In In particular, we can be much more precise on how we want to render contextual information. In the original CensusMapper we used <a href="https://maps.stamen.com/#toner/12/37.7706/-122.3782">Stamen Toner</a> themed overlays that just show the roads and labels and are drawn on top of the census data. That allows for rich colours for the census data with simple and informative contextual data as overlays. Unfortunately we lost this layer when these base maps moved to Stadia and we regressed to drawing census data on top of base maps, requiring opacity for the census data and losing a lot colour vibrancy and contrast in the process.</p>
<p>With the new CensusMapper we decided to build our own Canada-wide contextual vector tiles that are specifically designed to work well with census data. For this we took the same design as the original Stamen Toner base maps and are drawing roads and place names on top, with some adjustments on what to show and what not to show, especially at high zoom levels. And for added context we decided to fade in building footprints at very high zoom levels, making it easier to orient oneself when zoomed in far.</p>
<p>An important addition in the new CensusMapper is that we also built a custom layer meant to filter out land uses where nobody lives. That is forests, parks, gold courses, and similar natural areas, as well as industrial areas. This layer is now by default also overplayed with a slight transparency to hint at which census regions extend below them. The idea is that it helps users to focus on areas where people are likely to live, and so that areas that contain large parks don’t dominate the map. This is only available at medium and high zoom levels, at low zoom levels much of the country gets blocked out that way and it distracts more than it helps. When people view Canadian data at the provincial or census district level the areas not covered by forests can we really small and hard to discern at that zoom level, and places with inconsistent or missing land use data in Open Street Map, which can become a concern at medium zoom levels too, become very visible.</p>
<p>The last change is the water layer. We now overlay water with full opacity, blocking out water helps provides important context. Census regions generally don’t block out internal bodies of water and even rivers, which can make it hard to orient oneself on a map. For the 2021 census data release we spent a lot of work on cropping out internal waterways to alleviate this, but this does not come without tradeoffs. Simply overlaying water on top of maps is the simpler and much better solution to this problem.</p>
<p>The dynamic nature of vector base maps also means that we can dynamically turn some of these layers on or off, and there is a new layer menu in the map controls that facilitate this.</p>
<p>In summary, this results in a much better user experience when viewing maps on CensusMapper.</p>
</section>
<section id="new-map-making" class="level3">
<h3 class="anchored" data-anchor-id="new-map-making">New map making</h3>
<p>The public version of the old CensusMapper only allowed for making simple maps based on single census variables or percentages that involved two variables. The internal version allowed for much more flexible and interesting map making, but it remained locked off for general users because it required extensive knowledge how it worked and was not user friendly. A big part of the revamp of CensusMapper was to make the more flexible map making functionality available to everyone in a user friendly way. Users can now write arbitrary functions based on census variables, and create custom intermediate variables to help organize things. And we have four basic types of maps available, with plans to add more. The currently available map types are:</p>
<ul>
<li>Choropleth maps, which are the classic type of map where each geographic unit is coloured based on the value of a variable.</li>
<li>Multi-choropleth maps, where users can create a selection of related choropleth maps with buttons that allow users to switch between them. This is useful for comparing different variables, or the same variable across different census years.</li>
<li>Category maps, a simple map that ranks (custom) variables and colours each region based on the dominant one.</li>
<li>Tricolour maps, which show proportions between three different variables. We have had these from the beginning of CensusMapper, but our original implementation was simply mixing RGB channels, for the new CensusMapper we looked toward the {tricolore} R package <span class="citation" data-cites="schöley2018">(Schöley and Kashnitsky 2018)</span> that we quite like for a better way to implement this in HCL colour space and we added discrete colour brackets, which makes the maps more legible.</li>
<li>Bivariate maps, these were an obvious blind spot in the original CensusMapper that we filled in this release. Bivariate maps can be a useful way to show data along two dimensions, but similar to tricolour maps the resolution along each dimension is somewhat limited so that the map remains legible.</li>
</ul>
<p>A big part of CensusMapper has been the map stories in the side panel. Stories allow map makers to frame the data and lead the reader. Map makers have likely spent a lot of time thinking about the data they are mapping and can share that knowledge. It’s perfectly possible, and even desirable, that two different map makes tell quite different stories using the same underlying map.</p>
<p>To enrich the storytelling the map stories accept markdown content, and we have made it a bit easier for newcomers to write richer stories. And we made it much easier for users to add custom widgets, for example scatterplots, based on the data in the map view. This has been available in CensusMapper for a long time but was not exposed to the general public because it wasn’t user friendly. Now it is, so anyone can make widgets based on custom variables they create.</p>
</section>
<section id="visual-impact" class="level3">
<h3 class="anchored" data-anchor-id="visual-impact">Visual impact</h3>
<p>The changes in mapping stack and refinements in map representation discussed above change the visual impact of the maps as illustrated in the comparisons below. We believe this significantly improves the user experience and the readability of the maps.</p>
<div id="fig-pop" class="quarto-layout-panel">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pop-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-pop" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-pop1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-pop1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/censusmapper1_pop.png" class="img-fluid figure-img" data-ref-parent="fig-pop">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-pop1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a) Old CensusMapper
</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-pop" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-pop2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-pop2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/censusmapper2_pop.png" class="img-fluid figure-img" data-ref-parent="fig-pop">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-pop2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b) New CensusMapper
</figcaption>
</figure>
</div>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-pop-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: <a href="https://censusmapper.ca/maps/3053#10/49.2111/-122.8433">Population density</a>
</figcaption>
</figure>
</div>
<div id="fig-pop" class="quarto-layout-panel">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pop-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-pop" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-afi1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-afi1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/censusmapper1_afi.png" class="img-fluid figure-img" data-ref-parent="fig-pop">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-afi1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a) Old CensusMapper
</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-pop" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-afi2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-afi2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/censusmapper2_afi.png" class="img-fluid figure-img" data-ref-parent="fig-pop">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-afi2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b) New CensusMapper
</figcaption>
</figure>
</div>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-pop-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: <a href="https://censusmapper.ca/maps/3710#10/49.2111/-122.8433">Adjusted after-tax family income brackets</a>
</figcaption>
</figure>
</div>
</section>
<section id="geolocation-services" class="level3">
<h3 class="anchored" data-anchor-id="geolocation-services">Geolocation services</h3>
<p>CensusMapper always had the problem that some users would not fully grasp the interactive Canada-wide nature of the maps and would not pan over to regions they are interested in but just stay at the map view the map originally loads in.</p>
<p>CensusMapper always had the ability for users to geo-locate them and automatically zoom and pan to where they are. But that requires users selecting that button and allowing access to their location, which some users are understandably reluctant to do. In principle this fairly precise geolocation information can then get harvested by web services, and while on CensusMapper this information remains in your web browser and never gets uploaded to the server, many web services do just that and it’s impossible for casual users to distinguish these cases.</p>
<p>But census data is inherently local and users tend to be interested in data around where they are. As a compromise CensusMapper now has an IP geolocation service. This is simply a lookup table that identifies the user IP address, something that is always shared with a web service, to an approximate geographic location. We are using a free database, so accuracy is somewhat limited and generally off by around 5 kilometres, frequently worse. This does not work when using VPN, or a corporate network connection, and sometimes it’s very far off for other reasons. But it most cases it works reasonably well to give a rough idea where a user is located, and this mechanism is now used at CensusMapper to pan and zoom maps to the rough (presumed) user location when navigating to the site without indicating a target location. If the user is located to be in Canada.</p>
<p>This makes the content when landing on the page more relevant to users without requiring additional information from users.</p>
</section>
<section id="better-social-previews" class="level3">
<h3 class="anchored" data-anchor-id="better-social-previews">Better social previews</h3>
<p>A related problem comes with the previous implementation of social previews. When sharing maps on social media CensusMapper generates a map preview image. This helps people understand what the link is about before clicking in, clearly indicating that they are about to go to a mapping website. But the previous implementation had one fixed image for a given map, but if that preview was e.g.&nbsp;for the City of Vancouver area, and the user sharing the map had panned over to Toronto and wanted to people to show the map there, the link would still lead them to Toronto but the preview would not match that and still show Vancouver. This has changed now, and social previews will automatically pick up where users are linking to and generate a social preview image for exactly that area.</p>
</section>
<section id="the-mcp-server" class="level3">
<h3 class="anchored" data-anchor-id="the-mcp-server">The MCP server</h3>
<p>No matter your opinion on the advent of generative AI and LLMs, they are here and will stick around in one form or another. CensusMapper is based on users making, narrating, and sharing maps. And it is also a general API server that provinces pinpointed access to census data, mostly for analysis purposes. The underlying motivation has always been to make census data more accessible for the general population, and to foster the (responsible) use of data throughout Canada and build up a community of data users.</p>
<p>CensusMapper, and the data APIs, significantly reduce the barriers to working with Canadian census data. But significant barriers remain. An important part of the back story to CensusMapper is that it started after an initial furor into census data triggered a lot of interest from journalists, and I started to get questions about census data, questions like:</p>
<ul>
<li>What is the average income in Vancouver?</li>
<li>What’s the share of the Filipino population in Burnaby?</li>
<li>How many German-born people live in Toronto?</li>
</ul>
<p>These are fairly simple questions that require the lookup of one or two census variables. At the time, just a couple of years after StatCan first opened up their data in February 2012, these were hard questions. CensusMapper made it easier to get these answers, but they required some clicking through maps and maybe using the “Census Wheel”, and some familiarity with CensusMapper to understand how to do this. Or using the API, which in many ways is simpler for this purpose but comes with it’s own set of barriers.</p>
<p>Nowadays these questions have become easier, not just because of CensusMapper but also because StatCan has gotten better at making their data more accessible. But chances are high that nowadays people who have questions like this will use a search engine, and just read the <em>AI Overview</em>. Or go straight to their preferred LLM, be it ChatGPT, Claude, Gemini or something else. And this creates a problem. While the barrier to ask – and get answers to – these kind of questions is virtually non-existent at this point, it has gotten harder to figure out how reliable the answer is. One way to improve this is a dedicated MCP server.</p>
<section id="whats-an-mcp-server" class="level4">
<h4 class="anchored" data-anchor-id="whats-an-mcp-server">What’s an MCP server?</h4>
<p>A Model Context Protocol (MCP) server is, roughly speaking, and API for an LLM. It’s provides a principled way for an LLM to access data. The MCP includes an overview on what kind of data access is available together with some brief instructions on how to use this service. To be useful it should be tailored specifically to LLMs.</p>
<p>We already have a data API that is great for querying and working with census data, but it’s not that useful for LLMs. The main reason is that the typical amount of data provided is too large. For example to discover census variables and decide which might be useful for a specific question, the data API workflow would download all census variable descriptions for a given census year and then filter and search through those variables. That’s not something an LLM can do effectively. The MCP implements a similar functionality by filtering on the server and only sending a filtered set of census variables down to the LLM. Small chunks that the LLM can handle, and potentially iterate on to narrow things down further or iterate on.</p>
<p>Basically, the data API is designed to allow for larger data download for desired regions, variables and aggregation level, the MCP is design to facilitate discovery of a very small number of relevant regions and variables and pinpointed data download. Because each query is small and pinpointed we have removed the quota we have on regular API calls, but we rate-limit the service so it won’t get overwhelmed.</p>
</section>
<section id="how-to-use-the-mcp-server" class="level4">
<h4 class="anchored" data-anchor-id="how-to-use-the-mcp-server">How to use the MCP server?</h4>
<p>You will have to point your LLM of choice to the CensusMapper server. For example for Claude you would either edit the config file or run</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">claude</span> mcp add <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--transport</span> http censusmapper https://censusmapper.ca/mcp</span></code></pre></div></div>
</div>
<p>For almost all queries you won’t need an API key, but if you are planning of using this for more complex queries it’s recommended to install your CensusMapper API key when registering the MCP, substituting in your API key for “YOUR_API_KEY”:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">claude</span> mcp add <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--transport</span> http <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--scope</span> user censusmapper <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\ </span>                                                              </span>
<span id="cb2-2">    <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">https://censusmapper.ca/mcp</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb2-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--header</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X-Api-Key: YOUR_API_KEY"</span></span></code></pre></div></div>
</div>
<p>Then Claude will use the CensusMapper MCP when asking census related questions for Canada. Here is the transcript when asking a somewhat vague but fairly common question:</p>
<div class="no-copy">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode markdown code-overflow-wrap code-with-copy"><code class="sourceCode markdown"><span id="cb3-1">❯ what is the average income in vancouver?    </span>
<span id="cb3-2"></span>
<span id="cb3-3">⏺ Let me search for income variables and the Vancouver region in parallel.</span>
<span id="cb3-4">  Called censusmapper 2 times (ctrl+o to expand)</span>
<span id="cb3-5">⏺ Now let me fetch the income data for both the Vancouver CMA and City of Vancouver.</span>
<span id="cb3-6">  Called censusmapper 3 times (ctrl+o to expand)</span>
<span id="cb3-7">⏺ Here's what the 2021 Census (2020 income data) shows for Vancouver:</span>
<span id="cb3-8"></span>
<span id="cb3-9">  City of Vancouver </span>
<span id="cb3-10">  </span>
<span id="cb3-11">  ┌───────────────────────────────────────────────────────────────────┬──────────┐</span>
<span id="cb3-12">  │                              Measure                              │  Amount  │</span>
<span id="cb3-13">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-14">  │ Average household income                                          │ $114,900 │</span>
<span id="cb3-15">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-16">  │ Average economic family income                                    │ $151,000 │</span>
<span id="cb3-17">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-18">  │ Average individual income (persons 15+, not in economic families) │ $55,850  │</span>
<span id="cb3-19">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-20">  │ — Male                                                            │ $58,500  │</span>
<span id="cb3-21">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-22">  │ — Female                                                          │ $53,350  │</span>
<span id="cb3-23">  └───────────────────────────────────────────────────────────────────┴──────────┘</span>
<span id="cb3-24">  </span>
<span id="cb3-25">  Vancouver Metro Area (CMA)</span>
<span id="cb3-26">  </span>
<span id="cb3-27">  ┌───────────────────────────────────────────────────────────────────┬──────────┐      </span>
<span id="cb3-28">  │                              Measure                              │  Amount  │</span>
<span id="cb3-29">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-30">  │ Average household income                                          │ $117,300 │</span>
<span id="cb3-31">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-32">  │ Average economic family income                                    │ $141,000 │</span>
<span id="cb3-33">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-34">  │ Average individual income (persons 15+, not in economic families) │ $52,650  │</span>
<span id="cb3-35">  ├───────────────────────────────────────────────────────────────────┼──────────┤</span>
<span id="cb3-36">  │ — Male                                                            │ $55,400  │</span>
<span id="cb3-37">  ├───────────────────────────────────────────────────────────────────┼──────────┤                                                </span>
<span id="cb3-38">  │ — Female                                                          │ $50,040  │</span>
<span id="cb3-39">  └───────────────────────────────────────────────────────────────────┴──────────┘                                                </span>
<span id="cb3-40"></span>
<span id="cb3-41">  Source: Statistics Canada, 2021 Census of Population (25% sample data, income year 2020).</span>
<span id="cb3-42">  </span>
<span id="cb3-43">  A few notes on interpreting these:</span>
<span id="cb3-44">  </span>
<span id="cb3-45"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  - </span>Household income is the most commonly cited figure — $114,900–$117,300 across city/metro.</span>
<span id="cb3-46"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  - </span>Economic family income is higher because it pools multiple earners in the same family unit.</span>
<span id="cb3-47"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  - </span>Individual income (~$53–56K) covers people 15+ who are not part of an economic family (e.g., single adults living alone).</span>
<span id="cb3-48"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  - </span>The gender gap is ~$5,000–$5,400 (male &gt; female) across both geographies.</span></code></pre></div></div>
</div>
<p>This gives some indication of how this works, and how the MCP helps Claude understand the question and find the relevant data, in this case opting to give a range of answers to cover the somewhat vague question. In other cases Claude may ask clarifying questions if the region or variable query yield too many results. Or no results at all and Claude widens the search categories.</p>
<p>There are several problems that, while obvious, should get stated explicitly:</p>
<ul>
<li>An MCP is just mitigating the problem that LLMs are generally bad at surfacing facts like this, and sometimes will make things up. One should view the CensusMapper MCP has a light harness that tries to steer the LLM toward more reliable ways of obtaining the data and answer (often vague) user questions, but it can’t eliminate the LLM problem of sometimes giving unreliable results.</li>
<li>Quoting numbers right from the MCP works reasonably well, but things get wonky fast when the LLM has to do calculations. Simple ratios, say share of population of a given visible minority, kind of works. The LLM will likely make the fairly common mistake of dividing by the total population when visible minority status is only available for the population in private households. But more importantly, LLMs are <em>really</em> bad at math. It may get even simple things like ratios wrong, but once things get more complicated mistakes can happen. And changing the question slightly by asking something like “Give me the top 10 cities by share of population with Turkish origin.” it completely collapses. It would have to pull the data for all cities and then rank them, that’s something an LLM will have a really hard time with.</li>
<li>At this point the CensusMapper MCP is not registered in any of the MCP server directories, it will have to be installed manually. People who know how to do that aren’t that different from the people who could call the API directly, so the benefit is very limited. (At some point we might advertise the MCP server more broadly which might spread it’s use more broadly.)</li>
<li>Census data is not the only source of socio-economic data in Canada. And it generally lags quite a bit. Right now the newest census data we have is from 2021, with income data from 2020. There is newer income data available, from the T1FF taxfiler data as well as from the Canadian Income Survey, which might be more appropriate for answering the question. (Yes, we have been contemplating of setting up an MCP server for this too.)</li>
<li>The CensusMapper MCP server is only a small step toward making it easier to interact with Canadian data via natural language queries. And it may well not be part of a more comprehensive attempt at this that implements a solution that has clear easily verifiable answers to natural language queries.</li>
</ul>
<p>To unregister the CensusMapper MCP run</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">claude</span> mcp remove censusmapper</span></code></pre></div></div>
</div>
<p>In summary, does the MCP server solve the problem of LLMs giving unreliable answers about (census) data? No.&nbsp;Does it significantly improve the accuracy and reliability of LLMs? Yes. Is it “good enough”? No, but better than not having it.</p>
</section>
</section>
</section>
<section id="the-future" class="level2">
<h2 class="anchored" data-anchor-id="the-future">The future</h2>
<p>There are lots of things that did not make it into this release of CensusMapper, but are in some form or another in the planning pipeline. In the near term we will be focused on ironing out quirks and little issue as we collect user feedback. But medium to longer term we got more exciting things in the pipeline.</p>
<section id="more-data" class="level3">
<h3 class="anchored" data-anchor-id="more-data">More data</h3>
<p>Right now CensusMapper has census data back to 1996, and StatCan has been making progress to make data from earlier censuses available in electronic form. We are planning to import data from earlier years. At the same time, there are a lot of interesting custom tabulations available that aren’t part of the regular census profiles that we import by default. For a mapping-focused system like CensusMapper we generally only consider datasets that at least go down to census tracts, and will start to set up processes that import some of these for at least the most recent census.</p>
</section>
<section id="more-tongfen" class="level3">
<h3 class="anchored" data-anchor-id="more-tongfen">More TongFen</h3>
<p>TongFen is the process of making census (and other) data comparable through time, where geographies might change but do so in a way that one can usefully build a “least common denominator” geography and re-aggregate the data, resulting in a semi-custom tabulation on the fly. We have automated this process in the <strong>TongFen</strong> R package. <span class="citation" data-cites="tongfen.2020">(<span class="nocase">von Bergmann</span> 2020c)</span> For CensusMapper we have done this for the 2011 and 2016 census geographies, which enables <a href="https://censusmapper.ca/maps/731">interesting cross-census maps</a>. It would be nice to have the ability to do this for more census years. There is a tradeoff between granularity and length of timelines, but there is value in creating these multi-census maps right in CensusMapper, and we plan on enabling more of this.</p>
</section>
<section id="dot-density-maps" class="level3">
<h3 class="anchored" data-anchor-id="dot-density-maps">Dot-density maps</h3>
<p>One notable omission from this list is dot-density maps. We had an implementation of these in the original CensusMapper <span class="citation" data-cites="dot-density.2017">(<span class="nocase">von Bergmann</span> 2017b)</span>, but there are a number of tradeoffs with these, especially on interactive maps, and we were never quite happy with the old implementation. We have plans for an improved version of this to be added in the medium term.</p>
</section>
<section id="censusmapper-chat" class="level3">
<h3 class="anchored" data-anchor-id="censusmapper-chat">CensusMapper Chat</h3>
<p>This is the logical extension of the MCP server, but it requires more work to implement a safe and verifiable way to to translate natural language queries into answers based in data. It will require some experimentation to train a foundation model to understand the language and delicacies of census data, and query and report on the data in a verifiable way. We have some ideas, but there are no guarantees we can implement a useful solution that people who can’t code can verify.</p>
</section>
</section>
<section id="upshot" class="level2">
<h2 class="anchored" data-anchor-id="upshot">Upshot</h2>
<p>We got a <a href="https://censusmapper.ca">new and shiny CensusMapper</a>, try it out, browse maps others have made, go back to maps you made previously and spiff them up, and make new maps!</p>
<p>There likely are still a number of quirks and issues, if you come across any ping us on <a href="https://censusmapper.ca/about#contact">any of our contact channels</a> so we can fix it.</p>



</section>

<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-schöley2018" class="csl-entry">
Schöley, Jonas, and Ilya Kashnitsky. 2018. <em>Tricolore: A Flexible Color Scale for Ternary Compositions</em>. The R Foundation. <a href="https://doi.org/10.32614/cran.package.tricolore">https://doi.org/10.32614/cran.package.tricolore</a>.
</div>
<div id="ref-canvas-vs-svg.2015" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2015a. <em>Canvas Vs <span>SVG</span></em>. <a href="https://doodles.mountainmath.ca/posts/2015-12-27-canvas-vs-svg/">https://doodles.mountainmath.ca/posts/2015-12-27-canvas-vs-svg/</a>.
</div>
<div id="ref-the-hidden-mortgage.2015" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2015b. <em>The <span>Hidden</span> <span>Mortgage</span></em>. <a href="https://doodles.mountainmath.ca/posts/2015-08-25-the-hidden-mortgage/">https://doodles.mountainmath.ca/posts/2015-08-25-the-hidden-mortgage/</a>.
</div>
<div id="ref-census-mapping-for-everyone.2016" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2016a. <em>Census <span>Mapping</span> for <span>Everyone</span></em>. <a href="https://doodles.mountainmath.ca/posts/2016-05-04-census-mapping-for-everyone/">https://doodles.mountainmath.ca/posts/2016-05-04-census-mapping-for-everyone/</a>.
</div>
<div id="ref-census-week.2016" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2016b. <em>Census <span>Week</span></em>. <a href="https://doodles.mountainmath.ca/posts/2016-05-02-census-week/">https://doodles.mountainmath.ca/posts/2016-05-02-census-week/</a>.
</div>
<div id="ref-comparing-censuses.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017a. <em>Comparing <span>Censuses</span></em>. <a href="https://doodles.mountainmath.ca/posts/2017-03-22-comparing-censuses/">https://doodles.mountainmath.ca/posts/2017-03-22-comparing-censuses/</a>.
</div>
<div id="ref-dot-density.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017b. <em>Dot-Density</em>. <a href="https://doodles.mountainmath.ca/posts/2017-08-24-dot-density/">https://doodles.mountainmath.ca/posts/2017-08-24-dot-density/</a>.
</div>
<div id="ref-2001-census-data-and-tongfen.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2019. <em>2001 <span>Census</span> <span>Data</span> (and <span>TongFen)</span></em>. <a href="https://doodles.mountainmath.ca/posts/2019-06-03-2001-census-data-and-tongfen/">https://doodles.mountainmath.ca/posts/2019-06-03-2001-census-data-and-tongfen/</a>.
</div>
<div id="ref-canadian-1996-census.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020a. <em>Canadian 1996 <span>Census</span></em>. <a href="https://doodles.mountainmath.ca/posts/2020-07-06-canadian-1996-census/">https://doodles.mountainmath.ca/posts/2020-07-06-canadian-1996-census/</a>.
</div>
<div id="ref-census-tract-level-t1ff-tax-data.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020b. <em>Census Tract Level <span>T1FF</span> Tax Data</em>. <a href="https://doodles.mountainmath.ca/posts/2020-04-23-census-tract-level-t1ff-tax-data/">https://doodles.mountainmath.ca/posts/2020-04-23-census-tract-level-t1ff-tax-data/</a>.
</div>
<div id="ref-tongfen.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020c. <em>TongFen</em>. <a href="https://doodles.mountainmath.ca/posts/2020-11-10-tongfen/">https://doodles.mountainmath.ca/posts/2020-11-10-tongfen/</a>.
</div>
<div id="ref-censusmapper-p-review.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2021. <em>CensusMapper (p)review</em>. <a href="https://doodles.mountainmath.ca/posts/2021-10-17-censusmapper-p-review/">https://doodles.mountainmath.ca/posts/2021-10-17-censusmapper-p-review/</a>.
</div>
<div id="ref-census-drilldown.2015" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Alejandro Cervantes</span>. 2015a. <em>Census <span>Drilldown</span></em>. <a href="https://doodles.mountainmath.ca/posts/2015-10-24-census-drilldown/">https://doodles.mountainmath.ca/posts/2015-10-24-census-drilldown/</a>.
</div>
<div id="ref-census-mapper.2015" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Alejandro Cervantes</span>. 2015b. <em>Census <span>Mapper</span></em>. <a href="https://doodles.mountainmath.ca/posts/2015-09-28-census-mapper/">https://doodles.mountainmath.ca/posts/2015-09-28-census-mapper/</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{von_bergmann2026,
  author = {von Bergmann, Jens and Chen, Leia},
  title = {CensusMapper 2.0},
  date = {2026-05-04},
  url = {https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2026" class="csl-entry quarto-appendix-citeas">
Bergmann, Jens von, and Leia Chen. 2026. <span>“CensusMapper
2.0.”</span> <em>MountainDoodles</em>, accepted, May 4. <a href="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/">https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/</a>.
</div></div></section></div> ]]></description>
  <category>CensusMapper</category>
  <category>OSM</category>
  <category>geeky</category>
  <category>tongfen</category>
  <guid>https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/</guid>
  <pubDate>Mon, 04 May 2026 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2026-05-04-censusmapper-20/images/cm-logo.png" medium="image" type="image/png" height="166" width="144"/>
</item>
<item>
  <title>Introducing CanViz</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/</link>
  <description><![CDATA[ 






<p><img src="https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/images/canviz_logo.png" alt="CanViz logo" style="max-width:300px;width=30%;min-width=100px;float:right;padding: 5px;"> Over the holidays I had some downtime jet-lagged in the early morning and then on various train rides, and I decided to try my hand on a little side project. I had various versions of this in the back of my mind for a while, and got recently reminded of this after discussions with Stephen Rouse who not long ago built something along those lines.</p>
<p>The idea is simple, build a web app to dynamically explore StatCan (or other) data, select time series, and plot them interactively, without needing any specialized tools. Ideally with the ability to download the selected data or the resulting graph. With the <a href="https://mountainmath.github.io/cansim/">cansim R package</a> <a href="https://www.dshkol.com">Dmitry Shkolnik</a> and I have built powerful functionality to do this for R users and have full flexibility and control, including offline use. But not everyone is comfortable in R, and making Canadian data more accessible to a broader audience is something dear to my heart. And tools like <a href="https://censusmapper.ca/">CensusMapper</a> have shown that there is a real appetite for easy to use web based tools to explore Canadian data, with high usage and engagement since I built this over ten years ago.</p>
<section id="why-now" class="level1">
<h1>Why now?</h1>
<p>The main reason I haven’t done this before is that it takes time. But this that has fundamentally changed over the last year or so. This kind of web-app is a fairly simple and straight-forward application using standard javascript frameworks and StatCan APIs. And LLMs, in particular Claude Code, can do most of the work for this kind of thing with only a little hand-holding, dramatically accelerating development of such an app. Taking it from a week (estimated) of full time work to just a couple of (longish) train rides with most of the time spent reading while the LLM is noodling away writing code, only requiring intermittent intervention, updated instructions, and occasional hand holding and reading of code when it gets stuck to give more pinpointed instructions to guide it back on track. Plus some light manual editing at the end for fine-tuning.</p>
</section>
<section id="building-the-app" class="level1">
<h1>Building the app</h1>
<p>There is nothing special about the process, LLMs, and in particular Claude Code, have found wide adoption in the industry and this is a fairly standard workflow. But many outsiders don’t have a view into how LLMs are rapidly changing processes in the industry and there probably is value to quickly sketch the process of creating this kind of web app aimed at a broader audience.</p>
<p>Two years ago the way such an app would have gotten created is by someone with strong familiarity of front end web frameworks to collaborate with someone familiar with StatCan data and how people use data to sketch out and develop the app. Or a single person combining those skills, but that is rare. Just a year ago half of the front-end work would have been shortcut by asking an LLM to write a bare-bones template to get things started, cutting the front-end work in half. Today all that’s required is a bit of superficial knowledge of front-end web frameworks to guide the process at a high level, trouble-shoot, and at the end manually refine things a bit.</p>
<p>How does it work? Pretty simple. To get it started I dropped into the Claude Code console, selected Sonnet 4.5 as the model<sup>1</sup>, enter <em>plan mode</em> and instructed Claude to plan a static web app leveraging <a href="https://www.statcan.gc.ca/en/developers/wds/user-guide">StatCan API</a> using <a href="https://react.dev">react</a> and <a href="https://observablehq.com/plot/">observable plot</a> for graphing. It should allow browsing StatCan tables, browse and select dimensions and members from specific tables, and fetch the corresponding data and metadata and plot the result.</p>
<p>Claude took some time to browse the StatCan API specifications, did some web searches, and presented me with a detailed implementation plan. I asked it to make some tweaks and then gave it the go ahead to build the app. Claude noodled along and came back 20 minutes later with a somewhat functional bare-bones implementation. Some more back and forth pointing it to various problems in the app, and I had a basic app. All in all it took maybe an hour and half to get there, much of the time on my side was spent making coffee and preparing breakfast while Claude was doing work in the background.</p>
<p>That’s when the bulk of the work started. This bare-bones version was usable, but barely so. What was needed is to help Claude design (and rearrange) the UI elements to make them more intuitive and informative, to properly access and parse the metadata and integrate it so users understand what they are doing. At this point it also required to also check through the code and tell Claude to redesign some parts. Partially because I have changed my mind on some UI choices and workflows half way, and partially with an eye toward future extensions. And to fit my idiosyncratic preferences.</p>
<p>Then came a phase to optimize the caching and API calls to minimize loading time for users and drag on StatCan APIs. This again required some hand-holding and quite specific instructions.</p>
<p>The last phase was a bit more tedious the goal was to fine-tune the user flows through the app and add styling. This involved a mixture of instructions to Claude and light manual editing of code. Some of this would probably have gone faster if I had taken full control and made all edits myself, but offloading a bunch of that to Claude gave me more time to read and was a net positive in terms of my time. That’s pretty much it.</p>
<p>I should add that while this sounds (and was) stupendously easy to do, it does require some expertise to give the right directions to Claude. Expertise both in terns of a detailed understanding the data and StatCan APIs, as well as user needs and common use cases. And expertise in front-end web frameworks to give clear instructions on how to implement the app and to effectively troubleshoot when Claude manoeuvred itself into a corner. Claude will get better at the some of this, in particular the last part. Already at this point one can probably trade lack of expertise in front-end development for more annoying back and forth with Claude to get things working. It’s a gradient of being super-effective in instructions and needing more back and forth with Claude to resolve issues, and I was definitely not always all that effective and wasted some time (and tokens) in the process.</p>
<p>There were also some quintessential LLM moments. Proper handling of dates and time zones was one such example where Claude Code struggled. Which goes back to the nature of LLMs, and the fact that there is an awful lot of code out there that does not handle dates and time zones properly and LLMs lack the ability to independently reason out the correct algorithm. This could have probably been resolved by repeatedly pointing out to Claude that some results were incorrect, with Claude repeatedly trying to fix it and probably succeeding at some point. But I decided to shortcut the process and just intervene manually to fix it. When one gets to non-standard tasks, or tasks that have often gotten implemented poorly in the wild, LLMs struggle and manual intervention is often easier.</p>
</section>
<section id="the-app" class="level1">
<h1>The app</h1>
<p>The app itself is quite straight-forward, it has three pages, one for data discovery, one for selecting time series, and one for plotting.</p>
<section id="data-discovery" class="level2">
<h2 class="anchored" data-anchor-id="data-discovery">Data discovery</h2>
<p>The landing page allows for browsing the 8,000+ StatCan data tables and, importantly, filtering and searching the tables to aid data discovery. Doing so interactively is quite convenient and in many way beats my previous preferred way of doing this via the <strong>cansim</strong> R package. The web app allows to filter by subject, survey, frequency, current vs archived status, geographic breakdown, reference date, and keywords in the table title or description. The keyword search tries to strike a balance between powerful search functionality and simplicity of use, allowing for exact match phrase search (in quotes) and allowing for exclusion of phrases (prefixed with a minus sign).</p>
<p>This makes it easy to find relevant tables.</p>
</section>
<section id="data-selection" class="level2">
<h2 class="anchored" data-anchor-id="data-selection">Data selection</h2>
<p>Once a table is selected the user can proceed to the data selection page. Here one can explore the table dimensions and select individual members from each dimension to filter the data down to the desired time series to generate the appropriate coordinates. Once done, the selected time series can be added to the plot but generating the appropriate vectors.<sup>2</sup></p>
</section>
<section id="plotting" class="level2">
<h2 class="anchored" data-anchor-id="plotting">Plotting</h2>
<p>Once data has been selected we can plot it. Going on the plot page will load the data for the selected vectors and plot the time series. For convenience there are some limited options to customize the plot. Individual series can be turned on or off in the plot and the time range can be narrowed down via brushing to aid dynamic exploration.</p>
<p>For added convenience there is functionality to download the data as CSV or the graph as PNG, as well as the R code to pull in the data in R using the <strong>cansim</strong> R package and reproduce the graph.</p>
<p>The app can be accessed at <a href="https://canviz.mountainmath.ca">canviz.mountainmath.ca</a>. There are still some quirks right now that I will iron out as I find time, but it’s quite functional. Give it a whirl!</p>
<div class="quarto-video"><video id="video_shortcode_videojs_video1" class="video-js vjs-default-skin vjs-big-play-centered vjs-fluid" controls="" preload="auto" data-setup="{}" title="CanViz demo"><source src="https://mountainmath.s3.ca-central-1.amazonaws.com/public/canviz-demo3.mp4"></video></div>
</section>
</section>
<section id="next-steps" class="level1">
<h1>Next steps</h1>
<p>This is a basic version of the app I had in mind, there are lots of ways to expand it and make it more useful:</p>
<ul>
<li>Most importantly bringing in different data sources, for example integrating <a href="https://mountainmath.github.io/cmhc/">CMHC data</a>, <a href="https://mountainmath.github.io/canbank/">Bank of Canada data</a> which I have already done for R users.</li>
<li>Allow for more advanced plotting options, including custom functions to allow combining of several time series.</li>
<li>Add ways to save several views/user states so that users can build up and share a repertoire of graphs they can revisit as data updates.</li>
<li>Provide more stable data access, some StatCan APIs can be unavailable for some time between midnight and 8:30am eastern, and every now and then the StatCan APIs go down during daytime too. These are quite annoying design failures of the StatCan API, it’s hard to understand how in this day and age StatCan designed a system with this much planned downtime (and high propensity for unplanned downtime).</li>
<li>Add functionality for selecting different dimensions for the x-axis, not just time.</li>
<li>Add functionality for visualizing data on a map, at least for high level geographies.</li>
<li>See where users take this and learn about use cases I have not thought about and continue to improve user experience.</li>
<li>Add in ways to display uncertainty (when available) and information on resolution/rounding of data.</li>
<li>Be more principled about units. That includes better handling of log scale depending on the data type (e.g.&nbsp;percentage or index data, and making log scale the default for some data types), and warning users if they plot the different data types on the same graph.</li>
<li>Be more principled about aggregating data depending on the data type, for example use geometric and arithmetic mean as appropriate</li>
<li>Add functionality for showing year over year change or month over month change.</li>
</ul>
<p>Some of these can be implemented within the current standalone web app framework, others require setting up a dedicated server that can store user information. And possibly setting up a separate database server to improve data availability and stability.</p>


</section>


<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>I don’t use Claude extensively and am on the lowest-cost plan, picking Sonnet over the newer Haiku gave me a bit more mileage although I might have missed out in terms of performance of the model.↩︎</p></li>
<li id="fn2"><p>In theory this step could get skipped, one important advantage of using vectors instead of table and coordinates to fetch the data is that some combinations of members aren’t valid, and the app will at this stage notify users of such cases. A disadvantage is that some tables, in paticular census tables, don’t have vectors, so they can’t currently be plotted. But the current plot setup is focused on time series and not set up to plot point in time data like a single year census. <a href="https://censusmapper.ca">CensusMapper</a> is a better tool for exploring census data interactively, although CensusMapper only hosts census profile data and not the finer cross tabulations.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{introducing-canviz.2026,
  author = {{von Bergmann}, Jens},
  title = {Introducing {CanViz}},
  date = {2026-01-11},
  url = {https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2026" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann. 2026. <span>“Introducing CanViz.”</span>
<em>MountainDoodles</em>, accepted, January 11. <a href="https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/">https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/</a>.
</div></div></section></div> ]]></description>
  <category>cansim</category>
  <category>geeky</category>
  <guid>https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/</guid>
  <pubDate>Sun, 11 Jan 2026 08:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2026-01-11-introducing-canviz/images/canviz_logo.png" medium="image" type="image/png" height="144" width="144"/>
</item>
<item>
  <title>The trouble with municipal-level population projections</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/12/07/the-trouble-with-municipal-level-population-projections/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cancensus)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dotdensity)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span></code></pre></div></div>
</details>
</div>
<p>Are people liquids or solids?</p>
<p>Trick question: they’re kind of both. This matters in terms of how we track people and project their location forward in time. There are basic demographic methods that effectively take people as solids. We can see where they are now. We can see how they’ve been moving recently. We can age them forward in time, including adding new little people and imagining older people dying off. And we can project forward how many people we’ll have in the future.</p>
<p>But people are also liquid. They slosh around a bit, but they eventually tend to settle downhill into the places where there are containers for them. Here our best bet in terms of projecting people’s location forward in time is to figure out the lay of the land and where the most likely containers are going to be located.</p>
<p>Sometimes our liquid and solid projections match up ok. But other times they don’t. Let’s make this discussion a little more solid by zooming in to take a look at a potential divergence in projections right here in Metro Vancouver.</p>
<p>When - if ever - will suburban Surrey surpass the population of the City of Vancouver?</p>
<p>The solid answer to this question tends to be that it’s going to happen, and quite soon! The liquid answer is much less certain on this point, leaving it mostly contingent on how much housing gets built where.</p>
<section id="solid-demographic-models" class="level1">
<h1>Solid demographic models</h1>
<p>We can see the answer to when Surrey will surpass the population of Vancouver in recently released <a href="https://www150.statcan.gc.ca/n1/pub/17-20-0003/172000032025001-eng.htm">StatCan population projections at the municipal (census subdivision) level</a>. StatCan’s method, in a nutshell, treats people as solid, aging them forward in place (within CSDs) via a crude approximation from past trends and made to sum into earlier calculated projections across the broader region (CD). Past net migration enters into past trends by age group and becomes extrapolated into the future. In trying to avoid running into absurd scenarios like negative population or unrealistically large growth scenarios in select areas and subgroups they crudely extrapolate areas and age groups that historically have been growing linearly and those that have been declining exponentially (while using language that would make any high school math teacher tear their hair out, but never mind that). More holistically this could be dealt with by a mechanism that implements regression to the mean over time.</p>
<p>We can see a slightly different answer to when Surrey will surpass the population of Vancouver in more standard provincial projections released by BC Stats in British Columbia. BC Stats also treats people as solids, but applies <a href="https://www2.gov.bc.ca/assets/gov/data/statistics/people-population-community/population/people_2025_population_projections.pdf">more refined methods to projecting age cohorts forward based upon distinct components of change</a> (fertility, mortality, and migration) estimated from the past with some adjustments for current policies and future expectations, especially concerning immigration.</p>
<p>Figure&nbsp;1 shows both of these projections, for BC Stats, the cross-over where Surrey surpasses Vancouver is imminent, happening sometime just after the Census, by the end of 2026. For StatCan, it looks like it’s one year further away, happening by the end of 2027.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">metro_van_cities <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"CSD"</span>,CMA_UID<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;">"59933"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_unique_names_to_region_list</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(Name,<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;">coalesce</span>(pop,<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;">|&gt;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span>region,Name)</span>
<span id="cb2-6"></span>
<span id="cb2-7">bc_projections <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>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/Population_Projections_metro_van.csv"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_pattern=</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;">"(.+)_(</span><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;">d{4})"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</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;">"Series"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", District Municipality"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (DM)"</span>,Municipality) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-10">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", City of"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (CY)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01-01"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Date,Municipality,Name,Series,Population) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"Name"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Series,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimates"</span>,</span>
<span id="cb2-17">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Projection"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Projections"</span>))</span>
<span id="cb2-18"></span>
<span id="cb2-19">csd_estimates <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0155"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<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;">4</span>) <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;">"5915"</span>,</span>
<span id="cb2-21">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>) </span>
<span id="cb2-24"></span>
<span id="cb2-25">csd_projections <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0162"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,</span>
<span id="cb2-27">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>,</span>
<span id="cb2-28">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Projection scenario M1: medium-growth"</span>,</span>
<span id="cb2-29">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<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;">4</span>) <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;">"5915"</span>,</span>
<span id="cb2-30">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>) </span>
<span id="cb2-33"></span>
<span id="cb2-34"></span>
<span id="cb2-35">all_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;">bind_rows</span>(</span>
<span id="cb2-36">    csd_projections <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan projections"</span>),</span>
<span id="cb2-37">    csd_estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statcan estimates"</span>)</span>
<span id="cb2-38">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Population=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(bc_projections <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Stats"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Series<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;">"Projections"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-01-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-42">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Stats projections"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Series,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Statcan estimates"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan projections"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Stats projections"</span>)))</span>
<span id="cb2-44"></span>
<span id="cb2-45">all_data_cleaned  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> all_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> ((.) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(Name,Series) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Name))) </span>
<span id="cb2-47"></span>
<span id="cb2-48">line_types <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;">setNames</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;">"solid"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>),</span>
<span id="cb2-49">                           <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;">"Statcan estimates"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan projections"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Stats projections"</span>))</span>
<span id="cb2-50">source_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>trios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c157,</span>
<span id="cb2-51">                           <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;">"Statcan estimates"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan projections"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Stats projections"</span>))</span>
<span id="cb2-52"></span>
<span id="cb2-53">all_data_cleaned <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-54">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surrey"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015-01-01"</span>,Date<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;">"2035-01-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-56"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Population, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span>Series,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span>Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-57">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-58">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>source_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 years"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Jul %Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),</span>
<span id="cb2-62">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-63">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population Estimates and Projections for Vancouver and Surrey"</span>,</span>
<span id="cb2-64">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb2-65">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population"</span>,</span>
<span id="cb2-66">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Muncipality"</span>,</span>
<span id="cb2-67">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-van-surrey-pop-estimates" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-van-surrey-pop-estimates-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-van-surrey-pop-estimates-1.png" id="fig-van-surrey-pop-estimates" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-van-surrey-pop-estimates-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can see the cross-over between Vancouver and Surrey is heavily driven by the projected decline in Vancouver’s population. This is striking. Where does it come from? As it turns out, temporary residents arriving in the metro area of Vancouver have more often landed in the City of Vancouver than the City of Surrey. Recent rollbacks in temporary residents due to Canadian immigration policy have been extrapolated forward, and have been built into the solid population models of both StatCan and BC Stats, where they enter in just slightly different ways. The assumption is that if you turn off this conveyor belt of temporary residents, then the City of Vancouver’s population will decline more than the City of Surrey’s. But is this correct? We could work with different assumptions. Let’s think about our conveyor belt as more like a stream, one of many feeding the pond of our metropolitan area. What happens to the deepest part of the pond - our central city - if this particular stream gets diverted?</p>
</section>
<section id="liquid-demography" class="level1">
<h1>Liquid demography</h1>
<p>Where will people sloshing around Metro Vancouver land? As it turns out, they land mostly where there’s housing to contain them. If we believe this, then projecting in the future should be based mostly on where housing is likely to land rather than our cohort projections. To make this more concrete, let’s think about housing growth.</p>
<p>Overall, both Vancouver and Surrey have been adding housing in recent years. To better match housing to population we would want to look more broadly at housing services provided, not just number of housing units. We don’t have open data on square footage or number of bedrooms added, but we can use dwelling types, combined with household size estimates for each dwelling type, to derive a rough and imperfect measure of growth in housing capacity and relate the to population growth. We show the household size by type estimates derived from the 2021 census in Table&nbsp;1.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">dwelling_types <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;">"Single"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Semi-Detached"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Row"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Apartment"</span>)</span>
<span id="cb3-2"></span>
<span id="cb3-3">hhsize_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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0240"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>),</span>
<span id="cb3-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Household size (8)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average household size"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Household size"</span>),</span>
<span id="cb3-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Number of bedrooms (6)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Number of bedrooms"</span>,</span>
<span id="cb3-7">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Statistics (3C)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of private households"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Tenure (4)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Tenure"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>VALUE,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Structural type of dwelling (10)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Household size (8)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Structural type of dwelling"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb3-14">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single-detached house"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single"</span>,</span>
<span id="cb3-15">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Semi-detached house"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Semi-Detached"</span>,</span>
<span id="cb3-16">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Row house"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Row"</span>,</span>
<span id="cb3-17">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Apartment in a building that has fewer than five storeys"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Apartment"</span>,</span>
<span id="cb3-18">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Apartment in a building that has five or more storeys"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Apartment"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hhsize=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Average household size</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total - Household size</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> dwelling_types) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>dwelling_types))</span>
<span id="cb3-22"></span>
<span id="cb3-23">hhsize_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities, <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;">"GeoUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(Name,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro Vancouver"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>GeoUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hhsize=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(hhsize,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>hhsize) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-30">tinytable<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;">tt</span>()</span></code></pre></div></div>
</details>
<div id="tbl-hhsize" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned" id="tbl-hhsize-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1
</figcaption>
<div aria-describedby="tbl-hhsize-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_ejom6v5py5i8h0h7s6un(i, j, css_id) {
          var table = document.getElementById("tinytable_ejom6v5py5i8h0h7s6un");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_ejom6v5py5i8h0h7s6un(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_ejom6v5py5i8h0h7s6un");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '3', j: 0 }, { i: '3', j: 1 }, { i: '3', j: 2 }, { i: '3', j: 3 }, { i: '3', j: 4 },  ], css_id: 'tinytable_css_fxcyk79zzapoyn6lj47o',}, 
          { positions: [ { i: '0', j: 0 }, { i: '0', j: 1 }, { i: '0', j: 2 }, { i: '0', j: 3 }, { i: '0', j: 4 },  ], css_id: 'tinytable_css_lsdz6ycsadm80l79y99c',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_ejom6v5py5i8h0h7s6un(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script>

    <style>
      /* tinytable css entries after */
      .table td.tinytable_css_fxcyk79zzapoyn6lj47o, .table th.tinytable_css_fxcyk79zzapoyn6lj47o { border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_lsdz6ycsadm80l79y99c, .table th.tinytable_css_lsdz6ycsadm80l79y99c { border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
    <div class="container">
      <table class="table table-borderless" id="tinytable_ejom6v5py5i8h0h7s6un" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        
              <tr>
                <th scope="col" data-row="0" data-col="0">Name</th>
                <th scope="col" data-row="0" data-col="1">Single</th>
                <th scope="col" data-row="0" data-col="2">Semi-Detached</th>
                <th scope="col" data-row="0" data-col="3">Row</th>
                <th scope="col" data-row="0" data-col="4">Apartment</th>
              </tr>
        </thead>
        
        <tbody>
                <tr>
                  <td data-row="1" data-col="0">Metro Vancouver</td>
                  <td data-row="1" data-col="1">3.1</td>
                  <td data-row="1" data-col="2">2.7</td>
                  <td data-row="1" data-col="3">2.8</td>
                  <td data-row="1" data-col="4">1.9</td>
                </tr>
                <tr>
                  <td data-row="2" data-col="0">Vancouver</td>
                  <td data-row="2" data-col="1">2.9</td>
                  <td data-row="2" data-col="2">2.7</td>
                  <td data-row="2" data-col="3">2.6</td>
                  <td data-row="2" data-col="4">1.7</td>
                </tr>
                <tr>
                  <td data-row="3" data-col="0">Surrey</td>
                  <td data-row="3" data-col="1">3.4</td>
                  <td data-row="3" data-col="2">2.6</td>
                  <td data-row="3" data-col="3">2.9</td>
                  <td data-row="3" data-col="4">2.3</td>
                </tr>
        </tbody>
      </table>
    </div>
<!-- hack to avoid NA insertion in last line -->
</div>
</div>
</figure>
</div>
</div>
<p>Dwellings of most types tend to contain more people in Surrey than in Vancouver. This likely reflects roomier dwellings in Surrey, indicating greater housing services being provided on average per dwelling, though it’s possible differences are also picking up other patterns, like more doubling up. Overall, our basic assumption is that on average dwellings produced in Surrey will probably contain slightly more of our liquid people than in the City of Vancouver. Multiplying these figures with our data on recent completions (with a minor adjustment for demolitions), we can roughly estimate the net housing capacity recently added per year in Vancouver and Surrey. The resulting estimated <em>housing capacity</em> growth is shown next to StatCan estimated population growth in Figure&nbsp;2.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">summarize_annual_by_type <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data){</span>
<span id="cb4-2">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">    <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=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb4-6">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">months=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(months<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;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>months)</span>
<span id="cb4-9">}</span>
<span id="cb4-10"></span>
<span id="cb4-11">van_completions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmhc<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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_annual_by_type</span>()</span>
<span id="cb4-13"></span>
<span id="cb4-14">surrey_completions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmhc<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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_annual_by_type</span>()</span>
<span id="cb4-16"></span>
<span id="cb4-17">yvr_completions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmhc<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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_annual_by_type</span>()</span>
<span id="cb4-19">  </span>
<span id="cb4-20"></span>
<span id="cb4-21"></span>
<span id="cb4-22">demolition_fudge <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.93</span></span>
<span id="cb4-23"></span>
<span id="cb4-24">completions_combined <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;">bind_rows</span>(</span>
<span id="cb4-25">  van_completions <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>),</span>
<span id="cb4-26">  surrey_completions <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>),</span>
<span id="cb4-27">  yvr_completions <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915"</span>)</span>
<span id="cb4-28">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(hhsize_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-30">  <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;">change=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Total<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>demolition_fudge<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>hhsize),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Metric=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing capacity growth"</span>)</span>
<span id="cb4-32">  </span>
<span id="cb4-33">pop_combined <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;">bind_rows</span>(</span>
<span id="cb4-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0155"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-35">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>),</span>
<span id="cb4-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0152"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-38">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915"</span>),</span>
<span id="cb4-39">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>,</span>
<span id="cb4-40">           Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-41">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>)</span>
<span id="cb4-42">  )<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>REF_DATE,GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Population=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change=</span>Population <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;">lag</span>(Population, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>GeoUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Population) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Metric=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population growth"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(change))</span>
<span id="cb4-48"></span>
<span id="cb4-49"></span>
<span id="cb4-50"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(pop_combined,</span>
<span id="cb4-51">          completions_combined,) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(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;">2002</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-53"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>change, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span>Metric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-54">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>,</span>
<span id="cb4-56">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_labeller</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;">"5915"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"City of Vancouver"</span>,</span>
<span id="cb4-57">                                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"City of Surrey"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c085) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-62">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population vs Housing Capacity Growth"</span>,</span>
<span id="cb4-63">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb4-64">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>,</span>
<span id="cb4-65">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb4-66">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMHC Scss and StatCan Tables 17-10-0152, 17-10-0155, 98-10-0240"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-housing-capacity-pop-growth" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-housing-capacity-pop-growth-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-housing-capacity-pop-growth-1.png" id="fig-housing-capacity-pop-growth" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-housing-capacity-pop-growth-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>The relationship is spiky and imperfect, reflecting in part the crudeness of our estimation as well as the compressibility of liquid demographics exhibiting short term adjustments in household formation and doubling up to smooth out mismatches. But generally as we add more housing, we also add more population. This relationship holds up pretty well until COVID hits in 2020. By 2021, the population of the City of Vancouver dropped in spite of additions to housing. Multiple issues account for this shift: immigrants stopped arriving, universities and workplaces went remote, and people increasingly valued more room at home (for work-from-home offices) relative to proximity to downtown. This last factor likely accounts for some of suburban Surrey’s resilience. Bigger homes and fewer commutes changed the landscape of demand. But people are liquid, and slosh, slosh, you’ll never guess what happened next. Lots of people sloshed back again!</p>
<p>This sloshing is important. Like a tsunami, the rollback in the City of Vancouver was temporary, to be followed by an inundation that completely erased the previous year’s loss in population in the City. What limited the City of Vancouver’s growth at that point? Housing. There was only so much available. People could double up (and they did!), exceeding the growth rate in housing capacity. But otherwise people would have to find room in the suburbs, which they also did. We can see from Surrey’s population that it also boomed. Surrey also saw lots of doubling up, but the boom there was further facilitated by a stronger underlying boost to housing capacity than we saw in the City of Vancouver.</p>
<p>Which brings us back to the differences between liquid and solid demographics. In a liquid demography, people will slosh around, but eventually make their way toward settling in the housing that’s available in the places they want to live. There are limits to how many people can be added, but we have a rough idea where they want to be. Accordingly, we need to pay attention mostly to how much supply has been created to meet the landscape of demand. And we don’t want to take housing for granted! In a solid demography, especially one where we don’t even put people in households but just focus on age cohorts, housing and its constraints are effectively ignored.</p>
<p>Ideally we want to bring liquid and solid treatments of people together. Both population dynamics and housing constraints matter. <span class="citation" data-cites="mulder2006">(Mulder 2006)</span> Because it is the case that housing doesn’t always get filled up. Just like housing doesn’t magically appear in response to population change, people don’t suddenly appear in response to additions to housing supply. But ignoring housing constraints is especially problematic when we’re using population projections to estimate how much housing we need. More on that below!</p>
</section>
<section id="vancouver-vs.-surrey-in-a-liquid-world" class="level1">
<h1>Vancouver vs.&nbsp;Surrey in a Liquid World</h1>
<p>Let’s get back to the horse race between Vancouver and Surrey. In terms of projecting when (or if) Surrey will overtake Vancouver in population, the liquid demography asks first, who is building more housing? Then, how is the landscape of demand changing? And finally, just as a check, are there any good reasons to believe we’ll see housing left empty even when people want to live there?</p>
<p>Figure&nbsp;3 provides information on who is building more housing. Here “completions” refer to what’s just been added, with “starts” and “under construction” telling us what’s coming down the pipeline. In general, we’d expect completions to lag starts, but note the rise in “under construction” visible in both cities, which reflects increasingly lengthy construction timelines, reducing the predictability for when things will finish. <span class="citation" data-cites="under-construction.2017">(<span class="nocase">von Bergmann</span> 2017b)</span></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">van_sur_completions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metro_van_cities <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^Vancouver|Surrey"</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(GeoUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(\(geo) {</span>
<span id="cb5-5">    <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;">"Starts"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(\(series) {</span>
<span id="cb5-7">        cmhc<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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> series, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, </span>
<span id="cb5-8">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> geo) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_annual_by_type</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span>series)</span>
<span id="cb5-11">      }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-12">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb5-13">               cmhc<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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Under Construction"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, </span>
<span id="cb5-14">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> geo) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-15">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m"</span>)<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;">"07"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-16">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>),</span>
<span id="cb5-17">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Under Construction"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-18">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, Year , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span>Value, Series, GeoUID)</span>
<span id="cb5-19">      ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-20">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span>geo)</span>
<span id="cb5-21">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>)</span>
<span id="cb5-23"></span>
<span id="cb5-24">van_sur_completions <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Total,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Series<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-30">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_fill_manual(values=sanzo::duos$c114, guide="none") +</span></span>
<span id="cb5-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing construction in Vancouver and Surrey"</span>,</span>
<span id="cb5-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of units"</span>,</span>
<span id="cb5-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMHC Scss"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-van-surrey-starts-completions" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-van-surrey-starts-completions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-van-surrey-starts-completions-1.png" id="fig-van-surrey-starts-completions" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-van-surrey-starts-completions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can see 2025 was a very good year for Surrey completions. But historically Vancouver has been building more dwelling units, and its pipeline looks much more robust. Still, as we have noted Vancouver’s dwellings have generally been smaller. We don’t have good historical open data on number of bedrooms, but we can continue to proxy for that by breaking data out by dwelling type. Importantly, Surrey is starting to run out of room for greenfield development due to the Agricultural Land Reserve, and it’s increasingly building rowhouses and apartments instead. New single-family detached dwellings built in Surrey are going to look increasingly like those built in Vancouver - either replacing a tear-down, in which case they don’t contribute much to supply, or laneway homes, which generally accommodate fewer people.</p>
<p>At the same time the City of Vancouver has several planning initiatives that look at loosening up regulation to allow more apartments in several key areas; the Broadway Corridor, Heather Lands, Jericho Lands, the Villages initiative and others. This includes plans to densify around Skytrain stations. Of course, this also applies to Surrey, but demand is much higher in the City of Vancouver, as can be seen by looking at the modelled price surface for multiplexes from our report on the provincial SSMUH and TOA initiatives. <span class="citation" data-cites="bc_ssmuh_toa.2023">(<span class="nocase">von Bergmann et al.</span> 2023)</span></p>
<div id="fig-yvr-price-surface" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-yvr-price-surface-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/images/yvr_multiplex_price_surface.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-yvr-price-surface-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Price surfaces across Metro Vancouver (SSMUH and TOA Scenarios in British Columbia)
</figcaption>
</figure>
</div>
<p>The price surface in Figure&nbsp;4 provides a glimpse at the underlying landscape of desire. Residential space in Surrey is painted in blue and green, at much lower price points than the same space in Vancouver, neatly split between the red of Westside and orange of Eastside. People seem to generally want to move toward downtown Vancouver. What holds them back? Primarily the lack of housing. Similarly, CMHC’s report on supply constraints highlights spatial differential in unmet demand for housing within Metro Vancouver. <span class="citation" data-cites="gensey_condos.2018">(CMHC 2018)</span> This kind of landscape suggests to a liquid demographer that if you divert one set of streams toward downtown Vancouver, like non-permanent resident inflows, they’re most likely going to be replaced by other streams that were also headed in that direction, but got backed up to places like Surrey by the competition for limited container space.</p>
<p>Figure&nbsp;5 gives another view into this by showing workers by whether they commute within our outside of their city of residence on their way to work.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">commute_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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DA"</span>,</span>
<span id="cb6-2">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_7617"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">same_csd=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_7620"</span>),</span>
<span id="cb6-3">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">different_csd=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,workers <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> same_csd)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">van_sur=</span>CSD_UID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(different_csd,same_csd), <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;">replace_na</span>(.,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))) </span>
<span id="cb6-7"></span>
<span id="cb6-8"></span>
<span id="cb6-9">random_round <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb6-10">    v <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.integer</span>(x)</span>
<span id="cb6-11">    r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>v</span>
<span id="cb6-12">    test <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stats<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;">runif</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(r), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>)</span>
<span id="cb6-13">    add<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;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(r))</span>
<span id="cb6-14">    add[r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>test] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L</span>
<span id="cb6-15">    value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> v<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>add</span>
<span id="cb6-16">    value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,value)</span>
<span id="cb6-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(value)</span>
<span id="cb6-18">}</span>
<span id="cb6-19"></span>
<span id="cb6-20"></span>
<span id="cb6-21">scale <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span></span>
<span id="cb6-22">commute_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> commute_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-23">      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;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(different_csd,same_csd),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>scale))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-24">      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;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(different_csd,same_csd),random_round))</span>
<span id="cb6-25"></span>
<span id="cb6-26">all_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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"same_csd"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"different_csd"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(cat) {</span>
<span id="cb6-28">    dd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> commute_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-29">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.name</span>(cat)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb6-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_sample</span>(dd,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span>dd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(cat),</span>
<span id="cb6-31">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warn_if_not_integer=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-32">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-33">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span>cat)</span>
<span id="cb6-34">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_sample</span>(.,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(.), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Type,</span>
<span id="cb6-38">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"same_csd"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Same city"</span>,</span>
<span id="cb6-39">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"different_csd"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Different city"</span>))</span>
<span id="cb6-40"></span>
<span id="cb6-41">cov_sur_geo <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CSD=</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;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>)</span>
<span id="cb6-42"></span>
<span id="cb6-43"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(all_data) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-45">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geom_roads() +</span></span>
<span id="cb6-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Type),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>cov_sur_geo,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">metro_van_bbox</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tight"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">override.aes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</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;">alpha=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c079) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">123.25</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</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;">123.25</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend=</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;">123.12</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.29</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.25</span>,</span>
<span id="cb6-54">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">curvature=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,</span>
<span id="cb6-55">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">122.95</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.05</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surrey"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</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;">122.95</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend=</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;">122.82</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.06</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.13</span>,</span>
<span id="cb6-58">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">curvature=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,</span>
<span id="cb6-59">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of work status in Metro Vancouver"</span>,</span>
<span id="cb6-61">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of work"</span>,</span>
<span id="cb6-62">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-63">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan census 2021"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-city-work-place" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-city-work-place-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-city-work-place-1.png" id="fig-city-work-place" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-city-work-place-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">commute_flow_lookup <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<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;">4</span>) <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;">"5915"</span>,</span>
<span id="cb7-3">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>()</span>
<span id="cb7-7"></span>
<span id="cb7-8">metro_names <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"CSD"</span>,CMA_UID<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;">"59933"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_unique_names_to_region_list</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span>region,Name)</span>
<span id="cb7-12"></span>
<span id="cb7-13">por_lookup <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;">get_cansim_column_categories</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of residence"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id=</span>Hierarchy,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[|</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">]"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Classification Code</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,UID)</span>
<span id="cb7-16"></span>
<span id="cb7-17">pow_lookup <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;">get_cansim_column_categories</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of work"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Member ID</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Member Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(por_lookup, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>))</span>
<span id="cb7-20"></span>
<span id="cb7-21">yvr_sur_por <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pow_lookup <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(UID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>))</span>
<span id="cb7-23"></span>
<span id="cb7-24">workers <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Gender (3)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Gender"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-28">  <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;">Workers=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(VALUE),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_names, <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;">"GeoUID"</span>)</span>
<span id="cb7-30"></span>
<span id="cb7-31">jobs <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Place of work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> yvr_sur_por<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Gender (3)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Gender"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-35">  <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;">Workers=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(VALUE),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Place of work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(yvr_sur_por, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of work"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_names, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>))</span>
<span id="cb7-38"></span>
<span id="cb7-39">flows <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0459"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915004"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Place of work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> yvr_sur_por<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Gender (3)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Gender"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_names <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Origin=</span>Name,GeoUID), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(yvr_sur_por <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Place of work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>Name,UID), <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;">"Place of work"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_names <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Destination=</span>Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UID=</span>GeoUID), <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;">"UID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Origin,Destination,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Value=</span>VALUE)</span>
<span id="cb7-48"></span>
<span id="cb7-49">van_sur_commuters <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> flows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Origin<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;">"Vancouver"</span>,Destination<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;">"Surrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Value) </span>
<span id="cb7-51">sur_van_commuters <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> flows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Origin<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;">"Surrey"</span>,Destination<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;">"Vancouver"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Value) </span>
<span id="cb7-53"></span>
<span id="cb7-54">van_workers <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> workers <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name<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;">"Vancouver"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Workers)</span>
<span id="cb7-57">sur_workers <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> workers <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name<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;">"Surrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Workers)</span>
<span id="cb7-60"></span>
<span id="cb7-61">van_jobs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> jobs <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name<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;">"Vancouver"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Workers)</span>
<span id="cb7-64">sur_jobs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> jobs <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Name<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;">"Surrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Workers)</span></code></pre></div></div>
</details>
</div>
<p>This shows the mismatch of work and commute location stacking the deck against Surrey. The 2021 census recorded that Vancouver had 16% more jobs than workers, while Surrey had 28% fewer jobs than workers.<sup>1</sup> This is consistent with data from previous censuses. <span class="citation" data-cites="journey-to-work.2017 commuter-growth.2019">(<span class="nocase">von Bergmann</span> 2017a, 2019a)</span></p>
<p>People are, as we keep pointing out, also sloshing around and compressing within containers, where people double up in existing housing when there isn’t enough housing to go around. This is an important mechanism for how housing systems adjust in the short term to demand shocks, but doubling up can also become a long term persistent feature of a housing market. The more people are doubling up all across the metro area, the larger the reservoir of people ready to decompress and fill up new containers wherever they may land, but especially if they land in the most desirable places. Figure&nbsp;6 shows how people double up by age in Metro Vancouver, and for comparison purposes in select other Canadian metro areas. <span class="citation" data-cites="housing_shortages_doubled_up_households.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span></p>
<div id="fig-doubling-up-by-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-doubling-up-by-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/images/doubling_up_cma_by_age.png" id="fig-doubling-up-by-age" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-doubling-up-by-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
<p>This type of liquidity in housing demographics renders solid demographic models particularly problematic when applied to the sub-metro level, as we explain in more detail below. Where there’s a landscape of desire together with a ready reservoir of demand, we have every reason to expect that where we add new containers will largely determine where people land. Will there still be some empty homes? Sure. But probably not many <span class="citation" data-cites="unoccupied-canada.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022b)</span>, especially when we’ve layered several taxes on to most long-term vacancies. These kinds of taxes can add pressure for sellers and landlords to adjust their prices and rents until people flow into the new containers they control.</p>
<p>In short, don’t count Vancouver out. Short-term sloshing aside, our liquid demography suggests it’s got a decent chance of staying ahead of Surrey. But even in a liquid world, Vancouver may not win! It really depends upon how much housing gets built. Surrey could continue to scale up housing production via more apartments while major investments like SFU’s new medical school could tip the landscape of desire further toward Surrey’s direction. Furthermore, if current policy constraints to more greenfield development, like the Agricultural Land Reserve, come under assault, all bets are off - Surrey’s got a lot more land under ALR protection than the City of Vancouver. But those possibilities aside, in a liquid world there are plenty of reasons to believe that Vancouver will continue to battle off Surrey for the title of most populous municipality in the Metro area. Mostly it just has to keep building more.</p>
</section>
<section id="the-danger-of-solid-projections-in-a-liquid-world" class="level1">
<h1>The danger of solid projections in a liquid world</h1>
<p>City level demographic projections are good in theory, especially if they are done well - ideally by combining our liquid and solid models. But it’s important to understand what they are useful for, and for what purposes they are not well-suited. The solid model pretty much ignores housing. The liquid model strongly emphasizes that in high demand supply-constrained areas, housing determines growth. What we can take away from both is that municipal population projections should not be used for planning around housing needs. Unfortunately, that is exactly what <a href="https://www150.statcan.gc.ca/n1/pub/17-20-0003/172000032025001-eng.htm">StatCan</a> expects will be done with them:</p>
<blockquote class="blockquote">
<p>These projections provide impartial, evidence-based insights to all levels of government, infrastructure owners, operators and investors to improve infrastructure planning and decision-making across Canada. The data is also expected to inform land use and urban planning, housing needs, transportation and communications.</p>
</blockquote>
<p>The positioning of the projections as “impartial, evidence-based insights” is a frighteningly naive attempt to cast the assumptions and decisions embedded in the projections as value-free. Treating something that’s mostly liquid and compressible as mostly solid is neither “impartial” nor “evidence-based”. Worse, the notion that projections are expected to “inform land use planning” and “housing needs” is likely to do harm.</p>
<p>Further down StatCan does acknowledge the limitation that “modifications in land zoning” and “local development objectives” can have a big impact on municipal level population growth (“induce rapid fluctuations” in their language). This gets to the key tension: StatCan needs to pick a lane. If local demographics are <em>liquid</em> so land use planning can have significant impact on the projections, then that significantly limits the usefulness of projections that treats local demographics as a <em>solid</em> for land use planning. You can’t have it both ways.</p>
<p>So far we have focused on the <em>M1</em> projection, StatCan offers a range of population projection scenarios where they vary underlying growth and inter-provincial migration assumptions. This can offer a range of scenarios and planners should not focus on just one of them, but the problem remains that all of these treat local demographics as solids rather than liquids. In Figure&nbsp;7 we show the full range of scenarios for the City of Vancouver.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">van_scenarios <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0162"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,</span>
<span id="cb8-3">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>,</span>
<span id="cb8-4">           GeoUID<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;">"5915022"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>)</span>
<span id="cb8-7"></span>
<span id="cb8-8">rank_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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0162"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,</span>
<span id="cb8-10">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>,</span>
<span id="cb8-11">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Projection scenario M1: medium-growth"</span>,</span>
<span id="cb8-12">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb8-13">           REF_DATE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">default_month =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(metro_van_cities,<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;">"GeoUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,Name,val_norm,n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Name))</span>
<span id="cb8-21"></span>
<span id="cb8-22">van_scenarios <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015-01-01"</span>,Date<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;">"2035-01-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>val_norm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linetype_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>line_types) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),</span>
<span id="cb8-30">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population Projection Scenarios for the City of Vancouver"</span>,</span>
<span id="cb8-32">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb8-33">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population"</span>,</span>
<span id="cb8-34">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-van-pop-projection-scenarios" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-van-pop-projection-scenarios-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-van-pop-projection-scenarios-1.png" id="fig-van-pop-projection-scenarios" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-van-pop-projection-scenarios-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7
</figcaption>
</figure>
</div>
</div>
</div>
<p>Most of these scenarios are utterly unreasonable. The two highest growth scenarios, the <em>high-growth</em> and <em>slow aging</em> scenarios see Vancouver’s population still increasing in 2025, but then decreasing and only coming up above 2025 levels sometime late 2028.</p>
<p>Of course in the very short term, on the order of a year or maybe two, population could decline. We know there’s sloshing and adjustments that get made even in a liquid world. We’ll get a frozen glimpse at where things stand through the 2026 Census. We have seen such declines before, as during COVID where a multitude of factors came together all at once, as we explained above. But should we really expect one now?</p>
<p>We do know that non-permanent residents consume on average less housing than Canadian born residents, and similarly immigrants consume less housing than those Canadian born (despite what a recent StatCan study claims <span class="citation" data-cites="metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada.2025">(<span class="nocase">von Bergmann and Lauster</span> 2025)</span>). So a reduction in non-permanent residents (and in immigration) may lead to housing being used less intensively, even while people slosh around to fill vacancies. In this sense, we would expect population to go down if the housing stock remained fixed. At the same time, and directly as a consequence of sloshing, we are seeing a softening of the rental market along with a temporary rise in vacancy rate and an increase in properties listed for sale. Altogether these patterns suggest that slightly fewer homes are being lived in until prices adjust to rebalance.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">van_stock <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cancensus<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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CSD=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Dwellings</span>
<span id="cb9-2"></span>
<span id="cb9-3">van_current_under_construction <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmhc<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;">get_cmhc</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Under Construction"</span>, </span>
<span id="cb9-4">                                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, </span>
<span id="cb9-5">                                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-10-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Value)</span>
<span id="cb9-8"></span>
<span id="cb9-9">van_length_of_construction <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmhc<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;">get_cmhc</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Length of Construction"</span>, </span>
<span id="cb9-10">                                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, </span>
<span id="cb9-11">                                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5915022"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-10-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Value)</span></code></pre></div></div>
</details>
</div>
<p>But the notion that Vancouver would see sustained population decline while still adding housing is difficult to reconcile with what we know about housing demand in Metro Vancouver. Vancouver has 17,065 units currently under construction alone with an average length of completion of about 21 months, a roughly 5% increase in housing stock that’s already baked in. Will the owners of those units really pay Empty Homes and Speculation and Vacancy Taxes to keep them vacant for long?</p>
<section id="planning-misuse" class="level2">
<h2 class="anchored" data-anchor-id="planning-misuse">Planning misuse</h2>
<p>We explained how the projections are not particularly useful, but what harm could they do? Mostly the harm comes from when projections are used to justify underbuilding. And this happens a lot.</p>
<p>Turns out that there is a long history of local and regional planning misusing projections like this to restrict housing supply. This is an important part of the story of how we got into our current housing crisis, and Vancouver, city and metro, can serve as a good example.</p>
<p>How does this work? The logic is quite simple. It starts from the assumption that the only reason we need new housing is to accommodate the solid population growth coming out of our assembly line. Then we match the municipal level housing production to fit the projected population growth.</p>
<p>This goes wrong in two ways. First, the assumption that housing is only needed to accommodate population growth (and ageing) is wrong. <span class="citation" data-cites="planning-for-scarcity.2022 metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada.2025">(<span class="nocase">von Bergmann and Lauster</span> 2022a, 2025)</span> Things like income growth together with old housing falling into disrepair also increase the demand for housing. Secondly, if projections are mainly based on past trends, as is almost always the case and also true for these StatCan projections, then any past underproduction of housing relative to demand will be baked into the projections. The underproduction of housing becomes self-perpetuating (and gradually worsening) as municipalities use these kinds of projections to plan for future housing.</p>
<p>There is, of course, another way things can go wrong. Planners and politicians can intentionally use their controls over housing to slow population growth.</p>
</section>
<section id="the-metro-vancouver-example" class="level2">
<h2 class="anchored" data-anchor-id="the-metro-vancouver-example">The Metro Vancouver example</h2>
<p>In the 70s Metro Vancouver regional planning explicitly targeted under-production of housing as a means of managing growth. Growth management became implicitly enshrined using technocratic language within regional growth strategies and housing projection models, which differ in some details but broadly follow the <em>solid</em> demographics that StatCan employed. <span class="citation" data-cites="metro-vancouver-planning-regimes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023)</span> The process is quite simple, BC Stats provided local population projections and Metro Vancouver turned them into housing targets for each municipality. <a href="https://www2.gov.bc.ca/assets/gov/data/statistics/people-population-community/population/people_2024_methodology_and_assumptions.pdf">For a long time BC Stats considered local community plans for housing</a> to derive the population projections, making this process almost comically circular. Recently BC Stats have changed their method which cuts this circular reasoning, but ironically this has moved BC Stats projections further into the world of solid demographics and made the estimates less suitable (and worse) for the purpose of land use and housing planning. But regional planning authorities seem happy to continue to use them for exactly that purpose.</p>
</section>
<section id="self-fulfilling-prophecies" class="level2">
<h2 class="anchored" data-anchor-id="self-fulfilling-prophecies">Self-fulfilling prophecies</h2>
<p>Similarly, and quite explicitly, a City of Vancouver councillor recently tried to restrict housing production in the city by using exactly these type of arguments and planning processes that, in the face of existing shortages, turn population projections into self-fulfilling prophecies. <span class="citation" data-cites="projections-and-self-fulfilling-prophecies.2020">(<span class="nocase">von Bergmann and Lauster</span> 2020)</span></p>
</section>
<section id="when-prophecies-fail" class="level2">
<h2 class="anchored" data-anchor-id="when-prophecies-fail">When prophecies fail</h2>
<p>We also have good examples of what happens when population projections turn out to be wrong. Metro Vancouver has been using municipal level population projections for a while and used them to derive housing targets. What can we learn from cases where the projections turned out to be wrong? Quite simply, those were the cases where municipalities did not meet their housing targets. <span class="citation" data-cites="on-vancouver-population-projections.2019">(<span class="nocase">von Bergmann</span> 2019b)</span> In other words, when there is an existing housing shortage, land use planning drives population growth, not the other way around.</p>
</section>
</section>
<section id="liquids-and-solids" class="level1">
<h1>Liquids and Solids</h1>
<p>As we noted at the outset, we think people are both liquids and solids. Ultimately we need demographic projections that combine these two forms. But we can go a little further to note that scale matters. At the national level, treating people as solids tends to work out ok. Immigration is subject to controls that really do make people look more like they’re coming off an assembly line. But once people land in Canada, the Charter works to preserve their ability to move freely. As a consequence, people become much more liquid as they move internally. This is mirrored in the <a href="https://homefreesociology.com/2019/11/24/why-do-people-move-new-data-mysteries-and-fundamental-rights/">reasons people give for moving</a>. Immigrants don’t tend to make the move across borders for reasons like better housing affordability, but within metropolitan areas, housing drives the majority of local moves. Correspondingly, when we get below the metropolitan level, we really need to take into account how people are likely to move in response to where housing is being constructed. In short, at the local level, <em>liquid</em> demographics is the name of the game.</p>
<p>For the race between the City of Vancouver and Surrey that means that it’s mostly up to Vancouver who wins. Demand to live in Vancouver is much higher, if Vancouver allows more housing people will flow toward Vancouver and Surrey will have a very hard time catching up. If Vancouver swings back and cuts down their development pipeline, following Metro guidance, then Surrey will likely overtake Vancouver sometime in the next decade or two. As laid out by Uytae Lee, Surrey seems ready to try.</p>
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/ybMhTlj-l5s" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb10-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-12-08 00:30:33 PST"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb12-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [efd3bd5] 2025-12-08: widgets</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mountainmathHelpers_0.1.4 sf_1.0-22                
 [3] dotdensity_0.1.0          rlang_1.1.6              
 [5] cancensus_0.5.11          cansim_0.4.4             
 [7] lubridate_1.9.4           forcats_1.0.1            
 [9] stringr_1.5.2             dplyr_1.1.4              
[11] purrr_1.1.0               readr_2.1.5              
[13] tidyr_1.3.1               tibble_3.3.0             
[15] ggplot2_4.0.0             tidyverse_2.0.0          

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       xfun_0.53          htmlwidgets_1.6.4  tzdb_0.5.0        
 [5] vctrs_0.6.5        tools_4.5.2        generics_0.1.4     curl_7.0.0        
 [9] proxy_0.4-27       fansi_1.0.6        pkgconfig_2.0.3    KernSmooth_2.23-26
[13] tinytable_0.13.0   RColorBrewer_1.1-3 S7_0.2.0           assertthat_0.2.1  
[17] lifecycle_1.0.4    git2r_0.36.2       compiler_4.5.2     farver_2.1.2      
[21] litedown_0.7       htmltools_0.5.8.1  class_7.3-23       yaml_2.3.10       
[25] pillar_1.11.1      classInt_0.4-11    tidyselect_1.2.1   digest_0.6.37     
[29] stringi_1.8.7      arrow_21.0.0.1     fastmap_1.2.0      grid_4.5.2        
[33] cli_3.6.5          magrittr_2.0.4     e1071_1.7-16       withr_3.0.2       
[37] scales_1.4.0       bit64_4.6.0-1      timechange_0.3.0   rmarkdown_2.30    
[41] httr_1.4.7         bit_4.6.0          hms_1.1.4          evaluate_1.0.5    
[45] knitr_1.50         Rcpp_1.1.0         glue_1.8.0         DBI_1.2.3         
[49] rstudioapi_0.17.1  jsonlite_2.0.0     R6_2.6.1           units_1.0-0       </code></pre>
</div>
</div>
</details>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-gensey_condos.2018" class="csl-entry">
CMHC. 2018. <em>Supply Constraints Increased Prices of Apartment Condominiums in Canadian Cities</em>. HOUSING RESEARCH REPORT. <a href="https://eppdscrmssa01.blob.core.windows.net/cmhcprodcontainer/sf/project/archive/research_5/rr_supply_constraints_increased_prices_mar_12.pdf">https://eppdscrmssa01.blob.core.windows.net/cmhcprodcontainer/sf/project/archive/research_5/rr_supply_constraints_increased_prices_mar_12.pdf</a>.
</div>
<div id="ref-housing_shortages_doubled_up_households.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“Housing Shortages and Doubled up Households.”</span> <em>Plan Canada</em> 64 (4): 16–21. <a href="https://mountainmath.github.io/housing_shortages_and_doubled_up_households/">https://mountainmath.github.io/housing_shortages_and_doubled_up_households/</a>.
</div>
<div id="ref-mulder2006" class="csl-entry">
Mulder, Clara. 2006. <span>“Population and Housing.”</span> <em>Demographic Research</em> 15 (November): 401–12. <a href="https://doi.org/10.4054/demres.2006.15.13">https://doi.org/10.4054/demres.2006.15.13</a>.
</div>
<div id="ref-journey-to-work.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017a. <em>Journey <span>To</span> <span>Work</span></em>. <a href="https://doodles.mountainmath.ca/posts/2017-11-29-journey-to-work/">https://doodles.mountainmath.ca/posts/2017-11-29-journey-to-work/</a>.
</div>
<div id="ref-under-construction.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017b. <em>Under <span>Construction</span></em>. <a href="https://doodles.mountainmath.ca/posts/2017-11-28-under-construction/">https://doodles.mountainmath.ca/posts/2017-11-28-under-construction/</a>.
</div>
<div id="ref-commuter-growth.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2019a. <em>Commuter Growth</em>. <a href="https://doodles.mountainmath.ca/posts/2019-10-29-commuter-growth/">https://doodles.mountainmath.ca/posts/2019-10-29-commuter-growth/</a>.
</div>
<div id="ref-on-vancouver-population-projections.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2019b. <em>On <span>Vancouver</span> Population Projections</em>. <a href="https://doodles.mountainmath.ca/posts/2019-08-01-on-vancouver-population-projections/">https://doodles.mountainmath.ca/posts/2019-08-01-on-vancouver-population-projections/</a>.
</div>
<div id="ref-bc_ssmuh_toa.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, Tom Davidoff, Albert Huang, Nathanael Lauster, and Tsur Somerville</span>. 2023. <em>SSMUH and TOA Scenarios in British Columbia</em>. BC Ministry of Housing. <a href="https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf">https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf</a>.
</div>
<div id="ref-projections-and-self-fulfilling-prophecies.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2020. <em>Projections and Self-Fulfilling Prophecies</em>. <a href="https://doodles.mountainmath.ca/posts/2020-05-25-projections-and-self-fulfilling-prophecies/">https://doodles.mountainmath.ca/posts/2020-05-25-projections-and-self-fulfilling-prophecies/</a>.
</div>
<div id="ref-planning-for-scarcity.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022a. <em>Planning for Scarcity</em>. <a href="https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/">https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/</a>.
</div>
<div id="ref-unoccupied-canada.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022b. <em>Unoccupied <span>Canada</span></em>. <a href="https://doodles.mountainmath.ca/posts/2022-02-14-unoccupied-canada/">https://doodles.mountainmath.ca/posts/2022-02-14-unoccupied-canada/</a>.
</div>
<div id="ref-metro-vancouver-planning-regimes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Metro <span>Vancouver</span> <span>Planning</span> <span>Regimes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/">https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/</a>.
</div>
<div id="ref-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada.2025" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2025. <em>Metrics, <span>Mechanisms,</span> and <span>Mismatch:</span> <span>Immigration</span> and Other <span>Components</span> of <span>Housing</span> <span>Demand</span> in <span>Canada</span></em>. <a href="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/">https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/</a>.
</div>
</div>


</section>
</section>


<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>This is only counting jobs with a usual place of work people commute to, and estimates from the 2021 census were likely still impacted by the COVID pandemic and proximity to the likely high point of Work From Home.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{the-trouble-with-municipal-level-population-projections.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {The Trouble with Municipal-Level Population Projections},
  date = {2025-12-07},
  url = {https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“The Trouble with
Municipal-Level Population Projections.”</span>
<em>MountainDoodles</em>, accepted, December 7. <a href="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/">https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/</a>.
</div></div></section></div> ]]></description>
  <category>Vancouver</category>
  <category>Surrey</category>
  <category>cansim</category>
  <category>land use</category>
  <category>zoning</category>
  <category>cancensus</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/</guid>
  <pubDate>Sun, 07 Dec 2025 08:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-12-07-the-trouble-with-municipal-level-population-projections/index_files/figure-html/fig-van-surrey-pop-estimates-1.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Age Disparity in Shelter Cost per Room</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/10/25/age-disparity-in-shelter-cost-per-room/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warn.conflicts =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canpumf)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span></code></pre></div></div>
</details>
</div>
<p>Residential floor space offers a common denominator for trying to standardize across a range of housing metrics (e.g.&nbsp;price per square foot). Unfortunately we don’t have it in the Census in Canada, but we can play around with rooms to get some pretty similar results. Here we investigate how shelter costs per room have changed over time, across various regions, and by age group to construct some comparable figures to those recently coming out of the UK.</p>
<p>Long story short: shelter cost per room has been getting more expensive, especially for young folks, and in those metro areas where we see the greatest housing shortages, and the age discrepancy mostly comes from older folks locking in past prices, especially as they transition into ownership.</p>
<section id="new-metric" class="level1">
<h1>New Metric!</h1>
<p>We are suckers for experimenting with new metrics to understand housing pressures and got nerd-sniped by figures on shelter cost per square meter of floorspace in the UK put out by the <a href="https://www.resolutionfoundation.org/major-programme/housing-indicators/housing-affordability/?section=HC%20sqm">Resolution Foundation</a>, in particular the breakdown of shelter cost per square meter by age groups as flagged by <a href="https://bsky.app/profile/antbreach.bsky.social/post/3m3heqfnyi22q">Ant Breach on Bluesky</a>, and referenced by <a href="https://bsky.app/profile/denysullivan.bsky.social/post/3m3igygsa6c2f">Deny Sullivan</a> asking for Canadian stats.</p>
</section>
<section id="room" class="level1">
<h1>Room</h1>
<p>In Canada we don’t know of a good data source on square footage and shelter costs by age breakdown, but we can achieve something similar by looking at shelter cost per room. Of note for current <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=dwelling-logements012">Census definitions</a>, number of rooms includes “kitchens, bedrooms and finished rooms in the attic or basement” but excludes “bathrooms, halls, vestibules and rooms used solely for business purposes,” with specific judgments otherwise left to the respondent. As a specific example, consider a studio apartment where the kitchen was partially behind a wall. The number of rooms might be listed as one or two, depending upon the respondent. This kind of ambiguity is built into the rooms measure. But we have looked at number of rooms as a metric for household tightness before <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023)</span>, and while it is far from perfect (with sizes of rooms, as well as how we divide homes into rooms, changing over time and likely differing across regions in addition to inherent ambiguity), we believe it still offers a somewhat decent proxy for the size of homes.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">get_combined_pumf_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb2-2">  </span>
<span id="cb2-3">  inflation <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mountainmathHelpers<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;">simpleCache</span>(</span>
<span id="cb2-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v41693271"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-6">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CPI=</span>val_norm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> val_norm[Year<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;">2021</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,CPI), </span>
<span id="cb2-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"inflation_annual_oct_2025.rds"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path=</span>here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>))</span>
<span id="cb2-9">  </span>
<span id="cb2-10"></span>
<span id="cb2-11">  years <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</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;">5</span>)</span>
<span id="cb2-12"> </span>
<span id="cb2-13">  pumf_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(year) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-15">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-16">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(years)</span>
<span id="cb2-18">  </span>
<span id="cb2-19">  year_age_to_age_group <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(age_column) {</span>
<span id="cb2-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(age_column,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">85</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>),<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>),</span>
<span id="cb2-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>,</span>
<span id="cb2-22">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,</span>
<span id="cb2-23">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"40 to 44 years"</span>,</span>
<span id="cb2-24">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 49 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50 to 54 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to 59 years"</span>,</span>
<span id="cb2-25">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"60 to 64 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 to 69 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"70 to 74 years"</span>,</span>
<span id="cb2-26">                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"75 to 79 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"80 to 84 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>),</span>
<span id="cb2-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">right=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-28">  }</span>
<span id="cb2-29"></span>
<span id="cb2-30">  select_columns_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ROOM"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AGEGRP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PRIHM"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SHELCO"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MOB1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TENUR"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VALUE"</span>)</span>
<span id="cb2-31">  </span>
<span id="cb2-32">  pumf_all_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb2-33">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-34">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-35">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(VALUE)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-36">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>),</span>
<span id="cb2-37">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-38">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ROOM=</span>ROOMS) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-39">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-40">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99999999</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">88888888</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-41">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2016</span>),</span>
<span id="cb2-42">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-43">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(OMP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>),</span>
<span id="cb2-44">                             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(GROSRT,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-45">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-46">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-47">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999999</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8888888</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-48">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011</span>),</span>
<span id="cb2-49">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2006"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(OMP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>),</span>
<span id="cb2-50">                                                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(GROSRT,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-51">                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-52">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-53">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999999</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8888888</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-54">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2006</span>),</span>
<span id="cb2-55">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2001"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(OMPP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>),</span>
<span id="cb2-56">                                                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(GROSRTP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-57">                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-58">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ROOM=</span>ROOMP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRIHM=</span>PRMAINP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">WEIGHT=</span>WEIGHTP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span>CMAP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MOB1=</span>MOB1P,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span>TENURP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUEP) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-59">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year_age_to_age_group</span>(AGEP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-60">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-61">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(VALUE,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-62">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2001</span>),</span>
<span id="cb2-63">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1996"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(OMPP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>),</span>
<span id="cb2-64">                                                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(GROSRTP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-65">                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-66">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ROOM=</span>ROOMP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRIHM=</span>PRMAINP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">WEIGHT=</span>WEIGHTP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span>CMAPUMFP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MOB1=</span>MOB1P,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span>TENURP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUEP) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-67">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year_age_to_age_group</span>(AGEP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-68">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-69">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999999</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">888888</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-70">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1996</span>),</span>
<span id="cb2-71">    pumf_list[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1991"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(OMPP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>),</span>
<span id="cb2-72">                                                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(GROSRTP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9999"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"8888"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-73">                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-74">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ROOM=</span>ROOMP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRIHM=</span>PRMAINP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">WEIGHT=</span>WEIGHTP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span>CMAPUMFP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MOB1=</span>MOB1P,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span>TENURP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUEP) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-75">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year_age_to_age_group</span>(AGEP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-76">      <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;">all_of</span>(select_columns_r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-77">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(VALUE,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-78">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>),</span>
<span id="cb2-79">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-80">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(inflation, <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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-81">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO_real =</span> SHELCO<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-82">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(ROOM<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;">"Not available"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb2-83">                           ROOM<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;">"NOT APPLICABLE"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb2-84">                           ROOM<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;">"Not applicable"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb2-85">                           ROOM<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;">"One room"</span> <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;">"1"</span>,</span>
<span id="cb2-86">                           ROOM<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;">"Two rooms"</span> <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;">"2"</span>,</span>
<span id="cb2-87">                           ROOM<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;">"Three rooms"</span> <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;">"3"</span>,</span>
<span id="cb2-88">                           ROOM<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;">"Four rooms"</span> <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;">"4"</span>,</span>
<span id="cb2-89">                           ROOM<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;">"Five rooms"</span> <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;">"5"</span>,</span>
<span id="cb2-90">                           ROOM<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;">"Six rooms"</span> <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;">"6"</span>,</span>
<span id="cb2-91">                           ROOM<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;">"Seven rooms"</span> <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;">"7"</span>,</span>
<span id="cb2-92">                           ROOM<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;">"Eight rooms"</span> <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;">"8"</span>,</span>
<span id="cb2-93">                           ROOM<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;">"Nine rooms"</span> <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;">"9"</span>,</span>
<span id="cb2-94">                           ROOM<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;">"Ten rooms"</span> <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;">"10"</span>,</span>
<span id="cb2-95">                           ROOM<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;">"Ten or more rooms"</span> <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;">"10"</span>,</span>
<span id="cb2-96">                           ROOM<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;">"Ten or &gt;rooms"</span><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;">"10"</span>,</span>
<span id="cb2-97">                           ROOM<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;">"Eleven rooms or more"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11"</span>,</span>
<span id="cb2-98">                           ROOM<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;">"Eleven or more rooms"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11"</span>,</span>
<span id="cb2-99">                           <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(ROOM,<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;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-100">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-101">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina - 705 and Saskatoon - 725"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina – Saskatoon"</span>,</span>
<span id="cb2-102">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina(705) + Saskatoon(725)"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina – Saskatoon"</span>,</span>
<span id="cb2-103">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina/Saskatoon"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina – Saskatoon"</span>,</span>
<span id="cb2-104">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa-Hull"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,</span>
<span id="cb2-105">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa Hull"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,</span>
<span id="cb2-106">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec"</span>,</span>
<span id="cb2-107">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montreal"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-108">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(TENUR,</span>
<span id="cb2-109">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter or Dwelling provided by the local government, First Nation or Indian band"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,</span>
<span id="cb2-110">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned by a member of the household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,</span>
<span id="cb2-111">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented or Band housing"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,</span>
<span id="cb2-112">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned (with or without mortgage)"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,</span>
<span id="cb2-113">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented (for cash, other) or Band housing"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,</span>
<span id="cb2-114">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned - with or without mortgage"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,</span>
<span id="cb2-115">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented - for cash, other or Band housing"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,</span>
<span id="cb2-116">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OwndWithWoutMortgage"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,</span>
<span id="cb2-117">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented Band Housing"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,</span>
<span id="cb2-118">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned (with or without mort.)"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,</span>
<span id="cb2-119">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented-cash/other or band hsg."</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-120">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span> <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;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>people) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA)))</span>
<span id="cb2-121">  </span>
<span id="cb2-122">  pumf_all_r</span>
<span id="cb2-123">}</span>
<span id="cb2-124"></span>
<span id="cb2-125">pumf_all_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mountainmathHelpers<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;">simpleCache</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_combined_pumf_data</span>(),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"combined_pumf_data.rds"</span>)</span></code></pre></div></div>
</details>
</div>
</section>
<section id="shelter-costs-per-room" class="level1">
<h1>Shelter costs per room</h1>
<p>Shelter costs, <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=households-menage033">as measured in the census</a>, capture how much households are directly paying on an ongoing monthly basis to maintain their shelter, including utilities, condominium fees, and property taxes. This differs from measuring the value of housing services consumed, a more theoretical quantity. For example an owner household in a fully paid-off home may have very low ongoing shelter costs, but the value of the housing services they consume is much higher, which we estimate by imputing the rent they pay themselves. Shelter costs can be thought of as capturing how much people feel directly pressured by the housing market rather than measuring the value of their housing services.</p>
<p>To make shelter cost more comparable across homes we normalize it by the number of rooms in the home as a proxy for the size of the home. One could also normalize by the number of bedrooms, but that data is only available for the 2011 through 2021 censuses and we are interested in longer timelines for this post.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">pd_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb3-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb3-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb3-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)</span>
<span id="cb3-10">  ) </span></code></pre></div></div>
</details>
</div>
<p>One decision we have to make is over what universe we are estimating this metric. There are two natural choices; we can estimate this over people or over households. With an eye to the rest of the post we choose to estimate this over households.</p>
<p>Figure&nbsp;1 shows the shelter cost per room across time for several large Canadian metro areas.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">filter_metros <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb4-2">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toron|Vancou|Calga|Montré|Ottaw|Québ|Edom|Halifax|Victor|Hamil"</span>,CMA))</span>
<span id="cb4-4">}</span>
<span id="cb4-5"></span>
<span id="cb4-6">pd_all <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Year<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;">2021</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>avg_shelco_per_room) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "18 to 19 years") |&gt;</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room in Canada"</span>,</span>
<span id="cb4-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro area"</span>,</span>
<span id="cb4-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb4-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb4-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1991 through 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-1.png" id="fig-shelter-cost-per-room" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>As one might expect, Vancouver and Toronto stand out with particularly high shelter costs per room, and also strong growth in the metric since 1991. At the other end of the spectrum, Québec City metro area shows low and fairly flat shelter cost per room.</p>
</section>
<section id="economies-of-scale-and-location-tradeoffs" class="level1">
<h1>Economies of Scale and Location Tradeoffs</h1>
<p>Importantly, we shouldn’t expect shelter cost per room to linearly scale up with the size of a dwelling overall. After all, we already know that the room metric excludes things like bathrooms - and sometimes even kitchens - which are needed to support a dwelling, but not on a per room basis. So there should be economies of scale with respect to dwellings where having more rooms becomes cheaper on a per room basis. We illustrate this with Figure&nbsp;2.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">shelter_cost_per_room <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb5-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb5-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<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;">sqrt</span>(rooms), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(rooms,CMA,Year)</span>
<span id="cb5-11">  ) </span>
<span id="cb5-12"></span>
<span id="cb5-13"></span>
<span id="cb5-14">shelter_cost_per_room <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(rooms,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" rooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 rooms"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10+ rooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb5-22">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Shelter cost per room by number of rooms reported"</span>,</span>
<span id="cb5-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metropolitan Area"</span>,</span>
<span id="cb5-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb5-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>name)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-rooms" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-rooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-rooms-1.png" id="fig-shelter-cost-per-room-by-rooms" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-rooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>Importantly, we’re also probably picking up some within metro area location effects here. That is, more central locations tend to have more studio and 1BR apartments, while locations further out toward the suburbs tend to have larger detached houses. So proximity to jobs and amenities may be folded into our estimates of costs per room as well, and also help explain why they vary over number of rooms. This helps set up our discussion of age effects.</p>
<p>In this context it’s also useful to understand how the distribution of the number of rooms per home has changed over time and differs across geographies, as shown in Figure&nbsp;3.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">room_over_time <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb6-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb6-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb6-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(rooms,CMA,Year)</span>
<span id="cb6-10">  )</span>
<span id="cb6-11"></span>
<span id="cb6-12"></span>
<span id="cb6-13">room_over_time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(rooms,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" rooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 rooms"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10+ rooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb6-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of number of rooms per home"</span>,</span>
<span id="cb6-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"# rooms"</span>,</span>
<span id="cb6-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of homes"</span>,</span>
<span id="cb6-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-room-over-time" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-room-over-time-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-room-over-time-1.png" id="fig-room-over-time" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-room-over-time-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>The low share of especially 1-room homes in some regions explains the volatility in the shelter cost per room metric for 1-room homes. We also note that the share of low-room count homes increases especially in regions with growing housing shortages, which likely contributes to the increase in shelter cost per room over time. This is consistent with the explanation that the increase in the number of low-room homes is driven by people’s desire for privacy of their own home, and being forced to economize on size where they face less competition from people economizing by doubling up.</p>
<p>This suggests that adjusting for the changing distribution of the number of rooms per home across geographies and time might be useful to account for the economies of scale relating overall floor space to the number of rooms, while at the same time cautioning against doing this because of higher rent/sf for smaller units and variations in the distribution of the number of rooms being driven by housing shortages. For the rest of the post we will keep it simple and not adjust for the number of rooms, but Figure&nbsp;4 shows the shelter cost per room adjusted for the changing distribution of the number of rooms per home to help gauge the potential impacts of doing such adjustment to our baseline Figure&nbsp;1.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">pd_all_adj <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb7-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb7-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb7-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb7-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,rooms)</span>
<span id="cb7-10">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(</span>
<span id="cb7-12">    room_over_time <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-13">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-14">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_rooms =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(rooms)),</span>
<span id="cb7-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rooms"</span>)</span>
<span id="cb7-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb7-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(avg_shelco_per_room, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> total_rooms),</span>
<span id="cb7-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)</span>
<span id="cb7-20">  )</span>
<span id="cb7-21"></span>
<span id="cb7-22"></span>
<span id="cb7-23">pd_all_adj <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Year<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;">2021</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>avg_shelco_per_room) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "18 to 19 years") |&gt;</span></span>
<span id="cb7-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room in Canada  (adjusted by number of rooms)"</span>,</span>
<span id="cb7-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro area"</span>,</span>
<span id="cb7-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb7-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb7-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-adjusted" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-adjusted-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-adjusted-1.png" id="fig-shelter-cost-per-room-adjusted" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-adjusted-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>As one would expect, adjusting for the distribution of number of rooms dampens the growth in shelter cost per room for Toronto and Vancouver, which saw the largest increases in the share of low-room count homes, and increases the relative position of Calgary, which has a large share of high-room count homes. But the overall patterns remain similar to the unadjusted results.</p>
<p>If one wanted to refine the results of this post one could take a more principled approach and choose a more structured way to adjust for the changing distribution of the number of rooms, similar to what we did when constructing first-time buyer Lorentz curves. <span class="citation" data-cites="first-time-buyer-lorenz-curves.2020 first-time-buyer-lorenz-curves-revisited.2024">(<span class="nocase">Stewart and von Bergmann</span> 2020, 2024)</span></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">pd_all_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb8-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms),</span>
<span id="cb8-5">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb8-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb8-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA,Year)</span>
<span id="cb8-11">  )  </span></code></pre></div></div>
</details>
</div>
</section>
<section id="age" class="level1">
<h1>Age</h1>
<p>We were drawn into this because of the age disparity in the UK data, and we want to understand the shelter cost per room by age. How do running shelter costs per room differ for people in different age groups? Here we first need to revisit the question of the universe over which we are estimating this metric. For example, for 25 to 29 year olds, do we mostly care about the experience of those who formed independent households or do we also want to consider the experience of those living with their parents? We expect these two groups to face very different shelter cost pressures. In this post we mostly care about the former, so we again look at the household level and code the age group based on the age of the primary household maintainer, with the breakdown shown in Figure&nbsp;5.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">pd_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"15 to 17 years"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "18 to 19 years") |&gt;</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room in Canada"</span>,</span>
<span id="cb9-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age of primary</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">household maintainer"</span>,</span>
<span id="cb9-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb9-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb9-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-age" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-age-1.png" id="fig-shelter-cost-per-room-by-age" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<p>This shows a fairly consistent pattern with younger people having higher shelter costs per room, and shelter costs per room declining as we move upward through the age groups. There is variance in the size of the spread, as well as how it increased over time. And the sample gets thin for some age groups in some regions, in particular the 18 to 19 year old bracket, leading to some noise. The Québec City metro area again stands out with it’s low spread and fairly flat development over time. Toronto and Vancouver again show the largest spread and largest increase.</p>
<p>Following the lead of how the UK data was sliced, Figure&nbsp;6 arranges the information into coarser age groups for easier readability.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">recode_broad_age_groups <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data){</span>
<span id="cb10-2">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(AGEGRP,</span>
<span id="cb10-4">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 29 years"</span>,</span>
<span id="cb10-5">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 29 years"</span>,</span>
<span id="cb10-6">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 29 years"</span>,</span>
<span id="cb10-7">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 29 years"</span>,</span>
<span id="cb10-8">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 44 years"</span>,</span>
<span id="cb10-9">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 44 years"</span>,</span>
<span id="cb10-10">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"40 to 44 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 44 years"</span>,</span>
<span id="cb10-11">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 49 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 64 years"</span>,</span>
<span id="cb10-12">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50 to 54 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 64 years"</span>,</span>
<span id="cb10-13">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to 59 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 64 years"</span>,</span>
<span id="cb10-14">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"60 to 64 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 64 years"</span>,</span>
<span id="cb10-15">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 to 69 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>,</span>
<span id="cb10-16">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"70 to 74 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>, </span>
<span id="cb10-17">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"75 to 79 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>,</span>
<span id="cb10-18">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"80 to 84 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>,</span>
<span id="cb10-19">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>,</span>
<span id="cb10-20">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 4 years"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>,</span>
<span id="cb10-21">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 to 6 years"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>,</span>
<span id="cb10-22">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"7 to 9 years"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>,</span>
<span id="cb10-23">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 to 11 years"</span>  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>,   </span>
<span id="cb10-24">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12 to 14 years"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 14 years"</span>)</span>
<span id="cb10-25">  )</span>
<span id="cb10-26">}</span>
<span id="cb10-27"></span>
<span id="cb10-28">grouped_age_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb10-30">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms),</span>
<span id="cb10-32">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-34">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb10-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode_broad_age_groups</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb10-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb10-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(rooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb10-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb10-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA,Year)</span>
<span id="cb10-41">  ) </span>
<span id="cb10-42"></span>
<span id="cb10-43">coarse_age_colours <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;">setNames</span>(RColorBrewer<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;">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;">"Dark2"</span>),</span>
<span id="cb10-44">                               <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;">"0 to 14 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 44 years"</span>,</span>
<span id="cb10-45">                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 64 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65 years and over"</span>))</span>
<span id="cb10-46"></span>
<span id="cb10-47">grouped_age_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>coarse_age_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-54">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room in Canada"</span>,</span>
<span id="cb10-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age of primary</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">household maintainer"</span>,</span>
<span id="cb10-57">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb10-58">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-59">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-coarse-age" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-coarse-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-coarse-age-1.png" id="fig-shelter-cost-per-room-by-coarse-age" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-coarse-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
</div>
</div>
<p>This is a good time to pause and think about how one might interpret this information. Increases in cost over time track fairly well with our understanding of housing shortages, with Québec City demonstrating very little shortage and Vancouver and Toronto demonstrating a lot. <span class="citation" data-cites="housing_shortages_doubled_up_households.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span> The differences by age are more difficult to interpret, they could be due to older people having been able to lock in housing costs in the past, having bought a home quite some time ago or benefiting from rent control after renting for a long time. But it could also be that older people tend to live in roomier places in the suburbs, benefiting from economies of scale, while younger people choose to live in more central locations, near more amenities, or in higher quality homes, which tend to have higher rents and prices. To disentangle this we can condition on renters, which removes the effects of e.g.&nbsp;people having low shelter costs because they have paid down their mortgage. We can also condition on recent movers to remove most of the effect of rent control. Figure&nbsp;7 shows how this group fares over time.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">movers_cats <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;">"Non-migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Different CSD, same census division"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Different CD, same province"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interprovincial migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Movers: Non-migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Movers: Migrants: Internal migrants: Intraprovincial migrants: Different CSD, same census division - CD"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Movers: Migrants: Internal migrants: Intraprovincial migrants: Different CD, same province"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Movers: Migrants: Internal migrants: Interprovincial migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Movers: Migrants: External migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MoversNonmigrant"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DifferentCSDSameCD"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DifferentCDSameProv"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"InterprovinclMigrant"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External Migrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intraprovincial movers"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interprovincial movers"</span>)</span>
<span id="cb11-2"></span>
<span id="cb11-3">grouped_age_data_movers <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb11-5">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> movers_cats) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms),</span>
<span id="cb11-9">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb11-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode_broad_age_groups</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb11-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(rooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb11-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb11-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cases=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb11-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA,Year)</span>
<span id="cb11-19">  ) </span>
<span id="cb11-20"></span>
<span id="cb11-21">grouped_age_data_movers <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>coarse_age_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room of renters who moved in the preceding year"</span>,</span>
<span id="cb11-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age of primary</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">household maintainer"</span>,</span>
<span id="cb11-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb11-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-coarse-age-renter-movers" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-coarse-age-renter-movers-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-coarse-age-renter-movers-1.png" id="fig-shelter-cost-per-room-by-coarse-age-renter-movers" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-coarse-age-renter-movers-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7
</figcaption>
</figure>
</div>
</div>
</div>
<p>This considerably narrows the spread across age groups. Data on recent renter movers in the senior age bracket should be interpreted with some caution due to the low number of cases in our sample, but overall trends indicated an interesting reversal for the senior age bracket which now shows up on top in many metro areas. Given our selection, it’s possible that in some cases shelter costs here might be picking up on ways that seniors newly moving into retirement communities and assisted living facilities see the costs of extra services bundled into their rents. Nevertheless, Toronto and Vancouver still show younger age groups with higher shelter costs per room, which is consistent with the hypothesis that some of the spread could be due to different preferences in location and roominess tradeoffs.</p>
<p>But there are some other factors that might play into this too. Household formation and tenure choice are both downstream of housing pressures, so conditioning on them can lead to collider bias, as we have previously explained. <span class="citation" data-cites="housing-outcomes.2023 mhu.2025 housing_shortages_doubled_up_households.2024">(<span class="nocase">von Bergmann and Lauster</span> 2023; Lauster and Bergmann 2025; <span class="nocase">Lauster and von Bergmann</span> 2024)</span>. We have proposed two measures of <em>housing frustration</em> based on household formation and tenure choice that can help quantify these pressures <span class="citation" data-cites="tenure-and-household-independence-across-the-life-course-1981-2021.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024)</span>, as shown in Figure&nbsp;8 that we include here again for convenience. The housing frustration metric shows very high levels of suppressed household formation especially in Vancouver and Toronto that could explain some of the age patterns we see here via selection of richer folks into independent households among younger age groups. The question about tenure choice is more complicated and the relationship to the different spreads between age groups is less clear.</p>
<div id="fig-housing-frustration" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-housing-frustration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-frustration-metro-1.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-housing-frustration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8: Housing frustration
</figcaption>
</figure>
</div>
<p>We can dig down a little deeper by examining how owners and renters differ in their ability to lock in lower shelter costs over time. Figure&nbsp;9 splits the data by tenure, for a smaller selection of metro areas to keep things simple.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">tenure_age_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb12-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms),</span>
<span id="cb12-5">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode_broad_age_groups</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb12-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb12-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(rooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb12-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb12-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA,Year,TENUR)</span>
<span id="cb12-15">  ) </span>
<span id="cb12-16"></span>
<span id="cb12-17"></span>
<span id="cb12-18">tenure_age_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toronto|Vancouver|Calgary|Montr"</span>,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>avg_shelco_per_room,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>coarse_age_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running shelter costs per room in Canada"</span>,</span>
<span id="cb12-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age of primary</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">household maintainer"</span>,</span>
<span id="cb12-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb12-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb12-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(CMA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>TENUR)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-coarse-age-tenure" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-coarse-age-tenure-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-coarse-age-tenure-1.png" id="fig-shelter-cost-per-room-by-coarse-age-tenure" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-coarse-age-tenure-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9
</figcaption>
</figure>
</div>
</div>
</div>
<p>Here we see how owners diverge more than renters. Some of this divergence may reflect the effects of the roominess-location tradeoff and economies of scale, insofar as households tend to move toward the suburbs as they age. But it’s also the case that older owners are especially likely to have locked in lower shelter costs by buying increasingly expensive properties earlier in time than in younger owners, and they’ve also had longer to pay down their mortgages. For renters, by contrast, both young and old are relatively more exposed to the current housing market. Nevertheless, comparing back to Figure&nbsp;7 it does appear that older renters in Toronto and Vancouver may still be benefiting from a cushion due to rent control interacting with longer term tenancies.</p>
<p>Figure&nbsp;10 offers another way to look at age variation for owners. As noted earlier, actual shelter costs are distinct from housing services consumed, with the latter incorporating a measure of rent that owner-occupiers are understood to be paying to themselves. Here we compare the value of housing services consumed, as measured by imputed rent - which we estimate by applying a 4% <a href="https://en.wikipedia.org/wiki/Capitalization_rate">CAP rate</a> to the reported value of each home - to the reported running shelter costs that we have been using so far.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">imputed_rent_age_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_all_r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,</span>
<span id="cb13-3">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(rooms),</span>
<span id="cb13-5">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(rooms,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(AGEGRP != "15 to 17 years") |&gt;</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode_broad_age_groups</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb13-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_shelco_per_room =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO_real<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb13-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_imputed_rent_per_room=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>((VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI<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.04</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;">12</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>rooms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> WEIGHT, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb13-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(rooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb13-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">people=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb13-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA,Year,TENUR)</span>
<span id="cb13-16">  ) </span>
<span id="cb13-17"></span>
<span id="cb13-18"></span>
<span id="cb13-19">imputed_rent_age_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"avg_"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(name,</span>
<span id="cb13-22">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"avg_shelco_per_room"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reported shelter cost per room"</span>,</span>
<span id="cb13-23">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"avg_imputed_rent_per_room"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Imputed rent per room"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter_metros</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toronto|Vancouver|Calgary|Montr"</span>,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>coarse_age_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1991</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">dollar_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prefix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Running imputed rent to shelter costs per room in Canada for owner-occupiers"</span>,</span>
<span id="cb13-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age of primary</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">household maintainer"</span>,</span>
<span id="cb13-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly shelter cost per room (2021 dollars)"</span>,</span>
<span id="cb13-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb13-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(CMA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>name)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-shelter-cost-per-room-by-coarse-age-imputed-rent" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-shelter-cost-per-room-by-coarse-age-imputed-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-coarse-age-imputed-rent-1.png" id="fig-shelter-cost-per-room-by-coarse-age-imputed-rent" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-shelter-cost-per-room-by-coarse-age-imputed-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10
</figcaption>
</figure>
</div>
</div>
</div>
<p>The age divergence mostly disappears when we look at housing services consumed by owners. This underscores the takeaway from Figure&nbsp;7 that the main driver of the spread between age groups is not a preference effect, but rather how renters tend to gradually become owners and longer term owners are able to lock in lower shelter costs over time. Savings, including building up equity, can also help older owners cash out when they move and put up large downpayments on new homes. So even if older owners are theoretically paying themselves high rents as owner-occupiers of their new homes, the mortgage payments contributing directly to their shelter costs stay lower than for younger homeowners.</p>
</section>
<section id="upshot" class="level1">
<h1>Upshot</h1>
<p>What does all of this mean for our understanding of housing pressures faced by different age groups in Canada? We know from a lot of our previous work, and as shown in Figure&nbsp;8, that younger people are forming households at successively lower rates in areas with growing housing shortages. At the same time, we see that young people increasingly face higher shelter costs per room compared to their older compatriots. Figure&nbsp;7 leads us to believe that this cannot be simply explained by changing preferences of younger people. Instead, the divergence shown in Figure&nbsp;5 and Figure&nbsp;6 seems mostly due to older people having on average lived in their homes longer and having locked in lower shelter costs in the past, often while transitioning from renter to homeowner. This means that older people are, on average, still somewhat insulated from current pressures in the housing market, and younger people, on average, face the brunt of the current housing shortage in Canada. Worth noting that these averages, of course, still hide a great deal of variability within each age group.</p>
<p>Household formation and housing costs are connected. Rising housing costs depress household formation, and in turn shortages that mechanically lead to depressed household formation also heighten competition for any housing coming to market. These are two sides of the same coin, as evidenced when directly comparing housing costs to household formation. <span class="citation" data-cites="housing-is-a-housing-problem.2025">(<span class="nocase">von Bergmann and Lauster</span> 2025)</span></p>
<p>At the same time it’s important to recognize that this is not a Canada-wide problem. The Québec City metro area has managed to avoid housing shortages, and real prices per room have remained fairly flat. Rising incomes in Québec City have allowed households to form at increasing rates, with the result being improved housing outcomes. This may in part be due to the Québec City metro area not facing the same population pressures as some of the other regions. But we can also see that Calgary, the metro area with the highest population growth among our sample, has done a much better job at keeping up with demand and mitigating housing shortages than some of the lower growth regions.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-10-25 21:34:42 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb16-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [841cf37] 2025-10-26: key image for extra school tax calculator post</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb18-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.0.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.5                
 [3] knitr_1.50                rlang_1.1.6              
 [5] xfun_0.53                 generics_0.1.4           
 [7] S7_0.2.0                  jsonlite_2.0.0           
 [9] glue_1.8.0                git2r_0.36.2             
[11] htmltools_0.5.8.1         mountainmathHelpers_0.1.4
[13] scales_1.4.0              rmarkdown_2.30           
[15] grid_4.5.1                evaluate_1.0.5           
[17] tibble_3.3.0              fastmap_1.2.0            
[19] yaml_2.3.10               lifecycle_1.0.4          
[21] compiler_4.5.1            dplyr_1.1.4              
[23] RColorBrewer_1.1-3        htmlwidgets_1.6.4        
[25] pkgconfig_2.0.3           rstudioapi_0.17.1        
[27] farver_2.1.2              digest_0.6.37            
[29] R6_2.6.1                  tidyselect_1.2.1         
[31] pillar_1.11.1             magrittr_2.0.4           
[33] tools_4.5.1               gtable_0.3.6             
[35] ggplot2_4.0.0            </code></pre>
</div>
</div>
</details>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-mhu.2025" class="csl-entry">
Lauster, Nathanael, and Jens von Bergmann. 2025. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981–2021.”</span> <em>The History of the Family</em> 0 (0): 1–30. <a href="https://doi.org/10.1080/1081602X.2024.2448986">https://doi.org/10.1080/1081602X.2024.2448986</a>.
</div>
<div id="ref-housing_shortages_doubled_up_households.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“Housing Shortages and Doubled up Households.”</span> <em>Plan Canada</em> 64 (4): 16–21. <a href="https://mountainmath.github.io/housing_shortages_and_doubled_up_households/">https://mountainmath.github.io/housing_shortages_and_doubled_up_households/</a>.
</div>
<div id="ref-first-time-buyer-lorenz-curves.2020" class="csl-entry">
<span class="nocase">Stewart, Keith, and Jens von Bergmann</span>. 2020. <em>First-Time Buyer <span>Lorenz</span> Curves</em>. <a href="https://doodles.mountainmath.ca/posts/2020-09-28-first-time-buyer-lorenz-curves/">https://doodles.mountainmath.ca/posts/2020-09-28-first-time-buyer-lorenz-curves/</a>.
</div>
<div id="ref-first-time-buyer-lorenz-curves-revisited.2024" class="csl-entry">
<span class="nocase">Stewart, Keith, and Jens von Bergmann</span>. 2024. <em>First Time Buyer <span>Lorenz</span> Curves Revisited</em>. <a href="https://doodles.mountainmath.ca/posts/2024-01-16-first-time-buyer-lorenz-curves-revisited/">https://doodles.mountainmath.ca/posts/2024-01-16-first-time-buyer-lorenz-curves-revisited/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
<div id="ref-tenure-and-household-independence-across-the-life-course-1981-2021.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024. <em>Tenure and <span>Household</span> <span>Independence</span> Across the <span>Life</span> <span>Course,</span> 1981-2021</em>. <a href="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/">https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</a>.
</div>
<div id="ref-housing-is-a-housing-problem.2025" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2025. <em>Housing Is a Housing Problem</em>. <a href="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/">https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/</a>.
</div>
</div>


</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{age-disparity-in-shelter-cost-per-room.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Age {Disparity} in {Shelter} {Cost} Per {Room}},
  date = {2025-10-25},
  url = {https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Age Disparity in
Shelter Cost Per Room.”</span> <em>MountainDoodles</em>, accepted,
October 25. <a href="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/">https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <category>PUMF</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/</guid>
  <pubDate>Sat, 25 Oct 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-10-25-age-disparity-in-shelter-cost-per-room/index_files/figure-html/fig-shelter-cost-per-room-by-coarse-age-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Multiplex reforms – the details matter</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/08/29/multiplex-reforms-the-details-matter/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(httr)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rvest)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(VancouvR)</span>
<span id="cb1-5"></span>
<span id="cb1-6">pplos_cache_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/pplos"</span>)</span>
<span id="cb1-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.exists</span>(pplos_cache_path)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(pplos_cache_path)</span></code></pre></div></div>
</details>
</div>
<p>From books to blog posts, we’ve long been on the record advocating for reforms to the regulation of low-density urban lots, enabling more people to share less land (e.g. <span class="citation" data-cites="lauster.2016 teardown_index.2018 lots-of-opportunity-estimating-the-zoning-tax-in-vancouver.2021 demand-based-zoning.2025">(Lauster 2016; <span class="nocase">Dahmen et al.</span> 2018; <span class="nocase">von Bergmann and Lauster</span> 2021, 2025)</span>). On all of the lots zoned to protect single-family detached housing - North America’s “Great House Reserve” - the most obvious reform has been to enable multiple families to divide up space instead. Reforms changing low-density zoning to enable duplex, triplex, and increasingly multiplex running to 4-6 units per lot or beyond, all seem like easy solutions to housing shortages. Vancouver was an early leader in many of these reforms via enabling secondary suite and laneway houses, but recently it seems like it is falling behind, even after a much touted shift to the <a href="https://bylaws.vancouver.ca/zoning/zoning-by-law-district-schedule-r1-1.pdf">R1-1 zone</a> putatively allowing multiplexes across most of the urban landscape. As it turns out, housing regulation has grown quite complicated, and restrictions on the number of dwellings per lot aren’t the only things holding back additional housing on low-density lots. When it comes to enabling multiplexes, the devil is in the details. In this post, we first step outside of Vancouver to highlight some of our recent research into the details of multiplex reforms elsewhere in BC, and then return to the City to see how multiplex are faring locally.</p>
<p>Working together with colleagues, we explored the current progress and future potential of various multiplex reforms across BC on behalf of the province. We noted that two communities, Kelowna and Coquitlam, upzoned about 800 single family parcels to allow four-plexes, Kelowna in 2016 and Coquitlam in 2019. We investigated the outcomes of this upzoning for our 2023 modelling report for the provincial Small Scale Multi-Unit Housing (SSMUH) legislation. <span class="citation" data-cites="bc_ssmuh_toa.2023">(<span class="nocase">von Bergmann et al.</span> 2023)</span> While these two upzonings looked quite similar on paper, they had quite different outcomes. This observation underlines the difficulty in modelling outcomes of the provincial legislation insofar as they left implementation details up to municipalities. We added very strong caveats throughout the analysis that our report assumed faithful implementation not just of the broad parameters of the legislation but also the full intent.</p>
<p>Subsequently, we felt that it would be worthwhile to turn the sections on Kelowna and Coquitlam into a more formal study to further quantify the effects of the two upzonings and turn this into a paper, which just came out. <span class="citation" data-cites="upzoning_details_matter.2025">(<span class="nocase">von Bergmann et al.</span> 2025)</span> This more formally quantifies the ways in which these two reforms that look very similar on paper differ in real word outcomes.</p>
<p>At a high level the impact of the multiplex zoning changes in these cities can be seen in Figure&nbsp;1, which shows the annual number of SFH, Duplex, Triplex and Fourplex dwelling units completed in the upzoned area as well as several “control” areas for each of the two cities.</p>
<div id="fig-kelowna-coquitlam-multiplexes" class="quarto-layout-panel">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-kelowna-coquitlam-multiplexes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-kelowna-coquitlam-multiplexes" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-kelowna-redevelopment" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-kelowna-redevelopment-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/images/kelowna_redevelopment.jpg" class="img-fluid figure-img" data-ref-parent="fig-kelowna-coquitlam-multiplexes">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-kelowna-redevelopment-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a) Kelowna
</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="fig-kelowna-coquitlam-multiplexes" style="flex-basis: 50.0%;justify-content: flex-start;">
<div id="fig-coquitlam-redevelopment" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-coquitlam-redevelopment-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/images/coquitlam_redevelopment.jpg" class="img-fluid figure-img" data-ref-parent="fig-kelowna-coquitlam-multiplexes">
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-coquitlam-redevelopment-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b) Coquitlam
</figcaption>
</figure>
</div>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-kelowna-coquitlam-multiplexes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
<p>The reasons for the difference in outcomes are complex, and we don’t have a full understanding. The biggest difference that we suspect matters here is that Kelowna focused on fast permit times, setting up pre-approved (outright) designs with very short permit times, and relatively fast permit times for general applications with different designs. One detail here is that the design competition for the fast-tracked pre-approved designs required architects to work in conjunction with developers to ensure that there was interest to actually build these. By contrast with Kelowna’s fast-tracking, permit times in Coquitlam were significantly longer, involving detailed conditional review and introducing significant risk into the development process that small builders are often ill equipped to handle.</p>
<p>Another difference was parking requirements, with Coquitlam requiring two parking spaces per unit while Kelowna only required one. Minimum lot width in both Kelowna and Coquitlam guaranteed that there was enough space for four parking spaces, and Coquitlam allowed the two parking spaces for each unit to be stacked, so the outer car would have to get moved in order for the inner car to get in or out. This seems like a drag, but we don’t believe parking requirements strongly constrained the number of lots where four-plexes could physically be built. Rather the Coquitlam requirements may have significantly constrained the design of four-plexes and degraded the usable outdoor space. Could be an issue, but probably not as big a deal as the permitting process.</p>
<p>The biggest takeaway of our comparative research is that the details of multiplex reforms matter, particularly as they apply to simplifying the process for developers, reducing timelines and providing certainty to outcomes. So let’s return to the City of Vancouver’s reform!</p>
<section id="vancouver-multiplexes" class="level1">
<h1>Vancouver multiplexes</h1>
<p>The province drew upon our research in formulating its <a href="https://www2.gov.bc.ca/gov/content/housing-tenancy/local-governments-and-housing/housing-initiatives/smale-scale-multi-unit-housing">Small Scale Multi Unit Housing (SSMUH) reforms</a>, mandating all municipalities allow multiplex on previously single-family lots (as of November 2023). The City of Vancouver was working on its own multiplex reform, and snuck under the wire by passing a bylaw that reclassified single-family lots to multiplex in October of 2023, just before the lots at issue would have come under provincial regulation.<sup>1</sup> We take this as an occasion to take stock of how Vancouver multiplexes have fared so far. We don’t have enough data to do a thorough analysis like we did for Kelowna and Coquitlam, but there is enough to take a preliminary look.</p>
<p>Prior to the multiplex legislation Vancouver allowed three units on most single family lots at 0.85 FSR under single ownership or up to four units structured as two strata lots with a main unit and a lock-off suite each for a combined 0.7 FSR. The multiplex legislation allowed for more freedom on how to configure units and increased the allowable density to 1 FSR. However, going beyond duplex and additions to floor space both remained conditional uses rather than outright, requiring contributions of various sorts to the City and close planner review. Contributions to the City were subjected to value capture analysis intended to balance out construction of multiplex with single detached and duplex. Subsequently the bylaw has been amended to allow up to six units in frequent transit areas as well as an expansion of the area that allows for multiplex as required by provincial SSMUH legislation. Of note, the density requirements remain far below the provincial guidelines of an implicit 1.5 to 1.6 FSR despite being in one of the the highest demand areas in the province.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">get_plpos_data_for_range <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(start_date,end_date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempdir</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">permit_type=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb2-2">  </span>
<span id="cb2-3">  url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://plposweb.vancouver.ca/Public/Default.aspx?PossePresentation=PermitSearchByDate"</span></span>
<span id="cb2-4">  hash <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> digest<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;">digest</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(url,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,start_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,end_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,permit_type))</span>
<span id="cb2-5">  cache_file <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;">file.path</span>(cache_path,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pplos_"</span>,hash,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".rds"</span>))</span>
<span id="cb2-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(cache_file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>refresh) {</span>
<span id="cb2-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_rds</span>(cache_file))</span>
<span id="cb2-8">  }</span>
<span id="cb2-9"> </span>
<span id="cb2-10">  datachanges <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;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"'AP0pCEcP9fH5dRPaDCclXjvW/RWG6DuU1GJqdoYCJdeMEyQgezIdkf31vuOO6FHEH8/cUCRQrVyF1WbfAGq8Y/T9t4QFxQutWcQbJVh9WHzZCVQ7Zpc6O75JEskEPmBFKDdtN0yeAWQB0yz6jVU1Yc8hGYZMN/whBxaSFWd5K6Zxe7JaoDMkr7AMmQw58VwFKYfL2AI7D4EPpAw98aeD/JCbWPGBB2DrVpwBAnIK6UTqiFwKdpteDDJp54Xpxn6dY3U2WldqXWhkTkpvRlhlYQ%3D%3D'"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>,</span>
<span id="cb2-11">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('C','S0',972146,'"</span>,start_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" 00:00:00')"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>,</span>
<span id="cb2-12">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('C','S0',984849,'"</span>,end_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" 00:00:00')"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>)</span>
<span id="cb2-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(permit_type)) {</span>
<span id="cb2-14">    datachanges <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;">paste0</span>(datachanges,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('C','S0',1039023,'"</span>,permit_type,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"')"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>)</span>
<span id="cb2-15">  }</span>
<span id="cb2-16">  datachanges <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;">paste0</span>(datachanges,</span>
<span id="cb2-17">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('C','S0',972146,'"</span>,start_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" 00:00:00')"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>,</span>
<span id="cb2-18">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('C','S0',984849,'"</span>,end_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" 00:00:00')"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>,</span>
<span id="cb2-19">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"('F','ext-gen1009',0,0)"</span>)</span>
<span id="cb2-20">  </span>
<span id="cb2-21">  result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> httr<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;">POST</span>(url, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">body =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datachanges =</span> datachanges,</span>
<span id="cb2-22">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">currentpaneid=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1018439</span>, </span>
<span id="cb2-23">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">functiondef=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb2-24">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">comesfrom=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"posse"</span>,</span>
<span id="cb2-25">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sortcolumns=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{}"</span>,</span>
<span id="cb2-26">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">paneid=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">987904</span>),</span>
<span id="cb2-27">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">encode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"form"</span>)</span>
<span id="cb2-28">  </span>
<span id="cb2-29">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>status_code <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;">200</span>) {</span>
<span id="cb2-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Failed to fetch data"</span>)</span>
<span id="cb2-31">  }</span>
<span id="cb2-32">  </span>
<span id="cb2-33">  content <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> httr<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;">content</span>(result)</span>
<span id="cb2-34">  </span>
<span id="cb2-35">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># data &lt;- html_table(content, fill = TRUE)[[1]]</span></span>
<span id="cb2-36">  </span>
<span id="cb2-37">  table <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> content <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-38">    rvest<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;">html_node</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"table"</span>)</span>
<span id="cb2-39">  </span>
<span id="cb2-40">  header <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> table<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"th.possegrid"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-41">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>()</span>
<span id="cb2-42">  </span>
<span id="cb2-43">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(header)<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="cb2-44">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">message</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No data found: "</span>,start_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" - "</span>,end_date)</span>
<span id="cb2-45">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span> (<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span>
<span id="cb2-46">  }</span>
<span id="cb2-47">  </span>
<span id="cb2-48">  header[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span></span>
<span id="cb2-49">  </span>
<span id="cb2-50">  data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> table <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-51">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tbody"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-52">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(tb){</span>
<span id="cb2-53">      d<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>tb <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"td.possegrid"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-54">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-55">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-56">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(header) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-57">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enframe</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-58">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-59">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url=</span>tb <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"href"</span>))</span>
<span id="cb2-60">    })  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-61">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Date"</span>),\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">n"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-62">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%B %d, %Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-63">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>X)</span>
<span id="cb2-64">  </span>
<span id="cb2-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_rds</span>(data,cache_file)</span>
<span id="cb2-66">  data</span>
<span id="cb2-67">}</span>
<span id="cb2-68"></span>
<span id="cb2-69">get_detail_plpos_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(url,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempdir</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb2-70">  hash <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> digest<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;">digest</span>(url)</span>
<span id="cb2-71">  cache_file <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;">file.path</span>(cache_path,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pplos_"</span>,hash,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".rds"</span>))</span>
<span id="cb2-72">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(cache_file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>refresh) {</span>
<span id="cb2-73">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_rds</span>(cache_file))</span>
<span id="cb2-74">  }</span>
<span id="cb2-75">  html<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_html</span>(url)</span>
<span id="cb2-76">  </span>
<span id="cb2-77">  tables <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;">html_table</span>(html)</span>
<span id="cb2-78"></span>
<span id="cb2-79">  zoning_table <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;">map_df</span>(tables, \(tb){</span>
<span id="cb2-80">    r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb2-81">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ncol</span>(tb)<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;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(tb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(tb[<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;">2</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> tb[<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;">2</span>]<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;">"Zoning Code"</span>) {</span>
<span id="cb2-82">      r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tb <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-83">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</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;">"name"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-84">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(name<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-85">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">duplicated</span>(name,value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-86">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>()</span>
<span id="cb2-87">    }</span>
<span id="cb2-88">    r</span>
<span id="cb2-89">  })</span>
<span id="cb2-90">  </span>
<span id="cb2-91">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sanity check</span></span>
<span id="cb2-92">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Zoning Code"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(zoning_table) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.list</span>(zoning_table<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Zoning Code</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) {</span>
<span id="cb2-93">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(url)</span>
<span id="cb2-94">  }</span>
<span id="cb2-95">   </span>
<span id="cb2-96">  details <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> html <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"span.possedetail"</span>)</span>
<span id="cb2-97">  detailsg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> html <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"span.possegrid"</span>)</span>
<span id="cb2-98">  </span>
<span id="cb2-99">  wd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WorkDescription"</span>,details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>)))</span>
<span id="cb2-100">  wt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TypeOfWork"</span>,details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>)))</span>
<span id="cb2-101">  wpid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ParcelID"</span>,detailsg <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>)))</span>
<span id="cb2-102">  wfolio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FormattedAccountNumber"</span>,details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>)))</span>
<span id="cb2-103">  </span>
<span id="cb2-104">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># permit_status &lt;- html |&gt; html_nodes("div.permitStatusDisplay") |&gt; html_text()</span></span>
<span id="cb2-105">  </span>
<span id="cb2-106">  dd<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 class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Work Description</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>details[wd] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb2-107">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type of Work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>details[wt] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb2-108">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(detailsg[wpid] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>),</span>
<span id="cb2-109">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Folio=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(detailsg[wpid] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>)) </span>
<span id="cb2-110">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(zoning_table)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb2-111">    dd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_cols</span>(zoning_table)</span>
<span id="cb2-112">  }</span>
<span id="cb2-113"></span>
<span id="cb2-114">  dd<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url=</span>url)</span>
<span id="cb2-115">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_rds</span>(dd,cache_file)</span>
<span id="cb2-116">  dd</span>
<span id="cb2-117">}</span>
<span id="cb2-118"></span>
<span id="cb2-119"></span>
<span id="cb2-120">start_date <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.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2023-10-01"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># date permit data seems to start in the system</span></span>
<span id="cb2-121">end_date <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.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-08-27"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sys.Date()</span></span>
<span id="cb2-122"></span>
<span id="cb2-123">dp_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;">seq</span>(start_date,end_date,<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;">"1 month"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-124">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(\(d){</span>
<span id="cb2-125">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_plpos_data_for_range</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_date=</span>d,</span>
<span id="cb2-126">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_date=</span>d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb2-127">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path =</span> pplos_cache_path,</span>
<span id="cb2-128">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">permit_type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Development Permit"</span>)</span>
<span id="cb2-129">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-130">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>()</span>
<span id="cb2-131"></span>
<span id="cb2-132">bp_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;">seq</span>(start_date,end_date,<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;">"1 month"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-133">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(\(d){</span>
<span id="cb2-134">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#if (strftime(d,"%m")=="01") print(paste0("Starting ",d))</span></span>
<span id="cb2-135">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_plpos_data_for_range</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_date=</span>d,</span>
<span id="cb2-136">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_date=</span>d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb2-137">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path =</span> pplos_cache_path,</span>
<span id="cb2-138">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">permit_type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building Permit"</span>)</span>
<span id="cb2-139">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-140">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>()</span>
<span id="cb2-141"></span>
<span id="cb2-142">recent_dp_details <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dp_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-143">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2023-10-17'</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-144">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(x){</span>
<span id="cb2-145">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_detail_plpos_data</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path=</span>pplos_cache_path)</span>
<span id="cb2-146">  },<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.progress=</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;">by=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"url"</span>)</span>
<span id="cb2-147"></span>
<span id="cb2-148">recent_bp_details <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bp_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-149">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2023-10-17'</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-150">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(x){</span>
<span id="cb2-151">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_detail_plpos_data</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cache_path=</span>pplos_cache_path)</span>
<span id="cb2-152">  },<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.progress=</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;">by=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"url"</span>)</span>
<span id="cb2-153"></span>
<span id="cb2-154">multiplexes_dp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> recent_dp_details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-155">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"multiplex"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Work Description</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-156">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Zoning Code</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1-1"</span>,</span>
<span id="cb2-157">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type of Work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New Building"</span>) </span>
<span id="cb2-158">multiplexes_bp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> recent_bp_details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-159">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"multiplex"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Work Description</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-160">         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#`Zoning Code`=="R1-1",</span></span>
<span id="cb2-161">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type of Work</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New Building"</span>) </span>
<span id="cb2-162"></span>
<span id="cb2-163">status_levels <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;">"Created"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In Review"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Preparing Recommendation"</span>,</span>
<span id="cb2-164">                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Response to Conditions"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Approved Subject to Conditions"</span>,</span>
<span id="cb2-165">                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stop Work"</span>,</span>
<span id="cb2-166">                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ready For Issue"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Issued"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completed"</span>)</span>
<span id="cb2-167"></span>
<span id="cb2-168">pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> multiplexes_dp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-169">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(multiplexes_bp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-170">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> multiplexes_dp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-171">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(PID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Type<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Development Permit"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-172">                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(PID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>())) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-173">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb2-174">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb2-175">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-176">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Completed Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-177">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>PID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-178">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Status=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Status,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>status_levels))</span>
<span id="cb2-179">  </span>
<span id="cb2-180">permit_colours <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;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Set1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(),status_levels)</span>
<span id="cb2-181"></span>
<span id="cb2-182">status_counts <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-183">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Type,Status,PID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-184">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-185">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(Type,Status) </span></code></pre></div></div>
</details>
</div>
<p>So far in Vancouver there have been 429 development permit applications for multiplexes, of which 143 have been issued (or completed) and subsequently 123 building permits have been issued (or completed).<sup>2</sup> Table Table&nbsp;1 table gives a more detailed breakdown.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">status_counts <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Number of multiplexes</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  tinytable<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;">tt</span>()</span></code></pre></div></div>
</details>
<div id="tbl-status-counts" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned" id="tbl-status-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1
</figcaption>
<div aria-describedby="tbl-status-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_figr8gndtqbddy0ganob(i, j, css_id) {
          var table = document.getElementById("tinytable_figr8gndtqbddy0ganob");
          var cell = table.rows[i]?.cells[j];  // Safe navigation to avoid errors
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_figr8gndtqbddy0ganob');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_figr8gndtqbddy0ganob(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_figr8gndtqbddy0ganob");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: 11, j: 0 }, { i: 11, j: 1 }, { i: 11, j: 2 },  ], css_id: 'tinytable_css_epcmc08i3g4btycgpnfe',}, 
          { positions: [ { i: 0, j: 0 }, { i: 0, j: 1 }, { i: 0, j: 2 },  ], css_id: 'tinytable_css_k84ugkm963qafy9ijamq',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_figr8gndtqbddy0ganob(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script>

    <style>
      /* tinytable css entries after */
      .table td.tinytable_css_epcmc08i3g4btycgpnfe, .table th.tinytable_css_epcmc08i3g4btycgpnfe { border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_k84ugkm963qafy9ijamq, .table th.tinytable_css_k84ugkm963qafy9ijamq { border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
    <div class="container">
      <table class="table table-borderless" id="tinytable_figr8gndtqbddy0ganob" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        
              <tr>
                <th scope="col">Type</th>
                <th scope="col">Status</th>
                <th scope="col">Number of multiplexes</th>
              </tr>
        </thead>
        
        <tbody>
                <tr>
                  <td>Development Permit</td>
                  <td>In Review</td>
                  <td>45</td>
                </tr>
                <tr>
                  <td>Development Permit</td>
                  <td>Preparing Recommendation</td>
                  <td>2</td>
                </tr>
                <tr>
                  <td>Development Permit</td>
                  <td>Response to Conditions</td>
                  <td>168</td>
                </tr>
                <tr>
                  <td>Development Permit</td>
                  <td>Approved Subject to Conditions</td>
                  <td>71</td>
                </tr>
                <tr>
                  <td>Development Permit</td>
                  <td>Issued</td>
                  <td>137</td>
                </tr>
                <tr>
                  <td>Development Permit</td>
                  <td>Completed</td>
                  <td>6</td>
                </tr>
                <tr>
                  <td>Building Permit</td>
                  <td>In Review</td>
                  <td>114</td>
                </tr>
                <tr>
                  <td>Building Permit</td>
                  <td>Stop Work</td>
                  <td>5</td>
                </tr>
                <tr>
                  <td>Building Permit</td>
                  <td>Ready For Issue</td>
                  <td>1</td>
                </tr>
                <tr>
                  <td>Building Permit</td>
                  <td>Issued</td>
                  <td>119</td>
                </tr>
                <tr>
                  <td>Building Permit</td>
                  <td>Completed</td>
                  <td>4</td>
                </tr>
        </tbody>
      </table>
    </div>
<!-- hack to avoid NA insertion in last line -->
</div>
</div>
</figure>
</div>
</div>
<p>Our data does not come with clean unit counts, a scan of permit detail descriptions indicates that a little below half of multiplex applications are for fourplexes, with the next popular configuration being triplexes at around 30%.</p>
<p>Figure&nbsp;2 shows how multiplex applications have been progressing.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">fit.dp <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>(rank <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Type<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Development Permit"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Created Date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rank=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</span>()))</span>
<span id="cb4-5"></span>
<span id="cb4-6">slope.dp <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;">coefficients</span>(fit.dp)[<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;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()</span>
<span id="cb4-7"></span>
<span id="cb4-8">eligible_zones <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;">"R1-1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RT-7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RT-9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FSD"</span>)</span>
<span id="cb4-9">eligible_parcels <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;">aggregate_cov_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"property-tax-report"</span>,</span>
<span id="cb4-10">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tax_assessment_year='2025'"</span>,</span>
<span id="cb4-11">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group_by=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'zoning_district'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(zoning_district <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(eligible_zones)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb4-15"></span>
<span id="cb4-16">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Status)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(.,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Status=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Created"</span>,Status)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-19">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Status=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Status,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>status_levels)),</span>
<span id="cb4-20">             <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Status =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Status, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completed"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Issued"</span>)), </span>
<span id="cb4-22">                          <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Completed Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Completed Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_segment</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>min_date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend=</span>max_date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend=</span>PID),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb4-26">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb4-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.minor.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb4-28">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>permit_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(permit_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</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;">"Development Permit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building Permit"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 month"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%b"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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;">"Multiplex Development Permits in the City of Vancouver"</span>,</span>
<span id="cb4-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: PLPOS"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-multiplex-timeline" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-multiplex-timeline-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/index_files/figure-html/fig-multiplex-timeline-1.png" id="fig-multiplex-timeline" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-multiplex-timeline-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>Starting the clock in November of 2023, development permit applications are coming in at an average pace of 23 per month so far, or about 273 per year, almost double of the 150 applications a year that Vancouver staff originally projected. Translated into a redevelopment rate of the roughly 69,000 eligible single family parcels in Vancouver this means that at the current rate each parcel has about a 0.4% percent chance of redevelopment each year, about double what Coquitlam saw after their upzoning but less than a tenth Kelowna’s outcomes.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">permit_tmielines <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Type<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building Permit"</span>,</span>
<span id="cb5-3">                         Status <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Issued"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completed"</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Status <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Issued"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Complted"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <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;">start=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>PID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span>end<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>start) </span></code></pre></div></div>
</details>
</div>
<p>Figure&nbsp;3 shows the distribution of permitting timelines, from creating of the development permit to issuance of building permit, conditioning on having an issued building permit. The right-censored nature of the data makes it difficult to give definitive statements about permit times, a strong lower bound on permit times derived from is 350 days, with a wide distribution ranging from very fast permit times of 200 days at the low end and over 500 days at the high end so far.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">permit_tmielines <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>diff)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(diff)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"City of Vancouver R1-1 multiplex permit time"</span>,</span>
<span id="cb6-7">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of days (DP submission to BP issued)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-multiplex-timeline-histogram" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-multiplex-timeline-histogram-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/index_files/figure-html/fig-multiplex-timeline-histogram-1.png" id="fig-multiplex-timeline-histogram" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-multiplex-timeline-histogram-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;4 shows permit timelines ordered by creation data, with blank lines where building permits have not yet been issued.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">permit_levels <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;">"Development permit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Development permit (Pending)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Parallel development/building permit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Application gap"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building permit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building permit (Pending)"</span>)</span>
<span id="cb7-2"></span>
<span id="cb7-3">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb7-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">last_type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Type),</span>
<span id="cb7-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(PID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(PID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Days=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Issue Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Created Date</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Days=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(last_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;">"Development Permit"</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,Days)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Days)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(.,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Days=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(Days,<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>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb7-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb7-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.minor.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb7-15">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(Days,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Permit time for multiplexes"</span>,</span>
<span id="cb7-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb7-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of days from DP application created in the system until BP issued"</span>,</span>
<span id="cb7-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: PLPOS"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-permit-timelines" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-permit-timelines-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/index_files/figure-html/fig-permit-timelines-1.png" id="fig-permit-timelines" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-permit-timelines-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>A naive interpretation might suggest that permit times are decreasing, but it would be foolish to conclude that from this graph. The blank spaces of projects that have not yet received a building permit highlight the right-censored nature of the data and signal projects with outstanding permits that, once they get issues, will necessarily have longer permit times than nearby (in terms of creation date) permit applications that have already been issued building permits. Vancouver council’s 3-3-3-1 Permit Approval Framework, which suggests that multiplex permits should be given in 3 weeks, is clearly not working yet, and there is no strong indication of improvement in multiplex permitting timelines.</p>
<p>Figure&nbsp;5 offers a view into the landscape of low-density development in the R1-1, RT-7, RT-9, and FSD zones that legalized multiplexes by tracking issued building permits for single family, duplex, and multiplexes by year the permit was issued.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">zoning <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;">get_cov_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zoning-districts-and-labels"</span>)</span>
<span id="cb8-2">zoning_mask <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> zoning <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(zoning_district <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> eligible_zones)</span>
<span id="cb8-3">building_permits <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;">get_cov_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"issued-building-permits"</span>,</span>
<span id="cb8-4">                                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"typeofwork='New Building' AND propertyuse = 'Dwelling Uses'"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-5">  sf<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;">st_filter</span>(zoning_mask) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(issuedate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-08-28"</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pin end date</span></span>
<span id="cb8-7"></span>
<span id="cb8-8">processed_permits_raw <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> building_permits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(permitcategory <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New Build - Low Density Housing'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New Build - Standalone Laneway'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb8-10">           permitnumber <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> multiplexes_bp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Number) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(permitnumber <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> multiplexes_bp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Number <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;">"Multiplex"</span>,</span>
<span id="cb8-12">                       specificusecategory <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Laneway House"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> specificusecategory,</span>
<span id="cb8-13">                       specificusecategory <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single Detached House w/Sec Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1FD w/ Family Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Principal Dwelling Unit w/Lock Off"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Secondary Suite,Single Detached House w/Sec Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single Detached House w/Sec Suite,Single Detached House"</span>) <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;">"SFH w/Sec Suite"</span>,</span>
<span id="cb8-14">                       specificusecategory <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single Detached House"</span>) <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;">"SFH"</span>,</span>
<span id="cb8-15">                       specificusecategory <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex w/Secondary Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex w/Secondary Suite,Secondary Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex,Lock -off Unit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Secondary Suite,Duplex w/Secondary Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex,Secondary Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lock -off Unit,Duplex"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lock -off Unit,Duplex w/Secondary Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex w/Secondary Suite,Lock -off Unit"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex,Lock -off Unit,Secondary Suite"</span>) <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;">"Duplex w/Sec Suite"</span>,</span>
<span id="cb8-16">                       <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-17">  sf<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;">st_transform</span>(mountainmathHelpers<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;">lambert_conformal_conic_at</span>(.))</span>
<span id="cb8-18"></span>
<span id="cb8-19">processed_permits <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> processed_permits_raw <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(use <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;">"Laneway House"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-21">  sf<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;">st_join</span>(processed_permits_raw <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-22">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(use <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;">"Laneway House"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-23">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LW_issueyear=</span>issueyear) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-24">                sf<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;">st_buffer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wLW=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(LW_issueyear) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(issueyear)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(LW_issueyear) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(issueyear)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(LW_issueyear) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(wLW <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> use<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;">"SFH"</span> <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;">"SFH w/LWH"</span>,</span>
<span id="cb8-27">                       wLW <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> use<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;">"SFH w/Sec Suite"</span> <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;">"SFH w/Sec Suite &amp; LWH"</span>,</span>
<span id="cb8-28">                       <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> use)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(use,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"SFH"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SFH w/Sec Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SFH w/LWH"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SFH w/Sec Suite &amp; LWH"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Duplex w/Sec Suite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiplex"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)))</span>
<span id="cb8-30"></span>
<span id="cb8-31">processed_permits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(use<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;">"Other"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">issueyear=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(issueyear,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(up to Aug)"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>issueyear,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(use))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</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;">"Dark2"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Building permits for new buildings in area eligible for multiplexes since Oct 2023"</span>,</span>
<span id="cb8-38">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year permit was issued"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of issued building permits"</span>,</span>
<span id="cb8-39">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Project type"</span>,</span>
<span id="cb8-40">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: CoV Open Data"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-low-density-building-permits" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-low-density-building-permits-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/index_files/figure-html/fig-low-density-building-permits-1.png" id="fig-low-density-building-permits" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-low-density-building-permits-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<p>We see the shift away from almost exclusive single family housing (though often suited and some with laneway houses<sup>3</sup>) towards more duplexes and multiplexes, but the overall number of low-density building permits has not increased substantially. The multiplex reform has – by design – not led to a significant increase in the overall rate of redevelopment of low-density lots.</p>
<p>So far results from Vancouver’s multiplex reform appear to fall somewhere between Kelowna’s and Coquitlam’s. To be sure, new multiplex have entered the pipeline, but their progress has been stalled by permitting review. Developers continue to fall back on dwelling types (single-family house and duplex) offering less relief for housing shortages but enabled by outright approval processes, as well as those including secondary suites requiring conditional approval processes, but where developers have more experience and certainty working through permitting processes.</p>
<p>It’s worth noting that Vancouver’s overall density of 1 FSR is higher than both Kelowna and Coquitlam, but the base density allowed for existing single family use, including secondary suites and laneway houses, is also higher in Vancouver. Nevertheless, both remain lower than provincial guidelines for SSMUH. Moreover, demand to live in the area is higher in Vancouver, so it’s not clear how differences in density allowances translates.</p>
<p>Apart from differences in demand and existing vs updated density allowances, value capture efforts may be holding back some of the reform’s potential. The reform handicapped higher density multiplex options with amenity contributions to the City and/or other limitations (secured rental or “affordable ownership” units) <a href="https://www.shapeyourcity.ca/multiplexes/widgets/142819/faqs#31283">put in place intentionally to keep land values low</a>. Importantly, though the equity concerns go unrecognized by the City, this tips the scales to the benefit of the most expensive form of housing - single-family detached - and against prospective buyers willing to share land across multiple households. Nevertheless small-scale developers are proving more willing to try out the new forms on offer than anticipated by planning staff, perhaps in hopes that they can scale up multiplex in the future or otherwise better prepare themselves for future reforms.</p>
<p>A more successful multiplex reform would see the City actively encouraging multiplex instead of just conditionally permitting them under value capture conditions. Expediting permits for pre-approved forms of multiplex, as was done for Kelowna, would help! Of note, there have been moves in this direction. A OneCity proposal <a href="https://council.vancouver.ca/20250723/documents/cfscmotion7.pdf">Streamlining the Provision of Duplex and Multiplex Housing in R1-1 Zoning</a> exploring further reforms was put forward as a motion by Councillor Lucy Maloney in July and was unanimously <a href="https://council.vancouver.ca/20250723/documents/cfsc20250723min.pdf#page=27">approved by Council</a> ahead of a forthcoming review of R1-1 zoning being prepared by staff. If, as we suggest, the devil is in the details for multiplex reform, there’s a still a chance to get him out!</p>
<p>More broadly, stepping out of the multiplex fixation, more successful housing reforms would see the City asking what form of housing would match demand to live in different parts of the city and generally work to enable those forms to get built. <span class="citation" data-cites="demand-based-zoning.2025">(<span class="nocase">von Bergmann and Lauster</span> 2025)</span> By contrast, the provincial SSMUH initiative just sets a new baseline for zoning, stepping up from single-family detached. The Transit-Oriented Area (TOA) initiative does the same by specifying new baselines near major transit investments. Cities can go beyond these minimums by allowing more people to share land for housing everywhere, and they can get an idea of what the outcomes will be by looking to current demand and proactively planning to let developers build to that demand. That doesn’t mean everywhere will look alike (indeed, its often planning constraints that reinforce cookie-cutter designs). Instead, providing greater flexibility for builders is likely to result in more diverse urban landscapes. Working through the implications for that kind of reform would return urban planning to a forward looking activity recognizing the value of city life for everyone rather than a backward looking activity reducing land values to protect the privileges of the select few who can still afford a full lot of their own.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-08-29-multiplex-reforms----the-details-matter/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-10-25 21:35:06 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb11-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [841cf37] 2025-10-26: key image for extra school tax calculator post</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.0.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] VancouvR_0.1.9  rvest_1.0.5     httr_1.4.7      lubridate_1.9.4
 [5] forcats_1.0.1   stringr_1.5.2   dplyr_1.1.4     purrr_1.1.0    
 [9] readr_2.1.5     tidyr_1.3.1     tibble_3.3.0    ggplot2_4.0.0  
[13] tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.6              xfun_0.53                
 [3] htmlwidgets_1.6.4         websocket_1.4.4          
 [5] processx_3.8.6            tzdb_0.5.0               
 [7] vctrs_0.6.5               tools_4.5.1              
 [9] ps_1.9.1                  generics_0.1.4           
[11] proxy_0.4-27              pkgconfig_2.0.3          
[13] KernSmooth_2.23-26        RColorBrewer_1.1-3       
[15] S7_0.2.0                  lifecycle_1.0.4          
[17] git2r_0.36.2              compiler_4.5.1           
[19] farver_2.1.2              chromote_0.5.1           
[21] mountainmathHelpers_0.1.4 htmltools_0.5.8.1        
[23] class_7.3-23              yaml_2.3.10              
[25] later_1.4.4               pillar_1.11.1            
[27] classInt_0.4-11           tidyselect_1.2.1         
[29] digest_0.6.37             stringi_1.8.7            
[31] sf_1.0-21                 rprojroot_2.1.1          
[33] fastmap_1.2.0             grid_4.5.1               
[35] here_1.0.2                cli_3.6.5                
[37] magrittr_2.0.4            triebeard_0.4.1          
[39] e1071_1.7-16              withr_3.0.2              
[41] scales_1.4.0              promises_1.4.0           
[43] timechange_0.3.0          rmarkdown_2.30           
[45] otel_0.2.0                hms_1.1.4                
[47] evaluate_1.0.5            knitr_1.50               
[49] rlang_1.1.6               urltools_1.7.3.1         
[51] Rcpp_1.1.0                glue_1.8.0               
[53] DBI_1.2.3                 xml2_1.4.0               
[55] rstudioapi_0.17.1         jsonlite_2.0.0           
[57] R6_2.6.1                  units_1.0-0              </code></pre>
</div>
</div>
</details>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-teardown_index.2018" class="csl-entry">
<span class="nocase">Dahmen, Joseph, Jens von Bergmann, and Misha Das</span>. 2018. <span>“Teardown Index: Impact of Property Values on Carbon Dioxide Emissions of Single Family Housing in Vancouver.”</span> <em>Energy and Buildings</em> 170 (July): 95–106. <a href="https://doi.org/10.1016/j.enbuild.2018.03.012">https://doi.org/10.1016/j.enbuild.2018.03.012</a>.
</div>
<div id="ref-lauster.2016" class="csl-entry">
Lauster, Nathanael. 2016. <em>The Death and Life of the Single-Family House</em>. November 2. <a href="https://doi.org/10.2307/j.ctvrdf3ms">https://doi.org/10.2307/j.ctvrdf3ms</a>.
</div>
<div id="ref-upzoning_details_matter.2025" class="csl-entry">
<span class="nocase">von Bergmann, Jens, Thomas Davidoff, Nathan Lauster, and Tsur Somerville</span>. 2025. <span>“Upzoning and Redevelopment: The Details Matter.”</span> <em>Journal of Housing Economics</em> 69 (September): 102078. <a href="https://doi.org/10.1016/j.jhe.2025.102078">https://doi.org/10.1016/j.jhe.2025.102078</a>.
</div>
<div id="ref-bc_ssmuh_toa.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, Tom Davidoff, Albert Huang, Nathanael Lauster, and Tsur Somerville</span>. 2023. <em>SSMUH and TOA Scenarios in British Columbia</em>. BC Ministry of Housing. <a href="https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf">https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf</a>.
</div>
<div id="ref-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021. <em>Lots of <span>Opportunity:</span> <span>Estimating</span> the <span>Zoning</span> <span>Tax</span> in <span>Vancouver</span></em>. <a href="https://doodles.mountainmath.ca/posts/2021-07-25-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver/">https://doodles.mountainmath.ca/posts/2021-07-25-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver/</a>.
</div>
<div id="ref-demand-based-zoning.2025" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2025. <em>Demand Based Zoning</em>. <a href="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/">https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/</a>.
</div>
</div>


</section>
</section>


<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>Vancouver amended it’s multiplex zoning to also allow multiplexes in RT-7, RT-9, and FSD zoning in <a href="https://council.vancouver.ca/20240613/phea20240613ag.htm">June 2024</a>.↩︎</p></li>
<li id="fn2"><p>Some projects might have several building permits, which we collapsed in this count.↩︎</p></li>
<li id="fn3"><p>Laneway houses can also be built on lots with existing single family homes as infill, we don’t show those here.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{multiplex-reforms----the-details-matter.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Multiplex Reforms -\/- the Details Matter},
  date = {2025-08-29},
  url = {https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Multiplex Reforms
-- the Details Matter.”</span> <em>MountainDoodles</em>, accepted,
August 29. <a href="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/">https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/</a>.
</div></div></section></div> ]]></description>
  <category>Vancouver</category>
  <category>land use</category>
  <category>zoning</category>
  <category>density</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/</guid>
  <pubDate>Fri, 29 Aug 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-08-29-multiplex-reforms----the-details-matter/index_files/figure-html/fig-low-density-building-permits-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Demand based zoning</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/08/04/demand-based-zoning/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(VancouvR)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span></code></pre></div></div>
</details>
</div>
<p>What if zoning was responsive to underlying demand to live in an area? That is, rather than reserving parts of the landscape for the exclusive use of those who can afford an entire underlying lot, what if we instead allow people to build enough residential floor space on the lot to share? This exercise sets up a kind of counterfactual, enabling us to get a look at both: a) what underlying demand for floor space on a lot actually looks like, and b) how our current zoning regime sets itself up to protect the most privileged from having to fully compete with this demand.</p>
<p>In Vancouver we have recently seen a range of land use reforms, from upzoning (almost) the entire city for multiplexes, to in principle allowing higher density in the Broadway corridor, and in some instances actually zoning for it, to land use plans around the Rupert and Renfrew Skytrain stations that also incorporate some upzoning in the “villages” areas. All these changes trigger a lot of discussions with people bringing arguments for or against land use changes. But one part that rarely enters the arguments is estimates of the underlying demand to live in these areas.</p>
<p>We believe failure to take underlying demand into account is a pretty large oversight. That’s because demand mostly reflects people working through competitive constraints on their housing choices. Housing is good, actually. People derive tremendous value from living in housing, in a location that offers them the mix of access to jobs and amenities that fits their needs. To the extent that zoning works against enabling more people to benefit from living in a given location, it’s holding people back from better meeting their needs. There are quite a range of justifications for zoning, but where zoning is strongly binding (holding back the addition of more housing), the costs of doing so should be more clearly taken into account.</p>
<p>Zoning in Vancouver has been strongly binding for several decades now. It is very rare that a developer would build below the maximum floor space allowed by outright zoning (usually explicitly governed here by floor space ratio - or FSR - relative to lot size). And there is very little capacity to build within existing outright zoning. <span class="citation" data-cites="zoned-capacity-promise-and-pitfalls.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024)</span> In other words, in Vancouver zoning has been used to limit the choices people have, to deny them to live where they would want to live. With the logical consequence that housing has become expensive, and people double up or move further out to make housing work. And in planning discussions we never sit down to quantify the harm that’s done in this way, and weigh it against the benefits of keeping densities low.</p>
<p>Quantifying the price of zoning people out is not easy of course, but we can flip this around and ask what it would look like if we zoned for the demand to live in an area. That’s complicated too of course, but in this post we will do a very rough first approximation on what that would look like in Vancouver.</p>
<p>The underlying idea is similar to what we have discussed before when trying to estimate useful housing targets. The demand to live in an area gets expressed via prices and rents, prices are information aggregators that combine the diverse drivers of demand into a single number. We can use this mechanism to estimate the demand for housing by how much housing could be profitably built there. We can assume that construction gets more expensive as we build taller, and a profit-maximizing developer will build until the marginal (social) cost of constructions, including profit expectations, equals the price they can sell it for. That’s a lot of work to estimate, but we can roughly proxy for it using the heuristic that when new building are constructed in an unconstrained environment, the underlying land value generally makes up about 20% of the total value of the property. <span class="citation" data-cites="glaeser_gyourko.2003">(Glaeser and Gyourko 2003)</span> This observation was made for single family homes, but work looking at the average vs marginal construction cost of multi-family buildings suggests that this is a reasonable approximation for multi-family buildings as well. <span class="citation" data-cites="eriksen2021">(Eriksen and Orlando 2021)</span></p>
<p>More precisely, with the land value per square foot of land <img src="https://latex.codecogs.com/png.latex?%5Coverline%7BLV%7D">, and the construction cost, including development fees and profit expectations, per square foot <img src="https://latex.codecogs.com/png.latex?C">, we can estimate the floor space ratio <img src="https://latex.codecogs.com/png.latex?FSR"> that would be needed achieve a share of land value of <img src="https://latex.codecogs.com/png.latex?LS"> as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0ALS%20=%20%5Cfrac%7B%5Coverline%7BLV%7D%7D%7B%5Coverline%7BLV%7D+FSR%20%5Ccdot%20C%7D%0A"></p>
<p>or equivalently</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AFSR%20=%20%5Cleft(%5Cfrac%7B%5Coverline%7BLV%7D%7D%7BLS%7D%20-%20%5Coverline%7BLV%7D%5Cright)%20%5Ccdot%20%5Cfrac%7B1%7D%7BC%7D%0A"></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">tax_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;">get_cov_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dataset_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"property-tax-report"</span>,</span>
<span id="cb2-2">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tax_assessment_year='2025'"</span>,</span>
<span id="cb2-3">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">select =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zoning_district, zoning_classification, current_land_value, land_coordinate as tax_coord"</span>)</span>
<span id="cb2-4">property_polygons <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;">get_cov_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dataset_id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"property-parcel-polygons"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">  sf<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;">st_transform</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">26910</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7">schools <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;">get_cov_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dataset_id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schools"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-8">  sf<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;">st_transform</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">26910</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-9">  sf<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;">st_make_valid</span>() </span>
<span id="cb2-10"></span>
<span id="cb2-11">parks <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;">get_cov_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dataset_id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parks-polygon-representation"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-12">  sf<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;">st_transform</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">26910</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-13">  sf<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;">st_make_valid</span>() </span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">construction_cost <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span></span>
<span id="cb3-2">ls <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span></span>
<span id="cb3-3"></span>
<span id="cb3-4">plot_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> property_polygons <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(tax_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <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;">current_land_value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(current_land_value),</span>
<span id="cb3-6">                                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zoning"</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>(.))),</span>
<span id="cb3-7">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>tax_coord),<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;">"tax_coord"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_area</span>(.) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> units<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;">set_units</span>(ft<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lv=</span>current_land_value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor =</span> (lv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>ls<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>lv)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>construction_cost) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_join</span>(schools <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">school=</span>school_name,geometry)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_join</span>(parks <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">park=</span>park_name,geometry) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_buffer</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(school) <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;">NA</span>,</span>
<span id="cb3-14">                             <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(park) <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;">NA</span>,</span>
<span id="cb3-15">                             tax_coord<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;">"17579092"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#langara golf course</span></span>
<span id="cb3-16">                             tax_coord<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;">"64003596"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#jericho</span></span>
<span id="cb3-17">                             tax_coord<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;">"81227904"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fraserview golf course</span></span>
<span id="cb3-18">                           <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FSR_floor)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(FSR_floor, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span></code></pre></div></div>
</details>
</div>
<p>In British Columbia the BC Assessment authority estimates land values and building values separately for each property. While this is difficult, estimates are fairly good at least for low density areas where teardowns are common and land value estimates can be anchored to lots that get redeveloped. <span class="citation" data-cites="HelsleyRosenthal">(Rosenthal and Helsley 1994)</span> We will rely on the BC Assessment estimates made available via the City of Vancouver Open Data portal for the rest of this post.</p>
<p>If we set land share at 20% and calculate FSR for properties in Vancouver, we get a map like Figure&nbsp;1 providing a rough overview what this metric does.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">fsr_colours <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;">setNames</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;">"firebrick"</span>,viridis<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;">viridis</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)),plot_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FSR_floor_d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())</span>
<span id="cb4-2">plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>FSR_floor_d),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>fsr_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Naive demand-based FSR"</span>,</span>
<span id="cb4-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(assuming $900/sqft construction cost and 20% land share)"</span>,</span>
<span id="cb4-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demand based FSR</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(lower bound)"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CoV Open Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-min-density-all" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-min-density-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/index_files/figure-html/fig-min-density-all-1.png" id="fig-min-density-all" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-min-density-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>Here we highlight areas where the estimated floor on the FSR limit is below 1 FSR in red. These tend to be special properties that either have industrial zoning, are on leased land, are non-market housing, or come with severe zoning restrictions. Which brings us to an important point limiting the usefulness of this metric:</p>
<p>Land values are affected by what zoning allows to be constructed on the land.</p>
<p>That is, in the map above, land values are downstream of zoning restrictions. The extreme gradients we see, for example, when moving half a block off of an arterial highlights this problem. Under current zoning, land values are a floor on demand estimates, and once we allow more housing, land values will likely also rise, which will in turn increase the FSR we need to allow to make sure not too much of purchaser’s money goes toward paying for land instead of the floor space they live in. On the other hand, high land values despite low density zoning are an expression of scarcity, forcing people to bid up housing. And making large scale changes in zoning, as opposed to lot by lot upzoning, reduces the scarcity pressure and thus reduces land values. Or to be more precise, <a href="https://michaelwiebe.com/blog/2025/07/land_model">as Michael Wiebe has pointed out</a>, upzoning from low density to high density increases the value of land zoned for low-density use, but decreases the value of land zoned for higher density use.</p>
<p>This complicates the picture substantially. At the same time, we are assuming a flat $900/sf cost function, but that’s really reasonable up to around 3 FSR. Above that we often move to concrete and everything gets not just more expensive but also more complicated on small lots. On the other hand, construction costs can come down substantially if we eliminate time and risk and allow for standardized buildings that enable modular construction.</p>
<section id="low-density-zoning" class="level1">
<h1>Low-density zoning</h1>
<p>We can simplify away a lot of these complications by just looking at low-density zoning. There are still some concerns, for example the city made building multiplexes on the west side more expensive in order to preserve some west-side exclusivity. More importantly minimum lot sizes and frontages vary substantially and have the effect of suppressing land values to subsidize mansions and foster exclusion in some parts of town. But just looking at low-density zoning gives a more level playing field. For this we take R1-1 zoning (formerly mostly RS zoning), RT zoning, and Shaughnessy (FSD) zoning as “low-density”, with results shown in Figure&nbsp;2.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">plot_data2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor =</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(zoning_district <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1-1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FSD"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^RT-"</span>,zoning_district) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FSR_floor,</span>
<span id="cb5-3">                                <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(FSR_floor, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb5-5"></span>
<span id="cb5-6">fsr_colours2 <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;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(viridis<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;">magma</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)),plot_data2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FSR_floor_d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())</span>
<span id="cb5-7"></span>
<span id="cb5-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(plot_data2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>FSR_floor_d),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>fsr_colours2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Naive demand-based FSR in low density zoning"</span>,</span>
<span id="cb5-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(assuming $900/sqft construction cost and 20% land share)"</span>,</span>
<span id="cb5-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demand based FSR</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(lower bound)"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CoV Open Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-min-density-low-density" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-min-density-low-density-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/index_files/figure-html/fig-min-density-low-density-1.png" id="fig-min-density-low-density" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-min-density-low-density-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>Focusing in on low-density zoning helps, but a new constraint emerges. The effect of minimum lot sizes is very visible, with e.g.&nbsp;sharp gradients around First Shaughnessy and across Blanca Street in the north-west part of Point Grey, where the city’s effort to force, and at the same time subsidize large mansion estates for those who can afford them is very visible.</p>
<section id="lot-size-adjustment" class="level2">
<h2 class="anchored" data-anchor-id="lot-size-adjustment">Lot size adjustment</h2>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">beta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.544</span></span>
<span id="cb6-2">standard_lot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</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;">33</span></span></code></pre></div></div>
</details>
</div>
<p>We have looked at the effect of minimum lot sizes previously and estimated the subsidy to estate mansion owners, or equivalently the loss of opportunity to Vancouverites due to the City preventing them from sharing land. <span class="citation" data-cites="lots-of-opportunity-estimating-the-zoning-tax-in-vancouver.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021)</span> We can leverage that to adjust for the effect of varying the size of (non-subdividable) lots. In that post we fit the random (grouped at the block level) intercept model</p>
<p><img src="https://latex.codecogs.com/png.latex?%0ALV%20=%20c%5Ccdot%20A%5E%5Cbeta,%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?LV=%5Coverline%7BLV%7D%5Ccdot%20A"> is the land value, <img src="https://latex.codecogs.com/png.latex?A"> is the lot area, <img src="https://latex.codecogs.com/png.latex?c"> is a constant depending on the group of parcels, and <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> is the scaling exponent that describes the attenuation of land values based on restrictive zoning. We estimated <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200.544"> for Vancouver, which allows us to scale land values across the city to a standard East Vancouver 33’ x 120’ lot of area <img src="https://latex.codecogs.com/png.latex?A_0%20=%203,960sf">, the modal lot size in Vancouver. More precisely, we estimate an adjusted land value <img src="https://latex.codecogs.com/png.latex?LV_0"> for each parcel that normalizes for the lot size effect via</p>
<p><img src="https://latex.codecogs.com/png.latex?%0ALV_0%20=%20LV%20%5Ccdot%20%5Cleft(%5Cfrac%7BA_0%7D%7B%7BA%7D%7D%5Cright)%5E%5Cbeta,%0A"> which we then normalize per square foot of standard lot size <img src="https://latex.codecogs.com/png.latex?%5Coverline%7BLV_0%7D%20=%20LV_0%20/%20A_0"> for consistency with the work above and map in Figure&nbsp;3.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">plot_data3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lv_adjusted =</span> current_land_value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (standard_lot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> standard_lot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted=</span>(lv_adjusted<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>ls<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>lv_adjusted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>construction_cost) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted =</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(FSR_floor) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FSR_floor_adjusted, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(FSR_floor_adjusted, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb7-6"></span>
<span id="cb7-7"></span>
<span id="cb7-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(plot_data3) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>FSR_floor_adjusted_d),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>fsr_colours2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lot size adjusted demand-based FSR in low-density zoning"</span>,</span>
<span id="cb7-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(assuming $900/sqft construction cost and 20% land share)"</span>,</span>
<span id="cb7-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demand based FSR</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(lower bound)"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CoV Open Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-min-density-normalized" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-min-density-normalized-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/index_files/figure-html/fig-min-density-normalized-1.png" id="fig-min-density-normalized" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-min-density-normalized-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can take that adjustment and mix it in with the estimates from Figure&nbsp;1 to get a more complete picture of the demand-based FSR across the city, as shown in Figure&nbsp;4.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">plot_data4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lv_adjusted =</span> current_land_value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (standard_lot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> standard_lot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted=</span>(lv_adjusted<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>ls<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>lv_adjusted)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>construction_cost) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted =</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(zoning_district <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1-1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FSD"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^RT-"</span>,zoning_district) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span></span>
<span id="cb8-5">                                         FSR_floor_adjusted,</span>
<span id="cb8-6">                                       <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FSR_floor)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted =</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(FSR_floor) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FSR_floor_adjusted, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FSR_floor_adjusted_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(FSR_floor_adjusted, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb8-9"></span>
<span id="cb8-10"></span>
<span id="cb8-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(plot_data4) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>FSR_floor_adjusted_d),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>fsr_colours2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demand-based FSR"</span>,</span>
<span id="cb8-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(assuming $900/sqft construction cost and 20% land share, lot size adjusted in low-density areas)"</span>,</span>
<span id="cb8-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demand based FSR</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(lower bound)"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CoV Open Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-min-density-normalized-all" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-min-density-normalized-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/index_files/figure-html/fig-min-density-normalized-all-1.png" id="fig-min-density-normalized-all" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-min-density-normalized-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>Having adjusted for low-density residential zoning, the map starts to look much more like we might expect, with job agglomeration and amenity effects driving demand more continuously around downtown and westward along the beachfront of Kitsilano, extending all the way to the border with the UBC Endowment Lands. At the same time, many of the remaining purple blotches on the map now highlight the zoning protections placed around industrial lands, here potentially blended with the disamenity effects of being surrounded by industrial uses. But it’s worth noting that even aside from industry, there are still some major issues with our integrated map.</p>
<p>We can clearly see the mixed-commercial zoning along many stretches of arterial roads that has higher (conditional) density limits forming a steep gradient to the lower density off-arterial areas. This gradient might indicate that our lower demand-based FSR estimates are too conservatives, but we also point out that upzoning broadly off-arterial, and thus greatly increasing land zoned for apartments, will decrease the value of the land along arterials that is currently one of the few places zoned for higher density.</p>
<p>Conversely we see parcels with unexpectedly low estimated demand along False Creek and Champlain Heights (likely related to leasehold status) as well as in multi-family zoned areas like the West End. The latter likely stems from how the very low density caps in most RM zones depress land values just like the minimum lot sizes in our low-density zones do. Unfortunately it gets harder to account for these effects given how area plans and (somewhat risky) upzoning expectations are layered on top of zoning. So our estimates are rather conservative outside of the low-density areas. On the other hand, a degree of conservatism might also be good insofar as adding a lot more high density multifamily zoning might be expected to reduce the price pressures on the existing high density multifamily zoning (as noted above). Aside from this, we also skip estimates for both parks and many other especially large properties that are either in the process of being developed (hello Jericho Lands!) or maybe should be (hello big empty golf courses!) Overall, while the adjustment we made for low-density zoning help (i.e.&nbsp;where limits on subdividing are strongly binding and impact land values), we’re stopping here for now, and we do not fully adjust for the effects of varying density and use limits across all zones.</p>
</section>
<section id="teardowns" class="level2">
<h2 class="anchored" data-anchor-id="teardowns">Teardowns</h2>
<p>Even based on the limited modelling here, there are several important corollaries for this kind of counterfactual exercise. Setting zoning “too high” so that the floor space allowed exceeds demand has little material consequence for housing construction; developers will simply avoid building out to the maximum allowable zoning if the marginal (social) cost of construction is higher than the price they can get for adding more housing. But when zoning restricts floor space significantly below the demand for housing, it ends up subsidizing the privileged few outbidding the rest at the cost of a range of other negative consequences.</p>
<p>The most immediate consequence of under-zoning land is that less housing gets built, so people get excluded from living in areas where they want to live, or have to double up to live there. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span> But there is a secondary consequence, insofar as under-zoning accelerates what we have called the <em>teardown cycle</em>. <span class="citation" data-cites="teardowns_data_story.2017">(<span class="nocase">von Bergmann and Dahmen</span> 2017)</span> When zoning does not allow new buildings to take full advantage of the value of the location, they start out with land value taking an elevated share of the total value of the property and the relative share of the building value remains artificially low relative to what we might normally expect. The typical share of land value for a typical new built single family home in Vancouver between 2006 and 2016 was 62%, far higher than our stipulated 20% threshold. <span class="citation" data-cites="teardowns_data_story.2017">(<span class="nocase">von Bergmann and Dahmen</span> 2017)</span></p>
<p>Low relative building values are generally well understood to be the most important predictor for when a building gets torn down. We usually expect these values to shrink over time as the building depreciates and underlying land values grow (assuming increasing demand over time), resulting in a gradually increasing likelihood of redevelopment. Under-zoning can dramatically speed up this process, leading to buildings that are still in good physical shape getting redeveloped. In Vancouver’s single-family zones we have observed this kind of acceleration with the average economic lifespan of buildings decreasing, resulting in a teardown cycle and increased carbon emissions. <span class="citation" data-cites="teardown_index.2018">(<span class="nocase">Dahmen et al.</span> 2018)</span> This is a direct negative consequence of planning policies that limit density far below demand, forcing new buildings to start halfway down their economic lifespan from the get-go. In addition to being bad for excluding people from where they want to live, zoning below demand is also a carbon time bomb – even before accounting for transportation related emissions from people being pushed further out of the city.</p>
</section>
</section>
<section id="zoning-for-resilience" class="level1">
<h1>Zoning for Resilience</h1>
<p>The best case for zoning is that we should be putting it to work in planning for the future rather than as a straitjacket tying us to the past. In Vancouver we generally expect demand to grow, so zoning should be more generous than current demand estimates, providing us the flexibility we need to adapt. Zoning enforcing low-density or low-rise forms should be more strongly justified in terms of costs to the future. Allowing taller “out of scale” buildings has several advantages. If builders are willing to provide more housing on a given site, that’s generally a good thing. Allowing more housing boosts supply and current supply elasticity. But also, allowing taller “out of scale” buildings boosts future supply elasticity by leaving more land for future (re-)development with minimal contribution to the teardown cycle. We see some of this kind of benefit today when we get infill development on sites containing with large setbacks around towers built during the late 60s and early 70s (a zoning requirement for the tower form at the time). Over the past 50 years Vancouver planning has had a high emphasis on uniformity and scaling down to meet existing context, but this backward looking zoning comes at a high cost to not just contemporary but also future supply elasticity. This is a direct cause of current and future unaffordability, and these trade-offs have mostly gone unacknowledged.</p>
<p>Forward looking zoning should take the costs of both exclusion and teardowns into account. We should be looking to increase resilience by allowing for a wide variety of uses and accommodating a broad range of building heights and forms in order to make it easier to adapt to future changes in demand.</p>
</section>
<section id="upshot" class="level1">
<h1>Upshot</h1>
<p>It’s useful to develop counterfactuals for existing floor space development, both to highlight underlying demand and illustrate the negative effects of zoning constraints. Ideally we would want to build a model that is less sensitive to minimum lot sizes as well as density and unit limits to draw out a price-sensitive demand surface, as we did in our <a href="https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf#page=63">report on the provincial SSMUH and TOA legislation</a> as visualized there in Figure 29. This approach can be extended to estimate economically optimal densities, with the additional benefit of being able to do away with the somewhat crude 20% land value share assumption.</p>
<p>Even though many complications remain to refined modelling, given both our provincial models and the crude estimates here, it’s safe to say that current zoning for residential floor space in the City of Vancouver is still far below demand in most parts of the city. Fundamentally that means official city policy is weighted against allowing people to share land for housing and toward forcing them to compete for it. It is unfortunate that when discussing reforms like multiplex zoning, demand estimates tend to either enter as a force to be countered (e.g.&nbsp;purposefully reducing potential land value to slow redevelopment), or never enter the discussion at all.</p>
<p>Planning necessitates accounting for an uncertain future. We believe that critically involves supporting people to live the lives they choose, without excluding future generations from doing the same. With respect to zoning, that means we should take current demand for housing (and other uses) seriously, and explicitly include it in planning discussions and tradeoffs. We need zoning that is resilient enough to adapt to changes and allow future demand growth to be met. And part of that resilience means taking a hard look at the climate impact of under-zoning, driving carbon emissions through the teardown cycle.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-08-04-demand-based-zoning/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-08-04 18:18:55 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb11-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [b18fe97] 2025-08-05: demand based zoning</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.5                
 [3] knitr_1.50                rlang_1.1.6              
 [5] xfun_0.52                 generics_0.1.4           
 [7] jsonlite_2.0.0            glue_1.8.0               
 [9] git2r_0.36.2              htmltools_0.5.8.1        
[11] mountainmathHelpers_0.1.4 scales_1.4.0             
[13] rmarkdown_2.29            grid_4.5.1               
[15] evaluate_1.0.4            tibble_3.3.0             
[17] fastmap_1.2.0             yaml_2.3.10              
[19] lifecycle_1.0.4           compiler_4.5.1           
[21] dplyr_1.1.4               RColorBrewer_1.1-3       
[23] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[25] rstudioapi_0.17.1         farver_2.1.2             
[27] digest_0.6.37             R6_2.6.1                 
[29] tidyselect_1.2.1          pillar_1.11.0            
[31] magrittr_2.0.3            tools_4.5.1              
[33] gtable_0.3.6              ggplot2_3.5.2            </code></pre>
</div>
</div>
</details>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-teardown_index.2018" class="csl-entry">
<span class="nocase">Dahmen, Joseph, Jens von Bergmann, and Misha Das</span>. 2018. <span>“Teardown Index: Impact of Property Values on Carbon Dioxide Emissions of Single Family Housing in Vancouver.”</span> <em>Energy and Buildings</em> 170 (July): 95–106. <a href="https://doi.org/10.1016/j.enbuild.2018.03.012">https://doi.org/10.1016/j.enbuild.2018.03.012</a>.
</div>
<div id="ref-eriksen2021" class="csl-entry">
Eriksen, Michael D., and Anthony W. Orlando. 2021. <span>“Returns to Scale in Residential Construction: The Marginal Impact of Building Height.”</span> <em>Real Estate Economics</em> 50 (2): 534–64. <a href="https://doi.org/10.1111/1540-6229.12357">https://doi.org/10.1111/1540-6229.12357</a>.
</div>
<div id="ref-glaeser_gyourko.2003" class="csl-entry">
Glaeser, Edward L., and Joseph Gyourko. 2003. <span>“The Impact of Zoning on Housing Affordability.”</span> <em>Federal Reserve Bank of New York Economic Policy Review</em> 9: 21–39. <a href="https://www.newyorkfed.org/medialibrary/media/research/epr/03v09n2/0306glae.pdf">https://www.newyorkfed.org/medialibrary/media/research/epr/03v09n2/0306glae.pdf</a>.
</div>
<div id="ref-mhu.2025" class="csl-entry">
Lauster, Nathanael, and Jens von Bergmann. 2025. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981–2021.”</span> <em>The History of the Family</em> 0 (0): 1–30. <a href="https://doi.org/10.1080/1081602X.2024.2448986">https://doi.org/10.1080/1081602X.2024.2448986</a>.
</div>
<div id="ref-HelsleyRosenthal" class="csl-entry">
Rosenthal, Stuart S., and Robert W. Helsley. 1994. <span>“Redevelopment and the Urban Land Price Gradient.”</span> <em>Journal of Urban Economics</em> 35 (2): 182–200. <a href="https://www.sciencedirect.com/science/article/abs/pii/S0094119084710126">https://www.sciencedirect.com/science/article/abs/pii/S0094119084710126</a>.
</div>
<div id="ref-teardowns_data_story.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Joseph Dahmen</span>. 2017. <em>Vancouver’s Teardown Cycle</em>. MountainMath. <a href="https://mountainmath.ca/teardowns">https://mountainmath.ca/teardowns</a>.
</div>
<div id="ref-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021. <em>Lots of <span>Opportunity:</span> <span>Estimating</span> the <span>Zoning</span> <span>Tax</span> in <span>Vancouver</span></em>. <a href="https://doodles.mountainmath.ca/posts/2021-07-25-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver/">https://doodles.mountainmath.ca/posts/2021-07-25-lots-of-opportunity-estimating-the-zoning-tax-in-vancouver/</a>.
</div>
<div id="ref-zoned-capacity-promise-and-pitfalls.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024. <em>Zoned <span>Capacity</span> - Promise and Pitfalls</em>. <a href="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/">https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/</a>.
</div>
</div>


</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{demand-based-zoning.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Demand Based Zoning},
  date = {2025-08-04},
  url = {https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Demand Based
Zoning.”</span> <em>MountainDoodles</em>, accepted, August 4. <a href="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/">https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/</a>.
</div></div></section></div> ]]></description>
  <category>Vancouver</category>
  <category>affordability</category>
  <category>density</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/</guid>
  <pubDate>Mon, 04 Aug 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-08-04-demand-based-zoning/index_files/figure-html/fig-min-density-normalized-all-1.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Housing is a housing problem</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/07/06/housing-is-a-housing-problem/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canpumf)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/mhr_pumf.R"</span>))</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/old_census_aehh_hh.R"</span>))</span></code></pre></div></div>
</details>
</div>
<p>The now well-know slogan <a href="https://homelessnesshousingproblem.com">Homelessness is a housing problem</a> <span class="citation" data-cites="colburn2022">(Colburn and Aldern 2022)</span> alludes to the fact that structural homelessness is caused by housing shortages, a topic that we recently examined in the Canadian context. <span class="citation" data-cites="homelessness-and-rents-in-canada.2025">(<span class="nocase">von Bergmann and Lauster</span> 2025)</span> In this post we want to take this to the logical conclusion and explain that <strong>housing is a housing problem</strong>. By this we mean that while, just like with homelessness, there are individual factors that explain why some people struggle finding adequate housing and others don’t, on a structural level the biggest issue is simply that we don’t have enough housing.</p>
<p>This might seem obvious, especially if we are familiar with the work on homelessness, which sits at the extreme of housing insecurity. But a surprising number of people keep insisting that the primary problem is not shortage but something else: The main culprit is sometimes the <a href="https://spacing.ca/toronto/2019/07/09/perks-the-risks-of-the-financialization-of-housing/"><em>financialization of housing</em></a>, or <a href="https://www.theglobeandmail.com/real-estate/vancouver/article-the-dark-side-of-investor-driven-housing/"><em>individual investors</em></a>, or simply <a href="https://www.thestar.com/opinion/contributors/greedy-landlords-make-moving-within-toronto-too-expensive/article_ec47ce70-6be6-5261-befe-97ef70c7dddf.html"><em>greed</em></a>, or <a href="https://www.ubcm.ca/about-ubcm/latest-news/bcs-housing-supply-keeping-pace-population-growth">not about the lack of housing overall, but just the lack of <em>affordable housing</em></a> (hint, this might be connected to the lack of housing overall).</p>
<p>We want to give a simple explanation for why these arguments fall short. This is not to say that fixing the housing shortage will solve all housing problems, but that fixing the housing shortage is necessary to solve most of our housing problems. Correspondingly, every kind of housing that adds on net to supply can help. Moreover a good chunk of the other issues that keep getting brought up are downstream of shortage. It is also clear that just adding new housing to the market to fix the shortage probably won’t be sufficient to ensure everyone has adequate access to the housing they need. As we have argued regularly we also need more non-market housing or cash supports to make this work. <span class="citation" data-cites="homelessness-and-rents-in-canada.2025 housing-targets.2023 distributional-effects-of-adding-housing.2024">(<span class="nocase">von Bergmann and Lauster</span> 2025, 2023b, 2024a)</span> But adding lots of new housing to the market in lots of different forms should almost certainly be part of the solution to fixing our housing shortage.</p>
<p>A secondary point we are making in this post is that the singular focus on “affordability”, generally measured via shelter cost to household income ratios, is problematic and needs augmenting with other measures. Taken on its own it is likely to misguide us. In technical terms, a utility function that focuses on shelter cost and household income is misspecified and not well-aligned with measuring housing outcomes as experienced by individuals.</p>
<section id="a-hypothetical-example" class="level1">
<h1>A hypothetical example</h1>
<p>Maybe the best way to understand the problem is to take an extreme example that addresses all of the common arguments against supply being the main problem. Let’s assume, by some mechanism, we could socialize the entire housing supply overnight. That eliminates any forms of <em>financialization</em>, <em>individual investors</em>, <em>greed</em> or profit motive, and government could set rents to eliminate any <em>affordability</em> concerns. What could housing in Canada look like under that scenario?</p>
<section id="allocation" class="level2">
<h2 class="anchored" data-anchor-id="allocation">Allocation</h2>
<p>The first question is how would housing get allocated under such a system? In real life, we’ve seen a few examples, for instance in China <span class="citation" data-cites="forrest2012shaping">(Forrest and Izuhara 2012)</span> and Russia <span class="citation" data-cites="zavisca2008property">(Zavisca 2008)</span>, where after a period of initial upheaval housing was generally allocated by work unit. But these systems famously didn’t last. For simplicity let’s assume that on the day the housing stock got nationalized everyone happened to want to move - but only locally (perhaps imagine something like China’s hukou system preventing interregional migration and set aside the <a href="https://www.justice.gc.ca/eng/csj-sjc/rfc-dlc/ccrf-ccdl/check/art6.html">Charter Right violations</a> entailed). Let’s also imagine government gets to allocate housing for everyone. Ignoring problems of how to allocate housing of different quality and location, government might want to allocate each family unit a home according to their needs, at a minimum by number of bedrooms.</p>
<p>But right off the bat this runs into a major problem: In most metro areas there are already a lot more family units than homes. Some families or unattached individuals will have to share homes and government will have to decide who and how. Some may enjoy sharing a home and one might imagine government setting up a system where people can volunteer to share a home rather than to get one of their own, but that probably requires giving out some perks (or exercising some coercion). To understand how this would play out we first need an estimate how many homes we are short and how many would have to share.</p>
<p>Fortunately that’s an easy question to answer since we have worked this out in the past, although the answer depends a bit on what kind of sharing we think is acceptable as a baseline. Our current rules in how we allocate non-market housing might give some guidance to that question. Non-market housing providers generally won’t issue lease agreements to doubled-up households and tenants who do share their non-market home with others run the risk of losing their benefits. One exception here is adult children who often are allowed in the parent’s household. To get a rough idea how we might distribute housing, we offer two metrics: a) the number of housing units required to avoid all doubling up (with some allowances for college-aged kids) shown in Figure&nbsp;1, <span class="citation" data-cites="housing_shortages_doubled_up_households.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span> and b) the number of homes needed so that every family unit can have their own home, with more generous allowances of adult children living with parents shown in Figure&nbsp;2.<sup>1</sup> <span class="citation" data-cites="doubling-up-distinguishing-families-from-households.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024b)</span></p>
<div id="fig-no-doubling-up" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-no-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/images/no_doubling_up.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-no-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: The minimum number of dwelling units needed to avoid any doubling up has increased between censuses in most census metropolitan areas. The Quebec City CMA is a notable exception in managing to translate increasing real incomes into improving housing outcomes.
</figcaption>
</figure>
</div>
<div id="fig-doubling-up-families" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-doubling-up-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-census-household-families-1.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-doubling-up-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Doubling up rates in Canadian metro areas. Doubling up rates are estimated as the excess ratio of families and unattached individuals to households.
</figcaption>
</figure>
</div>
<p>No matter which metric we pick, we end up with a significant number of families and individuals who would have to share homes, and in some metro areas that number is excessively high - to the level that it would require very strong government incentives to get enough people to share homes in order to make the numbers work. Some doubling up is voluntary, and metro regions at the lower end of the spectrum put some rough bounds on how much that might be given our general economic conditions in Canada. Of note, during the eras of state and work unit allocation in China and Russia, doubled up families remained strikingly common, with lengthy queues for young adults to achieve apartments of their own <span class="citation" data-cites="forrest2012shaping zavisca2008property">(Forrest and Izuhara 2012; Zavisca 2008)</span>. For instance, as Zavisca notes, “In 1985, the Soviet government estimated that 40 million new housing units, or a doubling of the housing stock, would be needed to provide separate dwellings for all families.” Dispensing with the trappings of capitalism did not, in fact, solve housing shortage.</p>
</section>
<section id="back-to-our-current-system" class="level2">
<h2 class="anchored" data-anchor-id="back-to-our-current-system">Back to our current system</h2>
<p>In our current system it’s not government giving out incentives to share housing, it’s the market generating high rents for a scarce resource. We can see the relationship directly by plotting prevailing rents against the number of homes needed to avoid all doubling up in Figure&nbsp;3. <span class="citation" data-cites="housing_shortages_doubled_up_households.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span></p>
<div id="fig-rents-doubling-up" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rents-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/images/rents_doubling_up.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rents-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: The relationship between rents and excess minimal household units over actual households can provide a benchmark for latent demographic housing demand across census metropolitan areas, excluding migration effects. Montréal and Vancouver are highlighted as large metro areas close to the regression line.
</figcaption>
</figure>
</div>
<p>Prevailing rents and prevalence of doubling up are tightly linked. People double up to pool income and make rent work. Rents, in turn, are mostly set by the wealthiest and most desperate person (or couple) who wants to escape their doubled-up living situation and form their own household. Doubling up is the main mechanism by which people adapt to a housing shortage, and in a (mostly) market driven housing system rents and prices adjust to sort people into minimal household units and doubled-up households.</p>
</section>
</section>
<section id="no-free-lunch" class="level1">
<h1>No free lunch</h1>
<p>The bottom line is that there is no free lunch. Rents are high because we don’t have enough housing. If all housing were socialized overnight the shortage would still be there and government would have to resort to coercion, queuing, or provision of high incentives to find enough people to double up in the existing housing stock. There is no way to solve this problem without building more housing. As government built more housing, use of line-ups, force, and incentives could drop. This, of course, is not so different from the relationship between rents and doubled-up households in our current market system. Rents, and people’s living situations, adapt to shortages and rents will fall as fewer people are forced to double up.<sup>2</sup> There are some other factors that matter too, income and wealth of the population as well as some cultural preferences for sharing, but that does not materially change this relationship. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span></p>
<section id="tweaking-allocation" class="level2">
<h2 class="anchored" data-anchor-id="tweaking-allocation">Tweaking allocation</h2>
<p>In our hypothetical example we changed the allocation mechanism while keeping the housing stock fixed. This re-shuffles who has to double up but does not change the number of families and unattached individuals that have to double up. Other softer changes to the housing system, for example introducing vacancy control, similarly just change the allocation mechanism, but in a different way. Here it’s not government deciding who has to double up, or giving out incentives for people to double up, but private landlords. If market mechanisms were tweaked to prevent rents from rising between tenants, a lot more people could theoretically afford to live on their own instead of doubling up. But without adding more housing as the number of potential household balloons, landlords are simply left with other mechanisms to decide who gets to rent the unit. Generally this will be who the landlord perceives as a “good renter”, which in many cases will be wealthier people, and families or individuals who seem most likely to pay or least likely to complain or damage the apartment. Maybe acquaintances or those bearing gifts. Probably not doubled up households, who after all add more wear and tear without bringing in more rent (this is why landlords aren’t generally fond of children! <span class="citation" data-cites="lauster2011no">(Lauster and Easterbrook 2011)</span>) Ultimately, freezing rents entails either further restricting landlord control and moving toward full state allocation, or it tends to introduce new means of assortment that may lead to those most in need doubling up even more – or left entirely without housing. After all, insofar as doubling up represents the slack we have in our housing system, without doubling up any shortage of housing means people will have to leave the region or become homeless. Changing the allocation mechanism in a way that directly reduces doubling up without adding housing can have disastrous consequences.</p>
</section>
</section>
<section id="a-history-of-progress-interrupted" class="level1">
<h1>A History of Progress Interrupted</h1>
<p>Figure&nbsp;3 directly links rents to how people manage to live. A theory about housing that can’t, or does not even attempt to explain why so many people remain doubled up in some markets, is simply not a serious theory about housing. This problem can sneak into analysis through taking existing households and their sizes for granted <a href="https://theconversation.com/ontarios-affordable-housing-task-force-report-does-not-address-the-real-problems-176869">as reflecting people’s differing preferences to live together</a> rather than differing constraints on their ability to live alone. Failing to note the flexibility of households in accommodating slack in our housing markets can lead to denial about our underlying housing shortages.</p>
<p>At an individual level we mostly experience housing as an affordability problem. When we say that housing in a specific region is unaffordable we may not mean that the housing we live in right now is unaffordable. For example, a 30 year old child living with parents likely lives in housing their (combined) household can easily afford. What we mean is that the housing outcomes we aspire to, the same outcomes that our peers in other parts of the country achieve, are out of reach in the region we live in. And while there may be good reasons why housing is somewhat more expensive in some parts of the country, there is no good reason why rents and prices have to vary as dramatically as they do.</p>
<p>At the systems level we see that collectively these housing aspirations can only be fulfilled if we have enough housing. We suggest making doubling up a primary target for housing policy. This lens avoids a lot of the pitfalls when using other metrics like Core Housing Need that are plagued by collider bias and lose sensitivity once our housing shortage is large enough. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span> What’s more, reducing doubled up households ties back to a history of housing progress. The rapid rise in household formation in post-war Canada until the early 1980s was seen as a great success for Canadian housing. <span class="citation" data-cites="wargon.1979 miron.1988 miron1989">(Wargon 1979; Miron 1988; Miron 1989)</span> Through the 1980s, however, these improvements were reversed in much of Canada, with household formation slipping in all metro areas outside of Quebec after 1981 as shown in Figure&nbsp;4. This happened despite real incomes continuing to rise.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">hmr_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_phm_timeline</span>(),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hmr_data_all.rds"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path=</span>here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-2"></span>
<span id="cb2-3">cma_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dark2"</span>),</span>
<span id="cb2-4">                          <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;">"Toronto"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,</span>
<span id="cb2-5">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Calgary"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Edmonton"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec City"</span>)),</span>
<span id="cb2-6">                          <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;">"Canada"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>))</span>
<span id="cb2-7"></span>
<span id="cb2-8">hmr_all <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,PRIHM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-10">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(PR,AGEGRP,PRIHM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-12">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span>PR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hmr=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,AGEGRP,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,PRIHM,CMA<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;">"Canada"</span>,Year<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;">"1981"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_hmr=</span>hmr),<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;">"AGEGRP"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Households=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(PRIHM,Count,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb2-16">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AEHH=</span>base_hmr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Households,AEHH),\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PUMF"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_1941_1976_aehh_hh</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-20">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Summary tapes</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Printed tables"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toronto"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,</span>
<span id="cb2-22">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Calgary"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Edmonton"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec City"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec (PR)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta (PR)"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>Households<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>AEHH) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>ratio) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fudge=</span>ratio<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;">lag</span>(ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Source),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fudge=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(fudge,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(fudge,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.direction=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"up"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fudge=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Source<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;">"PUMF"</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,fudge)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fudge=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(fudge,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fudge=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Year<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;">"1976"</span>,fudge,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only fudge 1976</span></span>
<span id="cb2-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>ratio<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>fudge,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span>Source)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PUMF"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Summary tapes</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Printed tables"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interaction</span>(CMA,Source))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1976"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1981"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cma_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1921</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;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ratio of Actual to Age-expected households (occupied (private) dwellings)"</span>,</span>
<span id="cb2-43">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb2-44">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Region/metro"</span>,</span>
<span id="cb2-45">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Occupied housing units / age-expected households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(based on 1981 Canadian household maintainer rates, log scale)"</span>,</span>
<span id="cb2-46">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1941-1976, 1971-2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-canada-cma-age-expected-households" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-canada-cma-age-expected-households-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/index_files/figure-html/fig-canada-cma-age-expected-households-1.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-canada-cma-age-expected-households-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Ratio of Actual to Age-expected households (occupied (private) dwelling units) in Canada
</figcaption>
</figure>
</div>
</div>
</div>
<p>Age-expected households are the number of households one would expect to see if age-specific household formation rates were equal to those in a fixed year, in our case 1981 when household formation peaked in Canada. The ratio of actual observed households to age-expected households based on the 1981 standard for Canada demonstrates where we’ve seen substantial backsliding since. Toronto and Vancouver really stand out! But really everywhere outside of Quebec (except for metropolitan Ottawa, which of course is partly in Quebec) has seen interruption to their progress in household formation since 1981.</p>
<p>To dive a bit further into the technicalities of assembling this figure, we split the time series into parts where the data was derived from the PUMF and that derived from published census tables and electronic summary tapes, these data series are not strictly comparable because the PUMF data allows for filtering on the population in private households, whereas the older data looks at the total population which is not quite the right metric to use here. In cases where the time series don’t overlap we connect them via dashed lines. Moreover, in older censuses the <em>households</em> concept was somewhat floating in definition as well as how enumerators coded this. <span class="citation" data-cites="wargon.1979 harris1994">(Wargon 1979; Harris 1994)</span>. Misalignment is small if age data as well as households counts are for the entire population, including households in collective dwellings, but larger discrepancies emerge if e.g.&nbsp;ages are reported for the entire population but household counts are only reported for private households, as is the case in the 1976 summary tapes. We adjusted the 1976 ratio to roughly account for this discrepancy. Some of the fields in the <a href="https://mdl.library.utoronto.ca/collections/numeric-data/census-canada/1961/statistics">1961</a> and <a href="https://mdl.library.utoronto.ca/collections/numeric-data/census-canada/1966/statistics">1966</a> summary tape data have coding issues, we replaced some of the data with manually entered data from the printed tables as appropriate. Consistency of reporting for older censuses is less clear and actual values may differ somewhat from the values we report in the graph, discrepancies because of inconsistencies in the consideration of private vs collective dwellings can result in a roughly 3% deviation from our reported ratios. Our time series for Canada exhibits a large kink in 1941, corresponding to a severe housing shortage caused by the great depression, triggering the government to directly participate in housing construction via the crown corporation <em>Wartime Housing Limited</em> it created for this purpose. <span class="citation" data-cites="wade1986">(Wade 1986)</span> The concept of Metropolitan areas (or “greater cities”) was introduced in 1941 and is not available prior to that. Metropolitan area boundaries adjust over time.</p>
<p>Age-expected households were previously suggested as input for econometric modelling <span class="citation" data-cites="dipasquale1994housing">(DiPasquale and Wheaton 1994)</span> to avoid collider bias when modelling housing demand elasticities, although unfortunately this insight seems to have become forgotten in much of the more recent economics literature, where people too often assume households as fixed and unresponsive to prices and rents, or household formation elasticities are under-estimated. Given the large changes in household formation over time and across metro areas shown in Figure&nbsp;4 misspecifying structural equation models by ignoring or under-estimating household formation leads to substantial collider bias.</p>
<p>The decline in household formation since 1981 cannot be explained by changes in cultural makeup. Cultural factors do play some small role, but these trends also hold when only looking at the non-immigrant non-visible minority sub-population in Canada and there is strong evidence that the main cause is increasing housing scarcity and, with it, increasing housing costs. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span></p>
</section>
<section id="doubling-up-as-a-metric" class="level1">
<h1>Doubling Up as a Metric</h1>
<p>We are not alone in pointing out that our standard household-based measures we use in Canada to monitor housing, like Core Housing Need, are insufficient, and calling for also tracking household living arrangements. This is particularly clear when looking at the period from 1941 to 1981 when Canada made a lot of progress in improving housing outcomes, while standard affordability measures did not change much. In 1989 John Miron observed:</p>
<blockquote class="blockquote">
<p>The analysis of affordability problems should not focus exclusively on the ratio of shelter cost to income. To do so is to view the outcome of the past forty years unduly harshly. Affordability measures should focus on how the opportunities for alternative housing have been improved over time. A nonfamily individual who now spends 40% of her income on a housing unit may feel much better off than her predecessor who had spent less on housing but shared her dwelling with others or lodged elsewhere. While not denying that this may still constitute an affordability problem, we should recognize that an important kind of progress has been made here. <span class="citation" data-cites="miron1989">(Miron 1989)</span></p>
</blockquote>
<p>The key insight here is that the utility function commonly used for housing outcomes that only looks at household income and shelter costs, is discontinuous across household formation, and more importantly, carries the opposite sign from how individuals experience their change in overall housing outcomes when un-doubling.</p>
<p>Miron continues:</p>
<blockquote class="blockquote">
<p>To focus exclusively on shelter-cost-to-income ratios as an indicator of affordable housing is thus too narrow. Those who point to the declining affordability of housing to the “average” household miss an important point. Given the large income and price elasticities of household formation among nonfamily individuals, each new program to improve affordability may well have the effect merely of increasing the number of newly-forming low-income households paying a high percentage of their income on housing.</p>
</blockquote>
<p>We note that people who see their shelter costs to income ratio go up when un-doubling generally form their own household because they feel it improves their overall housing outcomes despite reducing their affordability. Facilitating un-doubling is thus a worthy goal in its own right and leads to material improvement, albeit one that is not captured by commonly used metrics.</p>
<p>The last sentence of Miron’s paper is still very relevant today:</p>
<blockquote class="blockquote">
<p>Especially in light of the household formation elasticities, what exactly are the benefits to be gained by further improving affordability, and how are they best measured? What are the costs involved, and are present tools to improve affordability the most cost-effective way of achieving the gains? Unfortunately, there has been little careful analysis of these issues.</p>
</blockquote>
<p>We have wrangled with these questions and suggest that Minimal Household Units provide a useful framework to monitor improvements in housing outcomes. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span> This can be augmented with a range of related metrics, for example the ones exemplified in Figure&nbsp;1, Figure&nbsp;2, or Figure&nbsp;4.</p>
<p>Miron made his observations after looking back at 40 years of improving housing outcomes between 1941 to 1981 <span class="citation" data-cites="miron.1988 miron1989">(Miron 1988; Miron 1989)</span>, while we have been making the same observation when looking back at the last 40 years 1981 to 2021, except during that period we saw deteriorating housing outcomes. During those last four decades Household formation did not go back as much as it grew in the preceding four decades, and they did not decrease in all of Canada, Quebec saw continued gains. But improving housing outcomes seems natural and we don’t think much about them, while deteriorating (or even stagnant) housing outcomes are painful and much more visceral, especially while incomes are still rising and many other aspects of life are continuing to improve. At the same time the main metrics we use to monitor housing outcomes, chiefly shelter cost to income ratios, have failed to capture the great improvements in housing outcomes 1941 to 1981 as observed by Miron, and they have done a fairly poor job at capturing the decline since as we have pointed out previously. <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span></p>
<p>With Canada’s renewed effort to undo our housing shortage we accumulated over the past 40 years maybe now is the right time to develop better metrics that allow us to track progress.</p>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>Housing is a Housing Problem. Which is to say there’s not enough of it. Vacancy rates are a direct measure of shortages immediately available to apartment hunters, but short-term variation means they aren’t always linked to underlying structural problems. Prices and rents can point toward shortages, but only if we accept underlying market dynamics of supply and demand (which we pretty much do in the Canadian context). Here we want to make it plain that there is also a relatively straightforward demographic measure of housing shortage rooted in the flexibility of the household. Doubling up within existing households offers a degree of slack to markets where there aren’t enough dwellings to go around. Doubling up can make housing appear more affordable. But doubling up also represents a hardship, as well as a ready pool of demand exerting price pressure. As such, it’s important to track rates of doubling up (and/or actual v. expected household formation) in order to better understand housing hardship related to shortage. Elevating household formation and doubling up to a primary metric to measure housing progress also serves as an important compliment to traditional affordability metrics used in Canada that suffer from collider bias that makes it difficult to use them to track progress in solving housing problems.</p>
<p>As an important bonus, tracking doubling up demonstrates how shortage is at the heart of Canada’s housing problems. There’s no simple solution, for instance involving a tweak to allocation, that will solve our housing problems without adding a lot more housing. We’ve done it before, adding a lot more housing in the post-war years, both market and non-market (but mostly market) and it mostly worked! Things got better! Since 1981, it’s clear this project has stalled, and we simply haven’t kept up. That sounds like a housing problem.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-07-06-housing-is-a-housing-problem/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-08-01 21:42:29 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb5-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [9d47816] 2025-08-01: Merge pull request #10 from maswiebe/patch-2</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.5                
 [3] knitr_1.50                rlang_1.1.6              
 [5] xfun_0.52                 generics_0.1.4           
 [7] jsonlite_2.0.0            glue_1.8.0               
 [9] git2r_0.36.2              htmltools_0.5.8.1        
[11] mountainmathHelpers_0.1.4 scales_1.4.0             
[13] rmarkdown_2.29            grid_4.5.1               
[15] evaluate_1.0.4            tibble_3.3.0             
[17] fastmap_1.2.0             yaml_2.3.10              
[19] lifecycle_1.0.4           compiler_4.5.1           
[21] dplyr_1.1.4               RColorBrewer_1.1-3       
[23] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[25] rstudioapi_0.17.1         farver_2.1.2             
[27] digest_0.6.37             R6_2.6.1                 
[29] tidyselect_1.2.1          pillar_1.11.0            
[31] magrittr_2.0.3            tools_4.5.1              
[33] gtable_0.3.6              ggplot2_3.5.2            </code></pre>
</div>
</div>
</details>



</section>


<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-colburn2022" class="csl-entry">
Colburn, Gregg, and Clayton Page Aldern. 2022. <em>Homelessness Is a Housing Problem</em>. March 15. <a href="https://doi.org/10.2307/j.ctv2kx88m9">https://doi.org/10.2307/j.ctv2kx88m9</a>.
</div>
<div id="ref-dipasquale1994housing" class="csl-entry">
DiPasquale, Denise, and William C. Wheaton. 1994. <span>“Housing Market Dynamics and the Future of Housing Prices.”</span> <em>Journal of Urban Economics</em> 35 (1): 1–27. <a href="https://doi.org/10.1006/juec.1994.1001">https://doi.org/10.1006/juec.1994.1001</a>.
</div>
<div id="ref-forrest2012shaping" class="csl-entry">
Forrest, Ray, and Misa Izuhara. 2012. <span>“The Shaping of Housing Histories in Shanghai.”</span> <em>Housing Studies</em> 27 (1): 27–44. <a href="https://doi.org/10.1080/02673037.2012.629292">https://doi.org/10.1080/02673037.2012.629292</a>.
</div>
<div id="ref-harris1994" class="csl-entry">
Harris, Richard. 1994. <span>“The Flexible House: The Housing Backlog and the Persistence of Lodging, 1891<span></span>1951.”</span> <em>Social Science History</em> 18 (1): 31–53. <a href="https://doi.org/10.1017/s0145553200021441">https://doi.org/10.1017/s0145553200021441</a>.
</div>
<div id="ref-mhu.2025" class="csl-entry">
Lauster, Nathanael, and Jens von Bergmann. 2025. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981–2021.”</span> <em>The History of the Family</em> 0 (0): 1–30. <a href="https://doi.org/10.1080/1081602X.2024.2448986">https://doi.org/10.1080/1081602X.2024.2448986</a>.
</div>
<div id="ref-lauster2011no" class="csl-entry">
Lauster, Nathanael, and Adam Easterbrook. 2011. <span>“No Room for New Families? A Field Experiment Measuring Rental Discrimination Against Same-Sex Couples and Single Parents.”</span> <em>Social Problems</em> 58 (3): 389–409.
</div>
<div id="ref-housing_shortages_doubled_up_households.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“Housing Shortages and Doubled up Households.”</span> <em>Plan Canada</em> 64 (4): 16–21. <a href="https://mountainmath.github.io/housing_shortages_and_doubled_up_households/">https://mountainmath.github.io/housing_shortages_and_doubled_up_households/</a>.
</div>
<div id="ref-miron.1988" class="csl-entry">
Miron, J. 1988. <em>Housing in Postwar <span>Canada</span> : Demographic Change Household Formation and Housing Demand</em>. McGill-Queen’s University Press. <a href="https://coilink.org/20.500.12592/pcx21p">https://coilink.org/20.500.12592/pcx21p</a>.
</div>
<div id="ref-miron1989" class="csl-entry">
Miron, J. R. 1989. <span>“Household Formation, Affordability, and Housing Policy.”</span> <em>Population Research and Policy Review</em> 8 (1): 55–77. <a href="https://doi.org/10.1007/bf00124280">https://doi.org/10.1007/bf00124280</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023a. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
<div id="ref-housing-targets.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023b. <em>Housing Targets</em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/">https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/</a>.
</div>
<div id="ref-distributional-effects-of-adding-housing.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024a. <em>Distributional Effects of Adding Housing</em>. <a href="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/">https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</a>.
</div>
<div id="ref-doubling-up-distinguishing-families-from-households.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024b. <em>Doubling <span>Up</span> - <span>Distinguishing</span> <span>Families</span> from <span>Households</span></em>. <a href="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/">https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/</a>.
</div>
<div id="ref-homelessness-and-rents-in-canada.2025" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2025. <em>Homelessness and <span>Rents</span> in <span>Canada</span></em>. <a href="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/">https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/</a>.
</div>
<div id="ref-wade1986" class="csl-entry">
Wade, Jill. 1986. <span>“Wartime Housing Limited, 1941 - 1947: Canadian Housing Policy at the Crossroads.”</span> <em>Urban History Review</em> 15 (1): 40–59. <a href="https://doi.org/10.7202/1018892ar">https://doi.org/10.7202/1018892ar</a>.
</div>
<div id="ref-wargon.1979" class="csl-entry">
Wargon, S. T. 1979. <em>Canadian Households and Families: Recent Demographic Trends</em>. Census Analytical Study, Catalogue 99-753. Statistics Canada. <a href="https://publications.gc.ca/collections/collection_2017/statcan/CS99-753-1979-eng.pdf">https://publications.gc.ca/collections/collection_2017/statcan/CS99-753-1979-eng.pdf</a>.
</div>
<div id="ref-zavisca2008property" class="csl-entry">
Zavisca, Jane. 2008. <span>“Property Without Markets: Housing Policy and Politics in Post-Soviet Russia, 1992<span></span>2007.”</span> <em>Comparative European Politics</em> 6 (3): 365–86. <a href="https://doi.org/10.1057/cep.2008.16">https://doi.org/10.1057/cep.2008.16</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>The family unit estimate suffers from under-counts, and it counts all adult children living with parents as part of the parent’s family unit irrespective of age.↩︎</p></li>
<li id="fn2"><p>These cross-sectional estimates can be interpreted as long-run elasticities of rents to the mismatch of minimal household units and the housing supply. This holds under the assumption that metro areas are near equilibrium, measuring the same relationship across several censuses supports this assumption.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{housing-is-a-housing-problem.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Housing Is a Housing Problem},
  date = {2025-07-06},
  url = {https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Housing Is a
Housing Problem.”</span> <em>MountainDoodles</em>, accepted, July 6. <a href="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/">https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <category>canpumf</category>
  <category>cansim</category>
  <category>cancensus</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/</guid>
  <pubDate>Sun, 06 Jul 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-07-06-housing-is-a-housing-problem/index_files/figure-html/fig-canada-cma-age-expected-households-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Metrics, Mechanisms, and Mismatch: Immigration and other Components of Housing Demand in Canada</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/06/08/metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canpumf)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cancensus)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tinytable)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cmhc)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/mhr_pumf.R"</span>))</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/mhu.R"</span>))</span>
<span id="cb1-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/census_import.R"</span>))</span></code></pre></div></div>
</details>
</div>
<p>Last week StatCan published a report on <strong>Housing use of immigrants and non-permanent residents in ownership and rental markets</strong> <span class="citation" data-cites="statisticscanada_housing_use.2025">(Zhang and Hou 2025)</span>. The report aims to understand the housing consumption of populations in different categories, namely non-permanent residents, immigrants (new and overall), and Canadian-born residents. The data are based on the 2021 Census and used to produce a novel metric in the form of housing occupancy rates for these groups. The goal of the study is to aid “developing effective housing policies and urban planning strategies”.</p>
<p>We like adding and thinking through novel housing metrics, so this kind of study is potentially useful. But there are some issues below the surface with how the metric has been thought through in this report that we want to latch on and nit-pick. Partially because we have thought quite a bit about related issues, and partially because the particular problems in the report mirror problems in how we have historically planned for housing, leading right up to our current housing shortages. We want to highlight some of these issues. But we also take this as an opportunity to broaden the scope and look more generally at why it is important to go beyond incorporating population growth when developing housing policies and urban planning strategies, and put some numbers onto different components of latent housing demand and demand growth.</p>
<p>More abstractly, our nit-pick of the study is on two points, one substantive and one petty.</p>
<p>The substantive nit-pick relates to a fairly common approach in descriptive stats where people try to avoid making assumptions. This may be especially relevant when the report is by a national statistical agency that wants to avoid any suspicion of bias. The approach to descriptive analysis we have taken on these pages can be described as a “concept first” approach, where we start by working to define what we’re talking about and try to make our assumptions clear, drawing upon causal pathways relevant to the questions we are interested in, and then describing data embedded in that context.<sup>1</sup> Reasonable people might disagree which is the better way to go about things, but we are <a href="https://bsky.app/profile/dingdingpeng.the100.ci/post/3lqi563mrus23">not alone in thinking that “science before statistics” is the more useful approach.</a> Whatever your thinking, this post will highlight some differences that arise from choosing between these approaches.</p>
<p>The petty nit-pick is of the “your aren’t talking about something else that I think you should be talking about” type, taking the report as an excuse to talk about those other things too. What makes it a criticism is that some of the phenomena described in the StatCan report are not causally tied to immigration per se, and are better explained by other mechanisms that impact housing consumption. So thinking through broader processes is helpful even when only interested in a narrow part of housing consumption.</p>
<section id="the-statcan-report-findings" class="level1">
<h1>The StatCan report findings</h1>
<p>The report abstract outlines the main findings:</p>
<blockquote class="blockquote">
<p>The analysis of the 2021 Census data shows that immigrants typically exhibit higher housing occupancy in the ownership and rental markets compared with Canadian-born individuals.</p>
</blockquote>
<p>While there is a specific technical context in which this statement can be viewed as true, in the context of the aims of the study it is not. As we will explain, this statement is an artifact of not thinking through the underlying mechanisms.</p>
<p>The report continues</p>
<blockquote class="blockquote">
<p>In their initial years after admission, immigrants have lower housing occupancy rates than Canadian-born individuals. Over time, however, their housing occupancy rises significantly, driven by a substantial growth in homeownership—underscoring the lasting impact of immigration on the ownership market.</p>
</blockquote>
<p>The first sentence is true, the second one correctly describes an increase in occupancy rates when following immigrants over time, or rather when observing successive immigrant cohorts, but it gets the causal mechanisms wrong in the subsequent explanation. This is a stronger version of what can go wrong when doing “stats without science”.</p>
<p>For the rest of the post we will look at these issues in detail.</p>
</section>
<section id="measuring-housing-consumption" class="level1">
<h1>Measuring housing consumption</h1>
<p>In order to measure the “housing use of immigrants and non-permanent residents” the study aims to estimate “housing unit occupancy rates” which it defines as “the number of dwellings per 1,000 people” for immigrants and NPRs, contrasting these to the occupancy rates for Canadian-born residents.</p>
<p>As the StatCan report points out, this is a question under discussion, and we have done quite similar work in the past to understand how changes in immigration and non-permanent resident intake policies impact housing demand. Only we used PUMF data instead of the full census sample that was used in the StatCan study.</p>
<p>The immediate difficulty with the approach taken by StatCan is that households are complex, and there are many situations where a household mixes members of the three categories; non-permanent residents, immigrants, and non-immigrant Canadians. The study sidesteps this issue by classifying housing consumption at the household level via the immigration status of the “primary household maintainer”. The statistics will likely be impacted somewhat by this choice vs other ways to select a representative household person. It would be interesting to look at mixed couples, for instance, to see how (largely arbitrary) reporting of the primary maintainer ends up placing them as immigrants or non-immigrants, but these effects might cancel each other out and could likely be managed <span class="citation" data-cites="statisticscanada_maintainers.2024">(Gorski et al. 2024)</span>. To arrive at a <em>housing occupancy rate</em> the number of primary household maintainers is then divided by the total number of people (in private households) in each group. This choice of denominator is a potentially bigger problem, as we’ll discuss ahead.</p>
<p>To understand how this plays out we reproduce the results of the report using PUMF data in Figure&nbsp;1. For good measure we also add in 2016 data, recognizing that 2021 was a COVID-directed year that experienced significant shocks in the housing market as well as to immigration, and in particular the non-permanent resident and recent immigrant populations.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">young_children <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;">"0 to 4 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 to 6 years"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"7 to 9 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 to 11 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12 to 14 years"</span>)</span>
<span id="cb2-2">old_children <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;">"15 to 17 years"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>)</span>
<span id="cb2-3"></span>
<span id="cb2-4">years <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;">"2016"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>)</span>
<span id="cb2-5">pumf_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(year)</span>
<span id="cb2-7">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-8">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-9">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_rbind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(SUBSIDY,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No, not a subsidized dwelling"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not subsidized"</span>,</span>
<span id="cb2-12">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes, a subsidized dwelling"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHTYPE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(HHTYPE,</span>
<span id="cb2-14">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Lone parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb2-15">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: one-parent family"</span>,</span>
<span id="cb2-16">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: Lone parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb2-17">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: one-parent family"</span>,</span>
<span id="cb2-18">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: one-person household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb2-19">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family households One person household"</span>,</span>
<span id="cb2-20">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: two-or-more-person non-census-family household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb2-21">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: Two or more person non-census-family household"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">living_with_parents =</span> CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,</span>
<span id="cb2-23">                                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a lone parent"</span>,</span>
<span id="cb2-24">                                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>,</span>
<span id="cb2-25">                                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person not in a census family but living with other relatives"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependen_child =</span> (AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> young_children) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb2-27">           ((AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> old_children) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> living_with_parents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> PRIHM<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;">"Person is primary maintainer"</span>))</span>
<span id="cb2-28"></span>
<span id="cb2-29">year_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c114,years)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb3-2">  pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMSTAT <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;">"Not available"</span>),</span>
<span id="cb3-4">  pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMSTAT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2012"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2013"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015 to 2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Year<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;">"2016"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb3-7">             YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2017"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020 to 2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">IMMSTAT=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Recent immigrants"</span>))</span>
<span id="cb3-9">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),</span>
<span id="cb3-11">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT,PRIHM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb3-13">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb3-14">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)<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;">1000</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>IMMSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,</span>
<span id="cb3-19">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb3-21">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb3-22">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb3-23">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb3-24">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb3-25">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb3-26">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT)),</span>
<span id="cb3-27">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x),</span>
<span id="cb3-29">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb3-30">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb3-31">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing occupancy by immigration status"</span>,</span>
<span id="cb3-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of housing units occupied per 1,000 people"</span>,</span>
<span id="cb3-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immigration-status-housing-consumption" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immigration-status-housing-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immigration-status-housing-consumption-1.png" id="fig-immigration-status-housing-consumption" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immigration-status-housing-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>These numbers are in line with the StatCan report derived from the full sample, and we added error bars to reflect uncertainty from drawing from the PUMF subsample (assuming no other measurement problems). Of note, patterns for 2021 are relatively similar to 2016, except for recent immigrants, where we might be seeing a Covid effect worth returning to.</p>
<p>In the meantime, let’s talk about the metric. The denominator here causes a number of issues that are likely to impact the results. The report mentions a particular issue arising from the non-uniformity of households, where household members span several immigration categories. In particular the report draws attention to the prevalence of Canadian-born children in immigrant households. These children, like all children under the age of 15 (and most children under the age of 20), don’t show up as household maintainers, so they don’t count into numerators of these ratios. However these children do show up in the denominator – but for the Canadian born population. In effect, the measure inherently strips away the Canadian born status of children of immigrants in the numerator, identifying their status with the primary householder. But the status is reapplied to these children in the denominator. This treatment of children inherently biases the housing occupancy measure upward for immigrants and downward for the Canadian born.</p>
<p>The StatCan study argues that using Canadian-born children of immigrants as part of the denominator for Canadian-born population makes sense because it “<em>aligns with the study’s objective of estimating the housing units needed to ‘absorb’ a specific number of immigrants</em>”. But this logic is flawed on three accounts. For one it implicitly claims that children of immigrants aren’t causally tied to immigrants. Elementary school biology tells us this is wrong, and we should put “science before statistics” and use that knowledge.<sup>2</sup></p>
<p>The second issue is that <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=households-menage008">children under 15 by definition cannot be “household maintainers” in Canadian data</a>, so the ratio constructed in the StatCan report compares statistics taken from two different populations. If children under 15 are mechanically excluded from the numerator, why include them in the denominator? The report does not address this question, and this again is a question that can only be resolved by properly conceptualizing the underling mechanisms when constructing metrics.</p>
<p>The third issue is related and comes with the failure to think more broadly about the metric in the context of the report’s aims and guiding questions. To understand how to construct a useful metric we need to think about how people consume housing. Children might reasonably be considered housing consumers within their homes, but they’re not independent consumers of homes. In other words, children take up space and are often given their own room. So thinking about children’s housing consumption as distinct from adults makes sense if we’re thinking about housing in terms of rooms, or floor space. But if we’re just thinking about housing consumption in terms of who consumes an independent dwelling as a unit of housing, as adopted in the metric at hand, then children just shouldn’t count. Children’s consumption of independent dwellings is effectively zero in Canada. Dependent children are broadly seen as not taking up additional housing units but being part of the housing unit the parents occupy. This is what motivates the StatCan definition of Household Maintainer to be restricted to the population aged 15 years or older as a hard cutoff, but in practice the issue goes beyond that.</p>
<p>Nobody would expect a 15 or 16 year old to be a household maintainer. At age 17 (in early May) we might run into edge cases, especially with children attending post-secondary programs and living alone or in other living arrangements away from their family home. But even here they often won’t be recorded as such by the Census. Realistically speaking we only expect to see measurable impacts of independent housing consumption around age 18, especially picking up children at the end of their first year in university or other training. For the purpose of the report a useful compromise might be to set the cutoff at the age of 20, but still include the few cases of people below that age who aren’t identified as living with their parents (or grandparents).<sup>3</sup></p>
<p>Thinking through how household formation, and the consumption of housing functions in Canada (as measured in number of housing units) leads us to exclude dependent children below some age from the metric as they are generally not seen as being part of the demand for dwelling units. Figure&nbsp;2 shows the impact when removing dependent children under the age of 20 from the metric.<sup>4</sup></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">housing_demand_no_children <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;">bind_rows</span>(</span>
<span id="cb4-2">  pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMSTAT <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;">"Not available"</span>),</span>
<span id="cb4-4">  pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMSTAT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2012"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2013"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015 to 2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Year<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;">"2016"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb4-7">             YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2017"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020 to 2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">IMMSTAT=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Recent immigrants"</span>))</span>
<span id="cb4-9">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>dependen_child) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),</span>
<span id="cb4-13">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT,PRIHM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb4-15">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb4-16">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)<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;">1000</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>)</span>
<span id="cb4-19"></span>
<span id="cb4-20">housing_demand_no_children <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>IMMSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,</span>
<span id="cb4-23">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb4-25">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb4-26">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb4-27">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb4-28">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb4-29">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb4-30">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMSTAT)),</span>
<span id="cb4-31">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x),</span>
<span id="cb4-33">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb4-34">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb4-35">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing occupancy by immigration status"</span>,</span>
<span id="cb4-39">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of housing units occupied per 1,000 population</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(excluding dependent children under 20 years old)"</span>,</span>
<span id="cb4-40">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immigration-status-housing-consumption-no-children" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immigration-status-housing-consumption-no-children-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immigration-status-housing-consumption-no-children-1.png" id="fig-immigration-status-housing-consumption-no-children" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immigration-status-housing-consumption-no-children-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>This simple adjustment pushes the housing consumption of Canadian born residents above that of immigrants, falling back in line with general expectations. In effect, we can see that the seeming immigrant overconsumption of housing is a simple artifact of choices about measurement. This is acknowledged in the report, but not fully carried through in terms of its implications, especially regarding later comparisons.</p>
<p>The adjustment also widens the gap between non-permanent residents and immigrants as well as Canadian-born residents, again in line with expectations. To return to the difference between results for recent immigrants in 2016 relative to 2021, its worth keeping in mind that Canada experienced a dramatic drop in immigration in 2020. This means the category of Recent Immigrants (arriving within the last five years) was more heavily weighted by those who had been in Canada longer in 2021. Recent immigrants coming in at essentially the same (for 2021) or slightly lower consumption rate than non-permanent residents (for 2016) is curious. This may speak to aspects of both selection and transitions between groups, but also to choice of household reference person. Let’s look at this a bit more in-depth.</p>
<p>We can provide a first-hand example of transitions between groups. One of us arrived as a solo NPR with an individual housing occupancy rate of 1. Then we applied for permanent residence as an immigrant and partnered up with another NPR turned immigrant to reach a housing occupancy rate of 0.5. This offers a clear illustration of how immigrants might end up with lower housing occupancy than NPRs. Carrying the example forward, we then had two children. It would make sense if this dropped our housing occupancy rate to 0.25 (four people living in a single dwelling). But since we were immigrants and the children were born in Canada, they don’t count toward our housing occupancy. Instead they somehow count toward lowering the housing occupancy of Canadian born primary household maintainers writ large. In addition to providing a potential explanation for the drop in consumption between NPR and recent immigrants rooted in transitions, the anecdote here demonstrates how the metric at hand ultimately fails to scale to the individual level - illustrating how and why the StatCan version doesn’t make sense. But can we do more with the Census data at hand?</p>
<p>The finer breakdowns below and the following analysis sheds some light onto further potential explanations for differences and we will see that to a large extent they are also a product of immigrant selection mechanisms. In this context it’s good to remember that the census <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/98-303/index-eng.cfm">has difficulty capturing non-permanent residents</a>, generally picking up only around 50% of the non-permanent resident population. NPR’s ties to Canada can be quite fluid, and they may not recognize that they have to fill out the census. There is reason to suspect that under-coverage for international students and temporary foreign workers is especially high, and that their housing consumption is especially low. Additionally, temporary foreign workers in collective housing, as is often the case for farm workers, are not covered in either the StatCan study nor in the PUMF data we used. In summary, there is good reason to suspect that housing occupancy rates of the non-permanent residents captured in the census significantly over-estimate the occupancy rates of the overall non-permanent resident population in Canada.</p>
<p>We can expand on the immigrant categories slightly by using the full range provided in the PUMF data in Figure&nbsp;3. Of note, admission categories are only collected for immigrants who landed after 1980, providing us the extra general purpose category of immigrants landing prior to this time.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMCAT5 <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>dependen_child) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),</span>
<span id="cb5-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5,PRIHM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb5-8">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb5-9">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)<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;">1000</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>IMMCAT5,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,</span>
<span id="cb5-14">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb5-16">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb5-17">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb5-18">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb5-19">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb5-20">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb5-21">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5)),</span>
<span id="cb5-22">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x),</span>
<span id="cb5-24">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb5-25">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb5-26">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing occupancy by immigration status"</span>,</span>
<span id="cb5-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of housing units occupied per 1,000 population</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(excluding dependent children under 20 years old)"</span>,</span>
<span id="cb5-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immcat5-consumption" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immcat5-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immcat5-consumption-1.png" id="fig-immcat5-consumption" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immcat5-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>Here we can see curiously high housing consumption for immigrants that landed before 1980, as well as interesting consumption patterns across the other immigrant categories. In particular refugees appear to consume more housing than economic immigrants, and almost as much housing as non-immigrants. To understand what’s going on here again leads us to go beyond just looking at frequencies but also to pay attention to the data generation process. Refugees interact with housing in different ways from other groups, and that’s important to understand.</p>
</section>
<section id="policy-relevant-analysis" class="level1">
<h1>Policy-relevant analysis</h1>
<p>This gets us to the main part of our post; how can we make data analysis policy relevant? Descriptive analysis that looks at frequencies, how people currently use housing, is a useful starting point, but it falls short of being useful for guiding policy.</p>
<p>For descriptive analysis the first question is how the metrics used align with the question one is interested in. In this case the question of interest is housing consumption, in terms of number of housing units, by various groups. The metric is occupancy rates, as defined by number of household maintainers in a given group divided by total population in that group. And the goal of the exercise is to guide policy intervention, which means we can’t avoid thinking about things causally. It’s not enough to just report frequencies observed in the data, we need to pay attention to the causal structure guiding how population interacts with housing. Failing to do so will likely lead to misguided policy.</p>
<p>So what does paying attention to the causal structure mean? Several things.</p>
<p>As already discussed above, we should remove dependent children from this denominator since they aren’t viewed as requiring independent housing in the Canadian context. Moreover in the data source at hand children under 15 aren’t even eligible to be part of the numerator population, calling into question the meaning and usefulness of the ratio. Our choice to drop dependent children under 20 from the denominator is just one of many that could be used to build a better metric here.</p>
<p>More broadly, analysis all too often simply draws upon present frequencies and projects them into the future. In the context of housing this plays a large part in our accumulated housing shortage, where policy makers have interpreted observed housing consumption rates as revealed preference instead of as constrained choices reflecting limitations on available housing stock. Very little attention has been paid to the drivers of household formation and housing consumption. This includes demographic factors, but also income and wealth. Ignoring these drivers of demand helps explain the past 50 years of failure to increase housing supply to match increased demand. <span class="citation" data-cites="planning-for-scarcity.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022b)</span> The report acknowledges that, noting that the housing occupancy rates “reflect housing use constrained by factors such as financial resources, living preferences and housing supply availability”, but the report fails to incorporate that knowledge into the analysis.</p>
<p>The curious differences in housing consumption across various groups in Figure&nbsp;3 are entirely driven by features of the data generation process that we have thus far ignored. It’s useful to go back to first principles and understand what drives household formation. As we have explained in the past, this is mostly driven by age, income and wealth, as well as couple status of the individual, set against the cost of housing at the regional level. <span class="citation" data-cites="housing_shortages_doubled_up_households.2024 mhu.2025">(<span class="nocase">Lauster and von Bergmann</span> 2024; Lauster and Bergmann 2025)</span> Immigrants who landed before 1980 distinguish themselves from the other groups most obviously by age, and the high housing consumption is a reflection of that, as opposed to a particular feature of their immigrant status. Similarly, the StatCan report breaks out statistics for recent immigrants, which tend to be younger. Their registering with a lower housing occupancy rate is again at least partially driven by age - as opposed to their immigration status - although income plays another role and it’s an unfortunate reality that labour force integration of recent immigrants is slow in Canada, leading to lower incomes, even for economic immigrants selected for by their skill level.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">subsidized_breakdown <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMCAT5 <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>dependen_child) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),</span>
<span id="cb6-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cases=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb6-7">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5,PRIHM,SUBSIDY)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb6-9">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb6-10">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)<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;">1000</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5,Weight,SUBSIDY)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(SUBSIDY <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s_share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Weight,IMMCAT5,Year))</span>
<span id="cb6-15"></span>
<span id="cb6-16">subsidized_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> subsidized_breakdown <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Weight<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;">"WEIGHT"</span>,SUBSIDY <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;">"Subsidized"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>IMMCAT5,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>s_share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>()</span>
<span id="cb6-20"></span>
<span id="cb6-21">refugee_vs_economic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> subsidized_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>Refugees<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Economic immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(ratio)</span>
<span id="cb6-25">refugee_vs_canadian <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> subsidized_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>Refugees<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Non-immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(ratio)</span></code></pre></div></div>
</details>
</div>
<p>For refugees the mechanism governing their housing consumption is quite different. Refugees in Canada disproportionately live in subsidized housing, at a rate 4.9 times higher that of economic immigrants and 3 times that of of Canadian-born householders. Subsidized rents, along with rules frequently preventing the sharing of non-market housing, mean refugees don’t double up as often as other people do in the market. Once we consider ratios of those in subsidized and non-subsidized (and ownership) housing separately, the distinct effect observed for refugees basically disappears, as shown in Figure&nbsp;4.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">subsidized_breakdown <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(SUBSIDY,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not subsidized"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Market rental"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized rental"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(cases&gt;500) |&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>IMMCAT5,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,</span>
<span id="cb7-6">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb7-8">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb7-9">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb7-10">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb7-11">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb7-12">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(rate,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb7-13">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,IMMCAT5,SUBSIDY)),</span>
<span id="cb7-14">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x),</span>
<span id="cb7-16">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb7-17">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb7-18">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>SUBSIDY) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing occupancy by immigration status and subsidized housing status"</span>,</span>
<span id="cb7-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of housing units occupied per 1,000 people</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(excluding dependent children under 20 years old)"</span>,</span>
<span id="cb7-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-subsidy-consumption" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-subsidy-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-subsidy-consumption-1.png" id="fig-subsidy-consumption" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-subsidy-consumption-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>That’s not to say that, for the purpose of estimating the housing consumption of future refugees, the crude rates aren’t useful. They can be, and here they’re likely a decent estimate for the expected housing consumption under our current housing system. But peeling back the layers of how and why these occupancy ratios come about helps understand how things fit together, highlighting the role, for instance, of the subsidized housing sector. And that’s especially important for policy considerations of how you might want to change the current housing system.</p>
</section>
<section id="age" class="level1">
<h1>Age</h1>
<p>Age is a major factor in determining household formation. For the purpose of understanding the immediate impact of immigrants and non-permanent residents on housing consumption this is not important, but it is if one wants to understand processes over a longer period of time. The StatCan report examines how different immigrant cohorts (by year of immigration) consume housing by tenure. The report frames this as studying trends of immigrants over time, which requires strong additional assumptions about housing markets and immigrant populations remaining comparable over time. There’s no reason to believe these assumptions are reasonable.<sup>5</sup></p>
<p>The report goes on to explain the increase in occupancy rates they observe for older immigrant cohorts as follows:</p>
<blockquote class="blockquote">
<p>Newcomers tend to have larger households, often living with extended family members such as parents and grandparents, to reduce costs and address economic constraints. As immigrants settle, household sizes typically decrease because of children moving out, increased economic stability and adaptation to Canadian norms of nuclear families.</p>
</blockquote>
<p>The report gives no evidence to the interpretation that newcomer’s “living with extended family members such as parents and grandparents” is responsible for the observed patterns, and the framing suggests a naive understanding on how people in Canada live together in households. A quick check in the data as done in Figure&nbsp;5 shows that while around 10% of recent immigrants live in multi-family households, which includes multi-generational households, this share is fairly low and does not change much across immigrant cohorts until very far back in time when it becomes important to account for aging and mortality.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(IMMSTAT <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;">"Immigrants"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imm_year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(YRIMM,YRIM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(imm_year<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yy=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(imm_year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imm_year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(imm_year,yy)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHTYPE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(imm_year<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(HHTYPE,Year,imm_year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb8-11">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb8-12">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span> Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,imm_year,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHTYPE<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;">"Multiple-census-family household"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>imm_year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb8-18">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb8-19">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb8-20">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb8-21">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb8-22">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb8-23">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,imm_year,HHTYPE)),</span>
<span id="cb8-24">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year,<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;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Immigrants in multi-family households"</span>,</span>
<span id="cb8-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of immigrants by preriod of immigration"</span>,</span>
<span id="cb8-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Period of immigration"</span>,</span>
<span id="cb8-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-multi-family-immigrant" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-multi-family-immigrant-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-multi-family-immigrant-1.png" id="fig-multi-family-immigrant" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-multi-family-immigrant-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<p>In Figure&nbsp;6 we complement this by looking at all household living arrangements of recent immigrants (within the past 5 years) compared to that of immigrants who landed 10 to 15 years ago.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">recent_immigrants <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recent_immigrant =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb9-3">    YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015 to 2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020 to 2021"</span>) <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;">"Recent immigrants"</span>,</span>
<span id="cb9-4">    YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2001"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2002"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2003"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2004"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2005"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2006"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2007"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2008"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2009"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2010"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> </span>
<span id="cb9-5">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Immigrated 10-15 year ago"</span>,</span>
<span id="cb9-6">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#IMMSTAT == "Non-immigrants" ~ "Canadian born",</span></span>
<span id="cb9-7">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Else"</span></span>
<span id="cb9-8">  ))</span>
<span id="cb9-9"></span>
<span id="cb9-10">recent_immigrants <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(recent_immigrant<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;">"Else"</span>,</span>
<span id="cb9-12">         HHTYPE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(HHTYPE,Year,recent_immigrant)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),</span>
<span id="cb9-15">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,</span>
<span id="cb9-16">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span> Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(HHTYPE),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb9-21">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb9-22">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb9-23">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb9-24">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb9-25">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb9-26">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant,HHTYPE)),</span>
<span id="cb9-27">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>recent_immigrant) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living arrangements of select immigrant cohorts"</span>,</span>
<span id="cb9-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share in living arrangement"</span>,</span>
<span id="cb9-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Cenusus 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immigrant-household-type" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immigrant-household-type-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immigrant-household-type-1.png" id="fig-immigrant-household-type" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immigrant-household-type-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
</div>
</div>
<p>This shows that there are many ways that people double up besides in multi-family households. Indeed roommate households, as captured in the last category, exceed multi-family households as a category containing recent immigrants in 2021. The share living in couple and couple with children households without additional persons are both larger for the cohort that immigrated 10-15 years ago compared to the one that immigrated in the year and a bit before the census, demonstrating the further moves toward partnering and childbearing that we expect to see with all populations as they age and settle into their lives, including their careers.</p>
<p>With some understanding of these processes we can now broaden our view on housing demand from other factors, beyond the addition of immigrants and net NPRs. This brings us to the second stage of this post, after which we will return to the question of changes in housing occupancy rates of subsequent immigrant cohorts and will be able to properly interpret these changes.</p>
</section>
<section id="existing-housing-shortfall-demographic-effects-income-growth-and-population-growth" class="level1">
<h1>Existing housing shortfall, demographic effects, income growth, and population growth</h1>
<p>For housing policy and planning purposes we need to understand all processes that impact our housing market. In media and public discussions there has been a lot of emphasis on the housing consumption of immigrants and non-permanent residents, but comparatively little on other factors contributing to our housing pressures.</p>
<p>Taking a more comprehensive view on this is a difficult task, and in the following we will heavily rely on previous work we have done. We also want to point out that the estimates come with varying degrees of uncertainty, in particular when it comes to estimating the existing housing shortfall. The goal of this section is less to provide an exact number for housing demand but to provide a broad overview of the factors that make up that demand, and ballpark estimates of the constituent components that are suitable for judging their relative size.</p>
<section id="existing-housing-shortfall" class="level2">
<h2 class="anchored" data-anchor-id="existing-housing-shortfall">Existing housing shortfall</h2>
<p>We start with the existing housing shortfall because it’s a key ingredient in understanding the housing need for all other factors. The existing housing shortfall impacts how people distribute over housing. In particular, the housing occupancy rates we observed in the StatCan report and in the analysis above are impacted by existing housing shortages. The StatCan report acknowledges this in the first paragraph of their abstract: “<em>These rates reflect housing use constrained by factors such as financial resources, living preferences and housing supply availability.</em>” Taking these rates observed under housing scarcity to plan for future housing need implicitly encodes the value statement that our current housing shortfall is good and we should plan for continued housing scarcity. By contrast, only after understanding and taking account of our current housing shortfall can we plan adequately for future growth.</p>
<p>Making sense of the concept of “housing shortfall” requires a clear counterfactual scenario. In their Supply Gap work CMHC asks how much more housing is needed to restore affordability to 2004 levels. <span class="citation" data-cites="cmhc_supply_2022 cmhc_supply_2023">(CMHC 2022, 2023)</span> Mike Moffatt asks how much housing is needed to bring household formation to the level seen outside of Ontario and British Columbia (The Rest of Canada, ROC metric). <span class="citation" data-cites="moffatt_2022">(Moffatt et al. 2022)</span> We have looked at differences in household composition across metro areas <span class="citation" data-cites="what-s-a-household.2017">(<span class="nocase">von Bergmann</span> 2017)</span>, using household formation rates in metro Montréal and Québec City as counterfactuals, and also considering historic changes in household formation rates and counterfactual scenarios to restore household formation to that seen in earlier years <span class="citation" data-cites="estimating-suppressed-household-formation.2022 still-short-suppressed-households-in-2021.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022a, 2022c)</span>. We have also drawn upon and advanced the concept of Minimum Household Units to derive counterfactual scenarios <span class="citation" data-cites="housing-outcomes.2023 housing_shortages_doubled_up_households.2024 mhu.2025">(<span class="nocase">von Bergmann and Lauster</span> 2023a; <span class="nocase">Lauster and von Bergmann</span> 2024; Lauster and Bergmann 2025)</span> as well as considering family units. <span class="citation" data-cites="doubling-up-distinguishing-families-from-households.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024b)</span> In a further scenario we estimate how much housing the market could profitably build as the counter-factual housing shortfall. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span></p>
<p>All these methods have advantages and disadvantages, and the size of the estimated shortfall critically depends on the choice of counterfactual scenario and its underlying assumptions. Additionally there are questions at what geographic levels these estimates should be estimated. Some regions, for example the Québec City metro area, have seen increased household formation over time driven by rising incomes and a housing supply that kept pace with demand. In this case, applying historic rates of doubling up would worsen housing outcomes. The geographically heterogeneous nature of housing outcomes, and how they evolve over time, requires delicate considerations for how to aggregate shortfall estimates up to the national level. Local differences in housing shortage also haunt the analysis of differences in the housing occupancy of immigrants, as we will see ahead.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">shortfall_low <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1100000</span></span>
<span id="cb10-2">shortfall_high <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500000</span></span></code></pre></div></div>
</details>
</div>
<p>We are separating out the work to give an overview of how these different methods to estimate housing shortfall fit together into a separate post. Suffice to say, depending on the choice of method, the existing housing shortfall estimate for 2021 can range from around 1,100k to over 2.5M housing units. These correspond to roughly setting national household formation rates equal to those observed in Montréal and Québec in 2021, respectively. An upper limit would be to provide enough housing to eliminate all doubling up, which would yield an additional 4.4M households.</p>
<p>These are estimates for the housing shortfall in 2021, it’s 4 years later now and the shortfall may well have changed. Given the large range of shortfall estimates based on different methods, the 4 year gap in estimates is probably not the biggest problem and we are just going to keep these fixed for now. Doing further work on shortfall estimates, like CMHC is already doing when they are updating their supply gap model, but also complementing this with alternative counterfactual scenarios and methods to derive more up-to-date estimates, would be very useful and worthwhile to invest time in.</p>
</section>
<section id="demographic-effects" class="level2">
<h2 class="anchored" data-anchor-id="demographic-effects">Demographic effects</h2>
<p>Canada’s population is ageing, and older people tend to consume more housing in terms of number of housing units. This leads to an increase of housing demand from demographic drivers alone. We have looked into the underlying processes in detail in the past. <span class="citation" data-cites="estimating-suppressed-household-formation.2022 housing-outcomes.2023 still-short-suppressed-households-in-2021.2022 tenure-and-household-independence-across-the-life-course-1981-2021.2024 housing_shortages_doubled_up_households.2024 mhu.2025">(<span class="nocase">von Bergmann and Lauster</span> 2022a, 2023a, 2022c, 2024c; <span class="nocase">Lauster and von Bergmann</span> 2024; Lauster and Bergmann 2025)</span></p>
<p>We can estimate the demographic effect on housing demand by taking StatCan population projections by age that already include mortality effects, and apply age-specific household maintainer rates from a fixed year. This translates population into age-expected households, and we can split these expected households into changes in household size and changes in population growth. The change in household size is the demographic effect, that we can then express in terms of additional households formed, assuming households form at the same rate as they did in the reference year. Figure&nbsp;7 shows the resulting demographic contribution to housing demand based on a range of reference years used for the underlying age-specific household formation rates.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">hmr_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_phm_timeline</span>(),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hmr_data_all.rds"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path=</span>here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb11-2"></span>
<span id="cb11-3">census_base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2006</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;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(y){</span>
<span id="cb11-6">    provinces <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;">get_census</span>(y,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">C=</span><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;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,GeoUID,Population,Households,Dwellings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Region)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>y) </span>
<span id="cb11-10">    </span>
<span id="cb11-11">    cmas <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;">get_census</span>(y,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</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;">"59933"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35505"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24505"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35535"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24462"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"48825"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"48835"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-12">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,GeoUID,PR_UID,Population,Households,Dwellings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-13">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Region)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-14">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-15">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR_UID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(PR_UID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<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;">2</span>)))</span>
<span id="cb11-16">    </span>
<span id="cb11-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(cmas)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb11-18">    </span>
<span id="cb11-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(provinces,cmas <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb11-20">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GeoUID=</span>PR_UID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-21">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Region) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-22">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(provinces <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Region,GeoUID),<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;">"GeoUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-23">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Population,Households,Dwellings),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~-</span>.x))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(cmas<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PR_UID) <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;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rest of "</span>,Region), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Region)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(cmas) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Population,Households,Dwellings),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Region,Year)) </span>
<span id="cb11-27">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Region,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa - Gatineau"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>))</span>
<span id="cb11-29"></span>
<span id="cb11-30">pop_projections <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;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0057"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,</span>
<span id="cb11-32">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Projection scenario</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Projection scenario M1: medium-growth"</span>,</span>
<span id="cb11-33">         GEO<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;">"Canada"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>()</span>
<span id="cb11-35"></span>
<span id="cb11-36">hmr_canada <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> hmr_all  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years ond over"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>,</span>
<span id="cb11-38">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span>,</span>
<span id="cb11-39">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-40">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,PRIHM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hmr=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>)</span>
<span id="cb11-44"></span>
<span id="cb11-45">pop_projections_match <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pop_projections <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">categories_for_level</span>(.,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age group"</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;">|&gt;</span></span>
<span id="cb11-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb11-48">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100 years and over"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>,</span>
<span id="cb11-49">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 to 89 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>,</span>
<span id="cb11-50">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"90 to 94 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>,</span>
<span id="cb11-51">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"95 to 99 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"85 years and over"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-52">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(val_norm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,Date)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))</span>
<span id="cb11-54"></span>
<span id="cb11-55">hh_sizes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pop_projections_match <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(hmr_canada <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  </span>
<span id="cb11-57">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>AGEGRP,hmr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-58">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">complete</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pop_projections_match<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hmr=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-59">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pop_projections_match<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))),</span>
<span id="cb11-60">            <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;">"Age group"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">relationship =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"many-to-many"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh=</span>hmr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-62">  <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;">hh=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(hh),</span>
<span id="cb11-63">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),</span>
<span id="cb11-64">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Date,Year))</span>
<span id="cb11-65"></span>
<span id="cb11-66"></span>
<span id="cb11-67">hh_contribution <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> hh_sizes <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-07-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2034-07-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hhsize=</span>pop<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>hh,</span>
<span id="cb11-70">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>hh<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-71">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>ratio<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;">lag</span>(ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Date),</span>
<span id="cb11-72">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-73">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2034-07-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hhgap=</span>gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pop)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">demographic_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> hh_contribution<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hhgap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>()</span>
<span id="cb12-2">hh_contribution <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>hhgap)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Demographic effects of housing demand"</span>,</span>
<span id="cb12-7">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of additional households 2024-2034"</span>,</span>
<span id="cb12-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Counterfactual household formation rate reference year"</span>,</span>
<span id="cb12-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1971-2021, StatCan population projections"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-demographic-contribution" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-demographic-contribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-demographic-contribution-1.png" id="fig-demographic-contribution" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-demographic-contribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7
</figcaption>
</figure>
</div>
</div>
</div>
<p>In summary, we should expect around 720,000 households to form over the next 10 years just based on the demographic shifts associated with an aging population. These estimates are taken at the national level, so this likely under-estimates the actual demand by mixing areas where household formation has increased with those where household formation has decreased. And housing consumption is sticky; older population have seen increased housing consumption even when younger populations have seen theirs deteriorate. A more careful analysis would follow cohorts and likely arrive at a higher estimate. <span class="citation" data-cites="housing-outcomes.2023 tenure-and-household-independence-across-the-life-course-1981-2021.2024">(<span class="nocase">von Bergmann and Lauster</span> 2023a, 2024c)</span> But this will suffice as a rough estimate.</p>
</section>
<section id="income-growth" class="level2">
<h2 class="anchored" data-anchor-id="income-growth">Income growth</h2>
<p>Income growth is a key driver of housing consumption. Rich people, counting both income and wealth, consume more housing. This manifests itself in nicer and larger dwellings, but also in consuming more overall housing units. These additional housing units can take the form of vacation homes. But more importantly for our purposes, higher income increases household formation by children moving out of their parent’s place earlier, leaving roommate setups earlier, splitting up multi-generational households into nearby independent dwelling units, and people generally doubling up at lower rates. When rising incomes are not met with increased housing supply this can, perversely, lead to decreased affordability at the lower end of the income spectrum.</p>
<p>Consider the case when a population and its demographic structure stays fixed, and housing supply also remains fixed, but incomes rise. Income effects are heterogeneous, triggering increased household formation for those who see income boosts. Since the housing stock is fixed, by the pigeonhole principle this increased household formation has to be matched by increased doubling up further down the (new) income spectrum. The aggregate change to affordability depends on the relative sizes of the demand elasticity of household formation and the price elasticity to income. These elasticities are difficult to estimate and the relative sizes likely depend on the particularities of housing markets, but some researchers have estimated that in aggregate rising incomes on the backdrop of a fixed housing supply lead to decreased aggregate affordability. <span class="citation" data-cites="meen2008">(Meen and Andrew 2008)</span> The effects of income on demand only further emphasize how freezing housing supply is bad.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">fudge_factor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.75</span></span>
<span id="cb13-2">rent_elasticity <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span></span>
<span id="cb13-3">income_to_rent_elasticity <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span></span>
<span id="cb13-4">income_elasticity<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>income_to_rent_elasticity<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>rent_elasticity</span>
<span id="cb13-5">income_elasticity_f<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>income_elasticity<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>fudge_factor</span>
<span id="cb13-6">income_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb13-7">household_growth_income_f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> income_elasticity_f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>income_growth<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;">100</span></span>
<span id="cb13-8">household_growth_income_f_10 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (household_growth_income_f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb13-9">additional_hh <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> household_growth_income_f_10 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> hh_sizes <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb13-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2034-07-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-11">  <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;">hh_mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(hh),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(hh),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(hh)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(hh_mean) </span></code></pre></div></div>
</details>
</div>
<p>We have done some work to estimate the impact of income growth on housing demand, but have not explicitly solved for this. For key household formation age groups the impact of income on household formation, controlling for couple status and age, and with it age-related increases in income, is about 0.1 times that of rent, with the opposite sign.<sup>6</sup> <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span> This means that in the Vancouver setting a 1% increase in real incomes results to an increase in household demand by about 0.4%. For all of Canada this is likely an over-estimate, and assuming the housing shortfall is reduced in Vancouver, it would also reduce Vancouver’s elasticity. A back of the envelope guesstimation suggests that maybe reducing this by a factor of 1.5 or even 2 might give a reasonable ballpark estimate. For the sake of this post we will use a fudge factor of 1.75 to reduce the elasticity to 0.2%.</p>
<p>Historically real age-adjusted family incomes in Canada have grown by about 1.4% per year, so we can expect, including our fudge factor, a 0.32% increase in household demand per year, or about 3.2% over the next decade. Using this ballpark estimate, that results in demand for roughly an additional 620,000 households from income growth as a ballpark estimate. Overall, the impact of income growth on housing demand remains under-studied and could use further research.</p>
</section>
<section id="population-growth" class="level2">
<h2 class="anchored" data-anchor-id="population-growth">Population growth</h2>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">housing_demand_no_children_rates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> housing_demand_no_children <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Weight<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;">"WEIGHT"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>IMMSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>rate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>() </span>
<span id="cb14-5">pr_demand_census <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Non-permanent residents</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Non-immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb14-6">imm_demand_census <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Immigrants<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Non-immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb14-7">recent_imm_demand_census <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Recent immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Non-immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb14-8"></span>
<span id="cb14-9">recent_immigrants_raw <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> housing_demand_no_children_rates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Recent immigrants</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
</details>
</div>
<p>Lastly, we can try and estimate the impact of population growth on housing demand. Given fixed boundaries, population growth combines information about births, deaths, and net migration. Births and deaths largely filter through slow-moving age structures in generating population-level housing demand (see effects of age above). Deaths of single person householders reduce housing consumption, but do not offer justifiable policy levers. Outside of these forces and at the national level, short-term variation in our population growth mostly comes from external migration, and resulting housing demand again depends on assumptions about housing consumption of immigrants and non-permanent residents. Setting aside the justifiability of policy levers here, which <a href="https://www.liberalcurrents.com/closed-borders-are-the-line-in-the-sand/">should not be assumed</a>, we have seen that the housing demand of non-permanent resident adults is very similar to that of recent immigrants, both sitting at about 75% that of Canadian-born adults. As discussed above, the estimate for non-permanent residents is likely a significant over-estimate. At the same time, recent changes to Canada’s immigration and NPR intake regime means that the total non-resident population will likely decline over the next 10 years as permit holders finish school or see their work permits expire. Some of the NPRs will physically depart Canada. Others will simply change their status, transitioning into permanent residents and showing up in our immigrant population instead.</p>
<p>The StatCan population projection scenarios have this transition happen rather fast, wrapping up by mid-2027. This seems overly optimistic to us, we suspect that this transition will likely take a couple of years longer.<sup>7</sup> But either way, it is good to remember that net NPR is a stationary process and will revert to near zero over longer time periods.<sup>8</sup></p>
<p>Given the comparatively small effect of changes to net NPR over a 10 year timeframe, as well as the high uncertainty of NPR housing consumption because of high under-coverage of exactly the categories that are likely to see the highest reductions, we won’t distinguish changes in net NPR and immigration and just look at the combined effects. Moreover, changes in natural growth are quite small, so we will just take the projected change in overall population as roughly proxying for immigration and apply housing consumption rates of recent immigrants.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">naive_housing_demand_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> hh_sizes <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-07-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2034-07-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-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;">hh=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(hh),</span>
<span id="cb15-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hh"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2034-07-01</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2024-07-01</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(diff) </span>
<span id="cb15-8"></span>
<span id="cb15-9">net_pop_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pop_projections <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-07-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2034-07-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2034-07-01</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2024-07-01</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(diff)</span>
<span id="cb15-16"></span>
<span id="cb15-17">imm_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> recent_imm_demand_census <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (naive_housing_demand_growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>demographic_growth) </span>
<span id="cb15-18">imm_growth2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> recent_immigrants_raw <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> net_pop_growth</span>
<span id="cb15-19">hh_contribution2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> naive_housing_demand_growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>imm_growth2</span></code></pre></div></div>
</details>
</div>
<p>Using the M1 population projections and subtracting out our estimates of housing demand growth due to demographic shifts gives roughly 790,000 from population growth due to immigration. We note that the assumed housing occupancy rate differential between recent immigrants and the Canadian-born population is the product of recent immigrants having lower incomes, as well as the cost of housing being high, making it harder to secure independent living on these lower incomes.<sup>9</sup> If the housing shortfall is reduced, and rents accordingly fall, the gap between the household formation rates of recent immigrants and the Canadian-born population will likely shrink.</p>
</section>
<section id="translating-households-into-housing" class="level2">
<h2 class="anchored" data-anchor-id="translating-households-into-housing">Translating households into housing</h2>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">moving_vacancies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span></span></code></pre></div></div>
</details>
</div>
<p>These previous sections provided various estimates on household growth or demand. To fully translate this into housing growth we need to add in moving vacancies. Generally a 5% bump to all estimates is a good ballpark to ensure people can move freely and housing is available. In the past planning has often skipped this step, effectively resulting in net attrition. This is not the largest problem with past past planning practices when it comes to projections for housing demand, but it’s a simple one to fix.<sup>10</sup></p>
<p>Additionally we want to point out that these estimates are about net additions, so actual new housing production needs to be significantly higher to make up for demolitions and deconversions.</p>
</section>
<section id="putting-everything-together" class="level2">
<h2 class="anchored" data-anchor-id="putting-everything-together">Putting everything together</h2>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">teardown_rate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.07</span></span>
<span id="cb17-2">total_growth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> additional_hh <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> imm_growth <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> demographic_growth</span>
<span id="cb17-3">total_with_shortfall <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>(total_growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>shortfall_low,total_growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>shortfall_high)</span>
<span id="cb17-4">total_with_shortfall_and_vacancy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> total_with_shortfall <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> moving_vacancies)</span>
<span id="cb17-5">total_with_shortfall_vacancy_teardown <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> total_with_shortfall_and_vacancy <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> teardown_rate) </span>
<span id="cb17-6"></span>
<span id="cb17-7">demand_components <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Component=</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;">"Existing shortfall"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ageing"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Income growth"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External migration"</span>),</span>
<span id="cb17-8">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">low=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(shortfall_low,demographic_growth,additional_hh,imm_growth),</span>
<span id="cb17-9">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">high=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(shortfall_high,demographic_growth,additional_hh,imm_growth)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(low,high),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> moving_vacancies)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> teardown_rate))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Component=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Component,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Existing shortfall"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ageing"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Income growth"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External migration"</span>))) </span></code></pre></div></div>
</details>
</div>
<p>Putting all the estimates above together we get demand of about 2,100,000 additional households from demographic shifts, immigration, and income growth over the next decade. Adding this to the existing housing shortage gets us to 3,200,000 to 4,600,000 additional households. Factoring in moving vacancies to translate this into housing units bumps that up to 3,400,000 to 4,900,000 additional net new housing units needed. Accounting for teardowns and deconversions, roughly estimated at 7% of new construction, we arrive at a need between 3,600,000 and 5,200,000 housing completions over the next decade.</p>
<p>We summarize these in Figure&nbsp;8. These estimates come with various degrees of uncertainty, and here we use a gradient fade to indicate the particularly large area of uncertainty in the estimate of the existing housing shortfall.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">demand_components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>high<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>low) <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;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Component)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_tile</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width=</span>low,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>low<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-5">  ggpattern<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_tile_pattern</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>low<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>,</span>
<span id="cb18-6">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gradient"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern_orientation=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horizontal"</span>,</span>
<span id="cb18-7">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern_fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern_fill2=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F8F4F0"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern_density=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>scales<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;">comma</span>(.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Comparison of components of housing demand over next 10 years"</span>,</span>
<span id="cb18-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of dwelling units"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-housing-demand-components" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-housing-demand-components-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-housing-demand-components-1.png" id="fig-housing-demand-components" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-housing-demand-components-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can compare these estimates of housing demand to historical rates of housing completions across Canadian population centres<sup>11</sup> as shown in Figure&nbsp;9.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># completions &lt;- get_cmhc(survey = "Scss", series = "Completions", dimension = "Dwelling Type", </span></span>
<span id="cb19-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                         breakdown = "Historical Time Periods", geoFilter = "All", geo_uid = "01") </span></span>
<span id="cb19-3">completions2 <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;">get_cmhc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">survey =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scss"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimension =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dwelling Type"</span>, </span>
<span id="cb19-4">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breakdown =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Historical Time Periods"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_uid =</span> <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;">frequency=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual"</span>) </span>
<span id="cb19-5">completions2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dwelling Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Completions in Canadian population centres"</span>,</span>
<span id="cb19-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual number of housing units"</span>,</span>
<span id="cb19-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb19-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMHC Scss"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cananda-centres-completions" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cananda-centres-completions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-cananda-centres-completions-1.png" id="fig-cananda-centres-completions" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-cananda-centres-completions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9
</figcaption>
</figure>
</div>
</div>
</div>
<p>This indicates that adopting the goal of doubling completions over the next decade is roughly in line with the expected increase in housing demand combined with digging our way out of our current housing shortfall. Doubling construction won’t happen instantly but ramp up over time, so it will likely take longer to make up for our shortfall, but this puts us on the right path. It remains to be seen how successful Canada will be in meeting this ambitious goal.</p>
<p>Comparing this to the CMHC Supply Gap estimates <span class="citation" data-cites="cmhc_supply_2022 cmhc_supply_2023">(CMHC 2022, 2023)</span>, which uses a different counterfactual scenario, we see that they estimate a need for around 3.5M additional housing units over a decade above and beyond business as usual construction, which is at the upper end of our estimates.</p>
</section>
</section>
<section id="housing-demand-beyond-number-of-dwelling-units" class="level1">
<h1>Housing demand beyond number of dwelling units</h1>
<p>Much of our housing discussions are focused on the number of dwelling units, at the expense of other important aspects of housing demand like housing quality and size. There are two main reasons for this. Firstly, in many provinces we don’t have good (publicly available) metrics to systematically measure housing quality and size.<sup>12</sup></p>
<p>The second reason is that quality and size are not core issues in our housing crisis in Canada. The market functions reasonably well to enable people to renovate their unit as they wish, and while they often remain constrained by regulations from building small units, builders are generally free to build larger units if they see that demand for them rises.<sup>13</sup> In fact, historically a lot of construction labour in Canada has shifted from new construction to repair and renovation construction as shown in Figure&nbsp;10.<sup>14</sup></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_vector</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v62144023"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reno=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v62144024"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>label,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>reno<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(new<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>reno)))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment in residential construction, share going to renovations"</span>,</span>
<span id="cb20-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb20-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of investment going toward renovations"</span>,</span>
<span id="cb20-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan vectors v62144023 and v62144024"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-new-repair-construction" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-new-repair-construction-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-new-repair-construction-1.png" id="fig-new-repair-construction" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-new-repair-construction-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10
</figcaption>
</figure>
</div>
</div>
</div>
<p>The StatCan report also talks about housing demand by tenure or by structural type. Here the analysis largely ignores the confounding issues of regional variation in housing stock and immigrant concentration in big cities, let alone how the addition of immigrants to small cities can lead to their growth into bigger ones. Moreover, tenure choice is of course highly endogenous to housing prices and rents. Changes to affordability will change shares of renters and owners throughout the entire population, not just for newcomers. There are real tradeoffs to buying vs.&nbsp;renting, and people do make choices, but treating observed frequencies of tenure as revealing static underlying preferences is wrong. People choose within constraints. Ignoring this for either newcomers or long-time residents is akin to planning by gaslight - telling folks they want something different than they want. There are lots of renters who would really like to buy but just can’t afford to.</p>
<p>The issue gets even worse when trying to “plan for” housing by structural type by looking at observed frequencies. When it comes to structural type, our housing market is highly distorted by zoning, where the kind of housing allowed interacts with location in ways that clearly disrupt any attempt to read underlying preferences from market outcomes. Any plan that seriously attempts to deal with our latent and growing housing demand will have to tackle zoning restrictions or invite large costs of sprawl (or both), which in turn will fundamentally change how people make tradeoffs. And again, this affects everyone.</p>
<p>After all, outside of a narrow portion of the subsidized sector, new housing isn’t set aside for or primarily occupied by immigrants, most of whom will likely find a home in older housing. In the 2021 census we see that around 11% of Canadian households moved (or newly formed) in the previous year, and of the population which moved only 15% moved from outside of Canada. When restricting to buildings built in the preceding 5 years, only 10% of householders are led by people who lived outside of Canada five years prior. <span class="citation" data-cites="distributional-effects-of-adding-housing.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024a)</span> Planning new housing based on assumed preferences of newcomers is not useful and underlines why it is so important to pay attention to causal mechanisms even when doing descriptive statistics. Especially when trying to inform policy. This kind exercise meant to inform planning without paying sufficient attention to the mechanism of how the housing system actually works is unfortunately still quite common.</p>
</section>
<section id="so-what-causes-rising-housing-consumption-of-immigrants-over-time" class="level1">
<h1>So what causes rising housing consumption of immigrants over time?</h1>
<p>Armed with this understanding we can come back to the question about why immigrants consume more housing over time. There remain very real concerns about reading immigrant experiences sideways (from a cross-section of cohorts) rather than directly across time (following cohorts), and these concerns are compounded by the changing origin and selection criteria applied to immigrants between cohorts. Where immigrants are coming from and how they’re selected can have big effects on things like how much equity they might be bringing! But we will set this aside. We already saw that some explanations offered in the report, e.g.&nbsp;that immigrants initially form multi-family households but then adapt to Canadian norms over time, do not explain much about housing consumption over time. The StatCan report also suggest that immigrant occupancy rates are “driven by a substantial growth in homeownership”, suggesting that homeownership causally increases household formation rates. This seems far fetched from the perspective of how we generally understand housing and household formation.</p>
<p>We can more usefully split this question about change in immigrant housing consumption over time into two parts, one that looks at why housing consumption is initially low compared to those born in Canada and the other why it rises over time.</p>
<p>For the first, we need to understand the selection process for immigrants. Immigrants to Canada often apply and get accepted as a family rather than as individuals. This means that recent immigrants are often already coupled up when they arrive to Canada, lowering their housing consumption. We can see that very clearly in Figure&nbsp;11, where the coupling rate of new immigrants exceeds the coupling rate of the Canadian born across nearly all ages. For this we took <em>recent immigrants</em> to be those who landed in the three years preceeding the census to have a robust enough sample to split by age group.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recent_immigrant =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb21-3">    YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2013"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2015 to 2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020 to 2021"</span>) <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;">"Recent immigrants"</span>,</span>
<span id="cb21-4">    IMMSTAT <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;">"Non-immigrants"</span> <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;">"Canadian born"</span>,</span>
<span id="cb21-5">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Else"</span></span>
<span id="cb21-6">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Couple=</span>MARSTH <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Legally married (and not separated)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living common law"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MARSTH <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Couple, Year, recent_immigrant,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant,AGEGRP,Weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(recent_immigrant<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;">"Else"</span>,</span>
<span id="cb21-13">         AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Couple<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Weight<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;">"WEIGHT"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb21-19">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb21-20">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(.,</span>
<span id="cb21-21">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb21-22">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb21-23">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q9=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(Share,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),</span>
<span id="cb21-24">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant,AGEGRP)),</span>
<span id="cb21-25">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin=</span>q1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax=</span>q9)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>recent_immigrant) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coupling up rates of recent immigrants and Canadian born by age"</span>,</span>
<span id="cb21-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share coupled up"</span>,</span>
<span id="cb21-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age group"</span>,</span>
<span id="cb21-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan 2016, 2021 Census PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immigrant-couples" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immigrant-couples-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immigrant-couples-1.png" id="fig-immigrant-couples" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immigrant-couples-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11
</figcaption>
</figure>
</div>
</div>
</div>
<p>Looking more closely we observe that recent immigrants of all age groups until about 70 years old are coupled up at higher rates than the Canadian born population, and we know that high rates of coupling up reduce housing occupancy rates. This is a product of how Canada selects for immigrants. <!--At the same time we see significant variation between 2016 and 2021. The exact causes for this variation are not clear, but may well indicate a pandemic effect.--></p>
<p>Apart from coupling, our general understanding of how housing and household formation works tells us that age and income are likely factors in explaining the initial housing occupancy rates of recent immigrants, as well as that of previous cohorts proxying changes over time. To start we look at income, where we want to compare recent immigrants to those landing ten years prior to get a sideways glance at trajectory. We set our landing dates for the comparison two years prior to the census in order to ensure that income data (covering previous tax year) actually gets captured. More precisely, we are interested in the economic resources available to families, so we will work with adjusted family income deciles. In Figure&nbsp;12 we adjust for age to remove age effects (where incomes generally rise with age) to just focus in on immigrant status and year of immigration.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">all_deciles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EFDECILE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>)</span>
<span id="cb22-2">decile_recodes <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;">setNames</span>(all_deciles[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^In "</span>,all_deciles)],all_deciles[<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;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^In "</span>,all_deciles)])</span>
<span id="cb22-3">age_dist <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>dependen_child) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-6">  <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;">Population=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb22-7">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP))</span>
<span id="cb22-8"></span>
<span id="cb22-9">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recent_immigrant =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb22-11">    YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2013"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018"</span>) <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;">"Recent immigrants"</span>,</span>
<span id="cb22-12">    YRIMM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2004"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2003"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> YRIM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2009"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2008"</span>) <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;">"10 year immigrants"</span>,</span>
<span id="cb22-13">    IMMSTAT <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;">"Non-immigrants"</span> <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;">"Canadian born"</span>,</span>
<span id="cb22-14">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Else"</span></span>
<span id="cb22-15">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recent_immigrant=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(recent_immigrant,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</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;">"Recent immigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 year immigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canadian born"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Else"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">EFDECILE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(EFDECILE,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!!</span>decile_recodes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(recent_immigrant, Year, EFDECILE,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WEIGHT|WT</span><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;">d+"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-20">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#mutate(Share=Count/sum(Count),.by=c(Year,recent_immigrant,AGEGRP)) |&gt;</span></span>
<span id="cb22-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(recent_immigrant<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;">"Else"</span>,</span>
<span id="cb22-22">         EFDECILE <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(age_dist,<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;">"AGEGRP"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Count,Population),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant,EFDECILE)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,recent_immigrant)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>recent_immigrant,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(EFDECILE))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adjusted family income of immigrants and Canadian born"</span>,</span>
<span id="cb22-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share in adjusted family income decile, excluding dependent children under 20, aged-adjusted to 2021"</span>,</span>
<span id="cb22-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb22-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adjusted after tax</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">family income decile"</span>,</span>
<span id="cb22-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan 2016, 2021 Census PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-immigrant-incomes" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-immigrant-incomes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-immigrant-incomes-1.png" id="fig-immigrant-incomes" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-immigrant-incomes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;12
</figcaption>
</figure>
</div>
</div>
</div>
<p>This shows that in the years after landing immigrant families have tend to have significantly lower income available to them than their Canadian born counterparts. While the immigrant cohort in Canada for 10 years remains behind the income distribution of the Canadian born, they more closely approximate it, demonstrating the process of “catching up” we expect to see with immigrants settling into the Canadian labour market. This increase in income over time will drive independent household formation.</p>
<p>At the same time, immigrants, like all people, age. And like income, as explained previously, this also drives independence as people feel higher pressure to form their own households and families, generally cohering with our understanding of Minimal Household Units. Some differences in cultural acceptance to alternatives likely remains, but most of the drivers of household formation for both immigrants and non-immigrants alike in Canada are economic and demographic. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span></p>
<p>These processes, income growth and aging, that drive increased housing consumption of immigrants over time could of course be understood as part of the consequence of immigration. At the same time, these processes also act on all other Canadians, and in the context of guiding housing policy or planning, the value of separating this out for immigrants is of questionable value.</p>
</section>
<section id="upshot" class="level1">
<h1>Upshot</h1>
<p>There are several takeaways from this discussion. Firstly, it’s important to embed discussions about housing demand within a solid theoretical framework of household formation and its underlying processes. Wherever possible analysis estimating housing demand - including descriptive analysis - should make these underlying assumptions explicit. Doing so allows us to construct meaningful metrics. More importantly, any analysis that aims to inform policy needs to be based in a clear causal understanding of the underlying mechanisms, even if the goal is just to provide descriptive analysis.</p>
<p>When looking at the components of latent housing demand and demand growth in Canada we note that housing demand due to immigration is similar in magnitude to the growth in housing demand due to aging of the existing population or to demand growth due to income growth. Additionally, the accumulated housing shortage is on the order of the combined expected demand growth over the next 10 years. Despite this, much of the public discussion on housing focuses exclusively on demand due to immigration, at best highlighting the poor grasp on housing by the general public and it’s reflection in media coverage, at worst highlighting an unfortunate pattern of immigrant scapegoating.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb23-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-07-14 23:35:43 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb25-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [f53e665] 2025-07-08: update text about wartime housing shortage</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info </span></span>
<span id="cb27-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cmhc_0.2.11               tinytable_0.9.0          
 [3] cancensus_0.5.8           mountainmathHelpers_0.1.4
 [5] cansim_0.4.3              canpumf_0.3.0            
 [7] lubridate_1.9.4           forcats_1.0.0            
 [9] stringr_1.5.1             dplyr_1.1.4              
[11] purrr_1.0.4               readr_2.1.5              
[13] tidyr_1.3.1               tibble_3.3.0             
[15] ggplot2_3.5.2             tidyverse_2.0.0          

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       jsonlite_2.0.0     compiler_4.5.1     tidyselect_1.2.1  
 [5] git2r_0.36.2       scales_1.4.0       yaml_2.3.10        fastmap_1.2.0     
 [9] here_1.0.1         R6_2.6.1           generics_0.1.4     knitr_1.50        
[13] htmlwidgets_1.6.4  rprojroot_2.0.4    pillar_1.10.2      RColorBrewer_1.1-3
[17] tzdb_0.5.0         rlang_1.1.6        stringi_1.8.7      xfun_0.52         
[21] timechange_0.3.0   cli_3.6.5          withr_3.0.2        magrittr_2.0.3    
[25] digest_0.6.37      grid_4.5.1         rstudioapi_0.17.1  hms_1.1.3         
[29] lifecycle_1.0.4    vctrs_0.6.5        evaluate_1.0.4     glue_1.8.0        
[33] farver_2.1.2       rmarkdown_2.29     tools_4.5.1        pkgconfig_2.0.3   
[37] htmltools_0.5.8.1 </code></pre>
</div>
</div>
</details>



</section>


<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-cmhc_supply_2022" class="csl-entry">
CMHC. 2022. <span>“Canada’s Housing Supply Shortages: Estimating What Is Needed to Solve Canada’s Housing Affordability Crisis by 2030.”</span> <em>Housing Market Information</em>. <a href="https://assets.cmhc-schl.gc.ca/sites/cmhc/professional/housing-markets-data-and-research/housing-research/research-reports/2022/housing-shortages-canada-solving-affordability-crisis-en.pdf?rev=88308aef-f14a-4dbb-b692-6ebbddcd79a0">https://assets.cmhc-schl.gc.ca/sites/cmhc/professional/housing-markets-data-and-research/housing-research/research-reports/2022/housing-shortages-canada-solving-affordability-crisis-en.pdf?rev=88308aef-f14a-4dbb-b692-6ebbddcd79a0</a>.
</div>
<div id="ref-cmhc_supply_2023" class="csl-entry">
CMHC. 2023. <span>“Housing Shortages in Canada: Updating How Much Housing We Need by 2030.”</span> <em>Housing Market Information</em>. <a href="https://www.cmhc-schl.gc.ca/professionals/housing-markets-data-and-research/housing-research/research-reports/accelerate-supply/housing-shortages-canada-updating-how-much-we-need-by-2030">https://www.cmhc-schl.gc.ca/professionals/housing-markets-data-and-research/housing-research/research-reports/accelerate-supply/housing-shortages-canada-updating-how-much-we-need-by-2030</a>.
</div>
<div id="ref-statisticscanada_maintainers.2024" class="csl-entry">
Gorski, Aaron, David Heisel, and Jerry Situ. 2024. <em>Households with Multiple Maintainers and the Impact on Homeownership Rates</em>. <a href="https://www150.statcan.gc.ca/n1/pub/46-28-0001/2024001/article/00004-eng.htm">https://www150.statcan.gc.ca/n1/pub/46-28-0001/2024001/article/00004-eng.htm</a>.
</div>
<div id="ref-mhu.2025" class="csl-entry">
Lauster, Nathanael, and Jens von Bergmann. 2025. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981–2021.”</span> <em>The History of the Family</em> 0 (0): 1–30. <a href="https://doi.org/10.1080/1081602X.2024.2448986">https://doi.org/10.1080/1081602X.2024.2448986</a>.
</div>
<div id="ref-housing_shortages_doubled_up_households.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“Housing Shortages and Doubled up Households.”</span> <em>Plan Canada</em> 64 (4): 16–21. <a href="https://mountainmath.github.io/housing_shortages_and_doubled_up_households/">https://mountainmath.github.io/housing_shortages_and_doubled_up_households/</a>.
</div>
<div id="ref-lauster2017labor" class="csl-entry">
Lauster, Nathanael, and Jing Zhao. 2017. <span>“Labor Migration and the Missing Work of Homemaking: Three Forms of Settling for Chinese-Canadian Migrants.”</span> <em>Social Problems</em> 64 (4): 497–512. <a href="https://doi.org/10.1093/socpro/spw035">https://doi.org/10.1093/socpro/spw035</a>.
</div>
<div id="ref-meen2008" class="csl-entry">
Meen, G., and M. Andrew. 2008. <span>“Planning for Housing in the Post-Barker Era: Affordability, Household Formation, and Tenure Choice.”</span> <em>Oxford Review of Economic Policy</em> 24 (1): 79–98. <a href="https://doi.org/10.1093/oxrep/grn010">https://doi.org/10.1093/oxrep/grn010</a>.
</div>
<div id="ref-moffatt_2022" class="csl-entry">
Moffatt, M, A. Dudu, and M Hosseini. 2022. <em>Ontario’s Need for 1.5 Million More Homes</em>. Smart Prosperity Institute. <a href="https://institute.smartprosperity.ca/sites/default/files/Ontarios-Need-for-1.5m-More-Homes-SPI-August-2022.pdf">https://institute.smartprosperity.ca/sites/default/files/Ontarios-Need-for-1.5m-More-Homes-SPI-August-2022.pdf</a>.
</div>
<div id="ref-what-s-a-household.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017. <em>What’s a <span>Household?</span></em> <a href="https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/">https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/</a>.
</div>
<div id="ref-estimating-suppressed-household-formation.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022a. <em>Estimating <span>Suppressed</span> <span>Household</span> <span>Formation</span></em>. <a href="https://doodles.mountainmath.ca/posts/2022-05-06-estimating-suppressed-household-formation/">https://doodles.mountainmath.ca/posts/2022-05-06-estimating-suppressed-household-formation/</a>.
</div>
<div id="ref-planning-for-scarcity.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022b. <em>Planning for Scarcity</em>. <a href="https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/">https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/</a>.
</div>
<div id="ref-still-short-suppressed-households-in-2021.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022c. <em>Still <span>Short:</span> <span>Suppressed</span> <span>Households</span> in 2021</em>. <a href="https://doodles.mountainmath.ca/posts/2022-10-03-still-short-suppressed-households-in-2021/">https://doodles.mountainmath.ca/posts/2022-10-03-still-short-suppressed-households-in-2021/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023a. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
<div id="ref-housing-targets.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023b. <em>Housing Targets</em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/">https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/</a>.
</div>
<div id="ref-metro-vancouver-planning-regimes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023c. <em>Metro <span>Vancouver</span> <span>Planning</span> <span>Regimes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/">https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/</a>.
</div>
<div id="ref-distributional-effects-of-adding-housing.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024a. <em>Distributional Effects of Adding Housing</em>. <a href="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/">https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</a>.
</div>
<div id="ref-doubling-up-distinguishing-families-from-households.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024b. <em>Doubling <span>Up</span> - <span>Distinguishing</span> <span>Families</span> from <span>Households</span></em>. <a href="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/">https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/</a>.
</div>
<div id="ref-tenure-and-household-independence-across-the-life-course-1981-2021.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024c. <em>Tenure and <span>Household</span> <span>Independence</span> Across the <span>Life</span> <span>Course,</span> 1981-2021</em>. <a href="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/">https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</a>.
</div>
<div id="ref-statisticscanada_housing_use.2025" class="csl-entry">
Zhang, Haozhen, and Feng Hou. 2025. <em>Housing Use of Immigrants and Non-Permanent Residents in Ownership and Rental Markets</em>. <a href="https://doi.org/10.25318/36280001202500500003-ENG">https://doi.org/10.25318/36280001202500500003-ENG</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>This of course does not mean that assumptions can be disconnected from data, rather often this is an iterative process where we check how well our assumptions align with the data and adjust as needed.↩︎</p></li>
<li id="fn2"><p>It might be correct to treat the children this way if all or the vast majority of Canadian-born children living in immigrant households were adopted, but this is clearly an unreasonable assumption.↩︎</p></li>
<li id="fn3"><p>There is an argument to be made to bump that up to 25, given how the census codes children attending post-secondary education often as living with their parents even if they live elsewhere during the regular semester. For reference, in recognition of the complexities of transition to adulthood and independence, the <a href="https://news.gov.bc.ca/releases/2024CFD0004-000480">BC government</a> now supports children in care to live with foster families up to age 19, and provides further support to transition up to age 27.↩︎</p></li>
<li id="fn4"><p>To be precise, we removed all children under the age of 15, and people under the age of 20 if they lived with parents or other relatives and were not flagged as primary household maintainer.↩︎</p></li>
<li id="fn5"><p>In fact, in the report StatCan does point out that they are making an assumption here and compare of recent immigrants over the past several censuses as a sanity check. But the housing occupancy rates they list show a huge variation in occupancy rates of recent immigrants, with 261 units per 1000 residents in 2001 increasing to 464 in 2021, directly contradicting their assumption, but fitting well with interpretations of many recent migrants from China as homemaking migrants <span class="citation" data-cites="lauster2017labor">(Lauster and Zhao 2017)</span>.↩︎</p></li>
<li id="fn6"><p>This is not the total effect of income, but only the portion not explained by couple status and age. There are some caveats in that it’s not clear how well these effects can be separated, but in our setup where we treat demographic effects separately and considering this partial effect avoids double-counting. An alternative approach would be to re-structure the estimates to prioritize the total effect of income and then consider the residual impact of age and coupling up on household formation.↩︎</p></li>
<li id="fn7"><p>The NPR and immigration projections are based on current and expected future policy will be based in external input from IRCC, with StatCan likely being reluctant to deviate from IRCC guidance.↩︎</p></li>
<li id="fn8"><p>A surprising number of people in the public immigration discourse who should know better seem to not understand this and think of net NPR growth as similar to growth due to immigration, that latter of which is an I(1) process. These are fundamentally different processes and there is a lot of public confusion and misinformation out there because of this mixup. It of course does not help that people often fail to clearly distinguish in their language between immigration and external in-migration.↩︎</p></li>
<li id="fn9"><p>Cultural norms and preferences for independent living do play a role too, but economic factors dominate. <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span>↩︎</p></li>
<li id="fn10"><p>Metro Vancouver blurs this distinction by mislabelling their <em>household projections</em> as <em>dwelling projections</em> in their growth strategy, adding additional shrinking on top of the other issues in their methods that systematically lead to housing shortages. <span class="citation" data-cites="metro-vancouver-planning-regimes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023c)</span>↩︎</p></li>
<li id="fn11"><p>CMHC used to have an estimate of completions for all of Canada which ran slightly higher than the completions it enumerated in the population centres it surveys, for the ballpark estimates in this post we will gloss over this difference.↩︎</p></li>
<li id="fn12"><p>In BC, where in principle we have good housing data maintained and curated by BC Assessment, information on housing quality and size (with exception on information on size of the majority of purpose-built rental units), is in principle available, but in practice locked away from the public so that BC Assessment can sell the data to cover around 3% to 4% of their budget and save the average property owner about 15 cents a month on the BC Assessment property tax bill. We continue to think this is a mistake, and some provinces make this data publicly available, e.g.&nbsp;Nova Scotia, enabling transparent analysis on aspects of the housing stock beyond just the number of dwelling units.↩︎</p></li>
<li id="fn13"><p>As our housing shortage accumulated over the years builders have responded for increased demand for smaller units as people are changing how they trade privacy and space when navigating whether they want to live in their own separate dwelling unit or double up in a potentially larger one with others.↩︎</p></li>
<li id="fn14"><p>Another angle on this is the popular refrain that productivity in the construction sector, typically measured as number of construction workers per newly completed unit of housing, has remained stagnant. This is at least partially due to an increase in the share of construction workers who don’t actually work to complete new housing but who renovate old housing, with the overall share of investment into repair construction rising from around 20% in in 60s to well over 40% now.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Metrics, {Mechanisms,} and {Mismatch:} {Immigration} and
    Other {Components} of {Housing} {Demand} in {Canada}},
  date = {2025-06-08},
  url = {https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Metrics,
Mechanisms, and Mismatch: Immigration and Other Components of Housing
Demand in Canada.”</span> <em>MountainDoodles</em>, accepted, June 8. <a href="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/">https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <category>canpumf</category>
  <category>cansim</category>
  <category>cancensus</category>
  <category>cmhc</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/</guid>
  <pubDate>Sun, 08 Jun 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-06-08-metrics-mechanisms-and-mismatch-immigration-and-other-components-of-housing-demand-in-canada/index_files/figure-html/fig-housing-demand-components-1.png" medium="image" type="image/png" height="72" width="144"/>
</item>
<item>
  <title>Elections fun - 2025 edition</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/</link>
  <description><![CDATA[ 






<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#remotes::install_github("mountainmath/mountainmathHelpers")</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rmapshaper)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cancensus)</span>
<span id="cb1-7"></span>
<span id="cb1-8">my_theme <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MountainMath, Elections Canada"</span>)</span>
<span id="cb1-10">)</span></code></pre></div></div>
</details>
</div>
<p>Following our posts on the <a href="https://doodles.mountainmath.ca/blog/2019/10/22/elections-fun/">2019 election</a> and <a href="https://doodles.mountainmath.ca/posts/2021-09-25-elections-fun-2021-edition/">2021 election</a> we might as well re-use the code to run a high-level analysis of the 2025 federal election results. And also include the obligatory “land does not vote - people do” map pioneered by <a href="https://bsky.app/profile/karimdouieb.bsky.social">Karim Douïeb</a>. And thanks to <a href="https://quarto.org">quarto</a> supporting <a href="https://observablehq.com/documentation/cells/observable-javascript">observable.js</a> we can now embed the interactive maps directly into the post, as we did with the <a href="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/">2024 BC election results</a>.</p>
<p>Initially I was writing this on election day, with the goal of getting this up and then updating it regularly as the results come in. But the Elections Canada webpage stopped reporting results to the general public and it became too much of a pain. Ridings that have not been called by CBC are coloured in a lighter tone, those will disappear as the remaining ridings get called and the results are updated.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">get_cbc_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(httr)</span>
<span id="cb2-3">cbc_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://canopy.cbc.ca/live/elections/prov/FED2025/all/"</span></span>
<span id="cb2-4"></span>
<span id="cb2-5"></span>
<span id="cb2-6">cbc_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;">content</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">GET</span>(cbc_url))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ridings <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(r){</span>
<span id="cb2-8">  ridings<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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridingNumber=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ridingNumber,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>englishName,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">totalVoters=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>totalVoters,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">totalPolls=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>totalPolls,</span>
<span id="cb2-9">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">resultStatus=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resultStatus),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>),</span>
<span id="cb2-10">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">isCandidateElected=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>isCandidateElected,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pollsReported=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pollsReported,</span>
<span id="cb2-11">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">totalVotesReported=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>totalVotesReported,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">candidateVotesLead=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidateVotesLead,</span>
<span id="cb2-12">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">leadingPartyCode=</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>leadingPartyCode)</span>
<span id="cb2-13">  parties <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>parties <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(p){</span>
<span id="cb2-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">partyId=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>partyId,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">englishCode=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>englishCode,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">candidateFirstName=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidateFirstName,</span>
<span id="cb2-15">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">candidateLastName=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidateLastName,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">votesPercentage=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>votesPercentage,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">votesLead=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>votesLead,</span>
<span id="cb2-16">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">votes=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">candidateId=</span>p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidateId)</span>
<span id="cb2-17">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>()</span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">full_join</span>(ridings,parties,<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;">"id"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>id)</span>
<span id="cb2-20">}) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">called=</span>isCandidateElected<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">District=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"’"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"'"</span>,name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"œ"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"oe"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_))</span>
<span id="cb2-24"></span>
<span id="cb2-25">  cbc_data</span>
<span id="cb2-26">}</span>
<span id="cb2-27"></span>
<span id="cb2-28">get_electoral_areas <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>){</span>
<span id="cb2-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({</span>
<span id="cb2-30">    geos <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;">get_shapefile</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://ftp.maps.canada.ca/pub/elections_elections/Electoral-districts_Circonscription-electorale/federal_electoral_districts_boundaries_2023/FED_CA_2023_EN-SHP.zip"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-31">      rmapshaper<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;">ms_simplify</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb2-32">    clip <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;">get_statcan_geographies</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-33">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_crs</span>(geos)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-34">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ms_simplify</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sys=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-35">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_union</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-36">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>() </span>
<span id="cb2-37"></span>
<span id="cb2-38">    geos <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-39">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_intersection</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_union</span>(clip)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-40">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_collection_extract</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POLYGON"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-41">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-42">      rmapshaper<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;">ms_simplify</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-43">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_collection_extract</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POLYGON"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-44">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FEDUID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(FED_NUM))</span>
<span id="cb2-45">    }, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canada_electoral_district_geos_2023"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</span> refresh) </span>
<span id="cb2-46">}</span>
<span id="cb2-47"></span>
<span id="cb2-48"></span>
<span id="cb2-49"></span>
<span id="cb2-50">get_election_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(){</span>
<span id="cb2-51">  url<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://enr.elections.ca/DownloadResults.aspx"</span></span>
<span id="cb2-52">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> httr<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;">GET</span>(url)</span>
<span id="cb2-53">  text_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> httr<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;">content</span>(r,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb2-54">  </span>
<span id="cb2-55">  rename_lookup <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb2-56">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FEDUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Electoral district number - Numéro de la circonscription"</span>,</span>
<span id="cb2-57">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"District"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Electoral district name"</span>,</span>
<span id="cb2-58">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Type"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Type of results*"</span>,</span>
<span id="cb2-59">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surname"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surname - Nom de famille"</span>,</span>
<span id="cb2-60">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Middle name(s)"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Middle name(s) - Autre(s) prénom(s)"</span>,</span>
<span id="cb2-61">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Given name"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Given name - Prénom"</span>,</span>
<span id="cb2-62">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Political affiliation"</span>,</span>
<span id="cb2-63">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Votes"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Votes obtained - Votes obtenus"</span>,</span>
<span id="cb2-64">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Votes_pct"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"% Votes obtained - Votes obtenus %"</span>,</span>
<span id="cb2-65">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejected"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejected ballots - Bulletins rejetés***"</span>,</span>
<span id="cb2-66">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total number of ballots cast - Nombre total de votes déposés"</span></span>
<span id="cb2-67">  )</span>
<span id="cb2-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_tsv</span>(text_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cols</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.default=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-69">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!!</span>rename_lookup) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-70">    <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;">names</span>(rename_lookup)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-71">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(FEDUID),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(District)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-72">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_at</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;">"Votes"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Votes_pct"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejected"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>),as.numeric) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-73">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Given name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,Surname)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-74">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP-New Democratic Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-75">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>))</span>
<span id="cb2-76">}</span>
<span id="cb2-77"></span>
<span id="cb2-78">party_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb2-79">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People's Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#4a3389"</span>,</span>
<span id="cb2-80">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Conservative=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#0C499C"</span>,</span>
<span id="cb2-81">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bloc Québécois"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#02819E"</span>,</span>
<span id="cb2-82">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Liberal=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#A50B0B"</span>,</span>
<span id="cb2-83">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NDP=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#DA3D00"</span>,</span>
<span id="cb2-84">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Green Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2E8724"</span>,</span>
<span id="cb2-85">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Independent"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#676767"</span>,</span>
<span id="cb2-86">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Undecided"="#676767",</span></span>
<span id="cb2-87">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Other=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yellow"</span>,</span>
<span id="cb2-88">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No results"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#444444"</span></span>
<span id="cb2-89">)</span>
<span id="cb2-90"></span>
<span id="cb2-91">previous_results <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;">"https://www.elections.ca/res/rep/tra/2023rep/csv/Transposition_343_FED.csv"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-92">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FEDUID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(FED_NUM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-93">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(FEDUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">District=</span>FED_EN,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span>Political_Party_EN,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes=</span>Transposed_Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes_pct=</span>Percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-94">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" Party of Canada"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New Democratic Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Green"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Green Party"</span>))</span>
<span id="cb2-95"></span>
<span id="cb2-96"></span>
<span id="cb2-97">clean_parties <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb2-98"> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-99">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Party <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours),Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-100">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-101">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Party,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)))</span>
<span id="cb2-102">}</span>
<span id="cb2-103"></span>
<span id="cb2-104">cleaned_previous_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> previous_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-105">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-106">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FEDUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"District"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-107">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-108">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span>Party)</span>
<span id="cb2-109"></span>
<span id="cb2-110">geos <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;">get_electoral_areas</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-111">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambert_conformal_conic_at</span>(.))</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">cbc_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;">simpleCache</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cbc_data</span>(),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cbc_election_results_2025_05_01_14_15"</span>)</span>
<span id="cb3-2"></span>
<span id="cb3-3">not_called<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cbc_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>called) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(District)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> unique</span>
<span id="cb3-4">called_districts<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cbc_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(called) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(District)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> unique</span>
<span id="cb3-5"></span>
<span id="cb3-6">new_results <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;">get_election_results</span>()  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_to_title</span>(Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Type=="validated" | (!validated &amp; Type !="validated")) %&gt;%</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People's Party - PPC"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People's Party"</span>))</span>
<span id="cb3-10"></span>
<span id="cb3-11">results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> new_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Surname, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Middle name(s)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Given name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(cleaned_previous_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-14">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">previous_winner=</span>Votes<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;">max</span>(Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-15">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(FEDUID,Party,previous_winner), </span>
<span id="cb3-16">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FEDUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dd=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,District)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">called=</span>dd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> called_districts) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Preliminary"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validated"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Judicially Certified"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxType=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(Type),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Type<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;">max</span>(Type),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID)</span>
<span id="cb3-22"></span>
<span id="cb3-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(results<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dd))<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;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(cbc_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>District)))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make sure we don't miss any</span></span>
<span id="cb3-24"></span>
<span id="cb3-25"></span>
<span id="cb3-26">tmp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"results_2025.csv"</span>)</span>
<span id="cb3-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#dd$called=sample(c(TRUE,FALSE), nrow(dd), TRUE)</span></span>
<span id="cb3-28">results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Registered=</span>Total) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Party <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(FEDUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Candidate=</span>Name,Party,Votes,called,previous_winner,Type,Registered,Total) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(tmp)</span>
<span id="cb3-34">dummy <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;">file_to_s3_gzip</span>(tmp,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mountainmath"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"elections/results_2025.csv"</span>)</span></code></pre></div></div>
</details>
</div>
<div class="cell" data-crop="true" data-clip="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">map_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geos <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_parties</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Votes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span>FEDUID),<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;">"FEDUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(Total<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No results"</span>,Party))</span>
<span id="cb4-7"></span>
<span id="cb4-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(map_data,<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;">fill=</span>Party)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada federal election 2025"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>This map makes it virtually impossible to get a good reading of the distribution of votes. There are a couple of ways around this.</p>
<p>For example, one could break out the areas with electoral districts too small to make a visible impact on the map, or use a cartogram, like shown on the <a href="https://en.wikipedia.org/wiki/2021_Canadian_federal_election">Wikipedia page of the 2021 federal election</a>.</p>
<p>Another way to structure a cartogram is to scale geographic regions to the size of their (voting) population, as can be seen in the following graph.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># this takes forever</span></span>
<span id="cb5-2">cartogram_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;">simpleCache</span>({</span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cartogram)</span>
<span id="cb5-4">  map_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_cast</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POLYGON"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_area</span>(geometry) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area_rank=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(a),</span>
<span id="cb5-8">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(a),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>Total<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>total_area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ms_simplify</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cartogram_cont</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pop"</span>,</span>
<span id="cb5-12">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">itermax =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,</span>
<span id="cb5-13">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxSizeError =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.01</span>,</span>
<span id="cb5-14">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prepare =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adjust"</span>,</span>
<span id="cb5-15">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,</span>
<span id="cb5-16">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb5-17">}, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"continuous_cartogram.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(District) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Votes<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;">max</span>(Votes),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID),<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;">"District"</span>)</span>
<span id="cb5-20"></span>
<span id="cb5-21"></span>
<span id="cb5-22">cartogram_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada federal election 2025"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>While this fairly accurately represents the “colour” of the vote, most of the geographic references are lost and it is only of limited usefulness. Although interesting how Canada gets pinched at Hudson Bay with low population areas collapsed.</p>
<p>Another way to bridge the gap is to animate a map that moves between a cartographic view of Canada and a Dorling cartogram as popularized by <a href="https://bsky.app/profile/karimdouieb.bsky.social">Karim Douïeb</a>, as as we have done for past election. The following is a live animation morphing between the map and the cartogram, with tooltips providing added interactivity and details on ridings.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="254" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 253;"><span id="cb6-254">vote_map_animation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb6-255">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ratio <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-256">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">select</span>(DOM<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;">svg</span>(width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height))</span>
<span id="cb6-257">      <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viewBox"</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;">"0 0 960 600"</span>)</span>
<span id="cb6-258">      <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;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</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;">"100%"</span>)</span>
<span id="cb6-259">      <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;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</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;">"auto"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-260"></span>
<span id="cb6-261">   <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">debugger</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-262">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// render map</span></span>
<span id="cb6-263">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> path <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">geoPath</span>(projection)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-264"></span>
<span id="cb6-265">   svg<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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb6-266">     <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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path"</span>)</span>
<span id="cb6-267">     <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;">data</span>(districts)</span>
<span id="cb6-268">     <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;">enter</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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path"</span>)</span>
<span id="cb6-269">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</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;">"districtShape"</span>)</span>
<span id="cb6-270">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</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> 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;">properties</span><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;">called</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> party_colors[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;">properties</span><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;">winner</span><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;">Party</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> party_colors2[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;">properties</span><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;">winner</span><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;">Party</span>])  </span>
<span id="cb6-271">     <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;">attr</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> path)</span>
<span id="cb6-272">     <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;">attr</span>(<span class="st" style="color: #20794D;
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;">"white"</span>)</span>
<span id="cb6-273">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</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;">0.5</span>)</span>
<span id="cb6-274">     <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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>)</span>
<span id="cb6-275">     <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>(tooltip) </span>
<span id="cb6-276">   </span>
<span id="cb6-277">  <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">setInterval</span>(() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-278">    svg<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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".districtShape"</span>)</span>
<span id="cb6-279">      <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;">transition</span>()</span>
<span id="cb6-280">      <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;">delay</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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> 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;">properties</span><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>
<span id="cb6-281">      <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;">duration</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>)</span>
<span id="cb6-282">      <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;">attrTween</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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) {</span>
<span id="cb6-283">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> flubber<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;">toCircle</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path</span>(d)<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;">x</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;">y</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;">properties</span><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;">radius</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;">maxSegmentLength</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-284">      })</span>
<span id="cb6-285"></span>
<span id="cb6-286">    svg<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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".districtShape"</span>)</span>
<span id="cb6-287">      <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;">transition</span>()</span>
<span id="cb6-288">      <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;">delay</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</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> 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;">properties</span><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>
<span id="cb6-289">      <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;">duration</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>)</span>
<span id="cb6-290">      <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;">attrTween</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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) {</span>
<span id="cb6-291">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> flubber<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;">fromCircle</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;">x</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;">y</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;">properties</span><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;">radius</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;">path</span>(d)<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;">maxSegmentLength</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-292">      })</span>
<span id="cb6-293">  }<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;">25000</span>)</span>
<span id="cb6-294"></span>
<span id="cb6-295">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> svg<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;">node</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-296">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">plot_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-2">  clean_parties <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Votes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Total) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(District) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LagShare=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> r)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_n</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin=</span>Share<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>LagShare)</span>
<span id="cb7-9"></span>
<span id="cb7-10">plurality <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> ungroup <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Share<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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>()</span></code></pre></div></div>
</details>
</div>
<p>This still loses a lot of nuance. The colour is determined by who won the district, the animation reveals no information on how wide or narrow the margin of victory was. Or how the other candidates performed.</p>
<section id="winning-vote-share" class="level2">
<h2 class="anchored" data-anchor-id="winning-vote-share">Winning vote share</h2>
<p>With more than 2 candidates in each riding, one does not necessarily require a plurality of votes to win. 217 out of the 343 candidates won with over 50% of the vote in their district, that’s almost double of what we saw in the last election. The largest vote share any winning candidate got was 84%, the lowest was 34%, both numbers up a little from what we saw in the last election.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(plot_data ,<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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(District,Share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-5">  my_theme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada 2025 federal election"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Voting districts"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vote share of winning candidate"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">top_party <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>()</span>
<span id="cb9-2"></span>
<span id="cb9-3">top_sweep <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> plot_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-4">  ungroup <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Party <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;">head</span>(.,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-9">  min <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span></code></pre></div></div>
</details>
</div>
<p>In the last election the top 4 spots in terms of vote share were taken by the Conservatives, this time around the Conservatives swept the top 23 spots.</p>
</section>
<section id="distribution-of-votes" class="level2">
<h2 class="anchored" data-anchor-id="distribution-of-votes">Distribution of votes</h2>
<p>We can expand this view to show the vote share by party for each district.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">all_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  clean_parties <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Votes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Total) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(District) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">winner=</span>Votes<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;">max</span>(Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-6">  ungroup <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">District=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(District,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.,District) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-8">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Party <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People's Party"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conservative"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-9">                           <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;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-10">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-11">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(District),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb10-12"></span>
<span id="cb10-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(all_data ,<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>District,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Party))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-17">  my_theme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada 2025 federal election"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Voting districts"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vote share"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="wasted-votes" class="level2">
<h2 class="anchored" data-anchor-id="wasted-votes">Wasted votes</h2>
<p>With our first-past-the-post system, we can also take a look at “wasted” votes. We define these as votes that have no bearing on the outcome. For winners it’s the vote margin by which they won, for the ones that did not win their district it’s the entirety of their votes.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">waste_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-2">  clean_parties <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(District) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(District,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">required=</span>Votes),<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;">"District"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">winner=</span>Votes<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;">max</span>(Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">waste=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(winner,Votes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>required<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-9">  <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;">waste=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(waste),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>)</span>
<span id="cb11-10"></span>
<span id="cb11-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(waste_data ,<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>Party,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>waste,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Party))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-14">  my_theme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada 2025 federal election"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Wasted votes"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>The parties that got the most votes are naturally also the ones with the most votes to waste. Wasted votes is a somewhat artificial system that does not necessarily reflect how parties would have performed under a different voting system. We will need to take a closer look for that.</p>
</section>
<section id="first-past-the-post-vs-proportional-representation" class="level2">
<h2 class="anchored" data-anchor-id="first-past-the-post-vs-proportional-representation">First-past-the-post vs proportional representation</h2>
<p>How would the parties have fared under a proportional representation system (PR) instead of first-past-the-post (FPTP)? There are many different kinds of proportional representation systems out there, but they generally try to approximate a seat distribution that mirrors the overall vote share. For simplicity we will simply take the overall vote share as a proxy for what a proportional representation system might have yielded. Well, kind of. The votes were cast under the expectation of a FPTP system, if we had switched to some kind of proportional representation or ranked ballot system some people would likely have voted differently and the outcome would have been different. We should view the PR alternative view as a first approximation to a PR outcome, if people were voting under a PR system the outcome could possibly be quite different.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">pr_name_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cancensus<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;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(region))</span>
<span id="cb12-2">pr_names <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;">set_names</span>(pr_name_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name,pr_name_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>region)</span>
<span id="cb12-3">pr_share_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> all_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(FEDUID,<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;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(PR,Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-6">  <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;">Votes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Seats=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(winner),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(PR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Votes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>pr_names[PR] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> as.character) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Province,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.,Province) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-11">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Party <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People's Party"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conservative"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-12">                           <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;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-13">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-14">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Province),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-15">  ungroup <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>PR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FPTP=</span>Seats,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span>Votes)  </span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">pr_share_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-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;">FPTP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(FPTP),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(PR),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span>PR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(PR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gather</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Voting system"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</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;">"FPTP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Voting system</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Party))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-10">  my_theme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada 2025 federal election, comparing FPTP to PR with 5% minimum vote cutoff"</span>,</span>
<span id="cb13-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(preliminary results)"</span>,</span>
<span id="cb13-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Voting system"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of seats"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Last time the Liberals were the big winner of FPTP, as was Bloc Québécois. This time around again the Liberals profited most from FPTP, at cost to the NDP<sup>1</sup> But overall, the election outcome would not have been that much different in who forms government under either system, but there is a difference in whether it’s a minority or majority government.</p>
<p>We can run this by individual province to see how well each province is represented in terms of first-past-the-post vs proportional representation.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">pr_share_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gather</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Voting system"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share"</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;">"FPTP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Province,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Party))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-7">  my_theme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"`Voting system`"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada 2025 federal election, comparing FPTP vs PR by province"</span>, </span>
<span id="cb14-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Province"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of seats"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/province_fptp_pr2-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="upshot" class="level2">
<h2 class="anchored" data-anchor-id="upshot">Upshot</h2>
<p>There is endless fun to be had with elections data. As usual, the code for this post, including the pre-processing for the animation, is <a href="https://github.com/mountainMath/doodles/blob/master/content/posts/2025-04-28-elections-fun---2025-edition/index.qmd">available on GitHub</a> for anyone to adapt and dig deeper into elections data.</p>
</section>
<section id="update-may-10th" class="level2">
<h2 class="anchored" data-anchor-id="update-may-10th">Update (May 10th)</h2>
<p>I have been re-running the code occasionally as Elections Canada updated results. And seats flipped, which happened twice since the election was called on election night.</p>
<p>Additionally, I got a <a href="https://bsky.app/profile/thomassomething.bsky.social/post/3loud5jbzp22h">question about showing seat flips</a>. With the redistricting in 2023 we now have more elecoral districts than in 2021 and not all ridings are comparable. Of course people also moved in the meantime, so it’s not the same people voting. Understanding this we can take the 2021 votes redistributed over the new electoral ridings used in the 2025 election and compare the 2025 outcome to the hypothetical outcome of the 2021 vote redistributed over the 2025 electoral riding boundaries.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">map_data2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> map_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Votes<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;">max</span>(Votes),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(previous_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Votes<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;">max</span>(Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</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;">.by=</span>FEDUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(FEDUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PreviousParty=</span>Party),</span>
<span id="cb15-4">            <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;">"FEDUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">flip=</span>Party<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span>PreviousParty) </span>
<span id="cb15-6"></span>
<span id="cb15-7">flips <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> map_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(flip) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(FEDUID,<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;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-11">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-12">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(name,pop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-13">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span>region,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>name),</span>
<span id="cb15-14">              <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;">"PRUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(Party) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> Party,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>n)</span>
<span id="cb15-17"></span>
<span id="cb15-18">flips_lost <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> map_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(flip) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(FEDUID,<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;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-22">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-23">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(name,pop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-24">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span>region,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>name),</span>
<span id="cb15-25">              <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;">"PRUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(PreviousParty) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> PreviousParty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>n)</span>
<span id="cb15-28"></span>
<span id="cb15-29">map_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(flip) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(FEDUID,<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;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-33">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-34">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(name,pop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-35">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PRUID=</span>region,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>name),</span>
<span id="cb15-36">            <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;">"PRUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Province,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>PreviousParty)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Party,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_labeller</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;">"Conservative"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conservative 2025"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Liberal"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Liberal 2025"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flipped seats 2025 vs redistricted 2021 federal election results"</span>,</span>
<span id="cb15-42">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of seats"</span>,</span>
<span id="cb15-43">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021 winner"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/index_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>This shows that overall the Liberals flipped 28 seats and the Conservatives flipped 28 in their favour, while the liberals lost 16 and the Conservatives lost 11 seats compared to the redistributed 2021 votes. No other parties picked up seats. The biggest losers in this election were the NDP who lost 17 seats, while the Bloc Québécois lost 11 seats and the Green Party lost 1 seat.</p>
<details>
<summary>
Remaining Observable code
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" data-startfrom="542" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 541;"><span id="cb16-542">applySimulation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (nodes) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb16-543">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> simulation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">forceSimulation</span>(nodes)</span>
<span id="cb16-544">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceX</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;">x</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">2</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;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>))</span>
<span id="cb16-545">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceY</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;">y</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">5</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;">8</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>))</span>
<span id="cb16-546">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceX</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;">x</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">properties</span><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;">centroid</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;">properties</span><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;">centroid</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;">0</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;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>))</span>
<span id="cb16-547">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceY</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;">y</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">properties</span><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;">centroid</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;">properties</span><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;">centroid</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 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>))</span>
<span id="cb16-548">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"charge"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceManyBody</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;">strength</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="cb16-549">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collide"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceCollide</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;">radius</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">properties</span><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;">radius</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nodePadding)<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;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>))</span>
<span id="cb16-550">    <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;">stop</span>()</span>
<span id="cb16-551"></span>
<span id="cb16-552">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <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>
<span id="cb16-553">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (simulation<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;">alpha</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>) {</span>
<span id="cb16-554">    simulation<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;">tick</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb16-555">    i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++;</span></span>
<span id="cb16-556">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">console</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;">log</span>(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>i<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;">200</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="cb16-557">  }</span>
<span id="cb16-558"></span>
<span id="cb16-559">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> simulation<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;">nodes</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-560">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" data-startfrom="564" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 563;"><span id="cb17-564">spreadDistricts <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;">applySimulation</span>(districts)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" data-startfrom="568" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 567;"><span id="cb18-568">maxRadius <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;">10</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" data-startfrom="572" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 571;"><span id="cb19-572">radiusScale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb19-573">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> populationMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts<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> 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;">properties</span><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;">Total</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;">reduce</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</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;">max</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b)<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>
<span id="cb19-574">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> d3<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;">scaleSqrt</span>()</span>
<span id="cb19-575">    <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;">domain</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> populationMax])</span>
<span id="cb19-576">    <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;">range</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> maxRadius]) </span>
<span id="cb19-577">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" data-startfrom="582" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 581;"><span id="cb20-582">ratio <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.8</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" data-startfrom="586" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 585;"><span id="cb21-586">nodePadding <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.3</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" data-startfrom="590" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 589;"><span id="cb22-590">tooltip <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb22-591">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f<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;">properties</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-592">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> p<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;">winner</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-593">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [</span>
<span id="cb22-594">        p<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;">District</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-595">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>p<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;">Type</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;"> winner: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>w<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;">Candidate</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>w<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;">Party</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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-596">  <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">comma</span>(p<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;">Total</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;"> votes counted`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-597">          p<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;">results</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;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="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="cb22-598">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</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;">Party</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">comma</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;">Votes</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">percent</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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p<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;">Total</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="cb22-599">          })<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;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb22-600">        ]<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;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb22-601">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" data-startfrom="607" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 606;"><span id="cb23-607">party_colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb23-608">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb23-609">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Liberal</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;">"#A50B0B"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-610">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Conservative</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;">"#0C499C"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-611">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bloc Québécois"</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;">"#02819E"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-612">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">NDP</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;">"#DA3D00"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-613">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Independent</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;">"#676767"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-614">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Green Party"</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;">"#2E8724"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-615">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</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;">"#aaaa11"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-616">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No results"</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;">"#808080"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb23-617">  }</span>
<span id="cb23-618">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" data-startfrom="622" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 621;"><span id="cb24-622">party_colors2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb24-623">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb24-624">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Liberal</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;">"#ce7474"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-625">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Conservative</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;">"#83ACF5"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-626">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bloc Québécois"</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;">"#03aad0"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-627">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">NDP</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;">"#FFB38D"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-628">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Independent</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;">"#FFCBB8"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-629">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Green Party"</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;">"#84DA80"</span></span>
<span id="cb24-630">  }</span>
<span id="cb24-631">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" data-startfrom="637" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 636;"><span id="cb25-637">format <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb25-638">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">density</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".2s"</span>)(x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".3r"</span>)(x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb25-639">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">percent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".1%"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb25-640">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">comma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">",.0f"</span>)</span>
<span id="cb25-641">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" data-startfrom="645" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 644;"><span id="cb26-645">projection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  d3<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;">geoIdentity</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;">reflectY</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fitSize</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">960</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;">600</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> canada)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" data-startfrom="649" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 648;"><span id="cb27-649">districts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> canada<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;">features</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;">map</span>(f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb27-650">  f<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;">properties</span><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;">centroid</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;">projection</span>([f<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;">properties</span><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;">X</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>f<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;">properties</span><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;">Y</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb27-651">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb27-652">})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-13" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" data-startfrom="656" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 655;"><span id="cb28-656">canada <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { </span>
<span id="cb28-657">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://s3.ca-central-1.amazonaws.com/mountainmath/elections/election_2025.json.gz"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-658">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> canada <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> d3<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;">json</span>(url)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-659">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> d3<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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://mountainmath.s3.ca-central-1.amazonaws.com/elections/results_2025.csv"</span>)</span>
<span id="cb28-660">  </span>
<span id="cb28-661">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> canada_results <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 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;">Set</span>(results<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> 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;">FEDUID</span>))]</span>
<span id="cb28-662">    <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;">reduce</span>((hash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> elem) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb28-663">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> results<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>(r <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> r<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;">FEDUID</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> elem)</span>
<span id="cb28-664">        <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> {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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">parseInt</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;">Votes</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-665">                  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;">Total</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">parseInt</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;">Total</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-666">                  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;">Registered</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">parseInt</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;">Registered</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-667">                  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span>(d)})</span>
<span id="cb28-668">        <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;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b<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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>a<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;">Votes</span>)</span>
<span id="cb28-669">      hash[elem] <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;">results</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-670">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">subTotal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>d3<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;">sum</span>(rs<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> 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;">Votes</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-671">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-672">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">called</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">called</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;">"TRUE"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-673">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">winner</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]}</span>
<span id="cb28-674">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> hash</span>
<span id="cb28-675">          }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {})</span>
<span id="cb28-676">  </span>
<span id="cb28-677">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> voteMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">max</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">keys</span>(canada_results)<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> canada_results[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;">winner</span><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;">Total</span>)</span>
<span id="cb28-678">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> radiusScale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">scaleSqrt</span>()</span>
<span id="cb28-679">      <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;">domain</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> voteMax])</span>
<span id="cb28-680">      <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;">range</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> maxRadius]) </span>
<span id="cb28-681">  </span>
<span id="cb28-682">  canada<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;">features</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;">forEach</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb28-683">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> canada_results[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;">properties</span><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;">FEDUID</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;">toString</span>()]</span>
<span id="cb28-684">      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;">properties</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb28-685">        <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;">properties</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-686">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>rp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-687">        <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> 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;">properties</span><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;">X</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-688">        <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> 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;">properties</span><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;">Y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-689">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">radius</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;">properties</span><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;">main</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;">radiusScale</span>(rp<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;">winner</span><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;">Total</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>
<span id="cb28-690">      }</span>
<span id="cb28-691">  })</span>
<span id="cb28-692"></span>
<span id="cb28-693">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">debugger</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb28-694">  </span>
<span id="cb28-695">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> canada<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb28-696">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-14" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" data-startfrom="701" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 700;"><span id="cb29-701">d3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d3@5"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-15" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" data-startfrom="705" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 704;"><span id="cb30-705">turf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@turf/turf@5"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-16" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" data-startfrom="709" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 708;"><span id="cb31-709">flubber <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/flubber'</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-17" data-nodetype="declaration">

</div>
</div>
</div>
</details>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb32-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-05-23 16:14:52 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb34-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [30d5ab6] 2025-05-16: lorentz curve pust fix speeling (thanks Michael), crop images to avoid white background and transition to quarto</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb36-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.5.0 (2025-04-11)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.5                
 [3] knitr_1.50                rlang_1.1.6              
 [5] xfun_0.52                 generics_0.1.4           
 [7] jsonlite_2.0.0            glue_1.8.0               
 [9] git2r_0.36.2              htmltools_0.5.8.1        
[11] mountainmathHelpers_0.1.4 scales_1.4.0             
[13] rmarkdown_2.29            grid_4.5.0               
[15] evaluate_1.0.3            tibble_3.2.1             
[17] fastmap_1.2.0             yaml_2.3.10              
[19] lifecycle_1.0.4           compiler_4.5.0           
[21] dplyr_1.1.4               RColorBrewer_1.1-3       
[23] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[25] rstudioapi_0.17.1         farver_2.1.2             
[27] digest_0.6.37             R6_2.6.1                 
[29] tidyselect_1.2.1          pillar_1.10.2            
[31] magrittr_2.0.3            tools_4.5.0              
[33] gtable_0.3.6              ggplot2_3.5.2            </code></pre>
</div>
</div>
</details>


</section>


<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>Some people would likely change their voting behaviour if the voting system changed, this comparison makes the simplifying and somewhat unrealistic assumption that this won’t happen and voting behaviour remains unchanged.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{elections-fun---2025-edition.2025,
  author = {{von Bergmann}, Jens},
  title = {Elections Fun - 2025 Edition},
  date = {2025-04-28},
  url = {https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann. 2025. <span>“Elections Fun - 2025 Edition.”</span>
<em>MountainDoodles</em>, accepted, April 28. <a href="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/">https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/</a>.
</div></div></section></div> ]]></description>
  <category>geeky</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/</guid>
  <pubDate>Mon, 28 Apr 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-04-28-elections-fun---2025-edition/images/canada_election_2025_cartogram.png" medium="image" type="image/png" height="221" width="144"/>
</item>
<item>
  <title>Housing shortage as an explanation for family and household change</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/03/11/housing-shortage-as-an-explanation-for-family-and-household-change/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>In our new paper “The new rules: housing shortage as an explanation for family and household change across large metro areas in Canada, 1981-2021” <span class="citation" data-cites="mhu.2025">(Lauster and Bergmann 2025)</span> (<a href="https://mountainmath.github.io/family_household_change/">preprint and replication code</a>) we estimate the impacts of housing shortage on the substantial variation we see in family and household structures, both across large metro areas in Canada and across time, focusing on 1981 through 2021.</p>
<p>We set up the paper by describing the historical backstory to a cultural shift toward households that look like Minimal Household Units (MHU). Following Ermisch &amp; Overton we describe four basic MHU living arrangements as becoming more broadly desirable:</p>
<ul>
<li>living alone,</li>
<li>living as a single parent of dependent child(ren),</li>
<li>living as a couple without children, and</li>
<li>living as a couple with dependent child(ren).</li>
</ul>
<p>The shift toward MHU arrangements maps onto rising desire for privacy and autonomy and a decreasing tolerance for various forms of servanthood, boarding, and lodging arrangements that used to be more common. This declining tolerance was also often directed at lodging houses and apartment buildings, ultimately resulting in various states of housing shortage across Canada. We provide a long-term view of rents across Canadian metropolitan areas as a measure of evolving housing shortages.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/rent-timelines.png" class="img-fluid figure-img"></p>
<figcaption>Real median rents are estimated at the CMA level from PUMF data 1981-2021, using the numerical gross rent distribution in newer PUMF and estimated from gross rent brackets for older PUMF. Data prior to 1981 is taken from census profile data tables and estimated from cash rent brackets.</figcaption>
</figure>
</div>
<p>It’s fun to track the positions of metropolitan areas over time, for instance following the oil busts and booms through Calgary or watching as Vancouver moved from middle of the pack to begin vying with Toronto for highest rents between 1971 and 1981, but overall we’re interested in the widening variation in shortage between metros. Metropolitan housing shortage, of course, can make it more or less difficult to achieve MHU living arrangements. We’re able to track this relationship for recent decades, gathering data on rents and minimal household unit status across nine major metropolitan areas within Canada. Conceptualizing household change as being driven by a variety of factors, we establish a robust relationship whereby lower rents sort more young adults (age 20-44) into minimal household units (MHU) over this time period.</p>
<p>Rising rents may also be a sign of improving quality of housing services, deflating rents by incomes instead of CPI offers another point of view that at least partially filters out effects of improving housing quality, as these are generally driven by income growth. Refining our methods leaves us with the shorter 1981 through 2021 time period, where we see significant variation in rents and incomes and across metro areas. Both real incomes (of young adults) and real rents have generally increased, but the rent-to-income ratio has diverged in interesting patterns that enable robust estimates of the effects of rents and incomes on household formation.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/rent-income-timeline.png" class="img-fluid figure-img"></p>
<figcaption>Rent to income ratios for Canadian metro areas are estimated using median total income for the population aged 25 to 44, including zeros, to reflect income available to our main population of interest. 20 to 24 year olds were excluded to guard against impacts of trends of increasing education and delayed entry into the workforce. Data availability in early years is limited.</figcaption>
</figure>
</div>
<p>The share of young adults not in minimal household units by age bracket follows a related pattern across metro areas and census years.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-shares-simple.png" class="img-fluid figure-img"></p>
<figcaption>Timelines of the share of individuals in MHU by CMA and age group, 1981-2021.</figcaption>
</figure>
</div>
<p>Putting this together with rents reveals a simple pattern, whereby higher rents correlate with lower MHU shares.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-shares-rents.png" class="img-fluid figure-img"></p>
<figcaption>Correlation between real rent and MHU by age group across CMAs and years, 1981-2021.</figcaption>
</figure>
</div>
<p>But is there a causal interpretation of this relationship? To investigate this we conceptualize the processes by which young adults sort into households by MHU status in the following way:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-model.png" class="img-fluid figure-img"></p>
<figcaption>Conceptual model of the determinants of MHU status, focusing on the main economic and social causal pathways. Wealth is unobserved as an uncontrolled confounder interacting with culture.</figcaption>
</figure>
</div>
<p>We focus on metro level prevailing rents, as determined by housing markets and regulations at the metro area level, as our primary determinant of interest with respect to MHU status, while including other important determinants for precision and to close potential backdoor paths mediated by “Culture” (and to a lesser degree incomes) as given by varying cultural makeup across metro areas. Wealth is an important variable that remains unfortunately unmeasured and likely has some confounding impact on our estimates, however we believe this remains only a minor concern.</p>
<p>We estimate our model by utilizing individual level census public use microdata files (PUMF) in a logit regression. As a baseline that does not consider the role of Canada’s growing cultural diversity we first restrict the model to the non-immigrant non-visible minority sub-population.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-model-baseline.png" class="img-fluid figure-img"></p>
<figcaption>MHU model using baseline non-visible minority non-immigrant population not attending school part or full time, year fixed effects not shown.</figcaption>
</figure>
</div>
<p>This shows a clear impact of rents on the probability of living in a minimal household unit vs doubling up. As expected, other factors also matter, in particular couple status and incomes. Couple status is not unrelated to housing outcomes and lacks a clear causal interpretation.</p>
<p>But what happens when we add “Culture” into the model and try to assess it’s impact on the relationship? Given the model utilizing data back to 1981, and working under the constraints of variables available in the PUMF data (not having access to the full sample of the census for this work), we lack the ability to include fine subgroups. Instead we settle for broad categories built from visible minority status and immigrant generation.<sup>1</sup></p>
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-model-culture.png" class="img-fluid" alt="MHU model including “Culture” using the full population except people attending school part or full time, year fixed effects not shown."> Our results do show an impact of “Culture”, especially for immigrants, as the estimated effect sizes are now averaged across the overall population. For an apples-to-apples comparison of the models including and excluding culture we can estimate the effect size of the culture model on the same baseline population we used in the baseline model.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/mhu-model-comparison.png" class="img-fluid figure-img"></p>
<figcaption>Comparison of estimated effects for the baseline model, the culture model, and a culture model for baseline population only to highlight variation in estimates.</figcaption>
</figure>
</div>
<p>If our model was successful in capturing all confounding effects we would expect that the effect sizes of the baseline and “Culture” model estimated on the baseline population to be identical, but we do notice some slight shifts. We attribute most of these to the unmeasured “Wealth” factor, which differs systematically across cultural groups and by immigration status. Additionally this comparison reveals hints of wealth-based sorting, some of the effects of which get soaked up in our mobility variable.</p>
<section id="takeaways" class="level1">
<h1>Takeaways</h1>
<p>We find broad support for a strong relationship between rents and the the likelihood that households will form into minimal household units, and that this relationship is causal. It serves as an important reminder that the form and size of <strong>households are malleable</strong>, and at least partially outcomes of housing pressure.</p>
<p>This has important implications for policy! Existing household arrangements should not be taken as the simple product of preferences of household members, and assuming households to remain fixed under policy interventions can introduce substantial collider bias threatening the validity of analysis. Our results indicate that housing policy should pay special attention to the malleability of households. Many household-based measures of housing pressure, like shelter cost to household income ratios, fail to incorporate how the composition of households itself reflects housing pressure. Moreover, as households split up into MHU, it often decreases aggregate household-based affordability measures despite being viewed as preferable by household members. This suggests that MHU formation should be directly incorporated into policy analysis to complement affordability-based metrics in order to better understand how housing shortage works and avoid misspecification of the welfare function.</p>
<p>The tight causal relationship between rents and the share of people in MHU can serve as a useful proxy for housing pressures brought on by shortage. This strong relationship also offers a clear direction to fixing our housing problems. To increase MHU shares it is necessary to address the underlying housing shortage by increasing the total amount of housing available. On a fundamental level this is a consequence of the “pigeonhole principle” and the mechanical relationship between dwellings and households.</p>
<p>The relationship of rents and MHU to shortage also highlights the importance of thinking through systemic effects when contemplating housing policy. Doubling up is the main mechanism by which people adjust to housing pressures. Unfortunately contemporary housing analysis and literature often forget this in suggesting that increasing housing supply primarily serves in-migrants. This is problematic insofar as it leads to misunderstandings about how housing works as a system, and can easily lead to counter-productive policy recommendations. For additional examples of potentially counter-productive policies, a policy freezing rents may help current tenants, but does little to alleviate underlying shortage, and correspondingly we wouldn’t expect it to have much effect on MHU status. Similarly, policies, as with some occupancy restrictions, that reinforce the move toward MHU shouldn’t be expected to drive down rents, and may, indeed, have the opposite effect, as well as driving up homelessness. It’s only by alleviating underlying housing shortage that we expect to see a rise in welfare, as measured by both a decline in rents and a rise in MHU, and in line with our results above.</p>
<p>This post has no code, but all the images are taken from <a href="https://www.tandfonline.com/doi/full/10.1080/1081602X.2024.2448986">our paper</a> that comes will <a href="https://github.com/mountainMath/family_household_change/blob/main/family_household_change.qmd">full replication code</a>.</p>



</section>


<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-mhu.2025" class="csl-entry">
Lauster, Nathanael, and Jens von Bergmann. 2025. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981–2021.”</span> <em>The History of the Family</em> 0 (0): 1–30. <a href="https://doi.org/10.1080/1081602X.2024.2448986">https://doi.org/10.1080/1081602X.2024.2448986</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>We estimate a model with finer categories in the Appendix of the paper based only on the most recent three census years.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{housing-shortage-as-an-explanation-for-family-and-household-change.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Housing Shortage as an Explanation for Family and Household
    Change},
  date = {2025-03-11},
  url = {https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Housing Shortage as
an Explanation for Family and Household Change.”</span>
<em>MountainDoodles</em>, accepted, March 11. <a href="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/">https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/</guid>
  <pubDate>Tue, 11 Mar 2025 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-03-11-housing-shortage-as-an-explanation-for-family-and-household-change/images/paper_title_abstract.png" medium="image" type="image/png" height="137" width="144"/>
</item>
<item>
  <title>cansim revamp</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/</link>
  <description><![CDATA[ 






<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(bench)</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cansim_repartition_cached_table</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_partitioning =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ensure we are starting with unpartitioned parquet</span></span></code></pre></div></div>
</details>
</div>
<p><img src="https://raw.githubusercontent.com/mountainMath/cansim/master/images/cansim-sticker.png" style="width:300px;max-width=45%;float:right;padding:5px;"> With version 0.4 <strong>cansim</strong> package got a major revamp. The <strong>cansim</strong> package has been available con CRAN since late 2018 and has undergone number of improvements since then. It started out focused on retrieving entire table data, with an emphasis on folding in metadata and making this additional layer of information easily available to users. From accessing table notes and footnotes to aid with data interpretation, to encoding the hierarchical structure within each dimension into the data frame to allow for filtering by sub-categories.</p>
<p>We then added support to query data by vector, or table and coordinate, for targeted data retrieval. And we enhanced the ability to access and browse the list of available StatCan tables, and retrieve their metadata without downloading the table first.</p>
<p>In 2021 we added support for more permanent caching of tables in SQLite, which makes it easier and faster to work with the data, especially for slowly updating tables, while warning users if the cached SQLite table becomes stale and there is a newer version available. This means users don’t have to re-download the table between R sessions, and querying data becomes much faster with database level filtering as well as summarizing while significantly reducing the memory footprint.</p>
<p>By further enhancing access to table metadata without downloading the table first we now also enrich data queries by vector or table and coordinate with the full metadata, giving context to how the downloaded data fits into the larger data table by e.g.&nbsp;providing the full levels of each data dimension.</p>
<p>While the functionality is now quite extensive, there was one particular issue that emerged for us and others that diminished the usefulness of the package: <strong>Some tables are very large, which makes working with these tables cumbersome in several ways:</strong></p>
<ul>
<li>The basic <code>get_cansim()</code> function takes a long time to download and parse the data. It also has a fairly large memory footprint, which can be a problem for users with limited memory.</li>
<li>A good way to deal with this has been to use <code>get_cansim_sqlite()</code> to cache the data as SQLite table after downloading it. However, even while this significantly reduces the memory footprint, the initial parsing to SQLite and indexing takes even longer than accessing the data via <code>get_cansim()</code>. And the storage space taken is larger than the initial CSV file, which is less than ideal. For some StatCan tables the resulting SQLite database can exceed 20Gb or even 40Gb, and having a couple of these cached noticeably eats into the local storage space.</li>
</ul>
<section id="enter-parquet" class="level1">
<h1>Enter parquet</h1>
<p>To get around the issues of long import times and large storage requirements for caching SQLite tables, we decided to give <a href="https://parquet.apache.org/">parquet</a> a try as alternative storage format. And this works extremely well for StatCan table data. Initial parsing to parquet is very fast with radically reduced storage space, by over one order of magnitude, for very large tables even over two orders of magnitude. Via the <code>arrow</code> package and <code>dbplyr</code> integration we can query the parquet files directly with dplyr verbs in pretty much the same way we accessed the tables via SQLite. Access speed when filtering data is still quite fast, roughly comparable to SQLite. However, if data is filtered in predictable ways, e.g.&nbsp;by geography or another dimension, we can specify a partition for the parquet data along one or several dimensions and significantly reduces access times, especially for queries that filter along those dimensions, resulting in access times faster than SQLite. At the same time we also implemented <em>feather</em> as an alternative data storage type, which preforms similarly to <em>parquet</em> for initial parsing and retrieval times but takes up more storage space.</p>
<p>Adding new storage methods required some mild changes to the interface when caching data in a database via <code>get_cansim_sqlite</code>.</p>
</section>
<section id="transition-guide" class="level1">
<h1>Transition guide</h1>
<p>If you have not been making use of the sqlite capabilities of <strong>cansim</strong> in the past then nothing changed. But you should consider making use of the new database capabilities, especially when working with large tables.</p>
<p>If you have been working with the sqlite capabilities your old code will still run, but emit a deprecation warning. You should transition your code by globally renaming <code>get_cansim_sqlite</code> to <code>get_cansim_connection</code>. This will from now on use <em>parquet</em> format instead of sqlite. If you want to keep making use of <em>sqlite</em> instead, you should set the <code>format</code> parameter as follows.</p>
<p><code>get_cansim_sqlite(...)</code> –&gt; <code>get_cansim_connection(..., format="sqlite")</code></p>
<p>Everything else works exactly like before, the different storage formats are hidden within the <code>get_cansim_connection</code> function.</p>
<p>If you have a lot of older sqlite tables it might be worthwhile to remove these to preserve disk space. Previous versions of <strong>cansim</strong> had the functions <code>list_cansim_sqlite_cached_tables()</code> and <code>remove_cansim_sqlite_cached_table()</code> to list cached data and remove select tables. The functionality of these has been transitioned over to <code>list_cansim_cached_tables()</code> and <code>remove_cansim_cached_tables()</code> with identical syntax, except the addition of the <code>format</code> parameter. <code>remove_cansim_cached_tables()</code> can also remove several tables at once and accepts (filtered) output from <code>list_cansim_cached_tables()</code> as input for the <code>cansimTableNumber</code> argument as an alternative way to remove tables. For example</p>
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_cansim_cached_tables</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(dataFormat<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;">"sqlite"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remove_cansim_cached_tables</span>()</span></code></pre></div></div>
</details>
</div>
<p>will remove all cached <em>sqlite</em> tables.</p>
</section>
<section id="parquet-in-action" class="level1">
<h1>parquet in action</h1>
<p>To showcase the changes to the <strong>cansim</strong> package we choose table <a href="https://www150.statcan.gc.ca/t1/tbl1/en/tv.action?pid=4610007001">“Investment status of residential properties” (46-10-0070)</a>, the tables comes as a 254.41MB compressed archive, containing metadata and a 6.45GB CSV file. This is quite large and going by the <a href="https://www150.statcan.gc.ca/n1/tbl/csv/46100070-eng.zip">hilarious warnings</a> StatCan put on the download page it seems that StatCan is aware that the data format is less than ideal.</p>
<p>Looking at storage space taken by each format we see the dramatic reduction in storage space when using <em>parquet</em>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_cansim_cached_tables</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(cansimTableNumber<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;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(rawSize) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(cansimTableNumber,dataFormat,niceSize) </span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 3 × 3
  cansimTableNumber dataFormat niceSize
  &lt;chr&gt;             &lt;chr&gt;      &lt;chr&gt;   
1 46-10-0070        parquet    368.7 Mb
2 46-10-0070        feather    1.8 Gb  
3 46-10-0070        sqlite     11.5 Gb </code></pre>
</div>
</div>
<p>To showcase data querying we reproduce an outlier search that was quite popular back when this data table first came out, looking for metro areas or census agglomerations with the highest share of not owner-occupied condominium apartment units, termed as “investor” units in this dataset. To not be totally irresponsible we restrict ourselves to regions with at least 1000 condominium apartment units.</p>
<p>The interface to access data via these data formats is identical as demonstrated here, with the slight exception that sqlite database connections should be disconnected after use. Execution times for the queries in the first three tabs is around 500 milliseconds on our machine, execution time for the traditional call is a lot longer because data first has be downloaded and the entire dataset gets normalized before the filtering operation.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset nav-pills">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">parquet</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">feather</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-3" aria-controls="tabset-1-3" aria-selected="false" href="">sqlite</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-4" aria-controls="tabset-1-4" aria-selected="false" href="">traditional</a></li></ul>
<div class="tab-content nav-pills">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># parquet is the default format</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number"</span>),</span>
<span id="cb5-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb5-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb5-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb5-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb5-7">         REF_DATE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020"</span>,</span>
<span id="cb5-8">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO,Estimates,val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Estimates,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Number<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter out ares with few condo apartments</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percentage - investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 4 × 4
  GeoUID GEO                                     Number Percentage - investmen…¹
  &lt;chr&gt;  &lt;fct&gt;                                    &lt;dbl&gt;                    &lt;dbl&gt;
1 544    Woodstock, Census agglomeration (CA)      1705                    0.95 
2 562    Sarnia, Census agglomeration (CA)         1465                    0.869
3 555    London, Census metropolitan area (CMA)   29530                    0.864
4 556    Chatham-Kent, Census agglomeration (CA)   1225                    0.839
# ℹ abbreviated name: ¹​`Percentage - investment status`</code></pre>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"feather"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number"</span>),</span>
<span id="cb7-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb7-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb7-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb7-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb7-7">         REF_DATE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020"</span>,</span>
<span id="cb7-8">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO,Estimates,val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Estimates,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Number<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter out ares with few condo apartments</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percentage - investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 4 × 4
  GeoUID GEO                                     Number Percentage - investmen…¹
  &lt;chr&gt;  &lt;fct&gt;                                    &lt;dbl&gt;                    &lt;dbl&gt;
1 544    Woodstock, Census agglomeration (CA)      1705                    0.95 
2 562    Sarnia, Census agglomeration (CA)         1465                    0.869
3 555    London, Census metropolitan area (CMA)   29530                    0.864
4 556    Chatham-Kent, Census agglomeration (CA)   1225                    0.839
# ℹ abbreviated name: ¹​`Percentage - investment status`</code></pre>
</div>
</div>
</div>
<div id="tabset-1-3" class="tab-pane" aria-labelledby="tabset-1-3-tab">
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqlite"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number"</span>),</span>
<span id="cb9-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb9-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb9-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb9-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb9-7">         REF_DATE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020"</span>,</span>
<span id="cb9-8">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO,Estimates,val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Estimates,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Number<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter out ares with few condo apartments</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percentage - investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 4 × 4
  GeoUID GEO                                     Number Percentage - investmen…¹
  &lt;chr&gt;  &lt;fct&gt;                                    &lt;dbl&gt;                    &lt;dbl&gt;
1 544    Woodstock, Census agglomeration (CA)      1705                    0.95 
2 562    Sarnia, Census agglomeration (CA)         1465                    0.869
3 555    London, Census metropolitan area (CMA)   29530                    0.864
4 556    Chatham-Kent, Census agglomeration (CA)   1225                    0.839
# ℹ abbreviated name: ¹​`Percentage - investment status`</code></pre>
</div>
</div>
</div>
<div id="tabset-1-4" class="tab-pane" aria-labelledby="tabset-1-4-tab">
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number"</span>),</span>
<span id="cb11-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb11-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb11-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb11-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb11-7">         REF_DATE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020"</span>,</span>
<span id="cb11-8">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO,Estimates,val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Estimates,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Number<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter out ares with few condo apartments</span></span>
<span id="cb11-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percentage - investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 4 × 4
  GeoUID GEO                                     Number Percentage - investmen…¹
  &lt;chr&gt;  &lt;fct&gt;                                    &lt;dbl&gt;                    &lt;dbl&gt;
1 544    Woodstock, Census agglomeration (CA)      1705                    0.95 
2 562    Sarnia, Census agglomeration (CA)         1465                    0.869
3 555    London, Census metropolitan area (CMA)   29530                    0.864
4 556    Chatham-Kent, Census agglomeration (CA)   1225                    0.839
# ℹ abbreviated name: ¹​`Percentage - investment status`</code></pre>
</div>
</div>
</div>
</div>
</div>
<p>At this point it is probably prudent to note that this outlier search surfaced data quirks, spotlighting regions with a high number of purpose-built rental apartments that were legally structured as condominium as we have documented in detail previously. <span class="citation" data-cites="investing-in-definitions-and-framing.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023)</span> The varying shares of “investor”-owned condos is mostly a function of differences how purpose-built rental apartments are structured in different regions, not that investors identified Woodstock as a particularly good place to invest. StatCan is <a href="https://bsky.app/profile/jensvb.bsky.social/post/3l5mmhst2b62w">now explicitly acknowledging this issue</a> in their <a href="https://www150.statcan.gc.ca/n1/daily-quotidien/241003/dq241003a-eng.htm">Daily article</a> on new releases of this table, but this has had little impact on media reporting in <a href="https://www.cbc.ca/news/canada/london/london-ontario-investment-property-1.6739784">highly misleading news reporting on this</a>, even for <a href="https://www.theglobeandmail.com/business/article-investors-own-big-chunk-of-ontarios-condo-market/">artices that specifically highlighed the four regions from our outlier search</a>, none of these have seen corrections.</p>
<p>The takeaway is that when hunting for outliers there is a good chance that one simply discovers data quirks instead of a surprising real phenomenon on the ground.</p>
<p>A more useful application might be to try and understand how the share of investment condominium apartments has varied over time. For this we can utilize database level summarizing, maybe looking at the spread between maximum and minimum share over the three years of data in each region.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>),</span>
<span id="cb13-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb13-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb13-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb13-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb13-7">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb13-8">  <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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb13-9">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb13-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb13-11">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb13-12">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spread=</span>max<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>min) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(spread,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>spread) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 10 × 7
   GeoUID GEO                                     years  mean   min   max spread
   &lt;chr&gt;  &lt;chr&gt;                                   &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;  &lt;dbl&gt;
 1 210    Kentville, Census agglomeration (CA)        3  50     0   100    100  
 2 215    Truro, Census agglomeration (CA)            3  49.0  40    62.5   22.5
 3 586    Timmins, Census agglomeration (CA)          3  71.2  60.2  77.1   16.9
 4 110    Summerside, Census agglomeration (CA)       2  54.1  46.7  61.5   14.8
 5 610    Brandon, Census agglomeration (CA)          3  44.3  35.3  50     14.7
 6 310    Saint John, Census metropolitan area (…     3  34.8  29.9  42.5   12.6
 7 965    Terrace, Census agglomeration (CA)          3  72    65.5  76.9   11.4
 8 225    Cape Breton, Census agglomeration (CA)      3  26.8  22.2  33.3   11.1
 9 335    Edmundston, Census agglomeration (CA)       3  18.7  14.3  25     10.7
10 305    Moncton, Census metropolitan area (CMA)     3  22.3  16.5  26.3    9.8</code></pre>
</div>
</div>
<p>Here the entire filtering and summarizing of the data happened during the data retrieval process, these operations are fast and have a low memory footprint.</p>
</section>
<section id="query-execution-speed" class="level1">
<h1>Query execution speed</h1>
<p>To quantify the performance of <em>parquet</em> we profile this summary query. The SQLite database is indexed on the individual columns and not on column interactions, which reduces the advantage of SQLite over (unpartitioned) <em>parquet</em> compared to scenarios where we filter only on a single dimension, but in real world applications that’s rarely the case anyway. So this should give a decent benchmark of general performance.</p>
<p>To start out we compare execution speed of the above query.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">bb<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>bench<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;">mark</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">query</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">execution"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-2">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>),</span>
<span id="cb15-3">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb15-4">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb15-5">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb15-6">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb15-7">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb15-8">                <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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb15-9">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-10">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-11">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-12">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-13">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spread=</span>max<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>min) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-14">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(spread,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-15">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>spread) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-16">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>(),</span>
<span id="cb15-17">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqlite</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">query</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">execution"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqlite"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-18">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>),</span>
<span id="cb15-19">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb15-20">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb15-21">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb15-22">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb15-23">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb15-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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb15-25">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-26">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-27">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-28">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-29">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spread=</span>max<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>min) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-30">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(spread,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-31">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>spread) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-32">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iterations=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)</span>
<span id="cb15-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(bb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Query execution time comparisons"</span>,</span>
<span id="cb15-35">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Garbage</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">collection"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>On this query <em>parquet</em> performs slightly better, averaging 1.36s compared to 2.29s for <em>sqlite</em>. Similarly, for memory footprint <em>parquet</em> compares favourably with 2.62MB for <em>parquet</em> and 4.54MB for <em>sqlite</em>.</p>
<p>For large tables like this it makes sense to partition the <em>parquet</em> data, which functions somewhat like an index for SQLite. The package creates single variable indexes for SQLite by default, partitioning for <em>parquet</em> works only along a single dimension, or a combination of dimensions more similar to a multi-index in SQLite. There are a number of choices along which dimension how to partition, a fairly generic one that works for a lot of use cases would be to index by geographic region, with the understanding that we often restrict queries by region. For our particular query we are profiling we filter by only considering metro areas and census agglomerations.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">tictoc<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;">tic</span>()</span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cansim_repartition_cached_table</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_partitioning =</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;">"GeoUID"</span>)) </span>
<span id="cb16-3">duration <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tictoc<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;">toc</span>()</span></code></pre></div></div>
</details>
</div>
<p>Repartitioning for this database took 7.3 seconds, not worth it if we are only doing a couple of queries, but it has the potential to save quite a bit of time if we query data repeatedly, depending how much this speeds up queries.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">bb2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>bench<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;">mark</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">query</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">execution"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-2">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>),</span>
<span id="cb17-3">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb17-4">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb17-5">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb17-6">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb17-7">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb17-8">                <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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb17-9">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-10">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-11">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-12">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-13">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spread=</span>max<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>min) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-14">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(spread,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-15">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>spread) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-16">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>(),</span>
<span id="cb17-17">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqlite</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">query</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">execution"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_cansim_connection</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"46-10-0070"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqlite"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-18">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage - investment status"</span>),</span>
<span id="cb17-19">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period of construction</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all periods of construction"</span>,</span>
<span id="cb17-20">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Property type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condominium apartment"</span>,</span>
<span id="cb17-21">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ownership type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total, all ownership types"</span>,</span>
<span id="cb17-22">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Investment status</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Investment property"</span>,</span>
<span id="cb17-23">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only CMAs</span></span>
<span id="cb17-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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb17-25">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-26">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-27">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-28">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GeoUID,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-29">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spread=</span>max<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>min) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-30">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(spread,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-31">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>spread) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-32">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iterations=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)</span>
<span id="cb17-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(bb2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Query execution time comparisons, single level parquet partitioning"</span>,</span>
<span id="cb17-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb17-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Garbage</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">collection"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/index_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>When partitioned by geography the query time for <em>parquet</em> drops significantly averaging 342ms, easily justifying the time spent repartitioning when running the query 50 times for the profiler. Memory footprint stays essentially unchanged. The somewhat small penalty for repartitioning shrinks even further if we partition data right at import. One downside of partitioning is that it increases the storage space taken up on disk as compression is less efficient on partitioned data.</p>
</section>
<section id="other-changes" class="level1">
<h1>Other changes</h1>
<p>Other changes in the new version include a more principled approach to column order. Column order is more standardized and also carries across querying data by vector or coordinate. This might cause some short-term disruptions if people have been relying on the particular column order, but makes things more consistent in the long run. In particular, data queried in different ways looks identical, although the row order might differ and has to be set manually if people rely on row order.</p>
<p>We also started to implement more systematic unit testing to ensure more stable ongoing package development. And the package also got some speed boost in various places and more robust data handling under the hood. In short <strong>cansim</strong> got better, and the new <em>parquet</em> option makes for a much better way to work with large tables by speeding up data import, dramatically reducing the storage requirements, and reducing the memory footprint.</p>
</section>
<section id="upshot" class="level1">
<h1>Upshot</h1>
<p>For people who have exclusively relied on <code>get_cansim</code> I recommend transitioning some uses over to <code>get_cansim_connection()</code>, possibly setting the <code>refresh="auto"</code> option to ensure they are always working with the latest data. From a coding perspective the cost is the additional <code>collect_and_normalize()</code> call, but the speedup when filtering before collecting is well worth it.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-02-23-cansim-revamp/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb18-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-02-23 20:40:01 PST"</code></pre>
</div>
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb20-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [bd04212] 2025-02-24: text tweaks</code></pre>
</div>
<details open="" class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb22-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.3.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bench_1.1.4     cansim_0.4      lubridate_1.9.4 forcats_1.0.0  
 [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.4     readr_2.1.5    
 [9] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] bit_4.5.0.1               gtable_0.3.6             
 [3] jsonlite_1.8.9            compiler_4.4.2           
 [5] tidyselect_1.2.1          git2r_0.33.0             
 [7] assertthat_0.2.1          arrow_18.1.0.1           
 [9] scales_1.3.0              yaml_2.3.10              
[11] fastmap_1.2.0             R6_2.6.1                 
[13] generics_0.1.3            knitr_1.48               
[15] htmlwidgets_1.6.4         munsell_0.5.1            
[17] pillar_1.10.1             tzdb_0.4.0               
[19] rlang_1.1.5               stringi_1.8.4            
[21] xfun_0.50                 bit64_4.6.0-1            
[23] timechange_0.3.0          cli_3.6.4                
[25] withr_3.0.2               magrittr_2.0.3           
[27] mountainmathHelpers_0.1.4 digest_0.6.37            
[29] grid_4.4.2                rstudioapi_0.16.0        
[31] hms_1.1.3                 lifecycle_1.0.4          
[33] vctrs_0.6.5               evaluate_1.0.3           
[35] glue_1.8.0                colorspace_2.1-1         
[37] rmarkdown_2.28            tools_4.4.2              
[39] pkgconfig_2.0.3           htmltools_0.5.8.1        </code></pre>
</div>
</div>
</details>



</section>

<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-investing-in-definitions-and-framing.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Investing in Definitions and Framing</em>. <a href="https://doodles.mountainmath.ca/posts/2023-02-20-investing-in-definitions-and-framing/">https://doodles.mountainmath.ca/posts/2023-02-20-investing-in-definitions-and-framing/</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{cansim-revamp.2025,
  author = {{von Bergmann}, Jens},
  title = {Cansim Revamp},
  date = {2025-02-23},
  url = {https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann. 2025. <span>“Cansim Revamp.”</span>
<em>MountainDoodles</em>, accepted, February 23. <a href="https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/">https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/</a>.
</div></div></section></div> ]]></description>
  <category>cansim</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-02-23-cansim-revamp/</guid>
  <pubDate>Sun, 23 Feb 2025 08:00:00 GMT</pubDate>
  <media:content url="https://raw.githubusercontent.com/mountainMath/cansim/master/images/cansim-sticker.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Homelessness and Rents in Canada</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2025/01/16/homelessness-and-rents-in-canada/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cancensus)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(canpumf)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cansim)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rvest)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)</span>
<span id="cb1-8">extrafont<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;">loadfonts</span>()</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R/census_import.R"</span>))</span>
<span id="cb1-10"></span>
<span id="cb1-11">child_ages <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;">"0 to 4 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 to 9 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 to 14 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>)</span>
<span id="cb1-12">year_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>trios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c157,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011</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;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>())</span>
<span id="cb1-13"></span>
<span id="cb1-14">highlight_metros <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;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Victoria"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Calgary"</span>,</span>
<span id="cb1-15">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toronto"</span>)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">homelessness_data_manual <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>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/Shared_PIT_Homeless_Count_CMA_Revised.csv"</span>),</span>
<span id="cb2-2">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cols</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.default=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Name,</span>
<span id="cb2-4">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna-Abbotsford-Mission"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna – Abbotsford-Mission"</span>,</span>
<span id="cb2-5">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina-Saskatoon"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regina – Saskatoon"</span>,</span>
<span id="cb2-6">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brantford-Guelph-Barrie"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brantford – Guelph – Barrie"</span>,</span>
<span id="cb2-7">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury-Thunder Bay"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury – Thunder Bay"</span>,</span>
<span id="cb2-8">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kingston-Peterborough"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kingston – Peterborough"</span>,</span>
<span id="cb2-9">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kitchener-Cambridge-Waterloo"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kitchener – Cambridge – Waterloo"</span>,</span>
<span id="cb2-10">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moncton-Saint John"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moncton – Saint John"</span>,</span>
<span id="cb2-11">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montreal"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>,</span>
<span id="cb2-12">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa-Gatineau"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>,</span>
<span id="cb2-13">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec City"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Québec"</span>,</span>
<span id="cb2-14">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sherbrooke-Trois-Rivieres"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sherbrooke – Trois-Rivières"</span>,</span>
<span id="cb2-15">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"St. Catherines-Niagara"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"St. Catharines – Niagara"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Name,Likely_Count_Geography,Notes,</span>
<span id="cb2-17">                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^Year"</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count_Source"</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pop_Source"</span>)),as.numeric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(Name,Absolute_Rate_Likely_Geography)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_source=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Absolute_Rate_CMA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>Absolute_Rate_Likely_Geography,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CSD"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA_pop2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Likely_Count_Geography<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;">"Region"</span>,Region_pop,CMA_pop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Population=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(pop_source<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;">"CMA"</span>,CMA_pop2,CSD_pop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">single_cma=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" – "</span>,Name)<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;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa"</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PIT_rate=</span>Absolute<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Population<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;">1000</span>)</span>
<span id="cb2-24"></span>
<span id="cb2-25"></span>
<span id="cb2-26"></span>
<span id="cb2-27"></span>
<span id="cb2-28">pumf_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;">get_harmonized_pumf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(year_colours))  </span>
<span id="cb2-29"></span>
<span id="cb2-30">cpi <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;">simpleCache</span>(cansim<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;">get_cansim_vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v41690973"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m"</span>)<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;">"05"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CPI=</span>val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CPI=</span>CPI<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;">last</span>(CPI,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year)),</span>
<span id="cb2-36">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cpi_series.Rda"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path=</span>here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>))</span>
<span id="cb2-37"></span>
<span id="cb2-38">mover_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 bedroom"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 bedrooms"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-41">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb2-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-movers"</span> ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(SUBSIDY<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;">"Subsidized"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(cpi,<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>GROSRT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-47">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(real_rent&gt;400) |&gt;</span></span>
<span id="cb2-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb2-49">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,BEDRM<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;">"1 bedroom"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-51">                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,m) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(m) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA)))</span>
<span id="cb2-52"></span>
<span id="cb2-53">all_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-54">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 bedroom"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 bedrooms"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-56">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb2-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-58">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(!(MOB1 %in% c("Non-movers" ,"Not applicable", "Not available"))) |&gt;</span></span>
<span id="cb2-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(SUBSIDY<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;">"Subsidized"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(cpi,<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>GROSRT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-62">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(real_rent&gt;400) |&gt;</span></span>
<span id="cb2-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb2-64">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,BEDRM<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;">"1 bedroom"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-66">                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,m) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(m) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA)))</span>
<span id="cb2-67"></span>
<span id="cb2-68"></span>
<span id="cb2-69">rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-71">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 bedroom"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 bedrooms"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-72">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb2-73">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-movers"</span> ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(SUBSIDY<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;">"Subsidized"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-76">  <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;">rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(spatstat.univar<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;">weighted.quantile</span>(GROSRT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,</span>
<span id="cb2-77">                                                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-78">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cases=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb2-79">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-80">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest_longer</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">indices_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"quantile"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-81">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(cpi,<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-82">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>rent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI) </span>
<span id="cb2-83"></span>
<span id="cb2-84">d1_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>,quantile<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;">"10%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-85">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,Year,real_rent) </span>
<span id="cb2-86">q1_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>,quantile<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;">"25%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,Year,real_rent) </span>
<span id="cb2-88">m_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>,quantile<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;">"50%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-89">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,Year,real_rent) </span></code></pre></div></div>
</details>
</div>
<p>Evidence suggests a clear correlation between rents and rates of homelessness in the USA. The simplest interpretation is that housing shortages drive rents higher and leave more people falling through the cracks of our systems for distributing housing. That is, <a href="https://homelessnesshousingproblem.com/">homelessness is a housing problem</a>.</p>
<p>Do we also see this relationship in Canada? And if so, just how does it work?</p>
<p>Here we’ll attempt to pull together some Canadian data to address the first question and also look into the second.</p>
<p>Speaking to the second question, we think there are lots of mechanisms by which the relationship works, but we’re motivated in part by a recent piece by Salim Furth wrote titled <a href="https://worksinprogress.co/issue/why-housing-shortages-cause-homelessness/"><em>Why housing shortages cause homelessness</em> for <em>Works in Progress</em></a>. We think this piece offers a potentially useful addition to current housing debates, thinking through a particular mechanism linking shortage of spare bedrooms to homelessness. Adding to our repertoire of explanatory mechanisms is great. But we also think Furth is too quick to foreclose on alternative mechanisms (including the simplest) and we have a few other quibbles with the details that we think are worth laying out in an effort to further discussion of mechanisms.</p>
<section id="canadian-homeless-count-data" class="level1">
<h1>Canadian Homeless Count Data</h1>
<p>Our first step is to pull some Canadian data on homeless counts.</p>
<p>Canadian Point-in-Time (PIT) Homeless Count data has been growing in volume and become increasingly standardized in recent years, and StatCan and <a href="https://housing-infrastructure.canada.ca/homelessness-sans-abri/resources-ressources/point-in-time-denombrement-ponctuel-eng.html">Infrastrucure Canada</a> are actively working toward improvement. The <a href="https://homelesshub.ca/community_profile/calgary/">Homeless Hub</a> has attempted to collect recent PIT homeless counts for communities profiled across the country. We started our analysis by scraping recent count data from this source. Unfortunately the geographies don’t quite match the ones we want to work with, but some other problems also quickly emerged from our exploration of count data. Closer investigation, starting with a comparison of Victoria and Vancouver results, revealed some big differences in PIT count procedures and resourcing between locations. Through a subsequent survey of homeless counts, we found challenges to comparability were widespread. Also issues with geographic matching and outdated data remain. Overall the Homeless Hub data provides a good starting point, but we found in necessary to dive into the PIT homeless count reports directly to establish more comparable estimates.</p>
<p>What we want to establish are 1) PIT counts derived from common definitions, 2) applied to correct geographic denominators for establishing risk, but reflective of extracted CMA geographies, 3) updated to be as recent as possible. From here on out we limited ourselves to counts from 2020 or beyond (see <span class="citation" data-cites="kneebone2021local">Kneebone and Wilkins (2021)</span> for investigation into limited access 2018 count data). We provide a dataset in CSV form of our count data broken down by category <a href="../../data/Shared_PIT_Homeless_count_CMA_Revised.csv">here</a>, with links to sources for each count and for underlying population paired to count geographies and matched to years as best we can figure out. Here we roughly match geographies of counts to Census CMAs, often joined together as extractable from PUMF data (e.g.&nbsp;Kelowna - Abbotsford-Mission), while attempting to preserve the integrity of underlying populations subject to count attempts for denominators. Where possible we looked to expand counts from cities to broader metropolitan areas, but we note imperfect division into metros within the PUMF data and imperfect mapping of geographies between homeless counts and CMAs (for instance, Oshawa here actually represents results from Durham County). We’ve attempted to minimize these issues in our matching, with instructions included in the file linked above, but uncertainties remain.</p>
<p>Returning to our first issue, authorities administering PIT counts employ different methodologies to count and tally up various categories of homelessness. In particular, those temporarily housed (e.g.&nbsp;in various kinds of transitional housing, sometimes including hotels), within institutional settings (e.g.&nbsp;hospitals and jails), and those with no-fixed-address (e.g.&nbsp;couch-surfing) are often defined and tabulated differently within different homeless counts, and in many cases not tabulated at all. These categories are also often (though not always) considered “provisionally housed” in order to distinguish them from the “absolute homelessness” of people spending the night in homeless shelters (usually including domestic violence shelters), or without shelter (in public, within encampments or vehicles not meant for permanent shelter). Diving into tabulations directly, Figure&nbsp;1 pulls out distinct categories to illustrate the differences between counts in who gets counted.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">homlessness_categories <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;">"Unsheltered"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sheltered"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couch_surfing"</span>,</span>
<span id="cb3-2">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Public_system"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Transitional"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Unknown"</span>)</span>
<span id="cb3-3">homlessness_category_colours <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;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Egypt"</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;">"darkgrey"</span>),</span>
<span id="cb3-4">                                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,homlessness_categories))</span>
<span id="cb3-5">homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(homlessness_categories),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"category"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,category)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(category,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,homlessness_categories))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PIT_rate=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Population<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(category))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>homlessness_category_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homeless counts per 1,000 residents"</span>,</span>
<span id="cb3-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT counts per 1,000 residents"</span>,</span>
<span id="cb3-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro area"</span>,</span>
<span id="cb3-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Category"</span>,</span>
<span id="cb3-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-pit-overview" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pit-overview-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-pit-overview-1.png" id="fig-pit-overview" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-pit-overview-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>By comparing categories of counts, we can see that some jurisdictions just count a lot more people as homeless. Reading through the Capital Region of Victoria’s homeless count methods, for instance, reveals a very inclusive definition applied to provisionally housed categories, at its broadest including people as homeless if they don’t have stable housing arranged for the next three years. Other counts use much narrower time frames, ranging from 30 days to one year, or don’t include provisionally housed categories (e.g.&nbsp;transitional, public system, and couch surfing) at all. Various inclusion of people as homeless when their location during the count remained unknown represents a further difficulty.</p>
<p>In order to ensure counts are comparable, we can strip out the provisional categories where people are often counted differently and compare just the absolute categories, where methods tend to be similar (see also <span class="citation" data-cites="kneebone2021local">Kneebone and Wilkins (2021)</span>). It’s important to remember this is simply a choice we’re making for comparability purposes - we’re not attempting to redefine who should count here - and in all cases, PIT counts are broadly recognized as undercounts. One useful way of thinking about this approach is that common methods to count unsheltered and sheltered groups likely undercount in a similar fashion. Using this as a base both enables comparison and allows the potential to predict what results of different metros might look like if they adopted similar count standards. For instance, insofar as differences in methods drive much of the variation, one could attempt to use absolute homelessness tabulations to predict what counts across Canada would look like if everyone employed Victoria’s relatively inclusive procedures. For our purposes here, focusing in on “unsheltered” and “sheltered” populations but excluding provisional categories provides us comparable results as shown in Figure&nbsp;2.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(homlessness_categories),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"category"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,category)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(category <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Unsheltered"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sheltered"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(category,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,homlessness_categories))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PIT_rate=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Population<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;">1000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(category))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>homlessness_category_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tittle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manually adjusted homlessness rate"</span>,</span>
<span id="cb4-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro area"</span>,</span>
<span id="cb4-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Category"</span>,</span>
<span id="cb4-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT counts (unsheltered and sheltered) per 1,000 residents"</span>,</span>
<span id="cb4-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-homelessness-rate-best-guess" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-homelessness-rate-best-guess-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homelessness-rate-best-guess-1.png" id="fig-homelessness-rate-best-guess" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-homelessness-rate-best-guess-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>Of note, while we stick to recent (2020 onward) counts, we recognize the dramatic changes on the ground in terms of Covid contexts and policies. In particular, most Ontario counts took place in 2021, often during acute phases of the epidemic. Other counts mostly occurred later (except for the Kelowna portion of the joint Kelowna - Abbotsford CMA below), for example through Quebec’s provincial counts in 2022. Counts were also carried out at different times of the year, making comparisons between sheltered and unsheltered populations especially unstable. In other words, even our efforts at carefully establishing comparable counts remain subject to lots of caveats.</p>
</section>
<section id="the-correlation-between-rents-and-homelessness-in-canada" class="level1">
<h1>The correlation between rents and homelessness in Canada</h1>
<p>Once we have more comparable PIT counts, we can return to our starting questions. We see a strong correlation between rents and homelessness in the USA. Do we see a similarly strong correlation in Canada? To get comparable rents, we pull data from the 2021 Census. Because housing stock varies broadly across regions (more on this below) we focus on 1BR rents for consistent comparability. We also recognize that rents for all tenants reported in the Census are often misleading concerning the housing stock actually available for rent. Policies like rent control can really favour long-term renters maintaining existing contracts, and the rents they pay are often far below current market rents. So here we focus on turnover rents. That is, what is the median rent charged for those moving into a 1BR dwelling within the last year? And how does it relate to PIT homeless count rates? The result is shown in Figure&nbsp;3.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">pd0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) ,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>))</span>
<span id="cb5-3"></span>
<span id="cb5-4">bedrooms <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(pd0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BEDRM) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>()</span>
<span id="cb5-5">  </span>
<span id="cb5-6">quantiles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(pd0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>quantile) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>()</span>
<span id="cb5-7"></span>
<span id="cb5-8">d<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>quantiles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(q){</span>
<span id="cb5-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> real_rent,</span>
<span id="cb5-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>,quantile<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>q))</span>
<span id="cb5-12">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(quantiles)</span>
<span id="cb5-14"></span>
<span id="cb5-15">r2 <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>(d,\(m)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()</span>
<span id="cb5-16">r2_labels <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;">names</span>(r2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(n)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"th percentile rent"</span>,n),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (R² = "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(r2[n],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(r2))</span>
<span id="cb5-20"></span>
<span id="cb5-21">pd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"50%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-25">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-26">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>Name),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb5-27">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb5-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness rates vs prevailing median rents (R² = "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(r2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50%"</span>],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>),</span>
<span id="cb5-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021 median 1-bedroom rents of recent movers (1 year)"</span>,</span>
<span id="cb5-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT counts (unsheltered and sheltered) per 1,000 residents"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rent-homelessness-canada" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rent-homelessness-canada-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-rent-homelessness-canada-1.png" id="fig-rent-homelessness-canada" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-rent-homelessness-canada-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>As noted above, many of Canada’s smaller metropolitan areas are combined in the PUMF release we’re using for rents, even when they’re not near one another. This creates potential comparability issues which can cause problems when examining the joint rent distribution, as well as combining homelessness counts. Sure enough, we note that combined metros are often outliers in the figure above. In Figure&nbsp;4 we exclude multiple-CMA regions from the regression, which shrinks the sample even further but yields a better fit, suggesting an even stronger relationship between rent and PIT count homelessness rates.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">fit_single <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>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> real_rent,</span>
<span id="cb6-2">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>,quantile<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;">"50%"</span>,single_cma))</span>
<span id="cb6-3">r2_single <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;">summary</span>(fit_single)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared</span>
<span id="cb6-4"></span>
<span id="cb6-5">pd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"50%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-9">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-10">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>Name),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb6-11">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple CMA"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness rates vs prevailing median rents (R² = "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(r2_single,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>),</span>
<span id="cb6-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021 median 1-bedroom rents of recent movers (1 year)"</span>,</span>
<span id="cb6-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT counts (unsheltered and sheltered) per 1,000 residents"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rent-homelessness-canada_single" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rent-homelessness-canada_single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-rent-homelessness-canada_single-1.png" id="fig-rent-homelessness-canada_single" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-rent-homelessness-canada_single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>Overall, we see a pretty strong correlation, similar to that found in the USA. This also roughly matches <span class="citation" data-cites="kneebone2021local">Kneebone and Wilkins (2021)</span> findings from 2018 matching rents to counts. There’s still a lot of unexplained variation. But the figure emphasizes interconnection between how the housing system operates in terms of rental markets and the prevalence of homelessness. That interconnectedness is, itself, an important takeaway: housing is a system! Overall, the simplest interpretation is that housing shortages drive high rents, which in turn exclude more people from being able to afford housing, producing more homelessness. Correspondingly, adding more housing could reduce rents and significantly reduce homelessness.</p>
<p>But is this right? And if so, just how does it work? We have a correlation, so let’s dive into mechanisms.</p>
</section>
<section id="how-does-it-work" class="level1">
<h1>How does it work?</h1>
<p>Furth’s piece is helpful in trying think through the mechanisms behind the rent and homelessness relationship. His article tries to bridge two well-known stylized facts:</p>
<ol type="1">
<li>Metro area level homelessness rates correlate with prevailing rent levels.</li>
<li>Many low-income adults can’t afford median rents, even in low-rent cities that have low rates of homelessness.</li>
</ol>
<p>The first fact links rents to homelessness, and suggests that building more (market) housing to lower rents should alleviate homelessness. The second fact calls this mechanism into question since many low-income people won’t be able to afford median rents even in low-rent cities, so lowering rents won’t reach those most in danger of becoming homeless.</p>
<p>To resolve this disconnect Furth points us toward considering doubled-up living arrangements. Furth writes:</p>
<blockquote class="blockquote">
<p>Housing costs and individual risk factors both matter – and the puzzle piece that links them is the role of family and friends. When housing is cheap, relatives and friends tend to have more space in their homes, enabling them to keep someone at risk of homelessness off the street and on their medications. When space is tight, the people forced out are those who are hardest to live with.</p>
</blockquote>
<p>Compellingly, Furth also dives into examples.</p>
<blockquote class="blockquote">
<p>Unlike Diona’s mom, Sherman’s parents had extra space. That’s very common among homeowning, empty-nest parents, meaning that a great deal of vacant housing is in the hands of the two people who are most likely to love and forgive an adult child in dire circumstances. But in more expensive regions, fewer parents (or other loving figures) have that resource, either because they couldn’t afford to buy a house in the first place or because there are demands from multiple family members to share the legacy residence.</p>
</blockquote>
<p>We think these observations are useful, and calling attention to how relationships matter to housing outcomes is well worthwhile (one of us is a sociologist, after all). But we believe this interpretation tends to be overstated, and requires some additional nuance to fully understand. Here, as we’ll explain, diving into Canadian data can actually help.</p>
</section>
<section id="rent-distribution" class="level1">
<h1>Rent distribution</h1>
<p>Among things worth pushing back on, it’s worth remembering that medians are just summaries for underlying distributions of rents. Median rents are imperfect stand-ins for the availability of low-end housing, but they can still indicate such availability, both in market and non-market forms.</p>
<p>We can get a fuller glimpse at how well median rents do by displaying them alongside upper and lower quartiles (bounding the yellow boxes) and top and bottom decile range (here represented as whiskers) for larger metro areas in Canada, as in Figure&nbsp;5 below. Note we also subdivide into 1BR and 2BR rentals, and exclude dedicated non-market or otherwise subsidized housing (we will return to this portion of systems for housing distribution later). Crucially we also distinguish between turnover rents available for recent movers (in past year) and all non-subsidized rents. On the left, the low end of the distribution of turnover rents offers probably the best estimate of what kind of market housing is generally available for those with low incomes. But on the right, the distribution of all rents can still be useful for understanding the situations current renters face.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">rent_dist_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;">bind_rows</span>(</span>
<span id="cb7-2">  mover_rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Recent (1 year) movers"</span>),</span>
<span id="cb7-3">  all_rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All non-subsidized"</span>),</span>
<span id="cb7-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(sample, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Recent (1 year) movers"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All non-subsidized"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <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;">y10=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)),</span>
<span id="cb7-8">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y25=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>)),</span>
<span id="cb7-9">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y50=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)),</span>
<span id="cb7-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y75=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)),</span>
<span id="cb7-11">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y90=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>)),</span>
<span id="cb7-12">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,sample,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,BEDRM<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;">"1 bedroom"</span>,sample<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;">"Recent (1 year) movers"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,y50) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(y50) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA)))</span>
<span id="cb7-14"></span>
<span id="cb7-15">rent_dist_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin=</span>y10,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower=</span>y25,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">middle=</span>y50,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper=</span>y75,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax=</span>y90)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gold"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_fill_manual(values=c("All non-subsidized"="azure","Recent (1 year) movers"="gold")) +</span></span>
<span id="cb7-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gold"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(BEDRM<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>sample) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-25">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># scale_x_continuous(labels=\(x)scales::dollar(x,scale=10^-3,suffix="k",accuracy=0.1),</span></span>
<span id="cb7-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                    trans="log", breaks=c(500,1000,1500,2500)) +</span></span>
<span id="cb7-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rent distributions in non-subsidized housing in Canadian CMAs"</span>,</span>
<span id="cb7-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rent in non-subsidized housing"</span>,</span>
<span id="cb7-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample"</span>,</span>
<span id="cb7-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb7-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011-2016 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rent-distribution1" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rent-distribution1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-rent-distribution1-1.png" id="fig-rent-distribution1" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-rent-distribution1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can see by the ordering of metros that median rents don’t fully capture what’s going on in the bottom quartile of the housing market, much less the lowest rents on offer (which also captures varying degrees of non-arms length rentals). For instance, Victoria’s 1-bedroom rents at the lowest decile are above Vancouver’s, and at the 25th percentile are relatively near to Vancouver’s, despite Victoria having median rents far below Vancouver’s. Furth is right that it’s these lower rents that really matter and we can do better to measure them directly instead of relying upon medians. Still, overall median rents generally do ok at predicting these lower rents, and it’s an error to dismiss their predictive power on the basis of their unaffordability to the poor.<sup>1</sup></p>
<p>We can also see that turnover rents at the lowest decile of the market are indeed generally lower than overall median rents, making them more affordable to those with very low incomes, but they are still relatively well predicted by median rents. We highlight this in Figure&nbsp;6, where we plot lower decile rents rents of recently available units against median overall rents.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb8-2">  all_rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-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;">value=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median non-subsidized"</span>),</span>
<span id="cb8-5">  mover_rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-6">    <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;">value=</span>spatstat.univar<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;">weighted.quantile</span>(real_rent,WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower decile recent (1 year) movers"</span>),</span>
<span id="cb8-8">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>sample,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median non-subsidized</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lower decile recent (1 year) movers</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-12">  <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="cb8-13">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rent distributions in non-subsidized housing in Canadian CMAs"</span>,</span>
<span id="cb8-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median non-subsidized real rent (2021 dollars)"</span>,</span>
<span id="cb8-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower decile recent (1 year) movers non-subsidized real rent"</span>,</span>
<span id="cb8-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011-2016 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rents-med-vs-lower-decidle" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rents-med-vs-lower-decidle-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-rents-med-vs-lower-decidle-1.png" id="fig-rents-med-vs-lower-decidle" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-rents-med-vs-lower-decidle-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
</div>
</div>
<p>Of note, rents at the lower end of the market generally reflect some combination of poorer quality, rent controlled, and worse located housing. But there are also lots of intermediate forms of ‘non-arm’s length’ rentals that fit pretty well in Furth’s “people don’t become homeless when they run out of money, they become homeless when they run out of relationships” framing. The share of households moving into non-arms length rentals varies across metro areas, in Metro Vancouver it seems to be around 10%. <span class="citation" data-cites="tumbling-turnover.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022)</span></p>
<p>Non-arm’s length rents can still be related to prevailing market rents. For instance, in cheaper markets, the landlord of an apartment that might otherwise filter out of the housing stock altogether, for instance because of its low quality, might more readily be persuaded to provide it to a friend or acquaintance at extremely low rent instead. On the flip side, those without access to extra housing units to rent out below market rates can and do at times provide cash transfers to help friends and family access market housing. Such help can also assist those with low incomes afford market housing, even if paying prevailing rents remains beyond their own incomes. In other words, and for lots of reasons, it is not necessarily the case that Furth’s point 2 challenges his point 1.</p>
<p>To further emphasize this objection, in Figure&nbsp;7 we plot PIT homelessness rates against prevailing metro area rents, taken at various percentiles, comparing median rents to those at the bottom 25th percentile and the bottom 10th percentile. We continue to focus on the single-CMA regions to understand the relationship.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"1 bedroom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10%"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25%"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50%"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,PIT_rate,single_cma),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate)) </span>
<span id="cb9-7"></span>
<span id="cb9-8">quantiles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>quantile <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>()</span>
<span id="cb9-11"></span>
<span id="cb9-12">pit.fits <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> quantiles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(q)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(single_cma,quantile<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>q,))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(quantiles)</span>
<span id="cb9-15">  </span>
<span id="cb9-16">r2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pit.fits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(x)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</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;">|&gt;</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enframe</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</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;">value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R2"</span>)</span>
<span id="cb9-21"></span>
<span id="cb9-22">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(r2,<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;">"quantile"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowwise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"th percentile rents"</span>,quantile),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (R² = "</span>,R2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-28">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb9-29">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb9-32">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb9-33">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple CMA"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>q,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs rents"</span>,</span>
<span id="cb9-39">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-subsidized 1 bedroom rent of recent (1 year) movers"</span>,</span>
<span id="cb9-40">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb9-41">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb9-42">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb9-43">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-homelessness-rents" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-homelessness-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homelessness-rents-1.png" id="fig-homelessness-rents" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-homelessness-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7
</figcaption>
</figure>
</div>
</div>
</div>
<p>Without trying to over-interpret inherently messy data, we note that the relationship becomes stronger if we focus on the lower end of the rent spectrum. This fits with our expectations that the lower end is what really matters. At the same time, the difference between what’s happening at the low end and at the median isn’t all that big and the relationship to homelessness doesn’t shift much. Medians do a decent job of capturing distributions, even if they’re not perfect.</p>
<p>Broadening the view to take into account the whole distribution of rents can go a long way to explaining how lowering market rents can help people stay housed. And acknowledging that people often double up, pooling low incomes to make things work, further narrows the gap between people’s incomes and rents at the lower end of the market. <span class="citation" data-cites="distributional-effects-of-adding-housing.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024)</span></p>
</section>
<section id="relationships-are-complex" class="level1">
<h1>Relationships are complex</h1>
<p>To offer another critique, Furth’s examples also tend to draw upon a beneficent view of relationships. This follows a larger trend in social sciences to think of relationships mostly in terms of their usefulness, e.g.&nbsp;as social capital. But as most people quickly grasp, relationships can also be toxic (see, e.g.&nbsp;<a href="https://www.youtube.com/watch?v=LOZuxwVk7TU">Britney Spears 2003</a> and <a href="https://www.nytimes.com/2024/04/26/arts/music/britney-spears-jamie-spears-legal-fees-conservatorship.html">since</a>). That is, it’s often the relationships themselves that drive people out of shared living situations. This can be witnessed within the homeless count data itself, where surveys often ask people the reason they became homeless. Where tabulated, the top 5 reasons for homelessness always include high rents and low incomes, providing further support for the idea that market rents matter in a direct way. But conflict with family members is also a top reason people provide for why they became homeless, as e.g.&nbsp;in <a href="https://downtownhalifax.ca/sites/default/files/2022-10/2022%20Point-in-Time%20Count%20_FINAL.pdf#page=12">Halifax</a>, <a href="https://homelesshub.ca/wp-content/uploads/2024/04/COF_PiT_Report_2020_R7.pdf#page=5">Kelowna</a>, <a href="https://flowcommunityprojects.ca/wp-content/uploads/2022/04/Regina-Point-in-Time-Count-2021-Electronic-Copy.pdf#page=91">Regina</a>, <a href="https://pub-niagararegion.escribemeetings.com/filestream.ashx?DocumentId=16848#page=11">The Niagara Region</a>, <a href="https://hsa-bc.ca/_Library/2023_HC/2023_Homeless_Count_for_Greater_Vancouver.pdf#page=43">Vancouver</a>, <a href="https://www.crd.bc.ca/docs/default-source/housing-pdf/housing-planning-and-programs/2023-point-in-time-count-report.pdf#page=21">Victoria</a>, <a href="https://endhomelessnesswinnipeg.ca/wp-content/uploads/2022-Winnipeg-Street-Census-Final-Report.pdf#page=14">Winnipeg</a>, and <a href="https://www.msss.gouv.qc.ca/inc/documents/ministere/salle-de-presse/Fiche_technique_Resultats_denombrement_2022_23-09-01_VF.pdf#page=4">across Quebec</a>.</p>
<p>This rubs against Furth’s view of familial relationships as generally beneficial, as if it’s only the lack of bedrooms that might prevent parents and children (or former partners) from remaining together. It’s not much considered, for instance, how factors aside from space might be influencing Diona’s eviction from her mother’s home. More broadly, family trauma is often behind a variety of the reasons people become homeless. A bedroom door provides only a limited degree of privacy within a household riven by conflict. People still have to live with one another. In many and perhaps most cases, the presence of extra bedrooms makes little difference.</p>
</section>
<section id="bedrooms-are-not-actually-housing" class="level1">
<h1>Bedrooms are not actually housing</h1>
<p>Because bedroom doors provide only a very limited degree of privacy, an extra bedroom door does not equate to housing. Instead it equates to membership within an existing household. Furth blurs this distinction when conceptualizing spare bedrooms as “decommodified housing.” Decommodified housing generally refers to housing traded or allocated through other-than-market mechanisms. <span class="citation" data-cites="commodity-and-keeping-it-in-the-family.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021)</span> Offering up a spare bedroom to someone involves the sharing of private space, and is treated differently as an aspect of daily living as well as in law. For instance, zoning regulations often closely patrol the placement of doors and possibilities for household members to split up a residence into multiple separate residences. Through their daily living routines, people joined as part of a household generally impose the burden of relationships upon one another and the corresponding possibilities for toxicity. More broadly, household membership challenges assumptions about independence, and this matters.</p>
<p>Of note, the distinction between bedrooms and housing has also been recognized in how we think about homelessness, with people in shelters, even if provided individual sleeping rooms, being counted as homeless. Similarly, people moving between households of others (as with Diona) are often termed “couch-surfers” and considered as experiencing another type of homelessness (and one that’s especially difficult for point-in-time homeless counts to catch). In valorizing spare bedrooms, it may be Furth is simply drawing too sharp a distinction between couch-surfers provided a temporary bedroom and those literally given a couch. Of note, such distinctions also show up in the Census, where people provided only a room of their own in a stable institutional setting are understood as living in collective households rather than private households. In short, we can think of privacy as joining stability as a key element of housing. It’s not clear Furth makes this distinction.</p>
</section>
<section id="confounders" class="level1">
<h1>Confounders</h1>
<p>We can get much deeper into the weeds by thinking about Furth’s mechanism in terms of causal analysis. Furth positions empty bedrooms as open to sharing (or as we often think of it, doubling up). He envisions the causal structure as:</p>
<!--
"high rents" -> "few spare bedrooms" -> "more homelessness"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>where the first mechanism is theorized as high rents inducing people to “right-size” housing, leaving few spare bedrooms, and the second is thought of as few spare bedrooms generating fewer opportunities and more friction for family and friends to offer informal housing (or, more accurately, household membership) to otherwise (potentially) homeless people.</p>
<p>While this particular chain of mechanisms is intriguing, a broader view should also consider potential confounding relationships likely to bias any observed relationship we see between the variables above. We consider a few of these below.</p>
</section>
<section id="low-opportunity" class="level1">
<h1>Low opportunity</h1>
<p>Flipping the causal chain around, Furth also makes the argument that:</p>
<!--
"low rents" -> "more spare bedrooms" -> "less homelessness, conditional on being poor"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>To get there, Furth finds the housed poor through IPUMS Census data, and sees they are overrepresented in cities with low rents. He then re-weights them to match the demographic characteristics of the homeless population, roughly following methods and findings he derives from an <a href="https://www.nber.org/system/files/working_papers/w32323/w32323.pdf">NBER study</a> using administrative data. The re-weighted sample appears to offer a counterfactual (what would happen if poor people in high rent cities were instead located in low rent cities?) that even more strongly supports the claim that low rents are linked to less homelessness, conditional on being poor.</p>
<p>While this is interesting, conditioning on being poor raises some potential problems in terms of selection. In particular, rents are set by both supply and demand, and low demand stemming from low economic opportunity is often the story behind low rents. What else does low economic opportunity likely create? More poor people. And crucially, the poor created by low economic opportunity are selected for differently than in places with high economic opportunity.</p>
<!--
"more (and different) poor people" <- "low economic opportunity" -> "low rents"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>This potentially confounds any observation of the relationship between low rents and the risk of homelessness given being poor. That is, it’s not necessarily the case that housed poor people would be unhoused poor people in a place with higher costs, challenging Furth’s counterfactual. It could instead be that housed poor people would be housed people with higher incomes in a place with better opportunities.</p>
<p>This confounding also comes up in the graphs showing the share of the population that is single, housed, and poor among working age adults, and contrasting this against rents. Generally, the share of the working age population that is single and housed does not vary much across metro areas, the main variation in the graph comes from the variation in prevalence of poverty. So really, it’s not a statement about housing but mostly just (anti-) correlating prevailing rents with regional poverty levels.</p>
<p>The confounding can also extend to bedroom figures. Low economic opportunity can also generate out-migration, especially of motivated young adults. As young adults leave, they generate more empty bedrooms, but these may not be the kind of bedrooms likely to take in the poor. Returning to our causal diagram:</p>
<!--
"more empty bedrooms" <- "low economic opportunity" -> "low rents"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Overlooking how economic opportunity works can be a real problem for Furth’s arguments.</p>
</section>
<section id="the-role-of-the-housing-stock-and-doubling-up" class="level1">
<h1>The role of the housing stock (and doubling up)</h1>
<p>Furth’s logic also underplays the important role of variation in housing stock. That is, there’s real variation in how housing stock structures the number of housing options available to people by bedrooms. A lot of this relates to various planning and bylaw constraints, but it can also relate to market conditions, both present and past. Old cities tend to have lots more apartments. Newer cities tend to have lots more houses, often with more bedrooms. Looking forward, the only way to add more housing is through densification of our existing cities, or sprawl. Planning constraints often allow densification within only a very limited number of lots made available for rezoning. In areas with existing housing shortages these lots come at high cost and and often get developed intensively (e.g.&nbsp;studio and 1BR apartments) to satisfy high demand for privacy of people who might otherwise end up in doubled-up households. By contrast, more bedrooms can often be added under existing zoning, by simply replacing a small house with a large one, and more houses can be produced by sprawling outward. This creates a potential policy takeaway from Furth that more big houses (likely to have spare bedrooms) are preferable for addressing homelessness than adding a lot more small apartments.</p>
<p>We don’t think this logic holds up, and it mostly has to do with the interrelationships between living independently and occupying a spare bedroom.</p>
<p>While we don’t want to completely dismiss the “right-sizing” explanation, we believe the main mechanisms don’t function as Furth suggests. To explain this, first consider what causes empty bedrooms. Empty bedrooms are the difference between the number of bedrooms and the household size, possibly discounted by couples sharing bedrooms, and possibly further discounted by some children sharing bedrooms along the lines of the <a href="https://www.cmhc-schl.gc.ca/professionals/industry-innovation-and-leadership/industry-expertise/affordable-housing/provincial-territorial-agreements/investment-in-affordable-housing/national-occupancy-standard">National Occupancy Standard (NOS)</a>. In aggregate, the number of bedrooms is given by the distribution of the housing stock, and the household size is given by the family structure of a region plus the pigeonhole principle: If there are more families and unattached individuals than housing units in a region (and that’s almost always the case) then some have to double-up and fill empty bedrooms (or crowd into already occupied bedrooms).</p>
<p>This observation leads us to the following conceptualization of the underlying mechanisms:</p>
<!--
"few spare bedrooms" <- "high rates of doubling up" <- "high rents" -> "homelessness"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>In other words, spare bedrooms and homelessness are both caused by high rents, with the “high rents” -&gt; “doubling up” channel capturing people priced out of the market who are making things work by pooling income in roommate situations or doubling up with family and friends, and the “high rents” -&gt; “homelessness” channel capturing those who fall through the cracks. There is a not insignificant third channel of financial help, either in form of non-arms length rental agreements or cash transfers from family members to enable independent living, which goes a lot further when rent is lower. Additionally the makeup of the housing stock, in particular the distribution by number of bedrooms, also impacts the number of spare bedrooms, or formally: “dwelling stock” -&gt; “spare bedrooms”.</p>
<p>To make that a little more precise we check into how the involved concepts of bedrooms, couple status, number of children, and doubling up break down by metro area.</p>
<section id="bedrooms" class="level2">
<h2 class="anchored" data-anchor-id="bedrooms">Bedrooms</h2>
<p>Let’s take a look at the data to understand how the mechanisms work. We’ll start by looking at the distribution of bedrooms in the occupied housing stock in large Canadian CMAs shown in Figure&nbsp;8.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE <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;">"Not available"</span>,</span>
<span id="cb10-4">         BEDRM<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,BEDRM,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BEDRM=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(BEDRM,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No bedroom"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Studio"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(BEDRM))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Occupied housing stock by number of bedrooms in large Canadian CMAs"</span>,</span>
<span id="cb10-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of occupied housing stock"</span>,</span>
<span id="cb10-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of bedrooms"</span>,</span>
<span id="cb10-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-bedrooms" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-bedrooms-1.png" id="fig-bedrooms" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8
</figcaption>
</figure>
</div>
</div>
</div>
<p>There is a fair bit of variation, with Oshawa showing a higher share of homes with many bedrooms, with Calgary and Edmonton not far behind. At the other end of the spectrum are Vancouver, Victoria, Montréal and the Québec CMA, which all show up with a relatively high share of studio, one and two bedroom units. These low-bedroom units can be viewed as enabling independent living or alternatively as constraining the ability of people to double up. Here is where the real variation in housing stock across Canada helps provide information to test the “spare bedroom” mechanism proposed by Furth.</p>
<p>In Figure&nbsp;9 we look at “spare bedrooms”, which we here define as the number of bedrooms in a home minus the number of people living in it, except that we discount households containing a married or common law couple by assuming they share a bedroom.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">spare_bedrooms <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE <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;">"Not available"</span>,</span>
<span id="cb11-4">         BEDRM<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(BEDRM<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No bedroom"</span> <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;">"1"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(BEDRM,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHSIZE_nf=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner without children"</span>,</span>
<span id="cb11-7">                                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner with children"</span>), HHSIZE_n<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,HHSIZE_n)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spare_bedrooms=</span>(bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>HHSIZE_nf)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,spare_bedrooms,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) </span>
<span id="cb11-11"></span>
<span id="cb11-12">spare_bedrooms <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(spare_bedrooms)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Occupied housing stock by number of spare bedrooms in large Canadian CMAs"</span>,</span>
<span id="cb11-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Affording each person a separate bedroom, except couples who share a bedroom)"</span>,</span>
<span id="cb11-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of occupied housing stock"</span>,</span>
<span id="cb11-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">spare bedrooms"</span>,</span>
<span id="cb11-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-spare-bedrooms" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-spare-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-spare-bedrooms-1.png" id="fig-spare-bedrooms" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-spare-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9
</figcaption>
</figure>
</div>
</div>
</div>
<p>We note that metro areas that have a lot of 4 or 5+ bedroom homes also tend to have more empty bedrooms. But there are other things going on too; for example the Québec City CMA does not fit that pattern.</p>
</section>
<section id="couple-structure-and-number-of-children" class="level2">
<h2 class="anchored" data-anchor-id="couple-structure-and-number-of-children">Couple structure and number of children</h2>
<p>Couple structure and number of children could also impact spare bedrooms, so let’s explore how these vary.</p>
<p>In Figure&nbsp;10 we contrast this by looking at the demographic structure in each metro area and their broad preferences for living in separate dwelling units as encoded by Ermisch’s Minimal Household Units (MHU) concept <span class="citation" data-cites="ermisch1985minimal">(Ermisch and Overton 1985)</span>. We discuss the concept in much greater detail elsewhere <span class="citation" data-cites="housing-outcomes.2023 housing_shortages_doubled_up_households.2024">(<span class="nocase">von Bergmann and Lauster</span> 2023; <span class="nocase">Lauster and von Bergmann</span> 2024)</span>, but the basic idea is that most couples and parents with younger children would all choose to continue living together even if offered a spare dwelling. It’s less clear this would hold for most other households, where we would expect much greater splitting apart if more dwellings were available.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> child_ages)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">couple=</span>CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner without children"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner with children"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cpl_weight=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(couple <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.5</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,couple)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>couple)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In couple</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">relationship"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single adult"</span>),</span>
<span id="cb12-12">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c047) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple status among people 20 years and over in large Canadian CMAs"</span>,</span>
<span id="cb12-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of married or in common law people"</span>,</span>
<span id="cb12-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb12-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Status"</span>,</span>
<span id="cb12-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-couple-single-adults" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-couple-single-adults-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-couple-single-adults-1.png" id="fig-couple-single-adults" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-couple-single-adults-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10
</figcaption>
</figure>
</div>
</div>
</div>
<p>Here we see relatively little variation in coupling up by metro area, certainly a lot smaller than the variation in bedroom mix. Given this, one might expect that the number of spare bedrooms is mostly driven by the overall bedroom mix, but the share of the population under the age of 20, which is what we here chose to count as “dependent” children, has a small impact too as seen in Figure&nbsp;11.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">child=</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> child_ages)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">living_with_parents=</span>CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>,</span>
<span id="cb13-6">                                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a lone parent"</span>,</span>
<span id="cb13-7">                                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person not in a census family but living with other relatives"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">child_at_home=</span>child <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> living_with_parents) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,child_at_home)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>child_at_home)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child living with parents"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adult"</span>),</span>
<span id="cb13-14">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c033) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Children under the age of 20 living with parents in Canadian CMAs"</span>,</span>
<span id="cb13-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population"</span>,</span>
<span id="cb13-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb13-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Status"</span>,</span>
<span id="cb13-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-child-share" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-child-share-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-child-share-1.png" id="fig-child-share" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-child-share-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="doubling-up" class="level2">
<h2 class="anchored" data-anchor-id="doubling-up">Doubling up</h2>
<p>Neither couple structure nor share of the population that are children exhibit enough variation to have a meaningful impact on spare bedrooms. The more important variation however is the rate of doubling up, which we can measure by the share of Minimal Household Units to actual households, focusing on the population 20 years and over as done in Figure&nbsp;12. This does not include households formed by people under the age of 20.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">mhu_ratio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> child_ages)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Maintainer <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;">"Not applicable"</span> ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">couple=</span>CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner without children"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner with children"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cpl_weight=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(couple <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.5</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_weight=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Maintainer<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;">"Maintainer"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>cpl_weight),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Houesholds=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>hh_weight),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>MHU<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Houesholds) </span>
<span id="cb14-10"></span>
<span id="cb14-11"></span>
<span id="cb14-12">mhu_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-13">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#left_join(m_rents,by=c("CMA","Year")) %&gt;%</span></span>
<span id="cb14-14">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#mutate(CMA=factor(CMA,levels=filter(.,Year=="2021") |&gt; arrange(-real_rent) |&gt; pull(CMA))) |&gt;</span></span>
<span id="cb14-15">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb14-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>ratio<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimal Household Units vs Households among people 20 years and over in Canadian CMAs"</span>,</span>
<span id="cb14-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess Minimal Household Units over Households"</span>,</span>
<span id="cb14-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb14-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011, 2016 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-hh-ratio" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-hh-ratio-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-mhu-hh-ratio-1.png" id="fig-mhu-hh-ratio" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-mhu-hh-ratio-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;12
</figcaption>
</figure>
</div>
</div>
</div>
<p>The variation in doubling up is significant, and is much stronger than the variation in couple structure, which is encoded here in the Minimum Household Units, and the variation in share of children. This, together with the somewhat smaller variation in bedroom mix, drives the variation in spare bedrooms. As we have argued in other places, the variation in doubling up is primarily driven by prevailing rents, and Figure&nbsp;13 gives another view into this using our shorthand of taking the population 20 years and over.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">mhu_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(m_rents,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>ratio<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-4">  <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="cb15-5">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Minimal Household Units vs Households among people 20 years and over in Canadian CMAs"</span>,</span>
<span id="cb15-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median real rent for recent (1 year) movers in non-subsidized 1 bedroom apartments (2021 dollars)"</span>,</span>
<span id="cb15-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess Minimal Household Units over Households"</span>,</span>
<span id="cb15-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011, 2016 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-rents" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-mhu-rents-1.png" id="fig-mhu-rents" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-mhu-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;13
</figcaption>
</figure>
</div>
</div>
</div>
<p>So rents drive doubling up directly. Does doubling up, in turn, drive variation in spare bedrooms?</p>
<!--
"high rents" -> "high rates of doubling up" -> "few spare bedrooms"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>To relate back to spare bedrooms, we count up all spare bedrooms per metro area and order the metro areas by their prevailing (median) 1-bedroom rent levels using recent movers as a proxy for recently available units. Additionally, we check whether those empty bedrooms can be found in homes occupied by Minimal Household Units, so homes without any doubling up, or in doubled-up homes as shown in Figure&nbsp;14.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">all_bedrooms <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb16-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE <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;">"Not available"</span>,</span>
<span id="cb16-4">         BEDRM<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(BEDRM<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No bedroom"</span> <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;">"1"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(BEDRM,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) </span>
<span id="cb16-7"></span>
<span id="cb16-8"></span>
<span id="cb16-9">combined_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> spare_bedrooms <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-11">  <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;">spare_bedrooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(all_bedrooms,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">share_empty=</span>spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>bedrooms) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(mhu_ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"50%"</span>,BEDRM<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;">"1 bedroom"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) </span>
<span id="cb16-16"></span>
<span id="cb16-17">spare_bedrooms_mhu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb16-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE <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;">"Not available"</span>,</span>
<span id="cb16-20">         BEDRM<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(BEDRM<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No bedroom"</span> <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;">"1"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(BEDRM,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHSIZE_nf=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner without children"</span>,</span>
<span id="cb16-23">                                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner with children"</span>), HHSIZE_n<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,HHSIZE_n)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spare_bedrooms=</span>(bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>HHSIZE_nf)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spare_bedrooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,MHU)) </span>
<span id="cb16-27"></span>
<span id="cb16-28">all_bedrooms_mhu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-29">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb16-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HHSIZE <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;">"Not available"</span>,</span>
<span id="cb16-31">         BEDRM<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(BEDRM<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No bedroom"</span> <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;">"1"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(BEDRM,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bedrooms=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,MHU)) </span>
<span id="cb16-34"></span>
<span id="cb16-35"></span>
<span id="cb16-36">combined_data_mhu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> spare_bedrooms_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(all_bedrooms_mhu,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<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;">"MHU"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">share_empty=</span>spare_bedrooms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>bedrooms) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(mhu_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHUs=</span>MHU),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"50%"</span>,BEDRM<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;">"1 bedroom"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(MHU <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;">"MHU"</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-MHU"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combined"</span>))</span>
<span id="cb16-43"></span>
<span id="cb16-44"></span>
<span id="cb16-45">combined_data_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb16-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,MHU<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;">"Combined"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(share_empty) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Egypt"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-51">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geom_smooth(aes(group=MHU),method="lm") +</span></span>
<span id="cb16-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spare bedrooms by MHU status"</span>,</span>
<span id="cb16-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-55">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of spare bredrooms"</span>,</span>
<span id="cb16-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU status"</span>,</span>
<span id="cb16-57">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rent-spare-bedrooms" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rent-spare-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-rent-spare-bedrooms-1.png" id="fig-rent-spare-bedrooms" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-rent-spare-bedrooms-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;14
</figcaption>
</figure>
</div>
</div>
</div>
<p>Not surprisingly, the share of spare bedroom differs widely between MHU and non-MHU (doubled up) households. MHU have more spare bedrooms. But there remains a correlation between the two, with lower share of empty bedrooms in MHU households generally corresponding to lower share of empty bedrooms in non-MHU households.</p>
<p>Figure&nbsp;15 relates these shares to prevailing rent levels to understand how rents might be driving the variation.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">combined_data_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,MHU<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;">"Combined"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>real_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-5">  <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="cb17-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>MHU),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Egypt"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spare bedrooms vs rent by MHU status"</span>,</span>
<span id="cb17-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median non-subsidized 1-bedroom rent of recent (1 year) movers"</span>,</span>
<span id="cb17-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of spare bredrooms"</span>,</span>
<span id="cb17-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU status"</span>,</span>
<span id="cb17-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-spare-bedroom-rents" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-spare-bedroom-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-spare-bedroom-rents-1.png" id="fig-spare-bedroom-rents" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-spare-bedroom-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;15
</figcaption>
</figure>
</div>
</div>
</div>
<p>The correlation is clear, but there is sizable variation in the data. The slope for the <em>Combined</em> category is steeper than that when MHU and non-MHU households are taken separately, suggesting that the variation in the overall share of spare bedrooms is driven by underlying variation in doubling up. In other words, there’s a strong case for:</p>
<!--
"high rents" -> "high rates of doubling up" -> "few spare bedrooms"
-->
<div class="cell" data-crop="true">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>What about the case Furth’s case for few spare bedrooms driving homeless counts?</p>
<p>To some extent, the relationship between doubling up and spare bedrooms supports Furth’s argument. Most of the cases of people he tracks living with parents or roommates are simply people we would consider doubled up. But doubling up is widespread as a response to high rents, rather than simply a last stop before homelessness. It probably works well for some people, but not so well for others.</p>
<p>To wrap this up let’s return to PIT homelessness rates and directly explore their relationships with rents, MHU, and spare bedrooms as done in Figure&nbsp;16.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pit_rent.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <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;">filter</span>(quantile<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;">"10%"</span>))</span>
<span id="cb18-4">r2_rent <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;">summary</span>(pit_rent.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb18-6"></span>
<span id="cb18-7">pd2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> combined_data_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb18-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>,MHU<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;">"Combined"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,share_empty) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,PIT_rate),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate))</span>
<span id="cb18-12"></span>
<span id="cb18-13">pit_brm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd2)</span>
<span id="cb18-14">r2_brm <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;">summary</span>(pit_brm.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb18-16"></span>
<span id="cb18-17"></span>
<span id="cb18-18">g_brm<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-20">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb18-21">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb18-24">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs spare bedrooms"</span>,</span>
<span id="cb18-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of spare bedrooms"</span>,</span>
<span id="cb18-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb18-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb18-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness countsl StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb18-31"></span>
<span id="cb18-32">pd3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb18-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,ratio) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,PIT_rate),</span>
<span id="cb18-36">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate))</span>
<span id="cb18-38"></span>
<span id="cb18-39">pit_mhu.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> (ratio),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd3)</span>
<span id="cb18-40"></span>
<span id="cb18-41">r2_mhu <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;">summary</span>(pit_mhu.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb18-43"></span>
<span id="cb18-44"></span>
<span id="cb18-45">g_mhu<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pd3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-47">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb18-48">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb18-51">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs excess MHU"</span>,</span>
<span id="cb18-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess MHU over households"</span>,</span>
<span id="cb18-55">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb18-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb18-57">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb18-58"></span>
<span id="cb18-59">g_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"10%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-63">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb18-64">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb18-67">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs rents"</span>,</span>
<span id="cb18-70">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-subsidized 1 bedroom rent of recent (1 year) movers"</span>,</span>
<span id="cb18-71">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb18-72">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb18-73">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb18-74"></span>
<span id="cb18-75">(g_rents <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_rent),</span>
<span id="cb18-76">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10th percentile rents"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-77">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-78">  (g_mhu <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_mhu),</span>
<span id="cb18-79">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess MHU"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-80">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-81">  (g_brm  <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_brm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spare bedrooms"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-82">     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-83">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-84">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_annotation</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;">"PIT rates vs housing indicators"</span>,</span>
<span id="cb18-85">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-homelessness-rents-mhu-brm" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-homelessness-rents-mhu-brm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homelessness-rents-mhu-brm-1.png" id="fig-homelessness-rents-mhu-brm" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-homelessness-rents-mhu-brm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;16
</figcaption>
</figure>
</div>
</div>
</div>
<p>Drawing upon Canadian data, we can replicate the basic finding that high rents are positively related to high rates of homelessness. By contrast, we cannot replicate Furth’s findings that spare bedrooms have a strong negative relationship to homelessness rates. Rates of doubling up (excess MHU relative to households) seem to relate to homelessness in a similar way as rents (not so surprising following much of our recent work establishing the strong relationship between rents and doubling up). This analysis of Canadian data so far suggests rent may be driving both doubling up and homelessness, but other factors, including housing stock, also drive spare bedrooms.</p>
<p>For completeness Figure&nbsp;17 shows the results when multiple-CMA regions are excluded from the regression.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pit_rent.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd <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;">filter</span>(Year<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;">"2021"</span>) <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;">filter</span>(quantile<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;">"10%"</span>,single_cma))</span>
<span id="cb19-4">r2_rent <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;">summary</span>(pit_rent.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb19-6"></span>
<span id="cb19-7">pd2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> combined_data_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb19-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>,MHU<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;">"Combined"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,share_empty) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,PIT_rate,single_cma),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate))</span>
<span id="cb19-12"></span>
<span id="cb19-13">pit_brm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(single_cma))</span>
<span id="cb19-14">r2_brm <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;">summary</span>(pit_brm.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb19-16"></span>
<span id="cb19-17"></span>
<span id="cb19-18">g_brm<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>share_empty,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-20">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb19-21">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb19-24">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,single_cma),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple CMA"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs spare bedrooms"</span>,</span>
<span id="cb19-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of spare bedrooms"</span>,</span>
<span id="cb19-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb19-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb19-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb19-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness countsl StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb19-34"></span>
<span id="cb19-35">pd3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb19-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CMA,ratio) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(homelessness_data_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,PIT_rate,single_cma),</span>
<span id="cb19-39">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(PIT_rate))</span>
<span id="cb19-41"></span>
<span id="cb19-42">pit_mhu.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(PIT_rate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> (ratio),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(single_cma))</span>
<span id="cb19-43"></span>
<span id="cb19-44">r2_mhu <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;">summary</span>(pit_mhu.fit)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span>
<span id="cb19-46"></span>
<span id="cb19-47"></span>
<span id="cb19-48">g_mhu<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pd3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-50">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb19-51">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb19-54">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,single_cma),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple CMA"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs excess MHU"</span>,</span>
<span id="cb19-59">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess MHU over households"</span>,</span>
<span id="cb19-60">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb19-61">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb19-62">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb19-63">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb19-64"></span>
<span id="cb19-65">g_rents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(quantile<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;">"10%"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>PIT_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>single_cma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-69">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb19-70">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-71">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-72">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb19-73">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,single_cma), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiple CMA"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-76">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-77">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness PIT rates vs rents"</span>,</span>
<span id="cb19-78">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-subsidized 1 bedroom rent of recent (1 year) movers"</span>,</span>
<span id="cb19-79">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb19-80">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb19-81">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT method"</span>,</span>
<span id="cb19-82">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) </span>
<span id="cb19-83"></span>
<span id="cb19-84">(g_rents <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_rent),</span>
<span id="cb19-85">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10th percentile rents"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-86">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-87">  (g_mhu <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_mhu),</span>
<span id="cb19-88">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess MHU"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-89">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-90">  (g_brm  <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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R² = "</span>,r2_brm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spare bedrooms"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-91">     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb19-92">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-93">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_annotation</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;">"PIT rates vs housing indicators"</span>,</span>
<span id="cb19-94">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-homelessness-rents-mhu-brm_single" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-homelessness-rents-mhu-brm_single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homelessness-rents-mhu-brm_single-1.png" id="fig-homelessness-rents-mhu-brm_single" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-homelessness-rents-mhu-brm_single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;17
</figcaption>
</figure>
</div>
</div>
</div>
<p>As we saw earlier, removing smaller Census-joined CMAs from the analysis significantly strengthens the relationship of PIT counts with rents. The relationships with MHU and Spare Bedrooms are also slightly stronger, but neither is significantly different from zero (a flat line). Relative to rents they exhibit very little explanatory power.</p>
</section>
</section>
<section id="other-possible-determinants" class="level1">
<h1>Other possible determinants</h1>
<p>The simplest interpretation for the correlation between rents and homelessness is that housing shortages drive rents higher and leave more people falling through the cracks of our systems for distributing housing. Diverse mechanisms explain how people fall through the cracks, but as those reached by homeless counts note, simply not being to afford rents is pretty important in its own right. In other words, yes, homelessness is largely a housing problem. Rents might not fully cover the range of mechanisms by which people fall through the cracks, but they’re not a bad proxy for the size of the cracks.</p>
<p>What other measures might we consider? Low income is an important risk factor but we won’t dive into this in this post. Aggregate income metrics vary much less between metro areas than rents, rendering it less informative than rents at the metro level. Additionally, income data around the time many of our homelessness PIT counts were taken is complicated by one-time pandemic support payments, which matters especially at the bottom of the income distribution that is relevant in this context. Rental vacancy rates around the time of the homelessness counts also suffer from pandemic shocks.</p>
<p>The relationship with non-market housing is a priori less clear. Non-market housing can offer both safety nets preventing homelessness and a direct solution for those experiencing homelessness. In other words, it’s an important way to fill in the cracks, and this has mostly been its role within Canada. This isn’t true everywhere. In many places, non-market housing contributes a sizable portion of the housing stock, directly contributing to reducing shortages. But in the Canadian context, non-market housing has been quite modest in its contribution. Insofar as filling in the cracks has become non-market housing’s primary role within Canadian systems for distributing housing, it is difficult to track its beneficial impact via metropolitan comparison. After all, it is often added in response to high rates of homelessness. Figure&nbsp;18 shows that in Canada there is a slight negative correlation between the share of households in subsidized housing and homelessness PIT counts, although with high uncertainty and not significantly different from zero.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">non_market <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(SUBSIDY,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No, not a subsidized dwelling"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not subsidized"</span>,</span>
<span id="cb20-4">                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes, a subsidized dwelling"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subsidized=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(TENUR<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;">"Owner"</span><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;">"Owner"</span>,</span>
<span id="cb20-6">                              SUBSIDY<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;">"Subsidized"</span><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;">"Subsidized renter"</span>,</span>
<span id="cb20-7">                              SUBSIDY<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;">"Not subsidized"</span><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;">"Market renter"</span>,</span>
<span id="cb20-8">                              <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(subsidized <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;">"Other"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subsidized=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(subsidized,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Owner"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Market renter"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized renter"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb20-12">  <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;">cases=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>HHSIZE_n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,subsidized,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year))</span>
<span id="cb20-14"></span>
<span id="cb20-15">non_market <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(subsidized<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;">"Subsidized renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(homelessness_data_manual,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Absolute_Rate_Likely_Geography)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Absolute_Rate_Likely_Geography)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb20-23">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-24">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb20-25">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness vs subsidized housing"</span>,</span>
<span id="cb20-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb20-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of households in non-market housing or with cash supports"</span>,</span>
<span id="cb20-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-homlessness-subsidized" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-homlessness-subsidized-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homlessness-subsidized-1.png" id="fig-homlessness-subsidized" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-homlessness-subsidized-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;18
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">non_market <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(subsidized<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;">"Owner"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(subsidized<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;">"Subsidized renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(homelessness_data_manual,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Absolute_Rate_Likely_Geography)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Absolute_Rate_Likely_Geography)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><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>
<span id="cb21-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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-12">  ggrepel<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_label_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb21-13">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> highlight_metros)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Homelessness vs subsidized rental housing"</span>,</span>
<span id="cb21-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PIT rate per 1000 population"</span>,</span>
<span id="cb21-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of renter households in non-market housing or with cash supports"</span>,</span>
<span id="cb21-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Assembled from individual jurisdiction homelessness counts; StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
</div>
<p>Placed in the context of the larger relationship between rents and homelessness rates, we think the important takeaway for non-market housing is that it’s much more effective as a direct means of preventing or alleviating homelessness when rents overall are low. Rising rents produce more cracks in our systems of housing distribution, and it’s much harder for non-market housing to fill those cracks when more and more keep appearing every time providers turn around. More broadly, while the contributions of non-market housing to relieving the housing shortage overall have been modest so far, every little bit helps, and more ambition would help further!</p>
</section>
<section id="limitations" class="level1">
<h1>Limitations</h1>
<p>Numerous caveats remain, the largest of which concern remaining issues with the comparability of homeless count data. In particular, agreed-upon methods for counting are still being worked out. Authorities carrying out counts are diverse, and reflect similarly diverse geographies. Moreover, both procedures for counts, and the counts themselves, were disrupted by the onset of the Covid pandemic. Conditions have often changed dramatically over even the short time in which we combined Point-in-Time homeless counts (2020-2023). Both rents, and policies relating to tenancies also changed over this time, with eviction moratoria, for instance, varying both across our study period and between provinces.</p>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>Overall, to the extent we’ve been able to produce comparable homeless counts across Canadian metropolitan areas we can see similar relationships to rents as observed in the USA. This relatively strong correlation joins data collected on “reasons for homelessness” within counts suggesting a strong relationship between housing markets and homelessness. It is likely there are multiple mechanisms producing this relationship.</p>
<p>Furth’s approach to try and link our understanding of aggregate impacts of housing shortages on homelessness rates to the mechanisms operating at the individual level is good and important. With this post we aim to draw upon Canadian data to add additional nuance to this in order to move the discussion forward.</p>
<p>Furth envisions the mechanism by which lower rents help low income people being mediated through spare bedrooms, which are offered up by family or friends of people with income too low to afford median rents. While we don’t think that’s entirely wrong, we believe that this isn’t the main mechanism, and instead joins a suite of possible mechanisms. Insofar as housing is an interconnected system, this isn’t too surprising. There are lots of things going on, and lots of ways people can become included within a diversified housing system or left out when there’s a shortage.</p>
<p>We continue to find it plausible that the chief mechanisms driving the relationship between median rents and homelessness are relatively straightforward market mechanisms. That is, median rents only proxy for the full distribution of rents, and absent a housing shortage full distributions can reach quite far below the medians, bringing them into the range of affordability for those who might otherwise find themselves homeless. Unfortunately, housing shortages shift rent distributions to the right, driving rents higher across their range as people struggle to find a seat in what becomes a giant game of musical chairs.</p>
<p>To be sure, relationships matter in this game. Some people are more willing to share chairs with each other, even if they’d rather sit on their own. Moreover, the size of the chair to be shared can also matter to peoples’ willingness to share. We take this as Furth’s main point. But we argue that ultimately the size of the chair matters far less than peoples’ willingness to share at all or the number of chairs overall.</p>
<p>In other words, we agree that housing shortages drive homelessness. But Canadian data drawing on variation in housing stock challenges the idea that the causal mechanism driving the relationship between rent and homelessness is strongly mediated through spare bedrooms, and we caution against an exclusively beneficent view of family relationships. While there are some differences in how housing and income work and are distributed south of the border, we don’t imagine these mechanisms to function radically differently in the USA.</p>
<p>To spell out the mechanisms clearly as we understand them, housing shortages drive high rents. High rent levels cause both elevated rates of homelessness, as well as increased doubling up and fewer spare bedrooms. When housing supply grows faster than the demand for housing, real prices and rents fall.<sup>2</sup> In research this is often tracked via average or median rents and prices, but there is a lot of empirical data showing that the effects act throughout the housing spectrum, and in particular reach into the lower end. <span class="citation" data-cites="distributional-effects-of-adding-housing.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024)</span> Of note, to the extent the lower end of the housing market is made illegal, for instance by outlawing rooming houses and SROs or by regulating minimum dwelling sizes, regulation can take away low rent options and make the systemic effects of housing shortage worse for those at risk of homelessness. Moreover, adding subsidies and social housing can definitely help in directly reaching those at risk for homelessness, but these approaches are best understood as operating within a broader housing system where shortages work against their overall effectiveness.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2025-01-16-homelessness-and-rents-in-canada/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb22-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2025-01-29 09:21:52 PST"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb24-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [5e8d524] 2025-01-17: post freeze</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb26-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.3

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] patchwork_1.3.0           rvest_1.0.4              
 [3] mountainmathHelpers_0.1.4 cansim_0.3.18            
 [5] canpumf_0.2.0             cancensus_0.5.8          
 [7] lubridate_1.9.4           forcats_1.0.0            
 [9] stringr_1.5.1             dplyr_1.1.4              
[11] purrr_1.0.2               readr_2.1.5              
[13] tidyr_1.3.1               tibble_3.2.1             
[15] ggplot2_3.5.1             tidyverse_2.0.0          

loaded via a namespace (and not attached):
 [1] generics_0.1.3    xml2_1.3.6        stringi_1.8.4     extrafontdb_1.0  
 [5] hms_1.1.3         digest_0.6.37     magrittr_2.0.3    evaluate_1.0.0   
 [9] grid_4.4.2        timechange_0.3.0  fastmap_1.2.0     rprojroot_2.0.4  
[13] jsonlite_1.8.9    processx_3.8.4    chromote_0.2.0    ps_1.7.6         
[17] promises_1.3.0    httr_1.4.7        scales_1.3.0      cli_3.6.3        
[21] rlang_1.1.5       munsell_0.5.1     sanzo_0.1.0       withr_3.0.2      
[25] yaml_2.3.10       tools_4.4.2       tzdb_0.4.0        colorspace_2.1-1 
[29] here_1.0.1        vctrs_0.6.5       R6_2.5.1          git2r_0.33.0     
[33] lifecycle_1.0.4   htmlwidgets_1.6.4 pkgconfig_2.0.3   pillar_1.10.1    
[37] later_1.3.2       gtable_0.3.6      glue_1.8.0        Rcpp_1.0.14      
[41] xfun_0.50         tidyselect_1.2.1  rstudioapi_0.16.0 knitr_1.48       
[45] extrafont_0.19    farver_2.1.2      websocket_1.4.1   htmltools_0.5.8.1
[49] rmarkdown_2.28    Rttf2pt1_1.3.12   compiler_4.4.2   </code></pre>
</div>
</div>
</details>



</section>


<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-ermisch1985minimal" class="csl-entry">
Ermisch, John F, and Elizabeth Overton. 1985. <span>“Minimal Household Units: A New Approach to the Analysis of Household Formation.”</span> <em>Population Studies</em> 39 (1): 33–54.
</div>
<div id="ref-kneebone2021local" class="csl-entry">
Kneebone, Ronald D, and Margarita Wilkins. 2021. <span>“Local Conditions and the Prevalence of Homelessness in Canada.”</span> <em>The School of Public Policy Publications</em> 14. <a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4032143">https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4032143</a>.
</div>
<div id="ref-housing_shortages_doubled_up_households.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“Housing Shortages and Doubled up Households.”</span> <em>Plan Canada</em> 64 (4): 16–21. <a href="https://mountainmath.github.io/housing_shortages_and_doubled_up_households/">https://mountainmath.github.io/housing_shortages_and_doubled_up_households/</a>.
</div>
<div id="ref-commodity-and-keeping-it-in-the-family.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021. <em>Commodity and <span>Keeping</span> It in the <span>Family</span></em>. <a href="https://doodles.mountainmath.ca/posts/2021-08-13-commodity-and-keeping-it-in-the-family/">https://doodles.mountainmath.ca/posts/2021-08-13-commodity-and-keeping-it-in-the-family/</a>.
</div>
<div id="ref-tumbling-turnover.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022. <em>Tumbling Turnover</em>. <a href="https://doodles.mountainmath.ca/posts/2022-07-29-tumbling-turnover/">https://doodles.mountainmath.ca/posts/2022-07-29-tumbling-turnover/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
<div id="ref-distributional-effects-of-adding-housing.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024. <em>Distributional Effects of Adding Housing</em>. <a href="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/">https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>For analysis rents are generally modelled on a log-normal distribution, which better approximates the rent distributions we see empirically. The median generally not being centred in 25th to 75th quartile range, and the upper whiskers in the plot being longer than the lower ones, speak to that.↩︎</p></li>
<li id="fn2"><p>A point of frequent confusion here is that it’s not the prices and rents of the new housing that are of primary interest, but the effects of adding housing on the prices and rents of the existing housing stock.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{homelessness-and-rents-in-canada.2025,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Homelessness and {Rents} in {Canada}},
  date = {2025-01-16},
  url = {https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2025" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2025. <span>“Homelessness and
Rents in Canada.”</span> <em>MountainDoodles</em>, accepted, January 16.
<a href="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/">https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <category>canpumf</category>
  <guid>https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/</guid>
  <pubDate>Thu, 16 Jan 2025 08:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2025-01-16-homelessness-and-rents-in-canada/index_files/figure-html/fig-homelessness-rents-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>No spike in “foreign buying”</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/11/08/no-spike-in-foreign-buying/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">ppt_datasetes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bcdata<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;">bcdc_search</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Property Transfer Tax"</span>)</span>
<span id="cb1-2"></span>
<span id="cb1-3">titles <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>(ppt_datasetes,\(x)x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>title)</span>
<span id="cb1-4"></span>
<span id="cb1-5">provincial_monthly_ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ppt_datasetes[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"property transfer tax data"</span>,titles,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(x)x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resource_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-7">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PROVINCIAL_MONTHLY_</span><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;">d{4}|PROVINCIAL MONTHLY </span><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;">d{4}|provincialmonthly</span><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;">d{4}"</span>,name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-8">                  format<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;">"csv"</span>))</span>
<span id="cb1-9"></span>
<span id="cb1-10">provincial_monthly <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> provincial_monthly_ids <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowwise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_map</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cols</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.default=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,Month,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-15"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_at</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">one_of</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;">"Year"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Month"</span>)),as.numeric)</span></code></pre></div></div>
</details>
</div>
<p>Today the Globe and Mail published an <a href="https://www.theglobeandmail.com/real-estate/vancouver/article-foreign-money-continues-to-flow-into-bc-real-estate/">opinion piece about continued flows of “foreign money” in B.C. real estate</a>. Broadly this is a topic that has been discussed in BC for over a decade now and regularly pops up in the news. We’ve written extensively about the slipperiness of the “foreign money” discourse in our paper on Canada’s turn toward Housing Nationalism <span class="citation" data-cites="housing_nationalism.2023">(<span class="nocase">Lauster and von Bergmann</span> 2023)</span> (<a href="https://open.library.ubc.ca/soa/cIRcle/collections/facultyresearchandpublications/52383/items/1.0438798">ungated version here</a>). There are a number of conceptualizations of “foreign” in the public discussion, as well as in data sources, policy and law as it applies to real estate holdings and purchases. Our paper describes how the flexible use and application of the “foreign” label plays an integral role in keeping anti-foreign narratives and sentiments alive.</p>
<p>The G&amp;M article continues this pattern, not just mixing and matching concepts but outright misrepresenting the groups targeted by the federal Foreign Buyer Ban and the BC Foreign Buyer Tax. Moreover, it leads with the claim of a “spike” in the value of foreign buying, continuing to push the narrative that our housing problems are driven by foreign origins. We will leave it to our article on Housing Nationalism to criticize this broader framing. For now we will demonstrate that the claim about a spike is wrong, and seems to be based on an error in summing across months in BC data.</p>
<p>In support of the idea there’s been a recent spike in foreign buying, the G&amp;M article claims:</p>
<blockquote class="blockquote">
<p>Using property transfer tax data provided by the B.C. government, Simon Fraser University associate professor Andy Yan showed that residential purchases categorized as “foreign involvement transactions” had a total dollar value of nearly $664-million from January to September, 2020. In that same period this year, 834 foreign involvement residential transactions added up to nearly $824-million. The dollar value of foreign residential transactions in 2023 was $744.5-million. The total number of foreign transactions, including commercial, increased from 1,018 in 2023 to 1,020 in 2024.</p>
</blockquote>
<p>The dollar values for 2023 and 2024 appear correct. However the dollar value for 2020 is plainly wrong. Table&nbsp;1 are the actual numbers for the first 9 months in every year since 2017.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">provincial_monthly <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Month <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(add_tax_paid,sum_FMV_foreign_res,sum_FMV_foreign),sum),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add_tax_paid=</span>scales<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;">dollar</span>(add_tax_paid,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>),</span>
<span id="cb2-6">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sum_FMV_foreign_res,sum_FMV_foreign),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>scales<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;">dollar</span>(.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bn"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total market value with foreign involvement</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>sum_FMV_foreign,</span>
<span id="cb2-8">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total residential market value with foreign involvement</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>sum_FMV_foreign_res,</span>
<span id="cb2-9">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total Foreign Buyer Tax</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>add_tax_paid,</span>
<span id="cb2-10">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">First 9 months of year</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-11">  tinytable<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;">tt</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Open Data"</span>,</span>
<span id="cb2-12">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">note=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Here </span><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;">foreign</span><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;"> refers to non-citizen, non-PR, non-provincial nominees"</span>)</span></code></pre></div></div>
</details>
<div id="tbl-fbt-first-9-months" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned" id="tbl-fbt-first-9-months-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1
</figcaption>
<div aria-describedby="tbl-fbt-first-9-months-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<!-- preamble start -->

    <script>
      function styleCell_o1e0et02vzcdg5jk3p17(i, j, css_id) {
        var table = document.getElementById("tinytable_o1e0et02vzcdg5jk3p17");
        table.rows[i].cells[j].classList.add(css_id);
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_o1e0et02vzcdg5jk3p17');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_o1e0et02vzcdg5jk3p17(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_o1e0et02vzcdg5jk3p17");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(0, 0, 'tinytable_css_id28xkiwedxo60shvowtit') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(0, 1, 'tinytable_css_id28xkiwedxo60shvowtit') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(0, 2, 'tinytable_css_id28xkiwedxo60shvowtit') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(0, 3, 'tinytable_css_id28xkiwedxo60shvowtit') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(9, 0, 'tinytable_css_idtbjottv1qqom0vlfspou') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(9, 1, 'tinytable_css_idtbjottv1qqom0vlfspou') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(9, 2, 'tinytable_css_idtbjottv1qqom0vlfspou') })
window.addEventListener('load', function () { styleCell_o1e0et02vzcdg5jk3p17(9, 3, 'tinytable_css_idtbjottv1qqom0vlfspou') })
    </script>

    <style>
    .table td.tinytable_css_id28xkiwedxo60shvowtit, .table th.tinytable_css_id28xkiwedxo60shvowtit {  border-bottom: solid 0.1em #d3d8dc; }
    .table td.tinytable_css_idtbjottv1qqom0vlfspou, .table th.tinytable_css_idtbjottv1qqom0vlfspou {  text-align: left; }
    </style>
    <div class="container">
      <table class="table table-borderless" id="tinytable_o1e0et02vzcdg5jk3p17" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        </thead><caption>BC Open Data</caption>
              <tbody><tr>
                <th scope="col">First 9 months of year</th>
                <th scope="col">Total Foreign Buyer Tax</th>
                <th scope="col">Total residential market value with foreign involvement</th>
                <th scope="col">Total market value with foreign involvement</th>
              </tr>
        
        </tbody><tfoot><tr><td colspan="4">Here "foreign" refers to non-citizen, non-PR, non-provincial nominees</td></tr></tfoot>
        <tbody>
                <tr>
                  <td>2017</td>
                  <td>$159.15M</td>
                  <td>$2.82bn</td>
                  <td>$3.34bn</td>
                </tr>
                <tr>
                  <td>2018</td>
                  <td>$127.98M</td>
                  <td>$2.04bn</td>
                  <td>$3.09bn</td>
                </tr>
                <tr>
                  <td>2019</td>
                  <td>$89.90M </td>
                  <td>$1.19bn</td>
                  <td>$1.71bn</td>
                </tr>
                <tr>
                  <td>2020</td>
                  <td>$77.76M </td>
                  <td>$1.02bn</td>
                  <td>$1.64bn</td>
                </tr>
                <tr>
                  <td>2021</td>
                  <td>$71.89M </td>
                  <td>$1.34bn</td>
                  <td>$1.64bn</td>
                </tr>
                <tr>
                  <td>2022</td>
                  <td>$57.39M </td>
                  <td>$1.22bn</td>
                  <td>$1.70bn</td>
                </tr>
                <tr>
                  <td>2023</td>
                  <td>$30.84M </td>
                  <td>$0.74bn</td>
                  <td>$1.23bn</td>
                </tr>
                <tr>
                  <td>2024</td>
                  <td>$24.24M </td>
                  <td>$0.82bn</td>
                  <td>$1.42bn</td>
                </tr>
        </tbody>
      </table>
    </div>
<!-- hack to avoid NA insertion in last line -->
</div>
</div>
</figure>
</div>
</div>
<p>We were able to replicate the dollar values for 2020 when we only summed up the first six months (rather than the first nine) of 2020, and it seems likely this is the source of the error. Importantly, it’s a pretty big error, and when it’s corrected the idea of a recent spike in foreign involved purchases disappears.</p>
<p>The errors in adding across months continue to reverberate in subsequent passages:</p>
<blockquote class="blockquote">
<p>B.C.’s foreign buyer tax revenues ranged from $51-million in 2020 to a high of $71-million in 2021, to $24-million in 2024.</p>
</blockquote>
<p>Again, as this is not correct as can be seen from Table&nbsp;1. Maybe more usefully, Figure&nbsp;1 shows the monthly tax revenue from the FBT, with annual means shown for added context.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">provincial_monthly <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">share=</span>n_foreign_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_res_trans) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">share2=</span>sum_FMV_foreign_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sum_FMV_res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>add_tax_paid)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>scales<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;">dollar</span>(.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-8">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Foreign buyer tax revenue"</span>,</span>
<span id="cb3-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monthly tax revenue"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Open Data"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-fbt-monthly-res" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-fbt-monthly-res-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/index_files/figure-html/fig-fbt-monthly-res-1.png" id="fig-fbt-monthly-res" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-fbt-monthly-res-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>Though the article does not mention this, BC’s Foreign Buyer Tax does not apply everywhere in BC, so this misses purchases with foreign involvement outside of the FBT areas. The article is also mum on the federal Foreign Buyer Ban not applying everywhere but only in another subset in BC as shown in Figure&nbsp;2, and applying to a different set of people than the Foreign Buyer Tax.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">rds <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;">bcdc_get_data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b66ed992-16c9-4527-b363-0ae4827d103b"</span>)</span>
<span id="cb4-2">geos <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;">get_census</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Foreign Buyer Ban"</span>)</span>
<span id="cb4-4">pr <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;">get_census</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59"</span>)) </span>
<span id="cb4-5"></span>
<span id="cb4-6">fb_rds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rds <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Capital|Fraser Valley|Metro Vancouver|Central Okanagan|Nanaimo"</span>,REGIONAL_DISTRICT_NAME)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Foreign Buyer Tax"</span>)</span>
<span id="cb4-8"></span>
<span id="cb4-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(geos,<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;">fill=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>fb_rds) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Foreign Buyer Ban"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>,</span>
<span id="cb4-13">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Foreign Buyer Tax"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgreen"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_roads</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Areas in BC with foreign buyer restrictions"</span>,</span>
<span id="cb4-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-foreign-buyer-restriction-goes" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-foreign-buyer-restriction-goes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/index_files/figure-html/fig-foreign-buyer-restriction-goes-1.png" id="fig-foreign-buyer-restriction-goes" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-foreign-buyer-restriction-goes-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>The article puts a lot of emphasis on the value of transactions involving foreign buyers, so not just the value attributed to foreign buyers based on ownership share. This is shown in Figure&nbsp;3.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">provincial_monthly <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>sum_FMV_foreign_res)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>scales<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;">dollar</span>(.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-5">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interaction</span>(Year)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value of residential property transactions involving foreign buyers"</span>,</span>
<span id="cb5-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total fair market value"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Open Data"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-fb-value-monthly-res" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-fb-value-monthly-res-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/index_files/figure-html/fig-fb-value-monthly-res-1.png" id="fig-fb-value-monthly-res" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-fb-value-monthly-res-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>In Figure&nbsp;4 we include non-residential properties to get the total market value of all properties with foreign involvement.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">provincial_monthly <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>sum_FMV_foreign)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>scales<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;">dollar</span>(.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-5">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interaction</span>(Year)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value of all property transactions involving foreign buyers"</span>,</span>
<span id="cb6-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total fair market value"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Open Data"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-fb-value-monthly-all" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-fb-value-monthly-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/index_files/figure-html/fig-fb-value-monthly-all-1.png" id="fig-fb-value-monthly-all" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-fb-value-monthly-all-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>Looking at this the opening claim in the article that “foreign buying in British Columbia spiked in dollar value this year” is untenable and directly contradicted by the data, undermining the entire narrative of the piece.</p>
<p>Of note, the article continues by helpfully reminding us that “people shouldn’t confuse foreign buyers with immigrants”, only to continue by using the slippery concept of “foreign money” and applying it to immigrants, as well as some citizens where the “foreign” component might be a spouse working abroad or immigrants not “anglicizing” their first name upon landing.</p>
<p>We now have a lot of data: data on foreign buyers, estimates on non-resident investment, estimates of problematic vacancies, etc. We have found this data useful and drawn extensively on it in our own work trying to understand local patterns. But it’s crucial that data analysis is performed carefully and thoughtfully with respect to impact. Hopefully this piece will be corrected, and the missimpressions created by its framing will be fixed by G&amp;M.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-11-08-no-spike-in-foreign-buying/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-11-10 23:12:48 PST"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb9-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [e567ead] 2024-11-09: freeze, and link to nathan</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb11-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.3                
 [3] knitr_1.48                rlang_1.1.4              
 [5] xfun_0.47                 generics_0.1.3           
 [7] jsonlite_1.8.8            glue_1.8.0               
 [9] colorspace_2.1-0          git2r_0.33.0             
[11] htmltools_0.5.8.1         mountainmathHelpers_0.1.4
[13] scales_1.3.0              fansi_1.0.6              
[15] rmarkdown_2.28            grid_4.4.1               
[17] munsell_0.5.1             evaluate_1.0.0           
[19] tibble_3.2.1              fastmap_1.2.0            
[21] yaml_2.3.10               lifecycle_1.0.4          
[23] compiler_4.4.1            dplyr_1.1.4              
[25] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[27] rstudioapi_0.16.0         digest_0.6.37            
[29] R6_2.5.1                  tidyselect_1.2.1         
[31] utf8_1.2.4                pillar_1.9.0             
[33] magrittr_2.0.3            tools_4.4.1              
[35] gtable_0.3.5              ggplot2_3.5.1            </code></pre>
</div>
</div>
</details>




<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-housing_nationalism.2023" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2023. <span>“The Rise of Housing Nationalism in Canada and Transnational Property Ownership Patterns.”</span> <em>Journal of Ethnic and Migration Studies</em>, December 20, 1–27. <a href="https://doi.org/10.1080/1369183x.2023.2293635">https://doi.org/10.1080/1369183x.2023.2293635</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{no-spike-in-foreign-buying.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {No Spike in “Foreign Buying”},
  date = {2024-11-08},
  url = {https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“No Spike in
<span>‘Foreign Buying’</span>.”</span> <em>MountainDoodles</em>,
accepted, November 8. <a href="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/">https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/</a>.
</div></div></section></div> ]]></description>
  <category>newsfail</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/</guid>
  <pubDate>Fri, 08 Nov 2024 08:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-11-08-no-spike-in-foreign-buying/index_files/figure-html/fig-fbt-monthly-res-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>BC Election 2024</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/</link>
  <description><![CDATA[ 






<p>We don’t yet have the final results for the 2024 BC provincial election, we are still waiting on the count of the vote-by-mail ballots that have not arrived yet. Some ridings are still in limbo, as is the overall outcome and who will form government.</p>
<p>But most ridings have been called and we wanted to take this opportunity to replicate a map highlighting the difference between land and people as we have done for earlier federal elections, following the idea <a href="https://observablehq.com/@karimdouieb/try-to-impeach-this-challenge-accepted">implemented for the 2016 US presidential elections</a> by <a href="http://twitter.com/karim_douieb">Karim Douïeb</a>. <span class="citation" data-cites="elections-fun.2019 elections-fun-2021-edition.2021">(<span class="nocase">von Bergmann</span> 2019, 2021)</span></p>
<p>As opposed to last time, we can now render the animation live within this blog, thanks quarto’s direct support for <a href="https://observablehq.com/documentation/cells/observable-javascript">observable js</a>. All it takes is a little bit of data prep, where we grab the electoral district boundaries, cut out water features and simplify the polygons. And then scrape the election results from Elections BC. (It’s 2024 and they probably have an actual data feed, but they sure make it hard to find.) Then we assemble a list of ridings that have not been called by hand, we will update that as more results come in.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mountainmathHelpers)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-4"></span>
<span id="cb1-5"></span>
<span id="cb1-6">district_boundaries <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;">simpleCache</span>({</span>
<span id="cb1-7">  bc_geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cancensus<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;">get_statcan_geographies</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRUID<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;">"59"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-9">    rmapshaper<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;">ms_simplify</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>()</span>
<span id="cb1-11">  </span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/Downloads/BCGW_7113060B_1729362546577_9396/EBC_ELECTORAL_DISTS_BS11_SVW/EBC_ED_23_polygon.shp"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(ED_ID,ED_ABBREV,ED_NAME,geometry) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-14">    rmapshaper<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;">ms_simplify</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_intersection</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(bc_geo,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_crs</span>(.))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-16">    rmapshaper<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;">ms_simplify</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_cast</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MULTIPOLYGON"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_coordinates</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_centroid</span>(geometry))[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_coordinates</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_centroid</span>(geometry))[,<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;">%&gt;%</span></span>
<span id="cb1-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rank =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_cast</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"POLYGON"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_area</span>(geometry) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mainShape=</span>area<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;">max</span>(area),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>ED_ID)</span>
<span id="cb1-25">},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_election_polygons.rds"</span>)</span>
<span id="cb1-26"></span>
<span id="cb1-27">upload_result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> district_boundaries <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(ED_ID,ED_NAME,x,y,rank,mainShape,geometry) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sf_to_s3_gzip</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mountainmath"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_2024_elections/district_boundaries.geojson"</span>)</span>
<span id="cb1-30"></span>
<span id="cb1-31"></span>
<span id="cb1-32">results_raw <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rvest<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;">read_html</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://electionsbcenr.blob.core.windows.net/electionsbcenr/Results_7097_GE-2024-10-19_Candidate.html"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-33">  rvest<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;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"table#tblReport"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-34">  rvest<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;">html_table</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ED_NAME=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Electoral District</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Candidate=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Candidate's Ballot Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span>Affiliation,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total Valid Votes</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">% of Votes</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ED_NAME =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na_if</span>(ED_NAME,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(ED_NAME,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"down"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Candidate,Party), \(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Candidate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Party<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>,x))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(Party<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Unaffiliated"</span>,Party)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Votes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(),</span>
<span id="cb1-42">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">%"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Share))<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;">100</span>) </span>
<span id="cb1-43"></span>
<span id="cb1-44"></span>
<span id="cb1-45">close_races <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-46">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coquitlam-Burke Mountain"</span>,</span>
<span id="cb1-47">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Courtenay-Comox"</span>,</span>
<span id="cb1-48">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Juan de Fuca-Malahat"</span>,</span>
<span id="cb1-49">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna Centre"</span>,</span>
<span id="cb1-50">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Maple Ridge East"</span>,</span>
<span id="cb1-51">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Richmond-Steveston"</span>,</span>
<span id="cb1-52">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surrey City Centre"</span>,</span>
<span id="cb1-53">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surrey-Guildford"</span>,</span>
<span id="cb1-54">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surrey-Panorama"</span>,</span>
<span id="cb1-55">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver-Langara"</span>,</span>
<span id="cb1-56">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vernon-Lumby"</span></span>
<span id="cb1-57">)</span>
<span id="cb1-58"></span>
<span id="cb1-59">open_races <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-60">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Coquitlam-Burke Mountain",</span></span>
<span id="cb1-61">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "Courtenay-Comox",</span></span>
<span id="cb1-62">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "Juan de Fuca-Malahat",</span></span>
<span id="cb1-63">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "Kelowna Centre",</span></span>
<span id="cb1-64">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Maple Ridge East",</span></span>
<span id="cb1-65">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Richmond-Steveston",</span></span>
<span id="cb1-66">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Surrey City Centre",</span></span>
<span id="cb1-67">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "Surrey-Guildford"</span></span>
<span id="cb1-68">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Surrey-Panorama",</span></span>
<span id="cb1-69">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Vancouver-Langara",</span></span>
<span id="cb1-70">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#"Vernon-Lumby"</span></span>
<span id="cb1-71">)</span>
<span id="cb1-72"></span>
<span id="cb1-73">results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results_raw <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Advance voting ballot boxes|Final Voting Day ballot boxes|Out-of-district ballots|Status | In Progress| Complete"</span>,ED_NAME)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(district_boundaries <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(ED_NAME,ED_ID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ED_NAME"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ED_NAME"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-76">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">close=</span>ED_NAME <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> close_races,</span>
<span id="cb1-77">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">called=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(ED_NAME <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> open_races))</span>
<span id="cb1-78"></span>
<span id="cb1-79">tmp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fileext =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".csv"</span>)</span>
<span id="cb1-80">cleaned_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-81">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Party<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-82">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(Party,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC NDP"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BC Green Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GRN"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conservative Party"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CON"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Independent"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"IND"</span>,</span>
<span id="cb1-83">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Freedom Party of BC"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Libertarian"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LTN"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Christian Heritage Party of B.C."</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CHP"</span>,</span>
<span id="cb1-84">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Communist Party of BC"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"COM"</span> ))</span>
<span id="cb1-85">cleaned_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-86">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(ED_ID,Candidate,Party,Votes,called) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>( tmp)</span>
<span id="cb1-88">upload_result <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;">file_to_s3_gzip</span>(tmp,</span>
<span id="cb1-89">                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mountainmath"</span>,</span>
<span id="cb1-90">                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_2024_elections/results.csv"</span>)</span></code></pre></div></div>
</details>
</div>
<p>With the data in hand<sup>1</sup> we can on observable to draw our map. Regions that have not yet been called are coloured in a lighter shade of the party that is currently in the lead. The tooltip on hover shows the full riding results.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="129" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 128;"><span id="cb2-129">vote_map_animation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-130">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ratio <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-131">  </span>
<span id="cb2-132">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> tooltip <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>
<span id="cb2-133">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</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;">properties</span><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;">ED_NAME</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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-134">        (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;">properties</span><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;">called</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Winner: `</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Leading: `</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</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;">properties</span><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;">winner</span><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;">Candidate</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 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;">properties</span><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;">winner</span><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;">Party</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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-135">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Margin: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">comma</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;">properties</span><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;">results</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes</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;">properties</span><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;">results</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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">percent</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;">properties</span><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;">results</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes</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;">properties</span><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;">results</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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Votes</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;">properties</span><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;">Total</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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-136">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-137">        <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;">properties</span><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;">results</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;">map</span>(p <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;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>p<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;">Candidate</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>p<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;">Party</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">comma</span>(p<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;">Votes</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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>format<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;">percent</span>(p<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;">Votes</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;">properties</span><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;">Total</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-138">        ]<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;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb2-139"></span>
<span id="cb2-140">  </span>
<span id="cb2-141">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">select</span>(DOM<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;">svg</span>(width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height))</span>
<span id="cb2-142">      <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viewBox"</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;">"0 0 960 600"</span>)</span>
<span id="cb2-143">      <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;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</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;">"100%"</span>)</span>
<span id="cb2-144">      <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;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</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;">"auto"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-145">  </span>
<span id="cb2-146">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// render map</span></span>
<span id="cb2-147">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> path <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">geoPath</span>(projection)</span>
<span id="cb2-148"></span>
<span id="cb2-149">   svg<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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb2-150">     <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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path"</span>)</span>
<span id="cb2-151">     <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;">data</span>(districts)</span>
<span id="cb2-152">     <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;">enter</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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path"</span>)</span>
<span id="cb2-153">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</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;">"bcDistrict"</span>)</span>
<span id="cb2-154">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> district <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> district<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;">properties</span><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;">called</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> party_colors[district<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;">properties</span><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;">winner</span><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;">Party</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> party_colors2[district<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;">properties</span><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;">winner</span><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;">Party</span>])  </span>
<span id="cb2-155">     <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;">attr</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> path)</span>
<span id="cb2-156">     <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;">attr</span>(<span class="st" style="color: #20794D;
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;">"white"</span>)</span>
<span id="cb2-157">     <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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</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;">0.5</span>)</span>
<span id="cb2-158">     <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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>)</span>
<span id="cb2-159">     <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>(tooltip) </span>
<span id="cb2-160">   </span>
<span id="cb2-161">  <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">setInterval</span>(() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-162">    svg<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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".bcDistrict"</span>)</span>
<span id="cb2-163">      <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;">transition</span>()</span>
<span id="cb2-164">      <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;">delay</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">properties</span><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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb2-165">      <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;">duration</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>)</span>
<span id="cb2-166">      <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;">attrTween</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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) {</span>
<span id="cb2-167">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> flubber<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;">toCircle</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path</span>(d)<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;">x</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;">y</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;">properties</span><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;">radius</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;">maxSegmentLength</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-168">      })</span>
<span id="cb2-169"></span>
<span id="cb2-170">    svg<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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".bcDistrict"</span>)</span>
<span id="cb2-171">      <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;">transition</span>()</span>
<span id="cb2-172">      <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;">delay</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</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;">properties</span><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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb2-173">      <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;">duration</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>)</span>
<span id="cb2-174">      <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;">attrTween</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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) {</span>
<span id="cb2-175">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> flubber<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;">fromCircle</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;">x</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;">y</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;">properties</span><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;">radius</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;">path</span>(d)<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;">maxSegmentLength</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-176">      })</span>
<span id="cb2-177">  }<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;">25000</span>)</span>
<span id="cb2-178"></span>
<span id="cb2-179">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> svg<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;">node</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-180">}</span></code></pre></div></div>
</details>
<div id="fig-land-vs-people" class="cell-output cell-output-display quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-land-vs-people-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-land-vs-people-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Land does not vote, people do
</figcaption>
</figure>
</div>
</div>
<p>The animation interpolates between the geographies of the ridings, and bubbles for each riding of size proportional to the total vote count. This visualizes the degree to which the map view over-emphasizes rural areas, which predominantly went to the Conservatives, whereas electoral districts with high population density and consequently lower area were predominantly won by the NDP.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">lead_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaned_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(ED_ID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Votes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lead=</span>Votes<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;">lead</span>(Votes),</span>
<span id="cb3-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Votes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(Votes,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lead_share=</span>lead<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Total) </span>
<span id="cb3-9"></span>
<span id="cb3-10">tightest_race <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lead_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_min</span>(lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) </span></code></pre></div></div>
</details>
</div>
<p>Some ridings had a clear winner with a large lead, others are still quite tight. Figure&nbsp;2 we give an overview over the vote share lead in each riding, the tightest race right now is Surrey-Guildford, where the NDP currently holds a 22 vote (0.1 percentage point) lead.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">party_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CON=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#115DA8"</span>,</span>
<span id="cb4-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NDP=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F58220"</span>,</span>
<span id="cb4-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">IND=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#676767"</span>,</span>
<span id="cb4-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GRN=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3D9B35"</span></span>
<span id="cb4-6">)</span>
<span id="cb4-7">party_colours2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb4-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CON=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#83ACF5"</span>,</span>
<span id="cb4-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NDP=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFB38D"</span>,</span>
<span id="cb4-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">IND=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFCBB8"</span>,</span>
<span id="cb4-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GRN=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#84DA80"</span></span>
<span id="cb4-12">)</span>
<span id="cb4-13">party_colours_combined <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>(party_colours,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(party_colours2),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours2),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>)))</span>
<span id="cb4-14"></span>
<span id="cb4-15"></span>
<span id="cb4-16">lead_results <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in each riding"</span>,</span>
<span id="cb4-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point lead"</span>,</span>
<span id="cb4-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb4-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-party-lead-by-riding" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-party-lead-by-riding-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/fig-party-lead-by-riding-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-party-lead-by-riding-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The vote share margind by which each party candidate is currently in the lead in each riding.
</figcaption>
</figure>
</div>
</div>
</div>
<section id="update-oct-23-2024" class="level2">
<h2 class="anchored" data-anchor-id="update-oct-23-2024">Update (Oct 23, 2024)</h2>
<p>Elections BC is still regularly updating vote counts, for convenience we added a graph with just the 11 races that CBC has not yet called. We will updated this regularly as updated voting results come in. Fore reference we kept some of the older version in the tabs.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">Nov 8, 2024</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Oct 28, 2024 - 6:50pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-3" aria-controls="tabset-1-3" aria-selected="false" href="">Oct 28, 2024 - 5pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-4" aria-controls="tabset-1-4" aria-selected="false" href="">Oct 28, 2024 - 4pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-5-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-5" aria-controls="tabset-1-5" aria-selected="false" href="">Oct 28, 2024 - 3pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-6-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-6" aria-controls="tabset-1-6" aria-selected="false" href="">Oct 28, 2024 - 2pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-7-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-7" aria-controls="tabset-1-7" aria-selected="false" href="">Oct 28, 2024 - 1pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-8-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-8" aria-controls="tabset-1-8" aria-selected="false" href="">Oct 28, 2024 - 12pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-9-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-9" aria-controls="tabset-1-9" aria-selected="false" href="">Oct 28, 2024 - 11am</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-10-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-10" aria-controls="tabset-1-10" aria-selected="false" href="">Oct 28, 2024 - 10am</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-11-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-11" aria-controls="tabset-1-11" aria-selected="false" href="">Oct 27, 2024 - 8:30pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-12-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-12" aria-controls="tabset-1-12" aria-selected="false" href="">Oct 27, 2024 - 5:40pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-13-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-13" aria-controls="tabset-1-13" aria-selected="false" href="">Oct 27, 2024 - 1pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-14-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-14" aria-controls="tabset-1-14" aria-selected="false" href="">Oct 26, 2024 - 4pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-15-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-15" aria-controls="tabset-1-15" aria-selected="false" href="">Oct 26, 2024 - 1pm</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-16-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-16" aria-controls="tabset-1-16" aria-selected="false" href="">Oct 25, 2024</a></li></ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>(lead_results,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-11-08.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb5-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb5-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb5-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-6:50pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb6-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb6-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb6-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-3" class="tab-pane" aria-labelledby="tabset-1-3-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-5pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb7-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb7-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb7-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb7-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-4" class="tab-pane" aria-labelledby="tabset-1-4-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-4pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb8-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb8-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb8-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb8-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-5" class="tab-pane" aria-labelledby="tabset-1-5-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-3pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb9-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb9-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb9-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb9-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-6" class="tab-pane" aria-labelledby="tabset-1-6-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-2pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb10-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb10-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb10-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-7" class="tab-pane" aria-labelledby="tabset-1-7-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-1pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb11-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb11-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb11-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-8" class="tab-pane" aria-labelledby="tabset-1-8-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-12pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb12-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb12-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb12-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb12-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-9" class="tab-pane" aria-labelledby="tabset-1-9-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-11am.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb13-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb13-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb13-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb13-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-10" class="tab-pane" aria-labelledby="tabset-1-10-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-28-10am.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb14-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb14-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb14-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb14-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<!--## Oct 28, 2024 - 9am-->
</div>
<div id="tabset-1-11" class="tab-pane" aria-labelledby="tabset-1-11-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-27-8pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb15-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb15-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb15-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-12" class="tab-pane" aria-labelledby="tabset-1-12-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-27-5pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb16-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb16-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb16-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<!--## Oct 27, 2024 - 4pm-->
</div>
<div id="tabset-1-13" class="tab-pane" aria-labelledby="tabset-1-13-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-27-1pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb17-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb17-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb17-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb17-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-18-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-14" class="tab-pane" aria-labelledby="tabset-1-14-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-26-4pm.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <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;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Party_call=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Party, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(called,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (lead)"</span>))) <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;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party_call))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <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;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours_combined,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(party_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb18-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb18-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb18-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb18-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-19-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-15" class="tab-pane" aria-labelledby="tabset-1-15-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-26-1pm.rds"</span>) <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;">filter</span>(close) <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;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">override.aes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>party_colours[<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;">"CON"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP"</span>)]))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb19-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb19-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb19-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-20-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-16" class="tab-pane" aria-labelledby="tabset-1-16-tab">
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simpleCache</span>({},<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bc_elections_2024_results-2024-10-25.rds"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">close=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>called) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(close) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>lead_share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(ED_NAME,lead_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Party))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>scales<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;">comma</span>(lead,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vote lead"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(lead_share<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.01</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>party_colours2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(d)scales<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;">percent</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">override.aes=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>party_colours[<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;">"CON"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NDP"</span>)]))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party lead in races CBC has not called yet"</span>,</span>
<span id="cb20-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage point vote lead"</span>,</span>
<span id="cb20-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Party"</span>,</span>
<span id="cb20-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Elections BC"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/index_files/figure-html/unnamed-chunk-21-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<details>
<summary>
Remaining Observable code
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" data-startfrom="572" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 571;"><span id="cb21-572">applySimulation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (nodes) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb21-573">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> simulation <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">forceSimulation</span>(nodes)</span>
<span id="cb21-574">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceX</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;">x</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">2</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;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>))</span>
<span id="cb21-575">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceY</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;">y</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">5</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;">8</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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>))</span>
<span id="cb21-576">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceX</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;">x</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">projection</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;">properties</span><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;">x</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;">properties</span><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;">y</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>))</span>
<span id="cb21-577">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceY</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;">y</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">projection</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;">properties</span><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;">x</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;">properties</span><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;">y</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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>))</span>
<span id="cb21-578">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"charge"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceManyBody</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;">strength</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="cb21-579">    <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;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collide"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<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;">forceCollide</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;">radius</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</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;">properties</span><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;">radius</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nodePadding)<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;">strength</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb21-580">    <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;">stop</span>()</span>
<span id="cb21-581"></span>
<span id="cb21-582">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <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>
<span id="cb21-583">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (simulation<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;">alpha</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>) {</span>
<span id="cb21-584">    simulation<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;">tick</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb21-585">    i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++;</span></span>
<span id="cb21-586">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//console.log(`${Math.round(100*i/200)}%`)</span></span>
<span id="cb21-587">  }</span>
<span id="cb21-588"></span>
<span id="cb21-589">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> simulation<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;">nodes</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb21-590">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" data-startfrom="594" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 593;"><span id="cb22-594">spreadDistricts <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;">applySimulation</span>(districts)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" data-startfrom="598" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 597;"><span id="cb23-598">maxRadius <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;">15</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" data-startfrom="602" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 601;"><span id="cb24-602">ratio <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></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" data-startfrom="606" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 605;"><span id="cb25-606">nodePadding <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.3</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" data-startfrom="610" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 609;"><span id="cb26-610">party_colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb26-611">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb26-612">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">CON</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;">"#115DA8"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb26-613">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">NDP</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;">"#F58220"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb26-614">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">IND</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;">"#676767"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb26-615">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">GRN</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;">"#3D9B35"</span></span>
<span id="cb26-616">  }</span>
<span id="cb26-617">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" data-startfrom="621" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 620;"><span id="cb27-621">party_colors2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb27-622">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb27-623">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">CON</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;">"#83ACF5"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb27-624">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">NDP</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;">"#FFB38D"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb27-625">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">IND</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;">"#FFCBB8"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb27-626">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">GRN</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;">"#84DA80"</span></span>
<span id="cb27-627">  }</span>
<span id="cb27-628">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" data-startfrom="634" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 633;"><span id="cb28-634">format <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb28-635">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">density</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".2s"</span>)(x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".3r"</span>)(x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-636">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">percent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".1%"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb28-637">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">comma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<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;">format</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">",.0f"</span>)</span>
<span id="cb28-638">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" data-startfrom="642" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 641;"><span id="cb29-642">projection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">geoIdentity</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;">reflectY</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fitSize</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">960</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;">600</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;">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;">"FeatureCollection"</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;">features</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> districts})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" data-startfrom="646" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 645;"><span id="cb30-646">districts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bc_districts<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;">features</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" data-startfrom="650" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 649;"><span id="cb31-650">bc_districts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { </span>
<span id="cb31-651">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://mountainmath.s3.ca-central-1.amazonaws.com/bc_2024_elections/district_boundaries.geojson"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb31-652">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> bc_districts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> d3<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;">json</span>(url)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb31-653">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> bc_results_all <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> d3<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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://mountainmath.s3.ca-central-1.amazonaws.com/bc_2024_elections/results.csv"</span>)</span>
<span id="cb31-654">    </span>
<span id="cb31-655">    </span>
<span id="cb31-656">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> bc_results <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 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;">Set</span>(bc_results_all<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> 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;">ED_ID</span>))]</span>
<span id="cb31-657">    <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;">reduce</span>((hash<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> elem) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb31-658">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bc_results_all<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>(r <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> r<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;">ED_ID</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> elem)</span>
<span id="cb31-659">        <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> {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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">parseInt</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;">Votes</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb31-660">                  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span>(d)})</span>
<span id="cb31-661">        <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;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b<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;">Votes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>a<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;">Votes</span>)</span>
<span id="cb31-662">      hash[elem] <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;">results</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb31-663">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Total</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>d3<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;">sum</span>(rs<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> 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;">Votes</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb31-664">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">called</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">called</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;">"TRUE"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb31-665">                    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">winner</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>rs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]}</span>
<span id="cb31-666">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> hash</span>
<span id="cb31-667">          }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {})</span>
<span id="cb31-668">  </span>
<span id="cb31-669">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> voteMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">max</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">keys</span>(bc_results)<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> bc_results[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;">Total</span>)</span>
<span id="cb31-670">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> radiusScale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<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;">scaleSqrt</span>()</span>
<span id="cb31-671">      <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;">domain</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> voteMax])</span>
<span id="cb31-672">      <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;">range</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> maxRadius]) </span>
<span id="cb31-673">  </span>
<span id="cb31-674">  bc_districts<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;">features</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;">forEach</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb31-675">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bc_results[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;">properties</span><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;">ED_ID</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;">toString</span>()]</span>
<span id="cb31-676">      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;">properties</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb31-677">        <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;">properties</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb31-678">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>rp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb31-679">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">radius</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;">properties</span><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;">mainShape</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;">radiusScale</span>(rp<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;">Total</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>
<span id="cb31-680">      }</span>
<span id="cb31-681">  })</span>
<span id="cb31-682">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> bc_districts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb31-683">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" data-startfrom="688" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 687;"><span id="cb32-688">d3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d3@5"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-13" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" data-startfrom="692" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 691;"><span id="cb33-692">turf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@turf/turf@5"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-14" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" data-startfrom="696" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 695;"><span id="cb34-696">flubber <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/flubber'</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-15" data-nodetype="declaration">

</div>
</div>
</div>
</details>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-10-20-bc-election-2024/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb35-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-11-08 14:43:48 PST"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb37-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [4bf0a38] 2024-10-30: freeze for final count of bc election results (not yet accounting for manual recounts).</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb39-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] sf_1.0-16                 mountainmathHelpers_0.1.4
 [3] lubridate_1.9.3           forcats_1.0.0            
 [5] stringr_1.5.1             dplyr_1.1.4              
 [7] purrr_1.0.2               readr_2.1.5              
 [9] tidyr_1.3.1               tibble_3.2.1             
[11] ggplot2_3.5.1             tidyverse_2.0.0          

loaded via a namespace (and not attached):
 [1] gtable_0.3.5        xfun_0.47           htmlwidgets_1.6.4  
 [4] websocket_1.4.1     processx_3.8.4      tzdb_0.4.0         
 [7] ps_1.7.6            vctrs_0.6.5         tools_4.4.1        
[10] generics_0.1.3      parallel_4.4.1      curl_5.2.2         
[13] proxy_0.4-27        fansi_1.0.6         pkgconfig_2.0.3    
[16] R.oo_1.26.0         KernSmooth_2.23-24  lifecycle_1.0.4    
[19] git2r_0.33.0        farver_2.1.2        compiler_4.4.1     
[22] munsell_0.5.1       chromote_0.2.0      htmltools_0.5.8.1  
[25] class_7.3-22        yaml_2.3.10         crayon_1.5.2       
[28] later_1.3.2         pillar_1.9.0        R.utils_2.12.3     
[31] aws.s3_0.3.21       classInt_0.4-10     mime_0.12          
[34] tidyselect_1.2.1    rvest_1.0.4         digest_0.6.37      
[37] stringi_1.8.4       labeling_0.4.3      fastmap_1.2.0      
[40] grid_4.4.1          colorspace_2.1-0    cli_3.6.3          
[43] magrittr_2.0.3      base64enc_0.1-3     utf8_1.2.4         
[46] e1071_1.7-14        aws.signature_0.6.0 withr_3.0.1        
[49] promises_1.3.0      scales_1.3.0        bit64_4.0.5        
[52] timechange_0.3.0    rmarkdown_2.28      httr_1.4.7         
[55] bit_4.0.5           R.methodsS3_1.8.2   hms_1.1.3          
[58] evaluate_1.0.0      knitr_1.48          rlang_1.1.4        
[61] Rcpp_1.0.13         glue_1.8.0          DBI_1.2.3          
[64] selectr_0.4-2       geojsonsf_2.0.3     xml2_1.3.6         
[67] vroom_1.6.5         rstudioapi_0.16.0   jsonlite_1.8.8     
[70] R6_2.5.1            units_0.8-5        </code></pre>
</div>
</div>
</details>



</section>


<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-elections-fun.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2019. <em>Elections Fun</em>. <a href="https://doodles.mountainmath.ca/posts/2019-10-22-elections-fun/">https://doodles.mountainmath.ca/posts/2019-10-22-elections-fun/</a>.
</div>
<div id="ref-elections-fun-2021-edition.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2021. <em>Elections Fun - 2021 Edition</em>. <a href="https://doodles.mountainmath.ca/posts/2021-09-25-elections-fun-2021-edition/">https://doodles.mountainmath.ca/posts/2021-09-25-elections-fun-2021-edition/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>We placed the data separately online to not interfere with page loading, and load it separately in via javascript.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{bc-election-2024.2024,
  author = {{von Bergmann}, Jens},
  title = {BC {Election} 2024},
  date = {2024-10-20},
  url = {https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann. 2024. <span>“BC Election 2024.”</span>
<em>MountainDoodles</em>, accepted, October 20. <a href="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/">https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/</a>.
</div></div></section></div> ]]></description>
  <category>geeky</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/</guid>
  <pubDate>Sun, 20 Oct 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-10-20-bc-election-2024/images/land_vs_people.png" medium="image" type="image/png" height="73" width="144"/>
</item>
<item>
  <title>Distributional effects of adding housing</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/08/14/distributional-effects-of-adding-housing/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>Who would benefit from dramatically expanding the supply of housing in the market? How would such an expansion address housing need? What non-market interventions would still be required to meet remaining need? How would it influence household formation and migration? This post is picking up where we left off on our housing targets post <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span>, grappling with the distributional effects of adding new housing to the market. To recap: one way of setting housing targets is to figure out how much housing municipalities would have if they weren’t actively restricting its construction. We can do that by estimating how much additional housing would be profitable to build. Setting that amount of housing as a target works to enable market mechanisms to bring housing supply in line with demand.</p>
<p>Our version of housing targets sets a (high) overall target number for net new housing, and that’s it. There are other versions of targets that attempt to more finely tailor numbers, keyed for instance to specific income bands. Here we explain why we think starting with an overall number is the right approach, insofar as adding housing has distributional effects across the entire system. It is generally understood that increasing the housing supply lowers prices of existing housing, all else being equal. What’s less clear are the systemic effects of adding housing and how even expensive new housing helps address underlying housing need. These broad distributional effects of reaching housing targets are what we want to address here.</p>
<section id="tldr" class="level1">
<h1>TL;DR</h1>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">pumf_2021 <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;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_lower=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"Under $2,000"</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;">0</span>,</span>
<span id="cb1-4">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+"</span>)))),</span>
<span id="cb1-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_upper=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"$250,000 and over"</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;">350000</span>,</span>
<span id="cb1-6">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+$"</span>))))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_income=</span>(hh_lower<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>hh_upper)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent=</span>hh_income<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.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent2=</span>hh_income<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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent,<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;">|&gt;</span></span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent2,<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;">|&gt;</span></span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(TENUR,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter or Dwelling provided by the local government, First Nation or Indian band"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other census metropolitan areas, census agglomerations and other geographies"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>)</span>
<span id="cb1-15"></span>
<span id="cb1-16">pumf_2016 <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;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_lower=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"Under $2,000"</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;">0</span>,</span>
<span id="cb1-19">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+"</span>)))),</span>
<span id="cb1-20">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_upper=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"$250,000 and over"</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;">350000</span>,</span>
<span id="cb1-21">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+$"</span>))))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TOTINC,SHELCO),as.numeric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TOTINC=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(TOTINC<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;">88888888</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,TOTINC)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_income=</span>(hh_lower<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>hh_upper)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent=</span>hh_income<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.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent2=</span>hh_income<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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent,<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;">|&gt;</span></span>
<span id="cb1-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent2,<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;">|&gt;</span></span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(TENUR,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented or Band housing"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned by a member of the household"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other census metropolitan areas, census agglomerations and other geographies"</span>,</span>
<span id="cb1-31">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury – Thunder Bay"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury / Grand Sudbury – Thunder Bay"</span>,</span>
<span id="cb1-32">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna – Abbotsford-Mission"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna – Abbotsford"</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)</span>
<span id="cb1-34"></span>
<span id="cb1-35">pumf_2011 <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;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_lower=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"Under $2,000"</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;">0</span>,</span>
<span id="cb1-38">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+"</span>)))),</span>
<span id="cb1-39">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_upper=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(HHINC<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;">"$250,000 and over"</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;">350000</span>,</span>
<span id="cb1-40">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$|,"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(HHINC),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">$[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d,]+$"</span>))))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TENUR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(TENUR,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Renter"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rented or Band housing"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owned by a member of the household"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TOTINC,GROSRT,OMP),as.numeric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TOTINC=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(TOTINC<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;">88888888</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,TOTINC),</span>
<span id="cb1-44">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GROSRT=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(GROSRT<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;">8888</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,GROSRT),</span>
<span id="cb1-45">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OMP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(OMP<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;">8888</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,OMP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SHELCO=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(GROSRT,OMP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hh_income=</span>(hh_lower<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>hh_upper)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent=</span>hh_income<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.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_rent2=</span>hh_income<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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent,<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;">|&gt;</span></span>
<span id="cb1-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent2,<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;">|&gt;</span></span>
<span id="cb1-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other census metropolitan areas, census agglomerations and other geographies"</span>,</span>
<span id="cb1-53">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury – Thunder Bay"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Greater Sudbury / Grand Sudbury – Thunder Bay"</span>,</span>
<span id="cb1-54">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna – Abbotsford-Mission"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Kelowna – Abbotsford"</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>)</span>
<span id="cb1-56"></span>
<span id="cb1-57"></span>
<span id="cb1-58">pumf_selects <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;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AGEGRP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PRIHM"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TENUR"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HCORENEED_IND"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SHELCO"</span>,</span>
<span id="cb1-59">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BEDRM"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MOB1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MOB5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TOTINC"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EFDECILE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SUBSIDY"</span>,</span>
<span id="cb1-60">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hh_income"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max_rent"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max_rent2"</span>,</span>
<span id="cb1-61">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gap"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gap2"</span>,<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;">"WEIGHT"</span>)</span>
<span id="cb1-62"></span>
<span id="cb1-63">pumf_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;">bind_rows</span>(pumf_2011 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</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;">any_of</span>(pumf_selects)),</span>
<span id="cb1-64">                       pumf_2016 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</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;">any_of</span>(pumf_selects)),</span>
<span id="cb1-65">                       pumf_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</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;">any_of</span>(pumf_selects))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">EFDECILE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(EFDECILE,</span>
<span id="cb1-68">                             <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;">setNames</span>(pumf_2021<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EFDECILE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(),</span>
<span id="cb1-69">                                         pumf_2016<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EFDECILE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())),</span>
<span id="cb1-70">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(SUBSIDY,</span>
<span id="cb1-71">                             <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;">setNames</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;">"Not subsidized"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>),</span>
<span id="cb1-72">                                         <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;">"No, not a subsidized dwelling"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes, a subsidized dwelling"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span> ))))</span>
<span id="cb1-73"></span>
<span id="cb1-74">pd1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Vancouver"</span>,Year<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;">"2011"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-76">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(gap),TENUR<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;">"Not available"</span>,PRIHM <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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-77">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb1-78">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb1-79"></span>
<span id="cb1-80">tenure_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c071,<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;">"Renter"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span>))</span>
<span id="cb1-81"></span>
<span id="cb1-82">price_fact <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span></span>
<span id="cb1-83">pd2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-84">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fact=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(TENUR<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;">"Owner"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,price_fact)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-85">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>fact<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent,<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;">|&gt;</span></span>
<span id="cb1-86">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(SHELCO<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;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>fact<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>max_rent2,<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;">|&gt;</span></span>
<span id="cb1-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(gap),PRIHM <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;">"Not applicable"</span>,TENUR<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-88">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb1-89">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<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;">|&gt;</span></span>
<span id="cb1-90">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Vancouver"</span>,Year<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;">"2011"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-91">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb1-92">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cw2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gap2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,WEIGHT,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb1-93"></span>
<span id="cb1-94">effect_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c070,<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;">"Actual"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">housing target"</span>))</span>
<span id="cb1-95"></span>
<span id="cb1-96">inflation <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;">get_cansim_vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v41690973"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-97">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m"</span>)<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;">"05"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-98">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-99">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-100">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-101">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CPI=</span>VALUE<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;">last</span>(VALUE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-102">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,CPI)</span>
<span id="cb1-103"></span>
<span id="cb1-104"></span>
<span id="cb1-105">summary_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;">bind_rows</span>(pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">housing target"</span>),</span>
<span id="cb1-106">                          pd1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-107">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(effect_colours))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-108">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-109">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-110">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-111">  <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;">Households=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb1-112">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb1-113">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Type,TENUR,HCORENEED_IND,Year)) </span>
<span id="cb1-114"></span>
<span id="cb1-115">summary_data_people <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;">bind_rows</span>(pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">housing target"</span>),</span>
<span id="cb1-116">                                 pd1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-117">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(effect_colours))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-118">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-119">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-120">  <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;">People=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb1-121">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb1-122">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Type,TENUR,HCORENEED_IND,Year)) </span>
<span id="cb1-123"></span>
<span id="cb1-124">total_change <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-125">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb1-126">  <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;">Households=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Households),</span>
<span id="cb1-127">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-128">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>Households) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-129">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">difference=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">housing target</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-130">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_change=</span>difference<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-131">  janitor<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;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-132">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(year))</span>
<span id="cb1-133"></span>
<span id="cb1-134">total_change_chn <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-135">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HCORENEED_IND<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;">"In core need"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-136">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb1-137">  <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;">Households=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Households),</span>
<span id="cb1-138">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-139">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>Households) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-140">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">difference=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">housing target</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-141">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_change=</span>difference<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-142">  janitor<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;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-143">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(year))</span>
<span id="cb1-144"></span>
<span id="cb1-145">total_change2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-146">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb1-147">  <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;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(gap),</span>
<span id="cb1-148">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-149">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>gap) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-150">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">difference=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">housing target</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-151">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_change=</span>difference<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-152">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(inflation,<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;">"Year"</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-153">  janitor<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;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-154">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-155">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_successful_housing_target=</span>successful_housing_target<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>cpi,</span>
<span id="cb1-156">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_actual=</span>actual<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>cpi)</span>
<span id="cb1-157"></span>
<span id="cb1-158">total_change3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_data_people <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-159">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Year=="2021") |&gt;</span></span>
<span id="cb1-160">  <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;">People=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(People),</span>
<span id="cb1-161">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-162">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from=</span>People) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-163">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">difference=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">housing target</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-164">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_change=</span>difference<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-165">  janitor<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;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-166">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(year))</span></code></pre></div></div>
</details>
</div>
<p>Housing is good, and adding a lot more of it in the places people want to live would have broadly beneficial effects. Even if new housing tends to house (slightly) higher income households, the vacancy chain moves these households set in motion have systemic effects, freeing up housing all across the income spectrum. To illustrate, our housing targets are set to reduce the price of new housing by roughly 30% in Metro Vancouver. We estimate this would reduce rents by an equivalent amount, and holding households constant we can further estimate this would reduce the population experiencing Core Housing Need by around 35%. The annual monetary subsidy necessary to make housing affordable for all Metro Vancouver households would drop from $1.48bn to $0.68bn. We further refine this estimate by relaxing the assumption that households would remain constant, considering the effects of meeting housing targets on new household formation and net migration. Our estimates of Core Housing Need still decline, but not by as much. We also consider the effects of rent control on who benefits from a boost to housing supply. Finally we consider the implications of these distributional effects. Finely tailored housing targets can be misleading and counterproductive when they fail to account for distributional effects of adding supply overall.</p>
</section>
<section id="introduction-and-overview" class="level1">
<h1>Introduction and Overview</h1>
<p>In this post we want to achieve a number of things:</p>
<ol type="1">
<li>quickly review what’s known about filtering through vacancy chains as the main mechanism by why effects of adding new, generally expensive, housing are transmitted throughout the housing system</li>
<li>outline results from the literature on how filtering works at the scale of the housing market depending on the scarcity of housing</li>
<li>take a look at some empirical data and studies on the impact of adding housing on rents at different points in the rent spectrum</li>
<li>estimate the effect of adding new housing on lifting households out of core housing need, and more generally out of housing unaffordability (taken as shelter cost to income ratio exceeding 30%), assuming households as fixed, following similar work by <span class="citation" data-cites="corinth2023">(Corinth and Irvine 2023)</span> in the US context</li>
<li>drop the assumption of fixed households and estimate the effect on household formation, which likely will increase the number of people in core housing need or unaffordable housing.</li>
<li>drop the assumption of fixed population and add a rough estimate of the effect on in-migration.</li>
<li>tie this back into the broader discussion around housing targets, and explain why creating targets for market housing based on household income bands does not make sense and can do more harm than good.</li>
</ol>
<p>By way of an overview, adding new (generally expensive) housing to the market has positive effects throughout the housing spectrum as new housing acts as “priming the pump” on chains of moves, enabling people to better match their housing preferences, lowering prices and rents throughout. There are some complexities, but adding housing is broadly progressive and results in a net transfer of income from existing landlords to tenants. On a system level, housing tends to filter down the income distribution as it ages if the housing market has adequate supply, but it filters up if housing is constrained and in high demand.</p>
<p>Places in the US that saw high rates of apartment construction saw rents fall through the spectrum, with particularly steep declines at the lower end of the spectrum. Data from New Zealand indicates that their upzoning lowered rents at the upper and the lower spectrum more than it did in the middle. This leads us to believe that the effects of new housing on prices and rents are transmitted broadly through the system, and we follow <span class="citation" data-cites="corinth2023">(Corinth and Irvine 2023)</span> to assume a (simplified) uniform prices effect throughout. This means that e.g.&nbsp;achieving the housing targets estimates we did for Metro Vancouver would reduce rents by about 30%, and keeping households fixed, this would lift about 35% of the households out of core housing need, and about 38% out of housing unaffordability. In effect, even if new housing brought to market doesn’t go directly to households most in need, it can still benefit households most in need because housing is a system.</p>
<p>To follow a good metaphor, our housing system operates like a game of musical chairs. Just like taking away chairs results in more losers, adding chairs results in more winners. Just like the slowest may benefit the most from adding more chairs, those most in need can benefit the most from adding more housing. But there’s a catch: our housing system operates like a game of musical chairs where people can share a chair. In the housing system, we talk about those sharing a chair as a household. All too often (as in common measures of housing need) we imagine households are fixed. In fact, those most in need are often stuck sharing chairs with others. If there were more chairs, they could get one of their own. The willingness of those sharing a chair to sprint for a new chair, if one was added, speeds up the game for everyone.</p>
<p>Here we note that households are malleable and our current rates of doubling up and suppressed households are the result of high housing costs. Conversely the desperation of people to change their current living situation and the compromises they make financially and socially are expressed in high housing costs. Modelling the resulting household formation of young adults moving out of their parent’s place or roommate households will undo some of the gains in our affordability metrics, with e.g.&nbsp;a young adult moving from a highly affordable arrangement of living with parents into a place of their own where they might be financially stressed. While it is important to model these effects on the affordability metrics, it’s also prudent to point out that these are choice moves and the young adults in question have, from their perspective, generally improved their housing outcomes.</p>
<p>Relating this back to targets that attempt to fix new housing brought to market to specific household income bands, they tend to ignore: a) the systemic effects of adding new housing throughout the spectrum; b) that households (and their incomes) are malleable and a very important part of housing policy is to enable household formation; and c) that there is no decent allocation mechanism to allocate market housing to specific income bands, making policy solutions impractical. Policies that aim to create new housing at specific household income bands are generally well-meaning, but where designed poorly may act to reduce the overall amount of housing produced, with regressive effects on the population.</p>
<p>The place where targeting housing to (family, not household) income bands makes sense, and indeed is necessary, is in housing distributed by need outside of markets. Like most around the world, Canada’s housing system is hybrid, with a relatively small segment of housing distributed by waitlists and other means. There are plenty of arguments for boosting this segment further, but chief among these is often the argument that markets aren’t meeting housing needs. Here we want to know not just how much need currently remains unaddressed by markets, but also how much need would continue to remain unaddressed if we added (or subtracted) to the housing supply distributed within the market. Estimating need that can not be met within market has to take into consideration the effects of new market housing, and can be derived from our distributional estimates that also consider household formation and family composition.</p>
<p>Our findings illustrate how non-market and market housing are complementary at meeting need within our hybrid systems, rather than in competition. Returning to the musical chairs metaphor, some chairs could be reserved and assigned by something other than speed. But how many chairs you would need to insure everyone had a seat would remain constant regardless of how they were distributed.</p>
</section>
<section id="vacancy-or-moving-chains" class="level1">
<h1>Vacancy (or moving) chains</h1>
<p>Vacancy chains, or how people move between our musical chairs, is a large topic, and we will approach this slowly. First we should appreciate that people move. A lot.</p>
<section id="movers" class="level2">
<h2 class="anchored" data-anchor-id="movers">Movers</h2>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">get_movers_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb2-2">  movers_data_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/movers_data.rds"</span>)</span>
<span id="cb2-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (refresh <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(movers_data_path)) {</span>
<span id="cb2-4">    pumf_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> canpumf<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;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021 (hierarchical)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-6">    movers_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary household maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-8">      <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;">WEIGHT=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB1,MOB5,AGEGRP,TENUR,BUILT,DTYPE,CMA))</span>
<span id="cb2-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(movers_data, movers_data_path)</span>
<span id="cb2-10">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb2-11">    movers_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;">readRDS</span>(movers_data_path)</span>
<span id="cb2-12">  }</span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(movers_data)</span>
<span id="cb2-14">}</span>
<span id="cb2-15"></span>
<span id="cb2-16">movers_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;">get_movers_data</span>()</span>
<span id="cb2-17"></span>
<span id="cb2-18">total_movers1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1 <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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-21">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB1)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb2-26"></span>
<span id="cb2-27">total_movers5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-28">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB5)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb2-33"></span>
<span id="cb2-34">new_movers <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BUILT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_housing=</span> BUILT <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;">"2016 to 2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-38">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(new_housing)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) </span>
<span id="cb2-40"></span>
<span id="cb2-41">new_built <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BUILT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-43">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(BUILT)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BUILT <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;">"2016 to 2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb2-48"></span>
<span id="cb2-49">mob_colours <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;">setNames</span>(MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Egypt"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(movers_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>MOB5),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))</span></code></pre></div></div>
</details>
</div>
<p>11% of Canada’s households<sup>1</sup> lived at a different address on census day in 2021 than a year prior, identifying them as movers. And comparing addresses enables StatCan to identify the start and end points of moves, as Figure&nbsp;1 shows, with a little over half of all movers moving within the same municipality or CSD. StatCan labels these movers “non-migrants” to compare to migrants, with the latter including those moving between municipalities, either within the same census district; between census districts within the same province; or between provinces. There are some complications due to geography (e.g.&nbsp;Vancouver has lots of municipalities in its census district while the City of Toronto is it’s own census district), but generally moves further down the figure represent moves across greater distances, and the data speak to a common pattern: most moves are local.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB1)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MOB1),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>MOB1)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">percent_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mob_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of movers by 1-year mobility status"</span>,</span>
<span id="cb3-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of residence 1 year prior"</span>,</span>
<span id="cb3-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of households"</span>,</span>
<span id="cb3-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (hierarchical)"</span></span>
<span id="cb3-14">  ) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-movers-mob1-status" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-movers-mob1-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-movers-mob1-status-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-movers-mob1-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Share of the population that moved residences in the year preceding the census, split by where they moved from. <em>Non-migrants</em> are people who moved within the same municipality (census subdivision, CSD).
</figcaption>
</figure>
</div>
</div>
</div>
<p>Lengthening our view of how often people move, we can look at 5-year mobility data. Based on 2021 data, we can estimate that nearly 2 in 5 people (38% of the population) will move across a 5-year period.<sup>2</sup> That’s substantially less than one might naively expect from extrapolating the 1-year mover share, but some people move several times in a 5-year period. In particular, those making big moves, e.g.&nbsp;between regions, may also subsequently make more small moves afterwards, as they adjust their housing based on accumulation of local knowledge. This can help explain why 5-year address change data shows an overrepresentation of big moves relative to the more local moves dominating 1-year address change comparisons, insofar as all the little moves that frequent movers make only show up as one address change across the 5-years recorded by census data. Figure&nbsp;2 gives the corresponding breakdown for 5-year mover status.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB5)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MOB5),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>MOB5)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">percent_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mob_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of movers by 5-year mobility status"</span>,</span>
<span id="cb4-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of residence 5 years prior"</span>,</span>
<span id="cb4-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of households"</span>,</span>
<span id="cb4-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (hierarchical)"</span></span>
<span id="cb4-13">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-movers-mob5-status" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-movers-mob5-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-movers-mob5-status-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-movers-mob5-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Share of the population that moved residences in the five years preceding the census, split by where they lived fiver years prior. <em>Non-migrants</em> are people who moved within the same municipality (census subdivision, CSD). Some people may have moved multiple times in the five year time frame.
</figcaption>
</figure>
</div>
</div>
</div>
<p>What kind of housing did these movers move into? Only 6.8% of Canada’s (occupied) housing stock was built January 2016 to May 2021, so the majority moved into old housing. In Figure&nbsp;3 we make that more precise by looking at mobility status by year the housing was built.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">movers_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BUILT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB5,BUILT)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>BUILT) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>BUILT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>MOB5)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">percent_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mob_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of movers by year housing was built"</span>,</span>
<span id="cb5-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Period housing was built"</span>,</span>
<span id="cb5-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Place of residence 5 years prior"</span>,</span>
<span id="cb5-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of households in particular period housing was built"</span>,</span>
<span id="cb5-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021 PUMF (hierarchical)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-movers-mob-status-year-built" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-movers-mob-status-year-built-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-movers-mob-status-year-built-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-movers-mob-status-year-built-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Share of the population that moved residences in the five years preceding the census, split by where they lived fiver years prior and year of construction of the structure they moved into. Almost all buildings built since 2016 got moved into in the five years prior to May 2021, but a small share were already moved in in the first half of 2016. Building age is self-reported, and there might be some small variation in how people report the year of construction.
</figcaption>
</figure>
</div>
</div>
</div>
<p>New housing, of course, mostly contains new movers insofar as people generally don’t live on construction sites (though there are some mismatches in age of housing and timing of move, which explain why we don’t reach 100%). With the exception of housing built in 2016 to 2021, people move at pretty comparable rates regardless of when the housing was built and only around 16% of all households that moved did so into new housing while around 84% moved into old housing. Are there big differences in who moves into new versus old housing in Canada?</p>
<p>In Figure&nbsp;4 we check directly into the income deciles, adjusted for family size, of those moving into new housing versus those moving into old housing. We will do this for both the 2016 and 2021 years, remaining mindful that 2021 was an odd year, in particular with regard to the 2020 incomes reported in the Census. Pandemic impacts reduced incomes for some while at the same time Covid supports boosted incomes for a partially overlapping segment. For this comparison we also conservatively removed recent movers to avoid cases where low census incomes (reported from the previous year) were least likely to reflect current income to housing situations (e.g.&nbsp;when people had recently left school and moved for a new job).</p>
<p>Comparing both census years, we can see that there are some differences between new and old housing, with those moving into new housing being slightly overrepresented in higher income deciles relative to those moving into older housing. This pattern was stronger in 2016 than 2021. By 2021, the median mover into new housing is in the sixth income decile, while the median mover into old housing is in the fifth. Importantly, and across both Census years, both old and new housing contain all adjusted family income deciles. We can see that even without filtering effects, new housing directly houses even the lowest income households.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">pumf_data_income <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mountainmathHelpers<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;">simpleCache</span>(</span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb6-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021 (hierarchical)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>),</span>
<span id="cb6-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016 (hierarchical)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename_columns =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)</span>
<span id="cb6-9">  )<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BUILT <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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1<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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Not applicable"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(EFDECILE<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_housing_status=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(BUILT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016 to 2021"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011 to 2016"</span>),</span>
<span id="cb6-16">                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New housing"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Old housing"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-17">    <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MOB5,new_housing_status,EFDECILE,CMA,SUBSIDY,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(SUBSIDY,</span>
<span id="cb6-19">                              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A subsidized dwelling"</span>,</span>
<span id="cb6-20">                              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not subsidized"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not a subsidized dwelling"</span>)),</span>
<span id="cb6-21">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pumf_2021_movers_income_new_housing.rds"</span>,</span>
<span id="cb6-22">  here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-23"></span>
<span id="cb6-24">pumf_data_income <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-25">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter(CMA=="Vancouver") |&gt;</span></span>
<span id="cb6-26">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(new_housing_status,EFDECILE,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>new_housing_status,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(EFDECILE))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">percent_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Income of movers into new vs old housing"</span>,</span>
<span id="cb6-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population who moved in past 5 years but not during past year into housing built "</span>,</span>
<span id="cb6-35">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adjusted family</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">income decile"</span>,</span>
<span id="cb6-37">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population moving into new and old housing"</span>,</span>
<span id="cb6-38">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2016, 2021 PUMF (hierarchical)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-movers-income-year-built" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-movers-income-year-built-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-movers-income-year-built-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-movers-income-year-built-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Adjusted family income deciles of the population moving into new build approximately in the previous 5 years, vs those who moved into old housing. Data from the 2016 census was included in case 2021 results are skewed by pandemic income losses as well as income supports like CERB.
</figcaption>
</figure>
</div>
</div>
</div>
<p>To put it differently, every 3-4 new dwellings could be expected to house roughly the same number of families in the bottom adjusted income decile as every 2 old dwellings. So where new dwellings markedly add to supply (rather than simply replacing old dwellings), they will probably house more, not fewer, lower income households as they’re added. As a cross-check, let’s look at old and new housing by sector. Figure&nbsp;5 separates out private or market rental (unsubsidized) and non-market rental housing (subsidized) from owner-occupied to highlight that the share of lower income people moving into new housing is not due to any recent burst of new non-market housing. There (unfortunately) simply isn’t enough of it to skew those numbers.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">pumf_data_income <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filter(CMA=="Vancouver") |&gt;</span></span>
<span id="cb7-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(new_housing_status,EFDECILE,SUBSIDY,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(SUBSIDY<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;">"Not available"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(SUBSIDY,</span>
<span id="cb7-6">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Market rental"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not subsidized"</span>,</span>
<span id="cb7-7">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-market or </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">cash supports"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span>,</span>
<span id="cb7-8">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Owner"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>new_housing_status,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(EFDECILE))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<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;">percent_format</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(SUBSIDY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Income of movers into new vs old housing"</span>,</span>
<span id="cb7-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population who moved in past 5 years but not during past year into housing built "</span>,</span>
<span id="cb7-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb7-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adjusted family</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">income decile"</span>,</span>
<span id="cb7-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population moving into new and old housing"</span>,</span>
<span id="cb7-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2016, 2021 PUMF (hierarchical)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-movers-income-year-built-subsidy" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-movers-income-year-built-subsidy-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-movers-income-year-built-subsidy-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-movers-income-year-built-subsidy-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Adjusted family income deciles of the population moving into new build approximately in the previous 5 years, vs those who moved into old housing, split by tenure.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The split highlights that in non-market housing the share of lower income households is, predictably, a lot higher than in what we typically think of as market housing. Interpreting variation between sectors, it is good to remember that a fair share of private housing gets allocated by non-market means, for example inheritance of homes, parents buying properties for their children, or other forms of non-market rentals. Empty Homes Tax and Speculation and Vacancy Tax data indicate that a not insignificant portion of the secondary rental market consists of non-arms length rentals. More on this topic in a previous post. <span class="citation" data-cites="commodity-and-keeping-it-in-the-family.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021a)</span>.</p>
<p>Despite differences between sectors, the general pattern holds across sectors: new housing provides homes to people across the income spectrum, with the median occupants having incomes either the same or just slightly higher than for residents of older housing. But let’s return to the additional positive filtering effects new housing produces by way of vacancy chains.</p>
</section>
<section id="moving-vacancies" class="level2">
<h2 class="anchored" data-anchor-id="moving-vacancies">Moving vacancies</h2>
<p>With some base understanding of mobility the next step is to look for moving vacancies. In keeping with the previous section, we focus on household reference persons to simplify the discussion.</p>
<p>We can come at this from two angles, for a household to move somewhere there first has to be a vacant unit they can move in to.<sup>3</sup> How do we get vacant units? Essentially there are two ways; either the unit has been newly built, or it’s left behind after being vacated by its previous occupants.</p>
<p>On the flip side, when someone moves into a unit they often leave a vacant dwelling unit behind. Here we have to be a little more careful, the household reference person in the new dwelling unit may not have been a household reference person in the previous dwelling unit, in which case they do not leave a vacancy behind. Examples include children moving out of their parents’ place, or a couple or roommate household splitting up with only part of the household moving out. In some cases they can leave multiple vacancies behind, for example when two single households combine and move into a new place. One other question is where the vacancy gets created; in some cases it’s in a different part of the country or a different country altogether, which is of limited use when trying to understand local housing markets. Overall, these moving vacancies are essential to enabling mobility. We often leave vacancies behind as well as filling vacancies when moving. These vacancies, and moves between them, can chain together to form <em>moving chains</em> or <em>vacancy chains</em>.</p>
<p>These vacancy chains have been studied for quite some time. Groundbreaking studies establishing housing as a dominant reason for mobility began at least as early as <span class="citation" data-cites="rossi_1955">Rossi (1955)</span>, but <span class="citation" data-cites="kristof_1965">Kristof (1965)</span> was one of the first to think through chained moves, and <span class="citation" data-cites="lansing_1969">Lansing et al. (1969)</span> did a large empirical study to understand vacancy chains, finding that vacancy chains were on average 3.5 moves long and most moves were moves up in the housing spectrum. This field has seen a modern revival, partially motivated by rising <em>supply skepticism</em>, with more modern data approaches pioneered by <span class="citation" data-cites="magnusson_turner_2008">Turner (2008)</span> using administrative data to track moves and <span class="citation" data-cites="mast_2019">Mast (2019)</span> using commercially available data tracking people’s addresses to study vacancy chains in the US context. To date possibly the best study was carried out in Finland by Bratu <span class="citation" data-cites="bratu2023">(Bratu et al. 2023)</span>.</p>
<p>All these studies consistently find that moving chains exist, they are longer when initial housing units are near the upper end of the housing spectrum, and a good proportion of vacancies reach into the lower part of the housing spectrum. If moving chains start lower down, for example by building new non-market housing, moving chains are shorter but a higher proportion and absolute number reach into the lower end of the housing spectrum.</p>
<p>Vacancy chains operate as the primary mechanism by which price and rent signals are transmitted throughout the housing spectrum. And given how often people move this information exchange happens relatively quickly.</p>
</section>
</section>
<section id="filtering" class="level1">
<h1>Filtering</h1>
<p>Filtering usually refers to the process by which units become available to people lower down the income spectrum as the housing units age. The mechanism by which is this happens is that buildings depreciate and generally newer buildings are higher quality. That means that older buildings tend to move down the quality spectrum of the building stock, so they tend to rent or sell for less than newer buildings. There are some caveats here of course. For example, if old buildings are in more desirable locations than newer buildings then this might not happen, and increasing investment in renovations may move old buildings back up the quality spectrum.</p>
<p>But just because older buildings tend to move down the quality spectrum does not mean they become available to lower income family units. Here the systemic effects of housing kick in. Research in several settings has shown that if the overall housing supply manages to keep up with (or exceed) demand growth, then older units filter down the income spectrum. Conversely, where supply lags behind demand growth, older units have been found to filter up the income spectrum. <span class="citation" data-cites="tsur_filtering.2001 tsure_filtering_supply.2003 myers_filtering.2020">(Somerville and Holmes 2001; Mayer and Somerville 2003; Myers and Park 2020)</span> In that case lower income families and individuals get squeezed, and are generally forced to either: a) pay a higher share of their income on housing; b) move away; or c) double up to form more complex households to share housing costs. Historically this last option has often involved taking in boarders or lodgers <span class="citation" data-cites="harris1992end">(Harris 1992)</span>, but doubling up as a response to shortage has evolved and we can now identify those doing so as “suppressed” or “concealed” households. In Vancouver and Toronto in particular we have shown how these kinds of doubled-up households have increased since the 1970s and detailed the corresponding shift in household living arrangements. <span class="citation" data-cites="estimating-suppressed-household-formation.2022 still-short-suppressed-households-in-2021.2022 housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2022a, 2022b, 2023a)</span> The rise in doubling up in Vancouver and Toronto indicates that housing supply has failed to keep up with demand and older units have likely filtered up over the past 5 decades.</p>
</section>
<section id="sec-rent-impacts" class="level1">
<h1>Impact of new market housing on rents</h1>
<p>Given the broad theory and data around vacancy chains and filtering, how much do rents move at different points in the spectrum in response to adding new housing to markets? One challenge to answering this question has been finding high demand locations that have experienced the addition of a lot of housing. Auckland in New Zealand underwent a series of upzonings, a small one in 2013 followed by a larger one in 2016. These resulted in large supply bumps in response. <span class="citation" data-cites="nz_rents.2024">Greenaway-McGrevy and So (2024)</span> carefully estimate the effect of these upzonings on rents, finding that the upzoning reduced rents by between 20% to 35%. This is based on average rents, but here we are particularly interested in the distributional effects. To assess if there were differential effects we take <a href="https://www.tenancy.govt.nz/about-tenancy-services/data-and-statistics/rental-bond-data/">rental bond data from the New Zealand Tenancy Services branch</a> that <a href="https://x.com/vb_jens/status/1723401648930980207">we have looked at before</a> and that splits out rents by quartile. Figure&nbsp;6 shows seasonally adjusted monthly quartile rents, deflated by full time equivalent average weekly earnings, since 2013, indexed to 2016. We note that all quartiles move quite similarly, with the upper and lower quartile dropping below the median.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">tbats_trend <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(value,frequency,date) {</span>
<span id="cb8-2">  year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>()</span>
<span id="cb8-3">  ts <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ts</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frequency=</span>frequency,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start=</span>year)</span>
<span id="cb8-4">  fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> forecast<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;">tbats</span>(ts)</span>
<span id="cb8-5">  components <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> forecast<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;">tbats.components</span>(fit)</span>
<span id="cb8-6">  out <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>()</span>
<span id="cb8-9">  </span>
<span id="cb8-10">  result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> out<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>level</span>
<span id="cb8-11">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lambda))</span>
<span id="cb8-12">    result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> forecast<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;">InvBoxCox</span>(result,fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lambda)</span>
<span id="cb8-13">  result</span>
<span id="cb8-14">}</span>
<span id="cb8-15"></span>
<span id="cb8-16">get_nz_earnings_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb8-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/QEM557301_20240715_121904_79.csv"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_names =</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;">"Quarter"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Earnings"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Earnings)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span>lubridate<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;">yq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>,Quarter)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span>Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb8-21">}</span>
<span id="cb8-22"></span>
<span id="cb8-23">get_nz_rent_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>){</span>
<span id="cb8-24">  path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<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;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/nz_rents.rds"</span>)</span>
<span id="cb8-25">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(path)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span>refresh) {</span>
<span id="cb8-26">  rents <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;">"https://www.tenancy.govt.nz/assets/Uploads/Tenancy/Rental-bond-data/Detailed-Monthly-May-2024-Rental-bond-data-TLA.csv"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cols</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.default=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Time Frame</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.after=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Time Frame</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb8-28">  </span>
<span id="cb8-29">  earnings <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;">get_nz_earnings_data</span>()   <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">complete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(rents<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Date)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Earnings=</span>zoo<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;">na.approx</span>(Earnings,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Date,Earnings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-34">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(Earnings,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.direction=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"down"</span>)</span>
<span id="cb8-35">    </span>
<span id="cb8-36">    rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-37">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(earnings,<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;">"Date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-38">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(path)</span>
<span id="cb8-39">  }</span>
<span id="cb8-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readRDS</span>(path)</span>
<span id="cb8-41">}</span>
<span id="cb8-42"></span>
<span id="cb8-43">rents <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;">get_nz_rent_data</span>()</span>
<span id="cb8-44"></span>
<span id="cb8-45">rent_pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rents <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Location<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;">"Auckland"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median|Quartile"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Earnings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trend=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tbats_trend</span>(v,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>,Date),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(name,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Location Id</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016-01-01"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Location Id</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base=</span>trend),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Location Id"</span>))</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">rent_pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2010-01-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>trend<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>base,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span>name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</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;">"2013-01-01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016-01-01"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>trios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c149) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rent trends in Auckland"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Seasonally adjusted index, deflated by FTE weekly average earnings</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(2016=100, log scale)"</span>,</span>
<span id="cb9-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rent quartile"</span>,</span>
<span id="cb9-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rental bond data, NZ Tenancy Services, NZ Stats QEM"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-auckland-rent-quartiles" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-auckland-rent-quartiles-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-auckland-rent-quartiles-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-auckland-rent-quartiles-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Rent quartiles in Auckland deflated by full-time equivalent weekly earnings, noting the 2013 and 2016 zoning reforms.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Overall rent increases relative to earnings slowed starting around the 2016 reforms until they reversed and dipped quite strongly in 2022, recovering somewhat in 2023. Lower quartile and median rents rose faster than upper quartile rents pre-2016, but post-2016 both upper and lower quartile rents decreased faster than median rents, even as the sample changed over time as new rental homes mostly add to the top quartile. This broadly aligns with economic theory that predicts a compression of the rent spectrum when housing is scarce. With additions to housing supply the opposite happens, but the rents at the top see more downward pressure because they are the closest substitute to the added new housing. Most importantly for our analysis, these differences are rather small compared to the overall rent movements, and they give us some confidence that not much will be lost if we simplify the analysis to assume that rents across the spectrum move in lockstep. Similar observations have been made about <a href="https://www.realpage.com/analytics/class-b-c-rent-cuts-2024/">US apartment rents</a> in areas that added a lot of supply.</p>
</section>
<section id="impact-of-new-market-housing-on-core-housing-need" class="level1">
<h1>Impact of new market housing on core housing need</h1>
<p>Putting the pieces together we can now use micro data to simulate what might happen as we increase the supply of housing. In particular, we want to compare our current housing system with where we would be if we met our housing targets (where municipalities stopped restricting housing). Much of this section follows similar work done in the US context <span class="citation" data-cites="corinth2023">(Corinth and Irvine 2023)</span>, adapted to the Canadian setting. This is also continuation on earlier work we did on housing targets that estimated the amount of market housing needed in Metro Vancouver to drive what’s also known as the “zoning tax” - the difference between the price of market housing and the marginal social cost to produce it - to zero. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span> In that post we focused only on market housing and promised to integrate the question about the need for non-market housing or cash subsidies at a later time. We will get to that in this post.</p>
<p>The idea is quite simple. Picking up from our previous post we assume enough housing has been built to meet our housing targets, and average prices for new housing have effectively dropped to the price of profitable production, declining by about 30%. Here uncertainties in demand elasticity estimates only affect the amount of housing needed to meet our targets (competing the zoning tax away), but not the average price and rent effects, which makes this part a little more straight-forward.</p>
<p>We follow <span class="citation" data-cites="corinth2023">Corinth and Irvine (2023)</span> in assuming that the price and rent effects of new supply distribute fairly uniformly throughout the housing spectrum. Our observations in Section&nbsp;5 confirms that this is quite reasonable – possibly rent effects are even stronger at the lower end which makes our assumptions conservative. We also need to estimate the cross-elasticity of rental and ownership housing. This can be tricky (e.g.&nbsp;involving assumptions about things like carrying costs, tax treatment, etc), and there are various estimates in the literature (see <span class="citation" data-cites="corinth2023">Corinth and Irvine (2023)</span> for a summary of US related studies), but for this post we will assume that cross-elasticity is 1, so the rent-to-price ratio remains unchanged. Armed with these assumptions, it’s time to do some work.</p>
<section id="step-1-how-much-need-currently-exists" class="level3">
<h3 class="anchored" data-anchor-id="step-1-how-much-need-currently-exists">Step 1) How much need currently exists?</h3>
<p>The first step in this follows <span class="citation" data-cites="corinth2023">(Corinth and Irvine 2023)</span> to estimate the effect of rent changes on Vancouver household’s current rent burden, keeping households fixed. We start by estimating the gap each household faces in getting their shelter costs to no more than 30% of total household income, if any. This is the amount of cash subsidy needed to ensure that the current housing situation of all households meets the 30% affordability criterion.</p>
<p>In Figure&nbsp;7 we split this by tenure and by Core Housing Need status and show the distribution of cash subsidies needed to lift households out of unaffordable housing. As a reminder, Canadians are considered to have their Core Housing Need met (<em>“Not in core need”</em>) when their housing is affordable (&lt;30% income), suitable (has enough bedrooms for resident mix), and adequate (in good repair), or their income would allow them to afford other housing locally that would meet their needs. Those considered to be in Core Housing Need (<em>“In core need”</em>) are households who fail this test. Except that some households are excluded from this measure (<em>“Not available”</em>), including those with shelter cost higher than income, as well as some non-family student households. As we can see there remain households deemed not to be in Core Housing Need who still have shelter costs higher than 30% of income. Here the CMHC assumes their income suffices to pay the median rent of alternative local housing that would meet their needs (i.e.&nbsp;they are likely choosing to pay more in rent because of amenities).</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">pd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight=</span>WEIGHT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(TENUR))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(</span>
<span id="cb10-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</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;">2500</span>, </span>
<span id="cb10-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>)</span>
<span id="cb10-9">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HCORENEED_IND) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>tenure_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-13">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_x_continuous(labels=\(x)scales::dollar(x+2500)) +</span></span>
<span id="cb10-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual cash supports needed so that every Metro Vancouver household</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">spends at most 30% of income on shelter costs"</span>,</span>
<span id="cb10-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(keeping shelter costs and households fixed)"</span>,</span>
<span id="cb10-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of households"</span>,</span>
<span id="cb10-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual mean cash supplement per household"</span>,</span>
<span id="cb10-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tenure"</span>,</span>
<span id="cb10-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cash-supports" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cash-supports-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-cash-supports-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cash-supports-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: Actual cash supports needed to lift all households out of unaffordable housing so that they pay at most 30% of their income on shelter costs, split by Core Housing Need status. 2016 data added for reference, pandemic transfers like CERB help lift some people out of unaffordable housing when using 2021 census data which relies on 2020 incomes.
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell" data-inlude="false">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">pd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cat=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span> <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;">"$1-$2,500"</span>,</span>
<span id="cb11-5">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span> <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;">"$2,500-$5,000"</span>,</span>
<span id="cb11-6">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span> <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;">"$5,000-$10,000"</span>,</span>
<span id="cb11-7">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span> <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;">"$10,000-$15,000"</span>,</span>
<span id="cb11-8">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span> <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;">"$15,000-$20,000"</span>,</span>
<span id="cb11-9">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$20,000-$25,000"</span>,</span>
<span id="cb11-10">                       gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span> <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;">"$25,000-$50,000"</span>,</span>
<span id="cb11-11">                       <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$50,000+"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-12">  <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;">count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,cat,Year,HCORENEED_IND)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>cat,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(TENUR))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-14">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geom_histogram(bins = 30) +</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HCORENEED_IND) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>tenure_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_x_continuous(labels=scales::dollar) +</span></span>
<span id="cb11-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cash supports needed so that every Vancouver household spends</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">at most 30% of income on shelter costs"</span>,</span>
<span id="cb11-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(keeping shelter costs and households fixed)"</span>,</span>
<span id="cb11-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of households"</span>,</span>
<span id="cb11-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual mean cash supplement per household"</span>,</span>
<span id="cb11-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tenure"</span>,</span>
<span id="cb11-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
</div>
<p>For the purpose of this post we will track all three of these Core Housing Need categories, recognizing that distinct interpretations apply to these housing situations. Even if households living in unaffordable housing but determined not be in “Not in core need” are often understood as trading off affordability against other preferences, we suspect that these households have better information about their particular situation than the measure allows for, and we want to avoid dismissing their current unaffordability as a simple matter of choice.</p>
<p>Households not assessed for Core Housing Need are more difficult to deal with in this framework. They defy the shelter-cost-to-income calculus and include a wide variety of scenarios, starting from the mundane, where they are created by the temporal mismatch of previous year’s incomes and current year’s shelter cost measurements. For example a recent university graduate beginning a new job may well be able to comfortably afford their current housing on their current income, but not based on their previous year’s income while they were still in university. Other examples include situations where income is primarily derived from capital gains or RRSP withdrawals, which are not included in standard StatCan total income metrics. But this category also includes households in dire financial situations, maybe trying to bridge a job loss by drawing down savings or taking on debt while holding onto existing housing.</p>
<p>We note that owner households in unaffordable housing face very different situations compared to renter households as they often have equity in their home, allowing them to transform their current situation into that of a wealthy renter. For this reason we will narrow down most of our analysis so it will be focused on need for renter households only, as shown in Figure&nbsp;8. As is evident, much need remains despite existing rental subsidy programs. For comparison’s sake, the current BC Rental Assistance Program, targeted at families with children, together with related subsidy programs, is made available to about 35,000 low-income households, and provides mean-tested rent subsidies that are generally well below the program maximum of around $12,000 per year ($1,000/mo), varying by location. <span class="citation" data-cites="bc_housing_2023">(Commission 2023)</span></p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">pd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight=</span>WEIGHT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(TENUR))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(</span>
<span id="cb12-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</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;">2500</span>, </span>
<span id="cb12-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>)</span>
<span id="cb12-8">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HCORENEED_IND) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>tenure_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># scale_x_continuous(labels=scales::dollar) +</span></span>
<span id="cb12-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual cash supports needed so that every Metro Vancouver renter household</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">spends at most 30% of income on shelter costs"</span>,</span>
<span id="cb12-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(keeping shelter costs and households fixed)"</span>,</span>
<span id="cb12-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of households"</span>,</span>
<span id="cb12-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual mean cash supplement per household"</span>,</span>
<span id="cb12-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tenure"</span>,</span>
<span id="cb12-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cash-supports2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cash-supports2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-cash-supports2-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cash-supports2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8: Actual cash supports needed to lift all renter households (ignoring owner households) out of unaffordable housing so that they pay at most 30% of their income on shelter costs, split by Core Housing Need status.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="step-2-how-much-need-would-still-exist-if-we-successfully-met-housing-targets" class="level3">
<h3 class="anchored" data-anchor-id="step-2-how-much-need-would-still-exist-if-we-successfully-met-housing-targets">Step 2) How much need would still exist if we successfully met housing targets?</h3>
<p>The question we ask is how many of these households would still be in unaffordable housing if we met our housing targets, building enough housing to drop prices and rents of (new) housing by 30%, a figure well in reach based on work by CMHC <span class="citation" data-cites="gensey_condos.2018">(CMHC 2018)</span> and explained in our previous post on housing targets. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span> Dropping prices and rents won’t alter the affordability situation of existing owner households, but it will make a difference for existing renters that we can easily simulate in the data as shown in Figure&nbsp;9.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight=</span>WEIGHT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(TENUR))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(</span>
<span id="cb13-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</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;">2500</span>, </span>
<span id="cb13-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>)</span>
<span id="cb13-10">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HCORENEED_IND) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-13">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_x_continuous(labels=scales::dollar) +</span></span>
<span id="cb13-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>tenure_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Successful housing target cash supports needed so that every</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> Metro Vancouver household spends at most 30% of income on shelter costs"</span>,</span>
<span id="cb13-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(assuming supply effects lower shelter costs by 30%, keeping households fixed)"</span>,</span>
<span id="cb13-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of households"</span>,</span>
<span id="cb13-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual mean cash supplement per household"</span>,</span>
<span id="cb13-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tenure"</span>,</span>
<span id="cb13-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cash-supports3" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cash-supports3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-cash-supports3-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cash-supports3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9: Successful housing target counter-factual simulation where rents are 30% lower, showing resulting cash supports needed to lift all renter households (ignoring owner households) out of unaffordable housing so that they pay at most 30% of their income on shelter costs, split by Core Housing Need status.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="step-3-how-would-successfully-meeting-housing-targets-affect-need-estimates" class="level3">
<h3 class="anchored" data-anchor-id="step-3-how-would-successfully-meeting-housing-targets-affect-need-estimates">Step 3) How would successfully meeting housing targets affect need estimates?</h3>
<p>Figure&nbsp;10 summarizes the previous two figures, and compares the actual vs counter factual cash supports needed to lift all renter households out of unaffordable housing.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">summary_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(HCORENEED_IND),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>effect_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro Vancouver cash supports needed to lift all renter households out of unaffordable housing"</span>,</span>
<span id="cb14-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual total cash supplement needed to ensure that</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">all households pay no more than 30% of income on shelter costs"</span>,</span>
<span id="cb14-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb14-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scenario"</span>,</span>
<span id="cb14-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cash-supports4" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cash-supports4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-cash-supports4-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cash-supports4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10: Cash supports needed, in actual vs successful housing target scenario with 30% lower rents, to lift all renter households out of unaffordable housing, by core housing need status.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The comparison demonstrates the sizable reduction in the cash supports needed to lift people out of unaffordable housing if we successfully met our housing targets, especially in the categories of people considered for Core Housing Need. In Figure&nbsp;11 we slice this comparison differently by looking at how many people and households successfully meeting housing targets would lift out of unaffordable housing relative to what we observe now.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)</span>
<span id="cb15-2">g1<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>summary_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(HCORENEED_IND),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Households,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>effect_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bottom'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Households in unaffordable housing"</span>,</span>
<span id="cb15-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Households paying &gt;30% of income"</span>,</span>
<span id="cb15-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-12">       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#caption="Data: StatCan Census 2016, 2021 PUMF (individuals)",</span></span>
<span id="cb15-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scenario"</span>) </span>
<span id="cb15-14">g2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>summary_data_people <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(HCORENEED_IND),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>People,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>effect_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in unaffordable housing"</span>,</span>
<span id="cb15-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in households paying &gt;30% of income"</span>,</span>
<span id="cb15-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-24">       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#caption="Data: StatCan Census 2021 PUMF (individuals)",</span></span>
<span id="cb15-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Scenario"</span>) </span>
<span id="cb15-26"></span>
<span id="cb15-27">(g1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>g2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-28">  (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_layout</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collect"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_annotation</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;">"Metro Vancouver renters (households and people) in unaffordable housing</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">by Actual vs successful housing targets and Core Housing Need"</span>,</span>
<span id="cb15-30">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2016, 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-cash-supports5" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cash-supports5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-cash-supports5-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cash-supports5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11: Number of households and people in unaffordable housing in actual vs successful housing target scenario with 30% lower rents, by core housing need status.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Again, this comparison shows that meeting housing targets would lead to large reductions in the numbers of people and households stuck in unaffordable housing, both for those in Core Housing Need and whose needs are currently considered met. By contrast, meeting housing targets does next to nothing for people excluded from the Core Housing Need measure. This is not surprising insofar as these are situations where income tends to be the largest factor for reasons explained above.</p>
</section>
<section id="in-summary" class="level3">
<h3 class="anchored" data-anchor-id="in-summary">In summary:</h3>
<p>Using 2016 and 2021 benchmarks, keeping (existing) households fixed, meeting housing targets, and thereby increasing the Metro Vancouver housing stock to drop the price and rent of (new) housing by 30%, would lift between 59,000 and 65,000 renter households out of unaffordable housing. This would reduce the total number of renter households in unaffordable housing by 35.7% and 41.1% in 2016 and 2021, respectively. Meeting housing targets would reduce the annual supplements required to lift all renter households out of unaffordable housing by $678M and $842M, a reduction by 52% and 55% in 2016 and 2021, respectively. Switching from households to people in unaffordable housing, meeting targets would result in a reduction of 117k and 106k people in need, a reduction by 39% and 43% in 2016 and 2021, respectively.</p>
<p>These changes are sizable, but not the only benefits. Renters throughout the spectrum would see their shelter costs reduced and their options to better match their living arrangements to their personal preferences improved. Building more market housing has very large redistributive effects of income from current landlords to renters, as we have explained in the past. <span class="citation" data-cites="what-if-recent-apartment-buildings-in-vancouver-were-20-taller.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024b)</span>.</p>
<p>This serves well as a simple estimate of the positive effects of meeting our housing targets. But we note that this would not lift all renter households out of unaffordable housing. Rent supplements or dedicated non-market housing would still be needed. Our estimates show that, assuming households as fixed and remaining in their current housing units, even after the supply shock from meeting targets 106,000 and 93,000 renter households would still be in unaffordable housing, requiring a total annual subsidy of $625M and $684M annually to lift them to the 30% shelter-cost-to-income threshold in 2016 and 2021, respectively. Just focusing on the households in Core Housing Need the supply shock would reduce the number of renter households in Core Housing Need paying more than 30% of income on shelter costs from 87,000 and 88,000 to 60,000 and 54,000 in 2016 and 2021, respectively. This gives an estimate of the total remaining unmet need for non-market housing or related rent supports after municipalities hit our targets (i.e.&nbsp;stop restricting the addition of housing to markets).</p>
<p>But as we stated at the outset, there are several further caveats. On one hand these estimates are likely conservative: even keeping households fixed but allowing them to move housing units, a reduction in prices and rents across the spectrum will likely trigger some households to move and upgrade their current housing. This would open up more lower cost housing for people to move into if they wish to reduce their housing cost and further depress the share of the population in Core Housing Need. On the other hand, we know households aren’t fixed. In fact, they’re quite malleable, and many people respond to high housing costs by doubling up. We look into that below. It’s also the case that rent control for existing tenants means that some households (usually the renters with the longest tenancies) will derive less direct benefit from a 30% reduction in market rents. We will return to this point in Section&nbsp;8.1 and try to estimate the impact of rent control on our estimates. Overall we see that households reaping large benefits from rent control have lower rates of unaffordable shelter costs, but they still benefit indirectly by seeing increased options to change their living arrangements.</p>
</section>
</section>
<section id="impact-of-new-housing-on-household-formation" class="level1">
<h1>Impact of new housing on household formation</h1>
<p>In order to better understand what is going on with households, we need to take another look at the processes that allowed rents to fall. We are modelling changes after prices and rents dropped by about 30%, and in our previous post on housing targets we estimated that to achieve this change in market prices and rents requires roughly 250k to 300k net new dwelling units in Metro Vancouver. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span> This takes time to build, which is roughly in line with our assumption of veering not too far off of a stationary market equilibrium for the allocation of housing (and requires even more housing to account for demand growth during this time). New housing will lead to new households getting formed, some by households who currently live outside of the region and some by people already in the region forming new households. This violates our initial assumption of keeping households fixed.</p>
<p>To adjust for this we need to</p>
<ul>
<li>estimate how many new households would form from the existing population, and their likely shelter-cost-to-income mismatch, and</li>
<li>estimate how many households would form from people moving into the region, and their distribution of incomes and shelter costs.</li>
</ul>
<p>Both of these are difficult, but we can give a rough estimate. The second one is particularly challenging to model directly. Here we will model the change in net migration as a residual via the difference of the new number of dwelling units, discounted by an assumed natural vacancy rate, and new household formation by existing dwelling units. This can introduce sizable errors and needs to be treated with caution. We then estimate the share of households in Core Housing Need or with shelter-cost-to-income mismatch by assuming that the overall makeup of the population moving into the region is comparable to the ones already in the region.<sup>4</sup> We then anchor these estimates by estimating the relationship between metro level prevailing rents and Core Housing Need or shelter-cost-to-income mismatch separately, introducing an alternative method to estimate the overall distribution of households struggling with shelter costs that include both households made up of the existing population as well as newcomers.</p>
<p>Accounting for new household formation of existing residents is also complex. We have previously looked at changes in household composition across metro areas in Canada <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span>, and have been working on extending this to tie household formation patterns directly to rents and incomes. <span class="citation" data-cites="mhu.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span> In future work we are planning to cast this explicitly in household formation elasticities to prevailing rent levels.</p>
<p>Many of the resulting households forming in response to changing rents would likely be near the 30% affordability cutoff, and introduce new households in unaffordable housing. In general, we know that single person households and single parent with children households are overrepresented in Core Housing Need. In part, this is because single incomes are simply more volatile than two-income households, and we know from longitudinal CMHC research that showing up in Core Housing Need is only temporary for most households. <span class="citation" data-cites="cmhc_2021">(CMHC 2021)</span> But importantly, these single income households are also more likely to form as people currently sharing housing with others due to housing costs become newly able to split off and live on their own.</p>
<p>Overall, the share of households in Core Housing Need in Vancouver has not increased over the past 15 years <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span> even though we have a lot of evidence that housing outcomes have gotten worse over this time period. This suggests caution that measuring Core Housing Need while holding households constant is the right approach. On the flip side, improvements in housing outcomes may not be reflected in Core Housing Needs either. In particular, enabling households to split up in favour of obtaining more privacy and reducing conflict is, in itself, arguably meeting an important need. Cheaper, more plentiful housing will be helping people if it also allows more people to strike out on their own with a single income, and even if those single income households are ultimately at higher risk paying more than 30% of their income on housing, potentially placing them into Core Housing Need.</p>
<p>To explore this further, let’s start out by looking at the ecological level relationship between rents and households struggling with housing costs.</p>
<section id="sec-rents-housing-pressures" class="level2">
<h2 class="anchored" data-anchor-id="sec-rents-housing-pressures">Prevailing rents vs housing pressures</h2>
<p>In Figure&nbsp;12 we show the relationship of rents to the share of the population in Core Housing Need across metro areas for some indication of how a supply shock decreasing rents might play out. As expected, as rents go up, the share of people in Core Housing Need also goes up. Correspondingly, bringing rents down could be expected to reduce Core Housing Need, providing broad confirmation for our results above.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">movers <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;">"Non-migrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Different CSD, same census division"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Different CD, same province"</span>,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interprovincial migrants"</span> ,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External migrants"</span>) </span>
<span id="cb16-2"></span>
<span id="cb16-3"></span>
<span id="cb16-4">rent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Age %in% c("25 to 29 years","30 to 34 years")) |&gt;</span></span>
<span id="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"2 bedrooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> movers) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(`Household size`=="1 person") |&gt;</span></span>
<span id="cb16-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-11">  <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;">Rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>WEIGHT),</span>
<span id="cb16-12">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(inflation,<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>Rent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI) </span>
<span id="cb16-15"></span>
<span id="cb16-16">montreal_vancouver_rent_ratio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb16-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb16-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name=</span>CMA,Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>real_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb16-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb16-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>Montréal<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Vancouver<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>)</span>
<span id="cb16-21"></span>
<span id="cb16-22">old_rent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Age %in% c("25 to 29 years","30 to 34 years")) |&gt;</span></span>
<span id="cb16-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(BEDRM<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;">"2 bedrooms"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(`Household size`=="1 person") |&gt;</span></span>
<span id="cb16-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Old rent</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(SHELCO,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>WEIGHT),</span>
<span id="cb16-29">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(inflation,<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_old_rent=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Old rent</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CPI) </span>
<span id="cb16-32"></span>
<span id="cb16-33">pd3<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-34">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb16-35">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(HCORENEED_IND != "Not available") |&gt;</span></span>
<span id="cb16-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb16-37">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Income=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(TOTINC,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb16-38">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,</span>
<span id="cb16-39">                  HCORENEED_IND,</span>
<span id="cb16-40">                  AGEGRP,</span>
<span id="cb16-41">                  Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),</span>
<span id="cb16-44">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Income_gap=</span>Income<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Income)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Income),</span>
<span id="cb16-45">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SCI=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Rent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Income,</span>
<span id="cb16-46">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,AGEGRP))</span>
<span id="cb16-47"></span>
<span id="cb16-48">metro_grep_string <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;">"Toronto|Vancouver|Montr|Qu|Calg|Edmon"</span></span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pd4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-2">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(Rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">first</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,HCORENEED_IND,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HCORENEED_IND<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;">"In core need"</span>,Year<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;">"2011"</span>) </span>
<span id="cb17-5"></span>
<span id="cb17-6">response <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(y){</span>
<span id="cb17-10">    chn.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share<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;">log</span>(real_rent),</span>
<span id="cb17-11">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>),</span>
<span id="cb17-12">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y))</span>
<span id="cb17-13">    </span>
<span id="cb17-14">    comparison_rent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (rent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb17-15">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb17-16">                                 Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-17">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent)) <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;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb17-18"></span>
<span id="cb17-19">    modelsummary<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;">modelplot</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draw=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coef_omit=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-20">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-21">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect=</span> marginaleffects<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;">avg_comparisons</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>comparison_rent))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate,</span>
<span id="cb17-22">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_share=</span>pd4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-23">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect_pct=</span>rent_effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>base_share)</span>
<span id="cb17-24">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#tibble(Year=y,rent=coef(chn.fit)[['log(real_rent)']])</span></span>
<span id="cb17-25">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>)))</span>
<span id="cb17-27"></span>
<span id="cb17-28">pd4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-30">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA)),</span>
<span id="cb17-32">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-37">  ggrepel<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_text_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),</span>
<span id="cb17-38">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>,</span>
<span id="cb17-41">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2400</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb17-43">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Core Housing Need by metro area"</span>,</span>
<span id="cb17-45">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of people in Core Housing Need (logit scale)"</span>,</span>
<span id="cb17-46">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average rent of 2-bedroom units moved in during the past year in metro area (log scale)"</span>,</span>
<span id="cb17-47">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-core-housing-need-rents" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-core-housing-need-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-core-housing-need-rents-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-core-housing-need-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;12: Relationship between the share of the population in Core Housing Need and real rents in 2016 and 2021. The impact of pandemic transfers is clearly visible in the 2021 data, in particular with regions with lower rents where CERB payments were more likely to make up for rent payments in excess of 30% of income. High rent areas show little movement.
</figcaption>
</figure>
</div>
</div>
</div>
<p>But how much would reducing rents matter? Here we get somewhat different estimates, varying even by the year we use. It’s worth noting that the 2021 data looks quite different from the 2016 data, with a much steeper slope. Places where rents were already lower in 2016 show a fairly pronounced drop in the share of people in Core Housing Need in 2021, whereas areas with high rents show much less movement. But 2021, using 2020 incomes, was hardly a normal census year and heavily impacted by the pandemic, with CERB payments likely lifting several households, and the people within them, out of core housing need. This effect seems most pronounced in places where rents were comparatively low and CERB payments go a long way.</p>
<p>Maybe we can go further back to better place 2021 results in context. The 2011 PUMF data is missing the Core Housing Need indicator, but we probably want to move away from Core Housing Need as the key metric here anyway. So here we’ll simply look at people in households with high shelter cost to income ratios, i.e.&nbsp;households with shelter costs exceeding 30% of total household income. Figure&nbsp;13 plots the share of people in households with high shelter costs to income ratios with 2011 data included.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pd5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb18-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HSC=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>SHELCO <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> max_rent) <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;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb18-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Income=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(TOTINC,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb18-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,</span>
<span id="cb18-6">                  HSC,</span>
<span id="cb18-7">                  Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HSC) </span>
<span id="cb18-11"></span>
<span id="cb18-12"></span>
<span id="cb18-13">response5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(y){</span>
<span id="cb18-16">    chn.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share<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;">log</span>(real_rent),</span>
<span id="cb18-17">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y),</span>
<span id="cb18-18">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))</span>
<span id="cb18-19">    </span>
<span id="cb18-20">    comparison_rent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (rent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb18-21">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb18-22">                                 Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-23">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent)) <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;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb18-24">    </span>
<span id="cb18-25">    modelsummary<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;">modelplot</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draw=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coef_omit=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-27">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect=</span> marginaleffects<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;">avg_comparisons</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>comparison_rent))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate,</span>
<span id="cb18-28">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_share=</span>pd5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-29">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect_pct=</span>rent_effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>base_share)</span>
<span id="cb18-30">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#tibble(Year=y,rent=coef(chn.fit)[['log(real_rent)']])</span></span>
<span id="cb18-31">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(Year))</span>
<span id="cb18-35"></span>
<span id="cb18-36"></span>
<span id="cb18-37">pd5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb18-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-39">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA)),</span>
<span id="cb18-41">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-46">  ggrepel<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_text_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),</span>
<span id="cb18-47">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>,</span>
<span id="cb18-50">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2400</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb18-52">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High shelter cost by metro area"</span>,</span>
<span id="cb18-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of people in households paying &gt;30% of income on shelter costs</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(logit scale)"</span>,</span>
<span id="cb18-55">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average real rent of 2-bedroom units moved in during the past year in metro area</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(2021 dollars, log scale)"</span>,</span>
<span id="cb18-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011 NHS, 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-unaffordable-housing-need-rents" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-unaffordable-housing-need-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-unaffordable-housing-need-rents-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-unaffordable-housing-need-rents-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;13: Relationship between the share of the population in households with high shelter costs to income ratios and real rents in 2011, 2016 and 2021. This further confirms 2021 to be an outlier for lower-rent regions, while showing a very consistent relationship 2011 to 2016, with the main difference that real rents were significantly higher in 2016 with the population with high shelter cost increasing accordingly.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The relationship between rents and high shelter costs was quite similar between 2011 and 2016, with the important difference that the real rent spectrum expanded at the upper end. This led to the slope of the relationship already becoming steeper in 2016, but driven increasing unaffordability in some high rent metros (e.g.&nbsp;Vancouver and Toronto) rather than CERB payments especially benefiting those in low cost areas. Ultimately this makes it more clear that 2021 was likely an outlier, and we should be careful basing our expectations of how decrease in rent would affect core housing need estimates on that year. The 2016 data likely offers a better guide.</p>
<p>Just for completeness we shift from people to households with high shelter cost in Figure&nbsp;14. We see the relationship looks quite similar.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pd6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <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;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <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;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HSC=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>SHELCO <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> max_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb19-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Income=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(TOTINC,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb19-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,</span>
<span id="cb19-7">                  HSC,</span>
<span id="cb19-8">                  Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(HSC) </span>
<span id="cb19-12"></span>
<span id="cb19-13">response6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(\(y){</span>
<span id="cb19-16">    chn.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share<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;">log</span>(real_rent),</span>
<span id="cb19-17">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>),</span>
<span id="cb19-18">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>pd6 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y))</span>
<span id="cb19-19">    comparison_rent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (rent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb19-20">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb19-21">                                 Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-22">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent)) <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;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb19-23">    </span>
<span id="cb19-24">    modelsummary<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;">modelplot</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draw=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coef_omit=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect=</span> marginaleffects<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;">avg_comparisons</span>(chn.fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>comparison_rent))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate,</span>
<span id="cb19-27">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_share=</span>pd6 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-28">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect_pct=</span>rent_effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>base_share)</span>
<span id="cb19-29">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#tibble(Year=y,rent=coef(chn.fit)[['log(real_rent)']])</span></span>
<span id="cb19-30">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pumf_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(Year))</span>
<span id="cb19-34"></span>
<span id="cb19-35">pd6 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb19-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-37">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA)),</span>
<span id="cb19-39">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-44">  ggrepel<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_text_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),</span>
<span id="cb19-45">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(metro_grep_string,CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>,</span>
<span id="cb19-48">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2400</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb19-50">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High shelter cost by metro area"</span>,</span>
<span id="cb19-52">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of households paying &gt;30% of income on shelter costs</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(logit scale)"</span>,</span>
<span id="cb19-53">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average real rent of 2-bedroom units moved in during the past year in metro area</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(2021 dollars, log scale)"</span>,</span>
<span id="cb19-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011 NHS, 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-unaffordable-housing-need-rents2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-unaffordable-housing-need-rents2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-unaffordable-housing-need-rents2-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-unaffordable-housing-need-rents2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;14: Relationship between the share of the households with high shelter costs to income ratios and real rents in 2011, 2016 and 2021.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Results suggest that for a 30% decrease in rents, which would bring Vancouver’s market rents close to Montréal’s levels (which were around 35% lower than Vancouver for the last three censuses), we would expect to see a roughly 17% and 21% reduction in the overall share of the population paying more than 30% of income on shelter costs in 2011 and 2016. In terms of households, this would translate to a 12% and 14% reduction in the overall share paying more than 30% of income on shelter costs in 2011 and 2016, bringing Metro Vancouver close to the Canadian average, including newly formed households by existing as well as new residents.</p>
<p>These reductions in the share of households paying more than 30% of income on shelter costs are significantly lower than the estimates we found in the previous section where we (naively) held households fixed. Why the discrepancy? This brings us to the next section that tries to understand new household formation due to lower rents in more detail.</p>
</section>
<section id="household-formation-and-rents" class="level2">
<h2 class="anchored" data-anchor-id="household-formation-and-rents">Household formation and rents</h2>
<p>Households are malleable, and who decides to live together or strike out on their own responds to rents. In previous work we have looked in detail how household formation varies across metro areas and across time. <span class="citation" data-cites="estimating-suppressed-household-formation.2022 still-short-suppressed-households-in-2021.2022 housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2022a, 2022b, 2023a)</span>, and we will have more to say about this soon where we model individual level decision making in how households are formed. <span class="citation" data-cites="mhu.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span></p>
<p>Here we briefly recap the building blocks for this analysis: Minimal Household Units (MHU). Ermisch and Overton introduced the concept of Minimal Household Units (MHU) to better understand household formation. <span class="citation" data-cites="ermisch1985minimal">(Ermisch and Overton 1985)</span> The idea is to define elemental building blocks of households, which may be combined to form “complex” households. They start with single adults, parent-child, and couple relationships where we typically assume people want to live together, leaving four basic building blocks for households as:</p>
<ul>
<li>Adult individuals (MHU1)</li>
<li>Lone parents with dependent children (MHU2)</li>
<li>Childless married (or common law) couples (MHU3)</li>
<li>Married (or common law) couples with dependent children (MHU4)</li>
</ul>
<p>People obviously aren’t limited to living in these MHU forms of household, and may desire to live in other arrangements as well. But where we find people living in other arrangements, we shouldn’t assume they find them optimal. It’s at least as possible that people find themselves forced to live in non-MHU arrangements due to housing costs. To return to our musical chairs metaphor, MHU households are where people are most likely to keep sharing a chair even if more chairs were made available. Correspondingly, MHU analysis enables a peek at where housing costs produce households that would likely split apart if conditions were cheaper. This is perfect for our purposes here, and we have played around enough with this concept in past work, including identifying where it may fall short, to feel comfortable applying MHU analysis here. <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span></p>
<p>To start with, let’s take a look at Core Housing Need status by MHU Status, both for Canada as a whole, and for Metro Vancouver in particular, as per Figure&nbsp;15. As noted above, we can clearly see that single person adult households and single adult with children households are overrepresented within the Core Housing Need category, as well as within the group of households excluded from the measurement. By contrast, couples, and couples with kids are much more dominant within the set of households NOT considered in Core Housing Need.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">mhu_cats_2021 <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;">"Married spouse or common-law partner without children"</span>,</span>
<span id="cb20-2">                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Married spouse or common-law partner with children"</span>,</span>
<span id="cb20-3">                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Parent in a one-parent family"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person living alone"</span>)</span>
<span id="cb20-4"></span>
<span id="cb20-5">mhu_hh_cats_2021<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb20-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Couple without children"</span>,</span>
<span id="cb20-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Couple with children"</span>,</span>
<span id="cb20-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: one-parent family"</span>,</span>
<span id="cb20-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: one-person household"</span>)</span>
<span id="cb20-10"></span>
<span id="cb20-11">mhu_2016_recodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb20-12">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: one-person household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family households One person household"</span>,</span>
<span id="cb20-13">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: one-parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Lone parent family"</span>,</span>
<span id="cb20-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: one-parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: Lone parent family"</span>,</span>
<span id="cb20-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: two-or-more-person non-census-family household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-census-family household: Two or more person non-census-family household"</span></span>
<span id="cb20-16">)</span>
<span id="cb20-17"></span>
<span id="cb20-18">cfstat_2016_recodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb20-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Parent in a one-parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lone parent"</span>,</span>
<span id="cb20-20">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a lone parent"</span>,</span>
<span id="cb20-21">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person not in a census family living with non-relatives only"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person living with non-relatives only"</span></span>
<span id="cb20-22">)</span>
<span id="cb20-23"></span>
<span id="cb20-24">fam_grep_string <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;">"common-law|married|spouse|partner|Comlaw|Commlaw|husband|wife"</span></span>
<span id="cb20-25"></span>
<span id="cb20-26">mhu4_cats_2021 <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;">"Married spouse or common-law partner with children"</span>)</span>
<span id="cb20-27"></span>
<span id="cb20-28"></span>
<span id="cb20-29">mhu_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;">bind_rows</span>(pumf_2021,</span>
<span id="cb20-30">                      pumf_2016 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb20-31">                        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CHDBN,CQPPB,CAPGN,CHLDC,EICBN,EMPIN,GOVTI,GTRFS,INCTAX,INVST,MRKINC,</span>
<span id="cb20-32">                                        OASGI,OTINC,RETIR,SEMPI,TOTINC_AT,VALUE,WAGES),</span>
<span id="cb20-33">                                      as.numeric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-34">                        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHTYPE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(HHTYPE,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!!</span>mhu_2016_recodes)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-35">                        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CFSTAT=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CFSTAT,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!!</span>cfstat_2016_recodes))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TOTINC,VALUE),\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">88888888</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,x)))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">child=</span>AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 4 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 to 6 years"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"7 to 9 years"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 to 11 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12 to 14 years"</span>,</span>
<span id="cb20-38">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_CFSTAT=</span>CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> mhu_cats_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb20-40">           (CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> child)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_HHTYPE=</span>HHTYPE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> mhu_hh_cats_2021) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_hhcf=</span>MHU_CFSTAT<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>MHU_HHTYPE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU4=</span>CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> mhu4_cats_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb20-44">           (CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> child)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GROSRT=</span>SHELCO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHCLASS=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Private household"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SEX=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(GENDER,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Woman+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Man+"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHSIZE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(HHSIZE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NULL =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CFSIZE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CFSIZE,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 person"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person not in a census family"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NULL =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">HHSIZE_n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(HHSIZE,<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;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" |</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CFSIZE_n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(CFSIZE,<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;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" |</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-52">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#mutate(CFSIZE_n=ifelse(CFSIZE=="Non-family person",1,CFSIZE_n)) |&gt;</span></span>
<span id="cb20-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_size=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE_n)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(HHSIZE_n) <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;">NA</span>,</span>
<span id="cb20-54">                            CFSIZE_n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>HHSIZE_n <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="cb20-55">                            CFSIZE_n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span>HHSIZE_n <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;">NA</span>,</span>
<span id="cb20-56">                            CFSIZE_n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>HHSIZE_n <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="cb20-57">                            <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_size=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(MHU_size <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a"</span>,CFSTAT) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> child),</span>
<span id="cb20-59">                           (<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;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a"</span>,CFSTAT) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> child))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(MHU_size<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>MHU_hhcf,MHU_hhcf)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU1=</span>MHU<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE_n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> CFSIZE_n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb20-62">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE_n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person living alone"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NCFPL Living alone"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU2=</span>MHU <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lone parent|lone-parent|Lonepar|one-parent"</span>,CFSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb20-64">                       HHTYPE<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;">"One-family only households: Lone parents"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU3=</span>MHU<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> CFSIZE_n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(fam_grep_string,CFSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb20-66">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE_n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> HHTYPE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Couple without children"</span>,</span>
<span id="cb20-67">                                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-family only households: Married couples or common-law partners without children"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU4=</span>MHU<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> CFSIZE_n<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;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(fam_grep_string,CFSTAT,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ignore.case =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb20-69">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(CFSIZE_n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> HHTYPE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fam-Oneh-Cou-NowM-wNMSD-woAP"</span>,</span>
<span id="cb20-70">                                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household without additional persons: Couple with children"</span>,</span>
<span id="cb20-71">                                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-family only households: Married couples or common-law partners with children"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> child) )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-72">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_cat=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb20-73">    MHU1 <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;">"Single adult (MHU1)"</span>,</span>
<span id="cb20-74">    MHU2 <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;">"Single with kid(s) (MHU2)"</span>,</span>
<span id="cb20-75">    MHU3 <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;">"Couple adult (MHU3)"</span>,</span>
<span id="cb20-76">    MHU4 <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;">"Couple with kid(s) (MHU4)"</span>,</span>
<span id="cb20-77">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-MHU"</span>,</span>
<span id="cb20-78">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-79">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_cat=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(MHU_cat,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Single adult (MHU1)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Single with kid(s) (MHU2)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple adult (MHU3)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple with kid(s) (MHU4)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-MHU"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-80">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">school=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(ATTSCH) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> ATTSCH <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;">"Not available"</span> <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;">"Not available"</span>,</span>
<span id="cb20-81">                          ATTSCH <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable (&lt; 15 years)"</span>) <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;">"Not applicable"</span>,</span>
<span id="cb20-82">                          ATTSCH <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Did not attend in past 9 mths."</span>,</span>
<span id="cb20-83">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NotAttendPast8Months"</span>,</span>
<span id="cb20-84">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Did not attend school"</span>,</span>
<span id="cb20-85">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Do not attend"</span>,</span>
<span id="cb20-86">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not attending school"</span>) <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;">"Not attending school"</span>, </span>
<span id="cb20-87">                          <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Attending school"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-88">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NMHU_cat =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb20-89">    MHU <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;">"MHU"</span>,</span>
<span id="cb20-90">    HHTYPE <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;">"Non-census-family household: two-or-more-person non-census-family household"</span> <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;">"Living with roommates"</span>,</span>
<span id="cb20-91">    HHTYPE <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;">"Multiple-census-family household"</span> <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;">"Living in multifamily household"</span>,</span>
<span id="cb20-92">    CFSTAT <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;">"Person not in a census family but living with other relatives"</span> <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;">"Living with relatives"</span>,</span>
<span id="cb20-93">    CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb20-94">      AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span>) <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;">"Young adult 25 to 39 living with parents"</span>,</span>
<span id="cb20-95">    CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb20-96">      AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 year old living with parents"</span>,</span>
<span id="cb20-97">    CFSTAT <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a couple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Child of a parent in a one-parent family"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb20-98">      AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"40 to 44 years"</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 49 years"</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50 to 54 years"</span>) <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;">"Older adult 40+ living with parents"</span>,</span>
<span id="cb20-99">    HHTYPE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: Couple without children"</span>,</span>
<span id="cb20-100">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: Couple with children"</span>,</span>
<span id="cb20-101">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-census-family household with additional persons: one-parent family"</span>)  <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;">"Living in complex household"</span>,</span>
<span id="cb20-102">    Year<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;">"2006"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> HHTYPE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One family, common-law couple"</span>,</span>
<span id="cb20-103">                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One family, lone parent family"</span>,</span>
<span id="cb20-104">                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One family, married couple"</span>) <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;">"Living in complex household"</span>,</span>
<span id="cb20-105">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span></span>
<span id="cb20-106">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-107">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NMHU_cat=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(NMHU_cat,</span>
<span id="cb20-108">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 year old living with parents"</span>,</span>
<span id="cb20-109">                                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Young adult 25 to 39 living with parents"</span>,</span>
<span id="cb20-110">                                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Older adult 40+ living with parents"</span>,</span>
<span id="cb20-111">                                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living in multifamily household"</span>,</span>
<span id="cb20-112">                                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living with roommates"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living with relatives"</span>,</span>
<span id="cb20-113">                                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living in complex household"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-114">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_full=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb20-115">    MHU <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> MHU_cat,</span>
<span id="cb20-116">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> NMHU_cat</span>
<span id="cb20-117">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-118">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">MHU_full=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(MHU_full,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(MHU_cat),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(NMHU_cat)),<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;">"MHU"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-MHU"</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-119">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Maintainer=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Primary household maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PrimaryHhldMaintainr"</span>,</span>
<span id="cb20-120">                                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is primary maintainer"</span>)<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;">"Maintainer"</span>,</span>
<span id="cb20-121">                              PRIHM <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not primary hhld. maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoPrimryHhldMaintain"</span>,</span>
<span id="cb20-122">                                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not primary household maintainer"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Person is not primary maintainer"</span>)<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;">"Not a maintainer"</span>,</span>
<span id="cb20-123">                              PRIHM<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;">"Not applicable"</span><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;">"Not applicable"</span>,</span>
<span id="cb20-124">                              <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-125">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">EFDECILE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(EFDECILE,</span>
<span id="cb20-126">                             <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;">setNames</span>(pumf_2021<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EFDECILE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(),</span>
<span id="cb20-127">                                         pumf_2016<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EFDECILE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())),</span>
<span id="cb20-128">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SUBSIDY=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(SUBSIDY,</span>
<span id="cb20-129">                             <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;">setNames</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;">"Not subsidized"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subsidized"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>),</span>
<span id="cb20-130">                                         <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;">"No, not a subsidized dwelling"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes, a subsidized dwelling"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span> ))))</span>
<span id="cb20-131"></span>
<span id="cb20-132">mhu_full_colours <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;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(RColorBrewer<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;">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;">"YlGn"</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(),</span>
<span id="cb20-133">                               RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OrRd"</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;">9</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>()),</span>
<span id="cb20-134">                             mhu_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>MHU_full <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())</span>
<span id="cb20-135"></span>
<span id="cb20-136"></span>
<span id="cb20-137">mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb20-138">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb20-139">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb20-140">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MHU_full,HCORENEED_IND,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-141">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-142">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb20-143">              <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(PRIHM=="Person is primary maintainer") |&gt;</span></span>
<span id="cb20-144">              <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb20-145">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MHU_full,HCORENEED_IND,CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-146">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#,"Calgary","Toronto","Montréal","Québec"</span></span>
<span id="cb20-147">              )))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb20-148">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-149">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(HCORENEED_IND),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full)))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-150">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-151">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># scale_x_continuous(labels = \(x)scales::comma(x,scale=10^-3,suffix="k")) +</span></span>
<span id="cb20-152">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-153">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_full_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-154">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-155">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-156">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population in private households by Minimum Household Unit status"</span>,</span>
<span id="cb20-157">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(counting parents of adult children as in MHU)"</span>,</span>
<span id="cb20-158">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb20-159">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Status"</span>,</span>
<span id="cb20-160">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of people"</span>,</span>
<span id="cb20-161">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-status-by-chn" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-status-by-chn-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-mhu-status-by-chn-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-status-by-chn-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;15: Population by Household Status and Core Housing Need
</figcaption>
</figure>
</div>
</div>
</div>
<p>Most households overall, both within and outside of Core Housing Need, are in our MHU (Minimal Household Unit) categories. But comparing horizontally, we can see a greater proportion of complicated households in the non-MHU categories are showing up in pricey Vancouver than across Canada as whole. In general, these non-MHU households mostly show up as Not in Core Housing Need. This is one of our indicators that people respond to high housing costs by doubling up. Once they double up, their combined incomes better enable them to spend less than 30% of their income on shelter costs. But residents of these doubled up households might not consider their living arrangements as optimal. Instead, their household types often reflect their unmet need.</p>
<p>Let’s look more specifically at people living in non-MHU households, and break them out by age, as per Figure&nbsp;16. We’re pulling the 20 to 24 year olds out from the broader category of other young adults living with their parents primarily because their status as adults is more malleable, as is how their residency is recorded within the Census (post-secondary students are often recorded as living with their parents, even if they spend most of the year away at school).</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(NMHU_cat<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;">"MHU"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb21-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(NMHU_cat,AGEGRP,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Canada"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(NMHU_cat<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;">"MHU"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-8">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb21-9">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(NMHU_cat,CMA,AGEGRP,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#,"Calgary","Toronto","Montréal","Québec"</span></span>
<span id="cb21-11">                      )))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb21-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb21-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(NMHU_cat),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(AGEGRP)))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population in private households not in Minimum Household Units"</span>,</span>
<span id="cb21-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(not counting parents of adult children)"</span>,</span>
<span id="cb21-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb21-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age"</span>,</span>
<span id="cb21-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>,</span>
<span id="cb21-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-non-mhu" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-non-mhu-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-non-mhu-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-non-mhu-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;16: Overview of living arrangements of the population not in Minimum Household Units in Canada and Metro Vancouver by age group
</figcaption>
</figure>
</div>
</div>
</div>
<p>Overall there is a fair amount of diversity in non-MHU household arrangements, including lots of single adults living with their parents, but also lots of multigenerational families, where parents live with their coupled children and/or grandchildren. Living with roommates is also common, especially for young adults. Complex households, including for instance unrelated adults living with couples, remain complex. To emphasize a point, many of these households might choose to live together even if they weren’t forced to do so by housing costs. But housing costs are probably a major reason for their shared arrangements, and if rent got cheaper, there’s a decent chance these households would fissure.</p>
<p>This helps understand how people adapt to our current housing shortage by doubling up, and we have traced out elsewhere how this changed over time and how shares of doubling up vary across metro areas. <span class="citation" data-cites="housing-outcomes.2023 tenure-and-household-independence-across-the-life-course-1981-2021.2024">(<span class="nocase">von Bergmann and Lauster</span> 2023a, 2024a)</span> But how does doubling up relate to prevailing rent levels, and how many more households can we expect to form if rents drop? Figure&nbsp;17 shows the relationship between metro area share of the population not in minimum household units and prevailing rents.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">mhu_model_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb22-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(MHU,CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>MHU) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) </span>
<span id="cb22-8"></span>
<span id="cb22-9">model_years <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;">"2016"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>)</span>
<span id="cb22-10">all_years <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;">"2011"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>)</span>
<span id="cb22-11">year_colours <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;">setNames</span>(sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>trios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c142 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(),all_years)</span>
<span id="cb22-12"></span>
<span id="cb22-13">mhu.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prihm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(model_years)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb22-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_modify</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> {.x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb22-16">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share <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;">log</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>mhu_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year),</span>
<span id="cb22-17">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-18">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log(real_rent)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>())</span>
<span id="cb22-19">      }) </span>
<span id="cb22-20"></span>
<span id="cb22-21">mhu.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share <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;">log</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>mhu_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y),</span>
<span id="cb22-23">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(model_years)</span>
<span id="cb22-25"></span>
<span id="cb22-26">mhu.coeffs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu.fit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-27">  modelsummary<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;">modelplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draw=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coef_omit=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>) </span>
<span id="cb22-28"></span>
<span id="cb22-29">mhu.effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y) marginaleffects<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;">avg_comparisons</span>(mhu.fit[[y]],</span>
<span id="cb22-31">                                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>(mhu_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb22-32">                                                                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb22-33">                                                                                  Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-34">                                                                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>real_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-35">                                                                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent))<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;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(model_years)</span>
<span id="cb22-37"></span>
<span id="cb22-38">mhu.effect_vancouver_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.3</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu.effect <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(me)me<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate) </span>
<span id="cb22-40"></span>
<span id="cb22-41">mhu_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb22-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-43">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-46">  ggrepel<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_label_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),</span>
<span id="cb22-47">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ffffff88"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb22-51">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population in private households not in Minimum Household Units"</span>,</span>
<span id="cb22-53">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(not counting parents of adult children)"</span>,</span>
<span id="cb22-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population not in MHU (logit scale)"</span>,</span>
<span id="cb22-55">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average real 2-bedroom rent of recent movers (2021 dollars, log scale)"</span>,</span>
<span id="cb22-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-share-rent" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-share-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-mhu-share-rent-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-share-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;17: Relationship between share of population not in minimum household units and prevailing rents for Canadian metro areas.
</figcaption>
</figure>
</div>
</div>
</div>
<p>There are some caveats for interpreting this relationship causally. The simplified linear plot is missing some important confounders, in particular income, couple status, and some measure of cultural openness to non-MHU living arrangements. The outlier in the lower left, Metro Québec, has high incomes and a comparatively homogeneous cultural makeup. We investigate this in more detail elsewhere <span class="citation" data-cites="mhu.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span> to show that even after accounting for these (and other) factors the relationship between rents and MHU status remains of similar strength and there is good reason to interpret it causally. Taking this graph at face value it suggests that a 30% reduction in rents leads to a 9 percentage point reduction in the share of the population not in MHU, bringing Vancouver close to Montréal’s share.</p>
<p>Reversing this interpretation and using a slightly different measure, we can look at primary household maintainer rates (also known as household headship rates). Statistics Canada defines this as the first person listed in the household roster who contributes to paying rent, mortgage, or other shared household costs, so only one person is identified as the primary maintainer for every household. This isn’t quite as neat a measure as MHU status, insofar as, e.g., a two-person household containing a couple, two roommates, or a parent and adult child would all have the same maintainer rate (0.5), even though we’re probably only safe in assuming the couple would continue living together if a free apartment was offered (and even this might be debated!) But household maintainer rates are easier to calculate than MHU status, and provide us with another check on the underlying relationship to rent. Figure&nbsp;18 provides a look at this relationship, which largely replicates the MHU analysis above. As rents go up, household maintainer rates go down.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">prihm_model_data_age <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0 to 4 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 to 6 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"7 to 9 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10 to 11 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12 to 14 years"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb23-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(PRIHM,CMA,Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,AGEGRP))</span>
<span id="cb23-7"></span>
<span id="cb23-8">age_model_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-11">  <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;">Pop=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb23-12">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP)) </span>
<span id="cb23-13"></span>
<span id="cb23-14"></span>
<span id="cb23-15">prihm_model_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prihm_model_data_age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(age_model_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AGEGRP"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-17">  <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;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Share,Pop),</span>
<span id="cb23-18">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),</span>
<span id="cb23-19">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,PRIHM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">naiveShare=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) </span>
<span id="cb23-23"></span>
<span id="cb23-24">prihm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(model_years)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb23-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_modify</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> {.x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb23-27">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share <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;">log</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>prihm_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year),</span>
<span id="cb23-28">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'logit'</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-29">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log(real_rent)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-30">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(naiveShare) <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;">log</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>prihm_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent2=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(fit2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log(real_rent)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>())</span>
<span id="cb23-32">      }) </span>
<span id="cb23-33"></span>
<span id="cb23-34">prihm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Share <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;">log</span>(real_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>prihm_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y),</span>
<span id="cb23-36">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(model_years)</span>
<span id="cb23-38"></span>
<span id="cb23-39">  </span>
<span id="cb23-40">prihm.effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y) </span>
<span id="cb23-42">         marginaleffects<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;">avg_comparisons</span>(prihm.fit[[y]],</span>
<span id="cb23-43">                                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>(mhu_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb23-44">                                                                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb23-45">                                                                             Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-46">                                                                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>real_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-47">                                                                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent))<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;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>))</span>
<span id="cb23-48">         )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(model_years)</span>
<span id="cb23-50"></span>
<span id="cb23-51">prihm.effect_vancouver_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.3</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prihm.effect <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(me)me<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate) </span>
<span id="cb23-53"></span>
<span id="cb23-54"></span>
<span id="cb23-55">prihm_model_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-57">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-60">  ggrepel<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_label_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Montréal"</span>)),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>CMA),</span>
<span id="cb23-61">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ffffff88"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-64">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb23-65">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household maintainer rates of the population 15 years or over in private households"</span>,</span>
<span id="cb23-67">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Age-adjusted to 2021 Canada population)"</span>,</span>
<span id="cb23-68">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age-adjusted household maintainer rate (logit scale)"</span>,</span>
<span id="cb23-69">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average real 2-bedroom rent of recent movers (2021 dollars, log scale)"</span>,</span>
<span id="cb23-70">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-prihm-share-rent" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-prihm-share-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-prihm-share-rent-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-prihm-share-rent-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;18: Relationship between age-adjusted household maintainer rates and prevailing rents for Canadian metro areas.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Interpreted causally this suggests that a 30% reduction in rent leads to a 5 percentage point higher household maintainer rate, which translates into 9% more households just from the population that already lives in the region and not accounting for fewer people leaving the region or more moving there if rents were 30% lower. Of course we don’t have an additional 9% housing units for these households to form, and that pent-up demand provides a very tangible reason why rents aren’t 30% lower.</p>
<p>This affects different age groups differently. Young adults stand to benefit most from rent reduction by increasing household formation. Figure&nbsp;19 shows this much higher sensitivity compared to the overall population.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">prihm_model_age_groups <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;">"25 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span>)</span>
<span id="cb24-2"></span>
<span id="cb24-3">prihm_model_data_age_clean <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prihm_model_data_age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PRIHM<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;">"Person is primary maintainer"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> prihm_model_age_groups) </span>
<span id="cb24-7"></span>
<span id="cb24-8">prihm.fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(prihm_model_age_groups,</span>
<span id="cb24-9">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>prihm_model_data_age_clean<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-10">                                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>()),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(model_years)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb24-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(AGEGRP,Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_modify</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> {</span>
<span id="cb24-13">    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;">glm</span>(Share <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;">log</span>(real_rent),</span>
<span id="cb24-14">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>prihm_model_data_age_clean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-15">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP,Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year),</span>
<span id="cb24-16">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'logit'</span>))</span>
<span id="cb24-17">    r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (prihm_model_data_age_clean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb24-18">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Vancouver"</span>),</span>
<span id="cb24-19">                   AGEGRP<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP,Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-20">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>real_rent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-21">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(real_rent))<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;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb24-22">    .x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb24-23">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(m)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(fit,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log(real_rent)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rent_effect=</span>marginaleffects<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;">avg_comparisons</span>(m,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">real_rent=</span>r))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate)</span>
<span id="cb24-26">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb24-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb24-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(prihm_model_data_age_clean <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-29">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Vancouver"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-30">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(AGEGRP,Year,Share),</span>
<span id="cb24-31">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AGEGRP"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_effect=</span>rent_effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Share) </span>
<span id="cb24-33">      </span>
<span id="cb24-34">prihm.effect_age_vancouver_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.3</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prihm.fit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-35">  <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;">rent_effect=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(rent_effect),</span>
<span id="cb24-36">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_effect=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(pct_effect),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>AGEGRP) </span>
<span id="cb24-37">  </span>
<span id="cb24-38">prihm_model_data_age_clean  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb24-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>real_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-40">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-42">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># geom_point(data=~filter(.,CMA %in% c("Vancouver","Montréal")),show.legend = FALSE) +</span></span>
<span id="cb24-43">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ggrepel::geom_label_repel(data=~filter(.,CMA %in% c("Vancouver","Montréal")),aes(label=CMA),</span></span>
<span id="cb24-44">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                           fill="#ffffff88",show.legend = FALSE) +</span></span>
<span id="cb24-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> \(x)scales<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;">dollar</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>,</span>
<span id="cb24-47">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household formation by age and prevailing rents"</span>,</span>
<span id="cb24-51">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household maintainer rate (logit scale)"</span>,</span>
<span id="cb24-52">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average 2-bedroom rent of recent movers (log scale)"</span>,</span>
<span id="cb24-53">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-prihm-share-rent-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-prihm-share-rent-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-prihm-share-rent-age-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-prihm-share-rent-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;19: Relationship between age-specific household maintainer rates for young adults and prevailing rents for Canadian metro areas.
</figcaption>
</figure>
</div>
</div>
</div>
<p>This shows a 30% decrease in rents leads to a 8, 5, and 4 percentage points higher household formation rate, translating into 25%, 11%, and 9% more households, for the age groups 25 to 29 years, 30 to 34 years, and 35 to 39 years, respectively.</p>
<p>To summarize, more housing would lead to lower rents, which in turn would still lead to a lower share of households in core housing need. But lower rents would also lead to more households overall, even if we held the population constant. And that’s because high rents suppress household formation by forcing people to live together who would otherwise prefer to live apart. Even though we expect Core Housing Need to decrease overall as estimated in Section&nbsp;7.1, many of the new households created would be at higher risk of core need than the non-MHU households they left behind, pointing to some of the complexities of Core Housing Need measurement as well as its underlying churn. Nevertheless, we can also see how more housing would have broad benefits extending beyond the Core Housing Need measure. And this also ties back to our earlier observation that Core Housing Need, as well as shelter-cost-to-income ratio affordability measures, have significant shortfalls when housing shortages impact household formation, as we have discussed before. <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span></p>
<p>What about if we don’t hold population constant?</p>
</section>
<section id="triangulating-migration-effects" class="level2">
<h2 class="anchored" data-anchor-id="triangulating-migration-effects">Triangulating migration effects</h2>
<p>We’re not worried about all sources population change (i.e.&nbsp;births, deaths, and migration). Births tend to take place within household contexts without much effect on the number of households. More broadly, changes in births and deaths tend to be slow moving, and don’t adjust much to housing availability. The same cannot be said of migration. If housing in Vancouver was cheaper, more people would probably move here, and fewer people would move away.</p>
<p>Migration effects are difficult to estimate, but we can approximate them by considering the gap between impacts on household formation rates and our general understanding of demand elasticities to price. General econometric estimates suggest that for each 1% increase in housing stock we expect a roughly 2% decrease in prices and rents.<sup>5</sup> Or conversely, to a achieve a 30% decrease in rents we would need to increase housing stock by about 15%. In the previous section we estimated that this would increase household formation by about 9%, and if tuned specifically to Vancouver this increases to 10%. The remaining 5% of housing growth needed to achieve our 30% rent reduction can mostly be interpreted as filling demand from increased net in-migration. These are the people being held back from living in Vancouver due to high rents, but who would move (or stay) here if rents were cheaper.</p>
<p>This assumes that households generally occupy just one dwelling, setting aside vacation homes and other long-term vacancies. Setting these aside seems to be a pretty safe assumption in Vancouver, given what we know from Empty Homes Tax and Speculation and Vacancy Tax data, but it might not hold everywhere.<span class="citation" data-cites="three-years-svt.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021b)</span> More importantly, these kind of estimates by triangulation of estimates of quantities using different methods are error prone. They should be taken with a grain of salt, but they give us at least some idea of how these different demand components, suppressed household formation and suppressed migration, might split if housing costs were cheaper in Vancouver. We expect different methods would come up with different splits, and we would also expect the splits to vary by metropolitan area. But while further triangulation, or better, a way to directly estimate migration effects, would be helpful, this provides a start at linking an expected demographic response to a big supply increase.</p>
</section>
</section>
<section id="other-considerations" class="level1">
<h1>Other considerations</h1>
<p>The above provides a decent summarization of the distributional effects we expect. But there are are a couple of other things we want to consider that may factor into further refinements of our projections. In particular, just as rent control can partially insulate long-term tenants from rapid rise in market rents, it also potentially insulates long-term tenants from the benefits of a drop in market rents, so we want to take a look at possible rent control effects. We also want to think a little more about the other side of our affordability metrics: incomes. Should we really be holding them constant?</p>
<section id="sec-rent-control" class="level2">
<h2 class="anchored" data-anchor-id="sec-rent-control">Rent control</h2>
<p>British Columbia has rent control tied to tenancies (not to units). The province controls the amount that landlords can raise rents for existing tenants. By contrast, landlords can set rents for new tenants at turnover to whatever they think the market will bear. As a result, long-term tenants tend to have much lower rents than new tenants. Currently there is a protective effect of rent control if long-term tenants stay put, but they lose this effect if they wish to move. This protective effect means that long-term tenants may not benefit as much from new supply. We can estimate the protective effect of rent control as a <em>Moving Penalty</em>, that is how much more in rent a sitting 2-bedroom tenant might pay if they had to move and rent an equivalent 2-bedroom unit at market rates. Working with census data to get some sense of long-term tenancy benefits, we compare rents of households who did not move in the past 5 years to those who moved in the past year as shown in Figure&nbsp;20.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">mp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb25-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(old_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb25-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Moving penalty</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>real_rent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>real_old_rent<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Moving penalty</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(CMA))) </span>
<span id="cb25-5"></span>
<span id="cb25-6">mp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb25-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Other"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb25-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Moving penalty</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moving penalty for people renting 2 bedroom units</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">for more than 5 years"</span>,</span>
<span id="cb25-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb25-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ratio of rents of people who did not move in previous 5 years to those who moved in previous year."</span>,</span>
<span id="cb25-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2011 NHS, 2016, 2021 PUMF (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-moving-penalty" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-moving-penalty-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-moving-penalty-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-moving-penalty-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;20: The Moving Penalty measures how binding rent control is. Here it’s measured as the ratio of rents of recent movers to those who have rented at the same place for five or more years. This does not control for quality, which likely biases this metric upward.
</figcaption>
</figure>
</div>
</div>
</div>
<p>There are some caveats to this simple measure of the moving penalty. It does not control for unit quality or location, and recent movers skew toward new buildings. Moreover, 2021 was also a special year with many provinces implementing rent freezes in the wake of the COVID pandemic. But the effects shown are sizable and stable when cross-checking against the thinner and more volatile hierarchical PUMF data (allowing for slicing by building age as an additional control). If we take non-rent controlled Calgary, Edmonton and Regina - Saskatoon as a baseline, then a 10% to 15% moving penalty might be considered <em>normal</em> in the absence of rent control. This also shows that there is no clear boundary between regions with rent control and regions without. Moderate rent control in areas that allow for a lot of new housing or don’t see much demand growth may not be very binding (e.g.&nbsp;Québec). But a large Moving Penalty indicates strongly binding rent control.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1">yvr_mp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Vancouver"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Moving penalty</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb26-2"></span>
<span id="cb26-3">mov_share <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Age %in% c("25 to 29 years","30 to 34 years")) |&gt;</span></span>
<span id="cb26-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(`Household size`=="1 person") |&gt;</span></span>
<span id="cb26-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">moved=</span>MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-9">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb26-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,moved)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>moved)</span>
<span id="cb26-13"></span>
<span id="cb26-14">mov_share <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pumf_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-15">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Age %in% c("25 to 29 years","30 to 34 years")) |&gt;</span></span>
<span id="cb26-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-17">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(`Household size`=="1 person") |&gt;</span></span>
<span id="cb26-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">moved=</span>MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-20">  <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;">Count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb26-21">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year,moved)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>Count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb26-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>moved)</span>
<span id="cb26-24"></span>
<span id="cb26-25"></span>
<span id="cb26-26">yvr_moved <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mov_share <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA<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;">"Vancouver"</span>,Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Share)</span></code></pre></div></div>
</details>
</div>
<p>Vancouver has a 40% moving penalty, meaning long-term tenants have a lot of protection against market rent-setting. As a result, our projected 30% market rent decrease doesn’t do much to lower rent for long-term tenants who want to stay put. While renters move more often than owners, long-term tenants are still a sizeable group, including 35% of Vancouver renter households who have not moved in the previous 5 years. But even if their rents likely won’t decrease, long-term tenants still benefit from the increased choice opened up by a much lower moving penalty, consequent reductions in doubling up, and potentially lower eviction pressure, especially in the secondary rental market.</p>
<p>This does add a caveat on some of our estimates of how many people may be lifted out of unaffordable housing by the reduction in market rent. In particular, where we hold households constant, as in Figure&nbsp;11, we know that a number of these households are probably long-time tenants. When take this into account and sum up across categories of beneficiaries, as in Figure&nbsp;21, we see that the majority of the drop in those experiencing unaffordable housing comes from recent movers, not long-time tenants. But taking long-time tenants into account, the drop overall would not be as large as predicted.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">summary_data_people_mob <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;">bind_rows</span>(pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Successful</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">housing target"</span>),</span>
<span id="cb27-2">                                 pd1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Actual"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(effect_colours))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(MOB5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not available"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not applicable"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">moved=</span>MOB5 <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;">"Non-movers"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-8">  <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;">People=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(WEIGHT),</span>
<span id="cb27-9">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WEIGHT),</span>
<span id="cb27-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Type,TENUR,HCORENEED_IND,Year,moved)) </span>
<span id="cb27-11"></span>
<span id="cb27-12">summary_data_people_mob <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb27-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>People,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>moved)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">comma</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c103,</span>
<span id="cb27-17">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moved in</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">pervious 5 years"</span>,</span>
<span id="cb27-18">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Did not move in</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">pervious 5 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,</span>
<span id="cb27-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people in households paying more than 30% of income on shelter costs"</span>,</span>
<span id="cb27-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb27-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb27-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: StatCan Census 2021 PUMF (individuals)"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-chn-reduction-movers" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-chn-reduction-movers-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-chn-reduction-movers-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-chn-reduction-movers-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;21: People in core housing need for actual vs counter-factual scenario where rents are 30% lower, split by whether they moved in the previous 5 years. The majority of people in core housing need are among those who moved in the previous 5 years, and that’s where the majority of the counter-factual reduction manifests.
</figcaption>
</figure>
</div>
</div>
</div>
<p>This effect is less clearly an issue for our estimates where we break out household formation and net in-migration effects in addition to the decline in unaffordable housing, insofar as other metro areas with rent control (e.g.&nbsp;Montréal) are part of the predictor for how much unaffordable housing would remain in Vancouver with much lower rents, but we could still expect the specific forms of rent control to matter.</p>
</section>
<section id="income" class="level2">
<h2 class="anchored" data-anchor-id="income">Income</h2>
<p>Turning to incomes, so far we have held these constant, but we know they matter enormously in affordability metrics, and indeed we’ve seen how the income boosts from Covid supports affected 2021 estimates. Should we hold incomes constant where we project a large boost in housing supply? We have seen that adding housing increases both household formation of existing households as well as net in-migration. Net in-migration results in an increase in labour supply that may not be fully off-set by an increase in labour demand resulting from said in-migration. <span class="citation" data-cites="corinth2023">Corinth and Irvine (2023)</span> assume a net downward pressure on income, which may slow the fairly strong growth in income Metro Vancouver has seen in the past. Lower incomes would worsen affordability metrics, even if they reflected greater accessibility for those previously feeling locked out of the area. At the same time, it’s not clear to us that labour demand would fail to keep pace with, or even exceed, incoming supply. In particular, constructing so much housing would, itself, put an enormous amount of pressure on labour markets. Moreover, we would expect productivity gains due to increases in agglomeration effects, as well as due to small effects of shifting some consumer spending away from housing to more productive uses. Rising incomes would result in fewer people in unaffordable housing. Overall, we know incomes matter enormously for affordability, and a supply shock of the sort we’re modeling here would likely also affect income distributions, but the direction and effects are difficult to fully predict.</p>
</section>
</section>
<section id="dos-and-donts-of-housing-targets" class="level1">
<h1>Dos and Don’ts of housing targets</h1>
<p>Finally, we want to return to a discussion of housing targets. We set our target as a big overall number of net new dwellings we want to hit. But that’s not how everyone approaches the matter. The broad distributional effects of hitting our target are why we think our approach is the right one. Here we want to turn to consideration of the problems with some of the alternatives.</p>
<p>Housing targets are generally seen as the way out of our current housing shortage. Ideally we would not need targets but reshape our housing system in a way that it would broadly allow people to build housing. But everything is path dependent, and housing targets might be a bridge to get us from our current regulatory framework to a different equilibrium point where the price of housing does not climb above the marginal social cost to produce it. In other words, we could treat housing as a societal good, rather than a nuisance to be regulated away.</p>
<p>But how should we structure housing targets? We have pointed out that housing targets strongly depend on values. <span class="citation" data-cites="simple-metrics-for-deciding-if-you-have-enough-housing.2019">(<span class="nocase">Lauster and von Bergmann</span> 2019)</span> If you’re already comfortably housed, but concerned about physical changes to your neighbourhood and value that over the desires of other people to live close to jobs and amenities, you might be inclined to set low (or even negative) housing targets. If you believe that housing is good, actually, you might set your minimum targets at the number of dwelling units the market would provide if it were not constrained by regulation like zoning. This latter is the value we chose when estimating housing targets for Metro Vancouver. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span></p>
<p>Additionally, some approaches to housing targets try to set targets based on household income bands, number of bedrooms, structural type of housing (e.g.&nbsp;ground oriented vs apartment), or tenure. These approaches tend to ignore the broad systemic effects of adding any kind of new housing, which we detail above. A lot of other assumptions are also left implicit in these approaches, generally crafted around the ideas that: a) net in-migration is exogenous to housing costs, b) the current household mix is exogenous to housing costs, c) some set of housing needs can be readily fitted to different types of households, and d) some set of preferences can be read from current arrangements. We believe the first two assumptions are simply wrong, as we show above (see also <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023a)</span>). Measures like Core Housing Need are directly derived from the third notion that we can fit needs to different types of households, and are fine where explicit. But from our analysis above we can already see all of the complexity of making Core Housing Needs work (where it does so), and the gaps where it doesn’t work at all. The final assumption, that preferences can be read from current arrangements, tends to ignore the constraints placed on people living under housing shortage, and cycles back to why the first two assumptions are wrong. People move. Distributions of people into dwellings under current housing shortages may not transfer to distributions where housing shortages are relieved. We will consider the main approaches to target housing to specific households and briefly discuss the problems that arise when ignoring distributional effects of adding housing.</p>
<section id="income-1" class="level2">
<h2 class="anchored" data-anchor-id="income-1">Income</h2>
<p>Some approaches are asking for new market housing to be built to specific income bands. This is probably well-meaning, but fundamentally misunderstands the systemic nature of how housing works. As we have seen, most moves are moves into old housing, but supply effects from new housing propagate throughout the housing system. As a result, the main purpose of new housing from an affordability perspective is to make old housing more affordable, as well as to prime the pump on moving chains that improve housing outcomes by allowing people to better match their preferences to their housing.</p>
<p>Moreover, households are outcomes of systemic housing pressures. Current households and their income and shelter cost tell us something about how people are coping with the current housing market, but they are of limited use to tell us how people would distribute over households in a situation where we had more housing as imagined when setting housing targets. This requires simulating distributional effects of adding housing, both for rents and for household formation. Holding them fixed introduces significant collier bias.</p>
<p>Additionally structuring housing targets to income bands runs into the technical problem that there is no decent allocation mechanism to ensure that market housing targeted at specific income bands gets allocated to households in these income bands. Waitlists can supplement, or replace market allocation, of course. But then the housing simply becomes non-market housing. While there’s nothing wrong with setting high targets for non-market housing, such targets shouldn’t be narrowly tailored or configured to hold back additional housing from the market. As we show above, market and non-market approaches complement one another in meeting need.</p>
<p>Where designed poorly, aiming housing policy only at small sub-segments of new housing runs a high risk of reducing the overall amount of housing created, to the detriment of meeting overall need. A productive way to account for the needs of those unable to find adequate housing in the market, even after housing targets are met, is to estimate the distribution of housing pressures in the counter-factual scenario where housing targets are met, and develop a strategy to address these needs with a mixture of measures like cash supports and dedicated non-market housing of various types, as we attempt to show above.</p>
</section>
<section id="bedrooms-or-structural-type" class="level2">
<h2 class="anchored" data-anchor-id="bedrooms-or-structural-type">Bedrooms or structural type</h2>
<p>Setting targets by structural type or number of bedrooms is generally thought of as needed to better align housing production with people’s preferences. For example, bedroom targets are often justified by pointing out that the market produces a lot of small 1-bedroom units, while people “prefer” larger units with more bedrooms, and there is a lack of appropriately sized housing options for families. But it’s not clear why the market is thought to work against people’s preferences or where the market failure lies. On the contrary, we know that in Vancouver rents per square foot are significantly higher for smaller units, giving clear evidence that people trade smaller units for the ability to live on their own. This is also reflected in our analysis of doubling up and household living arrangements, where we see that people are making tradeoffs to pool their income and share a larger unit vs living on their own in a smaller unit.</p>
<p>Similarly, the focus on <em>ground oriented</em> housing is often tied to housing for families, based on implicit assumptions that families can’t or won’t be served by apartments. <span class="citation" data-cites="lauster.2016">(Lauster 2016)</span> However, it is not clear what market failure exists that needs correcting when forcing housing of specific types. In fact, holding the number of bedrooms constant there is little evidence that structural type has a significant influence on how housing is used in Vancouver. <span class="citation" data-cites="a-bedroom-is-a-bedroom.2019">(<span class="nocase">von Bergmann</span> 2019)</span> A related issue is that of minimum unit size regulation, which can work against people’s preference to trade privacy for smaller spaces. While these policies are often justified as pertaining to livability concerns, it’s not clear who should set the standards for livability, especially when those standards often lead to adaptive doubling up or exclusion altogether. <span class="citation" data-cites="lauster2019s">(Lauster 2019)</span> We should also keep in mind that households themselves are adaptive, and may not conform to planner expectations (e.g.&nbsp;households of grumpy roommates who wish they had their own place may come to fill the 2BR units built to attract or retain families with children).</p>
<p>There may be a case for forcing developers to build more 2 and 3 bedroom units, or build more <em>ground oriented</em> housing, or build larger dwellings than they would if otherwise left to respond to where they saw demand, but these cases do not come without tradeoffs, and the tradeoffs should be made explicit. This is especially the case where part of the tradeoff involves a reduction in housing overall.</p>
<p>For instance, a case could be made that diversity in housing types is, itself, an important quality to bring to neighbourhoods, better promoting inclusion and enabling people to age in place. Note these are two different goals! The strongest application of such a case would be to low-density suburbs, currently the most homogenous of neighbourhoods in terms of housing typologies. Diversification of housing types in low-density neighbourhoods could increase the overall number of dwellings, resulting in the distributional benefits we discuss above and promoting greater inclusion overall as well as enabling more people to age in place. But in higher density neighbourhoods some forms of diversification might suggest a reduction in the overall number of dwellings. Here more scrutiny should be placed on the costs. Diversification in the name of greater inclusion in high demand places runs up against the potential exclusion generated by producing less housing overall. Turning to our other goal of enabling people to age in place, we may want to weigh this idea against the mobility we observe and how it is usually associated with upward moves in housing quality. Maybe it’s actually not such an important goal, especially when weighed against other neighbourhood goals, like ensuring inclusion, or enabling as many people to live close to transit as possible, or enabling neighbourhoods to develop qualitatively different scenes.</p>
</section>
<section id="tenure" class="level2">
<h2 class="anchored" data-anchor-id="tenure">Tenure</h2>
<p>Lastly, setting targets by tenure (e.g.&nbsp;purpose-built rental vs.&nbsp;condominium) comes with risks too, and is likely to do more harm than good if implemented based on naive observations of current tenure frequencies. Tenure choice is ultimately downstream of housing pressures. Many people rent simply because they can’t afford ownership rather than any perceived benefits, like the flexibility of being a tenant. If housing were cheaper, many such renters would likely become owners.<sup>6</sup> Hence, once again, we would likely see distributional effects of increasing housing supply overall on giving more people a real choice in tenure, shifting the balance of renters to owners.</p>
<p>Producing more flexible forms of housing (e.g.&nbsp;condominium) that can readily switch between supporting renters or owners could better enable people to switch between tenures. But there’s a catch, insofar as the very flexibility of condominium housing relative to purpose-built rental can produce less stable tenure for tenants. Setting targets for purpose-built rental housing can be aimed at providing greater security for renters than can be found in the secondary rental market. Some of that is priced in, with primary market rental renting at a premium over comparable secondary rentals, but some benefits likely remain when shifting the overall balance in the rental market. That said, the greater security of purpose-built rental housing is, in part, also a result of rent control policies that are easier to evade in the secondary rental market (where owner use enables a readier justification for eviction). As we see in our consideration of the moving penalty, this protective effect of rent control is less important when there is greater overall housing supply.</p>
<p>Overall setting housing targets by tenure, which effectively pushes housing production toward one tenure or another, may be justifiable but should be carefully justified. Existing tenure-based targets are sometimes based on concerns about affordability<sup>7</sup> that actively ignore the endogeneity of tenure choice. Such policies can work against people’s preferences and do harm, especially if they bring down the total amount of housing constructed.</p>
</section>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>Understanding distributional effects of new housing is essential when thinking about housing policy. People move around a lot and housing acts a system. Limits on the overall amount of housing creates pressure within this system, and the households people form are in part a response to this pressure.</p>
<p>We have previously estimated ambitious but attainable overall housing targets. <span class="citation" data-cites="housing-targets.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span> Hitting our housing targets would lead to cheaper housing, and filtering via vacancy chains would spread these effects across all sectors of the market. Cheaper housing would lead to fewer people in Core Housing Need, fewer suppressed households, and more net in-migrants, and we can at least roughly estimate how those effects might break out. To recap our results above, we expect that expanding housing by 15% would lead to a decrease in prices and rents of about 30%. This would result in about 9% more households formed from the existing population as those doubled up move apart, and an additional 5% more households from increased net in-migration, with some uncertainty especially around the split between household formation and migration components. Accounting for these new households we project the total share of the population in households spending more than 30% of their income on shelter cost would still drop by 19% with a reduction of 35% of the population in Core Housing Need due to high shelter costs. This still leaves a sizable role for non-market housing or related subsidies to meet remaining housing need.</p>
<p>Given the importance of distributional effects, we make the case that housing targets should first and foremost be aimed at increasing housing supply overall, and raise concerns about more narrowly designed formulations of targets. We can see how all of these outcomes flow from adding a lot more supply to the housing market. The converse also holds. Not building enough housing leads to more doubled up households, less net in-migration, and more households spending too much on rent. Moreover, these are systemic effects, rather than tied specifically to the residents moving into new housing. This is why we argue that overall housing targets are more important than attempting to micromanage what kinds of new housing get built.</p>
<p>Methodologically, this post takes a first stab at estimating distributional effects. Our use of PUMF data is well-suited for our estimations, enabling us to simulate how policy changes could translate throughout the system. That said, some of the models should probably continue to be refined. In particular, we have stuck mostly to estimating effects at the aggregate level, but PUMF data allows a much better understanding of the processes that affect household formation and how people live together in housing. We have undertaken more refined modelling of the household formation processes underlying distributional effects in forthcoming work <span class="citation" data-cites="mhu.2024">(<span class="nocase">Lauster and von Bergmann</span> 2024)</span>, but there is a lot of room for further refinement and tailoring estimates to specific policy questions.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-08-14-distributional-effects-of-adding-housing/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb28-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-08-14 11:54:49 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb30-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [ea9a700] 2024-08-14: final touches</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb32-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.3                
 [3] knitr_1.47                rlang_1.1.4              
 [5] xfun_0.44                 generics_0.1.3           
 [7] jsonlite_1.8.8            glue_1.7.0               
 [9] colorspace_2.1-0          git2r_0.33.0             
[11] htmltools_0.5.8.1         mountainmathHelpers_0.1.4
[13] scales_1.3.0              fansi_1.0.6              
[15] rmarkdown_2.27            grid_4.4.1               
[17] munsell_0.5.1             evaluate_0.23            
[19] tibble_3.2.1              fastmap_1.2.0            
[21] yaml_2.3.8                lifecycle_1.0.4          
[23] compiler_4.4.1            dplyr_1.1.4              
[25] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[27] rstudioapi_0.16.0         digest_0.6.35            
[29] R6_2.5.1                  tidyselect_1.2.1         
[31] utf8_1.2.4                pillar_1.9.0             
[33] magrittr_2.0.3            tools_4.4.1              
[35] gtable_0.3.5              ggplot2_3.5.1            </code></pre>
</div>
</div>
</details>



</section>


<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-bratu2023" class="csl-entry">
Bratu, Cristina, Oskari Harjunen, and Tuukka Saarimaa. 2023. <span>“JUE Insight: City-Wide Effects of New Housing Supply: Evidence from Moving Chains.”</span> <em>Journal of Urban Economics</em> 133 (January): 103528. <a href="https://doi.org/10.1016/j.jue.2022.103528">https://doi.org/10.1016/j.jue.2022.103528</a>.
</div>
<div id="ref-gensey_condos.2018" class="csl-entry">
CMHC. 2018. <em>Supply Constraints Increased Prices of Apartment Condominiums in Canadian Cities</em>. HOUSING RESEARCH REPORT. <a href="https://eppdscrmssa01.blob.core.windows.net/cmhcprodcontainer/sf/project/archive/research_5/rr_supply_constraints_increased_prices_mar_12.pdf">https://eppdscrmssa01.blob.core.windows.net/cmhcprodcontainer/sf/project/archive/research_5/rr_supply_constraints_increased_prices_mar_12.pdf</a>.
</div>
<div id="ref-cmhc_2021" class="csl-entry">
CMHC. 2021. <em>Research Insight: Transitions into and Out of Core Housing Need</em>. Canada Mortgage and Housing Corporation. <a href="https://www.cmhc-schl.gc.ca/professionals/housing-markets-data-and-research/housing-research/research-reports/housing-needs/research-insight-transitions-into-out-core-housing-need">https://www.cmhc-schl.gc.ca/professionals/housing-markets-data-and-research/housing-research/research-reports/housing-needs/research-insight-transitions-into-out-core-housing-need</a>.
</div>
<div id="ref-bc_housing_2023" class="csl-entry">
Commission, BC Housing Management. 2023. <em>2023/24-2024/25 Service Plan</em>. Canada Mortgage and Housing Corporation. <a href="https://www.bcbudget.gov.bc.ca/2023/sp/pdf/agency/bch.pdf">https://www.bcbudget.gov.bc.ca/2023/sp/pdf/agency/bch.pdf</a>.
</div>
<div id="ref-corinth2023" class="csl-entry">
Corinth, Kevin, and Amelia Irvine. 2023. <span>“JUE Insight: The Effect of Relaxing Local Housing Market Regulations on Federal Rental Assistance Programs.”</span> <em>Journal of Urban Economics</em> 136 (July): 103572. <a href="https://doi.org/10.1016/j.jue.2023.103572">https://doi.org/10.1016/j.jue.2023.103572</a>.
</div>
<div id="ref-ermisch1985minimal" class="csl-entry">
Ermisch, John F, and Elizabeth Overton. 1985. <span>“Minimal Household Units: A New Approach to the Analysis of Household Formation.”</span> <em>Population Studies</em> 39 (1): 33–54.
</div>
<div id="ref-nz_rents.2024" class="csl-entry">
Greenaway-McGrevy, Ryan, and Yun So. 2024. <em>Can Zoning Reform Reduce Housing Costs? Evidence from Rents in Auckland</em>. <a href="https://www.auckland.ac.nz/assets/business/our-research/docs/economic-policy-centre/EPC-WP-016.pdf">https://www.auckland.ac.nz/assets/business/our-research/docs/economic-policy-centre/EPC-WP-016.pdf</a>.
</div>
<div id="ref-harris1992end" class="csl-entry">
Harris, Richard. 1992. <span>“The End Justified the Means: Boarding and Rooming in a City of Homes, 1890-1951.”</span> <em>Journal of Social History</em>, 331–58.
</div>
<div id="ref-kristof_1965" class="csl-entry">
Kristof, Frank S. 1965. <span>“HOUSING POLICY GOALS AND THE TURNOVER OF HOUSING.”</span> <em>Journal of the American Institute of Planners</em> 31 (3): 232–45. <a href="https://doi.org/10.1080/01944366508978170">https://doi.org/10.1080/01944366508978170</a>.
</div>
<div id="ref-lansing_1969" class="csl-entry">
Lansing, John B., James N. Morgan, Charles Wade Clifton, and University of Michigan. 1969. <em>New Homes and Poor People ; a Study of Chains of Moves</em>. Institute for Social Research, University of Michigan. <a href="https:////catalog.hathitrust.org/Record/001106818">//catalog.hathitrust.org/Record/001106818</a>.
</div>
<div id="ref-lauster.2016" class="csl-entry">
Lauster, Nathanael. 2016. <em>The Death and Life of the Single-Family House</em>. November 2. <a href="https://doi.org/10.2307/j.ctvrdf3ms">https://doi.org/10.2307/j.ctvrdf3ms</a>.
</div>
<div id="ref-lauster2019s" class="csl-entry">
Lauster, Nathanael. 2019. <span>“What’s Livable? Comparing Concepts and Metrics for Housing and Livability.”</span> In <em>A Research Agenda for Housing</em>. Edward Elgar Publishing.
</div>
<div id="ref-mhu.2024" class="csl-entry">
<span class="nocase">Lauster, Nathanael, and Jens von Bergmann</span>. 2024. <span>“The New Rules: Housing Shortage as an Explanation for Family and Household Change Across Large Metro Areas in Canada, 1981-2021.”</span> <em>Forthcoming</em>.
</div>
<div id="ref-simple-metrics-for-deciding-if-you-have-enough-housing.2019" class="csl-entry">
<span class="nocase">Lauster, Nathan, and Jens von Bergmann</span>. 2019. <em>Simple <span>Metrics</span> for <span>Deciding</span> If <span>You</span> <span>Have</span> <span>Enough</span> <span>Housing</span></em>. <a href="https://doodles.mountainmath.ca/posts/2019-06-12-simple-metrics-for-deciding-if-you-have-enough-housing/">https://doodles.mountainmath.ca/posts/2019-06-12-simple-metrics-for-deciding-if-you-have-enough-housing/</a>.
</div>
<div id="ref-mast_2019" class="csl-entry">
Mast, Evan. 2019. <span>“The Effect of New Market-Rate Housing Construction on the Low-Income Housing Market (July 24, 2019).”</span> <em>Upjohn Institute WP</em>, 19–307. <a href="http://dx.doi.org/10.2139/ssrn.3426103">http://dx.doi.org/10.2139/ssrn.3426103</a>.
</div>
<div id="ref-tsure_filtering_supply.2003" class="csl-entry">
Mayer, Christopher, and C. Tsuriel Somerville. 2003. <span>“Government Regulation and Changes in the Affordable Housing Stock.”</span> <em>Economic Policy Review</em> 9: 45–62. <a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=790506">https://papers.ssrn.com/sol3/papers.cfm?abstract_id=790506</a>.
</div>
<div id="ref-myers_filtering.2020" class="csl-entry">
Myers, Dowell, and Jungho Park. 2020. <em>Filtering of Apartment Housing Between 1980 and 2018</em>. <a href="https://www.nmhc.org/research-insight/research-report/nmhc-research-foundation-study-filtering-of-apartment-housing-between-1980-and-2018/">https://www.nmhc.org/research-insight/research-report/nmhc-research-foundation-study-filtering-of-apartment-housing-between-1980-and-2018/</a>.
</div>
<div id="ref-rossi_1955" class="csl-entry">
Rossi, Peter H. 1955. <em>Why Families Move: A Study in the Social Psychology of Urban Residential Mobility</em>. Free Press.
</div>
<div id="ref-tsur_filtering.2001" class="csl-entry">
Somerville, C. Tsuriel, and Cynthia Holmes. 2001. <span>“Dynamics of the Affordable Housing Stock: Microdata Analysis of Filtering.”</span> <em>Journal of Housing Research</em> 12 (1): 115–40. <a href="http://www.jstor.org/stable/24833794">http://www.jstor.org/stable/24833794</a>.
</div>
<div id="ref-magnusson_turner_2008" class="csl-entry">
Turner, Lena Magnusson. 2008. <span>“Who Gets What and Why? Vacancy Chains in Stockholm’s Housing Market.”</span> <em>European Journal of Housing Policy</em> 8 (1): 1–19. <a href="https://doi.org/10.1080/14616710701817133">https://doi.org/10.1080/14616710701817133</a>.
</div>
<div id="ref-a-bedroom-is-a-bedroom.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2019. <em>A Bedroom Is a Bedroom</em>. <a href="https://doodles.mountainmath.ca/posts/2019-04-20-a-bedroom-is-a-bedroom/">https://doodles.mountainmath.ca/posts/2019-04-20-a-bedroom-is-a-bedroom/</a>.
</div>
<div id="ref-commodity-and-keeping-it-in-the-family.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021a. <em>Commodity and <span>Keeping</span> It in the <span>Family</span></em>. <a href="https://doodles.mountainmath.ca/posts/2021-08-13-commodity-and-keeping-it-in-the-family/">https://doodles.mountainmath.ca/posts/2021-08-13-commodity-and-keeping-it-in-the-family/</a>.
</div>
<div id="ref-three-years-svt.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021b. <em>Three Years of Speculation &amp; Vacancy Tax Data</em>. <a href="https://doodles.mountainmath.ca/posts/2021-11-21-three-years-of-speculation-vacancy-tax-data/">https://doodles.mountainmath.ca/posts/2021-11-21-three-years-of-speculation-vacancy-tax-data/</a>.
</div>
<div id="ref-estimating-suppressed-household-formation.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022a. <em>Estimating <span>Suppressed</span> <span>Household</span> <span>Formation</span></em>. <a href="https://doodles.mountainmath.ca/posts/2022-05-06-estimating-suppressed-household-formation/">https://doodles.mountainmath.ca/posts/2022-05-06-estimating-suppressed-household-formation/</a>.
</div>
<div id="ref-still-short-suppressed-households-in-2021.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022b. <em>Still <span>Short:</span> <span>Suppressed</span> <span>Households</span> in 2021</em>. <a href="https://doodles.mountainmath.ca/posts/2022-10-03-still-short-suppressed-households-in-2021/">https://doodles.mountainmath.ca/posts/2022-10-03-still-short-suppressed-households-in-2021/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023a. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
<div id="ref-housing-targets.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023b. <em>Housing Targets</em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/">https://doodles.mountainmath.ca/posts/2023-06-27-housing-targets/</a>.
</div>
<div id="ref-tenure-and-household-independence-across-the-life-course-1981-2021.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024a. <em>Tenure and <span>Household</span> <span>Independence</span> Across the <span>Life</span> <span>Course,</span> 1981-2021</em>. <a href="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/">https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</a>.
</div>
<div id="ref-what-if-recent-apartment-buildings-in-vancouver-were-20-taller.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024b. <em>What If Recent Apartment Buildings in <span>Vancouver</span> Were 20% Taller?</em> <a href="https://doodles.mountainmath.ca/posts/2024-04-11-what-if-recent-apartment-buildings-in-vancouver-were-20-taller/">https://doodles.mountainmath.ca/posts/2024-04-11-what-if-recent-apartment-buildings-in-vancouver-were-20-taller/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Technically not households but Canada’s household reference persons. We’ll definitely be returning to how this distinction matters.↩︎</p></li>
<li id="fn2"><p>Notably, 2021 felt the effects of the COVID pandemic, which may have boosted mobility rates above usual levels. But overall mobility rates in 2016 and 2021 were quite similar, so while the pandemic might have changed where people move, it had only a minimal effect on the overall amount of mobility.↩︎</p></li>
<li id="fn3"><p>There are cases where someone might move in with other people that already live in the unit, for example someone who moves in with their partner, or a roommate household where one roommate moved out and the person moves in to take their spot. Or a child moves back in with their parent. Here we gloss over these subtleties and focus on household reference persons, which does not completely avoid these issues but is a suitable simplification.↩︎</p></li>
<li id="fn4"><p>This is somewhat conservative insofar as in-migrants, when adjusted by age, usually have higher (adjusted) family incomes than incumbent residents.↩︎</p></li>
<li id="fn5"><p>These estimates come with considerable uncertainties, and using them to triangulate effects as we do here pushes the limits of what these kind of estimates can be used for. Our purpose here is to show that these estimates are generally consistent with our household formation estimates and leave room for migration effects. Demand elasticity estimates are generally thought to vary across metro areas, but precise region-specific elasticities are difficult to estimate. Additionally, a 30% rediction in rents is a large change that puts us far from the current housing situation, and it is not clear that elasticity estimates adequately model the functional relationship to allow extrapolation over such a broad range.↩︎</p></li>
<li id="fn6"><p>One could argue that here we really do see market failures, with <a href="https://www.torontomu.ca/centre-urban-research-land-development/blog/blogentry49/">subsidies for ownership housing vastly exceeding those for rental housing in Canada</a>, even if this is better addressed directly. Some work in that direction has recently been done with the federal government eliminating GST on rental housing and most provinces following suit and eliminating corresponding provincial taxes. This effectively treats rental housing preferentially to ownership housing where these taxes still apply and reduces the overall tax imbalance.↩︎</p></li>
<li id="fn7"><p>Sometimes in this context it is argued that purpose-built rental housing is more “affordable” than secondary market condo rentals, which is flat-out false. Consumer surveys, as well as observational data, show that rents are higher in purpose-built rental units compared to condo rentals of similar quality and location. The increased security of tenure and professional management is of value and at least partially priced in.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{distributional-effects-of-adding-housing.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Distributional Effects of Adding Housing},
  date = {2024-08-14},
  url = {https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“Distributional
Effects of Adding Housing.”</span> <em>MountainDoodles</em>, accepted,
August 14. <a href="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/">https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</a>.
</div></div></section></div> ]]></description>
  <category>cansim</category>
  <category>cancensus</category>
  <category>canpumf</category>
  <category>affordability</category>
  <category>rental</category>
  <category>Vancouver</category>
  <category>geeky</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/</guid>
  <pubDate>Wed, 14 Aug 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-08-14-distributional-effects-of-adding-housing/index_files/figure-html/fig-prihm-share-rent-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Geocoding errors in aggregate data</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/</link>
  <description><![CDATA[ 






<p>Determining the exact location of data points comes with measurement errors, in particular when geographic locations is derived from geocoding. Data that gets aggregated by geographic areas relies on geocoding to determine which area each data point belongs to.</p>
<p>Geocoding is the process of converting addresses into geographic coordinates, which can then be used to determine which area each data point belongs to. However, geocoding is not perfect, and the resulting location can have errors. When aggregating data to polygons those errors can lead to data points being assigned to the wrong polygon.</p>
<p>If all data was geocoded with the same process, as for example using single year census data, this does not matter much, it might just shift the relative composition of variables at small geographies but data associated with housing and the people therein is kept intact. But when looking at multi-year census data, with data being geocoded with separate processes in each census year, this can lead to problems.</p>
<p>As an example, consider the 1971 through 2011 semi-custom tabulation on 2016 dissemination area geographies <span class="citation" data-cites="statisticscanada-long-census-timelines.2019">(Statistics Canada 2019)</span> that we have worked with extensively in the past. StatCan geocodes building by <em>block face</em>, which is based on their road network file with attached block level civic numbers. In some areas, especially when roads did not exist in earlier census years or were substantially changed since then, the geocoding was done inconsistently and will lead to counts being incorrectly attributed to neighbouring areas in some cases and census years. One solution to this is to join neighbouring regions across which data has been misattributed, resulting in a slightly coarser geography but with consistent data over time.</p>
<section id="tongfen" class="level1">
<h1>Tongfen</h1>
<p>Before we dive into details and examples, we want to situate this problem within a broader set of problems of making data comparable through time. Our <a href="https://mountainmath.github.io/tongfen/index.html">Tongfen package</a> addresses a large set of use cases where temporal data comes on different yet congruent geographies by creating a least <em>common denominator geography</em> and re-aggregating data accordingly. <span class="citation" data-cites="vonbergmann2020">(<span class="nocase">von Bergmann</span> 2020b)</span> This stands in contrast with other approach that estimate data based on areal or dasymetric interpolation that has been shown to lead to significant errors. <span class="citation" data-cites="logan2016">(Logan et al. 2016)</span> This becomes problematic because the errors typically correlate with changes in density, which in turn often correlates with variables of interest, which can introduce systematic bias in analysis. <span class="citation" data-cites="tongfen.2020 toward-universal-tongfen-change-in-polling-district-voting-patterns.2020">(<span class="nocase">von Bergmann</span> 2020a, 2020c)</span></p>
<p>Our current problem faces similar issues in that inconsistent geocoding over time is often associated with significant changes to the built environment, and thus the very regions we are most interested in and that are likely be responsible for a significant portion of effect sizes in analysis.</p>
<p>We think of the correction of geocoding errors by joining adjacent regions as an extension of the Tongfen functionality and will, after some more testing and refinements, incorporate this into the package.</p>
</section>
<section id="census-timelines" class="level1">
<h1>Census timelines</h1>
<p>The semi-custom tabulation of census profile data for Toronto and Vancouver to 2016 dissemination areas will serve as our main example. In Figure&nbsp;1 we replicated the work from the previous post to take the 1971 through 2011 cross tabulation on 2016 dissemination areas, augment it with the 2016 data, and use TongFen to extend it to 2021. <span class="citation" data-cites="population-timelines-update.2024">(<span class="nocase">von Bergmann</span> 2024)</span></p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">all_years <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1971</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1981</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb1-2">breaks <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,<span class="sc" 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 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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>)</span>
<span id="cb1-3">labels <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;">"Loss of over 100"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Loss of 50 to 100"</span>,</span>
<span id="cb1-4">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Loss of 25 to 50"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Loss of 10 to 25"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Loss of 5 to 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"About the same"</span>,</span>
<span id="cb1-5">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gain of 5  to 10"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gain of 10 to 25"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gain of 25 to 50"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gain of 50 to 100"</span>,</span>
<span id="cb1-6">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gain over 100"</span>)</span>
<span id="cb1-7">change_colors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> RColorBrewer<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;">brewer.pal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(labels),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PiYG"</span>)</span>
<span id="cb1-8"></span>
<span id="cb1-9">data_2021 <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35535"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>,<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="cb1-10">data_2016 <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35535"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>,<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="cb1-11"></span>
<span id="cb1-12">db_correspondence<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>tongfen<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;">get_single_correspondence_ca_census_for</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(data_2016 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DBUID2016=</span>GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DAUID2016=</span>DA_UID),<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;">"DBUID2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">full_join</span>(data_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DBUID2021=</span>GeoUID),<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;">"DBUID2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DBUID2021,DAUID2016) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-16">  tongfen<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;">get_tongfen_correspondence</span>()</span>
<span id="cb1-17"></span>
<span id="cb1-18">tongfen_geos <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35535"</span>), </span>
<span id="cb1-19">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DA"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-21">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DAUID2016,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DAUID2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-23">  <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;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Shape Area</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) </span>
<span id="cb1-24"></span>
<span id="cb1-25">years<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;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1971</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1981</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb1-26">old_vectors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA"</span>,y,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x16_1"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_names</span>(years)</span>
<span id="cb1-27">pop_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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16CT"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35535"</span>),</span>
<span id="cb1-28">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(old_vectors,<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;">"2016"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_1"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DA"</span>,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select_at</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;">"GeoUID"</span>,years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> as.character,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(GeoUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise_all</span>(sum,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) </span>
<span id="cb1-32"></span>
<span id="cb1-33">combined_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pop_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DAUID2016,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DAUID2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">full_join</span>(data_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-38">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-39">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DBUID2021,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-40">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),</span>
<span id="cb1-41">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DBUID2021"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-42">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2021</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Population,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>TongfenID),</span>
<span id="cb1-43">            <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;">"TongfenID"</span>)</span>
<span id="cb1-44"></span>
<span id="cb1-45">geo_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tongfen_geos <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(area,<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;">|&gt;</span></span>
<span id="cb1-47">  rmapshaper<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;">ms_simplify</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep_shapes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(combined_data,<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;">"TongfenID"</span>) </span>
<span id="cb1-49"></span>
<span id="cb1-50">toronto_city <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CSD=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3520005"</span>),</span>
<span id="cb1-51">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sf'</span>,<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="cb1-52">bbox<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>sf<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;">st_bbox</span>(toronto_city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_crs</span>(geo_data))) </span>
<span id="cb1-53"></span>
<span id="cb1-54">geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2021</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">1971</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change_h=</span>change<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(change_h,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>breaks,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>labels)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>change_d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>change_colors) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(bbox) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population change 1971-2021 in Toronto"</span>,</span>
<span id="cb1-64">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change per hectare"</span>,</span>
<span id="cb1-65">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1971 - 2021"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-pop-timeline-toronto" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pop-timeline-toronto-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-pop-timeline-toronto-1.png" id="fig-pop-timeline-toronto" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-pop-timeline-toronto-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1
</figcaption>
</figure>
</div>
</div>
</div>
<p>The <a href="https://doodles.mountainmath.ca/html/yyz_pop_timeline_2021.html">interactive map</a> makes it possible to browse the data in more detail. And it makes it possible to identify quirks likely due to geocoding problems. But what do these geocoding problems look like? Time for a concrete example.</p>
<section id="crescent-town" class="level2">
<h2 class="anchored" data-anchor-id="crescent-town">Crescent Town</h2>
<p>A particular example, which also provided much of the motivation for this work, was flagged to me by Tai Huynh from <a href="https://thelocal.to">The Local</a>, who has been using this data to look in more detail at neighbourhood change in Toronto. Here the population jumped in erratic ways in the early census years as visualized in Figure&nbsp;2.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">data_nb <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;">poly2nb</span>(geo_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names=</span>geo_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">queen=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-2"></span>
<span id="cb2-3">id_example <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;">"35204370001"</span></span>
<span id="cb2-4">id0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> id_example</span>
<span id="cb2-5"></span>
<span id="cb2-6">new_ids <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;">attr</span>(data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)[data_nb[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>id0)]]]</span>
<span id="cb2-7"></span>
<span id="cb2-8">cr_bbox <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_bbox</span>()</span>
<span id="cb2-9"></span>
<span id="cb2-10"></span>
<span id="cb2-11">geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_filter</span>(cr_bbox <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sfc</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3000</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>),</span>
<span id="cb2-16">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(pop_d,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt; 0"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>pop_d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(cr_bbox) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population density in Crescent Town"</span>,</span>
<span id="cb2-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>,</span>
<span id="cb2-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1971 - 2021"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-towm-density-change-map" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-towm-density-change-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-towm-density-change-map-1.png" id="fig-crescent-towm-density-change-map" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-towm-density-change-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2
</figcaption>
</figure>
</div>
</div>
</div>
<p>We see the central moon-shaped area starting out with zero population in 1971, growing to very high population in 1986, but then dropping back to low levels in 1996. At the same time, some of the surrounding areas are showing opposite patterns.</p>
<p>In Figure&nbsp;3 we highlight the population timelines of the moon-shaped central area and the surrounding ones in a line graph.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">cr_colours <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;">setNames</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;">"black"</span>,RColorBrewer<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;">brewer.pal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(new_ids),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dark2"</span>)),</span>
<span id="cb3-2">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids))</span>
<span id="cb3-3"></span>
<span id="cb3-4">combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>TongfenID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cr_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>id0),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>all_years) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population timelines in candidate and neighbouring regions"</span>,</span>
<span id="cb3-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-towm-density-change-graph" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-towm-density-change-graph-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-towm-density-change-graph-1.png" id="fig-crescent-towm-density-change-graph" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-towm-density-change-graph-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;4 shows the regions shown here on a map for added context.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_filter</span>(cr_bbox <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sfc</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3000</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>),</span>
<span id="cb4-6">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(pop_d,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt; 0"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids))),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>TongfenID),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb4-12">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf_label</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>TongfenID),</span>
<span id="cb4-14">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cr_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(cr_bbox) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crescent Town geographic region identifiers"</span>,</span>
<span id="cb4-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb4-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2016 dissemination areas"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-towm-tongfenid-graph" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-towm-tongfenid-graph-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-towm-tongfenid-graph-1.png" id="fig-crescent-towm-tongfenid-graph" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-towm-tongfenid-graph-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4
</figcaption>
</figure>
</div>
</div>
</div>
<p>The erratic behaviour of the timelines in the individual regions is quite striking, especially regions with zero population at the start point to development in previously undeveloped (for housing) areas that might come along with reconfiguration of streets that trigger geocoding inconsistencies, and population dropping from high values to zero is a red flag. But if we squint long enough at the data we notice that among those regions there are two pairs with complementary and partially cancelling patterns. Figure&nbsp;5 shows what happens when we combine join the region, and the corresponding populations.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">id2 <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;">"35204372001"</span></span>
<span id="cb5-2"></span>
<span id="cb5-3">id2 <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;">"35204765002"</span></span>
<span id="cb5-4"></span>
<span id="cb5-5">combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35204765002"</span>),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group 1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group 2"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>((.) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb5-11">              <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),</span>
<span id="cb5-12">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(TongfenID),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>),</span>
<span id="cb5-13">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-14">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combined"</span>) ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,TongfenID))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,TongfenID))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cr_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>all_years) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linetype_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>),</span>
<span id="cb5-23">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combined"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,TongfenID)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population timelines in candidate and neighbouring regions"</span>,</span>
<span id="cb5-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-towm-density-change-graph-combined" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-towm-density-change-graph-combined-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-towm-density-change-graph-combined-1.png" id="fig-crescent-towm-density-change-graph-combined" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-towm-density-change-graph-combined-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5
</figcaption>
</figure>
</div>
</div>
</div>
<p>The lines in red showing the populations of the combined regions are much more stable and don’t exhibit the drastic population changes that the individual regions do. This gives us fairly high confidence that the dramatic population changes in the individual regions were caused by geocoding errors, and that combining the regions fixes this (at the expense of moving to a slightly coarser geography). Figure&nbsp;6 shows the resulting timeline on the combined geographic regions.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_filter</span>(cr_bbox <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sfc</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> id2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0,new_ids),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combined"</span>,TongfenID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID,Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(area),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pretty_cut</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7500</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>),</span>
<span id="cb6-9">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(pop_d,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt; 0"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>pop_d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_d</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(cr_bbox) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population density in Crescent Town"</span>,</span>
<span id="cb6-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>,</span>
<span id="cb6-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1971 - 2021"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-towm-density-change-graph-combined-map" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-towm-density-change-graph-combined-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-towm-density-change-graph-combined-map-1.png" id="fig-crescent-towm-density-change-graph-combined-map" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-towm-density-change-graph-combined-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6
</figcaption>
</figure>
</div>
</div>
</div>
<p>Hopefully this example has made the problem clear, and also shown, at least in principle, how to fix this problem. But this becomes a daunting task when we have to do this for all 7,518 regions in Metro Toronto. We need a way to automate this process.</p>
</section>
</section>
<section id="automating-the-process" class="level1">
<h1>Automating the process</h1>
<p>Automation comes with risks of missing regions that should be combined, and on the flip side it risks of being too aggressive and joining regions with suspicious population changes that aren’t due to geocoding but to real processes on the ground. And these risks vary by region and by type of data considered. We need a process that is flexible enough to be adapted to a range of situations, and that can be calibrated based on use cases and tolerance for type 1 vs type 2 errors.</p>
<section id="identifying-potential-geocoding-problems" class="level2">
<h2 class="anchored" data-anchor-id="identifying-potential-geocoding-problems">Identifying potential geocoding problems</h2>
<p>As a first step we have to draw up a list of candidate regions that might have geocoding problems. Intuitively we are looking regions with “surprising” jumps in population. But what makes a population change “surprising”? We have looked a similar problem before <span class="citation" data-cites="surprise.2017">(<span class="nocase">von Bergmann</span> 2017)</span>, to determine surprise we have to first build an expectation of what the population change might look like and then look for significant deviations from this expectation.</p>
<p>Do build and expectation of population change we have to understand the data generation process. Generally, we expect population change to be gradual, with possibly large increases when new residential development occurs. Strong decreases in population are less common, but they could occur e.g.&nbsp;during a large scale fire or natural disaster. Based on this we formulate our expectation fairly broadly as “significant population decreases over relatively short periods of time are surprising”. This will constitute our first round of candidate areas for geocoding problems.</p>
<p>What constitutes “significant” or “surprising” change is context dependent, Figure&nbsp;7 gives an overview of the distribution of the negative absolute and relative population changes in the data.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Absolute change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>value<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;">lag</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year),</span>
<span id="cb7-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Relative change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>value<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;">lag</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb7-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"change"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"change"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(change<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>change,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Period)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of negative population changes"</span>,</span>
<span id="cb7-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population change"</span>,</span>
<span id="cb7-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of regions and periods"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-surprise-yyz" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-surprise-yyz-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-surprise-yyz-1.png" id="fig-surprise-yyz" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-surprise-yyz-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7
</figcaption>
</figure>
</div>
</div>
</div>
<p>Based on this we somewhat heuristically and conservatively take a population drop of at least 100 people and at least 20% between two census periods as starting to be a “surprising” change and formalize this by modelling the amount of “surprise” with an inverse exponential distribution with a “surprise” value of 0 at 0 population change and a “surprise” value of 0.5 at 0.25 and 100 relative and absolute population change respectively. We then estimate the total surprise by multiplying the relative and absolute surprise values, with our candidate regions being those with a total surprise of at least 0.25, so just capturing a case where a region’s population decreased by 0.25% and 100 people. Figure&nbsp;8 shows the distribution of total surprise.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">rel_surprise <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x){</span>
<span id="cb8-2">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.finite</span>(x))</span>
<span id="cb8-3">  r[r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dexp</span>(x[r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</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.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-4">  r</span>
<span id="cb8-5">}</span>
<span id="cb8-6"></span>
<span id="cb8-7">abs_surprise <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x){</span>
<span id="cb8-8">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.finite</span>(x))</span>
<span id="cb8-9">  r[r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dexp</span>(x[r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</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;">200</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-10">  r</span>
<span id="cb8-11">}</span>
<span id="cb8-12"></span>
<span id="cb8-13">add_surprise <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_field=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>) {</span>
<span id="cb8-14">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Absolute change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>value<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;">lag</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year),</span>
<span id="cb8-17">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Relative change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Absolute change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.name</span>(base_field),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year),</span>
<span id="cb8-18">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-19">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># mutate(surprise=1-(1-rel_surprise(`Relative change`))*(1-abs_surprise(`Absolute change`))) |&gt;</span></span>
<span id="cb8-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">surprise=</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rel_surprise</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Relative change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs_surprise</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Absolute change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we want both!</span></span>
<span id="cb8-21">    </span>
<span id="cb8-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Period=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">surprise_count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(surprise<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.75</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>TongfenID)</span>
<span id="cb8-24">}</span>
<span id="cb8-25"></span>
<span id="cb8-26"></span>
<span id="cb8-27">combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">min</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>surprise,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Period)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of surprising population changes"</span>,</span>
<span id="cb8-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surprise"</span>,</span>
<span id="cb8-37">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of regions and periods"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-total-surprise-yyz" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-total-surprise-yyz-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-total-surprise-yyz-1.png" id="fig-total-surprise-yyz" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-total-surprise-yyz-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8
</figcaption>
</figure>
</div>
</div>
</div>
<p>To get a better view of the regions we are most interested in we zoom in a bit and only show regions with a total surprise of at least 0.15 in Figure&nbsp;9.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">combined_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">min</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>surprise,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Period)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of surprising population changes"</span>,</span>
<span id="cb9-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surprise"</span>,</span>
<span id="cb9-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of regions and periods"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-total-surprise-yyz-zoomed" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-total-surprise-yyz-zoomed-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-total-surprise-yyz-zoomed-1.png" id="fig-total-surprise-yyz-zoomed" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-total-surprise-yyz-zoomed-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9
</figcaption>
</figure>
</div>
</div>
</div>
<p>We note that the candidates lean heavy toward the earlier periods, which is expected when looking for geocoding errors, but also consistent with this being a time period of slower growth, and possibly stronger declines in some areas that reflects real conditions on the ground. But as mentioned above, not all these surprising population changes are due to geocoding errors. And geocoding errors can also lead to strong increases in population. To account for this we take the first round candidates and consider the neighbouring regions for each of these to look for complementary patterns with population boosts in years where we see surprising population drops.</p>
<p>To implement this we make this more precise. Ideally we would look at the joint distribution of pairs (or higher order combinations) of regions and estimate the surprise and reduction in surprise at that level, but for exploratory as well as practical considerations regarding the computational intensity of such an approach we settle for a more pedestrian approach. At this point this is still somewhat heuristic, we plan on refining this and settling on a principled and parsimonious approach. At this point, we proceed as follows. We rank all regions by <em>total surprise</em> by taking the <img src="https://latex.codecogs.com/png.latex?L%5Ep"> norm across years, with <img src="https://latex.codecogs.com/png.latex?p"> chosen to be 4 in this case, but retaining the ability to tune this further in order to trade off between only considering the maximum surprise across years (<img src="https://latex.codecogs.com/png.latex?p=%5Cinfty">) and simply taking the sum of all the individual surprises (<img src="https://latex.codecogs.com/png.latex?p=1">) across years.</p>
<p>Guided by our example case we will look for neighbouring regions that, when combined with the candidate region, result in a significant drop in our <em>surprise</em> metric when joining the regions. To estimate the reduction in surprise we remain mindful that surprise decreases when we simply add a region with flat population as that increases the denominators in our relative surprise measure. To avoid this effect and measure the reduction in surprise in a comparable way we keep the original denominators but the take the combined change in population as new numerators when evaluating the change in surprise. When then combine the regions if the relative or absolute reduction in surprise passes a specified threshold that we deemed significant enough. We repeat this process until we don’t see any significant reductions in surprise anymore.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">get_match_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(geo_data2,</span>
<span id="cb10-2">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cutoff_fact =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_surprise_cutoff =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb10-3">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">surprise_reduction_const=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sum_fact =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) {</span>
<span id="cb10-4">  </span>
<span id="cb10-5">  data_nb <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;">poly2nb</span>(geo_data2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names=</span>geo_data2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">queen=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb10-6"></span>
<span id="cb10-7">  summarize_surprise <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fields=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"surprise"</span>){</span>
<span id="cb10-8">    data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(fields),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count=</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(.x<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="cb10-10">                                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total=</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>p))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p))),</span>
<span id="cb10-11">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-12">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.name</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(fields[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_count"</span>)),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.name</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(fields[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_total"</span>)))</span>
<span id="cb10-13">  }</span>
<span id="cb10-14">  </span>
<span id="cb10-15">  long_data2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geo_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(TongfenID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>()</span>
<span id="cb10-20">  </span>
<span id="cb10-21">  candidate_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_surprise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_df</span>(rev) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise_count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,surprise_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> total_surprise_cutoff)</span>
<span id="cb10-25">  </span>
<span id="cb10-26">  match_list <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_character_</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID_original=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_character_</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb10-28"></span>
<span id="cb10-29">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(candidate_list)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(match_list)</span>
<span id="cb10-30"></span>
<span id="cb10-31">  </span>
<span id="cb10-32">  </span>
<span id="cb10-33">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(candidate_list)) {</span>
<span id="cb10-34">    id0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> candidate_list<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID[i]</span>
<span id="cb10-35">    </span>
<span id="cb10-36">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (id0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> match_list<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID_original) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb10-37">    </span>
<span id="cb10-38">    neighbour_ids <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;">attr</span>(data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)[data_nb[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>id0)]]]</span>
<span id="cb10-39">    </span>
<span id="cb10-40">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(neighbour_ids)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb10-41">    </span>
<span id="cb10-42">    od <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-43">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id0))</span>
<span id="cb10-44">    </span>
<span id="cb10-45">    original <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>od <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-46">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_surprise</span>()</span>
<span id="cb10-47"></span>
<span id="cb10-48">    reductions <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-49">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(neighbour_ids)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-50">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(od <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ov=</span>value),<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;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-51">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>ov) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-52">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_field=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ov"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-53">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">surprise_ov=</span>surprise) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-54">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-55">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_surprise</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;">"surprise_ov"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"surprise"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-56">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb10-57">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID2=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-58">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID1=</span>original<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.before=</span>TongfenID2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-59">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(TongfenID1,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,TongfenID2))</span>
<span id="cb10-60">    </span>
<span id="cb10-61">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(match_list<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID_original)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb10-62">    </span>
<span id="cb10-63">    pre_sum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> long_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-64">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID1,reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-65">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_surprise</span>()</span>
<span id="cb10-66">    </span>
<span id="cb10-67">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_ov_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> cutoff_fact<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>original<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb10-68">        original<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_ov_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> surprise_reduction_const <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> </span>
<span id="cb10-69">        reductions<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_ov_total <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> cutoff_fact <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sum_fact <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(pre_sum<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>surprise_total)) {</span>
<span id="cb10-70">      match_list <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;">bind_rows</span>(match_list,</span>
<span id="cb10-71">                              reductions  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-72">                                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TongfenID1,TongfenID2),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TongfenID_original"</span>))</span>
<span id="cb10-73">    }</span>
<span id="cb10-74">  }</span>
<span id="cb10-75">  match_list</span>
<span id="cb10-76">}</span>
<span id="cb10-77"></span>
<span id="cb10-78">iterate_geo_match_joins <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(geo_data2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">debug_level=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,...) {</span>
<span id="cb10-79"></span>
<span id="cb10-80">  stop_looking <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb10-81"></span>
<span id="cb10-82">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>stop_looking) {</span>
<span id="cb10-83">    </span>
<span id="cb10-84">    match_list <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;">get_match_list</span>(geo_data2,...)</span>
<span id="cb10-85">    </span>
<span id="cb10-86">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(match_list)<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="cb10-87">      stop_looking <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb10-88">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb10-89">    }</span>
<span id="cb10-90">    </span>
<span id="cb10-91">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (debug_level<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"combining "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(match_list)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" region pairs..."</span>))</span>
<span id="cb10-92">    </span>
<span id="cb10-93">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (debug_level<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) {</span>
<span id="cb10-94">      dm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> match_list <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-95">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(TongfenID_original,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(length) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-96">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb10-97">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dm)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb10-98">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dm),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" multi-matches:"</span>))</span>
<span id="cb10-99">        <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(dm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID_original[x], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" -- "</span>,dm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID[x]))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()</span>
<span id="cb10-100">      }</span>
<span id="cb10-101">    }</span>
<span id="cb10-102">    </span>
<span id="cb10-103">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(match_list <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">duplicated</span>(TongfenID_original)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</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;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sanity check</span></span>
<span id="cb10-104">    </span>
<span id="cb10-105">    g1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geo_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-106">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID_original=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-107">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(match_list <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(TongfenID,TongfenID_original),</span>
<span id="cb10-108">                 <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;">"TongfenID_original"</span>,</span>
<span id="cb10-109">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">relationship =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"many-to-one"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-110">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(TongfenID,TongfenID_original)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-111">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>TongfenID_original) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-112">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-113">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area|</span><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;">d{4}"</span>),sum), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-114">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>()</span>
<span id="cb10-115">    </span>
<span id="cb10-116">    g2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geo_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-117">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> match_list<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID_original)) </span>
<span id="cb10-118">    </span>
<span id="cb10-119">    geo_data2 <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;">bind_rows</span>(g1,g2)</span>
<span id="cb10-120">  }</span>
<span id="cb10-121">  geo_data2</span>
<span id="cb10-122">}</span>
<span id="cb10-123"></span>
<span id="cb10-124">geo_data2 <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;">iterate_geo_match_joins</span>(geo_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_surprise_cutoff=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)</span>
<span id="cb10-125"></span>
<span id="cb10-126"></span>
<span id="cb10-127">join_count <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(geo_data)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(geo_data2)</span></code></pre></div></div>
</details>
</div>
<p>The automated process performed 976 region joins, reducing the total number of regions from 7,518 to 6,542 to arrive at a slightly coarser geography.</p>
<p>Checking back in with our motivating example of Crescent Town we see in Figure&nbsp;10 that the automatic process resulted in the same grouping that we had identified manually.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">data_nb2 <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;">poly2nb</span>(geo_data2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> geo_data2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">queen=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb11-2"></span>
<span id="cb11-3">id02 <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;">attr</span>(data_nb2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(id_example,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(data_nb2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>))]</span>
<span id="cb11-4"></span>
<span id="cb11-5">neighbour_ids2 <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;">attr</span>(data_nb2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)[data_nb2[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(data_nb2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>id02)]]]</span>
<span id="cb11-6"></span>
<span id="cb11-7">main_ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> geo_data2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(id02,neighbour_ids2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(TongfenID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area|</span><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;">d{4}"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(TongfenID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb11-13">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(length) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb11-14">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID_new=</span>TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(TongfenID_new,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest_longer</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>()</span>
<span id="cb11-20"></span>
<span id="cb11-21">geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(main_ids,<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;">"TongfenID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,TongfenID_new)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-27">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TongfenID=</span>TongfenID_new,</span>
<span id="cb11-28">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combined"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>TongfenID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-30">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_color_manual(values=cr_colours2) +</span></span>
<span id="cb11-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>TongfenID_new) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>all_years) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brown"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>,TongfenID)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population timelines in candidate and neighbouring regions"</span>,</span>
<span id="cb11-39">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-crescent-town-check" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-crescent-town-check-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-town-check-1.png" id="fig-crescent-town-check" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-crescent-town-check-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="vancouver-version" class="level2">
<h2 class="anchored" data-anchor-id="vancouver-version">Vancouver version</h2>
<p>We can perform the same operations on the Vancouver data and identify possibly geocoding problems there, the resulting cumulative population change is shown in Figure&nbsp;11.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">yvr_data_2021 <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>,<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="cb12-2">yvr_data_2016 <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>,<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="cb12-3"></span>
<span id="cb12-4">yvr_db_correspondence<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>tongfen<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;">get_single_correspondence_ca_census_for</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DB"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(yvr_data_2016 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DBUID2016=</span>GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DAUID2016=</span>DA_UID),<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;">"DBUID2016"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">full_join</span>(yvr_data_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DBUID2021=</span>GeoUID),<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;">"DBUID2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DBUID2021,DAUID2016) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-8">  tongfen<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;">get_tongfen_correspondence</span>()</span>
<span id="cb12-9"></span>
<span id="cb12-10">yvr_tongfen_geos <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>), </span>
<span id="cb12-11">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DA"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geo_format=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(yvr_db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-13">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DAUID2016,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DAUID2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-15">  <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;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Shape Area</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) </span>
<span id="cb12-16"></span>
<span id="cb12-17"></span>
<span id="cb12-18">years<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;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1971</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1981</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2011</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb12-19">old_vectors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(y)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA"</span>,y,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x16_1"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_names</span>(years)</span>
<span id="cb12-20">yvr_pop_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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16CT"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59933"</span>),</span>
<span id="cb12-21">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(old_vectors,<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;">"2016"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_1"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DA"</span>,<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select_at</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;">"GeoUID"</span>,years <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> as.character,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(GeoUID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise_all</span>(sum,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) </span>
<span id="cb12-25"></span>
<span id="cb12-26">yvr_combined_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> yvr_pop_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(yvr_db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DAUID2016,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DAUID2016"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),\(x)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">full_join</span>(yvr_data_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-31">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(yvr_db_correspondence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-32">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(DBUID2021,TongfenID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-33">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),</span>
<span id="cb12-34">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DBUID2021"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-35">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2021</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Population,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span>TongfenID),</span>
<span id="cb12-36">            <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;">"TongfenID"</span>)</span>
<span id="cb12-37"></span>
<span id="cb12-38">yvr_geo_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> yvr_tongfen_geos <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(area,<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;">|&gt;</span></span>
<span id="cb12-40">  rmapshaper<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;">ms_simplify</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">keep_shapes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(yvr_combined_data,<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;">"TongfenID"</span>) </span>
<span id="cb12-42"></span>
<span id="cb12-43"></span>
<span id="cb12-44">yvr_geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2021</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">1971</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change_h=</span>change<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>area) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">change_d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(change_h,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>breaks,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>labels)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>change_d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>change_colors) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_bbox</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">metro_van_bbox</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'tight'</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-53">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population change 1971-2021 in Vancouver"</span>,</span>
<span id="cb12-54">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change per hectare"</span>,</span>
<span id="cb12-55">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 1971 - 2021"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-yvr-pop-change-map" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-yvr-pop-change-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-yvr-pop-change-map-1.png" id="fig-yvr-pop-change-map" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-yvr-pop-change-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11
</figcaption>
</figure>
</div>
</div>
</div>
<p>Based on this we again look for surprising population changes, the distribution shown in Figure&nbsp;12 looks quite similar to the Toronto version.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">yvr_geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_drop_geometry</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_surprise</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">min</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(surprise<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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>surprise,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Period)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of surprising population changes"</span>,</span>
<span id="cb13-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Surprise"</span>,</span>
<span id="cb13-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of regions and periods"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-yvr-surprise-distribution" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-yvr-surprise-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-yvr-surprise-distribution-1.png" id="fig-yvr-surprise-distribution" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-yvr-surprise-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;12
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">yvr_geo_data2 <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;">iterate_geo_match_joins</span>(yvr_geo_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total_surprise_cutoff=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)</span>
<span id="cb14-2"></span>
<span id="cb14-3"></span>
<span id="cb14-4">yvr_join_count <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(yvr_geo_data)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(yvr_geo_data2)</span></code></pre></div></div>
</details>
</div>
<p>Repeating the procedure with the same parameters as in Toronto results in 416 region matches and correspondingly slightly coarser geographies.</p>
<p>Once this is automated it’s simple to apply this to other regions or other types of data. But it’s generally a good idea to take a more detailed look at how it performs on some examples.</p>
</section>
<section id="little-mountain" class="level2">
<h2 class="anchored" data-anchor-id="little-mountain">Little Mountain</h2>
<p>One danger of employing this procedure is that we might lose information of localized population declines that are real. Strong real population declines are rare, population change tends to be slow and dramatic declines rarely manifest themselves over a single 5 year inter-census period. But there are some examples where we can see <em>surprising</em> population declines that correspond to real process, Little Mountain in Vancouver provides a prominent example, with plenty of <a href="https://vancouversun.com/news/local-news/vancouvers-little-mountain-the-money-and-the-sad-history-behind-a-long-stalled-project">good news coverage with background information</a>. This was a social housing development that got sold off by the province to private developers and most tenants were evicted in 2009 and buildings were subsequently torn down, with planned replacement housing on the site mostly stalled since then. This lead to a <em>surprising</em> drop in population in those areas between the 2006 and 2011 censuses as can be seen when looking at census timelines of the two corresponding dissemination areas. Figure&nbsp;13 shows the population change 2006 to 2011 in the two regions covering the Little Mountain development, as well as the surrounding regions.</p>
<div class="cell" data-crop="true">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">little_mountain <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_as_sf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</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;">123.104</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">49.238</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;">4326</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coords=</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;">"x"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>)) </span>
<span id="cb15-2">yvr_data_nb <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;">poly2nb</span>(yvr_geo_data,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names=</span>yvr_geo_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">queen=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb15-3"></span>
<span id="cb15-4">little_mountain_ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> yvr_geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_filter</span>(little_mountain <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_buffer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(TongfenID)</span>
<span id="cb15-5"></span>
<span id="cb15-6"></span>
<span id="cb15-7">little_mountain_neighbour_ids <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb15-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(yvr_data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(yvr_data_nb[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(little_mountain_ids,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"|"</span>),</span>
<span id="cb15-9">                                                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(yvr_data_nb,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region.id"</span>)))])]</span>
<span id="cb15-10"></span>
<span id="cb15-11">yvr_geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb15-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(little_mountain_ids,little_mountain_neighbour_ids))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2011</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">2006</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> little_mountain_ids),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> little_mountain_ids),</span>
<span id="cb15-17">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>TongfenID),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_gradient2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_water</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_roads</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">datum=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population change 2006 to 2011 in Little Mountain and neighbouring regions"</span>,</span>
<span id="cb15-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">2006-2011"</span>,</span>
<span id="cb15-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2006 - 2011"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-little-mountain-map" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-little-mountain-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-little-mountain-map-1.png" id="fig-little-mountain-map" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-little-mountain-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;13
</figcaption>
</figure>
</div>
</div>
</div>
<p>The two areas that overlap the Little Mountain site also include neighbouring regions, but the drop in population is noticeable for both.</p>
<p>Figure&nbsp;14 shows the full timelines of the regions, we note that neighbouring regions don’t exhibit complementary patterns that suggest that this drop was due to geocoding errors.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">yvr_geo_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb16-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(little_mountain_ids,little_mountain_neighbour_ids))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}$"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">little_mountain=</span>TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> little_mountain_ids) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>TongfenID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span>little_mountain)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> little_mountain_ids),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,TongfenID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> little_mountain_ids)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>all_years) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linetype_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>),</span>
<span id="cb16-12">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Little Mountain"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neighbouring regions"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Population timelines in Little Mountain and neighbouring regions"</span>,</span>
<span id="cb16-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of people"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-little-mountain-timelines" class="quarto-float quarto-figure quarto-figure-center anchored" width="768">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-little-mountain-timelines-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-little-mountain-timelines-1.png" id="fig-little-mountain-timelines" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig quarto-uncaptioned" id="fig-little-mountain-timelines-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;14
</figcaption>
</figure>
</div>
</div>
</div>
<p>While the algorithm does flag the regions as <em>possible candidates</em> for geocoding errors, it does not find enough evidence that this is due to patterns consistent with geocoding problems because of the lack of complementary patterns in neighbouring regions. Considering examples like this can help calibrate the sensitivity of the algorithm.</p>
</section>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>The current implementation is useful and effective in detecting and dealing with geocoding problems where data gets misattributed to neighbouring regions. Dealing with this is important as these errors tend to happen precisely in regions that have experienced significant change and thus correlate with changes in density, which has a high chance of biasing analysis. The process of joining regions across boundaries that were subject to geocoding problems solves this problem in a similar way that Tongfen solves the problem of changing census geographies across time, and most importantly it does so in a way that avoids biasing the analysis.</p>
<p>The downside is the loss of control over the exact geographic regions used to aggregate the data and a resulting slightly coarser geography. In applications where it is important to retain the given geographies one has to find other solutions to solve this problem.</p>
<p>In the near future we plan to integrate this functionality in the Tongfen package to make it easier to use, and also to tie into existing functionality to re-aggregate data on joint geographies.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-07-26-geocoding-errors-in-aggregate-data/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb17-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-07-26 10:01:26 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb19-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [cfd8e12] 2024-07-25: updated image in md</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cancensus_0.5.8           mountainmathHelpers_0.1.4
 [3] spdep_1.3-5               spData_2.3.1             
 [5] tongfen_0.3.6             sf_1.0-16                
 [7] lubridate_1.9.3           forcats_1.0.0            
 [9] stringr_1.5.1             dplyr_1.1.4              
[11] purrr_1.0.2               readr_2.1.5              
[13] tidyr_1.3.1               tibble_3.2.1             
[15] ggplot2_3.5.1             tidyverse_2.0.0          

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1   farver_2.1.2       fastmap_1.2.0      lazyeval_0.2.2    
 [5] digest_0.6.35      timechange_0.3.0   lifecycle_1.0.4    geojsonio_0.11.3  
 [9] magrittr_2.0.3     compiler_4.4.0     rlang_1.1.4        tools_4.4.0       
[13] utf8_1.2.4         yaml_2.3.8         knitr_1.47         labeling_0.4.3    
[17] htmlwidgets_1.6.4  bit_4.0.5          sp_2.1-4           classInt_0.4-10   
[21] curl_5.2.1         RColorBrewer_1.1-3 KernSmooth_2.23-22 httpcode_0.3.0    
[25] withr_3.0.0        rmapzen_0.5.1      grid_4.4.0         fansi_1.0.6       
[29] git2r_0.33.0       e1071_1.7-14       colorspace_2.1-0   scales_1.3.0      
[33] crul_1.4.2         tinytex_0.51       cli_3.6.3          rmarkdown_2.27    
[37] crayon_1.5.2       generics_0.1.3     rstudioapi_0.16.0  geojson_0.3.5     
[41] httr_1.4.7         tzdb_0.4.0         DBI_1.2.3          proxy_0.4-27      
[45] assertthat_0.2.1   parallel_4.4.0     s2_1.1.6           vctrs_0.6.5       
[49] V8_4.4.2           boot_1.3-30        jsonlite_1.8.8     geojsonsf_2.0.3   
[53] hms_1.1.3          bit64_4.0.5        magick_2.8.3       rmapshaper_0.5.0  
[57] units_0.8-5        glue_1.7.0         codetools_0.2-20   stringi_1.8.4     
[61] gtable_0.3.5       deldir_2.0-4       munsell_0.5.1      pillar_1.9.0      
[65] htmltools_0.5.8.1  R6_2.5.1           jqr_1.3.3          wk_0.9.1          
[69] vroom_1.6.5        evaluate_0.23      lattice_0.22-6     class_7.3-22      
[73] Rcpp_1.0.12        xfun_0.44          pkgconfig_2.0.3   </code></pre>
</div>
</div>
</details>



</section>

<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-logan2016" class="csl-entry">
Logan, John R., Brian J. Stults, and Zengwang Xu. 2016. <span>“Validating Population Estimates for Harmonized Census Tract Data, 2000<span></span>2010.”</span> <em>Annals of the American Association of Geographers</em> 106 (5): 1013–29. <a href="https://doi.org/10.1080/24694452.2016.1187060">https://doi.org/10.1080/24694452.2016.1187060</a>.
</div>
<div id="ref-statisticscanada-long-census-timelines.2019" class="csl-entry">
Statistics Canada. 2019. <em>1971, 1981-2011 Census Profiles and 2011 National Household Survey Profile Aggregated to 2016 Dissemination Area Level Geographies [Semi-Custom Tabulation]</em>. Borealis. <a href="https://doi.org/10.5683/SP2/QNO5JG">https://doi.org/10.5683/SP2/QNO5JG</a>.
</div>
<div id="ref-surprise.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017. <em>Surprise <span>Maps</span></em>. <a href="https://doodles.mountainmath.ca/posts/2017-04-10-surprise/">https://doodles.mountainmath.ca/posts/2017-04-10-surprise/</a>.
</div>
<div id="ref-tongfen.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020a. <em>TongFen</em>. <a href="https://doodles.mountainmath.ca/posts/2020-11-10-tongfen/">https://doodles.mountainmath.ca/posts/2020-11-10-tongfen/</a>.
</div>
<div id="ref-vonbergmann2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020b. <em>Tongfen: Make Data Based on Different Geographies Comparable</em>. The R Foundation. <a href="https://doi.org/10.32614/cran.package.tongfen">https://doi.org/10.32614/cran.package.tongfen</a>.
</div>
<div id="ref-toward-universal-tongfen-change-in-polling-district-voting-patterns.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2020c. <em>Toward Universal <span>TongFen:</span> <span>Change</span> in Polling District Voting Patterns</em>. <a href="https://doodles.mountainmath.ca/posts/2020-05-20-toward-universal-tongfen-change-in-polling-district-voting-patterns/">https://doodles.mountainmath.ca/posts/2020-05-20-toward-universal-tongfen-change-in-polling-district-voting-patterns/</a>.
</div>
<div id="ref-population-timelines-update.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2024. <em>Population Timelines Update</em>. <a href="https://doodles.mountainmath.ca/posts/2024-04-23-population-timelines-update/">https://doodles.mountainmath.ca/posts/2024-04-23-population-timelines-update/</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{geocoding-errors-in-aggregate-data.2024,
  author = {{von Bergmann}, Jens},
  title = {Geocoding Errors in Aggregate Data},
  date = {2024-07-26},
  url = {https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann. 2024. <span>“Geocoding Errors in Aggregate
Data.”</span> <em>MountainDoodles</em>, accepted, July 26. <a href="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/">https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/</a>.
</div></div></section></div> ]]></description>
  <category>cancensus</category>
  <category>tongfen</category>
  <category>Vancouver</category>
  <category>Toronto</category>
  <category>geeky</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/</guid>
  <pubDate>Fri, 26 Jul 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-07-26-geocoding-errors-in-aggregate-data/index_files/figure-html/fig-crescent-town-check-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Tenure and Household Independence across the Life Course, 1981-2021</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/07/11/tenure-and-household-independence-across-the-life-course-1981-2021/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>How does owning or renting relate to household independence across the life course? How have these relationships changed over recent history? We use Census data from 1981-2021 to check in on historical relationships between age, tenure, and household composition. From these we develop a couple of preliminary demographic metrics of housing frustration. Patterns suggest that frustration abounds.</p>
<p>In previous posts we have looked in detail how Canadians distribute into households, and have focused in on Minimum Household Units, and how individuals move through different living arrangements across their lives. <span class="citation" data-cites="housing-outcomes.2023 what-s-a-household.2017">(<span class="nocase">von Bergmann and Lauster</span> 2023; <span class="nocase">von Bergmann</span> 2017)</span> In this post we want to add another dimension into the picture: tenure.</p>
<section id="tenure-trajectories" class="level1">
<h1>Tenure trajectories</h1>
<p>It’s customary in demographic approaches to housing to divide tenure from peoples’ household types (i.e.&nbsp;who they live together with), and to treat both as distinct choices people make. But this isn’t quite right, of course. People’s tenure arrangements and who they live tend to be ordered in terms of what is culturally valued versus what is stigmatized. Both also speak to questions of power in interesting ways that we can even consider feudal (who is “head” of the household, and who is lord of their land, i.e.&nbsp;the landlord). Perhaps more importantly for our purposes, both also speak to constraints. The harder it is to transition into ownership as a head of household, the more people may be frustrated by less-than-ideal alternatives.</p>
<p>On the flip side, policy also treats these statuses quite differently, and the reality in Canada is that we don’t have tenure neutrality. Property rights receive far greater protections than those granted through Canada’s rental tenancy acts, though these vary by province. Our tax and incentive system also heavily favours owners, first and foremost through the non-taxation of imputed rent, and secondly through the non-taxation of capital gains on principal residences, in addition to various other breaks like BC’s home owner grant against property taxes. Non-taxation of capital gains has increasingly gained in importance as we have allowed home prices to rise much faster than inflation. Relatedly, we have seen rents rising faster than inflation, decreasing security of tenure for renters and increasing incentives for renters to become owners and lock in their housing costs.</p>
<p>Ultimately this returns us to choice. Not everyone has a choice, which can cause a lot of frustration. For those who do, rental and ownership housing offer different advantages and disadvantages to people. Renting offers more flexibility and has lower moving friction, but less security and control over the living environment. And importantly, it does not require a down-payment, other than a security deposit. This all works out across the life course so that, after leaving their parental home, most people start out their housing journey as renters and then at some later point potentially transition into ownership.</p>
<p>We have looked at tenure in other contexts in the past, in particular in conjunction with mobility. <span class="citation" data-cites="tumbling-turnover.2022 residential-mobility-in-canada.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022; <span class="nocase">von Bergmann</span> 2022)</span> But we have also looked at <a href="https://x.com/vb_jens/status/1067664674194317312">tenure by age group in Canadian metro area</a> several years back using 2011 data, which is more similar to where we are going with this post.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">year_colours <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;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spectral"</span>)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</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;">11</span>)],<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1981</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;">5</span>)))</span>
<span id="cb1-2"></span>
<span id="cb1-3">pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-5">  <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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span>Share<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;">lag</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>AGEGRP) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(diff,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) </span></code></pre></div></div>
</details>
</div>
<p>Indeed, when looking at the share of the population (in private households) living in renter households by age group in Figure&nbsp;1, we see children generally living in owner households (with their parents), and the prevalence of living in owner households increasing with age as parents might have rented when the child was young and then transitioned into ownership. That changes once children reach the age of 18, at what point they start to live in renter households at much higher rates, peaking at almost half living in renter households at the age 25 to 29 years.</p>
<p>Then follows a steady trend of transition to homeownership, with peak home ownership being somewhere between the ages of 50 to 70, with the peak age group over time increasing. After that the share of renters increases again.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by age"</span>,</span>
<span id="cb2-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb2-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,</span>
<span id="cb2-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-canada-renter-share-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-canada-renter-share-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-canada-renter-share-age-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-canada-renter-share-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: The share of the population in renter households by age group in Canada 1981-2021, showing how tenure changes by age and over time.
</figcaption>
</figure>
</div>
</div>
</div>
<p>To understand the development of renter share over time Figure&nbsp;2 shows the (crude) average share of people in renter households, as well as an age adjusted average, using the 2021 population distribution by age as a baseline. Age adjustment here helps account for how the early years of our timeline, in particular, included a lot of young Baby Boomers, who re-weighted the balance between owning and renting for the population as a whole as they moved through their life course.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">pop_weights <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age_share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(AGEGRP,age_share) </span>
<span id="cb3-6"></span>
<span id="cb3-7">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(pop_weights,<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;">"AGEGRP"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age-adjusted average</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>age_share),</span>
<span id="cb3-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Crude average</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</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;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age-adjusted average</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Crude average</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Type"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c033) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean share of people in renter households"</span>,</span>
<span id="cb3-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb3-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb3-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-canada-renter-share-summary" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-canada-renter-share-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-canada-renter-share-summary-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-canada-renter-share-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The share of the population in renter households in Canada 1981-2021, showing the overall share and age-adjusted (to 2021 population) share of the population in renter households.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Overall the share of people in renter households was fairly constant between 1981 to 1996, then dropped quite rapidly until 2011 and increased since then with the age-adjusted renter share climbing back up to 1981 levels in 2021 but staying below the 1996 high point. Age structure hasn’t been much of a factor in accounting for tenure mix since at least 2006.</p>
<p>But this is just looking at age groups in single years, how much of this is really due to people changing tenure vs people aging and bringing their old tenure forward? Demographers also try to be attentive to these kind of cohort effects. Figure&nbsp;3 shows the same information by age cohort instead of census year, which makes it easier to disentangle this.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lower_age=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_b=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Lower_age)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(upper_b<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-4</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,upper_b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(Cohort,upper_b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"85 years and over"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(upper_b<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;">1910</span>,upper_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2010</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Cohort),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Cohort))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-15">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#scale_fill_manual(values=MetBrewer::met.brewer("Egypt",5)) +</span></span>
<span id="cb4-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by age"</span>,</span>
<span id="cb4-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb4-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Birth cohort"</span>,</span>
<span id="cb4-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-canada-renter-share-age-chohort" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-canada-renter-share-age-chohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-canada-renter-share-age-chohort-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-canada-renter-share-age-chohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: The share of the population in renter households in Canada by birth cohort, showing the progression of people through tenure as they age.
</figcaption>
</figure>
</div>
</div>
</div>
<p>This shows that the peak homeownership age is much more consistently between 55 to 69 years, and what looked like dramatic increases in renter share for people at older ages is largely driven by cohort effects with each age cohort starting at higher homeownership rates, although there remains a tendency to transition from ownership to rental for seniors. (Making the reasonable assumption that owners don’t die at faster rates then renters.)</p>
<p>But housing is local, and national average can mask diverging local trends. Figure&nbsp;1 breaks this down to metro geographies. For all metro areas, the biggest historical pattern remains the declining share of seniors renting, which as we have noted, is largely (though not entirely) a cohort effect. But other patterns vary by metro area, including renter shares overall, with Montréal having by far the highest rates of renters, and Calgary having the lowest. Another pattern that starts to become visible is the dramatic slowing of pathways into home ownership through middle age for Metro Vancouver. In 1981, most transitions into ownership were well underway by age 35-39, with less than a quarter in that age group still renting. By 2021, the age gradient of ownership was far more gradual, with 40% of those age 35-39 were still renting. Not surprisingly, a similar transition shows up for older children (age 10-17), likely matching parents remaining renters for longer as they aged. While this pattern of steadily delayed transition into ownership through middle age is most apparent in Vancouver, there is also evidence of it elsewhere, particularly Winnipeg and Hamilton.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">pd2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span>Share<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;">lag</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(diff,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) </span>
<span id="cb5-8"></span>
<span id="cb5-9">cma_selection <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pd2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span>)</span>
<span id="cb5-10">cma_colours <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;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(cma_selection),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Set1"</span>),cma_selection)</span>
<span id="cb5-11"></span>
<span id="cb5-12">pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by metro area and age"</span>,</span>
<span id="cb5-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb5-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,</span>
<span id="cb5-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-renter-share-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-renter-share-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-metro-renter-share-age-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-renter-share-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: The share of the population in renter households by age group in Canadian metro areas 1981-2021, showing how tenure changes by age and over time.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Once again, slicing the data by cohorts in Figure&nbsp;5 shows that much of the shift we see, both in declining rentership for seniors, and delayed ownership for those middle-aged (in select metros) is due to cohort effects. Successive cohorts of seniors starting out with lower renter shares than their predecessors and kept these shares as they aged. In Vancouver, successive cohorts of those entering middle-age stayed renters longer before transitioning into ownership.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">pd3<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>pd2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AGEGRP=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 17 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"15 to 19 years"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"18 to 19 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lower_age=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_b=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Lower_age)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(upper_b<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-4</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,upper_b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(Cohort,upper_b))</span>
<span id="cb6-10"></span>
<span id="cb6-11"></span>
<span id="cb6-12">pd3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"85 years and over"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(upper_b<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;">1910</span>,upper_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2010</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Cohort),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Cohort))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by metro area and age"</span>,</span>
<span id="cb6-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb6-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Birth cohort"</span>,</span>
<span id="cb6-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-renter-share-age-cohort" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-renter-share-age-cohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-metro-renter-share-age-cohort-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-renter-share-age-cohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: The share of the population in renter households in Canadian metro areas by birth cohort, showing the progression of people through tenure as they age.
</figcaption>
</figure>
</div>
</div>
</div>
<p>What about young adults? Here the patterns are more complicated. The sharp spike in renting across young adulthood we can see in 1981, both at the national level and for metro areas, has become lower and shifted later. To understand this pattern better requires mixing back in household composition.</p>
</section>
<section id="mixing-in-household-composition" class="level1">
<h1>Mixing in household composition</h1>
<p>Interpreting tenure composition at the younger ages is complicated by household living arrangements. For example dropping renter shares for 30 year olds could be indicative of people in their thirties transitioning into homeownership faster than previous generations, but it could also be due to people in their thirties remaining longer in their parent household which tend to be owner-occupied. These provide diverging interpretations of the data with very different housing outcomes for people in their thirties, so it’s important to try and separate these.</p>
<p>In previous posts we have worked with the concept of Minimum Household Unit (MHU) to address this <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023)</span> and we can split the population, and our renter shares, into two groups, those living in MHU and those outside of MHU. One problem is that we can’t cleanly separate out MHUs in the case of adult children living with parents. We can identify the children, and assign them to non-MHU households, but with the PUMF data we can’t separate out the parents, so they will still be counted as living in MHUs even with adult children at home. If we take a “frustration” approach to understanding housing goals, this is probably fine for our purposes. In particular, we may want to think of parents with adult children living at home as within MHU, insofar as they may feel like their particular housing and household situation is fine. At the same time, we may want to think of their children as being outside of MHU, insofar as they may feel frustrated in their housing and household situation. We acknowledge there may be some complexity here, including “failure to launch” situations where parents are more frustrated than children, but overall we feel ok about assigning most of the frustration concerning housing access to adult children rather than their parents.</p>
<p>Figure&nbsp;6 gives a quick overview of the share of the population living in Minimum Household Units by age group. The vertical dashed line between the 20 to 24 and 25 to 29 year old age groups indicates where we switched from considering children living with parents as being “dependent” children, and those still living in MHU if they live with parents, to no longer being in MHU if they still live with their parents. That cutoff is partially informed by census coding and the “usual place of residence” concept that might code post-secondary students as living with their parents, even though the live elsewhere for most of the year.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">pd_mhu<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) </span>
<span id="cb7-5"></span>
<span id="cb7-6">pd_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MHU<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;">"Living in MHU"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pd_mhu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</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.5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in minimum household units by age"</span>,</span>
<span id="cb7-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Parents with adult children at home are classifed as MHU)"</span>,</span>
<span id="cb7-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in minimum household units"</span>,</span>
<span id="cb7-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,</span>
<span id="cb7-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-age-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: The share of the population in Minimum Household Units by age group in Canada for 1981 through 2021. Minimum Household Units are constitued of households made up of either adult individuals, lone parents with dependent children, childless (married or common law) couples, and couples with dependent children.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The big pattern here is the dramatic drop in the proportion of young adults living in MHU from 1981 to 2021. Meanwhile, older adults became increasingly likely up from 1981-2001 to live in MHU, before the pattern reversed somewhat from 2001-2021 except for all but the most senior (age 80+). On the other side of the lifespan, young children follow similar patterns as adults in their 30s and 40s - increasingly likely their parents. Insofar as the drop in the share of young adults in their late 20s living in MHUs is particularly pronounced, we zoom into this group in Figure&nbsp;7 to highlight how this drop is driven by fewer couple with children households. Young people are delaying coupling and childbearing. This is made up for by an increase of children living with parents and to a somewhat lesser extent an increase in living with roommates, leading non-MHU situations (in pastel colours). In terms of MHU situations, those living alone also rose over time, but not nearly enough to make up for the decline in those living as couples with children. Those living as single parents rose and then dropped again and those living as part of childless couples remained stable, rounding out our MHU categories.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">pd_mhu<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU_full)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) </span>
<span id="cb8-5"></span>
<span id="cb8-6"></span>
<span id="cb8-7">pd_mhu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP<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;">"25 to 29 years"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_colours,</span>
<span id="cb8-14">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>mhu_labels) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 year olds by MHU (and non-MHU) status"</span>,</span>
<span id="cb8-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of 25 to 29 year olds in private households"</span>,</span>
<span id="cb8-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU/non-MHU status"</span>,</span>
<span id="cb8-18">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-25-29" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-25-29-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-25-29-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-25-29-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: The share of 25 to 29 year olds by detailed MHU and non-MHU status by age group in Canada for 1981 through 2021.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Armed with this understanding of Minimum Household Units we proceed to look at the share of MHU (and non-MHU) households by tenure in Figure&nbsp;8. We again mark the age group below which we count children living with parents as being in MHU. Here we can see how living in MHU and renting are complementary strategies. Renting is generally an important strategy for people hoping to achieve some form of household independence. Renting is less common for those outside of MHU, except for the youngest group, where renting with roommates (a non-MHU household) is especially common.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">pd4<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP,MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span>Share<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;">lag</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,MHU)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(diff,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) </span>
<span id="cb9-8"></span>
<span id="cb9-9">pd4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pd_mhu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</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.5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>MHU) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by age"</span>,</span>
<span id="cb9-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Parents with adult children at home are classifed as MHU)"</span>,</span>
<span id="cb9-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb9-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,</span>
<span id="cb9-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-tenure-canada" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-tenure-canada-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-tenure-canada-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-tenure-canada-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8: Share of people in Canada who are renting by MHU status across census years.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Overall it seems clear that rental housing plays an important role at enabling young adults to live in MHU, and from there they tend to transition into ownership as they age, with transitions taking progressively longer over time. Renting has also enabled aging adults to maintain the independence of an MHU household, whether in the face of unexpected relationship dissolution, or moving to a desirable retirement destination. But this has become less important over historical time, as older adults have become more likely to obtain and hold onto both independence and home ownership. Remaining in non-MHU status (especially living with parents, but also living with roommates) offers a more linear path out of renting in terms of how it relates to age. Indeed, the seniors in non-MHU households are, in many cases, likely the owners of homes they share with their adult children.</p>
<p>Figure&nbsp;9 breaks this down by major metro area. The patterns are broadly similar between metro areas, with some, in particular Edmonton, showing an earlier peak in MHU households already at the 20 to 24 year old age.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">pd5<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(TENUR,Year,AGEGRP,MHU,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span>Share<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;">lag</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AGEGRP,MHU,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coalesce</span>(diff,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) </span>
<span id="cb10-8"></span>
<span id="cb10-9">pd5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ott.–Gat."</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>AGEGRP,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Year))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(pd_mhu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>AGEGRP)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20 to 24 years"</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.5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>year_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(CMA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>MHU) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"People in renter households by age"</span>,</span>
<span id="cb10-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Parents wtih adult children at home are classifed as MHU)"</span>,</span>
<span id="cb10-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population in private households</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">living in renter households"</span>,</span>
<span id="cb10-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,</span>
<span id="cb10-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-tenure-cma" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-tenure-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-tenure-cma-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-tenure-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9: Share of people in Canada who are renting by MHU status and metro area across census years.
</figcaption>
</figure>
</div>
</div>
</div>
<p>In Figure&nbsp;10 we come back to the detailed look at 25 to 29 year olds and split them by MHU status and tenure. Roughly half of 25-29 year olds show up in each tenure status. In 1981, owners are dominated by those in MHU, especially couples with children, but we can see this status declining dramatically, even as living with parents rises. The same pattern unfolds for renters, but not nearly to the same extent. Moreover, living with roommates plays a much bigger role in the rise of non-MHU households for renters. Even so, by 2021 fewer owners are in MHU than renters in this age range, mostly reflecting more 25-29 year olds living in their parents’ (owned) homes. Overall, it appears renting became a more prevalent route to MHU households than owning for young adults over the past 40 years.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">pd_mhu_tenure<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU_full,TENUR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP))</span>
<span id="cb11-5"></span>
<span id="cb11-6">pd_mhu_tenure <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP<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;">"25 to 29 years"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>TENUR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_colours,</span>
<span id="cb11-14">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU1"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living alone"</span>,</span>
<span id="cb11-15">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU2"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lone parent"</span>,</span>
<span id="cb11-16">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU3"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Childless couple"</span>,</span>
<span id="cb11-17">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU4"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple with children"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 year olds by MHU (and non-MHU) status"</span>,</span>
<span id="cb11-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of 25 to 29 year olds in private households"</span>,</span>
<span id="cb11-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU/non-MHU status"</span>,</span>
<span id="cb11-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-25-29-tenure" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-25-29-tenure-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-25-29-tenure-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-25-29-tenure-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;10: Breakdown of share of 25 to 39 year olds in Canada by household living arrangements and tenure and census year.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The national trends obscure, to some extent, how the same historical transformation took place even more quickly within the big metros where rental stock was more prevalent. There, 25-29 years were always more likely to rent, and renting was even more associated with being in MHU status than ownership, remaining so over the years, even as more renters took on roommates. By contrast, many mid-size metros (e.g.&nbsp;Calgary, Edmonton, and Ottawa) saw a bump in 2006 and 2011 where owner-occupied households were as likely in MHU as renters, before renters began to outpace in MHU status once more.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">pd_mhu_tenure_cma<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,MHU_full,TENUR,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA))</span>
<span id="cb12-5"></span>
<span id="cb12-6">pd_mhu_tenure_cma <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP<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;">"25 to 29 years"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CMA=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(CMA,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ott.–Gat."</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ottawa – Gatineau"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(CMA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>TENUR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_colours,</span>
<span id="cb12-16">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU1"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Living alone"</span>,</span>
<span id="cb12-17">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU2"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lone parent"</span>,</span>
<span id="cb12-18">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU3"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Childless couple"</span>,</span>
<span id="cb12-19">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU4"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple with children"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 year olds by MHU (and non-MHU) status"</span>,</span>
<span id="cb12-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of 25 to 29 year olds in private households"</span>,</span>
<span id="cb12-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MHU/non-MHU status"</span>,</span>
<span id="cb12-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census PUMF 1981 through 2021 (individuals)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-25-29-tenure-cma" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-25-29-tenure-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-25-29-tenure-cma-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-25-29-tenure-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;11: Breakdown of share of 25 to 39 year olds by household living arrangements and tenure by metro area and census year.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="housing-frustration" class="level1">
<h1>Housing Frustration?</h1>
<p>We can think about age relationships to MHU status and renter status in a different way if we consider them in terms of age-normative aspirations. While many people are open to alternative ways of sharing their living space, it can also be frustrating to find one’s self living with parents or roommates past a certain age. Similarly, it can be frustrating to rent when a person really desires ownership. We can align this frustration with expectations associated with age in a simple way by setting aside age 25-34 as a time when people want to head up their own MHU household, i.e.&nbsp;with or without a partner and children. Similarly we can imagine those age 35-59 as wanting to move into home ownership. Living outside of these statuses over these age ranges could be taken as a measure of housing frustration. Let’s consider these kinds of frustration separately, first by looking at age standardized proportions frustrated as measured historically as done in Figure&nbsp;12.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">pd_frustration_1<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,MHU,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MHU<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;">"Not living in MHU"</span>)</span>
<span id="cb13-7"></span>
<span id="cb13-8">pd_frustration_2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"40 to 44 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 49 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50 to 54 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to 59 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-11">  <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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,TENUR,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>)</span>
<span id="cb13-14"></span>
<span id="cb13-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(pd_frustration_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 34 year olds not in MHU"</span>),</span>
<span id="cb13-16">          pd_frustration_2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 59 year olds not in owner households"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(pop_weights,<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;">"AGEGRP"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>age_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Type,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>Type)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>duos<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c071) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing frustration"</span>,</span>
<span id="cb13-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Frustration measure"</span>,</span>
<span id="cb13-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb13-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age-adjusted share of the respective population"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-frustration" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-frustration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-frustration-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-frustration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;12: Normative concept of ‘housing frustration’ as measured by the time 25 to 34 year olds spent not in MHU and the time 35 to 59 year olds spent not in owner households.
</figcaption>
</figure>
</div>
</div>
</div>
<p>We can see that the potential frustration of young adults (25-34) has risen most strongly over time, likely reflecting more and more young people finding themselves unable to head up MHU households. By contrast, the potential frustration of middle-aged renters (35-59) has risen, fallen, then risen again, but never quite equalled the potential frustrations of the young since 1981. We can usefully pull these trends out by metro area in Figure&nbsp;13.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">pd_frustration_1_cma<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,MHU,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(MHU<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;">"Not living in MHU"</span>)</span>
<span id="cb14-7"></span>
<span id="cb14-8">pd_frustration_2_cma<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 39 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"40 to 44 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45 to 49 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"50 to 54 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55 to 59 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-11">  <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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,TENUR,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(TENUR<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;">"Renter"</span>)</span>
<span id="cb14-14"></span>
<span id="cb14-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(pd_frustration_1_cma <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 34 year olds not in MHU"</span>),</span>
<span id="cb14-16">          pd_frustration_2_cma <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 59 year olds not in owner households"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(pop_weights,<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;">"AGEGRP"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>age_share),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Type,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>CMA,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cma_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Housing frustration"</span>,</span>
<span id="cb14-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb14-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb14-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age-adjusted share of the respective population"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-frustration-metro" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-frustration-metro-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-frustration-metro-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-frustration-metro-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;13: ‘Housing frustration’ by metro area, as measured by the time 25 to 34 year olds spent not in MHU and the time 35 to 59 year olds spent not in owner households.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Perhaps not surprisingly, Toronto and Vancouver lead the housing frustrations of young adults unable to head up MHU households. But all metros have seen a gradual rise in the housing frustrations of the young, save for Québec City. By contrast, Québec metro areas lead for our measure of those still renting in middle age, even though the share renting there declines over time. This may not reflect frustration, in this case, so much as a different and changing set of norms. Renting through the life course has historically been more common in Québec, but has nevertheless been on the decline, mirroring a rise in access to home ownership for those desiring it. If people were frustrated about their access to ownership before (an open question), that frustration may have eased a bit over recent history. Anglophone metro areas tend to exhibit more of a wave pattern, with stable or rising shares renting from 1981, to a decline in 2006, and a rise in renting share since. We’re possibly seeing a bit of an effect from the Great Recession here, where ownership became harder to achieve as both mortgage rules and supply tightened through the Great Recession. By this measure, frustration in Vancouver was rising most quickly prior to 2001, and if it eased somewhat prior to the Great Recession, it has since returned with a vengeance, likely reflecting a middle-aged population feeling increasingly locked out from home ownership.</p>
<p>Focusing in on the 25 through 34 year olds we look at their changing living arrangements, showing how they distribute into MHU (left) and non-MHU (right) categories by metro area in Figure&nbsp;14. Pay special attention to the dividing line between magenta and pastel orange (share of 25-34 years in MHU couple with children households versus share in non-MHU living with their parents households).</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pd_frustration_full_cma<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,MHU,MHU_full,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) </span>
<span id="cb15-6"></span>
<span id="cb15-7">pd_frustration_full_cma <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-9">  <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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Share)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,MHU_full,Year)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(years),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>years,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</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;">ncol=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_colours, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>mhu_labels) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household living arrangements of 25 to 34 year olds by census year"</span>,</span>
<span id="cb15-19">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-20">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb15-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average number of years in living arrangement during 10 year timespan"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-status-cma" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-status-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-status-cma-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-status-cma-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;14: Household living arrangeents, showing the the average time 25 to 34 year olds spent in four MHU categories as well as non-MHU households broken down into 5 non-MHU categories by census year, using synthetic cohorts.
</figcaption>
</figure>
</div>
</div>
</div>
<p>All areas saw a strong decline in time spent in couple with children households over this time period. In Metro Québec this was made up for by an increase of time spent living alone and by childless couples, so that MHU households overall remained stable. A similar but less pronounced replacement of couple with children households by other MHU households occurred in Montréal. Elsewhere, in more Anglophone metro areas, there was little change from the left (in the time spent living alone and in childless couple relationships) to compensate for the decline in time spent in couple with children households. Mostly, young adults increasingly found themselves in the non-MHU household situations on the right, especially continuing to live with their parents, a pattern especially pronounced in Vancouver and Toronto.</p>
<p>To round this up we slice this by birth cohorts in order to separate out cohort effects and directly compare the experience of different birth cohorts over time. Unfortunately we need full cohorts for this approach, akin to shifting from Total Fertility Rate to Cohort Fertility Rates to describe childbearing. So this does effectively reduce the timeliness of the estimates. But in exchange we get something closer to the completed experience of historical cohorts. The results are shown in Figure&nbsp;15.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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">pd_frustration_full_cma<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>mhu_pumf_combined <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <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;">"Not available"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(AGEGRP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(AGEGRP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 29 years"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"30 to 34 years"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-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;">n=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,MHU,MHU_full,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,AGEGRP,CMA)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lower_age=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(AGEGRP,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_b=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(Lower_age)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(upper_b<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-4</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,upper_b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cohort=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(Cohort,upper_b))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,MHU_full,Cohort))</span>
<span id="cb16-11"></span>
<span id="cb16-12">pd_frustration_full_cma <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CMA <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cma_selection) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-15">  <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;">years=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(Share)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(CMA,MHU_full,Cohort)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(years),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Cohort,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>years,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(MHU_full))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stack"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reverse=</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;">ncol=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>CMA) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>mhu_colours,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>mhu_labels) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"living arrangements of 25 to 34 year olds by birth cohort"</span>,</span>
<span id="cb16-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average number of years in living arrangement during 10 year timespan"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mhu-status-cma-cohort" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mhu-status-cma-cohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-mhu-status-cma-cohort-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mhu-status-cma-cohort-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;15: Household living arrangeents, showing the the average time 25 to 34 year olds spent in four MHU categories as well as non-MHU households broken down into 5 non-MHU categories by birth cohort.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The results are quite similar to the previous figure, with less variation across time, indicating that some of the variation between years in the previous graph stems from cohort effects. The difference between metro areas, in particular Québec and to a lesser extent Montréal vs the other areas, remains quite stark.</p>
<p>Some of this variation may be due to shifting normative expectations driven by changes in cultural makeup. Indeed, Metro Québec stands out in being culturally quite homogeneous compared to other Canadian metro areas. We attempt to look at this more in-depth in work currently under review. But the majority of the effect we are seeing can be attributed to differences in rent.</p>
</section>
<section id="upshot" class="level1">
<h1>Upshot</h1>
<p>Tenure choice is an important and interesting dimension of housing to watch in Canada. In many places, tenure choice is also likely a source of increasing frustration. Given the strong government subsidies for homeownership we expect people to aspire to home ownership. And indeed home ownership increased 1981 through 2006, a time period where incomes rose and baby boomers and, to a lesser extent Gen X, managed to outrun rising housing pressures and costs, with these cohorts sliding through with relatively high home ownership rates.</p>
<p>In terms of housing pressures, we can also consider tenure in conjunction with whether individuals, either on their own or jointly with a partner, are able to head up a household of their own. This ultimately remains a more expressive metric of housing frustration, be it household maintainer rates or more refined measures like the population in minimum household units (MHU), or elaborated across more detailed living arrangements. Here we see worsening housing outcomes throughout the forty year timeframe explored (1981-2021), in particular in high-cost areas. Monitoring changes in household living arrangements of people during their prime household formation years, 25 to 34 year olds, potentially allows demographers to track housing pressures in near real time.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb17-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-07-11 16:37:01 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb19-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [f15e1f6] 2024-06-26: remove unnecessary images</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5               cli_3.6.3                
 [3] knitr_1.47                rlang_1.1.4              
 [5] xfun_0.44                 generics_0.1.3           
 [7] jsonlite_1.8.8            glue_1.7.0               
 [9] colorspace_2.1-0          git2r_0.33.0             
[11] htmltools_0.5.8.1         mountainmathHelpers_0.1.4
[13] scales_1.3.0              fansi_1.0.6              
[15] rmarkdown_2.27            grid_4.4.0               
[17] munsell_0.5.1             evaluate_0.23            
[19] tibble_3.2.1              fastmap_1.2.0            
[21] yaml_2.3.8                lifecycle_1.0.4          
[23] compiler_4.4.0            dplyr_1.1.4              
[25] htmlwidgets_1.6.4         pkgconfig_2.0.3          
[27] rstudioapi_0.16.0         digest_0.6.35            
[29] R6_2.5.1                  tidyselect_1.2.1         
[31] utf8_1.2.4                pillar_1.9.0             
[33] magrittr_2.0.3            tools_4.4.0              
[35] gtable_0.3.5              ggplot2_3.5.1            </code></pre>
</div>
</div>
</details>



</section>

<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-what-s-a-household.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017. <em>What’s a <span>Household?</span></em> <a href="https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/">https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/</a>.
</div>
<div id="ref-residential-mobility-in-canada.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2022. <em>Residential Mobility in <span>Canada</span></em>. <a href="https://doodles.mountainmath.ca/posts/2022-05-27-residential-mobility-in-canada/">https://doodles.mountainmath.ca/posts/2022-05-27-residential-mobility-in-canada/</a>.
</div>
<div id="ref-tumbling-turnover.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022. <em>Tumbling Turnover</em>. <a href="https://doodles.mountainmath.ca/posts/2022-07-29-tumbling-turnover/">https://doodles.mountainmath.ca/posts/2022-07-29-tumbling-turnover/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{tenure-and-household-independence-across-the-life-course-1981-2021.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Tenure and {Household} {Independence} Across the {Life}
    {Course,} 1981-2021},
  date = {2024-07-11},
  url = {https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“Tenure and
Household Independence Across the Life Course, 1981-2021.”</span>
<em>MountainDoodles</em>, accepted, July 11. <a href="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/">https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</a>.
</div></div></section></div> ]]></description>
  <category>canpumf</category>
  <category>affordability</category>
  <category>Vancouver</category>
  <category>Toronto</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/</guid>
  <pubDate>Thu, 11 Jul 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-07-11-tenure-and-household-independence-across-the-life-course-1981-2021/index_files/figure-html/fig-frustration-metro-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Migration and Housing Costs</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/06/11/migration-and-housing-costs/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>New data supports a common theme: Housing costs seem to be increasingly important as a determinant of long-distance migration, adding to their traditional importance within short-distance moves. But there are still some interesting caveats. We have a look at the data, compare it to what we know of flows, and think through some of its perhaps unexpected implications.</p>
<section id="leaving-bc" class="level1">
<h1>Leaving BC</h1>
<p>We have become used to an endless stream of news about people leaving (or wanting to leave) Vancouver. Mostly because of housing costs. But what about BC writ large? The latest news comes in the form of an <a href="https://angusreid.org/bc-investment-migration-housing/">Angus Reid survey</a><sup>1</sup> on people’s intention to leave British Columbia because of housing costs, with this sentiment dropping off for people 55 or older.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/images/angus-reid-leaving-bc.png" class="img-fluid figure-img"></p>
<figcaption>Angus Reid poll on people’s intention to leave British Columbia because of housing costs, keyed by age group</figcaption>
</figure>
</div>
<p>The age relationship makes sense insofar as older people move less and are more likely settled in their housing. Strikingly, when broken out by geography the numbers are lower for Metro Vancouver than the (cheaper) parts to the East, with fewer people agreeing or strongly agreeing that they are seriously thinking of leaving the province because of housing costs.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/images/angus-reid-leaving-vancouver.png" class="img-fluid figure-img"></p>
<figcaption>Angus Reid poll on people’s intention to leave British Columbia because of housing costs keyed by current region of residence</figcaption>
</figure>
</div>
<p>Part of the difference might be explained simply by proximity to Alberta. Leaving the province isn’t such a big a deal when the border is nearby anyway. This fits with the idea that housing related moves are mostly local. There may also be some selection insofar as people looking to leave Metro Vancouver because of housing costs consider other parts of the province too, whereas people in those other parts concerned about housing costs likely won’t consider Metro Vancouver as a feasible alternative. We’re going to return to thinking about these metropolitan differences.</p>
<p>But first, the article also points out that:</p>
<div class="line-block">&nbsp;&nbsp;“In 2023, the province lost 8,000 more residents to other provinces than it gained, an inter-provincial net loss not seen in B.C. since 2012.”</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">internal_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;">get_cansim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0045"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span>Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">days</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>))</span>
<span id="cb1-3">pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography, province of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> levels</span>
<span id="cb1-4">po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>GEO <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> unique <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", province of origin"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,.)</span>
<span id="cb1-5">provinces <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;">"Alberta"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ontario"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saskatchewan"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manitoba"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other provinces"</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7">external_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;">get_cansim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0040"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span>Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">days</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#%&gt;%</span></span>
<span id="cb1-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(GEO==prov) %&gt;%</span></span>
<span id="cb1-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#mutate(value=case_when(`Components of population growth`=="Emigrants" ~ -val_norm, TRUE ~ val_norm))</span></span>
<span id="cb1-11"></span>
<span id="cb1-12">natural_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;">get_cansim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0059"</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span>Date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">months</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%m+%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">days</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Births"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deaths"</span>))</span>
<span id="cb1-15"></span>
<span id="cb1-16"></span>
<span id="cb1-17"></span>
<span id="cb1-18">internal_migration_data_for <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(internal_data,</span>
<span id="cb1-19">                                        province,</span>
<span id="cb1-20">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">province_count=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb1-21">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level_date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2010-01-01"</span>)){</span>
<span id="cb1-22">  internal <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Origin=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", province of origin"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>po)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Destination=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography, province of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-25">                                  <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;">setNames</span>(pd,po))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Destination<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Destination, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Origin)) </span>
<span id="cb1-28">  </span>
<span id="cb1-29">  province_levels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span>level_date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(val_norm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>province_count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-34">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-35">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-37">    <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;">"Other provinces"</span>)</span>
<span id="cb1-38">  </span>
<span id="cb1-39">  internal <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-40">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> province_levels <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(Name), </span>
<span id="cb1-41">                          <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other provinces"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-42">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>province_levels)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-43">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Out-migration"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In-migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-44">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Migration<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;">"Out-migration"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm,val_norm)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-45">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Date,Name,Migration) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-46">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-47">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.,Date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-48">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>province)</span>
<span id="cb1-49">}</span>
<span id="cb1-50"></span>
<span id="cb1-51">migration_graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(internal,</span>
<span id="cb1-52">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">migration_colours=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dark2"</span>),</span>
<span id="cb1-53">                              <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;">"Ontario"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saskatchewan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manitoba"</span>,</span>
<span id="cb1-54">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nova Scotia"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other provinces"</span>))){</span>
<span id="cb1-55">  </span>
<span id="cb1-56">  missing_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(internal<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> levels,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(migration_colours))</span>
<span id="cb1-57">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(missing_colours)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb1-58">    migration_colours <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>(migration_colours,</span>
<span id="cb1-59">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Juarez"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(missing_colours)),missing_colours))</span>
<span id="cb1-60">  }</span>
<span id="cb1-61">  migration_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> migration_colours[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(internal<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name)]</span>
<span id="cb1-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(internal,<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>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Name))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-63">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Migration<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;">"Net migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-64">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-65">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Migration<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;">"Net migration"</span>) ,</span>
<span id="cb1-66">              <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>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Province),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inherit.aes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-67">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-68">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brown"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net Migration"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-70">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>migration_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-71">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gross interprovincial migration flows for "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(internal<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Province)),</span>
<span id="cb1-72">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quarterly gross migration flows"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb1-73">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MountainMath, Data: StatCan table 17-10-0045"</span>)</span>
<span id="cb1-74">}</span>
<span id="cb1-75"></span>
<span id="cb1-76">all_migration_data_for <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(internal_data,external_data,</span>
<span id="cb1-77">                                        province,</span>
<span id="cb1-78">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">province_count=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb1-79">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level_date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2010-01-01"</span>)){</span>
<span id="cb1-80">  internal <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-81">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Origin=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", province of origin"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>po)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-82">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Destination=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography, province of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-83">                                  <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;">setNames</span>(pd,po))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-84">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Destination<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-85">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Destination, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Origin)) </span>
<span id="cb1-86">  </span>
<span id="cb1-87">  province_levels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-88">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span>level_date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-89">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-90">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(val_norm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-91">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>province_count,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-92">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Value) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-93">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-94">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-95">    <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;">"Other provinces"</span>)</span>
<span id="cb1-96">  </span>
<span id="cb1-97">  external <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> external_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-98">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GEO<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-99">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, inflows"</span>,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, outflows"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net emigration"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-100">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb1-101">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Origin=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"External"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-102">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Date,Name,Origin,val_norm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-103">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(val_norm))</span>
<span id="cb1-104">  </span>
<span id="cb1-105">  internal <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-106">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> province_levels <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(Name), </span>
<span id="cb1-107">                          <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other provinces"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-108">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>province_levels)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-109">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(external) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-110">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(internal<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Date),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(external<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Date))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-111">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Origin<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>province <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> Name<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;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Out-migration"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In-migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-112">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Migration<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;">"Out-migration"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm,val_norm)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-113">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Date,Name,Migration) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-114">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-115">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.,Date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-116">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>province)</span>
<span id="cb1-117">}</span>
<span id="cb1-118"></span>
<span id="cb1-119">all_migration_graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(migration,</span>
<span id="cb1-120">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">internal_colours=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dark2"</span>),</span>
<span id="cb1-121">                              <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;">"Ontario"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saskatchewan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manitoba"</span>,</span>
<span id="cb1-122">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nova Scotia"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other provinces"</span>)),</span>
<span id="cb1-123">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">external_colours =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(RColorBrewer<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;">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;">"Pastel1"</span>),</span>
<span id="cb1-124">                                                          <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;">"Immigrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Returning emigrants"</span>,</span>
<span id="cb1-125">                                                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net temporary emigrants"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net non-permanent residents"</span>))) {</span>
<span id="cb1-126"></span>
<span id="cb1-127">  </span>
<span id="cb1-128">  missing_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(migration<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> levels,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(internal_colours,external_colours)))</span>
<span id="cb1-129">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(missing_colours)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb1-130">    internal_colours <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>(internal_colours,</span>
<span id="cb1-131">                           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Juarez"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(missing_colours)),missing_colours))</span>
<span id="cb1-132">  }</span>
<span id="cb1-133">  internal_colours <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> internal_colours[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setdiff</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(migration<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Name),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(external_colours))]</span>
<span id="cb1-134"></span>
<span id="cb1-135"></span>
<span id="cb1-136"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(migration,<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>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Name))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-137">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Migration<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;">"Net migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-138">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-139">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Migration<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;">"Net migration"</span>) ,</span>
<span id="cb1-140">              <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>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Province),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inherit.aes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-141">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-142">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 year"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-143">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brown"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net Migration"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-144">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(internal_colours,external_colours)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-145">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gross migration flows for "</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(migration<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Province)),</span>
<span id="cb1-146">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quarterly gross migration flows"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb1-147">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MountainMath, Data: StatCan table 17-10-0045 17-10-0040"</span>)</span>
<span id="cb1-148">}</span>
<span id="cb1-149"></span>
<span id="cb1-150">bc_annual_flows <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;">internal_migration_data_for</span>(internal_data,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-151">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2001-01-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-152">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-153">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration)) </span>
<span id="cb1-154">bc_2023_flows <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_flows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">2023</span>)</span>
<span id="cb1-155"></span>
<span id="cb1-156">bc_annual_external_flows_detail <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> external_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-157">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID<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;">"59"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-158">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-159">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(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;">2022</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-160">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-161">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Components<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Immigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Returning emigrants"</span>,</span>
<span id="cb1-162">                                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net temporary emigration"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, inflows"</span>,</span>
<span id="cb1-163">                                                 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, outflows"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-164">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, outflows"</span>),</span>
<span id="cb1-165">                     <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm,val_norm)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-166">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Components))</span>
<span id="cb1-167"></span>
<span id="cb1-168">bc_annual_external_flows <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_external_flows_detail <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-169">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-permanent residents, outflows"</span>) <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;">"Out-migration"</span>,</span>
<span id="cb1-170">                             <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In-migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-171">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-172">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Migration=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net migration"</span>))</span>
<span id="cb1-173">bc_2023_external_flows <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_external_flows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">2023</span>)</span>
<span id="cb1-174"></span>
<span id="cb1-175">bc_annual_all_flows <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;">all_migration_data_for</span>(internal_data,external_data,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-176">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Date<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2001-01-01"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-177">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-178">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration)) </span>
<span id="cb1-179">bc_2023_all_flows <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_all_flows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">2023</span>)</span>
<span id="cb1-180"></span>
<span id="cb1-181">bc_2023_all_flows_detail <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_external_flows_detail <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">2023</span>)</span></code></pre></div></div>
</details>
</div>
<p>Glossing over some minor issues with this statement<sup>2</sup>, this does not directly relate to the question of people leaving the province. To understand this we need to take a more detailed look at the data.</p>
</section>
<section id="provincial-flow-data" class="level1">
<h1>Provincial Flow Data</h1>
<p>Net interprovincial flows subtract leavers from those arriving. Gross flows can be plotted to look at both streams together and break them out by region as shown in Figure&nbsp;1.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">internal_migration_data_for</span>(internal_data,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(Date&gt;=as.Date("2001-01-01")) |&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration,Name,Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01-01"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">migration_graph</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual gross migration flows"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1970</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</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;">"-01-01"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-bc-interprovincial-migration" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-bc-interprovincial-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-bc-interprovincial-migration-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-bc-interprovincial-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Gross interprovincial migration flows for British Columbia
</figcaption>
</figure>
</div>
</div>
</div>
<p>Interprovincial flows for BC are almost always dominated by what’s happening in Alberta (and usually more about oil prices than housing prices).</p>
<p>When looking more broadly at gross out-flows, we can also incorporate out-flows to other countries. StatCan estimated that 67,994 left BC for other provinces in 2023, with another whopping 134,257 leaving BC for other countries, 115,381 of which were non-permanent residents and 18,876 people emigrated. That’s a lot of people leaving, but there are also a lot of people moving to BC. And those international outflows are more than offset by international inflows as illustrated in Figure&nbsp;2. For simplicity, and for data availability, we are condensing the non-permanent resident flows into net flows.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">bc_annual_all_miration_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;">all_migration_data_for</span>(internal_data,external_data,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration,Name,Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01-01"</span>)))</span>
<span id="cb3-5"></span>
<span id="cb3-6">bc_annual_simple <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_all_miration_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># mutate(Migration=case_when(value&lt;0 ~ "Out-migration",</span></span>
<span id="cb3-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                            TRUE ~ "In-migration")) |&gt;</span></span>
<span id="cb3-9">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Migration)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#%&gt;%</span></span>
<span id="cb3-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#bind_rows(summarize(.,value=sum(value),.by=Year) |&gt; mutate(Migration="Net migration"))</span></span>
<span id="cb3-11"></span>
<span id="cb3-12">bc_2023_simple <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bc_annual_simple <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">2023</span>)</span>
<span id="cb3-13"></span>
<span id="cb3-14">bc_annual_all_miration_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_migration_graph</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual gross migration flows"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1970</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</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;">"-01-01"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-bc-interprovincial-external-migration" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-bc-interprovincial-external-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-bc-interprovincial-external-migration-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-bc-interprovincial-external-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Gross interprovincial and external migration flows for British Columbia
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">natural_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;">get_cansim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0059"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GEO<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;">"British Columbia"</span>,Estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Births"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deaths"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(val_norm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Year,Estimates)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(Estimates<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;">"Births"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> value,</span>
<span id="cb4-6">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Estimates=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net natural"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-01-01"</span>))) </span>
<span id="cb4-9"></span>
<span id="cb4-10">natural_data_2023 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> natural_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year<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;">"2023"</span>)</span></code></pre></div></div>
</details>
</div>
<p>The pandemic effect and subsequent boom in non-permanent resident population<sup>3</sup>, as well as changes to permanent resident quotas, come out much more strongly here. So in total 268,488 people moved to BC in 2023, and 86,870 left BC, for a net increase due to migration of 181,618 people. Rounding this out, because population change is the sum of net migration + births - deaths, we can see that even more 41,019 people were born in BC at the same time that -44,122 died. Looking at only births and deaths leaves us with a net decrease of 3,103. In other words, the “natural population growth” we would see without net migration turned negative in the last couple of years, as shown in Figure&nbsp;3.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">natural_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(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;">1970</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>value)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Estimates),</span>
<span id="cb5-5">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Estimates<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;">"Net natural"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Estimates),</span>
<span id="cb5-7">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,Estimates<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;">"Net natural"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net natural"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brown"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Births"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightblue"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deaths"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"salmon"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Natural population growth in British Columbia"</span>,</span>
<span id="cb5-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual number of people"</span>,</span>
<span id="cb5-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1970</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</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;">"-01-01"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-natural-population-growth" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-natural-population-growth-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-natural-population-growth-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-natural-population-growth-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Natural population growth in British Columbia
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="housing-as-a-reason-for-move" class="level1">
<h1>Housing as a Reason for Move</h1>
<p>Back to housing and moves! Housing has long been one of the most important reasons that people make local moves. But it’s less often considered a reason for longer-distance moves, especially between regions or provinces. We can get a glimpse of this pattern with the “reason for move” data from the Canada Housing Survey. Figure&nbsp;4 shows the reasons people gave for moving within or between cities.<sup>4</sup> Using municipal boundaries isn’t ideal for distinguishing between short moves and long-distance migration, insofar as some metro areas contain lots of municipalities (e.g.&nbsp;Vancouver), mixing short distance moves into our “between city” figure. But we can see the split emerging, with employment a leading reason for “between city” moves, while housing definitely dominates for “within city” moves.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">chs_2021 <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;">get_pumf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CHS"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_pumf_data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rename =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-3"></span>
<span id="cb6-4">var_labels <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_pumf_var_labels</span>(chs_2021) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PPAC_45"</span>,name))</span>
<span id="cb6-6"></span>
<span id="cb6-7">reasons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> var_labels<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>label <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^.+ - "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(n)<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toupper</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(n,<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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(n,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(n)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()</span>
<span id="cb6-11"></span>
<span id="cb6-12">reasons_order <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;">"Employment"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat1"</span>,</span>
<span id="cb6-13">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reduce commuting time"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat1"</span>,</span>
<span id="cb6-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"School"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat1"</span>,</span>
<span id="cb6-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"To be closer to family"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat2"</span>,</span>
<span id="cb6-16">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Form own household"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat2"</span>,</span>
<span id="cb6-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household size change"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat2"</span>,</span>
<span id="cb6-18">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Become homeowner"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat3"</span>,</span>
<span id="cb6-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bigger/better housing"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat3"</span>,</span>
<span id="cb6-20">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"More desirable neighbourhood"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat3"</span>,</span>
<span id="cb6-21">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reduce housing costs"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat4"</span>,</span>
<span id="cb6-22">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Issue with previous landlord/tenants"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat5"</span>,</span>
<span id="cb6-23">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Forced to move"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat5"</span>,</span>
<span id="cb6-24">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Personal health"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat6"</span>,</span>
<span id="cb6-25">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cat6"</span>)</span>
<span id="cb6-26"></span>
<span id="cb6-27">chs_2021 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PPAC_10 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In different city/town..., Indian reserve or outside Canada"</span>,</span>
<span id="cb6-29">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In same city/town/village/township.../Indian reserve"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PPAC_10=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(PPAC_10,</span>
<span id="cb6-31">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Within city"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In same city/town/village/township.../Indian reserve"</span>,</span>
<span id="cb6-32">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Between cities or outside Canada"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In different city/town..., Indian reserve or outside Canada"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-33">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(!grepl("^Outside| - |Territories|Newfoundland and Labrador|Prince Edward Island",PGEOGR)) |&gt;</span></span>
<span id="cb6-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(PPAC_45C<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;">"Not stated"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PPAC_45"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(PFWEIGHT),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(name,value,PPAC_10)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Share=</span>count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(name,PPAC_10)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(value<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;">"Yes"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nn=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(reasons,var_labels<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name)[name] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+ - "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>_)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cat=</span>reasons_order[nn]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nn=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(nn,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(reasons_order))),</span>
<span id="cb6-42">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cat=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(cat,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(reasons_order))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-43">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filter(grepl("employment|homeowner|bigger",nn)) |&gt;</span></span>
<span id="cb6-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Share,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>nn,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>cat)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>PPAC_10) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</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;">"Dark2"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reasons for last move for move within Canada"</span>,</span>
<span id="cb6-50">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of movers giving this reason (multiple allowed)"</span>,</span>
<span id="cb6-51">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reason for last move"</span>,</span>
<span id="cb6-52">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan CHS 2021 PUMF"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-reason-for-last-move" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-reason-for-last-move-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-reason-for-last-move-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-reason-for-last-move-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Reasons given for moving within a municipality or between municipalities, including from abroad. Respondants could give multiple reasons.
</figcaption>
</figure>
</div>
</div>
</div>
<p>It’s worth noting here that moves are pretty common, and mostly positive. That is, people mostly move to somewhere they want to be more than where they used to live. When this flips (as with forced moves) is when we become concerned. Moving to “reduce housing costs” is a bit of an edge case in this categorization.</p>
<p>Interestingly, when we look at the specifics of moving to “reduce housing costs”, the prevalence as a reason for move is similar for within city and between city moves. But it’s important to note that reasons for move clearly overlap (and people could choose multiple reasons for their move). For a given budget, people could think of themselves as moving to a cheaper place both because it offered “homeownership” opportunities, “bigger/better housing” and/or “reduced housing costs”. Overall we get some support for the idea that housing matters for short distance moves and increasingly also for longer-distance ones - even if not quite to the same level. That said, if we focus only on why people chose one particular place to live, we can miss why they didn’t choose other places. Thinking about this at a provincial level, we know lots of people are thinking of leaving BC because of housing costs, but we don’t have good data (beyond anecdotal) about how many people are avoiding coming to BC because of housing costs. We do know, thanks to a <a href="https://www.cbc.ca/news/canada/calgary/poll-canadians-comfortable-living-1.6302361">CBC/Maru study</a> from December of 2021, that BC is most often identified as a province where Canadians would feel “comfortable” living.<sup>5</sup> That suggests a lot of untapped interest in moving to BC. We’re really interested in how much perceived housing costs inhibit people from making the move, and this underlies a great deal of the uncertainty regarding our ability to forecast into the future. How many people would come to BC if we made housing cheaper?</p>
</section>
<section id="metro-areas" class="level1">
<h1>Metro Areas</h1>
<p>Ultimately, people mostly don’t move because they want to live in a particular province. You don’t move to live in BC, but instead to live in or near Vancouver, or Victoria, or Kelowna. Correspondingly, what we’re really interested in when we look at longer distance migration is the metropolitan level.</p>
<p>We’ve actually looked at various claims of people leaving Metro Vancouver a lot over the years <span class="citation" data-cites="lifeblood.2016 lifeblood.2017 millennials-redux.2017">(Lauster 2016; <span class="nocase">von Bergmann</span> 2017a, 2017b)</span> which were mostly the result of poor understanding of data and demographics, and we have also quantified the in and outflows of people from Vancouver and other metro areas. <span class="citation" data-cites="gross-migration.2018 keeping-the-leavers.2020 there-is-no-brain-drain-but-there-might-be-zombies.2019">(<span class="nocase">von Bergmann</span> 2018; <span class="nocase">von Bergmann and Lauster</span> 2020, 2019)</span>. But the notion that lots of people are fleeing Vancouver is remarkably persistent, and often housing costs are thought to be behind the imagined exodus. The recent Angus Reid survey results return us to this notion, but also provide seemingly surprising evidence against it. That is, Metro Vancouver is not the place in BC where most people are thinking of leaving the province over housing costs.</p>
<p>So how does Metro Vancouver compare to other Census Metropolitan Areas (CMAs) in terms of its outflows? Do we see a larger proportion of the population leaving each year than elsewhere? We start by looking at outflows to other parts of Canada, adding in emigrants as a separate category but suppressing the more volatile non-permanent residents.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">pop <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0135"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Sex<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;">"Both sexes"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>val_norm,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>REF_DATE)</span>
<span id="cb7-5"></span>
<span id="cb7-6">pop_new <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0148"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span>val_norm,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>REF_DATE)</span>
<span id="cb7-10"></span>
<span id="cb7-11"></span>
<span id="cb7-12"></span>
<span id="cb7-13">main_provinces <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;">"Ontario"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>)</span>
<span id="cb7-14">other_prairies <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;">"Saskatchewan"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manitoba"</span>)</span>
<span id="cb7-15">atlantic <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;">"Newfoundland and Labrador"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nova Scotia"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New Brunswick"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prince Edward Island"</span>)</span>
<span id="cb7-16"></span>
<span id="cb7-17">outflows_new <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0154"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#summarize(VALUE=sum(VALUE),.by=c(GeoUID,GEO,REF_DATE)) |&gt;</span></span>
<span id="cb7-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(.,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Destination GeoUID</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>GeoUID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-21">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),</span>
<span id="cb7-22">            <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;">"Geography of destination"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO),</span>
<span id="cb7-24">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+/"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,DPR),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,DPR),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(OPR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>DPR <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;">"Same province"</span>,</span>
<span id="cb7-29">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> main_provinces <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> DPR,</span>
<span id="cb7-30">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> other_prairies <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;">"Other prairies"</span>,</span>
<span id="cb7-31">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> atlantic <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;">"Atlantic provinces"</span>,</span>
<span id="cb7-32">                     <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Territories"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Same province"</span>,main_provinces,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other prairies"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic provinces"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Territories"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>)))</span>
<span id="cb7-34"></span>
<span id="cb7-35">outflows <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0141"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-36">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#summarize(VALUE=sum(VALUE),.by=c(GeoUID,GEO,REF_DATE)) |&gt;</span></span>
<span id="cb7-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(.,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Destination GeoUID</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>GeoUID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-39">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(),</span>
<span id="cb7-40">            <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;">"Geography of destination"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO),</span>
<span id="cb7-42">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Geography of destination</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+/"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,DPR),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">DPR=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,DPR),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>,DPR)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(OPR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>DPR <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;">"Same province"</span>,</span>
<span id="cb7-47">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> main_provinces <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> DPR,</span>
<span id="cb7-48">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> other_prairies <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;">"Other prairies"</span>,</span>
<span id="cb7-49">                     DPR <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> atlantic <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;">"Atlantic provinces"</span>,</span>
<span id="cb7-50">                     <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Territories"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Same province"</span>,main_provinces,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Other prairies"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic provinces"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Territories"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>)))</span>
<span id="cb7-52"></span>
<span id="cb7-53"></span>
<span id="cb7-54">components <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0136"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>, Sex<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;">"Both sexes"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Sex) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deaths"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm,</span>
<span id="cb7-59">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> val_norm)) </span>
<span id="cb7-60"></span>
<span id="cb7-61">components_new <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0149"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All ages"</span>, Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Gender) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-64">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deaths"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>val_norm,</span>
<span id="cb7-66">                         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> val_norm)) </span>
<span id="cb7-67"></span>
<span id="cb7-68"></span>
<span id="cb7-69"></span>
<span id="cb7-70">components_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-71">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part, "</span>,GEO),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-72">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-73">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2016</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(pop,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pop),</span>
<span id="cb7-76">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(pop),</span>
<span id="cb7-77">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO,GeoUID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-78">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(pop<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;">150000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^All|^Area|^Canada"</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-79">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-80">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO))</span>
<span id="cb7-81"></span>
<span id="cb7-82">components_new_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> components_new <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-83">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part, "</span>,GEO),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-84">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-85">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</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;">2022</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-86">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(pop_new,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value=</span>value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-88">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lpop=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span>(pop,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by=</span>Year),</span>
<span id="cb7-89">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO,GeoUID,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-90">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(lpop<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;">150000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^All|^Area|^Canada"</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-91">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(value),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span>GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-92">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO))</span>
<span id="cb7-93"></span>
<span id="cb7-94">components_colours <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;">setNames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(RColorBrewer<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;">brewer.pal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dark2"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rev</span>(),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>),outflows_new<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>())</span></code></pre></div></div>
</details>
</div>
<p>Figure&nbsp;5 shows the latest available data, for the July 2021 to 2022 time frame (using 2021 CMA boundaries).</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">outflows_new <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(components_new <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-3">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(outflows_new<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-5">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(outflows_new<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>REF_DATE),<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(VALUE),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(REF_DATE,d,GEO,GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(pop_new,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part, "</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">leaving_rate=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-13">  <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;">leaving_rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(leaving_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>pop),</span>
<span id="cb8-14">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(pop,VALUE),mean),</span>
<span id="cb8-15">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO,d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(leaving_rate),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(pop<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;">150000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cansim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:::</span>short_prov.en,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ontario/Quebec"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ON/CQ"</span>)[province]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Name,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>,Province,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Name,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>total),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>leaving_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(d))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>components_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population leaving metro area 2021/2022 for other parts of Canada"</span>,</span>
<span id="cb8-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(metro areas with at least 150k population)"</span>,</span>
<span id="cb8-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb8-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Province of destination"</span>,</span>
<span id="cb8-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of people leaving metro area 2021/2022"</span>,</span>
<span id="cb8-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Tables 17-10-0154 and 17-10-0148"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-leaving-rates_2021" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-leaving-rates_2021-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-metro-leaving-rates_2021-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-leaving-rates_2021-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Share of population leaving metro area each year for other parts of Canada and emigrants
</figcaption>
</figure>
</div>
</div>
</div>
<p>Metro Vancouver rounds out the major metropolitan areas with the lowest proportion of their populations joining an outflow, at less than 3%. By contrast, other BC metropolitan areas show up in the middle of the distribution (Victoria) and among the most outwardly mobile, exceeding 4% (Abbotsford - Mission and Kelowna). In effect, the cheaper places tend to see more people leave. Single year fluctuations can mask longer trends, so it’s good to also check 5-year averages to smooth out annual bumps. Overall, the July 2016 to 2021 averages (on 2016 CMA boundaries) look quite similar, as shown in Figure&nbsp;6..</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">outflows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(components <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-3">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(outflows<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-5">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(outflows<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>REF_DATE),<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-6">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Emigrants"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VALUE=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(VALUE),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(REF_DATE,d,GEO,GeoUID)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(REF_DATE,<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;">4</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(pop,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GeoUID"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part, "</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">leaving_rate=</span>VALUE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-13">  <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;">leaving_rate=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(leaving_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w=</span>pop),</span>
<span id="cb9-14">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(pop,VALUE),mean),</span>
<span id="cb9-15">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO,d)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(leaving_rate),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(pop<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;">150000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+, "</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cansim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:::</span>short_prov.en,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ontario/Quebec"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ON/CQ"</span>)[province]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,GEO)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Name,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>,Province,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Name,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>total),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>leaving_rate,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(d))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>components_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of population leaving metro area each year for other parts of Canada and emigrants"</span>,</span>
<span id="cb9-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(metro areas with at least 150k population)"</span>,</span>
<span id="cb9-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb9-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Province of destination"</span>,</span>
<span id="cb9-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Share of people leaving metro area (2016-2021 average)"</span>,</span>
<span id="cb9-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Tables 17-10-0141 and 17-10-0135"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-leaving-rates" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-leaving-rates-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-metro-leaving-rates-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-leaving-rates-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Share of population leaving metro area between 2016 and 2021 for other parts of Canada and emigrants
</figcaption>
</figure>
</div>
</div>
</div>
<p>Even averaged over the long-term, people leave Vancouver at relatively low rates compared to other metro areas. Indeed, Vancouver moves into the second spot in terms of retaining its residents, just after Montréal. And if we ignored emigrants Vancouver would take the top spot. This might seem counter-intuitive at first. Why do we hear so much about people leaving Vancouver over housing if so few people are leaving?</p>
<p>Importantly, the people that show up here have generally already found some sort of housing. They might not be happy with it. But Vancouver overall is a nice place to live, so people don’t want to leave. And generally speaking, they don’t. But when they do leave, they make sure we hear about it. And it’s probably increasingly because of housing.</p>
</section>
<section id="migration-by-age-group" class="level1">
<h1>Migration by age group</h1>
<p>Unhappiness with housing in Vancouver tracks pretty well with age. Migration and mobility track with age as well. Unfortunately we don’t have the age breakdown for gross migration flows, but we can look at net migration by age group. Figure&nbsp;7 looks at intra- and inter-provincial net migration for Metro Vancouver.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">d<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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0149"</span>) </span>
<span id="cb10-2"></span>
<span id="cb10-3">ages <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;">get_cansim_column_categories</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"17-10-0149"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age group"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Parent Member ID</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Parent Member ID</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Member Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb10-6"></span>
<span id="cb10-7">d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GeoUID<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;">"933"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Gender<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - gender"</span>,</span>
<span id="cb10-10">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> ages) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net interprovincial migration"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net intraprovincial migration"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>val_norm,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>REF_DATE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span>REF_DATE)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-14">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geom_point(shape=21) +</span></span>
<span id="cb10-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"turbo"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>ages[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(ages),<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)][<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Metro Vancouver net migration by age"</span>,</span>
<span id="cb10-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Period"</span>,</span>
<span id="cb10-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Net migration (number of people)"</span>,</span>
<span id="cb10-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Table 17-10-0149"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-van-net-migration-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-van-net-migration-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-metro-van-net-migration-age-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-van-net-migration-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: Net migration by age group for Metro Vancouver, focusing on intra- and inter-provincial movers
</figcaption>
</figure>
</div>
</div>
</div>
<p>For intraprovincial migration we see a clear trend of declining net migration across all age groups, with on net increasingly more people leaving than arriving from other parts of the province. Metro Vancouver still (just barely) absorbs more young people of university age from around the province than it sends back out. But in all other age ranges, more people leave for other parts of the province than arrive from those parts. The inter-provincial patterns are more volatile, and more driven by economic conditions between the provinces. Looking back at our reasons for moving data, with housing being more important for more local moves and employment related reasons more important for longer distance moves, this is consistent with the notion that housing is increasingly interfering with people’s movements across regions.</p>
<p>Lastly, Figure&nbsp;8 compares net migration patterns by age across selected metro areas for recent time periods.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">components_age_new_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <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;">value=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(value,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm=</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;">.by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,Period,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>value,</span>
<span id="cb11-4">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Components of population growth</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(Period<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;">fct_rev</span>(Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>cat_colours) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Components of population growth"</span>,</span>
<span id="cb11-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb11-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean annual share of population"</span>,</span>
<span id="cb11-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Tables 17-10-0136 and 17-10-0135"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-metro-age-migration" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-metro-age-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-metro-age-migration-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-metro-age-migration-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8: Net migration by age group for select metro areas and time periods.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Here we averaged over (roughly) 5 year periods to smooth out the data and simplify the presentation. Different metro areas show distinct migration patterns, with e.g.&nbsp;Toronto, Vancouver and Montréal showing significant net intra-provincial out-migration (in green), acting as <em>arrival cities</em> for their provinces. All three CMAs also show an increase in net intraprovincial out-migration over time, only somewhat suppressed for young adults ages, likely by the strong pull of their universities.</p>
</section>
<section id="takeaway" class="level1">
<h1>Takeaway</h1>
<p>It’s great to see more data on housing costs as a factor in people’s thinking about moves, especially for longer distances. That said the data can still be tricky to interpret, and “moving to another province”, as in the Angus Reid survey, doesn’t constitute a long move for those living near borders. In conjunction with data on actual moves and reasons given for moves, we can see some support for the idea that housing costs are increasingly driving migration patterns. On the other hand, high housing costs also reflect migration and indicate that people want to live in a place.</p>
<p>Even though really expensive regions, like Metro Vancouver, don’t see that much out-migration, many of the people who do leave likely do so in part for housing reasons. But there are a lot of reasons people move. We should also keep an eye on net migration patterns, insofar as many of the people who would like to come to places like Metro Vancouver are probably feeling shut out by housing costs. It’s hard to get at this directly insofar as we seldom ask everyone about where they’d like to be. But when we do, Canadians often say BC.</p>
<p>And we agree. BC, and particularly Metro Vancouver, is a nice place to live. It’d be even nicer if it was a little more welcoming. Adding more housing is how we get there.</p>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-06-11-migration-and-housing-costs/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-07-11 16:36:34 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb14-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [f15e1f6] 2024-06-26: remove unnecessary images</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<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"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cansim_0.3.17   canpumf_0.2.0   lubridate_1.9.3 forcats_1.0.0  
 [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
 [9] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.5              xfun_0.44                
 [3] htmlwidgets_1.6.4         tzdb_0.4.0               
 [5] vctrs_0.6.5               tools_4.4.0              
 [7] generics_0.1.3            curl_5.2.1               
 [9] parallel_4.4.0            fansi_1.0.6              
[11] RSQLite_2.3.6             blob_1.2.4               
[13] pkgconfig_2.0.3           dbplyr_2.5.0             
[15] RColorBrewer_1.1-3        lifecycle_1.0.4          
[17] git2r_0.33.0              compiler_4.4.0           
[19] farver_2.1.2              munsell_0.5.1            
[21] mountainmathHelpers_0.1.4 htmltools_0.5.8.1        
[23] yaml_2.3.8                pillar_1.9.0             
[25] crayon_1.5.2              cachem_1.1.0             
[27] tidyselect_1.2.1          rvest_1.0.4              
[29] digest_0.6.35             stringi_1.8.4            
[31] labeling_0.4.3            fastmap_1.2.0            
[33] grid_4.4.0                colorspace_2.1-0         
[35] cli_3.6.3                 magrittr_2.0.3           
[37] utf8_1.2.4                withr_3.0.0              
[39] scales_1.3.0              bit64_4.0.5              
[41] timechange_0.3.0          rmarkdown_2.27           
[43] httr_1.4.7                bit_4.0.5                
[45] hms_1.1.3                 memoise_2.0.1            
[47] evaluate_0.23             knitr_1.47               
[49] viridisLite_0.4.2         rlang_1.1.4              
[51] glue_1.7.0                DBI_1.2.3                
[53] xml2_1.3.6                rstudioapi_0.16.0        
[55] vroom_1.6.5               jsonlite_1.8.8           
[57] MetBrewer_0.2.0           R6_2.5.1                 </code></pre>
</div>
</div>
</details>



</section>


<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-lifeblood.2016" class="csl-entry">
Lauster, Nathan. 2016. <em>Is the Lifeblood of Vancouver Leaving?</em> <a href="https://homefreesociology.com/2016/02/12/is-the-lifeblood-of-vancouver-leaving/">https://homefreesociology.com/2016/02/12/is-the-lifeblood-of-vancouver-leaving/</a>.
</div>
<div id="ref-lifeblood.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017a. <em>Lifeblood</em>. <a href="https://doodles.mountainmath.ca/posts/2017-05-16-lifeblood/">https://doodles.mountainmath.ca/posts/2017-05-16-lifeblood/</a>.
</div>
<div id="ref-millennials-redux.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017b. <em>Millennials <span>Redux</span></em>. <a href="https://doodles.mountainmath.ca/posts/2017-08-06-millennials-redux/">https://doodles.mountainmath.ca/posts/2017-08-06-millennials-redux/</a>.
</div>
<div id="ref-gross-migration.2018" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2018. <em>Gross Migration</em>. <a href="https://doodles.mountainmath.ca/posts/2018-08-16-gross-migration/">https://doodles.mountainmath.ca/posts/2018-08-16-gross-migration/</a>.
</div>
<div id="ref-there-is-no-brain-drain-but-there-might-be-zombies.2019" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2019. <em>There Is No <span>Brain</span> <span>Drain,</span> but There Might Be <span>Zombies</span></em>. <a href="https://doodles.mountainmath.ca/posts/2019-02-03-there-is-no-brain-drain-but-there-might-be-zombies/">https://doodles.mountainmath.ca/posts/2019-02-03-there-is-no-brain-drain-but-there-might-be-zombies/</a>.
</div>
<div id="ref-keeping-the-leavers.2020" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2020. <em>Keeping the <span>Leavers</span></em>. <a href="https://doodles.mountainmath.ca/posts/2020-08-27-keeping-the-leavers/">https://doodles.mountainmath.ca/posts/2020-08-27-keeping-the-leavers/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Following an increasingly common practice, the survey was directed at a “representative randomized sample” of members of the <a href="https://www.angusreidforum.com/en-ca/FAQ">Angus Reid Forum</a>, an opt-in set of “engaged adults” organized by demographic criteria and regularly solicited for their opinions in exchange for making their voices “count” and also awards, like <a href="https://www.reddit.com/r/beermoney/comments/l66jqp/canadians_anyone_use_angus_reid_forum/">beer money</a>. We take these results in good faith, but there are <a href="https://www.pewresearch.org/short-reads/2024/03/05/online-opt-in-polls-can-produce-misleading-results-especially-for-young-people-and-hispanic-adults/">reasonable concerns about data from these kind of panels</a>.↩︎</p></li>
<li id="fn2"><p>StatCan estimated that 8,624 more people left BC for other parts of Canada than it gained, which does not round to 8,000. Angus Reid likely took their estimate from annual net inter-provincial migration estimates and did not understand that these are pegged from July 1st 2022 to July 1st 2023, and thus not the same as estimates for the calendar year.↩︎</p></li>
<li id="fn3"><p>There is a lot of misunderstanding about the nature of the increase in non-permanent residents out there, net non-permanent residents acts very differently from e.g.&nbsp;increases in immigration. The data generation process for net non-permanent residents act essentially like a derivative and tends to zero absent of policy changes, but can temporarily rise (or fall) when hiring caps or student visa policies are changed.↩︎</p></li>
<li id="fn4"><p>While municipalities are sometimes similar to metro areas, e.g.&nbsp;Calgary, Edmonton, or Winnipeg, there are important examples where they differ substantially and moves between municipalities are happening at high rates within the same metro area, e.g.&nbsp;Vancouver, Toronto, or Montréal.↩︎</p></li>
<li id="fn5"><p>The <a href="https://www.marugroup.net/public-opinion-polls/canada/living-comfortably-elsewhere">survey of Maru Voice Canada members</a> is structured similarly to the Angus Reid Forum, drawing upon an opt-in on-line panel in a manner meant to reflect the Canadian population as a whole↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{migration-and-housing-costs.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Migration and {Housing} {Costs}},
  date = {2024-06-11},
  url = {https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“Migration and
Housing Costs.”</span> <em>MountainDoodles</em>, accepted, June 11. <a href="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/">https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/</a>.
</div></div></section></div> ]]></description>
  <category>cansim</category>
  <category>canpumf</category>
  <category>affordability</category>
  <category>Vancouver</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/</guid>
  <pubDate>Tue, 11 Jun 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-06-11-migration-and-housing-costs/index_files/figure-html/fig-metro-leaving-rates-1.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>Doubling Up - Distinguishing Families from Households</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/06/04/doubling-up-distinguishing-families-and-households/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>The concepts of <em>family</em> and <em>household</em> frequently get mixed up in the broader housing discourse. We have attempted to explain how these concepts differ, their various statistical constructions, and why it matters in the past. But these explanations can quickly turn quite abstract, so we wanted to complement them by talking about <em>doubling up</em>. This is a very simple way of demonstrating why families and households should not be viewed as interchangeable. We’re also hoping to provide an important reminder that households are malleable and should not be used as the basic unit to analyze housing needs.</p>
<section id="households" class="level1">
<h1>Households</h1>
<p>In Canadian data <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=households-menage007">households are generally defined as</a> “a person or group of persons who occupy the same dwelling and do not have a usual place of residence elsewhere in Canada or abroad.” In short, a household is just an occupied dwelling unit. This is a very broad definition, and includes a wide range of living arrangements, as explained in detail previously. <span class="citation" data-cites="what-s-a-household.2017 housing-outcomes.2023">(<span class="nocase">von Bergmann</span> 2017; <span class="nocase">von Bergmann and Lauster</span> 2023)</span></p>
<p>There are specific cases where we can find different definitions of household. In particular, the household concept in the National Household Economic Accounts series from Statistics Canada <a href="https://www150.statcan.gc.ca/n1/pub/13-607-x/2016001/926-eng.htm">uses the OECD definition of households</a> that only counts people as living in the same household if they share some non-housing expenses, for example for food and transportation. Here more than one household can share the same dwelling. We have looked into the difference between these two concepts before. <span class="citation" data-cites="first-peek-at-population-and-household-data-during-covid-caveats.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021)</span></p>
</section>
<section id="sec-families" class="level1">
<h1>Families (and unattached indvididuals)</h1>
<p>To make things complicated, Statistics Canada also has several definitions of family, in particular that of <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=fam011"><em>economic family</em></a> and of <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=fam004"><em>census family</em></a>. By definition, everyone identified within a census family is also part of an economic family, but the reverse may not be true (e.g.&nbsp;a two-person household with two siblings living together would qualify as an economic family, but not a census family). Either type of family is a subset of a household, but households may contain several families, or additionally house other non-family members, or consist entirely of non-family members. As a corollary to this, census or economic families can occupy at most one dwelling unit.<sup>1</sup></p>
</section>
<section id="datasets" class="level1">
<h1>Datasets</h1>
<p>Families and households are also defined differently across different datasets, and there are also some variations within datasets over time.<sup>2</sup> The Census attempts to capture all individuals in Canada at a specific point in time, the “Census day” in the second week of May, by tracking possible residences, enabling the division of residents into households and families by response. Tax data attempts to capture individuals through tax-filings, assembling them into households and families over the tax year by addresses around April (tax filing day) in the following year, and cross-referenced exemptions claimed. Economic Accounts data draws upon modelling with several inputs. All are known to have undercount issues, but in different ways. We have looked at these coverage issues in detail before. <span class="citation" data-cites="first-peek-at-population-and-household-data-during-covid-caveats.2021">(<span class="nocase">von Bergmann and Lauster</span> 2021)</span> The T1FF taxfiler data draws upon the Census Family concept, while the Economic Accounts match up to the OECD Household concept.</p>
</section>
<section id="comparing-different-ways-to-count-households-and-families" class="level1">
<h1>Comparing different ways to count households and families</h1>
<p>So how do these different conceptualizations of households and families stack up? We can compare different concepts across different data sources. National Economic Accounts data is only available at the provincial geography, so that’s what we choose as the basis of comparison.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">hec_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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"36-10-0101"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-3"></span>
<span id="cb1-4"></span>
<span id="cb1-5">census_households <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;">"CA01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA06"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA21"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(ds) </span>
<span id="cb1-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_census</span>(ds,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</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;">"48"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(ds,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,GeoUID,Year,Households,Dwellings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/.+$| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Change=</span>(Households<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;">lag</span>(Households,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb1-14"></span>
<span id="cb1-15">t1ff <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"11-10-0012"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_refresh =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GEO <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ontario"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>),</span>
<span id="cb1-17">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age of older adult</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total all ages"</span>,</span>
<span id="cb1-18">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Family income</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All income groups"</span>,</span>
<span id="cb1-19">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Family type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Couple families"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lone-parent families"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Persons not in census families"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span>REF_DATE,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span>GEO) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-22">  <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;">Households=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(val_norm),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>)</span>
<span id="cb1-23"></span>
<span id="cb1-24"></span>
<span id="cb1-25">ef <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA21"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_989"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_1001"</span>),</span>
<span id="cb1-26">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_4993"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_5005"</span>),</span>
<span id="cb1-27">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA11"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA11N_2455"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA11N_2479"</span>),</span>
<span id="cb1-28">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA06"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA06_1729"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA06_1829"</span>),</span>
<span id="cb1-29">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA01"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA01_1609"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA01_1613"</span>))</span>
<span id="cb1-30"></span>
<span id="cb1-31"></span>
<span id="cb1-32">cf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA21"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_499"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_531"</span>),</span>
<span id="cb1-33">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_484"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA16_501"</span>),</span>
<span id="cb1-34">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA11"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA11F_110"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA11F_148"</span>),</span>
<span id="cb1-35">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA06"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA06_50"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA06_86"</span>),</span>
<span id="cb1-36">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA01"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fam=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA01_53"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ind=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA01_84"</span>))</span>
<span id="cb1-37"></span>
<span id="cb1-38">census_families <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;">"CA01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA06"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA21"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(ds){</span>
<span id="cb1-40">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_census</span>(ds,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</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;">"48"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span>cf[[ds]]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-41">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(ds,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)))</span>
<span id="cb1-42">    }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,GeoUID,Year,Households,fam,ind) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/.+$| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Households=</span>fam<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>ind) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Change=</span>(Households<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;">lag</span>(Households,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census (census families)"</span>)</span>
<span id="cb1-50"></span>
<span id="cb1-51">economic_families <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;">"CA01"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA06"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA21"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(ds){</span>
<span id="cb1-53">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_census</span>(ds,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR=</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;">"48"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"59"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35"</span>)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span>ef[[ds]]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-54">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(ds,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)))</span>
<span id="cb1-55">    }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,GeoUID,Year,Households,fam,ind) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/.+$| </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Households=</span>fam<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>ind) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-61">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Change=</span>(Households<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;">lag</span>(Households,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Year))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census (economic families)"</span>)</span>
<span id="cb1-63"></span>
<span id="cb1-64"></span>
<span id="cb1-65">pd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(hec_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-66">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", households"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Socio-demographic characteristics</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb1-67">                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta|British|Ontario|Quebec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Socio-demographic characteristics</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb1-68">                         Quintile<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;">"All quintiles"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-69">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Socio-demographic characteristics</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-70">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Change=</span>val_norm<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;">lag</span>(val_norm,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> Date))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-71">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-72">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Socio-demographic characteristics</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Households=</span>val_norm,Change,Year,Date) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-73">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", households"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,Name),</span>
<span id="cb1-74">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household economic accounts"</span>),</span>
<span id="cb1-75">                census_households <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-76">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census (households)"</span>,</span>
<span id="cb1-77">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-05-10"</span>))),</span>
<span id="cb1-78">                t1ff <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T1FF (census families)"</span>,</span>
<span id="cb1-79">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-07-01"</span>))),</span>
<span id="cb1-80">                census_families <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-05-10"</span>))),</span>
<span id="cb1-81">                economic_families <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Date=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Year,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-05-10"</span>)))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-82">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Source=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Source,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Census (households)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household economic accounts"</span>,</span>
<span id="cb1-83">                                         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census (economic families)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Census (census families)"</span>,</span>
<span id="cb1-84">                                         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T1FF (census families)"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-85">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Name,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</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;">"Ontario"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quebec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"British Columbia"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alberta"</span>)))</span>
<span id="cb1-86"></span>
<span id="cb1-87"></span>
<span id="cb1-88"></span>
<span id="cb1-89"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(pd,<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>Date,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>Households,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Name,</span>
<span id="cb1-90">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interaction</span>(Name,Source),</span>
<span id="cb1-91">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Source),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Source))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-92">  <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="cb1-93">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(d)scales<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;">comma</span>(d,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">suffix=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-94">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>sanzo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>quads<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c252) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-95">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-96">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household and family unit estimates"</span>,</span>
<span id="cb1-97">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of households or family units"</span>,</span>
<span id="cb1-98">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb1-99">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>,</span>
<span id="cb1-100">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>,</span>
<span id="cb1-101">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2001-2021, Table 36-10-0101, 11-10-0012"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-households-families-timeline-comparison" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-households-families-timeline-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-households-families-timeline-comparison-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-households-families-timeline-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Comparing census household counts, National Economic Accounts household estimates, economic family as well as census family and unattached individuals counts from the census, and the census families and unattached individuals derived from T1FF data.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;1 shows how these different sources compare over time at the provincial level. As expected, there are more census family units than economic families or OECD households, and more OECD households than census households. There are also generally more T1FF census family units than seen in the Census, though this varies by province.<sup>3</sup>. We can compare how varying estimates of families and household compare to the underlying estimate for number of dwellings, keeping in mind that households, by definition, cannot exceed dwellings.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">pd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2001</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;">5</span>),</span>
<span id="cb2-3">         Source <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;">"Household economic accounts"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strftime</span>(Date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m"</span>)<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;">"07"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>((.) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Source<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;">"Census (households)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Name,Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CensusDwellings=</span>Dwellings),</span>
<span id="cb2-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Name"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio=</span>Households<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>CensusDwellings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Year,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>ratio<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>,</span>
<span id="cb2-8">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Source))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodge"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span>MetBrewer<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;">met.brewer</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Egypt"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Name)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Household and family unit estimates in excess of census dwelling counts"</span>,</span>
<span id="cb2-14">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess percentage over census dwelling counts"</span>,</span>
<span id="cb2-15">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb2-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source"</span>,</span>
<span id="cb2-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2001-2021, Table 36-10-0101, 11-10-0012"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-households-families-ratio-comparison" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-households-families-ratio-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-households-families-ratio-comparison-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-households-families-ratio-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Difference of census household counts, National Economic Accounts household estimates, economic families and unattached individuals from the census, census family and unattached individuals counts from the census and the same derived from T1FF data, compared to census dwelling counts.
</figcaption>
</figure>
</div>
</div>
</div>
<p>For census years Figure&nbsp;2 takes the dwelling counts as a baseline and checks how these measures of households and families and unattached individuals differ from the census dwelling counts. There are differences in the timing during the year these estimates are taken, which may cause some variation. But overall we still get a good overview of how these measures differ, and a pointer toward how simple metrics that compare households to dwellings might fall short.</p>
</section>
<section id="metro-level-data" class="level1">
<h1>Metro level data</h1>
<p>Housing is inherently local, so it’s useful to take these estimates to the metro level. The Household Economic Accounts don’t break down their estimates at the metro level, so we will have to drop the estimates of OECD households. Moreover, metro areas change over time which makes clean temporal comparisons more complicated, and we will skip historical variation in the following analysis by focusing in on data from the 2021 Census, with the understanding that this misses census under-counts. This is also the most recent data available. The T1FF data for 2022 will become available later this summer, but isn’t out yet. Sticking with the census has the added advantage of providing ready dwelling and household estimates.</p>
<section id="families-and-unattached-individuals-vs-households" class="level2">
<h2 class="anchored" data-anchor-id="families-and-unattached-individuals-vs-households">Families (and unattached individuals) vs households</h2>
<p>A simple measure of the difference between family units and households is the ratio of families and unattached individuals to households. As discussed above this ratio can’t be less than 1 since by census definition no family unit can live in more than one household. This ratio measures the amount of <em>doubling up</em> in a region; i.e.&nbsp;how many family units are sharing residence where we might expect them not to?</p>
<p>Families may also encode some kinds of doubling up, for example adult children still living with parents are generally counted as being part of the census family. Families may also use more than one dwelling unit, for example when family members temporarily occupy dwelling units in other jurisdictions for work purposes. We set these issues aside for now, but will revisit adult children living with parents later.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">census_family_children <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0134"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(GEO<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;">"Canada"</span>,</span>
<span id="cb3-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Gender (3a)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Gender"</span>,</span>
<span id="cb3-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Household type of person (10)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Household type of person"</span>,</span>
<span id="cb3-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Census family status and household living arrangements (11)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Children in census families"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,GEO,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Census year (3)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group (11)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Value=</span>VALUE) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 34 years"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35 to 44 years"</span>))</span>
<span id="cb3-9"></span>
<span id="cb3-10">doubling_data_canada <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">C=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01"</span>),</span>
<span id="cb3-11">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Families=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_499"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Individuals=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_531"</span>))</span></code></pre></div></div>
</details>
</div>
<p>Importantly, this is not meant to be a prescriptive measure. From the perspective of people living together, <em>doubling up</em> may be desirable, tolerated, or stressful. There’s nothing to keep people from living together when it’s desirable for them to do so. But for those at best tolerating <em>doubling up</em> with others, it is useful to keep track of prevalence. Canada wide there are 14,978,941 households vs 10,262,925 census families and 6,850,005 unattached individuals, so on average there are 2,133,989 (14%) more families and unattached individuals than households. Additionally in 2021 in Canada there were 1,253,600 children between the ages of 25 and 44 living with their parents.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">provinces <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list_census_regions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(level<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;">"PR"</span>)</span>
<span id="cb4-2">province_levels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> provinces <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(name)</span>
<span id="cb4-3">doubling_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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">C=</span><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;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,</span>
<span id="cb4-4">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Families=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_499"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Individuals=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_531"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR_UID=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<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;">2</span>),</span>
<span id="cb4-7">         <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(provinces <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PR_UID=</span>region,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span>name),<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;">"PR_UID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Province,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span>province_levels)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Province=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_recode</span>(Province,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prince Edward Island"</span>,</span>
<span id="cb4-11">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Newfoundland and Labrador"</span>,</span>
<span id="cb4-12">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New Brunswick"</span>,</span>
<span id="cb4-13">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Atlantic"</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nova Scotia"</span>,</span>
<span id="cb4-14">                             ))</span>
<span id="cb4-15">doubling_data_canada <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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">C=</span><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;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regions"</span>,</span>
<span id="cb4-16">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Families=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_499"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Individuals=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_531"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Name=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(.+</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))</span>
<span id="cb4-18"></span>
<span id="cb4-19">doubling_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(doubling_data_canada) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<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;">100000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>(Families<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Individuals)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Households<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#pivot_longer(c(Families,Individuals)) |&gt;</span></span>
<span id="cb4-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Name,gap),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</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;">"Dark2"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Doubling up in Canada"</span>,</span>
<span id="cb4-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess share of families and unattached individuals relative to households"</span>,</span>
<span id="cb4-30">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb4-31">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-census-household-families" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-census-household-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-census-household-families-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-census-household-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Doubling up rates in Canadian metro areas. Doubling up rates are estimated as the excess ratio of families and unattached individuals to households.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Our <em>doubling up</em> measure here, excess families and unattached individuals to households, is highest in Abbotsford, Toronto, and Vancouver, and lowest across Quebec. But this need not be the only measure we use. Rather than looking at households to benchmark measures of doubling up, we can also look directly at housing stock. That is, what’s the ratio of census families and unattached individuals to dwellings? This misses things like frictional vacancies, which are necessary for residential mobility, and it also glosses over temporarily occupied homes when people work in a different location for some time, or other kinds of vacancies like vacation homes. This also does not take into account census under-counts, which <a href="https://www.statcan.gc.ca/en/hp/estima">was estimated at about 1,201,000, or 3.25% of the population, in the 2021 census</a> and typically skews toward unattached individuals (suggesting we’re still likely underestimating doubling up). But it offers a more direct measure of <em>doubling up</em> as it might relate to housing shortages.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">doubling_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(doubling_data_canada) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<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;">100000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>(Families<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Individuals)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Dwellings<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Name,gap),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</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;">"Dark2"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Doubling up in Canada"</span>,</span>
<span id="cb5-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess share of families and unattached individuals relative to dwellings"</span>,</span>
<span id="cb5-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb5-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-census-dwellings-families" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-census-dwellings-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-census-dwellings-families-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-census-dwellings-families-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Doubling up rates in Canadian metro areas. Doubling up rates are estimated as the excess ratio of families and unattached individuals to dwellings.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Once again, Abbotsford, Toronto, and Vancouver top the doubling up measure, while Quebec rounds out the bottom. Here we added a dashed line indicating the <em>doubling up</em> measure we would expect to see if every family and unattached individual lived on their own and each metro area had a (fairly tight) 3% rate of homes being vacant.<sup>4</sup> It should not surprise that no region achieves that expectation. After all, it is likely that some people find it desirable to double up, preferring to e.g.&nbsp;live with roommates even if they had the option to live alone. But we may still be missing a lot of people who would prefer to live alone. Let us return to adult children living with parents.</p>
</section>
<section id="adult-children-living-with-parents" class="level2">
<h2 class="anchored" data-anchor-id="adult-children-living-with-parents">Adult children living with parents</h2>
<p>Adult children living with parents are still considered part of census families, but we might want to break them out, on the assumption that they too may be only tolerating (at best) their housing situation. We restrict ourselves to adult children aged 25 to 34. This is the age range when adult children most clearly attain adulthood (and an expectation of independence), as opposed to those under 25, for instance, who might still be attending school or just starting in their careers. By contrast, adult children living with parents at later ages (35+) might start to reflect caretaking situations where elderly parents move back in with their children. These cutoffs are chosen to be conservative in our expectations, but extending to e.g.&nbsp;include 35-39 year olds living with parents won’t move things much as the share of children living with parents drops off quickly with age. For comparison with closely related academic concepts, see <span class="citation" data-cites="ermisch1985minimal">Ermisch and Overton (1985)</span>, or our discussion elsewhere concerning the Canadian context. <span class="citation" data-cites="housing-outcomes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023)</span> If we include adult children 25 to 34 living with parents in our measure of doubling up, what does it look like?</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">adult_children <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;">get_cansim_sqlite</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"98-10-0134"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Gender (3a)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Gender"</span>,</span>
<span id="cb6-3">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Census year (3)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,</span>
<span id="cb6-4">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Age group (11)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"25 to 34 years"</span>),</span>
<span id="cb6-5">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Census family status and household living arrangements (11)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Children in census families"</span>,</span>
<span id="cb6-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Household type of person (10)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total - Household type of person"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">collect_and_normalize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disconnect=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">short_id=</span>GeoUID,GEO,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Children=</span>VALUE)</span>
<span id="cb6-9"></span>
<span id="cb6-10"></span>
<span id="cb6-11">doubling_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(doubling_data_canada) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">short_id=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(adult_children,<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;">"short_id"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<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;">100000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>(Families<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Individuals<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Children)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Dwellings<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Name,gap),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>gap,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill=</span>Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"identity"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</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;">"Dark2"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.value=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>percent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Doubling up in Canadian metro areas"</span>,</span>
<span id="cb6-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess share of families, unattached individuals,</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">and children aged 25 to 34 living with parents relative to dwellings"</span>,</span>
<span id="cb6-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb6-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021, Table 98-10-0134"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-census-dwellings-families-adult-children" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-census-dwellings-families-adult-children-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-census-dwellings-families-adult-children-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-census-dwellings-families-adult-children-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Doubling up rates in Canadian metro areas. Doubling up rates are estimated as the excess ratio of families and unattached individuals, plus adult children aged 25 to 34 living with parents to dwellings.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The addition of children 25-34 living with parents increases our estimates of doubling up substantially, and also slightly rearranges our ordering. In particular, Oshawa sidles up next to Toronto in between Abbotsford and Vancouver at the top. More movements can be observed in the middle, where, e.g.&nbsp;Calgary surpasses Nanaimo. But Quebec still rounds out the bottom, with the least amount of doubling up.</p>
<p>We might ask ourselves what causes these variations in doubling up. An obvious candidate is the cost of housing. In particular, we would expect a lot more people who don’t desire <em>doubling up</em> to nevertheless adopt it as a strategy in places with severe housing shortages. Figure&nbsp;6 explores this by plotting doubling-up rates against Census data on average rents.</p>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">rent_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;">get_census</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2021"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">regions=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">C=</span><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;">level=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CMA"</span>,</span>
<span id="cb7-2">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectors=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">median_rent=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_4317"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">average_rent=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"v_CA21_4318"</span>))</span>
<span id="cb7-3"></span>
<span id="cb7-4">dd<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>doubling_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(doubling_data_canada) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">short_id=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(GeoUID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(GeoUID))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(adult_children,<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;">"short_id"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Population<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;">100000</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"part"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Region Name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gap=</span>(Families<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Individuals<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Children)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>Dwellings<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(rent_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GeoUID,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matches</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rent"</span>)),<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;">"GeoUID"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">excess=</span>Families<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Individuals<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>Children<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Dwellings)</span>
<span id="cb7-12"></span>
<span id="cb7-13">fit.lm<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;">lm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(gap)<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;">log</span>(average_rent),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>dd)</span>
<span id="cb7-14"></span>
<span id="cb7-15">dd <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>gap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>average_rent,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span>Province)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-17">  <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="cb7-18">  ggrepel<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_text_repel</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label=</span>Name),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb7-19">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min.segment.length=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span>,</span>
<span id="cb7-20">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toronto|Vancouver|Montr|Qué|Cal|Edmon|Otta"</span>,Name))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-21">  <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><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula=</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>\(x)scales<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;">percent</span>(x<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span>scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>dollar,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trans=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-24">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ggConvexHull::geom_convexhull(aes(fill=Province),alpha=0.25,colour=NA) +</span></span>
<span id="cb7-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Doubling up in Canadian metro areas"</span>,</span>
<span id="cb7-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Excess share of families, unattached individuals,</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">and children aged 25 to 34 living with parents</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">relative to dwellings (log scale)"</span>,</span>
<span id="cb7-27">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average rent (log scale)"</span>,</span>
<span id="cb7-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"StatCan Census 2021, Table 98-10-0134"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-rent-doubling-up" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rent-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-rent-doubling-up-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rent-doubling-up-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Comparison of average rents to doubling up rates in Canadian metro areas. Doubling up rates are estimated as the excess ratio of families and unattached individuals, plus adult children aged 25 to 34 living with parents to dwellings.<sup>5</sup>
</figcaption>
</figure>
</div>
</div>
</div>
<p>This confirms that there is indeed a strong relationship. In particular, we’re likely picking up the relationship to housing cost for those people doubling up as an adaptive response (rather than a strong desire). More people tolerate (and experience stress from) <em>doubling up</em> as housing markets become more expensive.</p>
<p>But there are also some noticeable outliers that suggest that other factors are at play too. Income is one factor we’re not controlling for here, and possibly distinct cultural preferences is another. There could be important variation in who finds doubling up desirable. A more careful analysis would also look at turnover rents instead of overall stock rents, as turnover rents are more important in preventing household formation. Trying to control for other features of rental units, e.g.&nbsp;number of bedrooms and ideally location within the metro area, would also be useful.</p>
<p>Unfortunately, more sophisticated approaches quickly run into data availability issues and also complicate the analysis. At this point the simple relationship is a good starting point. And we believe it is informative regarding the main causal mechanism behind differences in doubling up rates across Canadian metro areas. This somewhat naive but broadly informative relationship suggests that a 1% increase in rents leads to a roughly 2.4% increase in doubling up rates. It likely also leads to an increase in net out-migration, but the size of this effect is difficult to identify.</p>
<p>An interesting question is how this relationship has evolved over time, and we have a working paper on this topic we hope to release soon.</p>
</section>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>In the context of housing discussions in Canada (and elsewhere) households are often assumed as fixed. But households are malleable. Given underlying familial relationships, how people distribute into households is impacted by prevailing housing pressures. Understanding the interplay between rents (or prices) and household formation gives important insights:</p>
<ul>
<li>Household-based measures of housing stress, like core housing need or shelter cost to household income ratios, paint a biased picture of housing pressures and need to be treated cautiously when informing policy. In particular, these metrics are ill-suited for housing targets aimed at undoing harms of housing scarcity insofar as they are blind to doubling up (and to housing-induced changes in migration).</li>
<li>There is no path to lower rents without building more housing to accommodate the households that would form in response. This also visualizes an important part of what it means to slide down the demand curve as supply increases: New households form in response to lower prices and rents. Many of these new households will form out of pre-existing households, moving out of doubled up situations. Others, not fully addressed here, will form from in-movers, or simply remain from families and individuals who otherwise would have left the region.</li>
<li>As a more general point we regularly return to, this provides another example of how and why it’s important to pay close attention to the metrics used, and to carefully examine how they fit into one’s conceptual and explanatory frameworks.</li>
</ul>
<p>As usual, the code for this post is <a href="https://github.com/mountainMath/mountain_doodles/blob/main/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index.qmd">available on GitHub</a> for anyone to reproduce or adapt for their own purposes.</p>
<details>
<summary>
Reproducibility receipt
</summary>
<div class="cell">
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## datetime</span></span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "2024-06-04 16:05:30 PDT"</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## repository</span></span>
<span id="cb10-2">git2r<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;">repository</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Local:    main /Users/jens/R/mountain_doodles
Remote:   main @ origin (https://github.com/mountainMath/mountain_doodles.git)
Head:     [ff0fda4] 2024-06-04: recompile</code></pre>
</div>
<details class="code-fold">
<summary>&lt;code&gt;</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Session info</span></span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sessionInfo</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cansim_0.3.17   cancensus_0.5.7 lubridate_1.9.3 forcats_1.0.0  
 [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
 [9] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.5              xfun_0.43                
 [3] htmlwidgets_1.6.4         ggrepel_0.9.5            
 [5] lattice_0.22-6            tzdb_0.4.0               
 [7] vctrs_0.6.5               tools_4.4.0              
 [9] generics_0.1.3            curl_5.2.1               
[11] parallel_4.4.0            fansi_1.0.6              
[13] RSQLite_2.3.6             blob_1.2.4               
[15] pkgconfig_2.0.3           Matrix_1.7-0             
[17] RColorBrewer_1.1-3        dbplyr_2.5.0             
[19] lifecycle_1.0.4           git2r_0.33.0             
[21] compiler_4.4.0            farver_2.1.2             
[23] munsell_0.5.1             mountainmathHelpers_0.1.4
[25] htmltools_0.5.8.1         yaml_2.3.8               
[27] pillar_1.9.0              crayon_1.5.2             
[29] cachem_1.0.8              nlme_3.1-164             
[31] tidyselect_1.2.1          rvest_1.0.4              
[33] digest_0.6.35             stringi_1.8.4            
[35] splines_4.4.0             labeling_0.4.3           
[37] fastmap_1.1.1             grid_4.4.0               
[39] colorspace_2.1-0          cli_3.6.2                
[41] magrittr_2.0.3            utf8_1.2.4               
[43] withr_3.0.0               scales_1.3.0             
[45] bit64_4.0.5               timechange_0.3.0         
[47] rmarkdown_2.26            httr_1.4.7               
[49] bit_4.0.5                 sanzo_0.1.0              
[51] hms_1.1.3                 memoise_2.0.1            
[53] evaluate_0.23             knitr_1.46               
[55] mgcv_1.9-1                rlang_1.1.3              
[57] Rcpp_1.0.12               glue_1.7.0               
[59] DBI_1.2.2                 xml2_1.3.6               
[61] rstudioapi_0.16.0         vroom_1.6.5              
[63] jsonlite_1.8.8            MetBrewer_0.2.0          
[65] R6_2.5.1                 </code></pre>
</div>
</div>
</details>



</section>


<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-ermisch1985minimal" class="csl-entry">
Ermisch, John F, and Elizabeth Overton. 1985. <span>“Minimal Household Units: A New Approach to the Analysis of Household Formation.”</span> <em>Population Studies</em> 39 (1): 33–54.
</div>
<div id="ref-what-s-a-household.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2017. <em>What’s a <span>Household?</span></em> <a href="https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/">https://doodles.mountainmath.ca/posts/2017-12-01-what-s-a-household/</a>.
</div>
<div id="ref-vacancy-rate-and-rent-change.2018" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2018. <em>Vacancy Rate and Rent Change</em>. <a href="https://doodles.mountainmath.ca/posts/2018-11-28-vacancy-rate-and-rent-change/">https://doodles.mountainmath.ca/posts/2018-11-28-vacancy-rate-and-rent-change/</a>.
</div>
<div id="ref-vacancy-rates-and-rent-change-2021-update.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens</span>. 2022. <em>Vacancy Rates and Rent Change, 2021 Update</em>. <a href="https://doodles.mountainmath.ca/posts/2022-02-18-vacancy-rates-and-rent-change-2021-update/">https://doodles.mountainmath.ca/posts/2022-02-18-vacancy-rates-and-rent-change-2021-update/</a>.
</div>
<div id="ref-first-peek-at-population-and-household-data-during-covid-caveats.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021. <em>First <span>Peek</span> at <span>Population</span> and <span>Household</span> <span>Data</span> <span>During</span> <span>COVID</span> &amp; <span>Caveats</span></em>. <a href="https://doodles.mountainmath.ca/posts/2021-11-28-first-peek-at-population-and-household-data-during-covid-caveats/">https://doodles.mountainmath.ca/posts/2021-11-28-first-peek-at-population-and-household-data-during-covid-caveats/</a>.
</div>
<div id="ref-housing-outcomes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023. <em>Housing <span>Outcomes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/">https://doodles.mountainmath.ca/posts/2023-08-17-housing-outcomes/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>This relates to the <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=pop126#">usual place of residence concept</a> that will count family members who temporarily live elsewhere, be it for work or for study purposes, at their <em>usual place of residence</em> instead of their current place of residence where they are counted as <em>temporarily present persons</em>.↩︎</p></li>
<li id="fn2"><p>We’ll mostly set historical variations in definitions aside, but see <a href="https://www12.statcan.gc.ca/census-recensement/2021/ref/98-500/002/98-500-x2021002-eng.cfm">Census Reference Materials</a> for details. Keeping track of these changes can be consequential for making historical comparisons.↩︎</p></li>
<li id="fn3"><p>This tracks with T1FF estimates generally running a little higher than census estimates. Variations from T1FF to Census may reflect in part the later date benchmarking of T1FF data, but can also be determined by varying coverage rates, see <a href="https://www150.statcan.gc.ca/n1/pub/72-212-x/2023001/sect1-eng.htm">more details from Statistics Canada</a>↩︎</p></li>
<li id="fn4"><p>While the choice of the vacant home rate at 3% was influenced by the observation that a 3% rental vacancy rate as measured by CMHC is generally viewed as balanced, associated with flat real rents, <span class="citation" data-cites="vacancy-rate-and-rent-change.2018 vacancy-rates-and-rent-change-2021-update.2022">(<span class="nocase">von Bergmann</span> 2018, 2022)</span> the rental vacancy rate does not include homes that are vacant but rented out and not moved in yet, or still rented but already moved out. A more realistic overall rate of vacant homes at a fixed point in time for a balanced market is <a href="https://www.lincolninst.edu/publications/policy-focus-reports/empty-house-next-door">generally taken considerably higher</a>.↩︎</p></li>
<li id="fn5"><p>On the y-axis we plot the log of the ratio, but label it as excess percentage.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{doubling-up-distinguishing-families-from-households.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Doubling {Up} - {Distinguishing} {Families} from
    {Households}},
  date = {2024-06-04},
  url = {https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“Doubling Up -
Distinguishing Families from Households.”</span>
<em>MountainDoodles</em>, accepted, June 4. <a href="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/">https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/</a>.
</div></div></section></div> ]]></description>
  <category>cansim</category>
  <category>cancensus</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/</guid>
  <pubDate>Tue, 04 Jun 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-06-04-doubling-up-distinguishing-families-from-households/index_files/figure-html/fig-rent-doubling-up-1.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Zoned Capacity - promise and pitfalls</title>
  <dc:creator>Jens von Bergmann</dc:creator>
  <dc:creator>Nathan Lauster</dc:creator>
  <link>https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/</link>
  <description><![CDATA[ 






<p style="text-align:center;">
<i>(Joint with Nathan Lauster and cross-posted at <a href="https://homefreesociology.com/2024/05/31/zoned-capacity-promise-and-pitfalls/" target="_blank">HomeFreeSociology</a>)</i>
</p>
<p>Is there room for new housing? There are lots of ways to try and get at this question, driven by a variety of different value calculations (e.g.&nbsp;if you need housing you might look around and see room for more of it everywhere, but if you’re well-housed and like your neighbourhood just the way it is, then you might think there’s no room at all). But this can also be transformed into a technical question, where we can pin a definition down to potential methods for making more room. Here’s where we start to talk about planning concepts, including zoned capacity. Is there room for new housing in municipal planning practices and regulations?</p>
<p>BC has recently joined a host of other jurisdictions in passing a requirement that municipalities plan for housing needs, ideally making a lot more room for housing. In BC’s case this means planning for 20 years worth of growth required to meet housing needs. The calculation of housing need is, itself, a complicated endeavour, and we’re not convinced anyone is doing it quite right yet. But here we want to talk a bit about the planning side. If you have a number representing housing need to work toward, what does it mean to plan for that number?</p>
<p>As initially passed by the province, <a href="https://www.leg.bc.ca/parliamentary-business/legislation-debates-proceedings/42nd-parliament/4th-session/bills/progress-of-bills">Housing Statutes Bill 44</a>, Part 11 added Section 473.1 to the Local Government Act to require that “the statements and map designations included in an official community plan of the council of a municipality must provide for at least the 20-year total number of housing units required to meet anticipated housing needs, which total number is included in the most recent housing needs report.” Part 13 similarly added Section 481.7 to require municipal zoning by-laws to “permit the use and density of use necessary to accommodate at least the 20-year total number of housing units required to meet the anticipated housing needs, which total number is included in the most recent housing needs report received.” The bill further explained, in adding section 481.8, that “a zoning by-law must not establish conditional density rules for the purpose of achieving the minimum number of housing units required to be permitted.” Part 33 adds sections 565.08 and 565.09 to the City of Vancouver’s Charter with identical language. Later bills, including <a href="https://www.leg.bc.ca/Pages/BCLASS-Legacy.aspx#%2Fcontent%2Fdata%2520-%2520ldp%2Fpages%2F42nd5th%2F3rd_read%2Fgov16-3.htm">Bill 16</a> and <a href="https://www.leg.bc.ca/Pages/BCLASS-Legacy.aspx#%2Fcontent%2Fdata%2520-%2520ldp%2Fpages%2F42nd5th%2F3rd_read%2Fgov18-3.htm">Bill 18</a> from 2024, have further amended the Housing Statutes related to these acts (including requiring Vancouver to develop an OCP), but do not appear to have fundamentally altered their meaning. But what is their meaning? Aspects remain unclear. Moreover, as of this post, these parts of the bill have not yet been incorporated into the consolidated <a href="https://www.bclaws.gov.bc.ca/civix/document/id/complete/statreg/r15001_14#section481">Local Government Act</a> or <a href="https://www.bclaws.gov.bc.ca/civix/document/id/complete/statreg/vanch_28#section565.07">Vancouver Charter</a> (both purportedly current to April 24, 2024). This may be because they are not yet in force. According to the <a href="https://news.gov.bc.ca/releases/2023HOUS0171-001945">provincial timeline</a> laid out by BC, June/July of 2024 will bring “guidance provided to municipalities to update Official Community Plans and zoning bylaws.” By Jan 1, 2025, “local governments must have completed their interim Housing Needs Report.” And due by by Dec 31, 2025: “municipalities update of their Official Community Plans and zoning bylaws (based on the interim Housing Needs Report).”</p>
<p>Both <em>Planned Capacity</em> and <em>Zoned Capacity</em> provide ways of defining the municipal planning side. Though still distinct, these terms have become increasingly connected insofar as rezonings that fit with Official Community Plans <a href="https://www2.gov.bc.ca/gov/content/governments/local-governments/planning-land-use/local-government-planning/engagement-on-local-planning-land-use/public-hearings">no longer go through City Council hearings</a>. But <a href="https://council.vancouver.ca/20240423/documents/r1-staffpresentation.pdf">“zoned capacity”</a> is the way that the City of Vancouver has understood the task set for them by the province, building upon a contentious history of the term in local politics and their historical lack of an OCP. Effectively, this should translate into how much room for new housing has been opened up within current zoning. If there isn’t twenty years worth of anticipated housing need in there, then zoning needs to be modified so that more room for housing is opened up. But the devil is in the details, and when it comes to zoning, there are a LOT of details. Let’s take a closer look. In so doing, we’ll explore the concept a bit more in-depth, consider how conditions matter, add an estimate of the City of Vancouver’s zoned capacity that we did as part of the Metro Vancouver Zoning Project, and review the recent history of how the term <em>zoned capacity</em> has been used in Vancouver housing discussions.</p>
<section id="why-do-we-care-about-zoned-capacity" class="level1">
<h1>Why do we care about zoned capacity?</h1>
<p>Zoning has a complicated history, but it was initially marketed as a tool to direct and “rationally” manage growth - especially for the benefit of an emerging white middle class - rather than constrain or sharply limit growth. Correspondingly, the idea was that there should always be ample “zoned capacity” within existing zoning to enable growth. Zoning would direct developers where to go to build housing, but leave plenty of room overall for supply to meet demand.<sup>1</sup></p>
<p>At some point a growing city will run out of zoned capacity as it gets used up, at which point the city needs to rezone to make more land, or height, or bulk, available for housing. Indeed, the planner Harland Bartholomew, hired by the City of Vancouver in the late 1920s to draft its first consolidated zoning plan, predicted his plan would only hold until around 1960. In effect, he thought he’d planned for about 30 years worth of housing need. Then the city would have to rezone to allow for more density. This is effectively what Vancouver started doing in many places after modernizing its zoning code in 1956 – right before the City turned around and downzoned many neighbourhoods in the mid-1970s. <span class="citation" data-cites="bartholomew-s-dot-density.2021 a-brief-history-of-vancouver-planning-development-regimes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2021, 2023a)</span></p>
<p>This all-too-brief history raises four characteristics of zoned capacity as a concept that are worth touching upon, and also speak to why we care about it.</p>
<ol type="1">
<li>Zoned Capacity has important and long-known regulatory effects</li>
<li>There are time lags that change these effects and challenge their observation</li>
<li>Regulatory effects operate simultaneously at multiple scales</li>
<li>Underlying regulations are complex and the capacity they create is tricky to define in practice</li>
</ol>
<p>Harland Bartholomew was able to predict the need for updating and changing zoning over time based upon growth projections. In effect, he predicted that pressure from growth would rise over time as it bumped up against the constraints of his plan. With enough growth, it would become important to reconfigure the plan. In this, we can envision his plan as working something like a steam engine tank. We’ve long known it’s important how big that tank might be.</p>
<p>Just like it takes a little while for steam to build up in an engine, there are time lags to the effects of zoning constraints. If there’s enough room for growth in initial planning, then effects will be localized and overall pressure will be hard to detect. But as zoned capacity overall gets used up, the pressure rises everywhere contained by the code. Attributing this pressure back to the underlying regulation (specifying the size of our steam tank) can be challenged by the passage of time between observing the effects of pressure and onset of the zoning code. Putting this back in economics terms: the ability of supply to meet rising demand (a.k.a. supply elasticity) becomes increasingly constrained by zoning capacity in ways we shouldn’t expect to be stable over time, even though (and especially if) the underlying zoning code and map hasn’t changed at all. That boils over into rapidly rising prices.</p>
<p>To further complicate matters, the pressure produced by zoning codes isn’t just limited to the neighbourhoods directly affected by them, or even the municipalities contained by the zoning bylaw overall. Instead, pressure is felt regionally, across municipalities, over a relatively integrated metropolitan housing market. It can even touch neighbouring metropolitan areas. This pressure is a systemic effect, layered over top of variation in code specifics at the local level.</p>
<p>Zoning codes and their interactions with planning are notoriously complicated, tending to grow more so over time. Indeed, Bartholomew’s development plan for the City of Vancouver WAS his zoning code. Since then, development plans have been layered over top of zoning codes, with the idea zoning might be progressively changed to enable plans (with the right contributions in place from developers). Meanwhile, zoning codes have become both increasingly technical and restrictive at the same time they’ve become riddled with conditional permissions. This makes it really difficult to define zoned capacity at any single point in time, let alone study how it changes over time.</p>
<p>So we’ve long known zoned capacity is really important. The province is putting this knowledge into action by requiring municipalities to do the work Bartholomew suggested they’d need to do about a century ago. But it’s also become really difficult to observe and measure zoned capacity, setting aside carefully linking its effects to market forces of supply and demand.</p>
<p>We can’t address all of these issues here, but we want to think a bit more about the complexity of measuring zoned capacity (point four above). What exactly should be considered “zoned capacity”? How can it be quantified, and how much is “enough” to allow for a given estimate of housing need, or (even better) for organic growth in response to demand? These are important questions that the province is trying to hammer out with municipalities right now. We will try to give some preliminary answers of our own through the following sections.</p>
</section>
<section id="what-is-zoned-capacity-a-closer-look." class="level1">
<h1>What is zoned capacity? – A closer look.</h1>
<p>At a simple level, zoning spells out what can be built where. For residential uses, our main concern, zoning spells out where residential uses are allowed and how much housing can be built down to the lot level. Aggregated across lots, <strong>zoned capacity</strong> is the difference of how much housing is allowed to be built in the city by the zoning bylaw compared to the housing that currently exists. “How much housing” already raises an interesting measurement question: are we interested in residential floor space? Number of bedrooms? Or number of dwellings? Different aspects of zoning code have something to say to each metric.</p>
<p>As we turn to exploring the metric for specific municipalities, starting with Vancouver, we add further complexity. As noted above, neighbourhood plans in Vancouver frequently differ from zoning. Moreover, the zoning bylaw distinguishes between <strong>outright zoning</strong>, developments that the zoning bylaw allows to proceed by building permit, and <strong>conditional zoning</strong> developments that the zoning bylaw may or may not allow (typically through development permit) but don’t require a rezoning. “Conditional” zoning in Vancouver is often highly discretionary. A prominent example in Vancouver is <a href="https://bylaws.vancouver.ca/zoning/zoning-by-law-district-schedule-c-2.pdf">C-2 zoning</a>, which makes up much of the commercial strips along Vancouver’s arterials. It allows a list of specified commercial uses (e.g.&nbsp;bowling alleys and retail stores) outright, but dwelling uses are only conditionally allowed, after the Director of Planning or the Development Permit Board first reviews:</p>
<ul>
<li>the intent of the zoning Schedule and all applicable policies and guidelines adopted by Council; and</li>
<li>the submission of any advisory group, property owner or tenant.</li>
</ul>
<p>While the maximum amount of housing the Director of Planning may allow is clearly spelled out in the schedule, the actual amount of housing that can reasonably be expected on a given parcel is far less clear. It might change over time as council changes guidelines, and it also depends on neighbourhood feedback. Established developers with a good relation to planners and tight grasp on neighbourhood dynamics may have a pretty good idea of what they can expect to be able to build. Outside developers with little experience in Vancouver may misjudge a specific site’s development potential.</p>
<p>For estimating <em>zoned capacity</em> this creates the challenge that it’s uncertain what level of discretionary density can be achieved on a given site, and Vancouver rarely allows the maximum discretionary density to actually be constructed. <span class="citation" data-cites="what-if-recent-apartment-buildings-in-vancouver-were-20-taller.2024">(<span class="nocase">von Bergmann and Lauster</span> 2024)</span> It also creates problems for cross-jurisdictional comparisons with jurisdictions where conditional zoning or density bonus schemes are encoded in bylaws and are predictable.</p>
</section>
<section id="estimating-zoned-capacity-in-vancouver" class="level1">
<h1>Estimating Zoned capacity in Vancouver</h1>
<p>To make this uncertainty concrete, we can take a look at zoned capacity estimates in Vancouver that we did in conjunction with the <a href="https://zoning.sociology.ubc.ca">Metro Vancouver Zoning Project</a>, summarized in Figure&nbsp;1. Here we focused on residential floor space. Our estimates are based on 2020 zoning data, so they do not reflect the recent changes to allow for multiplexes. They also require access to BC Assessment roll data to get a detailed understanding of current use, and this data is unfortunately not openly available.<sup>2</sup> We express zoned capacity in terms of additional floor space allowed under current zoning and distinguished between outright and maximum conditional zoning to show the range of what might be allowed. Of note, the highly discretionary nature makes it difficult to distinguish which properties it may apply to, so we took the broadest possible approach and assumed that conditional zoning could be applied to all properties within each respective zone. Most of the additional zoned capacity in 2020 existed in RS and RT zones. It could be realized by tearing down smaller houses and replacing them with larger ones, probably adding more bedrooms, but generally very little in the way of more dwellings.</p>
<div id="fig-cov-zoned-capacity-overview" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cov-zoned-capacity-overview-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/images/cov_zoned_capacity.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cov-zoned-capacity-overview-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Zoned capacity in the City of Vancouver, estimated in 2022 before the multiplex zoning came into effect that expands the capacity in RS and RT zones.
</figcaption>
</figure>
</div>
<p>Were no new dwellings possible? If we consider theoretical maximum conditional zoning this adds considerable zoned capacity to low density zoning by allowing laneway houses and potential secondary suites, as well as highly discretionary density bonusing schemes that often rely on vague notions of “character” and aren’t available on all sites. The <a href="https://bylaws.vancouver.ca/zoning/zoning-by-law-district-schedule-r1-1.pdf">R1-1 multiplex zoning</a> that came into effect after our estimates were done adds further conditional zoned capacity in terms of both dwellings (4-plex to 8-plex) and floor space.</p>
<p>On the larger-scale multi-family side we note that there is virtually no outright zoned capacity, and in fact a considerable amount of negative zoned capacity. Negative zoned capacity reflects the existence of non-conforming buildings that have a higher overall density than what current outright or conditional zoning allows. Some of these buildings pre-date the 1970s downzonings, others pre-date zoning altogether.</p>
<p>Setting these aside, there is some outright zoned capacity that our modelling could not account for. BC Assessment does not consistently keep data on floor area of rental buildings, and we have dropped rental buildings without information on existing floor area from the analysis. In most cases there was little zoned capacity available for these under existing zoning, but in some cases there were smaller footprint 3 storey rental buildings that could, conditionally, be torn down and replaced by slightly larger rental buildings without having to change zoning.</p>
<p>Most of the multi-family conditional zoned capacity exists in C-2 zones that conditionally allow for residential uses. To activate this requires redevelopment of the existing (mostly commercial) uses, and the conditional zoned capacity reflects the maximum allowable without changing the zoning, even if in practice this is rarely achieved. Some of the zoned capacity also exists within existing mixed use developments that have a residential component but do not achieve the full maximal conditional density.</p>
<p>In Figure&nbsp;2 we provide further context by mapping zoned capacity of each parcel zoned for outright or conditional residential use in the City of Vancouver. The map illustrates how most capacity sits along arterials within Commercial zones.</p>
<div id="fig-cov-zoned-capacity-map" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cov-zoned-capacity-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/images/cov_zoned_capacity_map.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cov-zoned-capacity-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Map of parcel level zoned capacity in the City of Vancuver, estimated in 2022 before the multiplex zoning came into effect that expands the capacity in RS and RT zones.
</figcaption>
</figure>
</div>
<p>This view into the City of Vancouver zoned capacity opens up several questions on how zoned capacity might be useful. Zoned capacity generally requires teardown and redevelopment to unlock, although <a href="https://de.wikipedia.org/wiki/Aufstockung_(Architektur)">Aufstockung</a>, the addition of storeys onto an existing building roughly translatable as “upstacking”, is in theory an alternative option. In practice economics and building engineering severely constrain the application of this strategy.</p>
</section>
<section id="zoned-capacity-and-development-outcomes" class="level1">
<h1>Zoned capacity and development outcomes</h1>
<p>If we make room for more housing, will it get built? This is really important for linking zoned capacity to meeting housing need. And once again, the details matter here. If new zoned capacity adds more floor space without allowing for more dwellings (as has often been the case with single-family zones), then you probably won’t house many more people, perhaps just richer people. Other aspects of zoning codes (e.g.&nbsp;maximum heights, minimum setbacks, lot coverage rules, bedroom mix rules, minimum dwelling size, etc.) can also limit how much new housing gets added. Similarly, other policies (e.g.&nbsp;view corridors, non-market overlays, etc.) can alter the way zoning codes work to limit, or sometimes increase housing densities.</p>
<p>Development outcomes also respond to a variety of forces beyond municipal codes, of course. To (overly) simplify what’s likely to get built, it’s helpful to think in terms of developers making sequential assessments as per:</p>
<ol type="1">
<li>What lots are for sale? (<em>available capacity</em>)</li>
<li>What can be built on those lots? (<em>zoned capacity</em>)</li>
<li>Is it worth it to build there? (<em>viable capacity</em>)</li>
</ol>
<p>Even if zoned capacity gets added to a lot, it won’t matter for development outcomes unless the lot’s current owner either a) puts it up for sale, or b) partners up with a developer or takes on the role themselves. In practice, most developments involve a sale. <span class="citation" data-cites="teardowns_data_story.2017">(<span class="nocase">von Bergmann and Dahmen</span> 2017)</span> And there are many reasons why a property owner may not want to sell a property, even if the property is worth more as a redevelopment site than in its current use. It may be a single family home that the current owner lives in and does not want to move out of. It may be an investment or commercial property that generates a satisfactory steady income stream and the transaction friction is too high to trigger a sale. Owner decisions on the sale of properties are highly idiosyncratic.</p>
<p>Even if zoned capacity gets added to a lot, it won’t matter for development outcomes if the anticipated profit from redevelopment doesn’t make it worthwhile for a developer to take on. To calculate whether it’s worthwhile, developers typically write up a “pro forma” that pulls together their perceptions of residential demand (achievable sales prices and rents) with the likely costs involved in financing the purchase of the lot, construction, and getting their project through permissions. Since these can be difficult to estimate, risk assessments also have to be built in to costs. The numbers don’t always make it worthwhile, even when anticipated profit is less important (as for non-profit developers).</p>
<p>In practice, our simplified sequence is actually a bit more complicated. Developers often specialize in certain types of developments, and may as a first step seek out lots where these types are allowed to start looking for sales there, checking each sale for viability of redevelopment (2-1-3). If zoned capacity is tight speculative behaviour might emerge, where developers look at viability of redevelopment first and snap up likely sites when they go up for sale, speculating about the potential for upzoning in the future (3-1-2). Of note, these speculative behaviours can be avoided by providing ample zoned capacity, and providing it in location where housing demand is high, thus reducing the potential profit from as well as the need for speculation. New Zealand regulation, for instance, explicitly requires a <em>competitive buffer</em> be built into zoned capacity to keep land markets from tightening up and reduce speculation. <span class="citation" data-cites="nz_policy.2022">(Ministry of Housing and Urban Development 2022)</span></p>
<p>Overcoming the inherent complexity to estimate the likely sale of a property for redevelopment requires a relatively sophisticated model, potentially informed by past data on property transactions and models of property values under current as well as redeveloped use, combined with pro formas incorporating redevelopment costs. (e.g. <span class="citation" data-cites="terner_redevelopment.2022">Romem (2022)</span> or <span class="citation" data-cites="bc_ssmuh_toa.2023"><span class="nocase">von Bergmann et al.</span> (2023)</span>).</p>
<p>Despite this complexity, a few takeaways are worth pointing out. In general, the more additional zoned capacity is added on a given site, the greater the possible profit to redevelopment. The greater the number of lots with additional zoned capacity, the more likely you are to get sales that lead to redevelopment. Similarly, the greater the number of lots with additional zoned capacity, the less competition between developers to buy those lots, driving down the price of land as an input to development. By contrast, concentration of additional zoned capacity across a narrow range of lots works in the opposite direction, driving up developer competition for the possible profit, inducing speculation, and driving up land as an input to development. Lack of zoned capacity forces developers to either turn elsewhere to build housing, or to engage in riskier, lengthier, and more expensive negotiations to rezone properties, driving down development overall.</p>
<p>With this understanding we return to our central question, what’s the minimal amount of zoned capacity for the housing market to function fairly freely? A reasonable answer might be to take one-and-a-half to two full development cycles as a minimum timeline, and take an estimate of the existing housing shortfall plus housing required for anticipated demand growth, as the basis for projection. This tells us how much housing we expect to get built in an unrestricted market. To be safe we want to take upper ends of the confidence intervals on the housing estimates. For the housing market to function freely we will want to add in a <em>competitiveness margin</em> to ensure that developers aren’t bidding up prices by having to compete for the same land. The appropriate size of this margin is difficult to rationalize, looking at what others have done we note that New Zealand chose 20%. <span class="citation" data-cites="nz_policy.2022">(Ministry of Housing and Urban Development 2022)</span> This would then be the minimum amount of economically viable and likely available zoned capacity to ensure a freely functioning housing market.</p>
</section>
<section id="recent-development-by-zoning-type-in-vancouver" class="level1">
<h1>Recent Development by Zoning Type in Vancouver</h1>
<p>Drawing from our work codifying zoning codes up to 2020, we can take a look at how development has unfolded within the City of Vancouver, as well as some of its surrounding municipalities. Where has new multi-family housing gone by zone?</p>
<p>In accordance with our estimates of zoned capacity, there was practically no outright zoned capacity left for multi-family housing in the City of Vancouver (upper left corner). Low-rise and high-rise zoning meant to support multi-family housing was effectively all used up for development by 1991. Conditional zoned capacity for housing remained for lots within Commercial zones, and these have been intensively developed since 1991, coded as Mixed Low-Rise and Mixed High-Rise below. But most housing built since 1991 has been constructed on individually tailored rezoned properties, the most uncertain, time-consuming, and expensive pathways to redevelopment, coded as Comprehensive Development (CD) below. The same pattern of a shift to rezonings in response to declining zoned capacity for multi-family housing is also evident across the region, showing up clearly in Burnaby, Surrey, New Westminster, North Vancouver, White Rock, and even Langley. Richmond and Coquitlam have so far bucked the trend toward rezoning, but still show increasing reliance upon placing new housing in mixed-use commercial developments.</p>
<div id="fig-multi-fam-zone-age" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-multi-fam-zone-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/images/multi-family_by_zone_age.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-multi-fam-zone-age-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Multi-family housing by zone and decade of construction in select Metro Vancouver municipalities
</figcaption>
</figure>
</div>
<p>What about single-family lots? Recent provincial legislation was intended to enable multiplexes by right across most urban areas of the province. It’s not yet clear how this will be implemented by municipalities, and there are signs many will attempt to do as little as possible to add more zoned capacity in this way. In the meantime, we can look at how low-density housing developers have responded to floor space constraints within the zoning code over time. Here, too, there is evidence that they have increasingly built as much floor space as the City allowed, reaching zoned capacity for each lot without generally adding much in the way of new dwellings.</p>
<div id="fig-fsr-gfa" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-fsr-gfa-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/images/fsr_gfa_vancouver_sfh.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-fsr-gfa-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: FSR and Gross Floor Area of (surviving) single family homes in the City of Vancouver and Maple Ridge by year built
</figcaption>
</figure>
</div>
</section>
<section id="estimating-zoned-capacity-for-20-years-of-housing-need" class="level1">
<h1>Estimating Zoned Capacity for 20 Years of Housing Need</h1>
<p>Let’s return to our central question. How do we add enough room for housing to meet housing needs? In particular, how do we get enough zoned capacity to insure we’re meeting at least twenty years of housing need, assuming we have a working estimate of housing need?</p>
<p>There remain a variety of technical obstacles in estimating zoned capacity and how it could be operationalized for planning purposes. One obstacle is sorting outright from conditional uses in establishing what counts as zoned capacity. BC’s legislation has seemingly forbid “conditional density” from counting, that is density enabled conditional on provision of benefits to the City in exchange (a.k.a. density bonusing). But that leaves open the possibility that other conditional zoning, like with the City of Vancouver’s Commercial zoning, might still count, potentially still requiring multi-unit housing to continue to go through lengthy, uncertain, and expensive negotiations and development permitting processes before approval. Another obstacle is remaining uncertainty over whether zoned capacity will lead to development. And unfortunately recent history is a poor guide here, especially insofar as for many Metro Vancouver municipalities, the majority of development has not been enabled via outright or even conditional zoning, but rather reactive spot rezoning via Comprehensive Development, which makes it difficult to learn about development patterns moving forward from historical data.</p>
<p>While it’s tricky and complicated in practice, what we can do here is at least list the ingredients needed to estimate zoned capacity in a way that’s useful for planning purposes. To know if you have enough zoned capacity to meet a particular estimate of housing need would require:</p>
<ul>
<li>Zoning data that’s properly coded for the understanding what can be built on each lot. In principle municipalities have such data, although our work on the <a href="https://zoning.sociology.ubc.ca">Metro Vancouver Zoning Project</a> has shown that it’s much less clear if it’s coded in a form that’s legible and comparable.</li>
<li>Data on the existing use of the property. In theory this is available from the BC Assessment Authority, but in practice there are issues, for example most purpose-built rental buildings don’t have information on the existing square footage of the building.</li>
<li>A model of likelihood of sale of current properties. This can be idiosyncratic, as noted above, but could be built on a history of transactions, and possibly weighted by the development option (see below).</li>
<li>A model of property values under current use. A shortcut to this may rely on assessed values from BC Assessment, but it might need adjusting if property markets move quickly or in cases like purpose-built rental buildings where assessments are based on the income approach instead of resale value.</li>
<li>A model of values of potential redeveloped use. This is a bit more complex as it requires a model able to estimate the value of a hypothetical property that does not yet exist. Not just on one particular site but on every site across the city. The difference between the value of the existing use and the hypothetical redeveloped use is the development option. This is not dissimilar from the work that has been done modelling the potential provincial SSMUH and TOA impacts in BC. <span class="citation" data-cites="bc_ssmuh_toa.2023">(<span class="nocase">von Bergmann et al.</span> 2023)</span></li>
<li>A model that takes the economically viable zoned capacity together with likely sales, the development option and historical redevelopment data to estimate the likelihood of development of economically viable zoned capacity. This is the only way to get at whether enough capacity has been zoned to enable meeting estimated needs.</li>
<li>In the case of existing shortages that are to be reduced, a model of how supply effects impact prices and economic viability given expectations about demand, which recursively flows back into previous points in a way enabling calculation across twenty years of expected development.</li>
</ul>
<p>In summary, it will be very challenging to arrive at useful estimates of zoned capacity for planning purposes in BC. From a technical perspective, the main missing ingredient is accurate information on zoning, the other parts have in principle been done in BC for other work. <span class="citation" data-cites="bc_ssmuh_toa.2023">(<span class="nocase">von Bergmann et al.</span> 2023)</span> From a practical perspective the fact that some of the underlying essential data, namely property roll and sale data, is locked up provides a challenge that prevents efficient and open analysis. This amplifies concerns that there may not be enough expertise within municipalities to carry out these estimates in a reasonable way. Centralizing zoned capacity estimates within the province could be more useful, especially if facilitated by reform providing a provincial template for consistent zoning codes that municipalities could pick and choose from as they seek to reach housing need targets. It remains unclear why our province needs thousands and thousands of different zones while e.g.&nbsp;Japan, a country with 25 times the population of BC, is doing fine with just 12. And probably more important than just making it easier to understand zoned capacity, provincial or national zoning codes would increase certainty and transparency, reduce costs to build housing and increase competition in the developer market.</p>
<p>Of note, we have dealt mostly with the complexity of estimating zoned capacity. As laid out in earlier sections, zoned capacity also works at a lag and operates across multiple scales. The lag is effectively built into provincial requirements to plan ahead for twenty years, but there is little justification as to why this is the best way to think about lagged effects. Ideally zoned capacity is constantly being reevaluated, leaving lots of excess room to accommodate growth in response to shifting demand. The issue of how zoned capacity relates to multiple scales also remains. In particular, while zoned capacity is estimated (and controlled) at the municipal level, we expect its effects to be felt across regional levels. This is also an issue plaguing estimation of housing needs, of course. Neighbouring municipalities clearly affect each other in ways that are difficult to disentangle to assign individualized housing need targets or the zoned capacities required to meet them.</p>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>Recent legislation in BC correctly places lack of zoned capacity as an important cause of our housing crisis, and looks to reform how it works. In this, the province is clearly aiming at moving planning from what we’ve called our current spot-discretionary regime back into a planning for growth regime.<sup>3</sup> Requiring municipalities to estimate their zoned capacities and fix them to 20 years of housing need has been joined to SSMUH and TOA legislation. SSMUH legislation in theory challenges the exclusion of multiplexes from low density zones, adding outright zoned capacity. At the same time the TOA legislation attempts to add capacity for development around transit stations, but the implementation details and if and how this flows into zoning have largely been left to municipalities.</p>
<p>The province also gave municipalities tools to allow them to actually zone for the development they want instead of relying on rezonings in order to extract financial or in kind contributions from developers going beyond DCC/DCLs, and they have created legislation that supports implementing tenant relocation policies at the Development Permit stage of the process instead of having to rely on rezonings for this. Additionally they have streamlined the rezoning process for projects that are compliant with community plans to remove some discretion.</p>
<p>When moving back toward the planning for growth regime, the concept of zoned capacity becomes useful again. And the province is incorporating zoned capacity back into planning processes. But given the history of spot-discretionary planning in some parts of BC with heavy reliance on discretionary planning processes, the checkered history of the usage of the term in Vancouver in particular, and the technical difficulties in usefully operationalizing this concept, it will likely be a bumpy road. Indeed, <a href="https://vancouver.ca/files/cov/provincial-housing-targets-report-oct-2023-mar-2024-council-presentation.pdf#page=9">Vancouver is having a hard time</a> even meeting very cautious and short-term housing approval targets. It makes sense for the province to continue a strategy of consultation with municipalities, but we suggest there are some red flags to be raised over leaving implementation to municipalities. That’s both because a) many municipalities appear to be actively working against the intent of the provincial legislation, and b) even if they weren’t, it has become very difficult for them to do the technical work required to estimate either their housing needs or their zoned capacity. To put it more succinctly, there’s still a devil at work in the municipal response, and that devil is all too likely to appear in the details, even where municipalities are doing their best to keep it out.</p>
</section>
<section id="appendix---recent-usage-of-the-term-zoned-capacity-in-the-city-of-vancouver" class="level1">
<h1>Appendix - recent usage of the term “zoned capacity” in the City of Vancouver</h1>
<p>The usefulness of the concept of zoned capacity hinges on the way development is carried out. With the downzoning in the mid-70s the City of Vancouver transitioned into the spot-discretionary planning regime and started to increasingly rely on one-off spot zoning and discretionary conditional zoning for growth. In this planning regime zoned capacity was reduced to a minimum in order to control development. The (former) RS and to some extent the RT zones where secondary suites and laneway houses could be added, if often conditionally, offered a bit more of a nod to zoned capacity. But overall the shift to a spot-discretionary regime fatally compromised the very concept of zoned capacity, and discussions around zoned capacity in the City of Vancouver have accordingly become confused and erratic. Neither council, nor staff, nor the general public seem to have a clear understanding how to approach the concept.</p>
<p>Zoned capacity estimates by staff, pegged at October 1996 and <a href="https://council.vancouver.ca/980205/PE3.HTM">discussed in a report to council in 1998</a>, do try to estimate build-out under existing zoning, but also include development potential they envision on sites that currently have no zoning for residential use in place. (And projections of how much population growth can be accommodated are hopelessly naive and certain to generate severe housing shortages if taken at face value. <span class="citation" data-cites="planning-for-scarcity.2022">(<span class="nocase">von Bergmann and Lauster</span> 2022)</span>)</p>
<p>In the years that followed, council often tried and failed to get zoned capacity estimates: (<a href="https://council.vancouver.ca/20110118/documents/regu20110118min.pdf">Woodsworth Tuesday, January 18, 2011</a>) (<a href="https://council.vancouver.ca/20120214/documents/cfsc8.pdf">Motion by Councillor Carr February 14, 2012</a>) (<a href="https://council.vancouver.ca/20200527/documents/pspc4.pdf">Motion by Councillor Hardwick</a>).</p>
<p>The starting point of the broader public <strong>zoned capacity</strong> discussions was probably a consultant report from 2014 that <a href="https://council.vancouver.ca/20150624/documents/ptec4.pdf">showed up in an administrative council report in the June 2, 2015 council meeting</a>, as well as the <a href="https://vancouver.ca/files/cov/CAC-coriolis-consulting-final-report-april-2019.pdf">2019 follow-up report</a>. Here we won’t comment on the report, and how it handled the question and tried to identify causal system-wide effects of CACs, but direct attention to the zoned capacity estimates in the report being based on staff estimates that explicitly include developments in principle contemplated in community plans with no actual zoning in place to support them. As source for estimates, the report cites the City of Vancouver, breaking out the following <strong>Development Potential</strong> reproduced in Table&nbsp;1.</p>
<div class="cell">
<div id="tbl-development-capacity-2014" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-development-capacity-2014-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Remaining Development Potential by Type of Capacity in the City of Vancouver (to 2041)
</figcaption>
<div aria-describedby="tbl-development-capacity-2014-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
 

  
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tinytable_biqpikr2qynxhtlbli83</title>
    <style>
.table td.tinytable_css_y0hgr0tuqioq8yed8nl3, .table th.tinytable_css_y0hgr0tuqioq8yed8nl3 {    border-bottom: solid 0.1em #d3d8dc; }
.table td.tinytable_css_yw949ni0mf4u7ez55kt9, .table th.tinytable_css_yw949ni0mf4u7ez55kt9 {  width: 87.5%;  }
.table td.tinytable_css_595j2aswshdd40pwrzeh, .table th.tinytable_css_595j2aswshdd40pwrzeh {  width: 12.5%;  }
    </style>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script>
    MathJax = {
      tex: {
        inlineMath: [['$', '$'], ['\\(', '\\)']]
      },
      svg: {
        fontCache: 'global'
      }
    };
    </script>
  

  
    <div class="container">
      <table class="table table-borderless" id="tinytable_biqpikr2qynxhtlbli83" style="table-layout: fixed; width: 80% !important; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        
              <tr>
                <th scope="col">Type</th>
                <th scope="col">Units</th>
              </tr>
        </thead>
        <tfoot><tr><td colspan="2">Source: City of Vancouver</td></tr></tfoot>
        <tbody>
                <tr>
                  <td>Capacity in Existing Multifamily Zoning Districts                 </td>
                  <td>25,700</td>
                </tr>
                <tr>
                  <td>Capacity in Recently Approved CD-1 Districts (approved since 2009)</td>
                  <td>15,137</td>
                </tr>
                <tr>
                  <td>Capacity in ODPs, Community Plan Areas, and Policy Statement Areas</td>
                  <td>35,420</td>
                </tr>
                <tr>
                  <td>Total                                                             </td>
                  <td>76,257</td>
                </tr>
        </tbody>
      </table>
    </div>

    <script>
      function styleCell_tinytable_g7lden61s7b2fjm5f964(i, j, css_id) {
        var table = document.getElementById("tinytable_biqpikr2qynxhtlbli83");
        table.rows[i].cells[j].classList.add(css_id);
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_biqpikr2qynxhtlbli83');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_tinytable_g7lden61s7b2fjm5f964(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_biqpikr2qynxhtlbli83");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }

window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(0, 0, 'tinytable_css_y0hgr0tuqioq8yed8nl3') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(0, 1, 'tinytable_css_y0hgr0tuqioq8yed8nl3') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(0, 0, 'tinytable_css_yw949ni0mf4u7ez55kt9') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(1, 0, 'tinytable_css_yw949ni0mf4u7ez55kt9') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(2, 0, 'tinytable_css_yw949ni0mf4u7ez55kt9') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(3, 0, 'tinytable_css_yw949ni0mf4u7ez55kt9') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(4, 0, 'tinytable_css_yw949ni0mf4u7ez55kt9') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(0, 1, 'tinytable_css_595j2aswshdd40pwrzeh') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(1, 1, 'tinytable_css_595j2aswshdd40pwrzeh') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(2, 1, 'tinytable_css_595j2aswshdd40pwrzeh') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(3, 1, 'tinytable_css_595j2aswshdd40pwrzeh') })
window.addEventListener('load', function () { styleCell_tinytable_g7lden61s7b2fjm5f964(4, 1, 'tinytable_css_595j2aswshdd40pwrzeh') })
    </script>

  


</div>
</div>
</figure>
</div>
</div>
<p>The <a href="https://vancouver.ca/files/cov/CAC-coriolis-consulting-final-report-april-2019.pdf">2019 report</a> on the same topic updates the estimates of Development Potential, shown in Table&nbsp;2 and again attributed to the City of Vancouver, and while it walks back some of the more egregious conclusions found in the first report, it still struggles with basic economics.</p>
<div class="cell">
<div id="tbl-development-capacity-2019" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-development-capacity-2019-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Remaining Development Potential to 2041 by Type of Capacity in the City of Vancouver
</figcaption>
<div aria-describedby="tbl-development-capacity-2019-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
 

  
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tinytable_e1kd5a8y205o8v0clcbl</title>
    <style>
.table td.tinytable_css_pepcdho9txiim1x0ax0c, .table th.tinytable_css_pepcdho9txiim1x0ax0c {    border-bottom: solid 0.1em #d3d8dc; }
.table td.tinytable_css_h6gv12b7tm59td7zgamo, .table th.tinytable_css_h6gv12b7tm59td7zgamo {  width: 87.5%;  }
.table td.tinytable_css_eg2r0cqugg2jg14iygeq, .table th.tinytable_css_eg2r0cqugg2jg14iygeq {  width: 12.5%;  }
    </style>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script>
    MathJax = {
      tex: {
        inlineMath: [['$', '$'], ['\\(', '\\)']]
      },
      svg: {
        fontCache: 'global'
      }
    };
    </script>
  

  
    <div class="container">
      <table class="table table-borderless" id="tinytable_e1kd5a8y205o8v0clcbl" style="table-layout: fixed; width: 80% !important; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        
              <tr>
                <th scope="col">Type</th>
                <th scope="col">Units</th>
              </tr>
        </thead>
        <tfoot><tr><td colspan="2">Source: City of Vancouver; Note these figures are the City’s estimate of residential capacity by zone to 2041; there is additional residential capacity beyond 2041 in these zones.</td></tr></tfoot>
        <tbody>
                <tr>
                  <td>Estimated capacity in Existing Multifamily Zoning Districts                                          </td>
                  <td>43,100</td>
                </tr>
                <tr>
                  <td>Estimated capacity in Recently Approved CD-1 Districts (approved since 2009), net of unit completions</td>
                  <td>5,725 </td>
                </tr>
                <tr>
                  <td>Estimated capacity in ODPs, Community Plan Areas, and Policy Statement Areas                         </td>
                  <td>46,388</td>
                </tr>
                <tr>
                  <td>Total                                                                                                </td>
                  <td>95,213</td>
                </tr>
        </tbody>
      </table>
    </div>

    <script>
      function styleCell_tinytable_ookqizclqa48asm7thle(i, j, css_id) {
        var table = document.getElementById("tinytable_e1kd5a8y205o8v0clcbl");
        table.rows[i].cells[j].classList.add(css_id);
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_e1kd5a8y205o8v0clcbl');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_tinytable_ookqizclqa48asm7thle(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_e1kd5a8y205o8v0clcbl");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }

window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(0, 0, 'tinytable_css_pepcdho9txiim1x0ax0c') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(0, 1, 'tinytable_css_pepcdho9txiim1x0ax0c') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(0, 0, 'tinytable_css_h6gv12b7tm59td7zgamo') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(1, 0, 'tinytable_css_h6gv12b7tm59td7zgamo') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(2, 0, 'tinytable_css_h6gv12b7tm59td7zgamo') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(3, 0, 'tinytable_css_h6gv12b7tm59td7zgamo') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(4, 0, 'tinytable_css_h6gv12b7tm59td7zgamo') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(0, 1, 'tinytable_css_eg2r0cqugg2jg14iygeq') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(1, 1, 'tinytable_css_eg2r0cqugg2jg14iygeq') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(2, 1, 'tinytable_css_eg2r0cqugg2jg14iygeq') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(3, 1, 'tinytable_css_eg2r0cqugg2jg14iygeq') })
window.addEventListener('load', function () { styleCell_tinytable_ookqizclqa48asm7thle(4, 1, 'tinytable_css_eg2r0cqugg2jg14iygeq') })
    </script>

  


</div>
</div>
</figure>
</div>
</div>
<p>The numbers on capacity in existing multifamily zones are difficult to reconcile with reality, and we guess that the City was counting potential development in commercial zones, in particular in C-2 zoning. The bulk of the capacity explicitly required a rezoning. Despite this, the report and the subsequent public discussion frequently referred to the totals as <em>zoned capacity</em>.</p>
<p>The 2019 consultant report does acknowledge some of the difficulties with the development capacities it presents:</p>
<blockquote class="blockquote">
<ul>
<li>A large part of the 43,000 unit capacity in existing zoning districts should be regarded as “paper” capacity that is not all readily available for development in the short term. Much of this capacity is “unused” density on sites that have already been developed and are not economically viable for redevelopment. For example, there are existing 3 storey residential buildings in locations zoned for 4 storeys. Until these properties redevelop, which may be many years in the future depending on the condition of the existing buildings, the unused zoning capacity exists on paper but is not practically available. If for illustrative purposes we assume that only half of this “paper” capacity is available for development in the short term, then the available total capacity is about 74,000 units or 19 years at the recent rate of development.</li>
<li>In order to avoid even more upward pressure on land value, the market needs significantly more capacity than will be developed in the short term.</li>
<li>Planning for significant increases in capacity takes years in Vancouver. The entire three-phase Cambie Corridor plan, focused on the Canada Line, took 10 years. Rezonings consistent with the plan have already occurred, but many of the sites are still in the approvals process.</li>
</ul>
</blockquote>
<p>Staff, including former head planner Gil Kelley, have at times made <a href="https://viewpointvancouver.ca/2016/10/19/viewpoint-issues-with-the-zoned-capacity-argument/">strong assertions about having enough zoned capacity</a>, while at other times <a href="https://council.vancouver.ca/20190313/documents/cfsc1presentation.pdf">Staff have made some rather crude attempts to explain that zoned capacity is not a useful concept</a>, as they did again <a href="https://vancouver.ca/files/cov/memo-housing-policy-recalibrating-housing-vancouver-targets.pdf">in response to the motion by Councillor Hardwick</a>.</p>
<p>These difficulties with talking about <em>zoned capacity</em> should not surprise, given the incompatibility of zoned capacity with the spot-discretionary planning regime. The City’s <a href="https://vancouver.ca/files/cov/memo-housing-policy-recalibrating-housing-vancouver-targets.pdf">alternative concept of <strong>Development capacity</strong></a> can be understood as relating to <em>economically viable and realistically expected to turn over zoned capacity</em> in that it estimates expected future development, where the target is not the context of a freely functioning housing market or provincially defined housing need, but that of an informal quota set by regional planning. <span class="citation" data-cites="metro-vancouver-planning-regimes.2023">(<span class="nocase">von Bergmann and Lauster</span> 2023b)</span></p>



</section>


<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-nz_policy.2022" class="csl-entry">
Ministry of Housing and Urban Development. 2022. <em>National Policy Statement on Urban Development 2020 - Updated May 2022</em>. New Zealand Government. <a href="https://environment.govt.nz/publications/national-policy-statement-on-urban-development-2020-updated-may-2022/">https://environment.govt.nz/publications/national-policy-statement-on-urban-development-2020-updated-may-2022/</a>.
</div>
<div id="ref-terner_redevelopment.2022" class="csl-entry">
Romem, Issi. 2022. <em>Technical Summary of Econometric Approach to Estimating Housing Element Site Capacity in the City of Los Angeles</em>. City of Los Angeles Housing Element 2021-2029. <a href="https://planning.lacity.gov/odocument/15117d38-35ca-416b-9980-25eb20201ba2/Appendix_4.6_-_Regression_Methodology.pdf">https://planning.lacity.gov/odocument/15117d38-35ca-416b-9980-25eb20201ba2/Appendix_4.6_-_Regression_Methodology.pdf</a>.
</div>
<div id="ref-teardowns_data_story.2017" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Joseph Dahmen</span>. 2017. <em>Vancouver’s Teardown Cycle</em>. MountainMath. <a href="https://mountainmath.ca/teardowns">https://mountainmath.ca/teardowns</a>.
</div>
<div id="ref-bc_ssmuh_toa.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, Tom Davidoff, Albert Huang, Nathanael Lauster, and Tsur Somerville</span>. 2023. <em>SSMUH and TOA Scenarios in British Columbia</em>. BC Ministry of Housing. <a href="https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf">https://news.gov.bc.ca/files/bc_SSMUH_TOA_scenarios_Final.pdf</a>.
</div>
<div id="ref-bartholomew-s-dot-density.2021" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2021. <em>Bartholomew’s Dot Destiny</em>. <a href="https://doodles.mountainmath.ca/posts/2021-02-03-bartholomew-s-dot-destiny/">https://doodles.mountainmath.ca/posts/2021-02-03-bartholomew-s-dot-destiny/</a>.
</div>
<div id="ref-planning-for-scarcity.2022" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2022. <em>Planning for Scarcity</em>. <a href="https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/">https://doodles.mountainmath.ca/posts/2022-04-26-planning-for-scarcity/</a>.
</div>
<div id="ref-a-brief-history-of-vancouver-planning-development-regimes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023a. <em>A <span>Brief</span> <span>History</span> of <span>Vancouver</span> <span>Planning</span> &amp; <span>Development</span> <span>Regimes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-02-06-a-brief-history-of-vancouver-planning-development-regimes/">https://doodles.mountainmath.ca/posts/2023-02-06-a-brief-history-of-vancouver-planning-development-regimes/</a>.
</div>
<div id="ref-metro-vancouver-planning-regimes.2023" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2023b. <em>Metro <span>Vancouver</span> <span>Planning</span> <span>Regimes</span></em>. <a href="https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/">https://doodles.mountainmath.ca/posts/2023-06-20-metro-vancouver-planning-regimes/</a>.
</div>
<div id="ref-what-if-recent-apartment-buildings-in-vancouver-were-20-taller.2024" class="csl-entry">
<span class="nocase">von Bergmann, Jens, and Nathan Lauster</span>. 2024. <em>What If Recent Apartment Buildings in <span>Vancouver</span> Were 20% Taller?</em> <a href="https://doodles.mountainmath.ca/posts/2024-04-11-what-if-recent-apartment-buildings-in-vancouver-were-20-taller/">https://doodles.mountainmath.ca/posts/2024-04-11-what-if-recent-apartment-buildings-in-vancouver-were-20-taller/</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>In practice restricting what can be built in some locations and trying to shift development to other areas does sacrifice some value and growth. Location matters.↩︎</p></li>
<li id="fn2"><p>This is something the province could (and should) change, as we have argued before there are large benefits to making this data openly available that far exceed the benefits of being able to sell this data, the main reason why it remains locked up for general public use.↩︎</p></li>
<li id="fn3"><p>see <span class="citation" data-cites="metro-vancouver-planning-regimes.2023"><span class="nocase">von Bergmann and Lauster</span> (2023b)</span> for details on these terms.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{zoned-capacity-promise-and-pitfalls.2024,
  author = {{von Bergmann}, Jens and Lauster, Nathan},
  title = {Zoned {Capacity} - Promise and Pitfalls},
  date = {2024-05-31},
  url = {https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-von_bergmann2024" class="csl-entry quarto-appendix-citeas">
Jens von Bergmann, and Nathan Lauster. 2024. <span>“Zoned Capacity -
Promise and Pitfalls.”</span> <em>MountainDoodles</em>, accepted, May
31. <a href="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/">https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/</a>.
</div></div></section></div> ]]></description>
  <category>affordability</category>
  <category>Vancouver</category>
  <guid>https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/</guid>
  <pubDate>Fri, 31 May 2024 07:00:00 GMT</pubDate>
  <media:content url="https://doodles.mountainmath.ca/posts/2024-05-31-zoned-capacity-promise-and-pitfalls/images/cov_zoned_capacity.png" medium="image" type="image/png" height="81" width="144"/>
</item>
</channel>
</rss>
