I Used the R Package EpiCurve to Make an Epidemiologic Curve. Here’s How It Turned Out.

Epidemiologic Curve of 2015 Middle East Respiratory Virus Outbreak Using R EpiCurve Package

With all this talk about “flattening the curve” of the coronavirus, I thought I would get into the weeds about what curve we are talking about when we say that. We are talking about what’s called an epidemiologic curve, or epicurve for short. And to demonstrate what an epicurve is and what it means, I used the R package EpiCurve to demonstrate making an epidemiologic curve so you can see how it works.

Source Data for my Epicurve

I actually back-engineered the data for my dataset based on viewing the epicurve in this article from Morbidity and Mortality Weekly Report of a nosocomial outbreak of Middle East respiratory syndrome (MERS) at King Abdulaziz Medical City in Riyadh, Saudi Arabia in June through August, 2015.

The downside to back-engineering data is that it might have errors, but the advantage is that I can assemble it into the perfect structure for the R package EpiCurve. If you look in the article, they have an epicurve, but they don’t include the raw numbers, so I just guessed the data. The data I guessed are below.

RowIDStart_of_WeekEnd_of_WeekFrequencySource
12015-05-312015-06-060Non-HCW
22015-06-072015-06-130Non-HCW
32015-06-142015-06-201Non-HCW
42015-06-212015-06-270Non-HCW
52015-06-282015-07-040Non-HCW
62015-07-052015-07-111Non-HCW
72015-07-122015-07-185Non-HCW
82015-07-192015-07-252HCW
92015-07-192015-07-256Non-HCW
102015-07-262015-08-014HCW
112015-07-262015-08-0111Non-HCW
122015-08-022015-08-084HCW
132015-08-022015-08-0821Non-HCW
142015-08-092015-08-1512HCW
152015-08-092015-08-1526Non-HCW
162015-08-162015-08-2213HCW
172015-08-162015-08-2210Non-HCW
182015-08-232015-08-296HCW
192015-08-232015-08-294Non-HCW
202015-08-302015-09-050HCW
212015-08-302015-09-051Non-HCW
222015-09-062015-09-120HCW
232015-09-062015-09-120Non-HCW

Variables for the R Package EpiCurve

Let’s look more closely at each variable:

  • RowID: This is just the number of the row. I always include this as a unique identifier in tables.
  • Start_of_Week: The epicurve in the article presents each frequency bar as representing a week. This variable is the day at the start of the week.
  • End_of_Week: This is the day at the end of the week.
  • Frequency: This is the number of cases for the week from the specified Source (see next column).
  • Source: You will see in the epicurve in the article, each bar is color-coded for healthcare worker (HCW) or non-HCW. To facilitate this color coding, each category needs its own row. You will see in the first rows, there were no cases, so I just put one row, randomly assigned it a source, and put 0. In rows 6 and 7, only non-HCW’s were cases, so those weeks have only one row. Whenever there were HCW and non-HCW identified as cases in the same week, they were each expressed in their own row.

Programming for the R EpiCurve Package

First, I knew I’d need two colors – one for HCW and one for non-HCW so I used the Coolors app and the logo for the Saudi Arabia Ministry of Health to pick my colors in hexadecimal. Once I selected them, I loaded them into variables, one called saudi_gold and one called saudi_green.

saudi_gold <- c("#806222")
saudi_green <- c("#045c20")

That way, I could just refer to them as saudi_gold and saudi_green when programming.

Next, after installing the EpiCurve package, I called up the library, and made these specifications to get the epicurve shown at the top the post.

library(EpiCurve)
EpiCurve(MERS,
date= "Start_of_Week",
period = "day",
to.period = "week",
freq = "Frequency",
cutvar = "Source",
colors = c(saudi_gold, saudi_green),
title = c("MERS at KAMC 2015 from MMWR"),
ylabel = c("Number of cases"),
xlabel = c("Week of 2015"))

Here are some important parts of the code above:

  • The EpiCurve package handles dates in factor format! In fact, converting them to date won’t work. So as you can see in the code above, where date=”Start_of_Week”, that date variable – as well as the date variable End_of_Week – are both actually in factor format.
  • Period and to.period: These had be correct in order for the date frequency to collapse and come out right as weeks. Many epicurves are by days, so if period=day and the data are daily so they do not have to be collapsed into weeks or months, the to.period argument can be left out.
  • Cutvar is the command to specify the categories: The argument curtvar=”Source” is what facilitated the epicurve looking at the categorical column Source that separates HCW and Non-HCW data.
  • Colors are specified using the variables set: This makes it easier to see what colors are being specified. You will see that between cutvar and the colors specification, the legend is automatically output.

