This resource function is obsolete. Use the data resource Epidemic Data for Novel Coronavirus COVID-19 instead.

Function Repository Resource:

COVIDTrackingData

Source Notebook

Obsolete. Import data about COVID-19 in the US from the COVID Tracking Project

Contributed by: Bob Sandheinrich

ResourceFunction["COVIDTrackingData"][type]

retrieves data of the specified type from the COVID Tracking Project.

Details

IMPORTANT NOTE: ResourceFunction["COVIDTrackingData"] ended data collection on March 7th 2021. The API and this resource function will stop working as of May 2021. Consider using the data resource Epidemic Data for Novel Coronavirus COVID-19 or the other resources listed here.
Available data types are "US", "USDaily", "States", "StatesDaily", "StateInformation" and "URLs". The default type is "StatesDaily".
The data is imported from the COVID Tracking Project API.

Examples

Basic Examples (6) 

Get the latest five days of national data:

In[1]:=
Take[ResourceFunction["COVIDTrackingData"]["USDaily"], 5]
Out[1]=

Current US data:

In[2]:=
ResourceFunction["COVIDTrackingData"]["US"]
Out[2]=

Get a sample of daily data on each state:

In[3]:=
RandomSample[ResourceFunction["COVIDTrackingData"]["StatesDaily"], 5]
Out[3]=

Current state data:

In[4]:=
RandomSample[ResourceFunction["COVIDTrackingData"]["States"], 5]
Out[4]=

Get state information:

In[5]:=
ResourceFunction["COVIDTrackingData"]["StateInformation"]
Out[5]=

Get time series data:

In[6]:=
timeseries = ResourceFunction["COVIDTrackingData"]["StatesDaily"][
   GroupBy["State"], AssociationMap[
     Function[key, TimeSeries[Lookup[#, key], {Lookup[#, "Date"]}]], {"Positive", "Negative", "Death"}] &];
In[7]:=
DateListPlot[#, PlotRange -> All] & /@ Transpose[Normal[timeseries]]
Out[7]=

Scope (2) 

Plot the number of hospitalizations in the data:

In[8]:=
ResourceFunction["COVIDTrackingData"]["USDaily"][
 Select[IntegerQ[#Hospitalized] &]/*DateListPlot, {"Date", "Hospitalized"}]
Out[8]=

Show positive test result counts:

In[9]:=
ResourceFunction["COVIDTrackingData"]["USDaily"][
 Select[IntegerQ[#Positive] &]/*DateListPlot, {"Date", "Positive"}]
Out[9]=

Applications (3) 

For each state, find the most recent date with positive and negative testing results:

In[10]:=
findupdateddata[{___, KeyValuePattern[{"DateChecked" -> dc_, "Death" -> d_, "Positive" -> p1_, "Negative" -> n1_}], KeyValuePattern[{"Positive" -> p2_, "Negative" -> n2_}], ___} /; p1 =!= p2 && n1 =!= n2] := Association @@ {"Positive" -> p1, "Negative" -> n1, "Death" -> d, "DateChecked" -> dc}
findupdateddata[_] := Missing[]
In[11]:=
testingdata = Prepend[DeleteMissing@
   ResourceFunction["COVIDTrackingData"][][GroupBy["State"], ReverseSortBy["Date"]/*findupdateddata],
  All -> Normal[Append[
     KeyDrop[First@ResourceFunction["COVIDTrackingData"]["US"], "States"], "State" -> All]]]
Out[11]=

See how positive test rates depend on the number of tests:

In[12]:=
testingdata[
 DeleteMissing/*(ListLogLinearPlot[#, PlotLabel -> "Positive Test Rate vs Number of Tests Conducted", PlotRange -> Full] &), {(#Positive + #Negative), N[#Positive/(#Positive + #Negative)]} &]
Out[12]=

See if deaths per positive test are dependent on the amount of testing:

In[13]:=
testingdata[Select[#Positive > 0 &]][
 DeleteMissing/*(ListLogLinearPlot[#, PlotLabel -> "Death Rate vs Number of Tests Conducted", PlotRange -> Full] &), {(#Positive + #Negative), N[#Death/(#Positive)]} &]
Out[13]=

See if deaths per positive test are correlated with the positive testing percent:

In[14]:=
testingdata[Select[#Positive > 0 &]][
 DeleteMissing/*(ListPlot[#, PlotLabel -> "Death Rate vs Number of Tests Conducted", PlotRange -> Full] &), {N[#Positive/(#Positive + #Negative)], N[#Death/(#Positive)]} &]
Out[14]=

Get the new deaths in each state:

In[15]:=
deathsdata = Prepend[
   ResourceFunction["COVIDTrackingData"][][GroupBy["State"], SortBy["Date"]/*Select[#Death > 5 &]],
   All -> Normal[ResourceFunction["COVIDTrackingData"]["USDaily"][
      Select[! MissingQ[#Death] &]/*SortBy["Date"]]
     ]][Select[Length[#] > 0 &]]
Out[15]=

Plot the new deaths in each state:

In[16]:=
DateListPlot[
 deathsdata[All, TimeSeries[
     Transpose[{Most[Lookup[#, "DateChecked"]], Differences[Lookup[#, "Death"]]}]] &][Select[Max[#] > 10 &]], PlotRange -> Full, PlotLabel -> "New Deaths Per State", PlotStyle -> Prepend[Table[Automatic, 50], Directive[Red, Dashed]]]
Out[16]=

Show the smoothed daily proportional increase in deaths in each state:

In[17]:=
DateListPlot[
 deathsdata[Select[Last[Lookup[#, "Death"]] > 20 &], MovingAverage[
    TimeSeries[
     Transpose[{Most[Lookup[#, "DateChecked"]], Ratios[Lookup[#, "Death"]]}]], Quantity[2, "Days"]] &], Sequence[
 PlotRange -> {{"March 14", Automatic}, {1, 2}}, PlotLabel -> "Death Increase Ratio Per State", PlotStyle -> Prepend[
Table[Automatic, 50], 
Directive[Red, 
Thickness[0.01], Dashed]]]]
Out[17]=

Publisher

Bob

Version History

  • 4.0.0 – 05 April 2021
  • 3.0.0 – 15 July 2020
  • 2.0.0 – 30 April 2020
  • 1.0.0 – 27 March 2020

Related Resources

License Information