Chapter 1 Introduction

Welcome to this introductory R programming course, specifically designed for Health Economics students to quickly give them a glimse of R. In today’s data-driven healthcare environment, the ability to analyze and visualize health economic data effectively is crucial. This 8 hours course will equip you with the essential skills to use R for data analysis, and visualization using R Markdown.

1.1 Learning Objectives

By the end of this course, you will be able to:

  • Master the fundamentals of R programming and RStudio environment
  • Understand data wrangling techniques using tidyverse packages
  • Create professional visualizations with ggplot2
  • Apply these skills to real-world health economics scenarios througth exercices

1.2 Why R and R Markdown?

R has become an essential tool in health economics for several reasons:

  • Open-source and Free: Access to powerful statistical and analytical tools without licensing costs
  • Reproducibility: Your analyses can be easily shared and reproduced by others
  • Extensive Package Ecosystem: Specialized packages for health economics and statistics
  • Data Visualization: Professional-quality graphics and interactive visualizations
  • Integration with Other Tools: Seamless integration with databases, other statistical software, and reporting tools

1.3 Course Structure

Our course is organized into several modules:

1.3.1 R basics and data manipulations (2h)

  • Introduction to R and RStudio
  • Data types and objects
  • Importing data and basic data manipulations
  • Exercices

1.3.2 Data Wrangling and basic statistics (2h)

  • Data cleaning (Filtering, selecting, and transforming data) and preparation
  • Combining datasets
  • Computing statistics (mean, variance)
  • Exercices

1.3.3 Data Visualization with ggplot (2h)

  • Principles of effective visualization
  • Creating plots with ggplot2
  • Customizing graphics for healthcare data
  • Exercices

1.4 Prerequisites

No prior programming experience is required Basic statistical knowledge Laptop with R and RStudio installed

1.5 Course Materials

All course materials will be provided at the end of the course in an R Markdown book format, allowing you to:

  • Follow along with interactive examples
  • Execute code in real-time
  • Create your own annotations
  • Test your leaning through exercices

1.6 Practical Applications in Health Economics

Throughout the course, we’ll work with real-world examples relevant to health economics, such as:

using the medicaldata library.

1.7 Assessment

Your learning will be evaluated through exercises during sessions.

1.8 Getting Started

Before our first session, please:

RStudio is a free software tool that makes working with the R programming language much easier. Think of it as a specialized workspace for R - like having a well-organized desk with all your tools in the right place. While you can use R by itself, RStudio gives you helpful features like:

  • A cleaner way to write and run your code
  • Better organization of your data
  • Simple ways to manage R add-ons (called packages)
  • Easy viewing of your results

There’s also a paid professional version available from the company Posit, but the free version has everything most people need. If you’re planning to work with R, using RStudio is highly recommended since it’s specifically designed to make R programming more user-friendly.

Harrer et al. (2023)
Harrer et al. (2023)

1.8.1 Understanding the RStudio Interface

When you first open RStudio, you’ll encounter three main sections:

  • Console :This is where the actual work happens in R. You can type R commands directly here and press Enter to execute them. Think of it as R’s command center.

  • Environment: Shows all your current R objects (variables, data, functions) like a workspace overview where you can see everything you’ve created.

  • Files/Plots/Packages/Help: a multi-purpose area that shows: your computer’s files and folders, graphs and visualizations you create, installed R packages, help documentation.

  • Editor : opens when you create a new R script (File > New File > R Script). This is where you write and save your R code Files are saved with a .R extension. *To run code from the editor: Select the code you want to run; Click the “Run” button (▹) in the top-right of the editor Or use the shortcut Ctrl+Enter (Windows) / Cmd+Enter (Mac)

Note: While you write code in the editor, it always executes in the console. Think of the editor as your notebook and the console as where the actual computation happens.

1.9 Support and Resources

Some online resources and reading materials: - Bookdown

Remember, learning to program is like learning a new language - it takes practice and patience. Don’t hesitate to ask questions and collaborate with your peers throughout this journey.

Let’s begin this exciting journey into the world of R programming for health economics!

References

Harrer, Mathias, Pim Cuijpers, Lea Schuurmans, Tim Kaiser, Claudia Buntrock, Annemieke van Straten, and David Daniel Ebert. 2023. Evaluation of Randomized Controlled Trials: A Primer and Tutorial for Mental Health Researchers. Vol. 24. 562. Trials. https://doi.org/10.1186/s13063-023-07596-3.