NY Times COVID-19 data visualization

Anton Antonov
​MathematicaForPrediction at WordPress​
​SystemModeling at GitHub​
March 2020
December 2020
January 2021

Introduction

The purpose of this notebook is to give data locations, data ingestion code, and code for rudimentary analysis and visualization of COVID-19 data provided by New York Times, [NYT1].
The following steps are taken:
◼
  • Ingest data
  • ◼
  • Take COVID-19 data from The New York Times, based on reports from state and local health agencies, [NYT1].
  • ◼
  • Take USA counties records data (FIPS codes, geo-coordinates, populations), [WRI1].
  • ◼
  • Merge the data.
  • ◼
  • Make data summaries and related plots.
  • ◼
  • Make corresponding geo-plots.
  • ◼
  • Do “out of the box” time series forecast.
  • ◼
  • Analyze fluctuations around time series trends.
  • Note that other, older repositories with COVID-19 data exist, like, [JH1, VK1].
    Remark: The time series section is done for illustration purposes only. The forecasts there should not be taken seriously.

    Import data

    NYTimes USA states data

    In[]:=
    dsNYDataStates=ResourceFunction["ImportCSVToDataset"]["https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv"];​​dsNYDataStates=dsNYDataStates[All,AssociationThread[Capitalize/@Keys[#],Values[#]]&];​​dsNYDataStates〚1;;6〛​​
    Out[]=
    Date
    State
    Fips
    Cases
    Deaths
    2020-01-21
    Washington
    53
    1
    0
    2020-01-22
    Washington
    53
    1
    0
    2020-01-23
    Washington
    53
    1
    0
    2020-01-24
    Illinois
    17
    1
    0
    2020-01-24
    Washington
    53
    1
    0
    2020-01-25
    California
    6
    1
    0
    In[]:=
    ResourceFunction["RecordsSummary"][dsNYDataStates]
    Out[]=
    
    1 Date
    2020-03-28
    55
    2020-03-29
    55
    2020-03-30
    55
    2020-03-31
    55
    2020-04-01
    55
    2020-04-02
    55
    (Other)
    17119
    ,
    2 State
    Washington
    359
    Illinois
    356
    California
    355
    Arizona
    354
    Massachusetts
    348
    Wisconsin
    344
    (Other)
    15333
    ,
    3 Fips
    Min
    1
    1st Qu
    17
    Median
    31
    Mean
    31.9093
    3rd Qu
    46
    Max
    78
    ,
    4 Cases
    Min
    1
    1st Qu
    4438.75
    Median
    33012
    Mean
    115145.
    3rd Qu
    129917.
    Max
    2857459
    ,
    5 Deaths
    Min
    0
    1st Qu
    96
    Median
    755
    Mean
    2931.98
    3rd Qu
    3255
    Max
    39760
    

    NYTimes USA counties data

    In[]:=
    dsNYDataCounties=ResourceFunction["ImportCSVToDataset"]["https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"];​​dsNYDataCounties=dsNYDataCounties[All,AssociationThread[Capitalize/@Keys[#],Values[#]]&];​​dsNYDataCounties〚1;;6〛
    Out[]=
    Date
    County
    State
    Fips
    Cases
    Deaths
    2020-01-21
    Snohomish
    Washington
    53061
    1
    0
    2020-01-22
    Snohomish
    Washington
    53061
    1
    0
    2020-01-23
    Snohomish
    Washington
    53061
    1
    0
    2020-01-24
    Cook
    Illinois
    17031
    1
    0
    2020-01-24
    Snohomish
    Washington
    53061
    1
    0
    2020-01-25
    Orange
    California
    6059
    1
    0
    In[]:=
    ResourceFunction["RecordsSummary"][dsNYDataCounties]
    Out[]=
    
    1 Date
    2020-10-18
    3248
    2020-10-17
    3247
    2020-11-17
    3247
    2020-11-18
    3247
    2020-11-19
    3247
    2020-11-20
    3247
    (Other)
    907525
    ,
    2 County
    Washington
    9180
    Unknown
    7842
    Jefferson
    7681
    Franklin
    7332
    Jackson
    6927
    Lincoln
    6889
    (Other)
    881157
    ,
    3 State
    Texas
    70304
    Georgia
    47289
    Virginia
    38615
    Kentucky
    34372
    Missouri
    32854
    Illinois
    29563
    (Other)
    674011
    ,
    4 Fips
    8664
    53061
    359
    17031
    356
    6059
    355
    4013
    354
    6037
    354
    (Other)
    916566
    ,
    5 Cases
    Min
    0
    1st Qu
    40
    Median
    257
    3rd Qu
    1114
    Mean
    2167.37
    Max
    958891
    ,
    6 Deaths
    0
    239662
    1
    91168
    2
    56117
    3
    38884
    4
    30966
    5
    24193
    (Other)
    446018
    

    US county records

    In[]:=
    dsUSACountyData=ResourceFunction["ImportCSVToDataset"]["https://raw.githubusercontent.com/antononcube/SystemModeling/master/Data/dfUSACountyRecords.csv"];​​dsUSACountyData=dsUSACountyData[All,Join[#,<|"FIPS"ToExpression[#FIPS]|>]&];​​dsUSACountyData〚1;;6〛
    Out[]=
    Country
    State
    County
    FIPS
    Population
    Lat
    Lon
    UnitedStates
    SouthCarolina
    AbbevilleCounty
    45001
    24932
    34.2226
    -82.4587
    UnitedStates
    Louisiana
    AcadiaParish
    22001
    62577
    30.2906
    -92.412
    UnitedStates
    Virginia
    AccomackCounty
    51001
    32973
    37.7626
    -75.6321
    UnitedStates
    Idaho
    AdaCounty
    16001
    434211
    43.4511
    -116.241
    UnitedStates
    Iowa
    AdairCounty
    19001
    7228
    41.3307
    -94.471
    UnitedStates
    Kentucky
    AdairCounty
    21001
    19027
    37.1042
    -85.2806
    In[]:=
    ResourceFunction["RecordsSummary"][dsUSACountyData]
    Out[]=
    
    1 Country
    UnitedStates
    3143
    ,
    2 State
    Texas
    254
    Georgia
    159
    Virginia
    134
    Kentucky
    120
    Missouri
    115
    Kansas
    105
    (Other)
    2256
    ,
    3 County
    WashingtonCounty
    30
    JeffersonCounty
    25
    FranklinCounty
    24
    JacksonCounty
    23
    LincolnCounty
    23
    MadisonCounty
    19
    (Other)
    2999
    ,
    4 FIPS
    Min
    1001
    1st Qu
    18177.5
    Median
    29177
    Mean
    30390.4
    3rd Qu
    45082.5
    Max
    56045
    ,
    5 Population
    Min
    89
    1st Qu
    10980
    Median
    25690
    3rd Qu
    67527.5
    Mean
    102248.
    Max
    10170292
    ,
    6 Lat
    Min
    19.6012
    1st Qu
    34.7014
    Median
    38.3717
    Mean
    38.456
    3rd Qu
    41.8074
    Max
    69.3047
    ,
    7 Lon
    Min
    -166.901
    1st Qu
    -98.2325
    Mean
    -92.2813
    Median
    -90.3965
    3rd Qu
    -83.4334
    Max
    -67.629
    

    Merge data

    Verify that the two datasets have common FIPS codes:
    In[]:=
    Length[Intersection[Normal[dsUSACountyData[All,"FIPS"]],Normal[dsNYDataCounties[All,"Fips"]]]]
    Out[]=
    3133
    Merge the datasets:
    In[]:=
    dsNYDataCountiesExtended=Dataset[JoinAcross[Normal[dsNYDataCounties],Normal[dsUSACountyData[All,{"FIPS","Lat","Lon","Population"}]],Key["Fips"]->Key["FIPS"]]];
    Add a “DateObject” column and (reverse) sort by date:
    In[]:=
    dsNYDataCountiesExtended=dsNYDataCountiesExtended[All,Join[<|"DateObject"DateObject[#Date]|>,#]&];​​dsNYDataCountiesExtended=dsNYDataCountiesExtended[ReverseSortBy[#DateObject&]];​​dsNYDataCountiesExtended〚1;;6〛
    Out[]=
    DateObject
    Date
    County
    State
    Fips
    Cases
    Deaths
    FIPS
    Lat
    Lon
    Wed 13 Jan 2021
    2021-01-13
    Ziebach
    South Dakota
    46137
    326
    8
    46137
    44.9806
    -101.666
    Wed 13 Jan 2021
    2021-01-13
    Zavala
    Texas
    48507
    1151
    28
    48507
    28.8662
    -99.7606
    Wed 13 Jan 2021
    2021-01-13
    Zapata
    Texas
    48505
    1266
    15
    48505
    27.0007
    -99.1686
    Wed 13 Jan 2021
    2021-01-13
    Yuma
    Colorado
    8125
    601
    14
    8125
    40.0029
    -102.424
    Wed 13 Jan 2021
    2021-01-13
    Yuma
    Arizona
    4027
    31789
    601
    4027
    32.7694
    -113.906
    Wed 13 Jan 2021
    2021-01-13
    Yukon-Koyukuk
    Census Area
    Alaska
    2290
    243
    4
    2290
    65.5096
    -151.388
    columns 1–10 of 11

    Basic data analysis

    We consider cases and deaths for the last date only. (The queries can easily adjusted for other dates.)
    In[]:=
    dfQuery=dsNYDataCountiesExtended[Select[#Date==dsNYDataCountiesExtended[1,"Date"]&],{"FIPS","Cases","Deaths"}];​​dfQuery=dfQuery[All,Prepend[#,"FIPS"ToString[#FIPS]]&];
    In[]:=
    Total[dfQuery[All,{"Cases","Deaths"}]]
    Out[]=
    Cases22387340,Deaths355736
    Here is the summary of the values of cases and deaths across the different USA counties:
    In[]:=
    ResourceFunction["RecordsSummary"][dfQuery]
    Out[]=
    
    1 FIPS
    10001
    1
    10003
    1
    10005
    1
    1001
    1
    1003
    1
    1005
    1
    (Other)
    3127
    ,
    2 Cases
    Min
    1
    1st Qu
    773.75
    Median
    1856
    3rd Qu
    4799.25
    Mean
    7145.66
    Max
    958891
    ,
    3 Deaths
    Min
    0
    1st Qu
    11
    Median
    31
    3rd Qu
    74.25
    Mean
    113.545
    Max
    12955
    
    The following table of plots shows the distributions of cases and deaths and the correspond Pareto principle adherence plots:
    A couple of observations:
    ◼
  • The logarithms of the cases and deaths have nearly Normal or Logistic distributions.
  • Distributions

    Here we find the distributions that correspond to the cases and deaths (using FindDistribution):

    Pareto principle locations

    Geo-histogram

    Heat-map plots

    An alternative of the geo-visualization is to use a heat-map plot. Here we use the package "HeatmapPlot.m", [AAp1].

    Cases

    Cross-tabulate states with dates over cases:
    Make a heat-map plot by sorting the columns of the cross-tabulation matrix (that correspond to states):

    Deaths

    Cross-tabulate states with dates over deaths and plot:

    Time series analysis

    Cases

    Time series

    For each date sum all cases over the states, make a time series, and plot it:
    Logarithmic plot:

    “Forecast”

    Fit a time series model to log 10 of the time series:
    Plot log 10 data and forecast:
    Plot data and forecast:

    Deaths

    Time series

    For each date sum all cases over the states, make a time series, and plot it:

    “Forecast”

    Fit a time series model:
    Plot data and forecast:

    Fluctuations

    We want to see does the time series data have fluctuations around its trends and estimate the distributions of those fluctuations. (Knowing those distributions some further studies can be done.)
    This can be efficiently using the software monad QRMon, [AAp2, AA1]. Here we load the QRMon package:

    Fluctuations presence

    Here we plot the consecutive differences of the cases:
    Here we plot the consecutive differences of the deaths:
    From the plots we see that time series are not monotonically increasing, and there are non-trivial fluctuations in the data.

    Absolute and relative errors distributions

    Here we take interesting part of the cases data:
    Here we specify QRMon workflow that rescales the data, fits a B-spline curve to get the trend, and finds the absolute and relative errors (residuals, fluctuations) around that trend:
    Here we find the distribution of the absolute errors (fluctuations) using FindDistribution:
    Here we find the distribution of the of the relative errors:

    References

    [NYT1] The New York Times, Coronavirus (Covid-19) Data in the United States, (2020), GitHub.
    [WRI1] Wolfram Research Inc., USA county records, (2020), System Modeling at GitHub.
    [JH1] CSSE at Johns Hopkins University, COVID-19, (2020), GitHub.
    [VK1] Vitaliy Kaurov, Resources For Novel Coronavirus COVID-19, (2020), community.wolfram.com.
    [AA1] Anton Antonov, "A monad for Quantile Regression workflows", (2018), at MathematicaForPrediction WordPress.
    [AAp1] Anton Antonov, Heatmap plot Mathematica package, (2018), MathematicaForPrediciton at GitHub.
    [AAp2] Anton Antonov, Monadic Quantile Regression Mathematica package, (2018), MathematicaForPrediciton at GitHub.