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

Timestamp:
Style[DateString[Today],32]
Out[]=
Tue 19 Jan 2021
Import the data from the New York Times:
AbsoluteTiming[coviddata=ResourceFunction["NYTimesCOVID19Data"]["USCountiesTimeSeries"];]
Out[]=
{95.8631,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[]=
{563.864,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
1
0
-1
-3
Round[Log[QuantityMagnitude["St. Croix"["PopulationDensity"]]]]
Round[Log[QuantityMagnitude["St. John"["PopulationDensity"]]]]
Round[Log[QuantityMagnitude["St. Thomas"["PopulationDensity"]]]]
Round[Log[QuantityMagnitude["Adjuntas"["PopulationDensity"]]]]
Round[Log[QuantityMagnitude["Aguada"["PopulationDensity"]]]]
Round[Log[QuantityMagnitude["Aguadilla"["PopulationDensity"]]]]
rows 1–20 of 99
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
64.3275
9
69.2014
8
76.9693
7
70.2338
6
74.3848
5
76.7179
4
75.7804
3
78.5684
2
82.2759
1
77.7458
0
68.7113
-1
77.3638
-2
69.9828
-3
36.2869

Keywords

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