%%{init: {'theme': 'base'}}%%
flowchart LR
P(["🌍 Population (unknown)"])
S(["📋 Sample (observed)"])
S -- "inference ± uncertainty" --> P
P -. "sampling" .-> S
Week 10: Analysis & Inference
2026-06-18
{infer} package: tidy hypothesis testing| Milestone | Date | Submission |
|---|---|---|
| ✓ general feedback in class today | ||
| Progress Update | 29 Jun | URL to rendered site, updated Project Proposal |
| Group reflection — in-class discussion | W14 practical | N/A |
Final submission + group-reflection.qmd |
Due 22 Jul | URL to final website/webpage, group reflection doc |
| Individual contribution statement | Due 23 Jul | PDF via Moodle |
| Oral exam | 29 Jul | — |
_quarto.yml to configure it as a website, make sure it renders, and use the template as a reference for what that looks likeAdjust the navbar as needed for your output:
A specific plan names:
Vague:
“We will use regression to analyse the data.”
Specific:
“We will estimate
bill_length_mm ~ body_mass_g + speciesusing linear regression to test whether body mass predicts bill length after accounting for species differences.”
Part 2 — Applied statistics
Part 1 — Programming skills
debug() or browser().”We will show you an example dataset or output and ask equivalent questions:
Preparation advice
Practice explaining decisions and implementation out loud — to a classmate, a rubber duck, or yourself. For each step in your project, ask: why did I do it this way, how did I implement it, and what would I have done differently?
Part 1: Statistical Programming Foundations
Part 2: Working with Real World Data
Part 3: Advanced Topics & Summary
renv::init() creates a project-local library and records versions in renv.lockrenv::snapshot() updates the lockfile; renv::restore() rebuilds the library from itrenv.lock to git; add renv/library/ to .gitignoredata-raw/YYYY-MM-DD dates, one value per cell, plain text filesStatistical inference across analysis goals
%%{init: {'theme': 'base'}}%%
flowchart LR
P(["🌍 Population (unknown)"])
S(["📋 Sample (observed)"])
S -- "inference ± uncertainty" --> P
P -. "sampling" .-> S
| Descriptive | Explanatory | Predictive | |
|---|---|---|---|
| Core question | What is the state of things? | Is there a real relationship? | How well can we predict? |
| Penguin example | Mean bill length per species | Does body mass predict flipper length? | Predict flipper length for a new penguin |
| Inference licenses | Population estimates with uncertainty | Association or effect claims | Generalisation to new cases |
A linear regression model estimates the average value of a numeric outcome \(y\) as a linear function of one or more predictors \(x_1, x_2, \ldots\):
\[\hat{y} = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots\]
lm(y ~ x1 + x2, data = df)The same lm() call can address either goal — what changes is how you read the output:
| Descriptive | Explanatory | Predictive | |
|---|---|---|---|
| Key question | Is this estimate reliable? | Is this real, and how large? | Does this generalise? |
| Point estimate | Mean, proportion, rate | Coefficient, effect size | Predicted value |
| Uncertainty | CI around the estimate | CI + hypothesis test | Prediction interval, cross-validation |
| Linear reg. | Summarise the sample relationship | Test whether coefficients are non-zero | Generate predictions for new cases |
| Common mistake | CI treated as a range of plausible individual values | p-value treated as proof of a causal relationship | Training accuracy reported as prediction accuracy |
| Exploratory | Confirmatory | |
|---|---|---|
| Descriptive | Plot all variables; report whichever summaries look interesting | Report pre-specified summaries (e.g. mean bill length per species) |
| Explanatory | Scan all variable pairs for associations; flag the strongest | Test one pre-specified relationship on a held-out sample |
| Predictive | Try many model variants; pick the one with the best-looking accuracy | Report accuracy on data held out before any modelling decisions were made |
The two axes are independent: what you are trying to learn (type) vs. whether the question was fixed before you looked (exploratory/confirmatory).
Descriptive
Explanatory
Predictive
This is genuinely hard
These mistakes appear constantly in published research, business analytics, and data journalism — including the replication crisis in psychology and medicine. They are not signs of incompetence. Knowing this should make you more careful, not less confident.
Not every analysis needs the same level of inferential discipline. Ask two questions:
| Stakes | Tolerance for error | Investment in rigour |
|---|---|---|
| Dashboards, operational reports | Wide — decision support, not proof | Low |
| Business decisions, policy evaluation | Moderate | Medium |
| Clinical trials, legal evidence, systemic models | Narrow — getting it wrong is harmful | High |
Statistics in a Court of Law?
lm() is already inferencelm() summary contains hypothesis tests and confidence intervals — inference is built in{infer}: Tidy Hypothesis Testing{infer} — a tidyverse-friendly package for hypothesis testingA p-value is not a probability that \(H_0\) is true
It is the probability of seeing a result at least this extreme, assuming \(H_0\) is true.
species island bill_length_mm bill_depth_mm
Adelie :152 Biscoe :168 Min. :32.10 Min. :13.10
Chinstrap: 68 Dream :124 1st Qu.:39.23 1st Qu.:15.60
Gentoo :124 Torgersen: 52 Median :44.45 Median :17.30
Mean :43.92 Mean :17.15
3rd Qu.:48.50 3rd Qu.:18.70
Max. :59.60 Max. :21.50
NA's :2 NA's :2
flipper_length_mm body_mass_g sex year
Min. :172.0 Min. :2700 female:165 Min. :2007
1st Qu.:190.0 1st Qu.:3550 male :168 1st Qu.:2007
Median :197.0 Median :4050 NA's : 11 Median :2008
Mean :200.9 Mean :4202 Mean :2008
3rd Qu.:213.0 3rd Qu.:4750 3rd Qu.:2009
Max. :231.0 Max. :6300 Max. :2009
NA's :2 NA's :2

