Today

  • Start with the module structure and assessment.
  • Set up RStudio and practise running commands from the slides.
  • Work through basic arithmetic, objects, vectors, indexing, and logical tests.
  • Complete a self-paced core script with similar but different examples.
  • Use the optional stretch script only if the core work feels comfortable; it is not required exam preparation.

This session is about confidence with the working environment, not statistical theory.

About Me: Dr Jens Roeser

Module Aims

  • Understand the statistical models commonly used in psychology.
  • See classical tests as part of a broader linear-model framework.
  • Connect theory, R output, and written interpretation.
  • Build enough RStudio fluency to run, check, and report analyses.

The module is not about memorising formulas. It is about recognising the model, running the analysis, and interpreting the result carefully.

How The Module Works

  • Watch the weekly online lecture before the workshop, even if some parts feel difficult.
  • Use the workshop to run the core analysis yourself in RStudio.
  • Read the output before moving to the next command.
  • Keep brief notes on commands, output, and interpretation.
  • Complete the weekly problem set in Weeks 3-8.
  • Ask questions on Teams or in class when something blocks you.

Running code is useful. Understanding what you ran and what the output means is the more important skill.

Module Plan

Week 1
Module overview
RStudio basics
Week 2
Inspecting and summarising prepared data
Weeks 3-4
Inference, t-tests, SEs, p-values, CIs
Weeks 5-6
Linear regression and model fit
Week 7
Categorical predictors and dummy coding
Week 8
Interactions and varying slopes
Week 9
Revision and exam-style practice
Week 10
Exam

Problem sets run in Weeks 3-8: lecture, workshop, problem set.

Assessment

  • The module is assessed by a single timed exam.
  • The exam is 90 minutes long.
  • Date and time: Friday 27 November 2026; exam starts at 3.30 pm.
  • There are roughly 30 questions.
  • Questions are a mixture of multiple choice and short free-text / numerical answers.
  • Some questions are theoretical; others ask you to run analyses in R or read R output.

The workshops and problem sets practise the same kinds of decisions: choose the model, run or read the analysis, and interpret the result.

What Exam-Style Questions Look Like

The exam is not about writing long essays or deriving equations from memory.

Typical questions ask you to:

  • interpret a statistical idea, such as a p-value or confidence interval;
  • identify the distribution or test statistic used in a model;
  • calculate a value from information given in the question;
  • run a specified analysis in R and report one value from the output;
  • interpret coefficients, predictions, R-squared, adjusted R-squared, or F statistics.

Example Theory MC Question

These are practice-style examples, not actual exam questions.

A null hypothesis test gives p = .04. What does this mean?

A. The null hypothesis has a 4% probability of being true.
B. If the null hypothesis were true, results this extreme or more extreme would be relatively unlikely.
C. The alternative hypothesis has a 96% probability of being true.
D. The effect explains 4% of the variance.
E. The sample mean must be 4% larger than the population mean.

Example Calculation Question

A linear model has ESS = 180 and RSS = 120. What is the value of \(R^2\)?

A. 0.33
B. 0.40
C. 0.60
D. 1.50
E. 3.00

Short-answer version: give the value of \(R^2\) to at least three decimal places.

Example R Analysis Question

Using a prepared data set, fit this model in R:

lm(score ~ anxiety + sleep, data = practice_data)

Which value would you report if the question asks for the overall model F statistic?

A. The Estimate for anxiety.
B. The Residual standard error.
C. The first value in summary(model)$fstatistic.
D. The Pr(>|t|) value for sleep.
E. The number of rows in the data set.

Different Starting Points

People come to this module with different starting points. The workshop structure is designed so you can build the core workflow step by step, with optional stretch tasks when you are ready.

  • Core route: get the analysis running and interpret the main result.
  • Support route: use comments, worked examples, and answer scripts to rebuild confidence.
  • Stretch route: change the model, compare outputs, or explain why two methods agree.

The aim is progress from your own starting point, not everyone moving at the same speed.

How We Will Practise Today

  1. First, we will look at commands on the slides together.
  2. I explain the command.
  3. You type it into RStudio and run it.
  4. Then you complete a self-paced script with similar but different values.
  5. If the core script feels comfortable, there is an optional stretch script.

The stretch script is not required and is not needed for exam preparation. It is there for students who finish the core work and want more challenge.

The Minimum Workflow

  1. Use one RStudio project folder for the whole module.
  2. Keep scripts, data, slides, and notes inside that folder.
  3. Write code in an R script, not directly in the Console.
  4. Run one line at a time while learning.
  5. Read the Console output before moving on.
  6. If something fails, read the first error message, fix one line, and run it again.

