Wolfram Research

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: COVIDTRACKING 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

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]:=
DateListPlot[#, PlotRange -> All] & /@ Transpose[Normal[timeseries]]
Out[6]=

Scope

Plot the number of hospitalizations in the data:

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

Show positive test result counts:

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

Applications

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

In[9]:=
testingdata = Prepend[DeleteMissing@
   ResourceFunction["COVIDTrackingData"][][GroupBy["State"], ReverseSortBy["Date"] /* findupdateddata],
  All -> Normal[
    Append[KeyDrop[First@ResourceFunction["COVIDTrackingData"]["US"], "States"], "State" -> All]]]
Out[9]=

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

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

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

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

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

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

Get the new deaths in each state:

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

Plot the new deaths in each state:

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

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

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

Resource History

Related Resources

License Information