Introduction to Regression Analysis with R

Authors

Sophie Lee

Dean Marchiori

Welcome

Welcome to the course materials for the Introduction to Regression Analysis with R short course.

This course provides a comprehensive understanding of regression analysis, including the theory behind these models, their application in R, validation techniques, and the interpretation of results. The course begins with an introduction to linear regression models, before advancing to the more flexible family of generalised linear models.

Topics covered as part of this course include:

  • Linear regression: concepts, assumptions, application, and interpretations
  • Diagnostics and validation of linear regression models
  • Generalised linear models: beyond continuous outcomes
  • Poisson regression: how to model counts and rates, and how this differs from linear regression
  • Best practices in communicating results of regression analysis

How to use this book

This book provides a combination of written explanations, code examples, and practical exercises to allow you to practice what you have learned.

Code examples will be provided in code blocks, such as this one:

1 + 1

Code in these blocks can be copied and pasted into your R session to save time when coding. We recommend typing the code yourself to familiarise yourself with the coding process and use the copy option if you are really stuck!

Throughout the book, you will see colour-coded boxes which are used to highlight important points, give warnings, or give tips such as keyboard shortcuts.

Note

These boxes will be used to highlight important messages, supplementing the main text.

Hint

These boxes will contain useful hints, such as keyboard shortcuts, that can make your coding life a little easier!

Warning

These boxes will contain warnings and highlight areas where you need to be more cautious in your coding or analysis.

To make these notes as accessible as possible, they are available to view in dark mode by toggling the button. They are also available to download as a PDF file using the button.

All exercise solutions are available in the appendices. Please attempt the exercises yourself first, making full use of R’s built in help files, cheatsheets (where available), and example R code in this book. Going straight to the solutions to copy and paste the code without thinking will not help you after the course!

Some exercises contain expandable hints, such as functions required to complete them, that can be viewed when needed. For example:

The functions you will need for this exercise are filter and count.

Data used in the course

The examples and exercises in these materials are based on real world data.

Data for this course can be downloaded from the data folder of this course’s repository.

For more information about this data, including variable descriptions and sources, see the appendix.

Feedback and issues

If you spot a bug or mistake in these notes, please let me know by raising an issue.

Contact Me

If you enjoyed this course and would like me to run a session for your organisation, or if you would like to engage me as a consultant on a project get in touch at deanmarchiori.com

Licence and Attribution

I believe that science should not be behind a paywall, that is why these materials are available for free online, in accordance with the licence.

This work is an adaptation of original work “Regression with R”. The material has been modified, to compare against the original works see here.

Regressions with R short course by Sophie Lee is licensed under Creative Commons Attribution-ShareAlike 4.0 International

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International.