View on GitHub

# Research Methods in R

2023 Edition.

Research Methods in R is a set of guides on how to use R as your central research methods tool. They are written by various authors, and curated by Andy Wills. The target audience is psychology undergraduate students. Research Methods in R is Creative Commons, so you are free to reuse these materials and adapt them as you wish, as long as you attribute them to their authors, and as long as your modifications have a Creative Commons licence. They come with absolutely no warranty of any kind.

Note to teachers: These materials have been tested against R version 4.2.1 (released 23rd June 2022), and the most recent version of packages that were available on MRAN on the 1st June 2022.

## List of guides

### Introductory quides

• Long, easy-going introduction
• Somewhat shorter introduction
• Even shorter introduction

### Intermediate guides

Next, go through BOTH of these guides.

## General resources

1. Why R? Discussion of the advantages of R over other software packages.

2. Pedagogy Discussion of philosophy of teaching and learning underlying these materials (mainly aimed at teachers).

3. Who is using R? Partial list of psychology degree programmes around the world than use R.

4. Other resources. A list of other Creative Commons resources about using R.

5. Calculating your module mark. How to calculate a final module mark from your component marks, using R.

6. Dealing with common errors. List of commonly-encountered errors and how to solve them.

7. Case studies

## Absolute Beginners’ Guide to R

A series of worksheets on using R for data analysis in psychology. No previous knowledge of R, or of psychology, is assumed.

### Part 2

• Inter-rater reliability. Percentage agreement. Cohen’s kappa.

• Relationships. Frequency and contingency tables. Mosaic plots. Traditional chi-square test. Bayesian test.

• More on relationships. Extension material on chi-square calculations, including issues surrounding ordered variables (e.g. age), the interpretation of large contingency tables, and a further explanation of the output of the Bayesian chi-square test.

• Sample characteristics. How to calculate summary information about your sample, such as number of participants or gender balance, from your data file.

• Relationships, part 2. Density plots. Scatter plots. Correlation co-efficient. Bayesian and traditional tests.

• More on relationships, part 2. Spearman’s correlation, Kendall’s tau, one-tailed tests, confidence intervals, plus a deeper look at the output of the Bayesian correlation test.

• Making reports with R. How to insert an RStudio graph into your word processor document (e.g. Word). Links to RMarkdown as an alternative.

## Putting R to work

These are mainly further practice in the skills learned in Absolute Beginners’. Where the exercises contain completely new skills, these are shown in bold. Where the exercises extend a skill you’ve already been taught, these are shown in italics. The exercises become somewhat more difficult as you go down the list.

If you are a current undergraduate student at Plymouth University, you should complete the accompanying Psych:EL (Psychology: Experiential Learning) activity first, in order to generate your own set of data. If you’re not, you can download sample data files here.

## A Very Brief Guide to R

The Absolute Beginners’ Guide to R and Putting R to Work provide, between them, about 20 hours of introductory material. For those in a hurry, the Very Brief Guide to R covers the most critical material from those two courses in about four hours.

## Research Methods in Practice (Quantitative section)

These are intermediate-level materials. They are maintained by Ben Whalley on a separate site, but have been designed to fit in here in this sequence of materials. Only the quantitative section of Ben’s site contains information concerning the usage of R.

## Intermediate Guide to R

These are intermediate-level materials. They provide analysis methods for conducting realistic, high-quality studies in psychology. They are aimed at a second-year undergraduate audience.

• Revision: A quick recap of key information covered in earlier courses.

• Statistical power: How to calculate the statistical power of experiments.

• More on statistical power: A deeper discussion on statistical power, including: (1) relation between statistical power and the replication crisis, (2) better standards for statistical power, (3) how to improve effect size, (4) estimating effect size from previous work.
• Data preprocessing: Getting data from lab-based (OpenSesame) experiments into a format closer to something you can actually analyse, in five steps: loading, selecting, filtering, summarising, and combining. Also covers combining data frames, renaming columns.

• More on preprocessing: A slightly more advanced worksheet, covering adding columns to a data frame, and subsetting strings.
• Within-subject differences: Data preprocessing (pivoting and mutating). One-factor within-subject Bayesian ANOVA. Pairwise comparisons, multiple comparisons.

• Understanding interactions: Learn what an interaction is, and learn how to do line plots at the same time.

• Factorial differences: Two-factor Bayesian ANOVA (one within, one between), plus advice on: pairwise comparisons, better graphs, reporting Bayesian ANOVA, and ordinal (i.e. ordered) independent variables.

## Going further with R

These are slightly more advanced materials, aimed at a final-year undergraduate psychology audience.

• Data management

• Data management: Anonymity and privacy, good and bad file types, creating and sharing a private github repository, adding a repository to Rstudio, adding files to github using Rstudio, modifying and updating files, git log as your logbook, branching, recovering an earlier version of a file.
• Preprocessing

• Descriptive statistics

• Better tables: correlation matrix, custom table of descriptive statistics.

• Better graphs: publication-quality graphs showing both central tendency and variability (or uncertainty) of your data, including: line plots, distribution plots (density, violion, half-violin), box plots, and confidence intervals. Suggested plots for one- and two-factor designs, within-subject, between-subject, or mixed designs, and with ordered and unordered variables. Discussion of common bad plots to avoid (bar plots; confusions over confidence intervals). Pairs plot for correlational designs.

• Analysing scales: Cronbach’s alpha.

• Bayesian inferential statistics

## Case studies

These are full preprocessing and analysis pipelines, mainly based on final-year undergraduate psychology projects.

• The effects of negative mental imagery on self-esteem: preprocessing, Cronbach’s alpha, Bayesian ANOVA.

• The Perruchet Effect: Downloading from OSF, de-duplicating data, excluding participants, line graphs, baseline correction of neuroscience data, functions, loops, merging data frames, list of participant numbers, log transforms, recoding data, Bayesian linear regression for within-subjects designs.

• Childrens’ language development: preprocessing, Bayesian t-test, tables of descriptive statistics, correlations, half-violin plot, Wilcoxon test.

## R for Pros

These worksheets go beyond what is taught in previous sections of RMINR. They are aimed at high-achieving undergraduates, as well as postgraduate students and professional researchers. They assume familiarity with material up to and including Going Further with R.

#### Source code

These teaching materials were generated using a combination of Markdown and RMarkdown. The full source code is available on github.