Wolfram Research

Function Repository Resource:

COVIDTrackingData

Source Notebook

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 and Options

Available data types are "US", "USDaily", "States", "StatesDaily", "StateInformation" and "URLs". The default type is "StatesDaily".
The data is imported from the The COVID Tracking Project API.

Examples

Basic Examples

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[6]=

Get time series data:

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

Scope

Plot the number of hospitalizations in the data:

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

Show positive test result counts:

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

Applications

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

In[11]:=
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[12]:=
testingdata = Prepend[DeleteMissing@
   ResourceFunction["COVIDTrackingData"][][GroupBy["State"], ReverseSortBy["Date"] /* findupdateddata],
  All -> Normal[
    Append[KeyDrop[First@ResourceFunction["COVIDTrackingData"]["US"], "States"], "State" -> All]]]
Out[12]=

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

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

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

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

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

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

Get the new deaths in each state:

In[16]:=
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[16]=

Plot the new deaths in each state:

In[17]:=
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[17]=

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

In[18]:=
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[18]=

Resource History

Related Resources

License Information