RStudio Projects

An RStudio project is basically a folder on your computer.

  • Create one project folder for the whole module.
  • Put all module files inside that folder.
  • Open the .Rproj file before working.
  • R will then look for files from that project folder.

To create one: File > New Project > New Directory or Existing Directory.

R Scripts

An R script is where you write and save code.

  • Create one with File > New File > R Script.
  • Save it with File > Save As.
  • Use a clear name, for example week_01_practice.R.
  • Comments start with # and are ignored by R.
# This is a comment.
2 + 2

RStudio Panes For Now

For today, focus on two parts of RStudio.

  • R script: where you write and save code.
  • Console: where R shows the result, warning, or error after you run code.

There are other panes in RStudio, but they are not important for the first workshop.

Running Code From A Script

Type this into a script and save it.

# First calculation
2 + 2

# Second calculation
10 / 2

Run one line at a time: put the cursor in the line and click Run, or press Ctrl + Enter / Cmd + Enter.

For learning R, it is useful to run one line, inspect the Console, and only then move to the next line.

Guided Exercise: R As A Calculator

9^2
3 * 3
20 - 6
sqrt(25)

Run each line. Which part is the function name and which part is the input?

Guided Exercise: Arithmetic

8 + 9 * 4
(8 + 9) * 4
8 + (9 * 4)

“What is 8 plus 9 times 4?” is ambiguous in English. Brackets make the mathematical meaning explicit.

Guided Exercise: More Operations

10 + 4 * 2
(10 + 4) * 2

Run these one at a time. Which operations happen first when there are no brackets?

Guided Exercise: Assignment

x <- 10
y <- 5
x + y
x * y
x^2

Objects appear in the Environment pane after assignment.

Guided Exercise: Vectors And Indexing

scores <- c(8, 9, 4, 7, 6)

scores[1]
scores[2:4]
scores[c(1, 3)]
mean(scores)
sd(scores)

Guided Exercise: Logical Tests

scores > 6
scores == 7
scores != 7
scores[scores > 6]
scores[scores < 6 | scores > 8]
scores[scores >= 6 & scores <= 8]

These tests become important later when we filter rows or define groups.

Next week we move from individual vectors to data frames and descriptive summaries of real data sets.

In-Class Task

Open week_01_workshop.R.

Complete the self-paced core script. It uses the same logic as the guided slide exercises, but with different numbers.

Optional Stretch Script

Only open week_01_stretch.R if the core script felt comfortable. There is no expectation that you complete the stretch script, and it is not required preparation for the exam.

Reading / Follow-Up

Recommended reading: Andrews (2021), Chapter 2, Introduction to R.

After the workshop, make sure RStudio opens the project folder and that you can run a script line by line.

Core R Functions

Function / operator What it does
<- saves a value into an object
c() combines values into a vector
mean() calculates an average
sd() calculates a standard deviation
length() counts how many values are in a vector
sqrt() calculates a square root
[] extracts positions or values from a vector

Before Week 2

You do not need to be fast. You do need to be able to do these slowly and deliberately.

  • Open the module RStudio project.
  • Create, save, and reopen an R script.
  • Write a comment with #.
  • Run one line from a script and inspect the Console output.
  • Use assignment, vectors, and basic functions.
  • Inspect a vector and calculate simple summaries.
  • Read the Console output before moving on.
  • Ask for help when an error blocks you.

References

Andrews, M. (2021). Doing data science in R: An Introduction for Social Scientists. SAGE Publications Ltd.

Andrews, M., & Roeser, J. (2021). Psyntur: Helper tools for teaching statistical data analysis. https://CRAN.R-project.org/package=psyntur

Garcia, R., Roeser, J., & Kidd, E. (2023). Finding your voice: Voice-specific effects in Tagalog reveal the limits of word order priming. Cognition, 236, 105424.

Roeser, J., Conijn, R., Chukharev, E., Ofstad, G. H., & Torrance, M. (2025). Typing in tandem: Language planning in multisentence text production is fundamentally parallel. Journal of Experimental Psychology: General, 154(7), 1824–1854. https://doi.org/10.1037/xge0001759

Roeser, J., De Maeyer, S., Leijten, M., & VaWaes, L. (2024). Modelling typing disfluencies as finite mixture process. Reading and Writing, 37(2), 359–384. https://doi.org/10.1007/s11145-023-10489-4

Roeser, J., Torrance, M., & Baguley, T. (2019). Advance planning in written and spoken sentence production. Journal of Experimental Psychology: Learning, Memory, and Cognition, 45(11), 1983–2009.