This website concerns the “R for Statistics” PhD course at the University of the Faroe Islands. Read more about the course here: https://www.setur.fo/fo/utbugving/stakgreinalestur/depilin-fyri-heilsu-og-almannagransking/r-for-statistics-basic-course-in-the-statistical-program-r-and-rstudio/

In this course, we learn how to use R and RStudio for statistics. We do not teach statistics in this course, and assume that participants are at least somewhat familiar with statistics. The course is very practical, and is based on short case studies where we go through four basic steps of statistics, loading, cleaning, plotting, and modelling data.

Attendees of this course should read this page carefully, in particular the “Preparation” section, including the “Reading material” and “Installing R/Rstudio” sections.

Preparation

Reading material

The course will be very hands-on, learning how to do actual statistical analyses in R, but we want to to understand some basic R concepts before the start of the course. To that end, you should read parts 1 and 2, that is, chapters 1 through 8, of “Hands-on Programming with R”. It is important that you read the material, as if you don’t you may find it difficult, or impossible, to follow the course.

“Hands-On Programming with R: Write Your Own Functions and Simulations” by Garrett Grolemund

https://rstudio-education.github.io/hopr/

We want you to understand the concepts layed out in these chapters to the best of your abilities. In general, we want you to understand:

  • How to use arithmetic and variables in R
  • How functions work and how to use them
  • Basic data types like strings, lists, vectors and especially data frames

We recommend that you have R open while you read, and try some of the commands to improve your understanding of the material in the book. The book has short excercises, but don’t worry if you don’t know how to solve all of these.

To help you get the most out of your reading, here’s what you should focus on when reading the chapters:

  • Part 1 (chapters 1-3):
    • Read carefully, understand to the best of your abilities.
  • Part 2 (chapters 4-8):
    • The material in these chapters is important as well. Don’t get caught up in details though, if you’re having great trouble with something, move on.
  • Chapter 2.1: The R User Interface
    • Don’t worry if you don’t fully grasp it, we will cover it in class.
  • Chapter 2.4: Writing Your Own Functions
    • We don’t expect you to be able to write your own functions.
  • Chapter 3.2: Getting Help with Help Pages
    • We will talk more about getting help in class.
  • Chapter 5.1.5: Complex and raw
    • Skip
  • Chapter 5.3-5.5
    • Skim these chapters. Read them, but don’t worry if you don’t fully understand their content.
  • Chapter 8: Environments
    • Skip.

Installing R/Rstudio

You need to bring a laptop to the course, and before you arrive you need to install R and Rstudio. Download and install the free desktop version of RStudio. R and RStudio are available for Windows, Mac and Linux.

Download and install the newest version of R:

https://www.r-project.org/

Download and install RStudio Desktop with the Open Source License:

https://www.rstudio.com

If you get stuck installing R and/or RStudio, a quick Google search will give some helpful resources, including:

After installing RStudio, try installing this package. Hopefully, the package will be installed on your system without problems.

install.packages('tidyverse')
install.packages('magrittr')
install.packages('devtools')

Course overview

An overview of the course program is in the table below.

Time Tuesday Wednesday Friday
8:30-11:30 Introduction and R/RStudio Case study 2 Case study 4
12:00-12:30 Lunch Lunch Lunch
12:30-16:00 Case study 1 Case study 3 Workshop and exam

Every case study session will include a small hands-on exercise session, a summary, and a coffee break.

After the course

First and foremost, our advice to you when the course is over is to start analysing data, writing scripts and notebooks, and making projects in R. Statistics and programming is something you primarily learn by experience. Here follow a few book ideas you can try if you want to read more.

You can of course continue reading Hands-on Programming with R, as part 3 contains some more advanced material covering, among other things, more programmatic aspects of R.

“R for Data Science” covers topics similar to this course, including plotting with ggplot2 and data manipulation with dplyr.

“R for Data Science” by Garrett Grolemund andHadley Wickham

https://r4ds.had.co.nz/

“Data Analysis for the Life Sciences” covers statistics using R, and is very practical and clear. It is more geared toward people who know R and are trying to learning statistics, rather than people trying to learn R, but is nonetheless very useful.

“Data Analysis for the Life Sciences” by Rafael A. Irizarry and Michael I. Love

https://leanpub.com/dataanalysisforthelifesciences

Case studies

Below is an overview of all the case study notebooks.

Number Description Notebook Data
1.1 Reading data, plotting, and t test Notes Data
1.2 Linear regression and more plotting Notes Data
2.1 Cleaning up messy data Notes Data (raw), Data (cleaned)
3.1 Logistic regression Notes Clean data from case 2.1
3.2 ANOVA Notes Data
3.3 Genomics with Bioconductor Notes Data avilable at https://www.ebi.ac.uk/gwas/
4.1 Survival analysis Notes R built-in
4.2 Working with map data Notes Web API

Exercises

Below is an overview of all the exercise notebooks.

Number Description Notebook
0 Plotting, directories, scripts and finding help Notes
1 More plotting and finding help Notes
2 Analyse data from case 2.1 Notes
3a Logistic regression Notes
3b Election data Notes