# Expected Outputs Reference — Superpowered Instructor's Kit

Date: 2026-11-15. 38 tasks. Values for input datasets are not invented; exact printed results shown only for self-contained deterministic exercises. Plot tasks describe the expected visual. R execution has not been verified in this authoring environment.

## W1-M01 — R as calculator

**Kind:** Exact, deterministic example

```text
[1] 7
[1] 8
[1] 11
```

**Check:** Do not interpret R’s console prefix [1] as the result.

## W1-M02 — Assignment and reusable results

**Kind:** Exact values where deterministic; otherwise preview

```text
[1] 5.5
# ls() also lists current object names; that list depends on the R session.
```

**Check:** ls() is session-dependent and may include other objects.

## W1-M03 — Text, numbers, vectors and indexing

**Kind:** Exact, deterministic example

```text
[1] 6
[1] 8 7
[1] 6.5
```

**Check:** In sleep_hours[sleep_hours > 6], the condition is applied element by element.

## W1-M04 — Built-in USArrests data frame

**Kind:** Exact values where deterministic; otherwise preview

```text
[1] 50 4
[1] "Murder" "Assault" "UrbanPop" "Rape"
# head(crime) prints six state rows with four columns.
```

**Check:** Built-in datasets are useful for syntax practice, not evidence about present-day conditions.

## W1-M05 — Functions, help and extraction

**Kind:** Exact values where deterministic; otherwise preview

```text
[1] 6
# print(crime$Murder) shows all 50 values (truncated here).
[1] 17.4
[1] 337
```

**Check:** A maximum is a descriptive statistic; it does not identify its row unless you inspect which state attained it.

## W1-M06 — Removing objects

**Kind:** Exact, deterministic example

```text
[1] FALSE
```

**Check:** Running this section twice without recreating crime can fail because rm(crime) cannot find it.

## W1-E01 — Additional: reproducible report

**Kind:** Exact, deterministic example

```text
  trial rt_ms
1     1   620
2     2   610
3     3   590
4     4   605
```

**Check:** Four simulated trials do not support general population conclusions.

## W2-M01 — Packages and importing CSV

**Kind:** Output format / checks (not fabricated values)

```text
n_participants n_responses
# Numeric counts depend on the included fictional public CSV files.
```

**Check:** Extract the full package and keep the data/ directory adjacent to the script.

## W2-M02 — Join by a compound key

**Kind:** Output format / checks (not fabricated values)

```text
rows unique_ids
# Two named counts; values depend on the loaded public datasets.
```

**Check:** The nrow inequality catches row explosions but does not prove that all records matched correctly.

## W2-M03 — select(): columns

**Kind:** Exact, deterministic example

```text
[1] "id" "intervention" "ahiTotal" "cesdTotal" "sex"
[6] "age" "educ" "income" "occasion"
```

**Check:** select() preserves row count and existing order unless other operations are added.

## W2-M04 — filter(): observations and a source correction

**Kind:** Output format / checks (not fabricated values)

```text
0   1
# Counts for baseline and posttest; public fictional data values vary.
```

**Check:** Do not use 1/2 as pre/post: the original worksheet shortcut contradicts the codebook.

## W2-M05 — arrange(): rows

**Kind:** Output format / checks (not fabricated values)

```text
  id occasion ahiTotal
# First six rows after ascending sorting; exact values are data-dependent.
```

**Check:** Sorting and filtering are different: arrange() retains all input rows.

## W2-M06 — summarise(): overall means

**Kind:** Output format / checks (not fabricated values)

```text
  n mean_ahi mean_cesd
# One row with three summary columns; numbers depend on input CSVs.
```

**Check:** n() counts all rows, including those with an NA in a measured variable.

## W2-M07 — group_by(): distinct occasion summaries

**Kind:** Output format / checks (not fabricated values)

```text
  occasion   n mean_ahi mean_cesd
# One summary row per occasion (0 and 1).
```

**Check:** If a score contains missing values, mean() without na.rm=TRUE may return NA.

## W2-M08 — mutate(): new column and scale caution

**Kind:** Output format / checks (not fabricated values)

```text
  sadness cesdTotal ahiTotal
# First six rows; sadness = cesdTotal - ahiTotal.
```

**Check:** This 'sadness' variable is ONLY a syntax exercise; it is not a legitimate clinical index.

## W2-M09 — Recode sex using the codebook

**Kind:** Output format / checks (not fabricated values)

```text
Female Male
# Category frequencies; an NA row appears if unmatched/missing values occur.
```

**Check:** Reversing the codebook mappings would silently mislabel participants.

## W2-E01 — Additional: paired change and attrition

**Kind:** Output format / checks (not fabricated values)

```text
  paired_n mean_change
# One row: count of matched pairs and their average ahi_post - ahi_pre.
```

**Check:** Check uniqueness of (id, intervention, occasion); missing follow-ups and NA scores need explicit handling.

## W3-M01 — Read AQ, formats, scoring

**Kind:** Output format / checks (not fabricated values)

```text
participants questions rules
# Three named counts; original private AQ source had 66 respondents and 10 items.
```

**Check:** The public data are fictional. Do not assume the original Moodle row counts are reproduced there.

## W3-M02 — Wide-to-long pivot

**Kind:** Output format / checks (not fabricated values)

```text
[1] <participants × 10> <column count after pivot>
# In original private data, there were 66 × 10 = 660 long-form rows.
```

**Check:** all_of() requires all Q1–Q10 columns to exist; verify column names and each participant's expected ten items.

## W3-M03 — Join directions and exact scoring rules

**Kind:** Output format / checks (not fabricated values)

```text
  Id Question Response QFormat Score
# First six matched response rows, each with a binary Score (0 or 1).
```

