# Data manipulation and visualization
install.packages("tidyverse")
# Publication-ready tables
install.packages("gtsummary")
# Epidemiological analysis
install.packages("survival")
install.packages("epiR")
# Outbreak analytics
install.packages("incidence")
install.packages("epicurve")Getting Started with R for Epidemiology
beginners
tutorial
setup
A beginner’s guide to setting up R and RStudio for epidemiological analysis
Introduction
Welcome to R programming! This post will guide you through setting up your R environment and running your first analysis.
Why R for Epidemiology?
R has become the standard tool for modern epidemiological analysis because it offers:
- Reproducibility: Your entire analysis can be documented and shared
- Powerful packages: Specialized tools for outbreak analytics, survival analysis, and more
- Free and open-source: No licensing costs
- Active community: Extensive support and resources
- Modern tools: Packages like EpiNow2 and epiparameter for cutting-edge analysis
Setting Up Your Environment
Step 1: Install R
Download R from CRAN:
- For Windows: Choose the
.exeinstaller - For Mac: Choose the
.pkginstaller - For Linux: Use your package manager
Step 2: Install RStudio
Download RStudio Desktop (free) from Posit.
Step 3: Install Essential Packages
Open RStudio and run:
Your First Analysis
Let’s analyze a simple outbreak dataset:
# Load packages
library(tidyverse)
# Create sample outbreak data
outbreak_data <- data.frame(
age_group = c("0-5", "6-10", "11-15", "16-20", "21+"),
cases = c(12, 18, 25, 15, 8)
)
# Create a simple epi curve
ggplot(outbreak_data, aes(x = age_group, y = cases)) +
geom_col(fill = "steelblue") +
theme_minimal() +
labs(
title = "Cases by Age Group",
x = "Age Group (years)",
y = "Number of Cases"
)Next Steps
- Join our bi-weekly training sessions via Meetup
- Explore the R for Data Science book (free online)
- Practice with real datasets from your field
Resources
Questions? Email us at info@unijosrusers.org or join our next training session!