Function Repository Resource:

VAERSData

Source Notebook

Import Vaccine Adverse Event Reporting System data

Contributed by: Bob Sandheinrich

ResourceFunction["VAERSData"][dir]

imports Vaccine Adverse Event Reporting System data from the directory dir.

ResourceFunction["VAERSData"][zip]

imports Vaccine Adverse Event Reporting System data from a ZIP file.

ResourceFunction["VAERSData"][{zip,dir}]

exports zip to the specified directory before importing.

ResourceFunction["VAERSData"][,elem]

imports the specified element elem.

ResourceFunction["VAERSData"][,id]

returns all data associated with VAERS ID id.

ResourceFunction["VAERSData"][,{id,elem}]

returns elem data for VAERS ID id.

ResourceFunction["VAERSData"][data,spec]

extracts the data specified by spec from the imported data.

ResourceFunction["VAERSData"][]

opens the VAERS data download website to acquire new data.

Details

The VAERS website requires manual download, so the data must be downloaded locally before it can be imported.
Supported elements are:
"Reports" (default)text descriptions of symptons along with dates, locations, ages and a VAERS ID number.
"Symptoms"symptoms for each VAERS ID
"Vaccines"information on vaccinations
"IDEventSeries"an EventSeries containing "VAERS_ID" values for each date
"Merged"a single Dataset containing combined report, vaccine and symptom data
ResourceFunction["VAERSData"] has built in caching on interpretation.
The spec can be:
ida VAERS ID
{id,elem}a VAERS ID and one of the elements listed above
{{id1,id2,}}combined data for several VAERS IDs
<|propval|>an Association of vaccine properties
Vaccine properties supported by prop include: "VAX_TYPE", "VAX_MANU", "VAX_LOT", "VAX_DOSE_SERIES", "VAX_ROUTE", "VAX_SITE" and "VAX_NAME".
Using the "Merged" element is faster for conducting repeated queries than using <|propval|> spec.

Examples

Basic Examples (3) 

Open the VAERS website to download the latest data:

In[1]:=
ResourceFunction["VAERSData"][]

Import data from the downloaded ZIP file (this takes a few minutes the first time but is faster thereafter):