**Check:** inner_join can drop unmatched answers; equal row counts alone do not prove one-to-one matching.

## W3-M04 — Participant total AQ score

**Kind:** Output format / checks (not fabricated values)

```text
  Id AQTotal
# First six participants with integer totals from 0 to 10.
```

**Check:** A total within 0–10 may still come from fewer than ten scored questions. Check item counts per Id.

## W3-M05 — Pipe version of a complete workflow

**Kind:** Exact, deterministic example

```text
# No printed output when stopifnot(identical(...)) passes.
# If it fails, R stops with an error.
```

**Check:** identical() checks classes, row order and attributes as well as values; equivalent data can sometimes differ in attributes.

## W3-M06 — Descriptives, cut-off and counts

**Kind:** Output format / checks (not fabricated values)

```text
  n mean sd min max above6
# One summary row; followed by rows with AQTotal > 6.
```

**Check:** A questionnaire screening threshold must not be interpreted as a clinical diagnostic finding.

## W3-M07 — AQ frequency histogram

**Kind:** Expected visual output

```text
[Plot] Ten-point integer-scale histogram; x-axis 0–10, y-axis participant counts.
```

**Check:** The familiar normal '68% within 1 SD' rule need not hold for a bounded discrete score.

## W3-E01 — Additional: variance, SE, missingness

**Kind:** Output format / checks (not fabricated values)

```text
sample_variance standard_error
# Two positive numeric values; data-dependent.
```

**Check:** Variance, SD and SE answer different questions. Do not substitute SE for SD on participant-level charts.

## W4-M01 — Histogram and binwidth

**Kind:** Expected visual output

```text
[Plot 1] AHI histogram with binwidth 5.
[Plot 2] The same distribution with binwidth 1.
```

**Check:** Histogram appearance depends strongly on breaks; avoid claiming a shape is inherent to the raw data.

## W4-M02 — Scatterplot and sex legend

**Kind:** Expected visual output

```text
[Plot] AHI on x-axis; CES-D on y-axis; coloured points and a Female/Male legend.
```

**Check:** Repeated observations for the same person can make apparent independence misleading.

## W4-M03 — Boxplot, violin, and raw points

**Kind:** Expected visual output

```text
[Plot 1] AHI boxplot by occasion.
[Plot 2] Violin + narrow boxplot + jittered individual points.
```

**Check:** A standard boxplot does not show mean ± SD; and a violin density may exaggerate thin groups.

## W4-M04 — Mean bar plot, grouped by intervention

**Kind:** Expected visual output

```text
[Plot 1] One mean-AHI bar per occasion.
[Plot 2] Side-by-side intervention mean bars per occasion.
```

**Check:** Compare denominators n by group, and do not mistake a descriptive bar difference for a tested effect.

## W4-M05 — Line plot and SD error bars

**Kind:** Expected visual output

```text
[Plot] Intervention mean-AHI trajectories across occasions with vertical ±1 SD error bars.
```

**Check:** coord_cartesian() zooms without filtering original data; SD bars must not be called confidence intervals.

## W4-M06 — Themes, labels, facets and point style

**Kind:** Expected visual output

```text
[Plot 1] Classic scatter with title.
[Plot 2] Black-and-white faceted scatter by sex.
[Plot 3] Purple triangle scatter.
```

**Check:** Visual style is not evidence of a statistical effect; transparency influences visibility.

## W4-E01 — Additional: correlation and ATSQ context

**Kind:** Output format / checks (not fabricated values)

```text
correlation
# One coefficient in [-1,1].
atsq_rows background_rows joined
# Three data-dependent row counts.
```

**Check:** Correlation does not prove causality; missing pairs and repeated observations require care.

## W5-E01 — Sampling distributions and descriptive variation

**Kind:** Exact, deterministic example

```text
n = 12
mean_ms = 606.75
sd_ms ≈ 10.3320
se_ms ≈ 2.9826
```

**Check:** Fictional trial values illustrate estimation only, not generalisable experimental results.

## W5-E02 — Resampling and bootstrap percentile interval

**Kind:** Output format / checks (not fabricated values)

```text
sd_n4 sd_n10
# Two simulation SDs (typically sd_n10 < sd_n4).
2.5% 97.5%
# Two bootstrap percentile endpoints; exact values require running R.
```

**Check:** The seed makes R reproducible, but no numeric bootstrap result is claimed without executing the R source.

## W5-E03 — Visualising the resampling distributions

**Kind:** Expected visual output

```text
[Plot] Two side-by-side resampled-mean histograms: n=4 and n=10.
```

**Check:** The two histograms need comparable axes if you want a strong visual claim about width.

## W6-E01 — Null hypothesis and one-sample t test

**Kind:** Exact values where deterministic; otherwise preview

```text
t ≈ 2.2631   df = 11   p ≈ 0.04484
# t.test() additionally prints the 95% confidence interval and sample mean.
```

**Check:** A small p-value does not establish substantive importance or guarantee the model's assumptions.

## W6-E02 — Confidence interval and effect size

**Kind:** Exact values where deterministic; otherwise preview

```text
ci_lower ≈ 600.1854
ci_upper ≈ 613.3146
cohens_d ≈ 0.6533
# stopifnot() prints nothing if the two CI calculations agree.
```

**Check:** An interval describes uncertainty about a mean under assumptions, not a probability that individual scores lie inside it.

## W6-E03 — Regression, correlation, model diagnostics

**Kind:** Output format / checks (not fabricated values)

```text
               Estimate Std. Error t value Pr(>|t|)
(Intercept)      ...      ...    ...      ...
ahiTotal         ...      ...    ...      ...
r = ... ; r_squared = ...
# Coefficient values depend on the public dataset.
```

**Check:** Do not treat this basic repeated-record model as a causal or fully valid independent-observation analysis.

