<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.5">Jekyll</generator><link href="https://practicalwolf.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://practicalwolf.com/" rel="alternate" type="text/html" /><updated>2020-05-19T07:43:41+00:00</updated><id>https://practicalwolf.com/feed.xml</id><title type="html">Practical Wolf</title><subtitle>Practical Wolf is a blog about using Wolfram Language to solve day-to-day programming tasks.</subtitle><author><name>Contact us</name></author><entry><title type="html">Recovering Dynkin’s interviews</title><link href="https://practicalwolf.com/2020/05/17/recovering-dynkin-s-interviews.html" rel="alternate" type="text/html" title="Recovering Dynkin’s interviews" /><published>2020-05-17T00:00:00+00:00</published><updated>2020-05-17T00:00:00+00:00</updated><id>https://practicalwolf.com/2020/05/17/recovering-dynkin-s-interviews</id><content type="html" xml:base="https://practicalwolf.com/2020/05/17/recovering-dynkin-s-interviews.html">&lt;p&gt;Mathematician Eugene B. Dynkin (1924-2014) conducted over 200 interviews with various mathematicians, and Cornell University Library has &lt;a href=&quot;http://dynkincollection.library.cornell.edu/interviews&quot;&gt;digitized this collection&lt;/a&gt;. However, that site is currently is broken as it required Flash to play audio and video files, and most of the pages throw PHP errors. In this blog post, we scrap audio and video links to underlying files, along with the metadata, to make this information available again until Cornell fixes its archive.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;extracting-interview-videoaudio-links-and-metadata&quot;&gt;Extracting interview video/audio links and metadata&lt;/h3&gt;

&lt;p&gt;The interviews TOC has links to all individual interview pages &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/node/xxx &lt;/code&gt;so that we can get all 200+ of them:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image1.png&quot; alt=&quot;image1.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image2.png&quot; alt=&quot;image2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Looking at the individual page’s XML soup, we can see that it has several &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;div&lt;/code&gt; pairs with classes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;field-label&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;field-items&lt;/code&gt;.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image3.png&quot; alt=&quot;image3.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image4.png&quot; alt=&quot;image4.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image5.png&quot; alt=&quot;image5.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Interview URL&lt;/code&gt; the flash player information is URL encoded in an XML element &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name=flashvars,&lt;/code&gt; so we need to extract &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;‘url’: ‘xxx’&lt;/code&gt; parts.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image6.png&quot; alt=&quot;image6.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Translation or Transcription&lt;/code&gt;, there are typically a few hyperlinks, so we need to extract them.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image7.png&quot; alt=&quot;image7.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For all the other fields, we extract all the strings and concatenate them together.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image8.png&quot; alt=&quot;image8.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image9.png&quot; alt=&quot;image9.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image10.png&quot; alt=&quot;image10.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;parsing-the-whole-collection&quot;&gt;Parsing the whole collection&lt;/h3&gt;