Where the Epicurve Starts Flattening

Epidemiologic Curve of 2015 Middle East Respiratory Virus Outbreak Using R EpiCurve Package Annotated

The reason we make an epicurve during an epidemic is that in addition to tracking the mortality rate, we are interested in tracking when the curve actually begins to flatten. Note where I annotated the epicurve from the MERS article to point out the week that that curve finally flattened. When the curve finally flattens, you are literally “on the other side” of the outbreak. The problem is that during the epidemic you never really know you are there until you get there, and the day or week you are in finally sees fewer new cases than the day or week before.

As you proceed through the epidemic, as long as you keep formatting your data the way I demonstrated, you can keep adding to it and generating a new epicurve every day.

Read all of our data science blog posts!

Apply Weights? It’s Easy in R with the Survey Package!

Apply weights to get weighted proportions and counts! Read my blog post to learn how [...]

Make Categorical Variable Out of Continuous Variable

Make categorical variables by cutting up continuous ones. But where to put the boundaries? Get [...]

Remove Rows in R with the Subset Command

Remove rows by criteria is a common ETL operation – and my blog post shows [...]

CDC Wonder for Studying Vaccine Adverse Events: The Shameful State of US Open Government Data

CDC Wonder is an online query portal that serves as a gateway to many government [...]

AI Careers: Riding the Bubble

AI careers are not easy to navigate. Read my blog post for foolproof advice for [...]

Descriptive Analysis of Black Friday Death Count Database: Creative Classification

Descriptive analysis of Black Friday Death Count Database provides an example of how creative classification [...]

Classification Crosswalks: Strategies in Data Transformation

Classification crosswalks are easy to make, and can help you reduce cardinality in categorical variables, [...]

FAERS Data: Getting Creative with an Adverse Event Surveillance Dashboard

FAERS data are like any post-market surveillance pharmacy data – notoriously messy. But if you [...]

Dataset Source Documentation: Necessary for Data Science Projects with Multiple Data Sources

Dataset source documentation is good to keep when you are doing an analysis with data [...]

Joins in Base R: Alternative to SQL-like dplyr

Joins in base R must be executed properly or you will lose data. Read my [...]

NHANES Data: Pitfalls, Pranks, Possibilities, and Practical Advice

NHANES data piqued your interest? It’s not all sunshine and roses. Read my blog post [...]

Color in Visualizations: Using it to its Full Communicative Advantage

Color in visualizations of data curation and other data science documentation can be used to [...]

Defaults in PowerPoint: Setting Them Up for Data Visualizations

Defaults in PowerPoint are set up for slides – not data visualizations. Read my blog [...]

Text and Arrows in Dataviz Can Greatly Improve Understanding

Text and arrows in dataviz, if used wisely, can help your audience understand something very [...]

Shapes and Images in Dataviz: Making Choices for Optimal Communication

Shapes and images in dataviz, if chosen wisely, can greatly enhance the communicative value of [...]

Table Editing in R is Easy! Here Are a Few Tricks…

Table editing in R is easier than in SAS, because you can refer to columns, [...]

R for Logistic Regression: Example from Epidemiology and Biostatistics

R for logistic regression in health data analytics is a reasonable choice, if you know [...]

1 Comments

Connecting SAS to Other Applications: Different Strategies

Connecting SAS to other applications is often necessary, and there are many ways to do [...]

Portfolio Project Examples for Independent Data Science Projects

Portfolio project examples are sometimes needed for newbies in data science who are looking to [...]

Project Management Terminology for Public Health Data Scientists

Project management terminology is often used around epidemiologists, biostatisticians, and health data scientists, and it’s [...]

Rapid Application Development Public Health Style

“Rapid application development” (RAD) refers to an approach to designing and developing computer applications. In [...]

Understanding Legacy Data in a Relational World

Understanding legacy data is necessary if you want to analyze datasets that are extracted from [...]

Front-end Decisions Impact Back-end Data (and Your Data Science Experience!)

Front-end decisions are made when applications are designed. They are even made when you design [...]

Reducing Query Cost (and Making Better Use of Your Time)

Reducing query cost is especially important in SAS – but do you know how to [...]

Curated Datasets: Great for Data Science Portfolio Projects!

Curated datasets are useful to know about if you want to do a data science [...]

Statistics Trivia for Data Scientists

Statistics trivia for data scientists will refresh your memory from the courses you’ve taken – [...]

Management Tips for Data Scientists

Management tips for data scientists can be used by anyone – at work and in [...]

REDCap Mess: How it Got There, and How to Clean it Up