In[2]:=
AbsoluteTiming[
 data = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip"];]
Out[2]=

See a random sample of the data:

In[3]:=
RandomSample[data, 20]
Out[3]=

Find reactions to the Pfizer COVID-19 vaccine:

In[4]:=
ResourceFunction[
 "VAERSData"]["/your path/to/download/2021VAERSData.zip", <|
  "VAX_TYPE" -> "COVID19", "VAX_MANU" -> "PFIZER\\BIONTECH"|>]
Out[4]=

Scope (4) 

Import symptom data:

In[5]:=
AbsoluteTiming[
 sympdata = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", "Symptoms"];]
Out[5]=

See how long the data is:

In[6]:=
Length[sympdata]
Out[6]=

See the columns in the data:

In[7]:=
Normal@sympdata[1, Keys]
Out[7]=

Find the most common symptoms:

In[8]:=
TakeLargest[
 Counts[Flatten@
   Normal@Values@
     sympdata[
      All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}]], 20]
Out[8]=

Get a TimeSeries of "VAERS_ID" values:

In[9]:=
es = ResourceFunction["VAERSData"][
  "/your path/to/download/2021VAERSData.zip", "IDEventSeries"]
Out[9]=

Find the number of events reported each day:

In[10]:=
eventsPerDay = TimeSeriesMap[Length[#"VAERS_IDs"] &, es]
Out[10]=

Plot the number of reported events over time along with a moving average:

In[11]:=
DateListPlot[{eventsPerDay, MovingMap[Mean, eventsPerDay, Quantity[14, "Days"]]}]
Out[11]=

Import the vaccine data:

In[12]:=
AbsoluteTiming[
 vaxdata = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", "Vaccines"];]
Out[12]=

See how long the data is:

In[13]:=
Length[vaxdata]
Out[13]=

See the columns in the data:

In[14]:=
Normal@vaxdata[1, Keys]
Out[14]=

See the 10 most common vaccine types:

In[15]:=
vaxdata[Counts/*TakeLargest[10], "VAX_TYPE"]
Out[15]=

See the most common manufacturers:

In[16]:=
vaxdata[Counts/*TakeLargest[10], "VAX_MANU"]
Out[16]=

Import all the data:

In[17]:=
AbsoluteTiming[
 alldata = ResourceFunction["VAERSData"][
    "/Users/bobs/Downloads/2021VAERSData (2).zip", All];]
Out[17]=

See how big it is:

In[18]:=
ByteCount /@ alldata
Out[18]=

Find all the information about a specific VAERS ID by passing the data back to VAERSData:

In[19]:=
results = ResourceFunction["VAERSData"][alldata, 1097798];
Head /@ results
Out[19]=

See the vaccine associated with the VAERS ID:

In[20]:=
results["Vaccines"]
Out[20]=

See the reports, while shortening long text:

In[21]:=
results["Reports"][All, All, # /. str_String :> Snippet[str] &]
Out[21]=

See the symptoms:

In[22]:=
results["Symptoms"]
Out[22]=

Get the symptoms directly:

In[23]:=
ResourceFunction["VAERSData"][alldata, {1097798, "Symptoms"}]
Out[23]=

Applications (27) 

Comparing COVID-19 vaccine reaction symptoms (5) 

Get all the data:

In[24]:=
AbsoluteTiming[
 alldata = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", All];]
Out[24]=

Get VAERS IDs for each manufacturer:

In[25]:=
pfizerids = DeleteDuplicates@
  Normal@ResourceFunction["VAERSData"][
     alldata["Vaccines"], <|"VAX_TYPE" -> "COVID19", "VAX_MANU" -> "PFIZER\\BIONTECH"|>][All, "VAERS_ID"]
Out[25]=
In[26]:=
modernaids = DeleteDuplicates@
  Normal@ResourceFunction["VAERSData"][
     alldata["Vaccines"], <|"VAX_TYPE" -> "COVID19", "VAX_MANU" -> "MODERNA"|>][All, "VAERS_ID"]
Out[26]=
In[27]:=
jnjids = DeleteDuplicates@
  Normal@ResourceFunction["VAERSData"][
     alldata["Vaccines"], <|"VAX_TYPE" -> "COVID19", "VAX_MANU" -> "JANSSEN"|>][All, "VAERS_ID"]
Out[27]=

Find the all the reported symptoms for each manufacturer. This is slow:

In[28]:=
AbsoluteTiming[
 pfizersymptoms = ResourceFunction["VAERSData"][alldata["Symptoms"], {pfizerids}];]
Out[28]=
In[29]:=
AbsoluteTiming[
 modernasymptoms = ResourceFunction["VAERSData"][alldata["Symptoms"], {modernaids}];]
Out[29]=
In[30]:=
AbsoluteTiming[
 jnjsymptoms = ResourceFunction["VAERSData"][alldata["Symptoms"], {jnjids}];]
Out[30]=

Count the number of reports of each symptom for each manufacturer:

In[31]:=
pfizercounts = ResourceFunction["Proportions"]@
   DeleteCases[
    Flatten@Normal@
      Values@pfizersymptoms[
        All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}], ""];
In[32]:=
modernacounts = ResourceFunction["Proportions"]@
   DeleteCases[
    Flatten@Normal@
      Values@modernasymptoms[
        All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}], ""];
In[33]:=
jnjcounts = ResourceFunction["Proportions"]@
   DeleteCases[
    Flatten@Normal@
      Values@jnjsymptoms[
        All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}], ""];

Plot the most common symptoms for each manufacturer as a BarChart:

In[34]:=
k = DeleteDuplicates[
  Flatten[Keys[
    TakeLargest[25] /@ {pfizercounts, modernacounts, jnjcounts}]]]
Out[34]=
In[35]:=
BarChart[Transpose[
  Lookup[k] /@ {pfizercounts, modernacounts, jnjcounts}], ChartLabels -> {Placed[k, Axis, Rotate[#, Pi/2] &], None}, ChartLegends -> {"Pfizer", "Moderna", "JohnsonAndJohnson"}]
Out[35]=

Querying data (4) 

Retrieve the datasets:

In[36]:=
AbsoluteTiming[
 alldata = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", All];]
Out[36]=

Find reports for patients between four and eight years old:

In[37]:=
kids = alldata["Reports"][
   Select[Quantity[4, "Years"] < #"AGE_YRS" < Quantity[9, "Years"] &]];
In[38]:=
Length[kids]
Out[38]=

Retrieve vaccine information for those patients:

In[39]:=
AbsoluteTiming[
 kidscovid = kids[Select[
     Function[k, SelectFirst[
         alldata["Vaccines"], #["VAERS_ID"] === k["VAERS_ID"] &][
        "VAX_TYPE"] === "COVID19"]]];]
Out[39]=
In[40]:=
Length[kidscovid]
Out[40]=

See the resulting data:

In[41]:=
kidscovid
Out[41]=

Finding symptoms over time (10) 

Get a TimeSeries of all "VAERS_ID" values:

In[42]:=
es = ResourceFunction["VAERSData"][
  "/your path/to/download/2021VAERSData.zip", "IDEventSeries"]
Out[42]=

Import the full dataset for searching:

In[43]:=
AbsoluteTiming[
 alldata = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", All];]
Out[43]=

Get the VAERS IDs for Pfizer COVID-19 vaccinations:

In[44]:=
pfizerids = DeleteDuplicates@
   Normal@ResourceFunction["VAERSData"][
      alldata["Vaccines"], <|"VAX_TYPE" -> "COVID19", "VAX_MANU" -> "PFIZER\\BIONTECH"|>][All, "VAERS_ID"];

Get the time series for those IDs:

In[45]:=
pfizerES = TimeSeriesMap[<|
    "VAERS_IDs" -> Intersection[#["VAERS_IDs"] /. _Missing -> {}, pfizerids]|> &, es]
Out[45]=

Plot the number of Pfizer reports and total number of reports over time:

In[46]:=
eventsPerDay = TimeSeriesMap[Length[#["VAERS_IDs"]] &, es];
In[47]:=
pfizerPerDay = TimeSeriesMap[Length[#["VAERS_IDs"]] &, pfizerES];
In[48]:=
DateListPlot[{MovingMap[Mean, pfizerPerDay, Quantity[14, "Days"]], MovingMap[Mean, eventsPerDay, Quantity[14, "Days"]]}]
Out[48]=

Define a function to find symptoms for events on a specific day for a specific vaccine:

In[49]:=
vaccineDaySymptoms[vaccine_, day_] := ResourceFunction["VAERSData"][alldata["Symptoms"], es[day]["VAERS_IDs"]]

Find Johnson & Johnson symptoms on May 5:

In[50]:=
AbsoluteTiming[
 jnjMay5 = vaccineDaySymptoms["JANSSEN", DateObject["May 5, 2021"]];]
Out[50]=
In[51]:=
Length[jnjMay5]
Out[51]=

Show the most common symptoms:

In[52]:=
KeyDrop[TakeLargest[
  Counts@Flatten@
    Normal@Values@
      jnjMay5[All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}], 10], ""]
Out[52]=

Repeat this for the first day of each month:

In[53]:=
AbsoluteTiming[
 jnjFirstOfTheMonth = Table[vaccineDaySymptoms["JANSSEN", DateObject[{2021, month, 1}]], {month, 3, 8}];]
Out[53]=

Get the tallies:

In[54]:=
jnjFirstOfTheMonthCounts = KeyDrop[Counts@
      Flatten@Normal@
        Values@#[
          All, {"SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"}], ""] & /@ jnjFirstOfTheMonth;
In[55]:=
DateListPlot[{DateObject[{2021, #, 1}] & /@ Range[3, 8], Lookup["Headache"] /@ jnjFirstOfTheMonthCounts}\[Transpose], Joined -> False, Filling -> Axis, PlotLabel -> "Johnson and Johnson headaches reported on the 1st of each month"]
Out[55]=

Using a single merged dataset (8) 

Compute the time needed to download the VAERS data:

In[56]:=
AbsoluteTiming[
 merged = ResourceFunction["VAERSData"][
    "/your path/to/download/2021VAERSData.zip", "Merged"];]
Out[56]=

Save the combined data for future use:

In[57]:=
Export["CombinedVAERSData-" <> DateString["ISODate"] <> ".mx", merged];

Work with the combined dataset. Query an age range:

In[58]:=
teens = merged[Select[13 <= QuantityMagnitude[#"AGE_YRS"] <= 19 &]];
In[59]:=
Length[teens]
Out[59]=

See a sample:

In[60]:=
RandomSample[teens, 5]
Out[60]=

Within the age range, count reports by sex:

In[61]:=
Counts[teens[All, "SEX"]]
Out[61]=

Within the age range, find non-COVID vaccine reports:

In[62]:=
noncovid = teens[Select[! MemberQ[#Vaccines[[All, "VAX_TYPE"]], "COVID19"] &]]
Out[62]=

Find COVID-19 vaccination reports in the age range:

In[63]:=
teenscovid = teens[Select[MemberQ[#Vaccines[[All, "VAX_TYPE"]], "COVID19"] &]]
Out[63]=

Show the number of reports over time as a histogram:

In[64]:=
DateHistogram[teenscovid[All, "RECVDATE"]]
Out[64]=

Publisher

Bob

Version History

  • 1.0.0 – 07 September 2021

Related Resources

License Information