&lt;p&gt;Since we might want to revise our extraction logic as we encounter more edge cases, it would make sense to download and parse every URL just once and cache the resulting XML objects.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image11.png&quot; alt=&quot;image11.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image12.png&quot; alt=&quot;image12.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image13.png&quot; alt=&quot;image13.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image14.png&quot; alt=&quot;image14.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is a full list of fields in the interview metadata, although many of these are missing.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image15.png&quot; alt=&quot;image15.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image16.png&quot; alt=&quot;image16.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The last touch will be to save the above collection in some sensible format. The easiest would probably be a static HTML file with direct links to Cornell collection. The easiest would be to generate a markdown file with a table that can be converted to HTML by Jekyll that runs this site. The final table is available &lt;a href=&quot;https://practicalwolf.com/dynkin/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image17.png&quot; alt=&quot;image17.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image18.png&quot; alt=&quot;image18.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-05-17-recovering-dynkin-s-interviews/image19.png&quot; alt=&quot;image19.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/notebooks/2020-05-17-recovering-dynkin-s-interviews.nb.gz&quot;&gt;&lt;small&gt;Download this notebook&lt;/small&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Contact us</name></author><summary type="html">Mathematician Eugene B. Dynkin (1924-2014) conducted over 200 interviews with various mathematicians, and Cornell University Library has digitized this collection. However, that site is currently is broken as it required Flash to play audio and video files, and most of the pages throw PHP errors. In this blog post, we scrap audio and video links to underlying files, along with the metadata, to make this information available again until Cornell fixes its archive.</summary></entry><entry><title type="html">A Tale of Two Coasts</title><link href="https://practicalwolf.com/2020/04/08/a-tale-of-two-coasts.html" rel="alternate" type="text/html" title="A Tale of Two Coasts" /><published>2020-04-08T00:00:00+00:00</published><updated>2020-04-08T00:00:00+00:00</updated><id>https://practicalwolf.com/2020/04/08/a-tale-of-two-coasts</id><content type="html" xml:base="https://practicalwolf.com/2020/04/08/a-tale-of-two-coasts.html">&lt;p&gt;US West Coast became infected by the coronavirus earlier in the epidemic, with the state of Washington having a &lt;a href=&quot;https://www.nejm.org/doi/full/10.1056/NEJMoa2001191&quot;&gt;first officially recorded COVID-19 case&lt;/a&gt; on January 19. Many West Coast companies started WFH policies well ahead of the curve, and a few counties in the Bay Area and Seattle issued “shelter in place” orders before the State did. On the other coast, a mayor of the biggest US city urged his fellow citizens to “&lt;em&gt;go on with your lives + get out on the town despite Coronavirus… thru Thurs 3/5 go see “The Traitor”&lt;/em&gt; .”&lt;/p&gt;

&lt;p&gt;Let’s compare the dynamics of confirmed cases and growth rates between different US states. While many confounding factors, such as population densities, use of public transportation, use of face masks, weather, administrative restrictions, etc. makes it harder to draw clear conclusions, there is a growing consensus that New York situation got &lt;a href=&quot;https://www.nytimes.com/2020/04/08/nyregion/new-york-coronavirus-response-delays.html&quot;&gt;substantially worse because of the city’s delayed response&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image1.png&quot; alt=&quot;image1.png&quot; /&gt;&lt;/p&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;data-preparation-and-helper-functions&quot;&gt;Data preparation and helper functions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;  This section is quite technical; if you just want to look at the results of the analysis, you can skip it.&lt;/p&gt;

&lt;p&gt;Before we dive into the analysis, let’s gather the data and define a few functions to make the plotting easier. A more detailed description of the data sources and how to use datasets and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Entity&lt;/code&gt; is provided in two previous posts &lt;a href=&quot;https://practicalwolf.com/2020/03/31/covid-19-confirmed-cases-and-deaths-in-the-us.html&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://practicalwolf.com/2020/04/05/correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, let’s combine the information on population and population densities with COVID-19 confirmed cases and deaths. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Merge&lt;/code&gt;, as it name implies, is used to join two associations by the same key, and the second argument, a pure function that replaces a head of the list with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Join&lt;/code&gt;, allows us to merge the nested association together, since both of the data structure that we are trying to merge as associations of associations. (If this is unclear, evaluate each of the arguments to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Merge&lt;/code&gt; separately, inspect and compare it to the result). We also use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KeyMap&lt;/code&gt; to convert association keys from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Entity&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image2.png&quot; alt=&quot;image2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is the structure of the result:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image3.png&quot; alt=&quot;image3.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image4.png&quot; alt=&quot;image4.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We do the same for the list of countries; the only difference is that the COVID-19 country dataset splits the data into administrative regions for US, China, Canada, Australia and UK, so we need to combine them to get the total:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image5.png&quot; alt=&quot;image5.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s define a function that would normalize timeseries in the following way: first, it will convert the absolute number of cases or deaths into cases per 10K (or 1M) people, to make the numbers between different states and countries comparable. And second, it will truncate all the values below a certain threshold, so that when we compare the growth over time, all the curves start (roughly) in the same place.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image6.png&quot; alt=&quot;image6.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For example, here is the entry for California:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image7.png&quot; alt=&quot;image7.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image8.png&quot; alt=&quot;image8.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;and here is the deaths per million since the day they exceeded 1:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image9.png&quot; alt=&quot;image9.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image10.png&quot; alt=&quot;image10.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We will also create shortcuts for cases and deaths that can be applied to whole associations:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image11.png&quot; alt=&quot;image11.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, let’s define some plotting routines. Since 50 US states (or 251 countries) is much to display on the same graph, we’ll define a function to plot selected lines with colors and labels, while plotting everything else with thin gray lines to create a context.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image12.png&quot; alt=&quot;image12.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image13.png&quot; alt=&quot;image13.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;a-tale-of-two-coasts&quot;&gt;A Tale of Two Coasts&lt;/h3&gt;

