COVID-surge [https://github.com/dpploy/covid-surge] : V. F. de Almeida 14May20
$ \newcommand{\Amtrx}{\boldsymbol{\mathsf{A}}} \newcommand{\Bmtrx}{\boldsymbol{\mathsf{B}}} \newcommand{\Cmtrx}{\boldsymbol{\mathsf{C}}} \newcommand{\Mmtrx}{\boldsymbol{\mathsf{M}}} \newcommand{\Imtrx}{\boldsymbol{\mathsf{I}}} \newcommand{\Pmtrx}{\boldsymbol{\mathsf{P}}} \newcommand{\Qmtrx}{\boldsymbol{\mathsf{Q}}} \newcommand{\Lmtrx}{\boldsymbol{\mathsf{L}}} \newcommand{\Umtrx}{\boldsymbol{\mathsf{U}}} \newcommand{\xvec}{\boldsymbol{\mathsf{x}}} \newcommand{\yvec}{\boldsymbol{\mathsf{y}}} \newcommand{\zvec}{\boldsymbol{\mathsf{z}}} \newcommand{\avec}{\boldsymbol{\mathsf{a}}} \newcommand{\bvec}{\boldsymbol{\mathsf{b}}} \newcommand{\cvec}{\boldsymbol{\mathsf{c}}} \newcommand{\rvec}{\boldsymbol{\mathsf{r}}} \newcommand{\norm}[1]{\bigl\lVert{#1}\bigr\rVert} \DeclareMathOperator{\rank}{rank} \DeclareMathOperator{\abs}{abs} $
On-line COVID-19 data is used in this notebook, and a fit to the sigmoid function
\begin{equation*} \boxed{ f(t) = \frac{\alpha_0}{1 + \alpha_1\, e^{\alpha_2\,t} } } \end{equation*}is systematically made. The time between points where the function has maximum and minimum curvature is computed and reported as the surge period. This period is relevant to public health officials to decide how long measures to control the epidemic should be in place. In addition, the surge period provides insight in comparing how different communities react to the epidemic.
'''Load the covid-surge package'''
#!pip install --upgrade --quiet covid-surge
from covid_surge import Surge
%matplotlib inline
'''Import data'''
# Get complete US surge data
us_surge = Surge()
print('# of states/districts: ',len(us_surge.names))
print('# of days: ',us_surge.dates.shape[0])
# of states/districts: 56 # of days: 121
'''Set parameters'''
us_surge.end_date = '4/20/20' # set end date wanted
us_surge.end_date = None # get all the data available
us_surge.ignore_last_n_days = 2 # allow for data repo to be corrected/updated
us_surge.min_n_cases_abs = 500 # min # of absolute cases for analysis
us_surge.deaths_100k_minimum = 41 # US death per 100,000 for Chronic Lower Respiratory Diseases per year: 41 (2019)
'''Fit data to model function'''
# Fit data to all states
fit_data = us_surge.multi_fit_data()
states = list()
print('')
for (i,(sort_key,data)) in enumerate(fit_data):
name = data[0]
states.append(name)
print('%2i) %15s: surge period %1.2f [day]'%(i,name,sort_key))
0) Virginia: surge period 18.80 [day] 1) New York: surge period 19.41 [day] 2) Massachusetts: surge period 20.97 [day] 3) Connecticut: surge period 21.00 [day] 4) Michigan: surge period 21.91 [day] 5) Minnesota: surge period 23.07 [day] 6) New Jersey: surge period 23.32 [day] 7) Maryland: surge period 23.57 [day] 8) Pennsylvania: surge period 23.72 [day] 9) Louisiana: surge period 23.99 [day] 10) North Carolina: surge period 24.88 [day] 11) Indiana: surge period 25.90 [day] 12) Georgia: surge period 26.48 [day] 13) Florida: surge period 26.79 [day] 14) Ohio: surge period 26.80 [day] 15) Colorado: surge period 26.98 [day] 16) California: surge period 27.40 [day] 17) Illinois: surge period 28.34 [day] 18) Missouri: surge period 28.54 [day] 19) Washington: surge period 28.91 [day]
'''Loop over the top states and calculate the surge period for counties/towns'''
for state in states:
print('')
print('***************************************************************')
print(' ',state )
print('***************************************************************')
c_surge = Surge(locale='US',sub_locale=state)
print('# of counties: ',len(c_surge.names))
# Set parameters
c_surge.end_date = '4/20/20' # set end date wanted
c_surge.end_date = None # get all the data available
c_surge.ignore_last_n_days = 2 # allow for data repo to be corrected/updated
c_surge.min_n_cases_abs = 200 # min # of absolute cases for analysis
c_surge.deaths_100k_minimum = 41 # US death per 100,000 for Chronic Lower Respiratory Diseases per year: 41 (2019)
# Fit data to all counties/cities
fit_data = c_surge.multi_fit_data()
print('# of fittings done = ',len(fit_data))
if len(fit_data) == 0:
continue
print('')
for (sort_key,data) in fit_data:
name = data[0]
print('%15s: surge period %1.2f [day]'%(name,sort_key))
# Create clustering bins based on surge period
bins = c_surge.clustering(fit_data,2,'surge_period')
print('')
print('----------------------------------------------------------------')
print(' Bins ')
print('----------------------------------------------------------------')
for k in sorted(bins.keys()):
print(' Bin %i %s'%(k,bins[k]))
# Use bins to create groups of counties/cities based on surge period
county_groups = dict()
for (sort_key,data) in fit_data:
county = data[0]
param_vec = data[3]
key = c_surge.get_bin_id(sort_key,bins)
if key in county_groups:
county_groups[key].append(county)
else:
county_groups[key] = list()
county_groups[key].append(county)
county_groups = [ county_groups[k] for k in
sorted(county_groups.keys(),reverse=False) ]
print('')
print('----------------------------------------------------------------')
print(' County Groups ')
print('----------------------------------------------------------------')
for g in county_groups:
print(' Group %i %s'%(county_groups.index(g),g))
# Plot the surge period for all grouped counties
c_surge.plot_group_surge_periods( fit_data, bins )
print('')
print('')
*************************************************************** Virginia *************************************************************** # of counties: 133 # of fittings done = 1 Fairfax: surge period 17.58 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [17.0, 18.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Fairfax']
*************************************************************** New York *************************************************************** # of counties: 62 # of fittings done = 7 Nassau: surge period 17.10 [day] Rockland: surge period 17.85 [day] New York: surge period 18.12 [day] Westchester: surge period 18.81 [day] Orange: surge period 21.97 [day] Suffolk: surge period 24.51 [day] Erie: surge period 24.93 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [17.0, 19.0] Bin 1 [19.0, 21.0] Bin 2 [21.0, 23.0] Bin 3 [23.0, 25.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Nassau', 'Rockland', 'New York', 'Westchester'] Group 1 ['Orange'] Group 2 ['Suffolk', 'Erie']
*************************************************************** Massachusetts *************************************************************** # of counties: 14 # of fittings done = 8 Norfolk: surge period 17.86 [day] Suffolk: surge period 17.88 [day] Middlesex: surge period 19.44 [day] Hampden: surge period 19.85 [day] Plymouth: surge period 19.88 [day] Essex: surge period 22.89 [day] Bristol: surge period 23.73 [day] Worcester: surge period 24.09 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [17.0, 19.0] Bin 1 [19.0, 21.0] Bin 2 [21.0, 23.0] Bin 3 [23.0, 25.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Norfolk', 'Suffolk'] Group 1 ['Middlesex', 'Hampden', 'Plymouth'] Group 2 ['Essex'] Group 3 ['Bristol', 'Worcester']
*************************************************************** Connecticut *************************************************************** # of counties: 8 # of fittings done = 3 Hartford: surge period 19.18 [day] Fairfield: surge period 21.21 [day] New Haven: surge period 21.88 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [19.0, 22.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Hartford', 'Fairfield', 'New Haven']
*************************************************************** Michigan *************************************************************** # of counties: 83 # of fittings done = 4 Genesee: surge period 19.22 [day] Macomb: surge period 19.34 [day] Wayne: surge period 20.96 [day] Oakland: surge period 24.58 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [19.0, 21.0] Bin 1 [21.0, 23.0] Bin 2 [23.0, 25.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Genesee', 'Macomb', 'Wayne'] Group 1 ['Oakland']
*************************************************************** Minnesota *************************************************************** # of counties: 87 # of fittings done = 1 Hennepin: surge period 19.86 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [19.0, 20.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Hennepin']
*************************************************************** New Jersey *************************************************************** # of counties: 21 # of fittings done = 13 Hudson: surge period 18.27 [day] Passaic: surge period 20.29 [day] Somerset: surge period 21.05 [day] Essex: surge period 21.23 [day] Union: surge period 21.35 [day] Bergen: surge period 22.21 [day] Morris: surge period 22.94 [day] Burlington: surge period 23.65 [day] Mercer: surge period 24.24 [day] Monmouth: surge period 24.84 [day] Camden: surge period 26.08 [day] Middlesex: surge period 26.55 [day] Ocean: surge period 27.46 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [18.0, 20.0] Bin 1 [20.0, 22.0] Bin 2 [22.0, 24.0] Bin 3 [24.0, 26.0] Bin 4 [26.0, 28.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Hudson'] Group 1 ['Passaic', 'Somerset', 'Essex', 'Union'] Group 2 ['Bergen', 'Morris', 'Burlington'] Group 3 ['Mercer', 'Monmouth'] Group 4 ['Camden', 'Middlesex', 'Ocean']
*************************************************************** Maryland *************************************************************** # of counties: 24 # of fittings done = 4 Montgomery: surge period 21.70 [day] Prince George's: surge period 23.32 [day] Baltimore City: surge period 23.36 [day] Baltimore: surge period 25.63 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [21.0, 23.5] Bin 1 [23.5, 26.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Montgomery', "Prince George's", 'Baltimore City'] Group 1 ['Baltimore']
*************************************************************** Pennsylvania *************************************************************** # of counties: 67 # of fittings done = 6 Lancaster: surge period 18.69 [day] Delaware: surge period 20.50 [day] Montgomery: surge period 20.61 [day] Chester: surge period 21.87 [day] Bucks: surge period 22.22 [day] Philadelphia: surge period 25.74 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [18.0, 20.0] Bin 1 [20.0, 22.0] Bin 2 [22.0, 24.0] Bin 3 [24.0, 26.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Lancaster'] Group 1 ['Delaware', 'Montgomery', 'Chester'] Group 2 ['Bucks'] Group 3 ['Philadelphia']
*************************************************************** Louisiana *************************************************************** # of counties: 64 # of fittings done = 3 Jefferson: surge period 20.73 [day] Orleans: surge period 22.63 [day] East Baton Rouge: surge period 25.82 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [20.0, 22.0] Bin 1 [22.0, 24.0] Bin 2 [24.0, 26.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Jefferson'] Group 1 ['Orleans'] Group 2 ['East Baton Rouge']
*************************************************************** North Carolina *************************************************************** # of counties: 100 # of fittings done = 0 *************************************************************** Indiana *************************************************************** # of counties: 92 # of fittings done = 1 Marion: surge period 24.70 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [24.0, 25.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Marion']
*************************************************************** Georgia *************************************************************** # of counties: 159 # of fittings done = 0 *************************************************************** Florida *************************************************************** # of counties: 67 # of fittings done = 3 Miami-Dade: surge period 24.68 [day] Broward: surge period 25.81 [day] Palm Beach: surge period 29.17 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [24.0, 26.0] Bin 1 [26.0, 28.0] Bin 2 [28.0, 30.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Miami-Dade', 'Broward'] Group 1 ['Palm Beach']
*************************************************************** Ohio *************************************************************** # of counties: 88 # of fittings done = 1 Lucas: surge period 20.82 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [20.0, 21.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Lucas']
*************************************************************** Colorado *************************************************************** # of counties: 64 # of fittings done = 2 Arapahoe: surge period 26.32 [day] Denver: surge period 27.10 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [26.0, 28.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Arapahoe', 'Denver']
*************************************************************** California *************************************************************** # of counties: 58 # of fittings done = 3 Los Angeles: surge period 24.67 [day] Riverside: surge period 26.60 [day] San Diego: surge period 28.99 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [24.0, 26.0] Bin 1 [26.0, 28.0] Bin 2 [28.0, 30.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Los Angeles'] Group 1 ['Riverside'] Group 2 ['San Diego']
*************************************************************** Illinois *************************************************************** # of counties: 102 # of fittings done = 4 Lake: surge period 26.15 [day] Will: surge period 26.35 [day] DuPage: surge period 27.76 [day] Cook: surge period 28.24 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [26.0, 29.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['Lake', 'Will', 'DuPage', 'Cook']
*************************************************************** Missouri *************************************************************** # of counties: 115 # of fittings done = 0 *************************************************************** Washington *************************************************************** # of counties: 39 # of fittings done = 1 King: surge period 31.47 [day] ---------------------------------------------------------------- Bins ---------------------------------------------------------------- Bin 0 [31.0, 32.0] ---------------------------------------------------------------- County Groups ---------------------------------------------------------------- Group 0 ['King']