REDCap mess happens often in research shops, and it’s an analysis showstopper! Read my blog [...]

GitHub Beginners in Data Science: Here’s an Easy Way to Start!

GitHub beginners – even in data science – often feel intimidated when starting their GitHub [...]

ETL Pipeline Documentation: Here are my Tips and Tricks!

ETL pipeline documentation is great for team communication as well as data stewardship! Read my [...]

Benchmarking Runtime is Different in SAS Compared to Other Programs

Benchmarking runtime is different in SAS compared to other programs, where you have to request [...]

End-to-End AI Pipelines: Can Academics Be Taught How to Do Them?

End-to-end AI pipelines are being created routinely in industry, and one complaint is that academics [...]

Referring to Columns in R by Name Rather than Number has Pros and Cons

Referring to columns in R can be done using both number and field name syntax. [...]

The Paste Command in R is Great for Labels on Plots and Reports

The paste command in R is used to concatenate strings. You can leverage the paste [...]

Coloring Plots in R using Hexadecimal Codes Makes Them Fabulous!

Recoloring plots in R? Want to learn how to use an image to inspire R [...]

Adding Error Bars to ggplot2 Plots Can be Made Easy Through Dataframe Structure

Adding error bars to ggplot2 in R plots is easiest if you include the width [...]

AI on the Edge: What it is, and Data Storage Challenges it Poses

“AI on the edge” was a new term for me that I learned from Marc [...]

Pie Chart ggplot Style is Surprisingly Hard! Here’s How I Did it

Pie chart ggplot style is surprisingly hard to make, mainly because ggplot2 did not give [...]

Time Series Plots in R Using ggplot2 Are Ultimately Customizable

Time series plots in R are totally customizable using the ggplot2 package, and can come [...]

Data Curation Solution to Confusing Options in R Package UpSetR

Data curation solution that I posted recently with my blog post showing how to do [...]

Making Upset Plots with R Package UpSetR Helps Visualize Patterns of Attributes

Making upset plots with R package UpSetR is an easy way to visualize patterns of [...]

4 Comments

Making Box Plots Different Ways is Easy in R!

Making box plots in R affords you many different approaches and features. My blog post [...]

Convert CSV to RDS When Using R for Easier Data Handling

Convert CSV to RDS is what you want to do if you are working with [...]

GPower Case Example Shows How to Calculate and Document Sample Size

GPower case example shows a use-case where we needed to select an outcome measure for [...]

Querying the GHDx Database: Demonstration and Review of Application

Querying the GHDx database is challenging because of its difficult user interface, but mastering it [...]

Variable Names in SAS and R Have Different Restrictions and Rules

Variable names in SAS and R are subject to different “rules and regulations”, and these [...]

Referring to Variables in Processing Data is Different in SAS Compared to R

Referring to variables in processing is different conceptually when thinking about SAS compared to R. [...]

Counting Rows in SAS and R Use Totally Different Strategies

Counting rows in SAS and R is approached differently, because the two programs process data [...]

Native Formats in SAS and R for Data Are Different: Here’s How!

Native formats in SAS and R of data objects have different qualities – and there [...]

SAS-R Integration Example: Transform in R, Analyze in SAS!

Looking for a SAS-R integration example that uses the best of both worlds? I show [...]

Dumbbell Plot for Comparison of Rated Items: Which is Rated More Highly – Harvard or the U of MN?

Want to compare multiple rankings on two competing items – like hotels, restaurants, or colleges? [...]

2 Comments

Data for Meta-analysis Need to be Prepared a Certain Way – Here’s How

Getting data for meta-analysis together can be challenging, so I walk you through the simple [...]

Sort Order, Formats, and Operators: A Tour of The SAS Documentation Page

Get to know three of my favorite SAS documentation pages: the one with sort order, [...]

Confused when Downloading BRFSS Data? Here is a Guide

I use the datasets from the Behavioral Risk Factor Surveillance Survey (BRFSS) to demonstrate in [...]

2 Comments

Doing Surveys? Try my R Likert Plot Data Hack!

I love the Likert package in R, and use it often to visualize data. The [...]

2 Comments

I Used the R Package EpiCurve to Make an Epidemiologic Curve. Here’s How It Turned Out.

With all this talk about “flattening the curve” of the coronavirus, I thought I would [...]

Which Independent Variables Belong in a Regression Equation? We Don’t All Agree, But Here’s What I Do.

During my failed attempt to get a PhD from the University of South Florida, my [...]

At the beginning of the pandemic, I used the EpiCurve package in R to make an early epicurve. I show you my code in this blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Verified by MonsterInsights