&lt;p&gt;As we mentioned in the beginning, West Coast states were more proactive than East Coast states in implementing WFH and quarantine measures. Add lower population density and significantly smaller public transportation, and you will see a drastically different picture in terms of both number of confirmed cases:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image14.png&quot; alt=&quot;image14.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image15.png&quot; alt=&quot;image15.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;and number of deaths:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image16.png&quot; alt=&quot;image16.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image17.png&quot; alt=&quot;image17.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is a full grid showing data for each individual state, for both confirmed cases:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image18.png&quot; alt=&quot;image18.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image19.png&quot; alt=&quot;image19.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;and deaths for those cases that have more than 1 per 1M:&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image20.png&quot; alt=&quot;image20.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image21.png&quot; alt=&quot;image21.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;population-density-and-other-factors&quot;&gt;Population density and other factors&lt;/h3&gt;

&lt;p&gt;To put New York numbers in the perspective, let’s compare them to aggregates for a few countries. Let’s see how it compares to Italy and Spain that didn’t do so well, as well as to  South Korea - a place with a high population density, as Seoul’s population is 10M people is over 20% of the country’s total.&lt;/p&gt;

&lt;p&gt;As you can see, New York  substantially dominate all of these countries. South Korea is barely visible at the bottom of the chart, as they have managed the pandemic exceptionally well, with ~4 deaths per 1M. In other observations, overall US numbers track France surprisingly well, and situation is much worse in Spain now that in Italy, which was the original “hot bed” in Europe, with France almost caught to Italy.&lt;/p&gt;

&lt;p class=&quot;Input&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image22.png&quot; alt=&quot;image22.png&quot; /&gt;&lt;/p&gt;

&lt;p class=&quot;Output&quot;&gt;&lt;img src=&quot;/assets/2020-04-08-a-tale-of-two-coasts/image23.png&quot; alt=&quot;image23.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/notebooks/2020-04-08-a-tale-of-two-coasts.nb.gz&quot;&gt;&lt;small&gt;Download this notebook&lt;/small&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Contact us</name></author><summary type="html">US West Coast became infected by the coronavirus earlier in the epidemic, with the state of Washington having a first officially recorded COVID-19 case on January 19. Many West Coast companies started WFH policies well ahead of the curve, and a few counties in the Bay Area and Seattle issued “shelter in place” orders before the State did. On the other coast, a mayor of the biggest US city urged his fellow citizens to “go on with your lives + get out on the town despite Coronavirus… thru Thurs 3/5 go see “The Traitor” .” Let’s compare the dynamics of confirmed cases and growth rates between different US states. While many confounding factors, such as population densities, use of public transportation, use of face masks, weather, administrative restrictions, etc. makes it harder to draw clear conclusions, there is a growing consensus that New York situation got substantially worse because of the city’s delayed response.</summary></entry><entry><title type="html">Correlation between COVID-19 per capita death rates and population density for US states</title><link href="https://practicalwolf.com/2020/04/05/correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states.html" rel="alternate" type="text/html" title="Correlation between COVID-19 per capita death rates and population density for US states" /><published>2020-04-05T00:00:00+00:00</published><updated>2020-04-05T00:00:00+00:00</updated><id>https://practicalwolf.com/2020/04/05/correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states</id><content type="html" xml:base="https://practicalwolf.com/2020/04/05/correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states.html">&lt;p&gt;We had a Zoom session with a friend yesterday as I was showing him around the Wolfram Language, and one of the questions we discussed is whether there is a correlation between death rate per capita and population density for US states. We could hypothesize that there should be one, In essence, higher population density means higher rates of infection, regardless of what the official number of confirmed cases say, as the testing protocols can be different between different states.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;population-density-for-the-continental-us-states&quot;&gt;Population density for the continental US states&lt;/h3&gt;

