# Psychology R Lab 01-03 — Student workbook

Independent beginner tutoring resource, **not official UCL material**. The student has not been confirmed as enrolled in PALS0046. All 18 records are invented. Each lab is a separate 90-minute guided session.

## Lab 01 — RStudio, research questions, vectors (90 min)

**Learning outcomes:** Save and run an .R script; explain Console vs Script; create and subset vectors; link a psychological research question to variables and possible confounders.

**0–10** Predict outputs of `5 + 3 * 2` and `length(c(4,8,12))`.
**10–25** Formulate: “Is sleep duration associated with reaction time?” Identify outcome, explanatory variable, unit and possible confounder.
**25–45** Open `scripts/week01_intro.R` and run line by line.
**45–65** Create `sleep_hours <- c(6,8,7,5)`; calculate length and mean; select values greater than 6.
**65–77** Plot trial vs reaction time; deliberately introduce a name typo and debug.
**77–90** Independently write three R lines; explain why association alone does not imply causation.

**Check:** (1) Why does R indexing start at one? (2) What is a reusable script? (3) What can synthetic data prove about real people?
**Homework:** Create your own five-value synthetic vector with a labelled plot and one careful sentence.

## Lab 02 — CSV, types, factors and missing data (90 min)

**Learning outcomes:** Read a CSV; distinguish participant IDs, categorical factors and numeric measurements; inspect a data frame; understand `NA`, `na.rm` and safe copying.

**0–10** Check that the data file is available; run `source("scripts/check_setup.R")`.
**10–25** Prepare a data dictionary for `id`, `condition`, `rt_ms`, `memory_pre`, `memory_post`, `sleep_hours`, `response`, `gain`.
**25–45** Run `scripts/week02_types_missing.R`; inspect `head(pals)`, `names(pals)`, `str(pals)`.
**45–65** Explain `factor`; set one RT in a *copy* to `NA` and compare summary results.
**65–77** Fix a column-name typo. Discuss why zero must not substitute for a missing observation.
**77–90** Independent three-item diagnostic: 18 rows? 8 columns? Three group counts?

**Check:** Why isn't ID an interval measurement? Why does `mean(x)` often return `NA` when one item is missing?
**Homework:** Explain the eight columns in a concise data dictionary.

## Lab 03 — Mean, median, SD, SE and groups (90 min)

**Learning outcomes:** Compute descriptive statistics with units; compare means across conditions; distinguish SD from the standard error; inspect outlier effects.

**0–10** Revisit factors and missing observations.
**10–25** Explain mean/median/SD/SE using reaction time (milliseconds).
**25–45** Run `scripts/week03_descriptive.R`; record mean, median, SD and SE with units.
**45–65** Compute means for Control, Training and Mindfulness; explain sample size per group.
**65–77** Change one RT to 900 **in a copy**, then compare mean and median.
**77–90** Draft three careful English sentences: description, grouping, scientific limitation.

**Check:** What is the difference between SD and SE? Does a different mean in these fabricated groups demonstrate a treatment effect?
**Homework:** Write a 100–150 word analysis of the synthetic dataset with explicit limitations.

## Self-check before sharing work

- I can run the script from a fresh RStudio session.
- I have not overwritten the original CSV.
- I can explain why `NA` and zero are different.
- I have used milliseconds for RT.
- I have not presented fictional observations as real research evidence.

Teacher solutions and graded assessment answers are not included in the public student package.
