# Example of a solution
ebola_linelist %>%
filter(
age > 25,
district == "Bolo"
)How to Guide
How should I use these case studies?
Choose a case study that fits your training needs based on topic, complexity, and language—details are available on the homepage and at the top of each case study page.
You can complete the case study individually or in a group. If facilitating, guide the group through the sections. There’s no facilitator’s guide; all learning materials are on the case study page, including the scenario, data download, tasks, and interactive hints and solutions.
What do I need to complete a case study?
Aside from opening up the case study, you need to:
- Have the relevant program on your computer, like R or Microsoft Excel.
- Organize yourself and put any related files in a project folder.
For projects using R, see more detail in the ‘New to RStudio Projects’? section below.
How can I get help?
There are several ways to get help:
- Look for the hints and solutions. They look like this:
Here you will see a helpful hint!
- Take a look at the EpiRHandbook
- Post a question in Applied Epi Community with reference to this case study
Can I edit this case study?
We encourage open-source material and sharing for learning purposes. However, case studies will be covered by different licenses. Check the terms of use at the bottom of each case study to see if it is suitable for modification. If you have any questions, send us an email at [email protected].
Where do the case studies come from?
All case studies are based on real or plausible scenarios. Some will use simulated data, while others will feature open-access or provided de-identified data. The type of data used will be clearly indicated at the start of each case study.
New to RStudio and RStudio Projects?
We recommend that you create an RStudio Project when working R. Check out the details below.
1) Install (and update!) R and RStudio
If this is your first time using R and RStudio, welcome! The Epidemiologist R Handbook or EpiRhandbook has a wealth of information to support you along the way. It has everything thing you need to get started with R basics, including installing and updating R and RStudio.
If you are new to RStudio, it might be a good idea to spend some time reviewing that page and others before trying out any case studies. Don’t forget that we also have free self-paced R tutorials if you’d like even more guidance and practice.
2) Folder Structure
Once you are ready to start your case study project itself, choose a location on your computer to create a dedicated folder. Once you’ve decided on the best spot, set up a folder with the case study’s name to keep everything organized from the start.
In your case study folder, you should have a:
- subfolder “scripts” to save any scripts related to the analysis
- subfolder “data” which will contain the raw data you will use
- subfolder “outputs” can be used to store any outputs (tables, graphs, documents) that are the result of the analysis
Make sure your folders and subfolders are well-organised as this will save you a headache later!
3) Create RStudio Project
Create an Rstudio project in the case study folder. If you are unsure on how to do that, read the EpiRhandbook on RStudio projects.
4) Start your R Script
Once you have created an RStudio project, start a new R script with an appropriate name (example case_study_name) and save it in the subfolder “scripts”.
If you are familiar with R markdown, you may decide to use this type of file instead of a standard R script. See below for more instructions on using R markdown.
No matter what type of file you choose to use, make sure the purpose, date last updated, and author are written as comments at the top.
#Purpose: To practice new skills using this case study
#Author: Your Name
#Date: Mmm dd, yyyy or whatever format you like best5) Or start your R Markdown
Some of our case studies use R markdown and the code goes within “chunks”, which is different from a standard R script. If you want to create a reproducible workflow, you need a place to save your code so you can run it again if you need to. You want all your files easily organised so you don’t get lost later on. You need to begin by setting the default chunk options.
Typically, you want to change the default chunk options of your R markdown script to:
- hide all code chunks in the report
- not show messages or warnings in the output
- show errors if they appear, but to not stop the rendering
- set up the default figure width to 7 and the figure height to 6
- show the figure titles on top of the plots by default
# hide all code chunks in the output, but show errors
knitr::opts_chunk$set(echo = FALSE, # hide all code chunks in output
error = TRUE, # show errors if they appear, but don't stop (produce the word doc)
warning = FALSE, # do not show warnings in the output word doc
message = FALSE, # do not show messages in the output word doc
fig.width = 7, # Figure width
fig.height = 6, # Figure height
fig.topcaption = TRUE # show figure titles on top of plot
)Be sure to review Reports with R Markdown in the EpiRhandbook before jumping in!
6) Define R Language
Depending on where you are and how you carried out R installation, your language “locale” might be different from the language of the report that you want to produce.
For example, a French-speaking person might have a French ‘locale’. If that is the case, when creating a graph by day of the week, “Monday” will be displayed as “lundi”. If that person wants to create an English report, as for this case study, the language ‘locale’ should be changed.
To ensure your ‘locale’ is set to English, use the following code:
# To see your language locale
Sys.getlocale()
# To change it into English
Sys.setlocale("LC_ALL", "English")7) Install packages
At the start of every R project, you will need to install the necessary packages. We do this with the {pacman} package. Its p_load() command will install packages if necessary and load them for use in the current session. If a listed package has already been installed, it will just load it. Each case study specifies at the beginning what packages you need to have installed.
You can find more about installing/loading packages in the suggested packages section of the EpiRhandbook.
Example code to install packages:
# Ensures the package "pacman" is installed
if (!require("pacman")) {
install.packages("pacman") }
# install (if necessary) from CRAN and load packages to be used
pacman::p_load(
rio, # importing data
skimr, # get overview of data
janitor, # data cleaning and tables
lubridate, # working with dates
epikit, # to create age categories
gtsummary, # summary statistics, tests and regressions
apyramid, # plotting age pyramids
tidyverse # data management and visualization
)If this step is not working, you may have limited administrative rights for your computer. Making sure your IT-department gives you the correct access can save a lot of headache. See these EpiRhandbook pages on the basics of installing packages and running R from network drives (company computers) for more detail.