&lt;p&gt;For a warmup, let’s plot the population densities for the continental US states, which is easy to do as this information is available as one of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AdministrativeDivision&lt;/code&gt; properties. We can use a convenient &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EntityValue&lt;/code&gt; function, with a proper &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EntityClass&lt;/code&gt; as the first argument, which can be entered by pressing Ctrl+=, typing “us states”, and hitting Enter. You can think of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EntityClass&lt;/code&gt; as a collection of entities of a particular type.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image1.png&quot; alt=&quot;image1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since we provided &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EntityAssociation&lt;/code&gt; as a third (optional) argument to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EntityValue&lt;/code&gt;, the result is an association which maps each US state entity to its population density.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image2.png&quot; alt=&quot;image2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image3.png&quot; alt=&quot;image3.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Notice that the population density is not just a simple number, but a number with some magnitude (people per square mile), represented in Wolfram Language by an expression with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Quantity&lt;/code&gt; head.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image4.png&quot; alt=&quot;image4.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image5.png&quot; alt=&quot;image5.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%&lt;/code&gt; refers to the result of the previous expression, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FullForm&lt;/code&gt; shows how the above expression is stored internally. FrontEnd does a charming job of displaying the entity, quantity, rule, and association nicely.&lt;/p&gt;

&lt;p&gt;Having the population density represented as a quantity is very convenient, as we, for example, can convert it into different units:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image6.png&quot; alt=&quot;image6.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image7.png&quot; alt=&quot;image7.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Before we can display these densities on a heat map, we would need to do a couple of things: first, we want to remove Alaska and Hawaii, and also DC (as it’s a clear outlier). And secondly, we want to apply &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Log&lt;/code&gt; to numerical values, as  the difference in densities between a tiny Delaware and a sparsely populated Wyoming is over 60x!&lt;/p&gt;

&lt;p&gt;The first task can be done with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KeyDropFrom&lt;/code&gt;, which drops given keys from association (you can copy and paste the names of the states from the output, or use Ctrl+= again to enter them). The second task can be accomplished by using a combination of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QuantityMagnitude&lt;/code&gt;, which extracts a numerical value from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Quantity&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Log,&lt;/code&gt;. Both of this functions are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Listable&lt;/code&gt; (= can be applied to a list or association without an explicit call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Map&lt;/code&gt;), and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Map[f, expr]&lt;/code&gt; applies &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f&lt;/code&gt; to &lt;em&gt;values&lt;/em&gt;  when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expr&lt;/code&gt; is an association. Finally, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GeoRegionValuePlot&lt;/code&gt; will color the states according to the (log) of their population density:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image8.png&quot; alt=&quot;image8.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image9.png&quot; alt=&quot;image9.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can combine the above two steps into a function that, given an entity list of countries or administrative divisions (everything that has a population density property) plots the above. The optional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exclude&lt;/code&gt; argument can be used to remove certain areas from plotting.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image10.png&quot; alt=&quot;image10.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image11.png&quot; alt=&quot;image11.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image12.png&quot; alt=&quot;image12.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image13.png&quot; alt=&quot;image13.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image14.png&quot; alt=&quot;image14.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note that we can also use a collection of countries as an argument to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plotPopulationDensities&lt;/code&gt;, since each country is an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Entity&lt;/code&gt; object that also has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PopulationDensity&lt;/code&gt; property:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image15.png&quot; alt=&quot;image15.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image16.png&quot; alt=&quot;image16.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image17.png&quot; alt=&quot;image17.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image18.png&quot; alt=&quot;image18.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;death-rates-per-capita-vs-population-density&quot;&gt;Death rates per capita vs population density&lt;/h3&gt;

