R Lab and Code
Welcome! Here you will find material for R lab and code for this course.
Set up
You need R for these exercises. It is recommended that you have R and RStudio on your laptop, but if there are problems with installation, you can choose Posit Cloud.
If you don’t have R yet, please read this page to get started.
Data and R scripts
Datasets can be found in this folder. R scripts used for each section are placed in this folder.
In the first R lab session, we will go through how to download them from GitHub; you can also try it yourself following instructions on this page.
If you have trouble downloading datasets from GitHub, please let us know as soon as possible.
Lab notes and exercises
In the lab sessions, you will have time to go through the examples and exercises with the help from the instructors. In the lab notes you can find:
- Brief summary of the topics discussed in class;
- Worked data analysis examples with code and visualization;
- Exercises and solution
If this is the first time you write R code, you might find it a bit overwhelming. It is ok! Programming is NOT the focus of this course.
Not all code shown in class are mandatory; it’s more for you to understand the topics we discussed.
To help you with the exercises and homework, we have created this list of commands. They should cover the most important commands for this course.
Week 1
Topics | Lab notes | |
---|---|---|
Lab 1 | Create new project, workspace navigation | Get started in Rstudio |
Variable, data types and structure, basic data manipulation, import data | Introduction to R | |
Lab 2 | Exploring a dataset, descriptive statistics | Descriptive statistics |
Lab 3 | Evaluation of diagnostic tests, sensitivity, specificity | Probability, diagnostic tests |
Lab 4 | Binomial and normal distribution | Statistical distributions |
Lab 5 | Inference and t-test | t-test |
Lab 6 | Proportions, contingency table, chi-square test | Categorical data analysis |
Week 2
Topics | Lab notes | |
---|---|---|
Lab 7 | Wilcoxon signed test, rank sum test | Non-parametric tests |
Sample size, power calculation | Exercises, code: lecture, code: exercises | |
Lab 8 | Correlation, univariate analysiss | Linear regression I |
Lab 9 | Multiple regression | Linear regression II |
Lab 10 | Model diagnostics, selection | Linear regression III |
Lab 11 | Logistic regression | Logistic regression |
Lab 12 | Kaplan-Meier curve, log rank tests | Survival analysis |
(EDA: exploratory data analysis)
Useful resources
List of commands that are useful for this course: list of commands
Book (Wickham et al) R for Data Science (2e)
Demo of webR