Preface

This book serves as a guide for instructors teaching statistics and research methods with R in the UMass Amherst Psychological & Brain Sciences Department. The book is organized into three main sections:

  1. An introduction to the R language and the RStudio development environment.
  2. A reference for performing and interpreting common statistical tests in R.
  3. Recommended best practices for instructors.

Section 1 is primarily intended for instructors who are unfamiliar with the R language and its ecosystem. However, we recommend even experienced R users read it, as it is useful to remind yourself of the perspective the majority of your students will be approaching R from, and to get “on the same page” as your fellow instructors.

Much of the information in this guide can be found in any “Introduction to R” book or resource. So, why write another one? There are two main reasons:

  1. To provide you with the information you need specifically for Psych 240 and 241, and none of the information you don’t.
  2. To provide opinionated guidance and reference material for the instructor specifically, not just the “average” R user.

It is worth emphasizing again that this guide is designed for instructors of Psych 340 and 241, not necessarily the students in Psych 240 and 241. This means that not everything in this guide should be recapitulated to students directly.

The material in Chapter 2 is a good example of this. Chapter 2 goes into some detail about general programming concepts and some characteristics of the R language itself (not just its application to statistics). It is likely that most students will not need to know, for example, the details of named vs. unnamed function arguments. However, you as the instructor probably do need to know something about this topic, if only to be able to help trouble-shoot problems your students encounter. And your students may not need to know all the data manipulation techniques covered here, but you may find them useful as you use R to prepare data for in-class demonstrations or assignments. So, think judiciously about what programming and R language concepts your students need to know, and don’t overwhelm them by teaching every detail in this guide.

With all the background out of the way, we hope that you find this guide useful as you embark on teaching a new class!

Getting Started

To follow along with the examples in this book, it is recommended that you install the latest version of R and RStudio to your personal computer.

The R Language

R is a complete programming language and computing environment designed to enable statistical modeling, data manipulation, and reporting. Despite its focus on statistics, it is still very feature rich - we can use it to perform mathematical calculations, create data visualizations, connect to remote databases, save results as files on your computer’s hard drive, and more. In fact, this entire manual was created in R!

To get started, download and install the most current version of R for your operating system:

RStudio

RStudio is a graphical program that simplifies common R-related tasks, organizes information about your current R session, and generally makes it easier to use R. This type of program is called an Integrated Development Environment, or IDE for short.

We strongly recommend using R within RStudio. However, it is important to understand that they are separate and distinct programs, and R can freely be used outside of RStudio.

To help your students understand their relationship, you could offer the following analogy: RStudio is like a workbench and toolbox, where R is like a hammer. You do not need a workbench and toolbox to build something with your hammer - but having a workbench to rest your project on while you work, and a toolbox where all your nails are organized is very convenient, and will probably help you do your work faster and more accurately.

The company which produces the RStudio software has several different products with “RStudio” in the name. You and your students will want to install the “RStudio Desktop - Open Source License” version (i.e., the free version):

Formatting Conventions

R source code (i.e., code run in the R console or from an R script) and output are presented in monospace font in regions with a light gray background. We do not include command line prompts (> and +, like you would see in a real R console) in the R source code. This is to allow you to conveniently copy and run the code without having to delete the leading prompt symbols. All text output from executing R commands is denoted with two preceeding hashes (##). So, any time you see ## following a block of R code, you are looking at the output of the preeceeding command.

Additional Materials

As alluded to earlier, this is far from the only “Intro to R” material in existence, though this guide has been developed with Psych 240 and 241 specifically in mind. But we do encourage you to supplement your knowlege with outside sources. We recommend the following resources to learning about R programming:

On campus, there are two great consulting resources for getting help with statistical analysis in R:

About the Authors

Andrea Cataldo (email) and Will Hopper (email) are 2019 graduates of the Cognitive Psychology PhD program. They each have extensive experience teaching statistics with R to undergraduate students as instructors and TAs for Psych 240, and have additional experience teaching R to graduate students and faculty through various methodological workshops on campus and as teaching assistants for Psych 640 and 641.

Funding

Development of this manual was funded by a Periodic Multi-Year Review (PMYR) Grant to Adrian Staub from the UMass Institute for Teaching Excellence & Faculty Development (TEFD). Please email Adrian for any comments and questions.