&lt;p&gt;Now for the main dish: we’re going to use the same dataset as in our &lt;a href=&quot;https://practicalwolf.com/2020/03/31/covid-19-confirmed-cases-and-deaths-in-the-us.html&quot;&gt;earlier blog post&lt;/a&gt; on this topic, and use the fact that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AdministrativeDivision&lt;/code&gt; column returned by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ResourceData&lt;/code&gt; is an Entity object:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image19.png&quot; alt=&quot;image19.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s take the first line of this dataset as an example (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Normal&lt;/code&gt; converts a one element dataset into an association):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image20.png&quot; alt=&quot;image20.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image21.png&quot; alt=&quot;image21.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s write a function that calculates two values - population density and COVID-19 deaths per capita. We also wrap these two values into a callout, so that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ListPlot&lt;/code&gt; can show these labels:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image22.png&quot; alt=&quot;image22.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image23.png&quot; alt=&quot;image23.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image24.png&quot; alt=&quot;image24.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now we can apply this function to each row of the dataset (we’ll also remove a couple of outliers) and plot the result:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image25.png&quot; alt=&quot;image25.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image26.png&quot; alt=&quot;image26.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image27.png&quot; alt=&quot;image27.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Visually, there is a weak correlation between log population density and log death rate per capita, as we expected. Let’s calculate the R-square explicitly. We can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cases&lt;/code&gt; to extract just the first argument from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Callout&lt;/code&gt;. There are two more subtle points: we apply &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;N&lt;/code&gt; to callouts, which calculates the numerical value to all the logarithms, and we only select cases where the second value is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt;, since for Wyoming, that death per capita is minus infinity.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image28.png&quot; alt=&quot;image28.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image29.png&quot; alt=&quot;image29.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image30.png&quot; alt=&quot;image30.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image31.png&quot; alt=&quot;image31.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The R-squared is pretty low, though at only 22%:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image32.png&quot; alt=&quot;image32.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image33.png&quot; alt=&quot;image33.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, let’s plot the fitted line on the chart:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image34.png&quot; alt=&quot;image34.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states/image35.png&quot; alt=&quot;image35.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/notebooks/2020-04-05-correlation-between-covid-19-per-capita-death-rates-and-population-density-for-us-states.nb.gz&quot;&gt;&lt;small&gt;Download this notebook&lt;/small&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Contact us</name></author><summary type="html">We had a Zoom session with a friend yesterday as I was showing him around the Wolfram Language, and one of the questions we discussed is whether there is a correlation between death rate per capita and population density for US states. We could hypothesize that there should be one, In essence, higher population density means higher rates of infection, regardless of what the official number of confirmed cases say, as the testing protocols can be different between different states.</summary></entry><entry><title type="html">Converting Wolfram Notebooks to Markdown</title><link href="https://practicalwolf.com/2020/04/02/converting-wolfram-notebooks-to-markdown.html" rel="alternate" type="text/html" title="Converting Wolfram Notebooks to Markdown" /><published>2020-04-02T00:00:00+00:00</published><updated>2020-04-02T00:00:00+00:00</updated><id>https://practicalwolf.com/2020/04/02/converting-wolfram-notebooks-to-markdown</id><content type="html" xml:base="https://practicalwolf.com/2020/04/02/converting-wolfram-notebooks-to-markdown.html">&lt;p&gt;We want to convert a Wolfram Notebook into a jekyll markdown to use on&lt;a href=&quot;https://practicalwolf.com&quot;&gt; this&lt;/a&gt; blog. &lt;!--more--&gt; At this point we are only converting 6 type of cells: Section, Subsection, Subsubsection, Text, Input and Output. Here is how to get all of these cells as a list:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image1.png&quot; alt=&quot;image1.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;processing-text-cells&quot;&gt;Processing text cells&lt;/h3&gt;