# A tibble: 3 × 4
species n mean_bill sd_bill
<fct> <int> <dbl> <dbl>
1 Adelie 152 38.8 2.66
2 Chinstrap 68 48.8 3.34
3 Gentoo 124 47.5 3.08
# A tibble: 2 × 4
adelie n mean sd
<chr> <int> <dbl> <dbl>
1 Adelie 151 38.8 2.66
2 Non-Adelie 191 48.0 3.23
{infer} workflowspecify() — declare response and explanatory variablesassume(distribution) — use a theoretical null distribution ("t", "z", "Chisq", "F")calculate(stat) — compute the observed test statistic from the data (must match the distribution)get_p_value() — compute the p-valueget_confidence_interval(point_estimate) — compute a CI around the observed statisticvisualize() — plot the null distribution with the observed statistic and/or CI overlaid# A tibble: 1 × 1
p_value
<dbl>
1 4.12e-18

What the test gives evidence for
What it does not establish
Beware collapsing groups!
generate()assume("t") works because mathematicians derived what the null distribution looks like for common statistics — the t-distribution, chi-square, F, etc.Note
For most standard tests (t, chi-square, ANOVA), assume() and generate() give essentially the same answer. generate() is most useful when you need a test that does not have a standard distribution.
generate() in code
hypothesize(null = "independence") — states that species label and bill length are unrelated under \(H_0\)generate(type = "permute", reps = 1000) — shuffles species labels 1000 times; each shuffle is one possible null worldcalculate(stat = ...) — computes the statistic for every shuffle, building up the null distributionGreat explainer: Andrew Heiss, Null Worlds — https://nullworlds.andrewheiss.com
{infer}?You already know t.test() and chisq.test() from Stat 1 & 2 — so why learn another tool?
assume() or generate()).{infer} is one way to run inference in R — it is not the only waylm(), t.test(), chisq.test(), cor.test(), aov(), …{infer}, or any other package that fits your analysis — what matters is that you can explain what test you are running and why{broom} makes model output tidy
tidy(), glance(), and augment() from the {broom} package (part of the tidymodels ecosystem) convert lm(), glm(), and other model objects into data frames — easier to work with downstream than base R’s summary() output.
{infer}specify() → assume() → calculate() → visualize() / get_p_value()assume("t" / "z" / "Chisq" / "F") uses the same theoretical distributions as Stat 1/2generate() simulates the null without assuming a distributionYour responsibility
LLMs do not know your data. Check every suggestion against your actual dataset.
Please log on to:
https://www.lehrevaluation.uni-muenchen.de/evasys/public/online/index
Lösung: 4JQS5