COVID-19 US County Confirmed Cases By Population Density​
​Bob Sandheinrich
Population density is a factor in how a virus spreads. This shows how the rate of confirmed cases in US counties corresponds to the population density in those counties

Plotting COVID-19 Confirmed Cases by Population Density

Import the data from the New York Times:
AbsoluteTiming[coviddata=ResourceFunction["NYTimesCOVID19Data"]["USCountiesTimeSeries"];]
Out[]=
{108.495,Null}
Split the counties into groups based on the Log of their population density. This can be very slow:
AbsoluteTiming[bydensity=coviddata[ResourceFunction["KeyGroupBy"][Round[Log[QuantityMagnitude[#["PopulationDensity"]]]]&]];]
Out[]=
{30.5611,Null}
Check the keys. The integers here represent the rounded Log of the population density (in people/square mile), notice that some counties had no density data, eliminate them:
Keys[bydensity]
Out[]=
6
8
7
9
4
5
10
Round[Log[
QuantityMagnitude[Missing[]["PopulationDensity"]]]]
3
2
columns 1–10 of 15
In[]:=
bydensity=bydensity[KeySelect[IntegerQ]];
Create the plot. There is a lot going on here. I add a zero point to each time series at March 1, to avoid an issue with counties that have not reported any cases. For each population density bucket I total the confirmed cases and divide it by the total of all the populations (then multiply by a thousand to give a nicer scale). Then I sort the keys and plot them all together:
bydensityKeySort/*Reverse/*KeyMap[ToString]/*DateListPlot#,
&,1000*Total[Values[#]]Total[QuantityMagnitude[EntityValue[Keys[#],"Population"]]]&,TimeSeriesInsert[#Cases,{DateObject["March 1, 2020"],0}]&
Out[]=
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
Get the latest raw values:
bydensity[KeySort/*Reverse,1000*Total[Values[#]]["LastValue"]/Total[QuantityMagnitude[EntityValue[Keys[#],"Population"]]]&,TimeSeriesInsert[#Cases,{DateObject["March 1, 2020"],0}]&]
Out[]=
10
24.1862
9
18.4162
8
8.40161
7
5.3599
6
4.12947
5
3.18014
4
2.84428
3
3.475
2
2.79873
1
1.42666
0
0.855927
-1
0.32551
-2
0.172028
-3
0.180278

Keywords

◼
  • COVID-19
  • ◼
  • Coronavirus
  • ◼
  • Epidemiology
  • ◼
  • Pandemic
  • ◼
  • Geographic Data
  • ◼
  • Timelines