&lt;p&gt;We’ll define a single function, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processCell&lt;/code&gt;, that will convert cells of a different type into strings. The simplest possible case is a simple text in (sub)section titles or text:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image2.png&quot; alt=&quot;image2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image3.png&quot; alt=&quot;image3.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A little bit more complex are cases where there is some formatting inside the text, for example italic, text formatted as input, etc. We’ll define a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processTextData&lt;/code&gt; function to deal with this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image4.png&quot; alt=&quot;image4.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image5.png&quot; alt=&quot;image5.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image6.png&quot; alt=&quot;image6.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;processing-inputs-and-outputs&quot;&gt;Processing inputs and outputs&lt;/h3&gt;

&lt;p&gt;To process inputs and outputs, we need to convert them into a PNG file. We’ll be using two global variables, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$imageOutputDir&lt;/code&gt; which defines where to output files, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$imageNumber&lt;/code&gt;, which is a counter for the current image being output.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image7.png&quot; alt=&quot;image7.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;main-conversion-function&quot;&gt;Main conversion function&lt;/h3&gt;

&lt;p&gt;Now that we have defined utilities for converting individual cells, we can define a function to convert a notebook. Since out ultimate goal is do conversion with a press of a single pallette button, we want to define reasonable default values for as many required parameters as possible.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image8.png&quot; alt=&quot;image8.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For simplicity, we expect the very first cell to contain a title and be formatted with Section style.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image9.png&quot; alt=&quot;image9.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Similarly, the second cell should contain a representation of date.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image10.png&quot; alt=&quot;image10.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If neither of this conditions holds, we’ ll signal an error and won’ t continue the conversion. We will also copy the notebook to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/assets/notebooks&lt;/code&gt; folder, and put the link to the source at the end of the blog post.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-04-02-converting-wolfram-notebooks-to-markdown/image11.png&quot; alt=&quot;image11.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/notebooks/2020-04-02-converting-wolfram-notebooks-to-markdown.nb.gz&quot;&gt;&lt;small&gt;Download this notebook&lt;/small&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Contact us</name></author><summary type="html">We want to convert a Wolfram Notebook into a jekyll markdown to use on this blog.</summary></entry><entry><title type="html">COVID-19 confirmed cases and deaths in the US</title><link href="https://practicalwolf.com/2020/03/31/covid-19-confirmed-cases-and-deaths-in-the-us.html" rel="alternate" type="text/html" title="COVID-19 confirmed cases and deaths in the US" /><published>2020-03-31T00:00:00+00:00</published><updated>2020-03-31T00:00:00+00:00</updated><id>https://practicalwolf.com/2020/03/31/covid-19-confirmed-cases-and-deaths-in-the-us</id><content type="html" xml:base="https://practicalwolf.com/2020/03/31/covid-19-confirmed-cases-and-deaths-in-the-us.html">&lt;p&gt;Wolfram Research maintains and regularly updates COVID-19 data series in their &lt;a href=&quot;http://wolfr.am/coronavirus&quot;&gt;repository&lt;/a&gt; and it provides the US state level data.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image1.png&quot; alt=&quot;image1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The data is stored in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dataset&lt;/code&gt;, a Wolfram Language’s way to organize and query structured data. It has 51 entries (for 50 US States and the District of Columbia), and tracks the cumulative number of confirmed cases, recovered cases, and deaths for each state by date.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image2.png&quot; alt=&quot;image2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image3.png&quot; alt=&quot;image3.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image4.png&quot; alt=&quot;image4.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cases and deaths are stored as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeSeries&lt;/code&gt;,  which is a sophisticated way to represent time-value pairs: for example, you can query the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeSeries&lt;/code&gt; object about the first / last date in the series, ask for a value on a particular date (and it will be automatically interpolated if the data point doesn’t exist), etc.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image5.png&quot; alt=&quot;image5.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image6.png&quot; alt=&quot;image6.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can plot the number of cases for New York using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DateListLogPlot&lt;/code&gt;, which makes the Y-axis logarithmic. We also start plotting from Mar 2nd, as there is no interesting data before:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image7.png&quot; alt=&quot;image7.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image8.png&quot; alt=&quot;image8.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dataset&lt;/code&gt; has a powerful query operator syntax: to quote from the official documentation,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dataset[op1, op2, ...]&lt;/code&gt;, query operators &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;op_i&lt;/code&gt; are applied at successively deeper levels of data, but any given one may be applied either while “descending” into the data or while “ascending” out of it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are many special cases: for example, a single number &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt; is a descending operator which takes part &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt; and applies subsequent operators to it, while &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;key&quot;&lt;/code&gt; similarly takes the value of key in the association. Therefore  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;usData[1, &quot;ConfirmedCases&quot;]&lt;/code&gt; takes the first row of the dataset, which is an association with six keys shown above, and then takes the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;ConfirmedCases&quot;&lt;/code&gt; key, returning a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeSeries&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is another example: since we are not going to use Country and GeoPosition fields, we can redefine &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;usData&lt;/code&gt; to omit those fields. In this case,  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;All&lt;/code&gt; is an operator that applies subsequent operators to every part of the list or association, and  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;|key1-&amp;gt;op1, key2-&amp;gt;op2, ...|&amp;gt;&lt;/code&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; &lt;/code&gt;applies multiple operators at once to the result, yielding an association with the given keys, and also let us rename the columns.&lt;/p&gt;

&lt;p&gt;While we are here, we will also convert state names to strings, since every state returned by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ResourceData&lt;/code&gt; is an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Entity&lt;/code&gt; object, not a string, and a combination of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StringSplit&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;First&lt;/code&gt; extract just the first part before the comma. We also use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/*&lt;/code&gt;, which represents a right composition of functions.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image9.png&quot; alt=&quot;image9.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Using a helper function that returns the last value for a time series, we can see the latest number of confirmed cases and deaths. Here we used another query syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{key1-&amp;gt;op1, key2-&amp;gt;op2, ...}&lt;/code&gt; applies different operators to specific parts in the result.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image10.png&quot; alt=&quot;image10.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image11.png&quot; alt=&quot;image11.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can now calculate and plot daily growth in number of cases and deaths. To avoid having too much noise in the charts, we will only calculate differences once a state has greater than 500 confirmed cases or 20 deaths. Note the use of a helper function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;growthAfter&lt;/code&gt; and how we use pure functions&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image12.png&quot; alt=&quot;image12.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image13.png&quot; alt=&quot;image13.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we will only plot a data series if it has more than 5 data points for deaths or 9 data points for cases:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image14.png&quot; alt=&quot;image14.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since we want to plot a few similar charts with different parameters, we’ll use a helper function for that:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image15.png&quot; alt=&quot;image15.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is a chart with the number of daily increases for deaths - New York is clearly dominating everything else&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image16.png&quot; alt=&quot;image16.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image17.png&quot; alt=&quot;image17.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is the same chart without New York: California has a recent spike, while Massachusetts remains pretty stable for a long time.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image18.png&quot; alt=&quot;image18.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image19.png&quot; alt=&quot;image19.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And here is the number of confirmed cases, with and without NY and NJ scale: Washington, which had the first case in the country, and New Jersey have somewhat stabilized, but it can just be a function of how much testing is done at a state level.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image20.png&quot; alt=&quot;image20.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image21.png&quot; alt=&quot;image21.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image22.png&quot; alt=&quot;image22.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us/image23.png&quot; alt=&quot;image23.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/notebooks/2020-03-31-covid-19-confirmed-cases-and-deaths-in-the-us.nb.gz&quot;&gt;&lt;small&gt;Download this notebook&lt;/small&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Contact us</name></author><summary type="html">Wolfram Research maintains and regularly updates COVID-19 data series in their repository and it provides the US state level data. The data is stored in a Dataset, a Wolfram Language’s way to organize and query structured data. It has 51 entries (for 50 US States and the District of Columbia), and tracks the cumulative number of confirmed cases, recovered cases, and deaths for each state by date.</summary></entry></feed>